forked from dsh/ROT-8-Machine
103 lines
3.4 KiB
Python
103 lines
3.4 KiB
Python
"""Draw the program counter, ROM, and indicator blocks for the first breadboard.
|
|
|
|
The pin assignments are in docs/bringup.md.
|
|
|
|
python tools/bringup_sketch.py img/bringup.png
|
|
"""
|
|
import sys
|
|
|
|
from PIL import Image, ImageDraw, ImageFont
|
|
|
|
S = 7
|
|
W, H = 200 * S, 96 * S
|
|
|
|
BG = (247, 245, 239)
|
|
BOX = (255, 254, 250)
|
|
EDGE = (52, 48, 44)
|
|
TEXT = (40, 36, 32)
|
|
DIM = (120, 112, 100)
|
|
BUS = (44, 82, 150)
|
|
CTRL = (172, 48, 40)
|
|
DATA = (36, 116, 74)
|
|
|
|
|
|
def font(pt):
|
|
for path in (r"C:\Windows\Fonts\consola.ttf", r"C:\Windows\Fonts\lucon.ttf"):
|
|
try:
|
|
return ImageFont.truetype(path, int(pt * S))
|
|
except OSError:
|
|
continue
|
|
return ImageFont.load_default()
|
|
|
|
|
|
def p(v):
|
|
return int(round(v * S))
|
|
|
|
|
|
def box(d, x, y, w, h, title, sub, fill=BOX):
|
|
d.rounded_rectangle([p(x), p(y), p(x + w), p(y + h)], radius=p(1.4),
|
|
fill=fill, outline=EDGE, width=p(0.35))
|
|
d.text((p(x + 3.0), p(y + 3.2)), title, font=font(2.0), fill=TEXT)
|
|
if sub:
|
|
for i, line in enumerate(sub.split("|")):
|
|
d.text((p(x + 3.0), p(y + 7.6 + i * 3.0)), line, font=font(1.35),
|
|
fill=DIM)
|
|
|
|
|
|
def bus(d, pts, label, colour, at=0.5, above=True):
|
|
d.line([(p(a), p(b)) for a, b in pts], fill=colour, width=p(0.8), joint="curve")
|
|
# arrow head on the last segment
|
|
(x0, y0), (x1, y1) = pts[-2], pts[-1]
|
|
d.polygon([(p(x1), p(y1)), (p(x1 - 2.0), p(y1 - 1.4)),
|
|
(p(x1 - 2.0), p(y1 + 1.4))] if abs(x1 - x0) > abs(y1 - y0) else
|
|
[(p(x1), p(y1)), (p(x1 - 1.4), p(y1 - 2.0)), (p(x1 + 1.4), p(y1 - 2.0))],
|
|
fill=colour)
|
|
# label along the first segment
|
|
seg = pts[0], pts[1]
|
|
lx = seg[0][0] + (seg[1][0] - seg[0][0]) * at
|
|
ly = seg[0][1] + (seg[1][1] - seg[0][1]) * at
|
|
tw = d.textlength(label, font=font(1.4)) / S
|
|
d.text((p(lx - tw / 2), p(ly - (3.4 if above else -1.4))), label,
|
|
font=font(1.4), fill=colour)
|
|
|
|
|
|
def main():
|
|
out = sys.argv[1] if len(sys.argv) > 1 else "bringup.png"
|
|
img = Image.new("RGB", (W, H), BG)
|
|
d = ImageDraw.Draw(img)
|
|
|
|
d.text((p(6), p(5)), "STAGE 1 · ip COUNTER → ROM → DATA LAMPS", font=font(2.6),
|
|
fill=TEXT)
|
|
d.text((p(6), p(10.6)),
|
|
"the whole point is to watch the address walk and the fetched byte change",
|
|
font=font(1.5), fill=DIM)
|
|
|
|
# blocks
|
|
box(d, 22, 30, 34, 22, "74LS161", "ip[3:0]|TC → next CET", BOX)
|
|
box(d, 22, 62, 34, 22, "74LS161", "ip[7:4]", BOX)
|
|
box(d, 82, 38, 34, 30, "28C256", "A0..A7 in|D0..D7 out|low 3 bits = opcode",
|
|
(250, 250, 244))
|
|
box(d, 144, 38, 34, 30, "8 LEDS", "330 Ω each|D0 left, D7 right", (250, 250, 244))
|
|
|
|
# buses
|
|
bus(d, [(56, 41), (70, 41), (70, 46), (82, 46)], "A0..A3", BUS, 0.45)
|
|
bus(d, [(56, 73), (70, 73), (70, 52), (82, 52)], "A4..A7", BUS, 0.45)
|
|
bus(d, [(39, 52), (39, 62)], "TC", CTRL, 0.5, above=False)
|
|
bus(d, [(116, 50), (144, 50)], "D0..D7", DATA, 0.5)
|
|
bus(d, [(6, 39), (22, 39)], "CLK", CTRL, 0.4)
|
|
bus(d, [(6, 73), (22, 73)], "RST", CTRL, 0.4)
|
|
|
|
# power and notes
|
|
d.text((p(6), p(86)), "5 V / GND to every part · ~CE and ~OE tied low (always "
|
|
"selected) · ~WE tied HIGH (read only!)", font=font(1.4), fill=DIM)
|
|
d.text((p(6), p(90)),
|
|
"clock: a button for single step first, then 74LS14 RC at ~5 Hz, 1 MHz only "
|
|
"when it all works", font=font(1.4), fill=DIM)
|
|
|
|
img.save(out)
|
|
print("wrote", out)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|