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

+39 -1
View File
@@ -392,7 +392,7 @@ static u16 bp; /* the user's breakpoint */
static u8 bp_set;
static u8 go_after; /* stepping off a breakpoint, then G */
static u16 steps; /* more single steps to do */
static char cmd[40];
static char cmd[80];
static u8 msg_err;
static const char *msg;
static u8 why_in; /* why the monitor was entered */
@@ -997,6 +997,43 @@ static u8 set_reg(void)
return 1;
}
/* :LLAAAATT data CC - an Intel HEX record, as tools/send-hex.py sends them.
Data records are written to memory; the end record reports the range. */
static u16 hx_lo = 0xFFFF, hx_hi;
static char hx_msg[24];
static u8 hexv(char c) { return c <= '9' ? c - '0' : c - 'A' + 10; }
static u8 hex2(const char *s) { return (hexv(s[0]) << 4) | hexv(s[1]); }
static void hex_record(void)
{
const char *p = cp + 1;
u8 n, t, sum, i, len = 0;
u16 a;
while (is_hex(p[len])) len++;
if (p[len] || len < 10 || (len & 1) || len != 10 + 2 * hex2(p)) {
msg = "BAD HEX RECORD"; msg_err = 1; return;
}
n = hex2(p);
for (sum = 0, i = 0; i < n + 5; i++) sum += hex2(p + 2 * i);
if (sum) { msg = "HEX CHECKSUM ERROR"; msg_err = 1; return; }
a = (u16)hex2(p + 2) << 8 | hex2(p + 4);
t = hex2(p + 6);
if (t == 1) {
if (hx_lo > hx_hi) { msg = "NO HEX DATA"; msg_err = 1; return; }
lp = line; s_str("HEX LOADED "); s_h4(hx_lo); s_ch('-'); s_h4(hx_hi); *lp = 0;
s_copy(hx_msg, line);
msg = hx_msg;
mem_a = hx_lo;
hx_lo = 0xFFFF; hx_hi = 0;
draw_mem();
return;
}
if (t != 0 || !n) return;
for (i = 0; i < n; i++)
if (!wr(a + i, hex2(p + 8 + 2 * i))) { msg = "ROM: NOT CHANGED"; msg_err = 1; return; }
if (a < hx_lo) hx_lo = a;
if (a + n - 1 > hx_hi) hx_hi = a + n - 1;
}
/* Returns 1 when the monitor should be left (u.exit set). */
static u8 command(void)
{
@@ -1005,6 +1042,7 @@ static u8 command(void)
cp = cmd;
skip_sp();
msg = 0; msg_err = 0;
if (*cp == ':') { hex_record(); return 0; }
if (!memcmp(cp, "ASM", 3)) {
cp += 3;
if (setjmp(fs_jmp)) { msg = fs_msg; msg_err = 1; return 0; }