Skip to content

Instantly share code, notes, and snippets.

@azechi
Created January 15, 2023 01:05
Show Gist options
  • Save azechi/600b49f18272a72aab7073e0b4d58fe1 to your computer and use it in GitHub Desktop.
Save azechi/600b49f18272a72aab7073e0b4d58fe1 to your computer and use it in GitHub Desktop.
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