From 6b7965facbeb34fd1fc84fff2bdd3d3a0c17e474 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Sat, 4 Nov 2023 11:59:35 +0200 Subject: Add dig-install make target for automatically installing memory data --- Makefile | 4 + asm/text_mode.atk16 | 2 +- digital/atk16_mem.dig | 416 ++++++++++++++++++++++++-------------------------- digital/atk16_tpu.dig | 26 +++- src/dig_install.py | 60 ++++++++ 5 files changed, 285 insertions(+), 223 deletions(-) create mode 100644 src/dig_install.py diff --git a/Makefile b/Makefile index 1f084a0..f06557f 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,10 @@ gen-charmem: convert-ttf: $(py) src/convert_ttf.py $(in) $(out) +# make dig-install bin=out/program.bin dig=digital/atk16_mem.dig label=MEM_ROM +dig-install: + $(py) src/dig_install.py $(bin) $(dig) $(label) + # make test test: $(py) src/test_alu.py digital/atk16_alu.dig diff --git a/asm/text_mode.atk16 b/asm/text_mode.atk16 index 335f71c..d7cdcec 100644 --- a/asm/text_mode.atk16 +++ b/asm/text_mode.atk16 @@ -11,7 +11,7 @@ cursor_to_line RC 1 put_string RC RB " HELLO CORECAMP" new_line RC - put_string RC RB " BY JAN" + put_string RC RB " »»»»»»» BY JAN" new_line RC new_line RC put_string RC RB " > " diff --git a/digital/atk16_mem.dig b/digital/atk16_mem.dig index 555abb6..e8efe27 100644 --- a/digital/atk16_mem.dig +++ b/digital/atk16_mem.dig @@ -1,11 +1,10 @@ - 2 romContent - + @@ -35,51 +34,40 @@ Data - 4014,2a00,6019,13*8000,7e,1a,1a,1a,8000,e000,e001,e002,e800,f800 -,4855,f000,4017,2000,4200,3008,6000,6001,f840,4422,2480,4220,3088 -,1488,4248,3088,1488,4245,3088,1488,424c,3088,1488,424c,3088,1488 -,424f,3088,1488,4220,3088,1488,4243,3088,1488,424f,3088,1488,4252 -,3088,1488,4245,3088,1488,4243,3088,1488,4241,3088,1488,424d,3088 -,1488,4250,3088,1488,14b5,1488,14b7,4220,3088,1488,4242,3088,1488 -,4259,3088,1488,4220,3088,1488,424a,3088,1488,4241,3088,1488,424e -,3088,1488,14b5,1488,14b7,14b5,1488,14b7,4220,3088,1488,423e,3088 -,1488,4220,3088,1488,4017,2000,4201,3008,61ff,3140,1b48,3148,1b48 -,4016,2000,2000,4215,2240,3080,1488,1029,1029,8401,600c,14b5,1488 -,14b7,4220,3088,1488,423e,3088,1488,4220,3088,1488,3148,1b48,3140 -,1b48,e000 + 4014,2a00,6019,8000,8000,8000,8000,8000,8000,8000,8000,8000,8000,8000,8000,8000,0096,001a,001a,001a,8000,e000,e001,e002,e800,f800,4855,f000,4017,2000,4200,3008,6000,6001,f840,4422,2480,4220,3088,1488,4248,3088,1488,4245,3088,1488,424c,3088,1488,424c,3088,1488,424f,3088,1488,4220,3088,1488,4243,3088,1488,424f,3088,1488,4252,3088,1488,4245,3088,1488,4243,3088,1488,4241,3088,1488,424d,3088,1488,4250,3088,1488,14b5,1488,14b7,4220,3088,1488,42bb,3088,1488,42bb,3088,1488,42bb,3088,1488,42bb,3088,1488,42bb,3088,1488,42bb,3088,1488,42bb,3088,1488,4220,3088,1488,4242,3088,1488,4259,3088,1488,4220,3088,1488,424a,3088,1488,4241,3088,1488,424e,3088,1488,14b5,1488,14b7,14b5,1488,14b7,4220,3088,1488,423e,3088,1488,4220,3088,1488,4017,2000,4201,3008,61ff,3140,1b48,3148,1b48,4016,2000,2000,4215,2240,3080,1488,1029,1029,8401,600c,14b5,1488,14b7,4220,3088,1488,423e,3088,1488,4220,3088,1488,3148,1b48,3140,1b48,e000 - + Ground rotation - + - + VDD rotation - + - + VDD rotation - + - + In @@ -97,7 +85,7 @@ 16 - + Splitter @@ -111,12 +99,12 @@ 13,1,1,1 - + atk16_mem_mux.dig - - + + Splitter @@ -130,7 +118,7 @@ 15 - + Splitter @@ -144,7 +132,7 @@ 2 - + Demultiplexer @@ -158,7 +146,7 @@ 15 - + Probe @@ -168,7 +156,7 @@ ROM_OUT - + Driver @@ -182,7 +170,7 @@ true - + Demultiplexer @@ -196,7 +184,7 @@ true - + Tunnel @@ -206,7 +194,7 @@ RAM_IE - + In @@ -228,7 +216,7 @@ true - + Tunnel @@ -238,7 +226,7 @@ CLK - + RAMDualPort @@ -256,59 +244,59 @@ 16 - + VDD rotation - + - + Tunnel rotation - + NetName CLK - + Tunnel rotation - + NetName RAM_IE - + Tunnel rotation - + NetName DBUS - + Probe @@ -318,7 +306,7 @@ RAM_OUT - + Driver @@ -328,7 +316,7 @@ 16 - + In @@ -342,7 +330,7 @@ CLK - + Out @@ -356,7 +344,7 @@ MMIO_IE - + Out @@ -370,7 +358,7 @@ MMIO_OE - + Tunnel @@ -380,7 +368,7 @@ MMIO_S - + Testcase @@ -406,7 +394,7 @@ C 0x8000 0 1 Z 0xAA - + In @@ -420,7 +408,7 @@ C 0x8000 0 1 Z 0xAA MEM_IE - + In @@ -434,17 +422,17 @@ C 0x8000 0 1 Z 0xAA MEM_OE - + And rotation - + - + Tunnel @@ -454,7 +442,7 @@ C 0x8000 0 1 Z 0xAA RAM_OE - + Tunnel @@ -464,7 +452,7 @@ C 0x8000 0 1 Z 0xAA MEM_OE - + Tunnel @@ -474,7 +462,7 @@ C 0x8000 0 1 Z 0xAA MEM_OE - + Tunnel @@ -484,17 +472,17 @@ C 0x8000 0 1 Z 0xAA DBUS - + And rotation - + - + Tunnel @@ -504,7 +492,7 @@ C 0x8000 0 1 Z 0xAA ROM_OE - + Tunnel @@ -514,7 +502,7 @@ C 0x8000 0 1 Z 0xAA MEM_OE - + Tunnel @@ -524,7 +512,7 @@ C 0x8000 0 1 Z 0xAA DBUS - + Tunnel @@ -534,7 +522,7 @@ C 0x8000 0 1 Z 0xAA DBUS - + Decoder @@ -548,7 +536,7 @@ C 0x8000 0 1 Z 0xAA true - + Tunnel @@ -558,7 +546,7 @@ C 0x8000 0 1 Z 0xAA ROM_OE - + Tunnel @@ -568,7 +556,7 @@ C 0x8000 0 1 Z 0xAA RAM_OE - + Tunnel @@ -578,7 +566,7 @@ C 0x8000 0 1 Z 0xAA MMIO_OE - + Tunnel @@ -588,73 +576,73 @@ C 0x8000 0 1 Z 0xAA MMIO_IE - + And - - + + Tunnel rotation - + NetName MEM_OE - + Tunnel rotation - + NetName MMIO_OE - + And - - + + Tunnel rotation - + NetName MEM_IE - + Tunnel rotation - + NetName MMIO_IE - + Out @@ -672,21 +660,21 @@ C 0x8000 0 1 Z 0xAA 13 - + Tunnel rotation - + NetName MMIO_S - + Tunnel @@ -696,266 +684,266 @@ C 0x8000 0 1 Z 0xAA MEM_IE - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + \ No newline at end of file diff --git a/digital/atk16_tpu.dig b/digital/atk16_tpu.dig index bb623df..f6b6398 100644 --- a/digital/atk16_tpu.dig +++ b/digital/atk16_tpu.dig @@ -844,6 +844,20 @@ + + VDD + + + rotation + + + + Bits + 2 + + + + @@ -894,14 +908,14 @@ - - - - + + + + @@ -1118,10 +1132,6 @@ - - - - diff --git a/src/dig_install.py b/src/dig_install.py new file mode 100644 index 0000000..c32229b --- /dev/null +++ b/src/dig_install.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python3 +# Install a generated .bin file into a memory chip in a .dig circuit file + +import sys +from typing import cast +import xml.etree.ElementTree as ET + +if len(sys.argv) != 4: + print("usage: dig_install.py ") + sys.exit(1) + +infile = sys.argv[1] +circuitfile = sys.argv[2] +chip_label = sys.argv[3] + +with open(infile, "rb") as f: + program_bytes = f.read() + +i = 0 +program_words: list[str] = [] +while i < len(program_bytes): + hi_byte = program_bytes[i] + lo_byte = program_bytes[i + 1] + word = f"{hi_byte:>02x}{lo_byte:>02x}" + #print(word) + program_words.append(word) + i += 2 + +program_data = ",".join(program_words) +print("program_data:", program_data) + +tree = ET.parse(circuitfile) +root = tree.getroot() + +# Iterate through each 'visualElement' element +def find_data_element(root: ET.Element) -> ET.Element: + is_correct_visual_element = False + for visual_element in root.findall('.//visualElement'): + element_attributes = visual_element.find('elementAttributes') + if element_attributes is None: continue + + entries = list(element_attributes) + for entry in entries: + strings = entry.findall("string") + is_label_entry = len(strings) == 2 and strings[0].text == "Label" and strings[1].text == chip_label + if is_label_entry and not is_correct_visual_element: + is_correct_visual_element = True + continue + + is_data_entry = len(strings) == 1 and strings[0].text == "Data" + if is_data_entry and is_correct_visual_element: + data_element = entry.findall("data")[0] + return data_element + + raise Exception(f"No data entry matching label {chip_label} found in tree") + +data_element = find_data_element(root) +data_element.text = program_data + +tree.write(circuitfile) \ No newline at end of file -- cgit v1.3