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:
1 parent
13373244e8
commit
743071cff3
19 files changed
+3544
-1306
No files matched your search
@@ -24,6 +24,11 @@
|
||||
// 65 out breakpoint 0 low 66 high 68 out breakpoint 1 low 69 high
|
||||
// 67 out bit 0 = breakpoint 0 on, bit 1 = breakpoint 1 on
|
||||
// 70-78, 80-87 sprites (see sprites.v)
|
||||
// 88 in keys held: bit 0 up (W, cursor or keypad 8), 1 down (S, 2), 2 left
|
||||
// (A, 4), 3 right (D, 6), 4 fire (Space or Ctrl), 5 Enter, 6 Shift,
|
||||
// 7 Esc
|
||||
// 89 out pick a scan code (set 2; add 128 for an E0 code)
|
||||
// in 1 if that key is held, else 0
|
||||
//
|
||||
// The monitor: an NMI (Pause key, port 61, a breakpoint or the step counter)
|
||||
// pushes the program's PC and jumps to 0066h, where both BASIC and the monitor
|
||||
@@ -66,6 +71,8 @@ module z80_system #(
|
||||
input sp_on,
|
||||
output [3:0] sp_pix,
|
||||
input sp_ftick,
|
||||
// keys held down (one bit per scan code, from the keyboard's clock)
|
||||
input [255:0] keys,
|
||||
// configuration flash (SPI)
|
||||
output fl_cs_n,
|
||||
output fl_sck,
|
||||
@@ -164,6 +171,22 @@ module z80_system #(
|
||||
.rd_on(sp_on), .pix(sp_pix), .gfx_pix(gfx_vpix), .ftick(sp_ftick)
|
||||
);
|
||||
|
||||
// ---------------------------------------------------------- held keys
|
||||
// The keyboard's clock writes these; a bit that changes while it is read
|
||||
// just reads as before or after.
|
||||
reg [7:0] key_sel = 8'd0;
|
||||
always @(posedge clk) if (io_wr && io_addr[7:0] == 8'h89) key_sel <= io_wd;
|
||||
wire [7:0] joy = {
|
||||
keys[8'h76], // Esc
|
||||
keys[8'h12] | keys[8'h59], // Shift
|
||||
keys[8'h5A] | keys[8'hDA], // Enter
|
||||
keys[8'h29] | keys[8'h14] | keys[8'h94], // Space, Ctrl
|
||||
keys[8'h23] | keys[8'hF4] | keys[8'h74], // D, right, keypad 6
|
||||
keys[8'h1C] | keys[8'hEB] | keys[8'h6B], // A, left, keypad 4
|
||||
keys[8'h1B] | keys[8'hF2] | keys[8'h72], // S, down, keypad 2
|
||||
keys[8'h1D] | keys[8'hF5] | keys[8'h75] // W, up, keypad 8
|
||||
};
|
||||
|
||||
// --------------------------------------------------------------- flash
|
||||
wire [7:0] fl_ctl_q, fl_dat_q;
|
||||
flash_spi flash (
|
||||
@@ -256,6 +279,8 @@ module z80_system #(
|
||||
8'h64: io_din = dbg_q;
|
||||
8'h78, 8'h80, 8'h81, 8'h82, 8'h83, 8'h84, 8'h85, 8'h86, 8'h87:
|
||||
io_din = spr_q;
|
||||
8'h88: io_din = joy;
|
||||
8'h89: io_din = {7'd0, keys[key_sel]};
|
||||
default: io_din = 8'hFF;
|
||||
endcase
|
||||
|
||||
|
||||
Reference in new issue
Block a user