Free games for graphing calculators: NumWorks, TI-Nspire CX, Casio fx-CG50 and soon TI-84 Plus CE. Balatro, Celeste, Hollow Knight, Minecraft and more.
C calculatorcalculator-gamescasiochesscrossy-roaddrive-madfx-cg50gamesgeometry-dashgraphing-calculatorndlessnumworksnumworks-appsnumworks-calculatornumworks-gamenumworks-gamestetristi-84-plus-ceti-nspire
#!/usr/bin/env python3
"""src/rom.h: the data tables of Donkey Kong's program ROM (boards, Kong's poses, paths, timings),
read from tcdev's annotated listing of it (dk.txt, "Donkey Kong Disassembly v0.1"), which shows every
byte. Only data is taken; the game's code is ported by hand in sim.c. No graphics ROM is read.
python3 -I tools/rom.py path/to/dk.txt src/rom.h
"""
import re
import sys
# (first address, end address): each becomes rom_XXXX[], read in sim.c with ROM(address)
RANGES = [
(0x0D17, 0x0D27), # the rivets' places in video RAM
(0x101B, 0x101F), # a new barrel
(0x1121, 0x1131), # the elevator shafts' motors
(0x117E, 0x1186), # 100m: the squares beside Kong
(0x11A2, 0x11A6), # a new spring
(0x3529, 0x3565), # points, 3 BCD bytes each
(0x364B, 0x3806), # the messages (GAME OVER, HOW HIGH CAN YOU GET?)
(0x380D, 0x3E70), # boards, Kong's poses and moves, paths, levels, start values
]
def number(tok):
tok = tok.strip()
return int(tok[:-1], 16) if tok[-1] in "hH" else int(tok)
def rebuild(path):
rom, known = bytearray(0x4000), bytearray(0x4000)
last, ptr = None, 0
for line in open(path, encoding="latin-1"):
m = re.match(r"^(?:ROM:)?([0-9A-F]{4}) (.{0,17})(.*)$", line.rstrip("\n"))
if not m:
continue
addr, hexcol, code = int(m.group(1), 16), m.group(2), m.group(3).split(";", 1)[0]
d = re.search(r"\b(db|dw)\s+(.+)$", code)
if d:
if addr != last:
ptr = addr
last = addr
for op in re.findall(r"'[^']*'|[^,]+", d.group(2)):
op = op.strip()
if not op:
continue
if op.startswith("'"):
vals = [ord(c) for c in op[1:-1]]
else:
try:
v = number(op)
vals = [v & 255] if d.group(1) == "db" else [v & 255, v >> 8]
except ValueError: # a label: its bytes are in the listing's byte column
vals = [int(b, 16) for b in re.findall(r"\b([0-9A-F]{2})\b", hexcol)[:2]]
for v in vals:
if ptr < 0x4000:
rom[ptr], known[ptr] = v, 1
ptr += 1
continue
b = re.match(r"((?:[0-9A-F]{2} ){1,4})", hexcol)
if b and "+" not in hexcol and code.strip():
for i, v in enumerate(b.group(1).split()):
rom[addr + i], known[addr + i] = int(v, 16), 1
last = None
return rom, known
def main():
rom, known = rebuild(sys.argv[1])
out = ["/* Generated by tools/rom.py from tcdev's listing of Donkey Kong's program ROM (data tables only).",
" * ROM(address) reads them by their address in the arcade's ROM, as sim.c's comments name them. */",
"#ifndef DK_ROM_H", "#define DK_ROM_H", "#include <stdint.h>"]
for a, b in RANGES:
if not all(known[a:b]):
sys.exit(f"bytes missing in {a:04X}-{b:04X}")
out.append(f"static const uint8_t rom_{a:04X}[{b - a}] = {{")
for i in range(a, b, 16):
out.append(" " + ",".join(f"0x{v:02X}" for v in rom[i:min(b, i + 16)]) + ",")
out.append("};")
out.append("static inline uint8_t rom_byte(unsigned a) {")
for a, b in RANGES:
out.append(f" if (a - 0x{a:04X}u < {b - a}u) return rom_{a:04X}[a - 0x{a:04X}u];")
out.append(" return 0;")
out.append("}")
out.append("#define ROM(a) rom_byte((uint16_t)(a))")
out.append("#endif")
open(sys.argv[2], "w").write("\n".join(out) + "\n")
if __name__ == "__main__":
main()