Skip to content

Instantly share code, notes, and snippets.

@drhodes
Last active February 4, 2020 21:44
Show Gist options
  • Save drhodes/00deb1c3339d648e45b6b2b702512a98 to your computer and use it in GitHub Desktop.
Save drhodes/00deb1c3339d648e45b6b2b702512a98 to your computer and use it in GitHub Desktop.
generate rom table
class Line(object):
def __init__(self, addr_pattern):
self.ins = addr_pattern.split(" ")[0].strip()
self.out = addr_pattern.split(" ")[1].strip()
def out_format(self):
return self.out.replace("x", "0")
def matches(self, addr):
# addr is a string of 0 and 1 chars.
if len(self.ins) != len(addr):
return False
for (bit1, bit2) in zip(self.ins, addr):
if bit1 == "-": continue
if bit1 != bit2: return False
return True
def ROM():
lines = map(Line, [
# S[2:0],Start,N,Z <space> S'[2:0], ASEL, ALE, BSEL, BLE, FN, BUSY
"000000 000000000",
"0001-- 001000000",
"001--- 010010100",
"010-00 011101001",
"010-10 100101001",
"010--1 000101001",
"011--- 01011x001",
"100--- 010x01111",
])
bad_state_output = "000000000"
for i in range(1<<6):
addr = "{0:06b}".format(i)
bad_state = True
prefix = "0b" + addr + "_"
for line in lines:
if line.matches(addr):
print(prefix + line.out_format())
bad_state = False
if bad_state:
print(prefix + bad_state_output)
if __name__ == "__main__":
ROM()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment