The Iron Keep: a top-down escape game, held-key ports, monitor HEX loader

games/keep: an original game in C for the Z-80 using the sprites - twelve
rooms, guards that patrol, see along rows and columns and shoot, keys and
locked doors, gold, ammunition and a crown to steal. gen.py holds the art
and castle map and checks reachability; test-keep.py runs it in z80emu on
a model of the board's ports, takes screenshots and has a bot play it
through. keep.bas loads KEEPGAME at 8600h and CALLs it.

Ports 88h/89h read keys held down (ps2_keystate), the monitor writes
Intel HEX records typed at its prompt, and tools/send-hex.py sends a
whole file and saves it as a memory file. Testbench covers both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
brad ArantandClaude Opus 5.5 committed 2026-11-29 09:21:02 -08:00
1 parent 13373244e8
commit 743071cff3
19 files changed
+3544 -1306

No files matched your search

+31 -2
View File
@@ -232,6 +232,27 @@ sprite-graphics collision flags. BASIC moves them with `OUT` (ports 112–119)
and reads the frame counter and collisions with `INP` (120, 128–135); see the
manual. `basic/examples/sprites.bas` is a small example.
**Held keys:** port 88h reads the arrows/WASD, fire, Enter, Shift and Esc as
held-down bits, and 89h any key by scan code (`rtl/ps2_keyboard.v`,
`ps2_keystate`), so games don't depend on typematic repeat.
**The Iron Keep** (`games/keep/`) is a top-down escape game in C for the Z-80
using all of this: twelve rooms, guards that patrol, see along rows and
columns and shoot, keys and locked doors, gold, ammunition and a crown to
steal. `RUN "KEEP"` on the board. To build and install it:
```bash
games/keep/build.sh # -> keep.ihx (SDCC)
tools/send-hex.py games/keep/keep.ihx --save KEEPGAME --baud 3000000 # through the monitor
tools/send-bas.py games/keep/keep.bas --baud 3000000 # the loader, then SAVE "KEEP"
python3 games/keep/test-keep.py --play --shots /tmp/keep # emulator test (pyte, Pillow)
```
`gen.py` holds the art and the castle map and checks that every room joins up
and every key, door and the crown can be reached. `test-keep.py` runs the game
in `tools/z80emu.py` on a model of the board's ports, takes screenshots, and
lets a bot play it through.
**Manual:** [docs/basic-manual.md](docs/basic-manual.md) describes every
statement and function, with examples, error messages and limits.
`docs/build-manual.sh` rebuilds the PDF from it.
@@ -300,8 +321,9 @@ Commands: Enter steps one instruction, `S n` steps *n*, `O` steps over a call,
`SAVE "NAME" start end`, `LOAD "NAME" [addr]` and `DIR` move memory to and
from files in flash (the same files as BASIC's `BSAVE`/`BLOAD`). `ASM "NAME"`
assembles Z-80 source (typed into BASIC as numbered lines and saved) into
memory, and `A addr` assembles a line at a time. The manual's
section 10 has the details.
memory, and `A addr` assembles a line at a time. A line starting with `:` is
an Intel HEX record, written into memory (`tools/send-hex.py` sends whole
files that way). The manual's section 10 has the details.
How it works:
- **Entry:** the NMI pushes PC and jumps to 0066h. Both BASIC's ROM and the
@@ -404,6 +426,8 @@ stack fill the top half.
| 78h | frame counter (+1 each vertical blank) | |
| 80h–83h | sprites that touched another sprite last frame (bit per sprite) | |
| 84h–87h | sprites that touched a graphics pixel last frame | |
| 88h | keys held: bit 0 up (W, cursor, keypad 8), 1 down, 2 left, 3 right, 4 fire (Space, Ctrl), 5 Enter, 6 Shift, 7 Esc | |
| 89h | 1 if the picked key is held | pick a key by scan code (set 2, +80h for E0 codes) |
BASIC is C (`basic/basic.c`) compiled with SDCC (`sudo apt install sdcc`):
@@ -481,6 +505,9 @@ older boards, Macronix `mx25l3273f` on newer ones).
- It defines sprite shapes and places overlapping, flipped and edge-clipped
sprites from BASIC, then checks the pixels on screen, the collision ports and
that `CLS` turns the sprites off.
- It holds Ctrl and right Shift on the PS/2 line and reads them back on the
held-key ports, then releases them.
- In the monitor, it sends an Intel HEX record and checks memory.
- Against a model flash (`sim/spiflash_model.v`) it sets the date, saves,
loads, runs and lists a program (checking the date in `DIR`), tries to erase
address 0 and checks the model saw no write below 240000h, then writes a data
@@ -505,6 +532,8 @@ which Vivado needs on newer distros.
| `monitor/` | Machine-code monitor (C and start-up code), its build script and disassembler test |
| `basic/tramp.s` | The NMI entry and exit bytes shared by BASIC and the monitor |
| `tools/send-bas.py`, `tools/get-bas.py` | Send a BASIC program to the board / copy one back, run commands |
| `tools/send-hex.py` | Load an Intel HEX file through the monitor and save it as a memory file |
| `games/keep/` | The Iron Keep: game (C), art and map generator, loader, emulator test |
| `basic/` | BASIC interpreter (C), start-up code, build script, `basic.mem` |
| `tools/z80emu.py`, `tools/cputest.py`, `scripts/cpusim.sh` | CPU test bench: reference emulator, random tests |
| `rtl/term_ctrl.v` | VT220 engine (parser, modes, attributes, copy/fill engine, smooth scroll) |