Created
January 15, 2023 01:05
-
-
Save azechi/600b49f18272a72aab7073e0b4d58fe1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from struct import * | |
dat = None | |
with open("../OV767X_dat", "rb") as f: | |
buf = f.read() | |
dat = unpack(f'<{len(buf)//4}I',buf) | |
pin_count = 2 | |
sample_per_word, padding = divmod(32, pin_count) | |
sample_count = len(dat) * sample_per_word | |
pinsymbols = "ABCDEFG" | |
import sys | |
ori_stdout = sys.stdout | |
with open("../vcd", "w") as f: | |
sys.stdout = f | |
print("$enddefinitions $end") | |
reg = [None] * pin_count | |
for tick in range(0, sample_count): | |
word_index, sample_index = divmod(tick, sample_per_word) | |
bit_index = (sample_index * pin_count) + padding | |
sample = (dat[word_index] >> bit_index) & ((1 << pin_count) - 1) | |
s = [] | |
for pin in range(pin_count): | |
if reg[pin] != (bit := bool(sample & (1 << pin))): | |
s.append(f'{int(bit)}{pinsymbols[pin]}') | |
reg[pin] = bit | |
if len(s) > 0: | |
s_ = "\n".join(s) | |
print(f'#{tick}\n{s_}') | |
sys.stdout = ori_stdout |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment