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
@@ -8,3 +8,4 @@ basic/out/
|
|||||||
sim/cpu/
|
sim/cpu/
|
||||||
__pycache__/
|
__pycache__/
|
||||||
monitor/out/
|
monitor/out/
|
||||||
|
games/keep/out/
|
||||||
@@ -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
|
and reads the frame counter and collisions with `INP` (120, 128–135); see the
|
||||||
manual. `basic/examples/sprites.bas` is a small example.
|
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
|
**Manual:** [docs/basic-manual.md](docs/basic-manual.md) describes every
|
||||||
statement and function, with examples, error messages and limits.
|
statement and function, with examples, error messages and limits.
|
||||||
`docs/build-manual.sh` rebuilds the PDF from it.
|
`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
|
`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"`
|
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
|
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
|
memory, and `A addr` assembles a line at a time. A line starting with `:` is
|
||||||
section 10 has the details.
|
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:
|
How it works:
|
||||||
- **Entry:** the NMI pushes PC and jumps to 0066h. Both BASIC's ROM and the
|
- **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) | |
|
| 78h | frame counter (+1 each vertical blank) | |
|
||||||
| 80h–83h | sprites that touched another sprite last frame (bit per sprite) | |
|
| 80h–83h | sprites that touched another sprite last frame (bit per sprite) | |
|
||||||
| 84h–87h | sprites that touched a graphics pixel last frame | |
|
| 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`):
|
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
|
- It defines sprite shapes and places overlapping, flipped and edge-clipped
|
||||||
sprites from BASIC, then checks the pixels on screen, the collision ports and
|
sprites from BASIC, then checks the pixels on screen, the collision ports and
|
||||||
that `CLS` turns the sprites off.
|
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,
|
- 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
|
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
|
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 |
|
| `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 |
|
| `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-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` |
|
| `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 |
|
| `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) |
|
| `rtl/term_ctrl.v` | VT220 engine (parser, modes, attributes, copy/fill engine, smooth scroll) |
|
||||||
|
|||||||
+74
-1
@@ -548,7 +548,7 @@ for full speed.
|
|||||||
| Addresses | Contents |
|
| Addresses | Contents |
|
||||||
|---|---|
|
|---|---|
|
||||||
| 0000–7FFF | BASIC itself (writes here are ignored) |
|
| 0000–7FFF | BASIC itself (writes here are ignored) |
|
||||||
| 8000–EFFF | BASIC's variables, your program and arrays, file buffers |
|
| 8000–EFFF | BASIC's variables, your program and arrays, file buffers (your program starts at 8482h) |
|
||||||
| F000–F3F7 | Free for your machine code (1016 bytes); BASIC never uses it |
|
| F000–F3F7 | Free for your machine code (1016 bytes); BASIC never uses it |
|
||||||
| F3F8–F3FF | The clock set by `DATE` |
|
| F3F8–F3FF | The clock set by `DATE` |
|
||||||
| F400–FFFF | The Z-80 stack |
|
| F400–FFFF | The Z-80 stack |
|
||||||
@@ -575,6 +575,8 @@ kept free for it.
|
|||||||
| 97 | — | enter the monitor (what `MONITOR` does) |
|
| 97 | — | enter the monitor (what `MONITOR` does) |
|
||||||
| 98–105 | memory read and breakpoint registers (used by the monitor) | |
|
| 98–105 | memory read and breakpoint registers (used by the monitor) | |
|
||||||
| 112–120, 128–135 | sprites (section 7) | sprites (section 7) |
|
| 112–120, 128–135 | sprites (section 7) | sprites (section 7) |
|
||||||
|
| 136 | keys held down, for games (below) | — |
|
||||||
|
| 137 | 1 if the key picked with `OUT 137` is held down, else 0 | pick a key by its scan code |
|
||||||
|
|
||||||
```
|
```
|
||||||
10 FOR I = 0 TO 255
|
10 FOR I = 0 TO 255
|
||||||
@@ -590,6 +592,39 @@ A key check that doesn't wait (the key is used up):
|
|||||||
100 IF INP(0) AND 1 THEN K = INP(1): PRINT "YOU PRESSED "; CHR$(K)
|
100 IF INP(0) AND 1 THEN K = INP(1): PRINT "YOU PRESSED "; CHR$(K)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Keys held down
|
||||||
|
|
||||||
|
Typed characters can't tell a game that a key is being *held*: they arrive
|
||||||
|
once, then repeat only after a pause. Ports 136 and 137 read the keyboard
|
||||||
|
directly instead, for as long as a key is down.
|
||||||
|
|
||||||
|
`INP(136)` adds up these values for the keys held now:
|
||||||
|
|
||||||
|
| Value | Keys |
|
||||||
|
|---|---|
|
||||||
|
| 1 | up: W, cursor up or keypad 8 |
|
||||||
|
| 2 | down: S, cursor down or keypad 2 |
|
||||||
|
| 4 | left: A, cursor left or keypad 4 |
|
||||||
|
| 8 | right: D, cursor right or keypad 6 |
|
||||||
|
| 16 | fire: Space or either Ctrl |
|
||||||
|
| 32 | Enter |
|
||||||
|
| 64 | either Shift |
|
||||||
|
| 128 | Esc |
|
||||||
|
|
||||||
|
```
|
||||||
|
10 J = INP(136)
|
||||||
|
20 IF J AND 4 THEN X = X - 1
|
||||||
|
30 IF J AND 8 THEN X = X + 1
|
||||||
|
40 IF J AND 16 THEN PRINT "BANG"
|
||||||
|
```
|
||||||
|
|
||||||
|
For any other key, `OUT 137` its PS/2 scan code (set 2; add 128 for keys whose
|
||||||
|
code starts with E0), then `INP(137)` is 1 while it is held: `OUT 137, 77:
|
||||||
|
IF INP(137) THEN …` checks P. The keys still type characters as well, so a
|
||||||
|
game should throw those away now and then with `IF INP(0) AND 1 THEN K =
|
||||||
|
INP(1)` in a loop. Held keys only work with the board's own keyboard, not with
|
||||||
|
characters sent from the PC.
|
||||||
|
|
||||||
### Speed
|
### Speed
|
||||||
|
|
||||||
The Z-80 runs at 90 MHz and needs about 2.7 clocks per instruction, roughly 50
|
The Z-80 runs at 90 MHz and needs about 2.7 clocks per instruction, roughly 50
|
||||||
@@ -669,6 +704,7 @@ Type a command on the bottom line and press Enter. Numbers are in hex.
|
|||||||
| Up / Down | Scroll the disassembly by one instruction |
|
| Up / Down | Scroll the disassembly by one instruction |
|
||||||
| Page Up / Page Down | Scroll the memory window |
|
| Page Up / Page Down | Scroll the memory window |
|
||||||
| `?` | A short reminder of the commands |
|
| `?` | A short reminder of the commands |
|
||||||
|
| `:` *record* | An Intel HEX record, written into memory (`tools/send-hex.py` sends whole files this way; see section 12) |
|
||||||
|
|
||||||
- **Stepping** runs exactly one instruction (a whole `LDIR`, or a `HALT` and
|
- **Stepping** runs exactly one instruction (a whole `LDIR`, or a `HALT` and
|
||||||
what wakes it). The hardware counts instructions, so it works on code in ROM
|
what wakes it). The hardware counts instructions, so it works on code in ROM
|
||||||
@@ -957,6 +993,18 @@ tools/get-bas.py --baud 9600 --cmd 'DIR' --cmd 'LOAD "SPIRO"' --cmd 'LIST'
|
|||||||
seconds, 30 by default). Program lines typed this way get no `READY`, so they
|
seconds, 30 by default). Program lines typed this way get no `READY`, so they
|
||||||
take the full timeout each; use `send-bas.py` for those.
|
take the full timeout each; use `send-bas.py` for those.
|
||||||
|
|
||||||
|
**Sending machine code compiled on the PC:**
|
||||||
|
|
||||||
|
```
|
||||||
|
tools/send-hex.py prog.ihx --save PROG --baud 3000000
|
||||||
|
```
|
||||||
|
|
||||||
|
This enters the monitor, sends the Intel HEX file (as SDCC and most
|
||||||
|
assemblers write it) a record at a time, saves the bytes as the memory file
|
||||||
|
`PROG`, and goes back to BASIC. `BLOAD "PROG"` then loads it where it was
|
||||||
|
compiled for. It must be at 8000h or above. That's how The Iron Keep
|
||||||
|
(section 14) gets onto the board.
|
||||||
|
|
||||||
When you're done, flip SW14 back down, and bring the getty back with
|
When you're done, flip SW14 back down, and bring the getty back with
|
||||||
`sudo systemctl unmask --runtime serial-getty@ttyUSB1` (a reboot does it too).
|
`sudo systemctl unmask --runtime serial-getty@ttyUSB1` (a reboot does it too).
|
||||||
Don't do that with SW14 up.
|
Don't do that with SW14 up.
|
||||||
@@ -1038,6 +1086,31 @@ An error stops the program and reports the line, for example
|
|||||||
bars, circles, a burst of lines, sine and cosine curves, random rectangles, a
|
bars, circles, a burst of lines, sine and cosine curves, random rectangles, a
|
||||||
bouncing ball and a Mandelbrot set, then prints how long it all took.
|
bouncing ball and a Mandelbrot set, then prints how long it all took.
|
||||||
|
|
||||||
|
### The Iron Keep
|
||||||
|
|
||||||
|
A game in machine code. You are a prisoner in a castle of twelve rooms:
|
||||||
|
steal the king's crown from the throne room and escape down the stairs.
|
||||||
|
Guards patrol, and shoot when they can see you along a row or column of the
|
||||||
|
castle; some come after you. Keys open locked doors, chests hold gold, crates
|
||||||
|
hold ammunition. You have three lives.
|
||||||
|
|
||||||
|
```
|
||||||
|
RUN "KEEP"
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Moving:** the cursor keys or W A S D. **Shooting:** Space or Ctrl, in the
|
||||||
|
direction you face.
|
||||||
|
- **P** pauses; **Esc** gives up the game. Esc on the title or the final
|
||||||
|
screen goes back to BASIC.
|
||||||
|
- **Score:** 100 a chest, 50 a guard, 1,000 for the crown, and 500 plus 200 a
|
||||||
|
remaining life for getting out.
|
||||||
|
|
||||||
|
`KEEP` is a four-line BASIC program that loads the game, the memory file
|
||||||
|
`KEEPGAME`, at 8600h, just past itself, and `CALL`s it. The game overwrites
|
||||||
|
the rest of BASIC's program area while it runs, so save your own program
|
||||||
|
first. It is written in C (`games/keep/` on the PC, with its build and
|
||||||
|
install steps).
|
||||||
|
|
||||||
## 15. Limits at a glance
|
## 15. Limits at a glance
|
||||||
|
|
||||||
| Item | Limit |
|
| Item | Limit |
|
||||||
|
|||||||
Binary file not shown.
@@ -0,0 +1,25 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Build The Iron Keep: keep.ihx (Intel HEX for tools/send-hex.py) and keep.bin.
|
||||||
|
# The program runs at 8600h with its variables at D000h, inside BASIC's
|
||||||
|
# program area (8482h-D6D5h) and clear of the KEEP loader program at its start.
|
||||||
|
set -e
|
||||||
|
cd "$(dirname "$0")"
|
||||||
|
mkdir -p out
|
||||||
|
python3 gen.py out/data.h
|
||||||
|
sdasz80 -plosgff out/crt0.rel crt0.s
|
||||||
|
sdcc -mz80 --opt-code-size --max-allocs-per-node 20000 --std-sdcc11 -Iout -c -o out/keep.rel keep.c
|
||||||
|
sdcc -mz80 --no-std-crt0 --code-loc 0x8620 --data-loc 0xD000 -o out/keep.ihx out/crt0.rel out/keep.rel
|
||||||
|
python3 - <<'EOF'
|
||||||
|
import re
|
||||||
|
m = open("out/keep.map").read()
|
||||||
|
def sym(n):
|
||||||
|
return int(re.search(r"([0-9A-F]{8})\s+" + n + r"\b", m).group(1), 16)
|
||||||
|
code_end = sym("s__CODE") + sym("l__CODE")
|
||||||
|
data_end = sym("s__DATA") + sym("l__DATA")
|
||||||
|
init = sym("l__INITIALIZED") + sym("l__INITIALIZER")
|
||||||
|
print("code 8600-%04X (%d bytes), variables D000-%04X" % (code_end - 1, code_end - 0x8600, data_end - 1))
|
||||||
|
assert code_end <= 0xD000, "code runs into the variables"
|
||||||
|
assert data_end <= 0xD6D6, "variables run past BASIC's program area"
|
||||||
|
assert init == 0, "initialised variables are not supported"
|
||||||
|
EOF
|
||||||
|
cp out/keep.ihx keep.ihx
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
; Start-up for a machine-code program that BASIC CALLs at 8600h: clear the
|
||||||
|
; variables, run main, and return to BASIC. The program has no initialised
|
||||||
|
; variables (gen.py's tables are const, so they stay in the code).
|
||||||
|
.module crt0
|
||||||
|
.globl _main
|
||||||
|
.globl s__DATA, l__DATA
|
||||||
|
|
||||||
|
.area _HEADER (ABS)
|
||||||
|
.org 0x8600
|
||||||
|
start:
|
||||||
|
ld hl, #s__DATA
|
||||||
|
ld bc, #l__DATA
|
||||||
|
ld a, b
|
||||||
|
or c
|
||||||
|
jr z, go
|
||||||
|
ld (hl), #0
|
||||||
|
dec bc
|
||||||
|
ld a, b
|
||||||
|
or c
|
||||||
|
jr z, go
|
||||||
|
ld d, h
|
||||||
|
ld e, l
|
||||||
|
inc de
|
||||||
|
ldir
|
||||||
|
go:
|
||||||
|
jp _main ; main's RET goes back to BASIC
|
||||||
|
|
||||||
|
.area _HOME
|
||||||
|
.area _CODE
|
||||||
|
.area _INITIALIZER
|
||||||
|
.area _GSINIT
|
||||||
|
.area _GSFINAL
|
||||||
|
.area _DATA
|
||||||
|
.area _INITIALIZED
|
||||||
|
.area _BSEG
|
||||||
|
.area _BSS
|
||||||
|
.area _HEAP
|
||||||
@@ -0,0 +1,454 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Turn the art and the castle map below into data.h for keep.c.
|
||||||
|
|
||||||
|
Shapes and tiles are 16 rows of 16 hex digits, one colour per pixel (the
|
||||||
|
terminal's 16 colours; 0 is see-through). The castle is 4 x 3 rooms; each room
|
||||||
|
is 18 x 12 tiles inside a wall border that gen.py adds, with gaps where two
|
||||||
|
rooms connect. Map characters:
|
||||||
|
|
||||||
|
# wall D locked door (a key opens it) X stairs out
|
||||||
|
. floor P where the player starts
|
||||||
|
K key G gold chest A ammunition C the crown
|
||||||
|
h guard patrolling left-right v guard patrolling up-down
|
||||||
|
c guard that chases you once it has seen you
|
||||||
|
|
||||||
|
The script checks that every room's objects fit the sprite budget and that
|
||||||
|
everything can be reached from the start, counting a key for every door.
|
||||||
|
"""
|
||||||
|
import sys
|
||||||
|
from collections import deque
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------ shapes
|
||||||
|
PLAYER_DOWN_TOP = [
|
||||||
|
"0000033333300000",
|
||||||
|
"0000333333330000",
|
||||||
|
"0000399999930000",
|
||||||
|
"0000390990930000",
|
||||||
|
"0000099999900000",
|
||||||
|
"0000000990000000",
|
||||||
|
]
|
||||||
|
PLAYER_UP_TOP = [
|
||||||
|
"0000033333300000",
|
||||||
|
"0000333333330000",
|
||||||
|
"0000333333330000",
|
||||||
|
"0000333333330000",
|
||||||
|
"0000033333300000",
|
||||||
|
"0000000990000000",
|
||||||
|
]
|
||||||
|
BODY_FRONT = [
|
||||||
|
"000CCCCCCCCCC000",
|
||||||
|
"00CCCCCCCCCCCC00",
|
||||||
|
"009CCCCCCCCCC900",
|
||||||
|
"009CCCCCCCCCC900",
|
||||||
|
"0000CCCCCCCC0000",
|
||||||
|
"0000444444440000",
|
||||||
|
]
|
||||||
|
LEGS_FRONT_A = [
|
||||||
|
"0000444004440000",
|
||||||
|
"0000444004440000",
|
||||||
|
"0000777007770000",
|
||||||
|
"0000000000000000",
|
||||||
|
]
|
||||||
|
LEGS_FRONT_B = [
|
||||||
|
"0000044004400000",
|
||||||
|
"0000044004400000",
|
||||||
|
"0000077007700000",
|
||||||
|
"0000000000000000",
|
||||||
|
]
|
||||||
|
PLAYER_SIDE_TOP = [
|
||||||
|
"0000033333300000",
|
||||||
|
"0000333333330000",
|
||||||
|
"0000333399990000",
|
||||||
|
"0000333990990000",
|
||||||
|
"0000033999990000",
|
||||||
|
"0000000999000000",
|
||||||
|
"00000CCCCCC00000",
|
||||||
|
"0000CCCCCCCC0000",
|
||||||
|
"0000CCCCC9990000",
|
||||||
|
"0000CCCCCC000000",
|
||||||
|
"00000CCCCC000000",
|
||||||
|
"0000044444400000",
|
||||||
|
]
|
||||||
|
LEGS_SIDE_A = [
|
||||||
|
"0000044004400000",
|
||||||
|
"0000444000440000",
|
||||||
|
"0000777000770000",
|
||||||
|
"0000000000000000",
|
||||||
|
]
|
||||||
|
LEGS_SIDE_B = [
|
||||||
|
"0000004444000000",
|
||||||
|
"0000004444000000",
|
||||||
|
"0000007777000000",
|
||||||
|
"0000000000000000",
|
||||||
|
]
|
||||||
|
PLAYER = [
|
||||||
|
PLAYER_DOWN_TOP + BODY_FRONT + LEGS_FRONT_A,
|
||||||
|
PLAYER_DOWN_TOP + BODY_FRONT + LEGS_FRONT_B,
|
||||||
|
PLAYER_UP_TOP + BODY_FRONT + LEGS_FRONT_A,
|
||||||
|
PLAYER_UP_TOP + BODY_FRONT + LEGS_FRONT_B,
|
||||||
|
PLAYER_SIDE_TOP + LEGS_SIDE_A,
|
||||||
|
PLAYER_SIDE_TOP + LEGS_SIDE_B,
|
||||||
|
]
|
||||||
|
# guards: grey helmet, green tunic, dark grey trousers, brown boots
|
||||||
|
GUARD = [[r.translate(str.maketrans("3C47", "7283")) for r in s] for s in PLAYER]
|
||||||
|
|
||||||
|
|
||||||
|
def dot(c):
|
||||||
|
rows = ["0" * 16] * 16
|
||||||
|
for y in range(6, 10):
|
||||||
|
rows[y] = "000000" + c * 4 + "000000"
|
||||||
|
return rows
|
||||||
|
|
||||||
|
|
||||||
|
KEY = ["0" * 16] * 3 + [
|
||||||
|
"000BBB0000000000",
|
||||||
|
"00B000B000000000",
|
||||||
|
"00B000BBBBBBBBB0",
|
||||||
|
"00B000B0000B0B00",
|
||||||
|
"000BBB00000B0B00",
|
||||||
|
] + ["0" * 16] * 8
|
||||||
|
CHEST = ["0" * 16] * 3 + [
|
||||||
|
"0003333333333000",
|
||||||
|
"0033333333333300",
|
||||||
|
"003BBBBBBBBBB300",
|
||||||
|
"0033333BB3333300",
|
||||||
|
"0033333BB3333300",
|
||||||
|
"0033333333333300",
|
||||||
|
"0033333333333300",
|
||||||
|
"003BBBBBBBBBB300",
|
||||||
|
"0033333333333300",
|
||||||
|
] + ["0" * 16] * 4
|
||||||
|
AMMO = ["0" * 16] * 3 + [
|
||||||
|
"0022222222222200",
|
||||||
|
"0028888888888200",
|
||||||
|
"0028BB8BB8BB8200",
|
||||||
|
"0028BB8BB8BB8200",
|
||||||
|
"0028BB8BB8BB8200",
|
||||||
|
"0028888888888200",
|
||||||
|
"0022222222222200",
|
||||||
|
] + ["0" * 16] * 6
|
||||||
|
CROWN = ["0" * 16] * 3 + [
|
||||||
|
"000B000BB000B000",
|
||||||
|
"000BB0BBBB0BB000",
|
||||||
|
"000BBBBBBBBBB000",
|
||||||
|
"000BB9BBBB9BB000",
|
||||||
|
"000BBBBCCBBBB000",
|
||||||
|
"000BBBBBBBBBB000",
|
||||||
|
"0000000000000000",
|
||||||
|
"000BBBBBBBBBB000",
|
||||||
|
] + ["0" * 16] * 5
|
||||||
|
PUFF = [
|
||||||
|
"0000000000000000",
|
||||||
|
"000F00000000F000",
|
||||||
|
"0000F00BB00F0000",
|
||||||
|
"00000F0BB0F00000",
|
||||||
|
"000000BFFB000000",
|
||||||
|
"0BBB0BFFFFB0BBB0",
|
||||||
|
"000000BFFB000000",
|
||||||
|
"00000F0BB0F00000",
|
||||||
|
"0000F00BB00F0000",
|
||||||
|
"000F00000000F000",
|
||||||
|
] + ["0" * 16] * 6
|
||||||
|
|
||||||
|
SHAPES = PLAYER + GUARD + [dot("B"), dot("9"), KEY, CHEST, AMMO, CROWN, PUFF]
|
||||||
|
SHAPE_NAMES = ["S_PDOWN", "S_PDOWN2", "S_PUP", "S_PUP2", "S_PSIDE", "S_PSIDE2",
|
||||||
|
"S_GDOWN", "S_GDOWN2", "S_GUP", "S_GUP2", "S_GSIDE", "S_GSIDE2",
|
||||||
|
"S_SHOT", "S_GSHOT", "S_KEY", "S_CHEST", "S_AMMO", "S_CROWN", "S_PUFF"]
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------- tiles
|
||||||
|
WALL = (["8888888888888888", "7777777877777778", "7777777877777778", "7777777877777778",
|
||||||
|
"8888888888888888", "7778777777787777", "7778777777787777", "7778777777787777"] * 2)
|
||||||
|
DOOR = (["8888888888888888"] + ["8333833383338338"] * 6 +
|
||||||
|
["8333833BB3338338"] * 2 + ["8333833383338338"] * 6 + ["8888888888888888"])
|
||||||
|
STAIRS = ["EEEEEEEEEEEEEEEE", "6666666666666666", "8888888888888888", "0000000000000000"] * 4
|
||||||
|
TILES = [["0" * 16] * 16, WALL, DOOR, STAIRS] # floor, wall, door, stairs
|
||||||
|
|
||||||
|
# -------------------------------------------------------------------- map
|
||||||
|
ROOMS = [[None] * 4 for _ in range(3)]
|
||||||
|
NAMES = [[None] * 4 for _ in range(3)]
|
||||||
|
|
||||||
|
def room(r, c, name, rows):
|
||||||
|
ROOMS[r][c] = rows
|
||||||
|
NAMES[r][c] = name
|
||||||
|
|
||||||
|
room(0, 0, "GATEHOUSE", [
|
||||||
|
"..................",
|
||||||
|
"..P...............",
|
||||||
|
"..................",
|
||||||
|
"....####....####..",
|
||||||
|
"....#..........#..",
|
||||||
|
"....#...A......#..",
|
||||||
|
"....#..........#..",
|
||||||
|
"....####....####..",
|
||||||
|
"..................",
|
||||||
|
"..................",
|
||||||
|
"..................",
|
||||||
|
"..................",
|
||||||
|
])
|
||||||
|
room(0, 1, "GUARD ROOM", [
|
||||||
|
"..................",
|
||||||
|
".h................",
|
||||||
|
"..................",
|
||||||
|
"..###.......###...",
|
||||||
|
"..#...........#...",
|
||||||
|
"..#.....K.....#...",
|
||||||
|
"..#...........#...",
|
||||||
|
"..###.......###...",
|
||||||
|
"..................",
|
||||||
|
"...........h......",
|
||||||
|
"..................",
|
||||||
|
"..................",
|
||||||
|
])
|
||||||
|
room(0, 2, "CHAPEL", [
|
||||||
|
"..................",
|
||||||
|
".v..........v.....",
|
||||||
|
"..................",
|
||||||
|
"......######......",
|
||||||
|
"......#G.G#.......",
|
||||||
|
"......#...D.......",
|
||||||
|
"......#####.......",
|
||||||
|
"..................",
|
||||||
|
"..................",
|
||||||
|
"....h.............",
|
||||||
|
"..................",
|
||||||
|
"..................",
|
||||||
|
])
|
||||||
|
room(0, 3, "ARMOURY", [
|
||||||
|
"..................",
|
||||||
|
"..A............A..",
|
||||||
|
"..................",
|
||||||
|
".####.......####..",
|
||||||
|
"..................",
|
||||||
|
"........h.........",
|
||||||
|
"..................",
|
||||||
|
".####.......####..",
|
||||||
|
"..................",
|
||||||
|
"..................",
|
||||||
|
".......c..........",
|
||||||
|
"..................",
|
||||||
|
])
|
||||||
|
room(1, 0, "CORRIDOR", [
|
||||||
|
"..................",
|
||||||
|
".v.......####.....",
|
||||||
|
".........#........",
|
||||||
|
".........#....h...",
|
||||||
|
"#######..#........",
|
||||||
|
"..................",
|
||||||
|
"..................",
|
||||||
|
"#######..########.",
|
||||||
|
".........#........",
|
||||||
|
"..A......#........",
|
||||||
|
".........#....v...",
|
||||||
|
"..................",
|
||||||
|
])
|
||||||
|
room(1, 1, "GREAT HALL", [
|
||||||
|
"..................",
|
||||||
|
"..G............G..",
|
||||||
|
"..................",
|
||||||
|
"....##......##....",
|
||||||
|
"....##..h...##....",
|
||||||
|
"..................",
|
||||||
|
"..................",
|
||||||
|
"....##......##....",
|
||||||
|
"....##...h..##....",
|
||||||
|
"..................",
|
||||||
|
".c...........v....",
|
||||||
|
"..................",
|
||||||
|
])
|
||||||
|
room(1, 2, "CELLARS", [
|
||||||
|
"...#.......#......",
|
||||||
|
"...#.#####.#.####.",
|
||||||
|
"...#.#.....#....#.",
|
||||||
|
".....#.#######..#.",
|
||||||
|
"######.#.....#..#.",
|
||||||
|
".......#..A..#....",
|
||||||
|
".#######.....###..",
|
||||||
|
".#.......###......",
|
||||||
|
".#.#######.#.####.",
|
||||||
|
".#.........#.#....",
|
||||||
|
".#####.#####.#.h..",
|
||||||
|
".......#.......#..",
|
||||||
|
])
|
||||||
|
room(1, 3, "LIBRARY", [
|
||||||
|
"..................",
|
||||||
|
".##.##.##.##.##.#.",
|
||||||
|
"..................",
|
||||||
|
".##.##.##.##.##.#.",
|
||||||
|
"..........h.......",
|
||||||
|
"..................",
|
||||||
|
".##.##.##.##.##.#.",
|
||||||
|
"..................",
|
||||||
|
".##.##.##.##.##.#.",
|
||||||
|
"........K.........",
|
||||||
|
"...v..............",
|
||||||
|
"..................",
|
||||||
|
])
|
||||||
|
room(2, 0, "STAIRWELL", [
|
||||||
|
"..................",
|
||||||
|
"..................",
|
||||||
|
"..######..######..",
|
||||||
|
"..#............#..",
|
||||||
|
"..#.....XX.....#..",
|
||||||
|
"..#.....XX.....#..",
|
||||||
|
"..#............#..",
|
||||||
|
"..######..######..",
|
||||||
|
"..................",
|
||||||
|
"....h.............",
|
||||||
|
"..................",
|
||||||
|
"..................",
|
||||||
|
])
|
||||||
|
room(2, 1, "DUNGEON", [
|
||||||
|
".#..#..#..#..#..#.",
|
||||||
|
".#..#..#..#..#..#.",
|
||||||
|
".#..#..#..#..#..#.",
|
||||||
|
".##.####..####.##.",
|
||||||
|
"..................",
|
||||||
|
"........v.........",
|
||||||
|
"..................",
|
||||||
|
".##.####..####.##.",
|
||||||
|
".#..#..#..#..#..#.",
|
||||||
|
".#K.#..#..#.G#..#.",
|
||||||
|
".#..#..#..#..#..#.",
|
||||||
|
"..................",
|
||||||
|
])
|
||||||
|
room(2, 2, "TREASURY", [
|
||||||
|
"..................",
|
||||||
|
"..h...............",
|
||||||
|
"..................",
|
||||||
|
".....##########...",
|
||||||
|
".....#G..G...G#...",
|
||||||
|
".....#........#...",
|
||||||
|
".....######D###...",
|
||||||
|
"..................",
|
||||||
|
"..................",
|
||||||
|
".........v........",
|
||||||
|
"..................",
|
||||||
|
"..................",
|
||||||
|
])
|
||||||
|
room(2, 3, "THRONE ROOM", [
|
||||||
|
"#######D##########",
|
||||||
|
"..................",
|
||||||
|
".c..............c.",
|
||||||
|
"..................",
|
||||||
|
"...####....####...",
|
||||||
|
"...#..........#...",
|
||||||
|
"...#....C.....#...",
|
||||||
|
"...#..........#...",
|
||||||
|
"...####....####...",
|
||||||
|
"..................",
|
||||||
|
".v..............v.",
|
||||||
|
"..................",
|
||||||
|
])
|
||||||
|
|
||||||
|
# links: (room, room) side by side or one above the other
|
||||||
|
H_LINKS = {(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1)} # (r, c) to (r, c+1)
|
||||||
|
V_LINKS = {(0, 0), (1, 0), (0, 3), (1, 3), (1, 1)} # (r, c) to (r+1, c)
|
||||||
|
|
||||||
|
W, H = 20, 14
|
||||||
|
GAP_ROWS = (6, 7) # side gaps, in room rows
|
||||||
|
GAP_COLS = (8, 9) # top/bottom gaps, in room columns
|
||||||
|
OBJ = "PKGAChvc"
|
||||||
|
|
||||||
|
|
||||||
|
def full_room(r, c):
|
||||||
|
inner = ROOMS[r][c]
|
||||||
|
assert len(inner) == 12 and all(len(x) == 18 for x in inner), NAMES[r][c]
|
||||||
|
g = [["#"] * W for _ in range(H)]
|
||||||
|
for y in range(12):
|
||||||
|
for x in range(18):
|
||||||
|
g[y + 1][x + 1] = inner[y][x]
|
||||||
|
if (r, c) in H_LINKS:
|
||||||
|
for y in GAP_ROWS: g[y][W - 1] = "."
|
||||||
|
if (r, c - 1) in H_LINKS:
|
||||||
|
for y in GAP_ROWS: g[y][0] = "."
|
||||||
|
if (r, c) in V_LINKS:
|
||||||
|
for x in GAP_COLS: g[H - 1][x] = "."
|
||||||
|
if (r - 1, c) in V_LINKS:
|
||||||
|
for x in GAP_COLS: g[0][x] = "."
|
||||||
|
return g
|
||||||
|
|
||||||
|
|
||||||
|
FULL = [[full_room(r, c) for c in range(4)] for r in range(3)]
|
||||||
|
|
||||||
|
# one big grid to check reachability across rooms
|
||||||
|
BIG = [[FULL[gy // H][gx // W][gy % H][gx % W] for gx in range(4 * W)] for gy in range(3 * H)]
|
||||||
|
|
||||||
|
def check():
|
||||||
|
start = [(x, y) for y in range(3 * H) for x in range(4 * W) if BIG[y][x] == "P"]
|
||||||
|
assert len(start) == 1
|
||||||
|
doors = sum(row.count("D") for row in BIG)
|
||||||
|
keys = sum(row.count("K") for row in BIG)
|
||||||
|
assert keys >= doors, f"{keys} keys for {doors} doors"
|
||||||
|
# with every door open, every non-wall tile must be reachable
|
||||||
|
seen = {start[0]}
|
||||||
|
q = deque(seen)
|
||||||
|
while q:
|
||||||
|
x, y = q.popleft()
|
||||||
|
for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
|
||||||
|
nx, ny = x + dx, y + dy
|
||||||
|
if 0 <= nx < 4 * W and 0 <= ny < 3 * H and (nx, ny) not in seen and BIG[ny][nx] != "#":
|
||||||
|
seen.add((nx, ny)); q.append((nx, ny))
|
||||||
|
lost = [(x, y, BIG[y][x]) for y in range(3 * H) for x in range(4 * W)
|
||||||
|
if BIG[y][x] != "#" and (x, y) not in seen]
|
||||||
|
objs_lost = [t for t in lost if t[2] != "."]
|
||||||
|
assert not objs_lost, f"unreachable objects: {objs_lost}"
|
||||||
|
# rooms' sprite budgets: 6 guards, 8 items
|
||||||
|
for r in range(3):
|
||||||
|
for c in range(4):
|
||||||
|
s = "".join("".join(row) for row in FULL[r][c])
|
||||||
|
assert sum(s.count(ch) for ch in "hvc") <= 6, NAMES[r][c]
|
||||||
|
assert sum(s.count(ch) for ch in "KGAC") <= 8, NAMES[r][c]
|
||||||
|
assert s.count("D") <= 8, NAMES[r][c]
|
||||||
|
return len(lost)
|
||||||
|
|
||||||
|
|
||||||
|
def nib(c):
|
||||||
|
return int(c, 16)
|
||||||
|
|
||||||
|
|
||||||
|
def main(out):
|
||||||
|
unreach = check()
|
||||||
|
L = ["/* made by gen.py - edit that instead */", ""]
|
||||||
|
L.append("#define N_SHAPES %d" % len(SHAPES))
|
||||||
|
for i, n in enumerate(SHAPE_NAMES):
|
||||||
|
L.append("#define %s %d" % (n, i))
|
||||||
|
for i, s in enumerate(SHAPES):
|
||||||
|
assert len(s) == 16 and all(len(row) == 16 for row in s), SHAPE_NAMES[i]
|
||||||
|
L.append("static const u8 shape_data[N_SHAPES * 128] = {")
|
||||||
|
for s in SHAPES:
|
||||||
|
b = [nib(row[x]) << 4 | nib(row[x + 1]) for row in s for x in range(0, 16, 2)]
|
||||||
|
L.append(" " + ",".join(str(v) for v in b) + ",")
|
||||||
|
L.append("};")
|
||||||
|
L.append("static const u8 tile_data[4 * 256] = {")
|
||||||
|
for t in TILES:
|
||||||
|
assert len(t) == 16 and all(len(row) == 16 for row in t)
|
||||||
|
L.append(" " + ",".join(str(nib(ch)) for row in t for ch in row) + ",")
|
||||||
|
L.append("};")
|
||||||
|
# rooms: tiles packed two per byte (low nibble first), then object lists
|
||||||
|
code = {".": 0, "#": 1, "D": 2, "X": 3}
|
||||||
|
L.append("static const u8 room_tiles[12][140] = {")
|
||||||
|
objs = []
|
||||||
|
for r in range(3):
|
||||||
|
for c in range(4):
|
||||||
|
g = FULL[r][c]
|
||||||
|
t = [code.get(g[y][x], 0) for y in range(H) for x in range(W)]
|
||||||
|
L.append(" {" + ",".join(str(t[i] | t[i + 1] << 4) for i in range(0, W * H, 2)) + "},")
|
||||||
|
ol = [(g[y][x], x, y) for y in range(H) for x in range(W) if g[y][x] in OBJ]
|
||||||
|
objs.append(ol)
|
||||||
|
L.append("};")
|
||||||
|
L.append("/* objects: type, tile x, tile y; ends with 0 */")
|
||||||
|
L.append("static const u8 room_objs[12][3 * 16 + 1] = {")
|
||||||
|
for ol in objs:
|
||||||
|
assert len(ol) <= 16
|
||||||
|
L.append(" {" + ",".join("'%s',%d,%d" % o for o in ol) + (",0}," if ol else "0},"))
|
||||||
|
L.append("};")
|
||||||
|
L.append("static const char *const room_names[12] = {")
|
||||||
|
L.append(" " + ", ".join('"%s"' % NAMES[r][c] for r in range(3) for c in range(4)))
|
||||||
|
L.append("};")
|
||||||
|
open(out, "w").write("\n".join(L) + "\n")
|
||||||
|
print("data.h: %d shapes, 12 rooms (%d floor tiles only reachable through nothing)" %
|
||||||
|
(len(SHAPES), unreach))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main(sys.argv[1] if len(sys.argv) > 1 else "data.h")
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
10 REM THE IRON KEEP: LOAD THE GAME (MEMORY FILE KEEPGAME) AND PLAY IT
|
||||||
|
20 REM THE GAME RUNS AT 8600H, PAST THIS PROGRAM, AND COMES BACK HERE
|
||||||
|
30 BLOAD "KEEPGAME": CALL 34304
|
||||||
|
40 CLS
|
||||||
@@ -0,0 +1,645 @@
|
|||||||
|
/* The Iron Keep: a top-down escape game for the Basys 3 Z-80.
|
||||||
|
|
||||||
|
You are a prisoner in a castle of twelve rooms. Steal the crown from the
|
||||||
|
throne room and get out down the stairs. Guards patrol, and shoot when they
|
||||||
|
can see you along a row or a column; some come after you. Keys open locked
|
||||||
|
doors, chests hold gold, crates hold ammunition.
|
||||||
|
|
||||||
|
It runs at 8600h, loaded by the KEEP program in BASIC, and returns to BASIC
|
||||||
|
when you quit. It uses the hardware sprites (ports 70h-78h), the graphics
|
||||||
|
layer (30h-34h), the held-key port (88h) and the terminal for text.
|
||||||
|
Build with build.sh; gen.py makes data.h from the art and the map. */
|
||||||
|
|
||||||
|
typedef unsigned char u8;
|
||||||
|
typedef signed char i8;
|
||||||
|
typedef unsigned int u16;
|
||||||
|
typedef int i16;
|
||||||
|
|
||||||
|
__sfr __at 0x00 con_stat; /* bit 0: key waiting, bit 1: can send */
|
||||||
|
__sfr __at 0x01 con_data;
|
||||||
|
__sfr __at 0x30 gx_lo;
|
||||||
|
__sfr __at 0x31 gx_hi;
|
||||||
|
__sfr __at 0x32 gy_p;
|
||||||
|
__sfr __at 0x33 gpix; /* plot, then X + 1 */
|
||||||
|
__sfr __at 0x34 gfill; /* fill the graphics (and turn sprites off) */
|
||||||
|
__sfr __at 0x70 sp_sel;
|
||||||
|
__sfr __at 0x71 sp_xlo;
|
||||||
|
__sfr __at 0x72 sp_xhi;
|
||||||
|
__sfr __at 0x73 sp_y;
|
||||||
|
__sfr __at 0x74 sp_shape;
|
||||||
|
__sfr __at 0x75 sp_ctl;
|
||||||
|
__sfr __at 0x76 sp_load;
|
||||||
|
__sfr __at 0x77 sp_data;
|
||||||
|
__sfr __at 0x78 frame_ctr;
|
||||||
|
__sfr __at 0x88 joy;
|
||||||
|
|
||||||
|
#include "data.h" /* out/data.h, made by gen.py */
|
||||||
|
|
||||||
|
#define J_UP 1
|
||||||
|
#define J_DOWN 2
|
||||||
|
#define J_LEFT 4
|
||||||
|
#define J_RIGHT 8
|
||||||
|
#define J_FIRE 16
|
||||||
|
#define J_ENTER 32
|
||||||
|
#define J_ESC 128
|
||||||
|
|
||||||
|
/* directions */
|
||||||
|
#define D_DOWN 0
|
||||||
|
#define D_UP 1
|
||||||
|
#define D_LEFT 2
|
||||||
|
#define D_RIGHT 3
|
||||||
|
static const i8 dir_dx[4] = { 0, 0, -1, 1 };
|
||||||
|
static const i8 dir_dy[4] = { 1, -1, 0, 0 };
|
||||||
|
|
||||||
|
/* tiles */
|
||||||
|
#define T_FLOOR 0
|
||||||
|
#define T_WALL 1
|
||||||
|
#define T_DOOR 2
|
||||||
|
#define T_STAIRS 3
|
||||||
|
#define T_OUT 0xFF
|
||||||
|
|
||||||
|
/* sprite numbers: lower numbers are in front */
|
||||||
|
#define SP_PLAYER 0
|
||||||
|
#define SP_PSHOT 1 /* 2 */
|
||||||
|
#define SP_GUARD 3 /* 6 */
|
||||||
|
#define SP_GSHOT 9 /* 4 */
|
||||||
|
#define SP_ITEM 13 /* 8 */
|
||||||
|
#define SP_PUFF 21
|
||||||
|
|
||||||
|
#define NG 6
|
||||||
|
#define NI 8
|
||||||
|
#define NPS 2
|
||||||
|
#define NGS 4
|
||||||
|
|
||||||
|
/* the hit box inside a 16 x 16 figure */
|
||||||
|
#define HB_X0 3
|
||||||
|
#define HB_X1 12
|
||||||
|
#define HB_Y0 2
|
||||||
|
#define HB_Y1 14
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------- state */
|
||||||
|
static u8 map[14][20];
|
||||||
|
/* not static: test-keep.py finds these in the link map */
|
||||||
|
u8 room; /* 0-11: row * 4 + column */
|
||||||
|
static u16 gone[12]; /* objects taken or guards beaten, by index */
|
||||||
|
static u8 opened[12]; /* doors opened, by order in the room */
|
||||||
|
|
||||||
|
i16 px, py; /* player */
|
||||||
|
static i16 ex, ey; /* where it entered the room */
|
||||||
|
static u8 pdir, panim, fire_cool, fire_held;
|
||||||
|
u8 inv, lives, keys, ammo, crown;
|
||||||
|
static u16 gold, kills;
|
||||||
|
|
||||||
|
static i16 gx[NG], gy[NG];
|
||||||
|
static u8 gdir[NG], gon[NG], gkind[NG], gcool[NG], gsee[NG], gobj[NG];
|
||||||
|
static i16 ix[NI], iy[NI];
|
||||||
|
static u8 itype[NI], ion[NI], iobj[NI];
|
||||||
|
static i16 psx[NPS], psy[NPS], gsx[NGS], gsy[NGS];
|
||||||
|
static u8 psd[NPS], pson[NPS], gsd[NGS], gson[NGS];
|
||||||
|
static u8 puff;
|
||||||
|
static i16 puff_x, puff_y;
|
||||||
|
|
||||||
|
static u8 last_frame, quit, status_dirty, msg_time;
|
||||||
|
u8 over, won;
|
||||||
|
static const char *msg;
|
||||||
|
static u16 rnd_state;
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------- text */
|
||||||
|
static void putch(char c) { while (!(con_stat & 2)); con_data = c; }
|
||||||
|
static void puts_(const char *s) { while (*s) putch(*s++); }
|
||||||
|
static void putn(u16 n)
|
||||||
|
{
|
||||||
|
char b[6];
|
||||||
|
u8 i = 0;
|
||||||
|
do { b[i++] = '0' + n % 10; n /= 10; } while (n);
|
||||||
|
while (i) putch(b[--i]);
|
||||||
|
}
|
||||||
|
static void at(u8 r, u8 c) { putch(27); putch('['); putn(r); putch(';'); putn(c); putch('H'); }
|
||||||
|
static void ink(const char *s) { putch(27); putch('['); puts_(s); putch('m'); }
|
||||||
|
static void centre(u8 r, const char *s)
|
||||||
|
{
|
||||||
|
u8 n = 0;
|
||||||
|
while (s[n]) n++;
|
||||||
|
at(r, 41 - n / 2);
|
||||||
|
puts_(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
static u16 rnd(void)
|
||||||
|
{
|
||||||
|
rnd_state ^= rnd_state << 7;
|
||||||
|
rnd_state ^= rnd_state >> 9;
|
||||||
|
rnd_state ^= rnd_state << 8;
|
||||||
|
return rnd_state;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void wait_frame(void)
|
||||||
|
{
|
||||||
|
while (frame_ctr == last_frame);
|
||||||
|
last_frame = frame_ctr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Keys also arrive as characters; throw them away (P pauses). */
|
||||||
|
static u8 drain_keys(void)
|
||||||
|
{
|
||||||
|
u8 c, p = 0;
|
||||||
|
while (con_stat & 1) {
|
||||||
|
c = con_data;
|
||||||
|
if (c == 'p' || c == 'P') p = 1;
|
||||||
|
}
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------- graphics */
|
||||||
|
static void clear_gfx(void)
|
||||||
|
{
|
||||||
|
gfill = 0; /* also turns every sprite off */
|
||||||
|
while (gfill & 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void draw_tile(u8 tx, u8 ty, u8 t)
|
||||||
|
{
|
||||||
|
const u8 *p = tile_data + ((u16)t << 8);
|
||||||
|
u16 x = tx << 4;
|
||||||
|
u8 y = 16 + (ty << 4), r, i;
|
||||||
|
for (r = 0; r < 16; r++) {
|
||||||
|
gx_lo = x; gx_hi = x >> 8; gy_p = y + r;
|
||||||
|
for (i = 0; i < 16; i++) gpix = *p++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void spr_at(u8 n, i16 x, i16 y)
|
||||||
|
{
|
||||||
|
sp_sel = n; sp_xlo = x; sp_xhi = (x >> 8) & 1; sp_y = y;
|
||||||
|
}
|
||||||
|
static void spr_show(u8 n, u8 shape, u8 ctl)
|
||||||
|
{
|
||||||
|
sp_sel = n; sp_shape = shape; sp_ctl = ctl;
|
||||||
|
}
|
||||||
|
static void spr_off(u8 n) { sp_sel = n; sp_ctl = 0; }
|
||||||
|
|
||||||
|
static void load_shapes(void)
|
||||||
|
{
|
||||||
|
const u8 *p = shape_data;
|
||||||
|
u8 s, i;
|
||||||
|
for (s = 0; s < N_SHAPES; s++) {
|
||||||
|
sp_load = s;
|
||||||
|
for (i = 0; i < 128; i++) sp_data = *p++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------- map */
|
||||||
|
static u8 tile_at(i16 x, i16 y)
|
||||||
|
{
|
||||||
|
if (x < 0 || x > 319 || y < 16 || y > 239) return T_OUT;
|
||||||
|
return map[(u8)((y - 16) >> 4)][(u8)(x >> 4)];
|
||||||
|
}
|
||||||
|
|
||||||
|
static u8 hit_tx, hit_ty;
|
||||||
|
|
||||||
|
/* What stops a figure at (x, y): 0 nothing, T_WALL or T_DOOR (hit_tx/ty say
|
||||||
|
which tile). Off the room is open for the player, a wall for guards. */
|
||||||
|
static u8 blocked(i16 x, i16 y, u8 guard)
|
||||||
|
{
|
||||||
|
static const u8 cx[4] = { HB_X0, HB_X1, HB_X0, HB_X1 };
|
||||||
|
static const u8 cy[4] = { HB_Y0, HB_Y0, HB_Y1, HB_Y1 };
|
||||||
|
u8 i, t;
|
||||||
|
for (i = 0; i < 4; i++) {
|
||||||
|
t = tile_at(x + cx[i], y + cy[i]);
|
||||||
|
if (t == T_WALL || t == T_DOOR) {
|
||||||
|
hit_tx = (u8)((x + cx[i]) >> 4);
|
||||||
|
hit_ty = (u8)((y + cy[i] - 16) >> 4);
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
if (t == T_OUT && guard) return T_WALL;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static u8 door_index(u8 tx, u8 ty)
|
||||||
|
{
|
||||||
|
const u8 *p = room_tiles[room];
|
||||||
|
u8 n = 0, i, t;
|
||||||
|
u16 k, want = ty * 20 + tx;
|
||||||
|
for (k = 0; k < want; k++) {
|
||||||
|
i = p[k >> 1];
|
||||||
|
t = (k & 1) ? i >> 4 : i & 15;
|
||||||
|
if (t == T_DOOR) n++;
|
||||||
|
}
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void say(const char *s)
|
||||||
|
{
|
||||||
|
msg = s;
|
||||||
|
msg_time = 180;
|
||||||
|
status_dirty = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------- status */
|
||||||
|
static void status(void)
|
||||||
|
{
|
||||||
|
status_dirty = 0;
|
||||||
|
at(1, 1); ink("0;93"); puts_("THE IRON KEEP"); ink("0;37"); puts_(" ");
|
||||||
|
puts_(room_names[room]);
|
||||||
|
puts_("\033[K");
|
||||||
|
if (msg && msg_time) { at(1, 40); ink("0;96"); puts_(msg); }
|
||||||
|
at(2, 1); ink("0;37");
|
||||||
|
puts_("LIVES "); ink("0;97"); putn(lives); ink("0;37");
|
||||||
|
puts_(" KEYS "); ink("0;97"); putn(keys); ink("0;37");
|
||||||
|
puts_(" AMMO "); ink("0;97"); putn(ammo); ink("0;37");
|
||||||
|
puts_(" GOLD "); ink("0;97"); putn(gold); ink("0;37");
|
||||||
|
if (crown) { puts_(" "); ink("0;93"); puts_("CROWN"); }
|
||||||
|
puts_("\033[K");
|
||||||
|
ink("0");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------- rooms */
|
||||||
|
static void enter_room(void)
|
||||||
|
{
|
||||||
|
const u8 *p = room_tiles[room], *o = room_objs[room];
|
||||||
|
u8 x, y, i, t, d = 0, ng = 0, ni = 0, k = 0;
|
||||||
|
|
||||||
|
clear_gfx();
|
||||||
|
for (y = 0; y < 14; y++)
|
||||||
|
for (x = 0; x < 20; x += 2) {
|
||||||
|
i = *p++;
|
||||||
|
map[y][x] = i & 15;
|
||||||
|
map[y][x + 1] = i >> 4;
|
||||||
|
}
|
||||||
|
for (y = 0; y < 14; y++)
|
||||||
|
for (x = 0; x < 20; x++) {
|
||||||
|
t = map[y][x];
|
||||||
|
if (t == T_DOOR && (opened[room] & (1 << d++))) t = map[y][x] = T_FLOOR;
|
||||||
|
if (t != T_FLOOR) draw_tile(x, y, t);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < NG; i++) gon[i] = 0;
|
||||||
|
for (i = 0; i < NI; i++) ion[i] = 0;
|
||||||
|
for (; *o; o += 3, k++) {
|
||||||
|
if (gone[room] & (1 << k)) continue;
|
||||||
|
t = o[0];
|
||||||
|
if (t == 'h' || t == 'v' || t == 'c') {
|
||||||
|
gx[ng] = o[1] << 4; gy[ng] = 16 + (o[2] << 4);
|
||||||
|
gkind[ng] = t; gon[ng] = 1; gsee[ng] = 0; gobj[ng] = k;
|
||||||
|
gdir[ng] = t == 'v' ? D_DOWN : D_RIGHT;
|
||||||
|
gcool[ng] = 30 + (rnd() & 31);
|
||||||
|
ng++;
|
||||||
|
} else if (t != 'P') {
|
||||||
|
ix[ni] = o[1] << 4; iy[ni] = 16 + (o[2] << 4);
|
||||||
|
itype[ni] = t; ion[ni] = 1; iobj[ni] = k;
|
||||||
|
spr_at(SP_ITEM + ni, ix[ni], iy[ni]);
|
||||||
|
spr_show(SP_ITEM + ni, t == 'K' ? S_KEY : t == 'G' ? S_CHEST : t == 'A' ? S_AMMO : S_CROWN, 1);
|
||||||
|
ni++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (i = 0; i < NPS; i++) pson[i] = 0;
|
||||||
|
for (i = 0; i < NGS; i++) gson[i] = 0;
|
||||||
|
puff = 0;
|
||||||
|
ex = px; ey = py;
|
||||||
|
status_dirty = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Leave by an edge into the next room. */
|
||||||
|
static void edges(void)
|
||||||
|
{
|
||||||
|
if (px + HB_X0 < 0) { room--; px = 304; }
|
||||||
|
else if (px + HB_X1 > 319) { room++; px = 0; }
|
||||||
|
else if (py + HB_Y0 < 16) { room -= 4; py = 224; }
|
||||||
|
else if (py + HB_Y1 > 239) { room += 4; py = 16; }
|
||||||
|
else return;
|
||||||
|
enter_room();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------- player */
|
||||||
|
static void open_door(void)
|
||||||
|
{
|
||||||
|
if (!keys) { say("LOCKED. YOU NEED A KEY."); return; }
|
||||||
|
keys--;
|
||||||
|
opened[room] |= 1 << door_index(hit_tx, hit_ty);
|
||||||
|
map[hit_ty][hit_tx] = T_FLOOR;
|
||||||
|
draw_tile(hit_tx, hit_ty, T_FLOOR);
|
||||||
|
say("THE KEY TURNS. THE DOOR OPENS.");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void move_player(u8 j)
|
||||||
|
{
|
||||||
|
i16 n;
|
||||||
|
u8 t, moved = 0;
|
||||||
|
if (j & (J_LEFT | J_RIGHT)) {
|
||||||
|
pdir = (j & J_LEFT) ? D_LEFT : D_RIGHT;
|
||||||
|
n = px + ((j & J_LEFT) ? -2 : 2);
|
||||||
|
t = blocked(n, py, 0);
|
||||||
|
if (!t) { px = n; moved = 1; }
|
||||||
|
else if (t == T_DOOR) open_door();
|
||||||
|
}
|
||||||
|
if (j & (J_UP | J_DOWN)) {
|
||||||
|
if (!(j & (J_LEFT | J_RIGHT))) pdir = (j & J_UP) ? D_UP : D_DOWN;
|
||||||
|
n = py + ((j & J_UP) ? -2 : 2);
|
||||||
|
t = blocked(px, n, 0);
|
||||||
|
if (!t) { py = n; moved = 1; }
|
||||||
|
else if (t == T_DOOR) open_door();
|
||||||
|
}
|
||||||
|
if (moved) panim++;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void fire(u8 j)
|
||||||
|
{
|
||||||
|
u8 i;
|
||||||
|
if (!(j & J_FIRE)) { fire_held = 0; return; }
|
||||||
|
if (fire_held || fire_cool) return;
|
||||||
|
fire_held = 1;
|
||||||
|
if (!ammo) { say("OUT OF AMMUNITION!"); return; }
|
||||||
|
for (i = 0; i < NPS; i++)
|
||||||
|
if (!pson[i]) {
|
||||||
|
pson[i] = 1; psd[i] = pdir;
|
||||||
|
psx[i] = px + 8 + dir_dx[pdir] * 6;
|
||||||
|
psy[i] = py + 8 + dir_dy[pdir] * 6;
|
||||||
|
ammo--; fire_cool = 8; status_dirty = 1;
|
||||||
|
spr_show(SP_PSHOT + i, S_SHOT, 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void player_hit(void)
|
||||||
|
{
|
||||||
|
u8 i;
|
||||||
|
if (inv || over) return;
|
||||||
|
puff = 30; puff_x = px; puff_y = py;
|
||||||
|
if (!--lives) { over = 1; won = 0; return; }
|
||||||
|
say("YOU ARE HIT!");
|
||||||
|
px = ex; py = ey; inv = 120;
|
||||||
|
for (i = 0; i < NGS; i++) { gson[i] = 0; spr_off(SP_GSHOT + i); }
|
||||||
|
}
|
||||||
|
|
||||||
|
static u8 overlap(i16 ax, i16 ay, i16 bx, i16 by)
|
||||||
|
{
|
||||||
|
return ax + HB_X0 <= bx + HB_X1 && bx + HB_X0 <= ax + HB_X1 &&
|
||||||
|
ay + HB_Y0 <= by + HB_Y1 && by + HB_Y0 <= ay + HB_Y1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void pick_up(void)
|
||||||
|
{
|
||||||
|
u8 i;
|
||||||
|
for (i = 0; i < NI; i++) {
|
||||||
|
if (!ion[i] || !overlap(px, py, ix[i], iy[i])) continue;
|
||||||
|
ion[i] = 0;
|
||||||
|
gone[room] |= 1 << iobj[i];
|
||||||
|
spr_off(SP_ITEM + i);
|
||||||
|
switch (itype[i]) {
|
||||||
|
case 'K': keys++; say("A KEY!"); break;
|
||||||
|
case 'G': gold += 100; say("GOLD! 100 CROWNS."); break;
|
||||||
|
case 'A': ammo += 5; say("FIVE MORE SHOTS."); break;
|
||||||
|
case 'C': crown = 1; say("THE CROWN! NOW FIND THE STAIRS."); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (tile_at(px + 8, py + 8) == T_STAIRS) {
|
||||||
|
if (crown) { over = 1; won = 1; }
|
||||||
|
else if (msg_time < 120) say("NOT WITHOUT THE CROWN.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------- guards */
|
||||||
|
/* Can guard i see the player along a row or a column? Returns the direction
|
||||||
|
to look in, plus 1, or 0. */
|
||||||
|
static u8 sees(u8 i)
|
||||||
|
{
|
||||||
|
i16 gcx = gx[i] + 8, gcy = gy[i] + 8, pcx = px + 8, pcy = py + 8, d;
|
||||||
|
u8 a, b, t, k;
|
||||||
|
d = gcy - pcy;
|
||||||
|
if (d > -8 && d < 8) {
|
||||||
|
k = (u8)((gcy - 16) >> 4);
|
||||||
|
a = (u8)(gcx >> 4); b = (u8)(pcx >> 4);
|
||||||
|
if (a > b) { t = a; a = b; b = t; }
|
||||||
|
for (; a <= b; a++) if (map[k][a] == T_WALL || map[k][a] == T_DOOR) return 0;
|
||||||
|
return (pcx < gcx ? D_LEFT : D_RIGHT) + 1;
|
||||||
|
}
|
||||||
|
d = gcx - pcx;
|
||||||
|
if (d > -8 && d < 8) {
|
||||||
|
k = (u8)(gcx >> 4);
|
||||||
|
a = (u8)((gcy - 16) >> 4); b = (u8)((pcy - 16) >> 4);
|
||||||
|
if (a > b) { t = a; a = b; b = t; }
|
||||||
|
for (; a <= b; a++) if (map[a][k] == T_WALL || map[a][k] == T_DOOR) return 0;
|
||||||
|
return (pcy < gcy ? D_UP : D_DOWN) + 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void guard_shoots(u8 i)
|
||||||
|
{
|
||||||
|
u8 k;
|
||||||
|
for (k = 0; k < NGS; k++)
|
||||||
|
if (!gson[k]) {
|
||||||
|
gson[k] = 1; gsd[k] = gdir[i];
|
||||||
|
gsx[k] = gx[i] + 8 + dir_dx[gdir[i]] * 6;
|
||||||
|
gsy[k] = gy[i] + 8 + dir_dy[gdir[i]] * 6;
|
||||||
|
spr_show(SP_GSHOT + k, S_GSHOT, 1);
|
||||||
|
gcool[i] = 45 + (rnd() & 63);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void guards(void)
|
||||||
|
{
|
||||||
|
u8 i, s, d;
|
||||||
|
i16 nx, ny;
|
||||||
|
for (i = 0; i < NG; i++) {
|
||||||
|
if (!gon[i]) continue;
|
||||||
|
if (gcool[i]) gcool[i]--;
|
||||||
|
s = inv ? 0 : sees(i);
|
||||||
|
if (s) {
|
||||||
|
gdir[i] = s - 1;
|
||||||
|
if (!gsee[i]) { gsee[i] = 1; if (gcool[i] < 25) gcool[i] = 25; }
|
||||||
|
if (!gcool[i]) guard_shoots(i);
|
||||||
|
if (gkind[i] != 'c') goto shown; /* the others stand and shoot */
|
||||||
|
} else
|
||||||
|
gsee[i] = 0;
|
||||||
|
d = gdir[i];
|
||||||
|
nx = gx[i] + dir_dx[d];
|
||||||
|
ny = gy[i] + dir_dy[d];
|
||||||
|
if (blocked(nx, ny, 1)) {
|
||||||
|
/* turn round, or for a chaser, try the other way across */
|
||||||
|
if (gkind[i] == 'c' && !s) gdir[i] = (rnd() & 3);
|
||||||
|
else if (!s) gdir[i] = d ^ 1;
|
||||||
|
} else {
|
||||||
|
gx[i] = nx; gy[i] = ny;
|
||||||
|
}
|
||||||
|
if (overlap(gx[i], gy[i], px, py)) player_hit();
|
||||||
|
shown:
|
||||||
|
d = gdir[i];
|
||||||
|
spr_at(SP_GUARD + i, gx[i], gy[i]);
|
||||||
|
spr_show(SP_GUARD + i,
|
||||||
|
(d == D_DOWN ? S_GDOWN : d == D_UP ? S_GUP : S_GSIDE) + (((gx[i] + gy[i]) >> 3) & 1),
|
||||||
|
d == D_LEFT ? 3 : 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------- bullets */
|
||||||
|
static void shots(void)
|
||||||
|
{
|
||||||
|
u8 i, k;
|
||||||
|
for (i = 0; i < NPS; i++) {
|
||||||
|
if (!pson[i]) continue;
|
||||||
|
psx[i] += dir_dx[psd[i]] * 5;
|
||||||
|
psy[i] += dir_dy[psd[i]] * 5;
|
||||||
|
k = tile_at(psx[i], psy[i]);
|
||||||
|
if (k == T_WALL || k == T_DOOR || k == T_OUT) { pson[i] = 0; spr_off(SP_PSHOT + i); continue; }
|
||||||
|
for (k = 0; k < NG; k++)
|
||||||
|
if (gon[k] && psx[i] >= gx[k] + HB_X0 && psx[i] <= gx[k] + HB_X1 &&
|
||||||
|
psy[i] >= gy[k] + HB_Y0 && psy[i] <= gy[k] + HB_Y1) {
|
||||||
|
gon[k] = 0;
|
||||||
|
gone[room] |= 1 << gobj[k];
|
||||||
|
spr_off(SP_GUARD + k);
|
||||||
|
pson[i] = 0; spr_off(SP_PSHOT + i);
|
||||||
|
puff = 20; puff_x = gx[k]; puff_y = gy[k];
|
||||||
|
kills++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (pson[i]) spr_at(SP_PSHOT + i, psx[i] - 8, psy[i] - 8);
|
||||||
|
}
|
||||||
|
for (i = 0; i < NGS; i++) {
|
||||||
|
if (!gson[i]) continue;
|
||||||
|
gsx[i] += dir_dx[gsd[i]] * 3;
|
||||||
|
gsy[i] += dir_dy[gsd[i]] * 3;
|
||||||
|
k = tile_at(gsx[i], gsy[i]);
|
||||||
|
if (k == T_WALL || k == T_DOOR || k == T_OUT) { gson[i] = 0; spr_off(SP_GSHOT + i); continue; }
|
||||||
|
if (gsx[i] >= px + HB_X0 && gsx[i] <= px + HB_X1 && gsy[i] >= py + HB_Y0 && gsy[i] <= py + HB_Y1) {
|
||||||
|
gson[i] = 0; spr_off(SP_GSHOT + i);
|
||||||
|
player_hit();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
spr_at(SP_GSHOT + i, gsx[i] - 8, gsy[i] - 8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void draw_player(void)
|
||||||
|
{
|
||||||
|
u8 s = pdir == D_DOWN ? S_PDOWN : pdir == D_UP ? S_PUP : S_PSIDE;
|
||||||
|
spr_at(SP_PLAYER, px, py);
|
||||||
|
spr_show(SP_PLAYER, s + ((panim >> 3) & 1),
|
||||||
|
(inv & 4) ? 0 : pdir == D_LEFT ? 3 : 1);
|
||||||
|
if (puff) {
|
||||||
|
spr_at(SP_PUFF, puff_x, puff_y);
|
||||||
|
spr_show(SP_PUFF, S_PUFF, --puff ? 1 : 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------- screens */
|
||||||
|
static u8 wait_fire(void)
|
||||||
|
{
|
||||||
|
u8 j;
|
||||||
|
while (joy & (J_FIRE | J_ENTER | J_ESC)) { wait_frame(); drain_keys(); }
|
||||||
|
for (;;) {
|
||||||
|
wait_frame(); drain_keys(); rnd();
|
||||||
|
j = joy;
|
||||||
|
if (j & J_ESC) return 0;
|
||||||
|
if (j & (J_FIRE | J_ENTER)) return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static u8 title(void)
|
||||||
|
{
|
||||||
|
u8 i;
|
||||||
|
clear_gfx();
|
||||||
|
puts_("\033[0m\033[2J");
|
||||||
|
for (i = 0; i < 20; i++) { draw_tile(i, 0, T_WALL); draw_tile(i, 13, T_WALL); }
|
||||||
|
for (i = 1; i < 13; i++) { draw_tile(0, i, T_WALL); draw_tile(19, i, T_WALL); }
|
||||||
|
draw_tile(9, 13, T_DOOR); draw_tile(10, 13, T_DOOR);
|
||||||
|
spr_at(0, 120, 168); spr_show(0, S_PDOWN, 1);
|
||||||
|
spr_at(1, 152, 168); spr_show(1, S_CROWN, 1);
|
||||||
|
spr_at(2, 184, 168); spr_show(2, S_GSIDE, 3);
|
||||||
|
spr_at(3, 72, 168); spr_show(3, S_GSIDE, 1);
|
||||||
|
ink("1;93"); centre(7, "T H E I R O N K E E P");
|
||||||
|
ink("0;37");
|
||||||
|
centre(10, "You are a prisoner in the Iron Keep. Steal the king's crown");
|
||||||
|
centre(11, "from the throne room, and escape down the stairs.");
|
||||||
|
centre(14, "ARROWS or W A S D move SPACE or CTRL shoot");
|
||||||
|
centre(15, "Keys open locked doors. Chests hold gold, crates hold shots.");
|
||||||
|
centre(16, "Guards see along rows and columns - and they shoot.");
|
||||||
|
centre(17, "P pauses. ESC gives up.");
|
||||||
|
ink("1;96"); centre(25, "PRESS SPACE TO BEGIN");
|
||||||
|
ink("0");
|
||||||
|
return wait_fire();
|
||||||
|
}
|
||||||
|
|
||||||
|
static u8 end_screen(void)
|
||||||
|
{
|
||||||
|
u16 score = gold + kills * 50;
|
||||||
|
u8 j;
|
||||||
|
if (won) score += 1000 + 500 + lives * 200;
|
||||||
|
else if (crown) score += 1000;
|
||||||
|
clear_gfx(); /* a clean box: no walls or figures behind it */
|
||||||
|
ink("0;44;97");
|
||||||
|
centre(12, " ");
|
||||||
|
centre(13, won ? " YOU ESCAPED WITH THE CROWN! " :
|
||||||
|
" THE GUARDS HAVE TAKEN YOU. ");
|
||||||
|
centre(14, " ");
|
||||||
|
at(15, 21); puts_(" SCORE "); putn(score);
|
||||||
|
for (j = 10 + (score > 9) + (score > 99) + (score > 999) + (score > 9999); j < 40; j++) putch(' ');
|
||||||
|
centre(16, " ");
|
||||||
|
centre(17, " SPACE TO PLAY AGAIN, ESC TO STOP ");
|
||||||
|
centre(18, " ");
|
||||||
|
ink("0");
|
||||||
|
return wait_fire();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------- game */
|
||||||
|
static void play(void)
|
||||||
|
{
|
||||||
|
u8 j, i;
|
||||||
|
const u8 *o = room_objs[0];
|
||||||
|
for (i = 0; i < 12; i++) { gone[i] = 0; opened[i] = 0; }
|
||||||
|
lives = 3; keys = 0; ammo = 10; gold = 0; kills = 0; crown = 0;
|
||||||
|
over = 0; won = 0; inv = 0; fire_cool = 0; fire_held = 1; panim = 0;
|
||||||
|
msg = 0; msg_time = 0; pdir = D_DOWN;
|
||||||
|
room = 0;
|
||||||
|
for (; *o; o += 3)
|
||||||
|
if (o[0] == 'P') { px = o[1] << 4; py = 16 + (o[2] << 4); }
|
||||||
|
puts_("\033[2J");
|
||||||
|
enter_room();
|
||||||
|
say("FIND THE CROWN. MIND THE GUARDS.");
|
||||||
|
while (!over) {
|
||||||
|
wait_frame();
|
||||||
|
if (drain_keys()) { /* P: pause until P again */
|
||||||
|
at(1, 40); ink("0;96"); puts_("PAUSED - P TO GO ON\033[K"); ink("0");
|
||||||
|
for (;;) {
|
||||||
|
wait_frame();
|
||||||
|
if (joy & J_ESC) { quit = 1; return; }
|
||||||
|
if (drain_keys()) break;
|
||||||
|
}
|
||||||
|
status_dirty = 1;
|
||||||
|
}
|
||||||
|
j = joy;
|
||||||
|
if (j & J_ESC) { over = 1; won = 0; break; }
|
||||||
|
move_player(j);
|
||||||
|
edges();
|
||||||
|
fire(j);
|
||||||
|
shots();
|
||||||
|
guards();
|
||||||
|
pick_up();
|
||||||
|
draw_player();
|
||||||
|
if (inv) inv--;
|
||||||
|
if (fire_cool) fire_cool--;
|
||||||
|
if (msg_time && !--msg_time) status_dirty = 1;
|
||||||
|
if (status_dirty) status();
|
||||||
|
}
|
||||||
|
status();
|
||||||
|
for (i = 0; i < 60; i++) { wait_frame(); drain_keys(); draw_player(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
void main(void)
|
||||||
|
{
|
||||||
|
rnd_state = 0xACE1 ^ frame_ctr;
|
||||||
|
last_frame = frame_ctr;
|
||||||
|
puts_("\033[?3l\033[?25l"); /* 80 columns (this clears), no cursor */
|
||||||
|
load_shapes();
|
||||||
|
quit = 0;
|
||||||
|
while (!quit) {
|
||||||
|
if (!title()) break;
|
||||||
|
play();
|
||||||
|
if (quit) break;
|
||||||
|
if (!end_screen()) break;
|
||||||
|
}
|
||||||
|
clear_gfx();
|
||||||
|
puts_("\033[0m\033[2J\033[H\033[?25h");
|
||||||
|
while (con_stat & 1) (void)con_data;
|
||||||
|
}
|
||||||
@@ -0,0 +1,432 @@
|
|||||||
|
:198600002100D001FB0178B1280C36000B78B12805545D13EDB0C315BB8B
|
||||||
|
:208620004FDB00CB4F28FA79D301C9000003333330000000003333333300000000399999EE
|
||||||
|
:20864000930000000039099093000000000999999000000000000990000000000CCCCCCC4E
|
||||||
|
:20866000CCC00000CCCCCCCCCCCC00009CCCCCCCCCC900009CCCCCCCCCC9000000CCCCCC18
|
||||||
|
:20868000CC0000000044444444000000004440044400000000444004440000000077700778
|
||||||
|
:2086A000770000000000000000000000000333333000000000333333330000000039999973
|
||||||
|
:2086C000930000000039099093000000000999999000000000000990000000000CCCCCCCCE
|
||||||
|
:2086E000CCC00000CCCCCCCCCCCC00009CCCCCCCCCC900009CCCCCCCCCC9000000CCCCCC98
|
||||||
|
:20870000CC00000000444444440000000004400440000000000440044000000000077007EF
|
||||||
|
:208720007000000000000000000000000003333330000000003333333300000000333333CB
|
||||||
|
:20874000330000000033333333000000000333333000000000000990000000000CCCCCCC78
|
||||||
|
:20876000CCC00000CCCCCCCCCCCC00009CCCCCCCCCC900009CCCCCCCCCC9000000CCCCCC17
|
||||||
|
:20878000CC0000000044444444000000004440044400000000444004440000000077700777
|
||||||
|
:2087A000770000000000000000000000000333333000000000333333330000000033333344
|
||||||
|
:2087C000330000000033333333000000000333333000000000000990000000000CCCCCCCF8
|
||||||
|
:2087E000CCC00000CCCCCCCCCCCC00009CCCCCCCCCC900009CCCCCCCCCC9000000CCCCCC97
|
||||||
|
:20880000CC00000000444444440000000004400440000000000440044000000000077007EE
|
||||||
|
:20882000700000000000000000000000000333333000000000333333330000000033339964
|
||||||
|
:2088400099000000003339909900000000033999990000000000099900000000000CCCCC36
|
||||||
|
:20886000C000000000CCCCCCCC00000000CCCCC99900000000CCCCCC00000000000CCCCC06
|
||||||
|
:208880000000000000044444400000000004400440000000004440004400000000777000D5
|
||||||
|
:2088A0007700000000000000000000000003333330000000003333333300000000333399DD
|
||||||
|
:2088C00099000000003339909900000000033999990000000000099900000000000CCCCCB6
|
||||||
|
:2088E000C000000000CCCCCCCC00000000CCCCC99900000000CCCCCC00000000000CCCCC86
|
||||||
|
:2089000000000000000444444000000000004444000000000000444400000000000077778D
|
||||||
|
:2089200000000000000000000000000000077777700000000077777777000000007999994B
|
||||||
|
:2089400097000000007909909700000000099999900000000000099000000000022222220B
|
||||||
|
:208960002220000022222222222200009222222222290000922222222229000000222222FD
|
||||||
|
:208980002200000000888888880000000088800888000000008880088800000000333003FF
|
||||||
|
:2089A000330000000000000000000000000777777000000000777777770000000079999998
|
||||||
|
:2089C00097000000007909909700000000099999900000000000099000000000022222228B
|
||||||
|
:2089E00022200000222222222222000092222222222900009222222222290000002222227D
|
||||||
|
:208A00002200000000888888880000000008800880000000000880088000000000033003BE
|
||||||
|
:208A2000300000000000000000000000000777777000000000777777770000000077777760
|
||||||
|
:208A400077000000007777777700000000077777700000000000099000000000022222225D
|
||||||
|
:208A60002220000022222222222200009222222222290000922222222229000000222222FC
|
||||||
|
:208A80002200000000888888880000000088800888000000008880088800000000333003FE
|
||||||
|
:208AA0003300000000000000000000000007777770000000007777777700000000777777DD
|
||||||
|
:208AC0007700000000777777770000000007777770000000000009900000000002222222DD
|
||||||
|
:208AE00022200000222222222222000092222222222900009222222222290000002222227C
|
||||||
|
:208B00002200000000888888880000000008800880000000000880088000000000033003BD
|
||||||
|
:208B200030000000000000000000000000077777700000000077777777000000007777993D
|
||||||
|
:208B40009900000000777990990000000007799999000000000009990000000000022222C9
|
||||||
|
:208B600020000000002222222200000000222229990000000022222200000000000222229B
|
||||||
|
:208B800000000000000888888000000000088008800000000088800088000000003330003A
|
||||||
|
:208BA0003300000000000000000000000007777770000000007777777700000000777799BA
|
||||||
|
:208BC000990000000077799099000000000779999900000000000999000000000002222249
|
||||||
|
:208BE00020000000002222222200000000222229990000000022222200000000000222221B
|
||||||
|
:208C0000000000000008888880000000000088880000000000008888000000000000333336
|
||||||
|
:208C2000000000000000000000000000000000000000000000000000000000000000000034
|
||||||
|
:208C4000000000000000000000000000000000000000000000000000000000000000BBBB9E
|
||||||
|
:208C6000000000000000BBBB000000000000BBBB000000000000BBBB000000000000000092
|
||||||
|
:208C80000000000000000000000000000000000000000000000000000000000000000000D4
|
||||||
|
:208CA0000000000000000000000000000000000000000000000000000000000000000000B4
|
||||||
|
:208CC000000000000000000000000000000000000000000000000000000000000000999962
|
||||||
|
:208CE0000000000000009999000000000000999900000000000099990000000000000000DE
|
||||||
|
:208D0000000000000000000000000000000000000000000000000000000000000000000053
|
||||||
|
:208D2000000000000000000000000000000000000000000000000000000000000000000033
|
||||||
|
:208D4000000000000BBB000000000000B000B00000000000B000BBBBBBBBB000B000B00041
|
||||||
|
:208D60000B0B00000BBB00000B0B0000000000000000000000000000000000000000000001
|
||||||
|
:208D80000000000000000000000000000000000000000000000000000000000000000000D3
|
||||||
|
:208DA0000000000000000000000000000000000000000000000000000000000000000000B3
|
||||||
|
:208DC00000000000033333333330000033333333333300003BBBBBBBBBB3000033333BB334
|
||||||
|
:208DE0003333000033333BB333330000333333333333000033333333333300003BBBBBBB83
|
||||||
|
:208E0000BBB3000033333333333300000000000000000000000000000000000000000000B2
|
||||||
|
:208E2000000000000000000000000000000000000000000000000000000000000000000032
|
||||||
|
:208E4000000000002222222222220000288888888882000028BB8BB8BB82000028BB8BB8F3
|
||||||
|
:208E6000BB82000028BB8BB8BB8200002888888888820000222222222222000000000000BC
|
||||||
|
:208E80000000000000000000000000000000000000000000000000000000000000000000D2
|
||||||
|
:208EA0000000000000000000000000000000000000000000000000000000000000000000B2
|
||||||
|
:208EC000000000000B000BB000B000000BB0BBBB0BB000000BBBBBBBBBB000000BB9BBBB4F
|
||||||
|
:208EE0009BB000000BBBBCCBBBB000000BBBBBBBBBB0000000000000000000000BBBBBBB8C
|
||||||
|
:208F0000BBB0000000000000000000000000000000000000000000000000000000000000E6
|
||||||
|
:208F200000000000000000000000000000000000000000000F00000000F0000000F00BB087
|
||||||
|
:208F40000F000000000F0BB0F00000000000BFFB0000000BBB0BFFFFB0BBB0000000BFFBEA
|
||||||
|
:208F600000000000000F0BB0F000000000F00BB00F0000000F00000000F00000000000007E
|
||||||
|
:208F80000000000000000000000000000000000000000000000000000000000000000000D1
|
||||||
|
:208FA0000000000000000000000000000000000000000000000000000000000000000000B1
|
||||||
|
:208FC000000000000000000000000000000000000000000000000000000000000000000091
|
||||||
|
:208FE000000000000000000000000000000000000000000000000000000000000000000071
|
||||||
|
:20900000000000000000000000000000000000000000000000000000000000000000000050
|
||||||
|
:20902000000000000000000000000000000000000000000000000000000000000000000030
|
||||||
|
:20904000000000000000000000000000000000000000000000000000000000000000000010
|
||||||
|
:209060000000000000000000000000000000000000000000000000000000000000000000F0
|
||||||
|
:209080000000000000000000000000000000000000000000000000000000000000000000D0
|
||||||
|
:2090A00000000000000000000000000808080808080808080808080808080807070707070D
|
||||||
|
:2090C0000707080707070707070708070707070707070807070707070707080707070707AC
|
||||||
|
:2090E00007070807070707070707080808080808080808080808080808080807070708077D
|
||||||
|
:2091000007070707070708070707070707070807070707070707080707070707070708076B
|
||||||
|
:2091200007070707070708070707070808080808080808080808080808080807070707073E
|
||||||
|
:2091400007070807070707070707080707070707070708070707070707070807070707072B
|
||||||
|
:209160000707080707070707070708080808080808080808080808080808080707070807FC
|
||||||
|
:209180000707070707070807070707070707080707070707070708070707070707070807EB
|
||||||
|
:2091A0000707070707070807070707080808080808080808080808080808080803030308C8
|
||||||
|
:2091C0000303030803030308030308080303030803030308030303080303080803030308FD
|
||||||
|
:2091E0000303030803030308030308080303030803030308030303080303080803030308DD
|
||||||
|
:209200000303030803030308030308080303030803030308030303080303080803030308BC
|
||||||
|
:2092200003030B0B03030308030308080303030803030B0B03030308030308080303030886
|
||||||
|
:2092400003030308030303080303080803030308030303080303030803030808030303087C
|
||||||
|
:2092600003030308030303080303080803030308030303080303030803030808030303085C
|
||||||
|
:2092800003030308030303080303080803030308030303080303030803030808080808082D
|
||||||
|
:2092A00008080808080808080808080E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E060606060658
|
||||||
|
:2092C0000606060606060606060606080808080808080808080808080808080000000000CC
|
||||||
|
:2092E00000000000000000000000000E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E060606060670
|
||||||
|
:2093000006060606060606060606060808080808080808080808080808080800000000008B
|
||||||
|
:2093200000000000000000000000000E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E06060606062F
|
||||||
|
:2093400006060606060606060606060808080808080808080808080808080800000000004B
|
||||||
|
:2093600000000000000000000000000E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0606060606EF
|
||||||
|
:2093800006060606060606060606060808080808080808080808080808080800000000000B
|
||||||
|
:2093A0000000000000000000000000111111111111111111110100000000000000001001F1
|
||||||
|
:2093C000000000000000000010010000000000000000100100101101001011011001001006
|
||||||
|
:2093E000000000000001100100100000000000010001001000000000000100010010110115
|
||||||
|
:209400000010110110010000000000000000100100000000000000001001000000000000F7
|
||||||
|
:209420000000100100000000000000001011111111001111111111111111111111111111D9
|
||||||
|
:209440001101000000000000000010010000000000000000100100000000000000001001C7
|
||||||
|
:20946000101100000010110010011000000000001000100010000000000010000000100039
|
||||||
|
:20948000000000001000000110110000001011001001000000000000000010010000000057
|
||||||
|
:2094A000000000001001000000000000000010010000000000000000101111111111111103
|
||||||
|
:2094C00011111111111111111111111111010000000000000000100100000000000000009D
|
||||||
|
:2094E0001001000000000000000010010000101111010000100100001000100000001000D6
|
||||||
|
:209500000000100020000000000000001011110000000001000000000000000010010000D7
|
||||||
|
:209520000000000000001001000000000000000010010000000000000000100100000000F8
|
||||||
|
:209540000000000010111111111111111111111111111111111111111101000000000000A6
|
||||||
|
:20956000000010010000000000000000100100000000000000001001111100000010110174
|
||||||
|
:20958000100100000000000000001000000000000000000010000000000000000000100189
|
||||||
|
:2095A000111100000010110110010000000000000000100100000000000000001001000034
|
||||||
|
:2095C00000000000000010010000000000000000101111111100111111111111111111008D
|
||||||
|
:2095E0001111111111010000000000000000100100000000111100001001000000000100D0
|
||||||
|
:209600000000100100000000010000001011111111000100000010010000000000000000D2
|
||||||
|
:2096200000010000000000000000001111111100111111111001000000000100000010017E
|
||||||
|
:209640000000000001000000100100000000010000001001000000000000000010111111A3
|
||||||
|
:209660001100111111111111111111111111111111010000000000000000100100000000C8
|
||||||
|
:20968000000000001001000000000000000010010010010000100100100100100100001054
|
||||||
|
:2096A000010010000000000000000000000000000000000000000001001001000010010076
|
||||||
|
:2096C000100100100100001001001001000000000000000010010000000000000000100124
|
||||||
|
:2096E000000000000000000010111111110011111111111111111111111111111101000115
|
||||||
|
:209700000000000100001001000111110101111110010001010000010010100100000111A9
|
||||||
|
:2097200011110110101111110101000001101000000000010000010000001111110100005A
|
||||||
|
:20974000110100010100000011010000100101111111010111111001010000000001010066
|
||||||
|
:209760001001111101111101010010010000000100000001101111111111111111111111B3
|
||||||
|
:209780001111110011111111110100000000000000001001111001111001111010010000B9
|
||||||
|
:2097A000000000000000100111100111100111101001000000000000000010000000000012
|
||||||
|
:2097C0000000000010001110011110011110100100000000000000001001111001111001AE
|
||||||
|
:2097E000111010010000000000000000100100000000000000001001000000000000000015
|
||||||
|
:209800001011111111001111111111111111110011111111110100000000000000001001F4
|
||||||
|
:2098200000000000000000001001101111011011110110011000000000000001100110006E
|
||||||
|
:20984000003003000001100110000030030000010001100000000000000100011011110139
|
||||||
|
:20986000101111011001000000000000000010010000000000000000100100000000000082
|
||||||
|
:20988000000010010000000000000000101111111111111111111111111111001111111175
|
||||||
|
:2098A0001101011000011000011010010110000110000110100101100001100001101001CA
|
||||||
|
:2098C000111011011011011110010000000000000000100000000000000000000000000001
|
||||||
|
:2098E00000000000000000011110110110110111100101100001100001101001011000019A
|
||||||
|
:2099000010000110100101100001100001101001000000000000000010111111111111114A
|
||||||
|
:20992000111111111111111111111111110100000000000000001001000000000000000038
|
||||||
|
:2099400010010000000000000000100100001111111111001001000001000000100010005E
|
||||||
|
:2099600000000100000010001000000011111112110010010000000000000000100100004E
|
||||||
|
:20998000000000000000100100000000000000001001000000000000000010010000000094
|
||||||
|
:2099A0000000000010111111111111111111111111111100111111111111111111121111DC
|
||||||
|
:2099C000111111010000000000000000100100000000000000001001000000000000000031
|
||||||
|
:2099E0001001001111000011110010010001000000001000100100010000000010001001BD
|
||||||
|
:209A00000001000000001000100100111100001111001001000000000000000010010000BE
|
||||||
|
:209A20000000000000001001000000000000000010111111111111111111115003024109BC
|
||||||
|
:209A4000060000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
:209A60000000000000000000000000006802024B0906680C0A0000000000000000000000A2
|
||||||
|
:209A800000000000000000000000000000000000000000000000000000000000007602024C
|
||||||
|
:209AA000760D02470805470A0568050A000000000000000000000000000000000000000000
|
||||||
|
:209AC000000000000000000000000000000041030241100268090663080B00000000000000
|
||||||
|
:209AE0000000000000000000000000000000000000000000000000000000000000000076F0
|
||||||
|
:209B00000202680F0441030A760F0B000000000000000000000000000000000000000000E8
|
||||||
|
:209B200000000000000000000000000000000000470302471002680905680A0963020B76A9
|
||||||
|
:209B40000E0B000000000000000000000000000000000000000000000000000000000000EC
|
||||||
|
:209B600000410B0668100B0000000000000000000000000000000000000000000000000010
|
||||||
|
:209B8000000000000000000000000000000000000000680B054B090A76040B00000000006A
|
||||||
|
:209BA0000000000000000000000000000000000000000000000000000000000000000000A5
|
||||||
|
:209BC00000000068050A00000000000000000000000000000000000000000000000000000E
|
||||||
|
:209BE00000000000000000000000000000000000000000007609064B030A470D0A0000002A
|
||||||
|
:209C0000000000000000000000000000000000000000000000000000000000000000000044
|
||||||
|
:209C20000000000000680302470705470A05470E05760A0A0000000000000000000000002A
|
||||||
|
:209C400000000000000000000000000000000000000000000000630203631103430907765C
|
||||||
|
:209C6000020B76110B00000000000000000000000000000000000000000000000000000045
|
||||||
|
:209C800000000000000000A79CB19CBC9CC39CCB9CD49CDF9CE79CEF9CF99C019D0A9D0043
|
||||||
|
:209CA00000FF0101FF000047415445484F55534500475541524420524F4F4D004348415013
|
||||||
|
:209CC000454C0041524D4F55525900434F525249444F520047524541542048414C4C004369
|
||||||
|
:209CE000454C4C415253004C49425241525900535441495257454C4C0044554E47454F4EC5
|
||||||
|
:209D0000005452454153555259005448524F4E4520524F4F4D007EB7C823E5CD2086E11826
|
||||||
|
:209D2000F5DDE5DD210000DD39F5F5F53B4D44DD36FF00DD5EFF16002100003919DD34FFC8
|
||||||
|
:209D4000E5C5110A006960CDC5BBC1E17BC63077110A006960CD85BB4B4278B120D5DD4ED7
|
||||||
|
:209D6000FF79B728110D59160021000039197EC5CD2086C118EBDDF9DDE1C967E53E1BCD43
|
||||||
|
:209D800020863E5BCD2086E1AFE56C67CD219D3E3BCD2086E12600CD219D3E48C32086E5EC
|
||||||
|
:209DA0003E1BCD20863E5BCD2086E1CD169D3E6DC32086470E00692600197EB728030C18D5
|
||||||
|
:209DC000F52E00CB2DCB193E2991D56F78CD7B9DD1EBC3169D2AF7D1292929292929293A6E
|
||||||
|
:209DE000F7D1AD32F7D13AF8D1AC32F8D1CB3F4F3AF7D1A932F7D121F8D1AE32F8D1ED5B71
|
||||||
|
:209E0000F7D1C9DB7821EFD19628F8DB7832EFD1C90E00DB000F300EDB01FE702804D650E7
|
||||||
|
:209E200020F10E0118ED79C9AFD334DB340F38FBC9DDE5DD210000DD39F53B474D11AB8F06
|
||||||
|
:209E4000DD66042E0019EB68260029292929E37987878787C610DD77FFDD4EFE0600DD7E2C
|
||||||
|
:209E6000FDD33079D33178DD86FFD332AFF51AD333F1133CFE1038F50478D61038E0DDF9F7
|
||||||
|
:209E8000DDE1E133E9D3707BD3717AE601D372FD210200FD39FD7E00D373E1F1E9D3707DCD
|
||||||
|
:209EA000D374FD210200FD39FD7E00D375E133E9D370AFD375C9012B861E007BD376160098
|
||||||
|
:209EC0000AD37703147AD68038F61C7BD61338EBC94D44CB78201B3E3FB93E019838137BCB
|
||||||
|
:209EE000D6107A173F1FDE8038083EEFBB3E009A30033EFFC97BC6F05F7ACEFF573E04CBBB
|
||||||
|
:209F00002ACB1B3D20F9576B6229291929291100D01959500604CB2ACB1B10FA1600197EBB
|
||||||
|
:209F2000C9DDE5DD210000DD39F5F54D44DD73FDDD72FEDD36FC00DD36FF00DD6EFF2600DC
|
||||||
|
:209F400011E39F195E1600DD7EFD835FDD7EFE8A573EDFDD86FF6F3E9FCE00676E260009D0
|
||||||
|
:209F6000C5CDD19E5FC17B3D28057BD602204A3EDFDD86FC6F3E9FCE00676E26000906047A
|
||||||
|
:209F8000CB2CCB1D10FA7D32F9D13EE3DD86FC6F3E9FCE00674E0600DD6EFDDD66FE097DFB
|
||||||
|
:209FA000C6F06F7CCEFF670604CB2CCB1D10FAFD21FAD1FD75007B181F1C200ADD7E04B770
|
||||||
|
:209FC00028043E011812DD34FFDD7EFFDD77FCDD7EFFD604DA3B9FAFDDF9DDE1E133E90307
|
||||||
|
:209FE0000C030C02020E0EDDE5DD210000DD39F53B5F553A18D14F0600696029292929097E
|
||||||
|
:20A000002909292901AB93094D446A2600D55D542929192929D1160019E3DD36FF002100FA
|
||||||
|
:20A02000007DDD96FD7CDD9EFE30285D54CB3ACB1B7B815F7A88571ACB452809070707071F
|
||||||
|
:20A04000E60F5F1803E60F5F7BD6022003DD34FF2318CEDD7EFFDDF9DDE1C922F5D121F2FC
|
||||||
|
:20A06000D136B421F1D13601C9AF32F1D13E016FCD7B9D215FA1CD9F9D2164A1CD169D211B
|
||||||
|
:20A0800072A1CD9F9D2177A1CD169D01879C3A18D126006F29097E23666FCD169D217BA1AA
|
||||||
|
:20A0A000CD169D3AF6D121F5D1B628193AF2D1B728132E283E01CD7B9D217FA1CD9F9D2A64
|
||||||
|
:20A0C000F5D1CD169D2E013E02CD7B9D2172A1CD9F9D2184A1CD169D218BA1CD9F9D3A4A09
|
||||||
|
:20A0E000D126006FCD219D2172A1CD9F9D2190A1CD169D218BA1CD9F9D3A4BD126006FCD52
|
||||||
|
:20A10000219D2172A1CD9F9D2199A1CD169D218BA1CD9F9D3A4CD126006FCD219D2172A168
|
||||||
|
:20A12000CD9F9D21A2A1CD169D218BA1CD9F9D2A4ED1CD219D2172A1CD9F9D3A4DD1B72894
|
||||||
|
:20A14000122177A1CD169D215FA1CD9F9D21ABA1CD169D217BA1CD169D21B1A1C39F9D30BE
|
||||||
|
:20A160003B3933005448452049524F4E204B45455000303B333700202020001B5B4B003094
|
||||||
|
:20A180003B3936004C495645532000303B3937002020204B4559532000202020414D4D4F51
|
||||||
|
:20A1A0002000202020474F4C44200043524F574E003000CDB4BB21F4FF39F901AB93FD2141
|
||||||
|
:20A1C00018D1FD5E0016006B6229292929192919292909DD75FADD74FB013B9AFD5E00161F
|
||||||
|
:20A1E000006B622919292929291909E3DD36FF00CD289EDD36FE000E00DD5EFE16006B62C7
|
||||||
|
:20A2000029291929291100D019DD75FCDD74FDDD6EFADD66FB4623DD7EFC815FDD7EFDCEA2
|
||||||
|
:20A22000005778E60F12793CDD86FC5F3E00DD8EFD577807070707E60F120C0C79D614388A
|
||||||
|
:20A24000D4DD75FADD74FBDD34FEDD7EFED60E38A6DD36FD00DD4EFD0600696029290929DD
|
||||||
|
:20A2600029EB2100D019DD75F6DD74F7DD7EFFDD77FEDD36FF00DD7EFFDD86F6DD77F83E35
|
||||||
|
:20A2800000DD8EF7DD77F9DD6EF8DD66F97EDD77FAD60220383E312118D186DD77FB3ED137
|
||||||
|
:20A2A000CE00DD77FCDD6EFBDD66FC7EDD46FE2101000418012910FDDD34FEA50E00B1284C
|
||||||
|
:20A2C0000CDD6EF8DD66F93600DD36FA00DD7EFAB7280EDD7EFAF533DD6EFDDD7EFFCD3151
|
||||||
|
:20A2E0009EDD34FFDD7EFFD614388BDD7EFEDD77FFDD34FDDD7EFDD60EDA55A20E00692645
|
||||||
|
:20A30000001170D11936000C79D60638F10E0069260011B6D11936000C79D60838F1DD36EF
|
||||||
|
:20A32000FC00DD36FD00DD7EF4DD77FEDD7EF5DD77FFDD36FB00DD6EFEDD66FF7EDD77FA68
|
||||||
|
:20A34000B7CA3BA53A18D126006F291119D1197E235EDD46FB2101000418012910FDA54F21
|
||||||
|
:20A360007BA4B1C228A5DD4EFA79D6763E012801AF47DD7EFEC601DD77F9DD7EFFCE00DDC4
|
||||||
|
:20A3800077FADD7EFEC602DD77F5DD7EFFCE00DD77F679D668280A78B7200679D663C25569
|
||||||
|
:20A3A000A4DD6EFD260029DD75F7DD74F83E52DD86F75F3ED1DD8EF857DD6EF9DD66FA6ECF
|
||||||
|
:20A3C0002600292929297D12137C123E5EDD86F75F3ED1DD8EF857DD6EF5DD66F66E260058
|
||||||
|
:20A3E00029292929D511100019D17D12137C123E76DD86FD6F3ED1CE0067713E70DD86FD63
|
||||||
|
:20A400006F3ED1CE006736013E82DD86FD6F3ED1CE006736003E88DD86FD5F3ED1CE005790
|
||||||
|
:20A42000DD7EFB123E6ADD86FD5F3ED1CE005778B72803AF18023E03123E7CDD86FD4F3EFC
|
||||||
|
:20A44000D1CE0047C5CDD59DC17BE61FC61E02DD34FDC328A579D650CA28A5DD5EFC1600CA
|
||||||
|
:20A46000EB29EB218ED119DD75F7DD74F8DD6EF9DD66FA6E260029292929DD75F9DD74FA63
|
||||||
|
:20A48000DD6EF7DD66F8DD7EF97723DD7EFA77219ED119EBDD6EF5DD66F66E260029292969
|
||||||
|
:20A4A000297DC610DD77F97CCE00DD77FA6B62DD7EF97723DD7EFA773EAEDD86FC6F3ED1EB
|
||||||
|
:20A4C000CE0067713EB6DD86FC6F3ED1CE006736013EBEDD86FC6F3ED1CE0067DD7EFB77BE
|
||||||
|
:20A4E000EB5E2356DD6EF7DD66F87E23666FDD7EFCC60DDD77FAC5EBE5DD7EFACD859EC194
|
||||||
|
:20A5000079D64B20042E0E181279D64720042E0F180979D6412E1028022E113E01F533DD84
|
||||||
|
:20A520007EFACD9D9EDD34FCDD7EFEC603DD77FE3003DD34FFDD34FBC336A30E0021E0D14F
|
||||||
|
:20A5400006000936000C79D60238F20E0021E6D106000936000C79D60438F2AF32EAD12AB5
|
||||||
|
:20A560003DD12241D12A3FD12243D121F1D13601DDF9DDE1C92A3DD1232323CB7C280D2174
|
||||||
|
:20A5800018D135213001223DD1C3B3A12A3DD1110C00193E3FBD3E019CE29EA5EE80F2AE4E
|
||||||
|
:20A5A000A52118D134210000223DD1C3B3A1ED4B3FD103033A18D15F79D61078173F1FDE56
|
||||||
|
:20A5C0008030102118D17BC6FC7721E000223FD1C3B3A12A3FD1010E00093EEFBD3E009C9D
|
||||||
|
:20A5E000E2E5A5EE80F07BC6043218D1211000223FD1C3B3A13A4BD1B720062156A6C35B49
|
||||||
|
:20A60000A0214BD1350131D13A18D16F2600094EE5C53AFAD16F3AF9D1CDE79FC1E1473E7A
|
||||||
|
:20A62000010418018710FDB1770100D03AFAD15F16006B622929192929093AF9D15F1600E9
|
||||||
|
:20A64000193600AFF5333AFAD16F3AF9D1CD319E216EA6C35BA04C4F434B45442E20594F25
|
||||||
|
:20A6600055204E4545442041204B45592E00544845204B4559205455524E532E20544845DC
|
||||||
|
:20A6800020444F4F52204F50454E532E00CDB4BB3B4F060079E60CDD77FFB7284279E60485
|
||||||
|
:20A6A0005F16007AB33E0220023E033245D17AB3280511FEFF18031102002A3DD119E5C57C
|
||||||
|
:20A6C000AFF533ED5B3FD1CD219FC1E1B72007223DD106011809D6022005C5CDF5A5C17983
|
||||||
|
:20A6E000E603284779E6015F1600DD7EFFB7200A7AB33E012001AF3245D17AB3280511FE05
|
||||||
|
:20A70000FF18031102002A3FD119E5C5AFF533EB2A3DD1CD219FC1E1B72007223FD10601CF
|
||||||
|
:20A720001809D6022005C5CDF5A5C178B728042146D13433DDE1C9CDB4BBF53BCB672007C8
|
||||||
|
:20A74000AF3248D1C326A83A48D1B7C226A83A47D1B7C226A82148D136013A4CD1B7200993
|
||||||
|
:20A76000212BA8CD5BA0C326A8DD36FD001E006B260001E0D1097EB7C21CA8360101DED170
|
||||||
|
:20A78000DD6EFD2600093A45D177DD6EFD2600294D4421C6D109DD75FEDD74FF3A3DD1C6E4
|
||||||
|
:20A7A000085F3A3ED1CE00573E9FFD2145D1FD86006F3E9CCE00677E6F079F67D55D542909
|
||||||
|
:20A7C0001929D119EBDD6EFEDD66FF73237221CAD109EB3A3FD1C6084F3A40D1CE00473E1A
|
||||||
|
:20A7E000A3FD86006F3E9CCE00677E6F079F67D55D54291929D1097D12137C12FD214CD185
|
||||||
|
:20A80000FD35003E083247D13E0132F1D1DD7EFD3C2601E5332E0CCD9D9E180A1CDD73FDA3
|
||||||
|
:20A820007BD602DA6FA7DDF9DDE1C94F5554204F4620414D4D554E4954494F4E21003A4906
|
||||||
|
:20A84000D1B7C03AF3D1B7C021EAD1361E2A3DD122EBD12A3FD122EDD1214AD1353A4AD115
|
||||||
|
:20A86000B7200A21F3D13601AF32F4D1C9219DA8CD5BA02A41D1223DD12A43D1223FD12141
|
||||||
|
:20A8800049D136780E0021E6D1060009360079C609C5CDB09EC10C79D60438EAC9594F5595
|
||||||
|
:20A8A00020415245204849542100DDE5DD210000DD39F54D44030303DD7E04C60CDD77FE92
|
||||||
|
:20A8C000DD7E05CE00DD77FFDD7EFE91DD7EFF98E2D5A8EE80FA27A9DD4E04DD4605030327
|
||||||
|
:20A8E00003D5110C0019D17D917C98E2F0A8EE80FA27A94B420303DD7E06C60E6FDD7E070C
|
||||||
|
:20A90000CE00677D917C98E20CA9EE80FA27A9DD4E06DD46070303210E00197D917C98E264
|
||||||
|
:20A9200024A9EE80F22AA9AF18023E01C1DDE1E1C1C1E9CDB4BBF53BDD36FF00DD7EFFC6A6
|
||||||
|
:20A94000B64F3E00CED1470AB7CA12AADD5EFF1600EB29EB219ED1197EDD77FD237EDD77CB
|
||||||
|
:20A96000FE218ED1195E2356C5DD6EFDDD66FEE5D5ED5B3FD12A3DD1CDAAA8C1B7CA12AAB4
|
||||||
|
:20A98000AF023A18D126006F291119D1194E23462B3EBEDD86FF5F3ED1CE00571AF511011D
|
||||||
|
:20A9A00000F13C1803EB29EB3D20FA79B34F78B247712370DD7EFFC60DCDB09E3EAEDD8672
|
||||||
|
:20A9C000FF6F3ED1CE00677EFE41282BFE432837FE472810D64B203A214BD134215BAACDB9
|
||||||
|
:20A9E0005BA0182E214ED17EC66477300223342162AACD5BA0181B3A4CD1C605324CD12174
|
||||||
|
:20AA000074AACD5BA0180B214DD136012185AACD5BA0DD34FFDD7EFFD608DA3CA93A3FD14E
|
||||||
|
:20AA2000C6085F3A40D1CE00572A3DD101080009CDD19ED603201F3A4DD1B7280C21F3D1B3
|
||||||
|
:20AA4000360121F4D13601180D3AF2D1D678300621A5AACD5BA0DDF9DDE1C941204B45591D
|
||||||
|
:20AA60002100474F4C4421203130302043524F574E532E0046495645204D4F52452053485B
|
||||||
|
:20AA80004F54532E005448452043524F574E21204E4F572046494E44205448452053544189
|
||||||
|
:20AAA0004952532E004E4F5420574954484F5554205448452043524F574E2E00CDB4BB2100
|
||||||
|
:20AAC000F6FF39F94F2152D10600CB21CB10095E235621080019EB215ED1097E2346C608D4
|
||||||
|
:20AAE0004F3001043A3DD1C608DD77F83A3ED1CE00DD77F93A3FD1C608DD77FA3A40D1CE8D
|
||||||
|
:20AB000000DD77FB79DD96FADD77FC78DD9EFBDD77FD79C6F06F78CEFF673333D53E04DDCD
|
||||||
|
:20AB2000CBF72EDDCBF61E3D20F53E04CB2CCB1D3D20F9DD7EF6DD77FEDD75FF3EF8DDBEDB
|
||||||
|
:20AB4000FC3EFFDD9EFDE24BABEE80F2C0ABDD7EFCD608DD7EFD173F1FDE803063DD4EFE85
|
||||||
|
:20AB6000DD6EF8DD66F90604CB2CCB1D10FA45789130037948477891382CD5DD5EFF160048
|
||||||
|
:20AB80006B622929192929D13E00856F3ED08C677D816F3001247EFE012804D6022004AF11
|
||||||
|
:20ABA000C349AC0C18D0DD7EF893DD7EF99AE2B3ABEE80F2BAAB3E0218023E033CC349AC81
|
||||||
|
:20ABC0007BDD96F85F7ADD9EF9573EF8BB3EFF9AE2D5ABEE80F248AC7BD6087A173F1FDE47
|
||||||
|
:20ABE000803065DD5EFFDD7EFAC6F057DD7EFBCEFF6F3E04CB2DCB1A3D20F97A9330037BE2
|
||||||
|
:20AC00005A577A93382AD516006B622929192929D13E00856F3ED08C677DDD86FE6F30011D
|
||||||
|
:20AC2000247EFE012804D6022003AF181C1C18D2DD7EFA91DD7EFB98E23DACEE80F244AC74
|
||||||
|
:20AC40003E011801AF3C1801AFDDF9DDE1C9CDB4BB21F7FF39F9DD77FF0E00597BC6E6DD49
|
||||||
|
:20AC600077FD3E00CED1DD77FEDD6EFDDD66FE7EB7C251ADDD6EFDDD66FE360179C6E25F73
|
||||||
|
:20AC80003E00CED157DD7EFFC66ADD77F73E00CED1DD77F8E1E57E1269260029DD75F9DD4C
|
||||||
|
:20ACA00074FA3ECEDD86F9DD77FD3ED1DD8EFADD77FE1152D1DD6EFF260029DD75FBDD743C
|
||||||
|
:20ACC000FC195E235621080019EBE1E57EC69F6F3E00CE9C677E6F079F67D55D5429192949
|
||||||
|
:20ACE000D119EBDD6EFDDD66FE732372DD7EF9C6D6DD77FD3E00CED1DD77FE115ED1DD6EF3
|
||||||
|
:20AD0000FBDD66FC195E235621080019EBE1E57EC6A36F3E00CE9C677E6F079F67D55D5431
|
||||||
|
:20AD2000291929D119EBDD6EFDDD66FE73237279C6092601E5332E0DCD9D9E017CD1DD6EDF
|
||||||
|
:20AD4000FF260009E5CDD59DE17BE63FC62D7718081C7B4FD604DA5CACDDF9DDE1C9CDB416
|
||||||
|
:20AD6000BB21EDFF39F9DD36FF00DD6EFF26001170D1197EDD77FEB7CA3FB0DD7EFFC67C10
|
||||||
|
:20AD8000DD77FD3E00CED1DD77FEDD6EFDDD66FE7EB728083DDD6EFDDD66FE773A49D1B7FD
|
||||||
|
:20ADA0002803AF1806DD7EFFCDBCAADD77EDDD6EFF260029DD75EEDD74EFDD7EEDB7285835
|
||||||
|
:20ADC0003E6ADD86FF6F3ED1CE0067DD7EED3D773E82DD86FF5F3ED1CE00571AB720163EC0
|
||||||
|
:20ADE0000112DD6EFDDD66FE7ED6193008DD6EFDDD66FE3619DD6EFDDD66FE7EB72006DD79
|
||||||
|
:20AE00007EFFCD4EAC3E76DD86FF6F3ED1CE00677ED663281AC37EAF3E82DD86FFDD77FDC9
|
||||||
|
:20AE20003ED1CE00DD77FEDD6EFDDD66FE36003E6ADD86FFDD77F03ED1CE00DD77F1DD6E69
|
||||||
|
:20AE4000F0DD66F17EDD77F23E52DD86EEDD77F33ED1DD8EEFDD77F4DD6EF3DD66F47EDD61
|
||||||
|
:20AE600077FB237EDD77FC3E9FDD86F2DD77FD3E9CCE00DD77FEDD6EFDDD66FE7EDD77FE99
|
||||||
|
:20AE8000DD77FD079FDD77FEDD7EFDDD86FBDD77F5DD7EFEDD8EFCDD77F63E5EDD86EEDD96
|
||||||
|
:20AEA00077F73ED1DD8EEFDD77F8DD6EF7DD66F87EDD77F9237EDD77FA3EA3DD86F2DD77AE
|
||||||
|
:20AEC000FD3E9CCE00DD77FEDD6EFDDD66FE7EDD77FEDD77FB079FDD77FCDD7EFBDD86F92B
|
||||||
|
:20AEE000DD77FDDD7EFCDD8EFADD77FE3E01F533DD5EFDDD56FEDD6EF5DD66F6CD219FB766
|
||||||
|
:20AF000028393E76DD86FF6F3ED1CE00677ED6632015DD7EEDB7200FCDD59D7BE603DD6EFF
|
||||||
|
:20AF2000F0DD66F1771832DD7EEDB7202CDD7EF2EE01DD6EF0DD66F177181EDD6EF3DD6608
|
||||||
|
:20AF4000F4DD7EF57723DD7EF677DD6EF7DD66F8DD7EFD7723DD7EFE77DD6EF7DD66F85E31
|
||||||
|
:20AF60002356DD6EF3DD66F44E237E2A3FD1E52A3DD1E56967CDAAA8B72803CD3EA83E6A8C
|
||||||
|
:20AF8000DD86FF4F3ED1CE00470ADD77FADD7EEEC65EDD77FB3E00CED1DD77FCDD6EFBDD78
|
||||||
|
:20AFA00066FC4E2346DD7EEEC652DD77FD3E00CED1DD77FEDD6EFDDD66FE5E2356DD7EFFDD
|
||||||
|
:20AFC000C603DD77F8C5CD859EDD7EFAD6023E0328023E01DD77F9DD7EFAB72006DD36FA44
|
||||||
|
:20AFE00006180DDD7EFA3D3E0828023E0ADD77FADD6EFDDD66FE7EDD77FD237EDD77FEDD66
|
||||||
|
:20B000006EFBDD66FC7EDD77FB237EDD77FCDD7EFBDD86FDDD77F6DD7EFCDD8EFEDD77F7BF
|
||||||
|
:20B02000DD7EF60F0F0FE601DD77FEDD86FADD77FEDD7EF9F533DD6EFEDD7EF8CD9D9EDDAD
|
||||||
|
:20B0400034FFDD7EFFD606DA6AADDDF9DDE1C9CDB4BB21EFFF39F9DD36FF00DD7EFFC6E0AA
|
||||||
|
:20B06000DD77EF3E00CED1DD77F0E1E57EDD77FEB7CA3BB3DD7EFFDD77FDDD36FE00DD7E50
|
||||||
|
:20B08000FDDD77FBDD36FC00DDCBFB26DDCBFC163EC6DD86FBDD77F13ED1DD8EFCDD77F26F
|
||||||
|
:20B0A000C1E1E5C57EDD77F7237EDD77F83EDEDD86FFDD77FD3ED1CE00DD77FEDD6EFDDD6B
|
||||||
|
:20B0C00066FE7EDD77FA3E9FDD86FADD77F93E9CCE00DD77FADD6EF9DD66FA7EDD77FADD99
|
||||||
|
:20B0E00077F9079FDD77FADD4EF9DD46FA6960292909DD75F9DD74FADD7EF7DD86F94FDD17
|
||||||
|
:20B100007EF8DD8EFA47D1E1E5D57123703ECADD86FBDD77F33ED1DD8EFCDD77F4DD6EF3F4
|
||||||
|
:20B12000DD66F47EDD77FB237EDD77FCDD6EFDDD66FE7EDD77FE3EA3DD86FEDD77FD3E9C54
|
||||||
|
:20B14000CE00DD77FEDD6EFDDD66FE7EDD77FEDD77FD079FDD77FEDD4EFDDD46FE696029F2
|
||||||
|
:20B160002909DD75FDDD74FEDD7EFBDD86FD5FDD7EFCDD8EFE57DD6EF3DD66F4732372C195
|
||||||
|
:20B18000E1E5C57E23666FCDD19E4FDD7EFF3CDD77F5793D280879D60228030C200DE13692
|
||||||
|
:20B1A00000E5DD7EF5CDB09EC33BB3DD36F6000E0079C670DD77F73E00CED1DD77F8DD6E09
|
||||||
|
:20B1C000F7DD66F87EB7CADCB2D1E1E5D57EDD77FB237EDD77FC591600EB29EB2152D119BB
|
||||||
|
:20B1E000DD75F9DD74FA46236678C603DD77FD7CCE00DD77FEDD7EFBDD96FDDD7EFCDD9E24
|
||||||
|
:20B20000FEE206B2EE80FADCB278C60C6F3001247DDD96FB7CDD9EFCE21DB2EE80FADCB20D
|
||||||
|
:20B22000DD6EF3DD66F47EDD77FB237EDD77FC215ED119DD75FDDD74FE5E23566B622323EA
|
||||||
|
:20B24000DD7EFB95DD7EFC9CE24DB2EE80FADCB2210E00197DDD96FB7CDD9EFCE261B2EE30
|
||||||
|
:20B2600080FADCB2DD6EF7DD66F836003A18D126006F291119D1194E23462B3E88DD86F61D
|
||||||
|
:20B280005F3ED1CE00571AF5110100F13C1803EB29EB3D20FA79B34F78B247712370DD7E11
|
||||||
|
:20B2A000F6C603CDB09EE13600E5DD7EF5CDB09E21EAD13614DD6EF9DD66FA7E2332EBD117
|
||||||
|
:20B2C0007E32ECD1DD6EFDDD66FE7E2332EDD17E32EED12A50D1232250D1180A0CDD71F655
|
||||||
|
:20B2E00079D606DAB1B1E1E57EB7284FDD6EF3DD66F47EDD77FD237EDD77FEDD7EFDC6F8FE
|
||||||
|
:20B30000DD77FBDD7EFECEFFDD77FCC1E1E5C57EDD77FD237EDD77FEDD7EFDC6F8DD77F9F7
|
||||||
|
:20B32000DD7EFECEFFDD77FADD6EFBDD66FCE5DD5EF9DD56FADD7EF5CD859EDD34FFDD7E23
|
||||||
|
:20B34000FFD602DA5BB0DD36FF003EE6DD86FFDD77FA3ED1CE00DD77FBDD6EFADD66FB7E1E
|
||||||
|
:20B36000B7CAB8B4DD7EFFDD77FDDD36FE00DD7EFDDD77F8DD36F900DDCBF826DDCBF916F7
|
||||||
|
:20B380003ECEDD86F8DD77FD3ED1DD8EF9DD77FEDD6EFDDD66FE4E2346FD21E2D1DD5EFFE5
|
||||||
|
:20B3A0001600FD19FD6E002600119F9C197E5F079F576B62291909EBDD6EFDDD66FE73236F
|
||||||
|
:20B3C000723ED6DD86F84F3ED1DD8EF94769605E2356FD7E00C6A36F3E00CE9C677E6F078D
|
||||||
|
:20B3E0009F67D55D542919D119EB6960732372DD6EFDDD66FE7E23666FC5CDD19E5FC1DDDC
|
||||||
|
:20B400007EFFC609DD77FC7B3D28087BD60228031C2011DD6EFADD66FB3600DD7EFCCDB050
|
||||||
|
:20B420009EC3B8B4DD6EFDDD66FE7EDD77FD237EDD77FEED5B3DD113131369604E2346DD08
|
||||||
|
:20B440007EFD93DD7EFE9AE24CB4EE80FA9DB42A3DD1110C00197DDD96FD7CDD9EFEE263BB
|
||||||
|
:20B46000B4EE80FA9DB42A3FD123237995789CE274B4EE80FA9DB42A3FD1110E00197D917A
|
||||||
|
:20B480007C98E287B4EE80FA9DB4DD6EFADD66FB3600DD7EFCCDB09ECD3EA8181B79C6F87A
|
||||||
|
:20B4A0004F78CEFF47DD7EFDC6F85FDD7EFECEFFC557DD7EFCCD859EDD34FFDD7EFFD6046F
|
||||||
|
:20B4C000DA4AB3DDF9DDE1C93A45D1B720034F180A3A45D13D0E0228020E04C52A3FD1E5E0
|
||||||
|
:20B4E000ED5B3DD1AFCD859EC13A49D1CB5728040600180D3A45D1D6022004060318020654
|
||||||
|
:20B50000013A46D10F0F0FE60181C5336FAFCD9D9E3AEAD1B7C82AEDD1E5ED5BEBD13E158E
|
||||||
|
:20B52000CD859E21EAD1353AEAD1B73E012001AFF5332E123E15CD9D9EC9DB88E6B028089A
|
||||||
|
:20B54000CD039ECD119E18F2CD039ECD119ECDD59DDB88CB7F2802AFC9E63028EB3E01C94E
|
||||||
|
:20B56000CD289E2170B6CD169D0E00C53E01F5332E0079CD319EC1C53E01F5332E0D79CD86
|
||||||
|
:20B58000319EC10C79D61438E22E01E53E01F533AFCD319EE1E53E01F5333E13CD319EE1D1
|
||||||
|
:20B5A0002C7DD60D38E53E02F5332E0D3E09CD319E3E02F5332E0D3E0ACD319E21A800E527
|
||||||
|
:20B5C000117800AFCD859E3E01F533AF6FCD9D9E21A800E51198003E01CD859E3E01F533C9
|
||||||
|
:20B5E0002E113E01CD9D9E21A800E511B8003E02CD859E3E03F5332E0A3E02CD9D9E21A86C
|
||||||
|
:20B6000000E51148003E03CD859E3E01F5332E0A3E03CD9D9E2179B6CD9F9D117EB63E07F0
|
||||||
|
:20B62000CDB39D2198B6CD9F9D119DB63E0ACDB39D11D9B63E0BCDB39D110BB73E0ECDB307
|
||||||
|
:20B640009D113FB73E0FCDB39D117CB73E10CDB39D11B0B73E11CDB39D21C9B7CD9F9D118E
|
||||||
|
:20B66000CEB73E19CDB39D21E3B7CD9F9DC33AB51B5B306D1B5B324A00313B39330054200A
|
||||||
|
:20B68000482045202020492052204F204E2020204B20452045205000303B333700596F750E
|
||||||
|
:20B6A00020617265206120707269736F6E657220696E207468652049726F6E204B6565706A
|
||||||
|
:20B6C0002E20537465616C20746865206B696E6727732063726F776E0066726F6D20746866
|
||||||
|
:20B6E00065207468726F6E6520726F6F6D2C20616E642065736361706520646F776E2074DC
|
||||||
|
:20B700006865207374616972732E004152524F5753206F72205720412053204420206D6FCE
|
||||||
|
:20B72000766520202020202020205350414345206F72204354524C202073686F6F74004BB4
|
||||||
|
:20B74000657973206F70656E206C6F636B656420646F6F72732E2043686573747320686F3E
|
||||||
|
:20B760006C6420676F6C642C2063726174657320686F6C642073686F74732E004775617290
|
||||||
|
:20B7800064732073656520616C6F6E6720726F777320616E6420636F6C756D6E73202D2078
|
||||||
|
:20B7A000616E6420746865792073686F6F742E0050207061757365732E2020455343206730
|
||||||
|
:20B7C000697665732075702E00313B393600505245535320535041434520544F20424547DA
|
||||||
|
:20B7E000494E003000ED4B50D1696029092929290929EB3A4ED1835F3A4FD18A573AF4D121
|
||||||
|
:20B80000B728193A4AD14F0600696029092929290929292901DC050919EB180B3A4DD1B76B
|
||||||
|
:20B82000280521E80319EBD5CD289E21C8B8CD9F9D11D0B83E0CCDB39DD13AF4D1B7280505
|
||||||
|
:20B8400021F9B818032122B9EBE53E0DCDB39D11D0B83E0ECDB39D2E153E0FCD7B9D214BE4
|
||||||
|
:20B86000B9CD169DD1EBE5CD219DD13E09BB3E009A3E0017C60A4F3E63BB3E009A3E0017BB
|
||||||
|
:20B88000814F3EE7BB3E039A3E0017814F3E0FBB3E279A3E0017814F79D628300AC53E20F8
|
||||||
|
:20B8A000CD2086C10C18F111D0B83E10CDB39D1155B93E11CDB39D11D0B83E12CDB39D2189
|
||||||
|
:20B8C0007EB9CD9F9DC33AB5303B34343B39370020202020202020202020202020202020F8
|
||||||
|
:20B8E00020202020202020202020202020202020202020202020202000202020594F5520CB
|
||||||
|
:20B90000455343415045442057495448205448452043524F574E21202020202020202020EB
|
||||||
|
:20B9200020002020205448452047554152445320484156452054414B454E20594F552E207E
|
||||||
|
:20B94000202020202020202020200020202053434F52452000202020535041434520544F1C
|
||||||
|
:20B9600020504C415920414741494E2C2045534320544F2053544F502020202020003000D1
|
||||||
|
:20B980000119D11E006B26002909AF7723772131D116001936001C7BD60C38E9214AD13687
|
||||||
|
:20B9A00003AF324BD1214CD1360A210000224ED12250D1AF324DD132F3D1AF32F4D132494E
|
||||||
|
:20B9C000D1AF3247D13E013248D1AF3246D122F5D1AF32F2D13245D1AF3218D1013B9A0A9D
|
||||||
|
:20B9E000B72829D65020206960236E260029292929223DD1696023235E1600EB2929292973
|
||||||
|
:20BA000011100019223FD103030318D321D1BACD169DCDB3A121D6BACD5BA03AF3D1B7C289
|
||||||
|
:20BA2000BEBACD039ECD119EB728322E283E01CD7B9D21F7BACD9F9D21FCBACD169D2113B3
|
||||||
|
:20BA4000BBCD9F9DCD039EDB8807300621F0D13601C9CD119EB728EC21F1D13601DB884F1F
|
||||||
|
:20BA6000CB79280B21F3D13601AF32F4D1184FC579CD8DA6CD75A5C179CD37A7CD4FB0CD83
|
||||||
|
:20BA80005EADCD33A9CDC8B43A49D1B728042149D1353A47D1B728042147D1353AF2D1B7AB
|
||||||
|
:20BAA000280F21F2D1353AF2D1B7200521F1D136013AF1D1B7CA1BBACD69A0C31BBACD694D
|
||||||
|
:20BAC000A0063CC5CD039ECD119ECDC8B4C110F3C91B5B324A0046494E4420544845204388
|
||||||
|
:20BAE000524F574E2E204D494E4420544845204755415244532E00303B3936005041555362
|
||||||
|
:20BB00004544202D205020544F20474F204F4E1B5B4B003000DB780E00EEE132F7D179EE27
|
||||||
|
:20BB2000AC32F8D1DB7832EFD12162BBCD169DCDB69EAF32F0D13AF0D1B72015CD60B5B718
|
||||||
|
:20BB4000280FCD80B93AF0D1B72006CDE5B7B720E5CD289E216EBBCD169DDB000FD0DB01B8
|
||||||
|
:20BB600018F81B5B3F336C1B5B3F32356C001B5B306D1B5B324A1B5B481B5B3F3235680092
|
||||||
|
:20BB80005D6F2600547BE680B220110610ED6A17933001833FED6A10F65FEBC906097D6C29
|
||||||
|
:20BBA0002600CB1DED6AED523001193F1710F5CB10505FC9E1DDE5DD210000DD39E95D6F7D
|
||||||
|
:0ABBC000CD82BBEBC9CD85BBEBC9FC
|
||||||
|
:00000001FF
|
||||||
@@ -0,0 +1,312 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Run The Iron Keep in tools/z80emu.py on a model of the board's game ports
|
||||||
|
(graphics, sprites, frame counter, held keys, terminal) and take screenshots.
|
||||||
|
|
||||||
|
python3 test-keep.py [--shots DIR] [--fuzz FRAMES]
|
||||||
|
|
||||||
|
The scripted run starts a game, walks east into the next room, fires, and
|
||||||
|
checks what the status line says; --fuzz then plays random keys for a while
|
||||||
|
and checks the program never leaves its code or wrecks the stack. Screenshots
|
||||||
|
need pyte and Pillow (text is drawn with the board's font).
|
||||||
|
"""
|
||||||
|
import argparse
|
||||||
|
import os
|
||||||
|
import random
|
||||||
|
import sys
|
||||||
|
|
||||||
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
sys.path.insert(0, os.path.join(HERE, "..", "..", "tools"))
|
||||||
|
from z80emu import Z80 # noqa: E402
|
||||||
|
|
||||||
|
PAL = ["000", "A00", "0A0", "A50", "00A", "A0A", "0AA", "AAA",
|
||||||
|
"555", "F55", "5F5", "FF5", "55F", "F5F", "5FF", "FFF"]
|
||||||
|
PAL = [tuple(int(c, 16) * 17 for c in p) for p in PAL]
|
||||||
|
UP, DOWN, LEFT, RIGHT, FIRE, ENTER, ESC = 1, 2, 4, 8, 16, 32, 128
|
||||||
|
|
||||||
|
|
||||||
|
class Board(Z80):
|
||||||
|
def __init__(self, mem):
|
||||||
|
super().__init__(mem)
|
||||||
|
self.frame = 0
|
||||||
|
self.joy = 0
|
||||||
|
self.gfx = bytearray(320 * 240)
|
||||||
|
self.gxv = self.gyv = 0
|
||||||
|
self.spr = [[0, 0, 0, 0] for _ in range(32)] # x, y, shape, ctl
|
||||||
|
self.sel = 0
|
||||||
|
self.xst = 0
|
||||||
|
self.pat = bytearray(8192)
|
||||||
|
self.pat_a = 0
|
||||||
|
self.text = bytearray()
|
||||||
|
self.keys_in = bytearray()
|
||||||
|
|
||||||
|
def io_in(self, port):
|
||||||
|
p = port & 0xFF
|
||||||
|
if p == 0:
|
||||||
|
return (1 if self.keys_in else 0) | 2
|
||||||
|
if p == 1:
|
||||||
|
return self.keys_in.pop(0) if self.keys_in else 0
|
||||||
|
if p == 0x78: # each read is a new frame
|
||||||
|
self.frame += 1
|
||||||
|
return self.frame & 0xFF
|
||||||
|
if p == 0x88:
|
||||||
|
return self.joy
|
||||||
|
if p == 0x33:
|
||||||
|
return self.gfx[self.gyv * 320 + self.gxv] if self.gxv < 320 and self.gyv < 240 else 0
|
||||||
|
if p == 0x34:
|
||||||
|
return 0
|
||||||
|
return 0xFF
|
||||||
|
|
||||||
|
def io_out(self, port, v):
|
||||||
|
p = port & 0xFF
|
||||||
|
if p == 1:
|
||||||
|
self.text.append(v)
|
||||||
|
elif p == 0x30: self.gxv = (self.gxv & 0x100) | v
|
||||||
|
elif p == 0x31: self.gxv = (self.gxv & 0xFF) | (v & 1) << 8
|
||||||
|
elif p == 0x32: self.gyv = v
|
||||||
|
elif p == 0x33:
|
||||||
|
if self.gxv < 320 and self.gyv < 240:
|
||||||
|
self.gfx[self.gyv * 320 + self.gxv] = v & 15
|
||||||
|
self.gxv = (self.gxv + 1) & 0x1FF
|
||||||
|
elif p == 0x34:
|
||||||
|
self.gfx[:] = bytes([v & 15]) * (320 * 240)
|
||||||
|
if not v & 0x80:
|
||||||
|
for s in self.spr: s[3] &= ~1
|
||||||
|
elif p == 0x70: self.sel = v & 31
|
||||||
|
elif p == 0x71: self.xst = (self.xst & 0x100) | v
|
||||||
|
elif p == 0x72: self.xst = (self.xst & 0xFF) | (v & 1) << 8
|
||||||
|
elif p == 0x73: self.spr[self.sel][0], self.spr[self.sel][1] = self.xst, v
|
||||||
|
elif p == 0x74: self.spr[self.sel][2] = v & 63
|
||||||
|
elif p == 0x75: self.spr[self.sel][3] = v & 7
|
||||||
|
elif p == 0x76: self.pat_a = (v & 63) * 128
|
||||||
|
elif p == 0x77:
|
||||||
|
self.pat[self.pat_a & 8191] = v
|
||||||
|
self.pat_a += 1
|
||||||
|
|
||||||
|
def run_frames(self, n, joy=0):
|
||||||
|
"""Run until the program has waited for n more frames (or returned)."""
|
||||||
|
self.joy = joy
|
||||||
|
end = self.frame + 2 * n # wait_frame reads the counter twice
|
||||||
|
while self.frame < end and self.pc != 0:
|
||||||
|
self.step()
|
||||||
|
if not (0x8600 <= self.pc < self.code_end or self.pc == 0):
|
||||||
|
raise SystemExit("PC left the program: %04X" % self.pc)
|
||||||
|
if self.sp < 0xF000:
|
||||||
|
raise SystemExit("stack ran into memory: SP %04X" % self.sp)
|
||||||
|
|
||||||
|
def screen_text(self):
|
||||||
|
import pyte
|
||||||
|
scr = pyte.Screen(80, 32)
|
||||||
|
pyte.ByteStream(scr).feed(bytes(self.text))
|
||||||
|
return scr
|
||||||
|
|
||||||
|
def shot(self, path, font):
|
||||||
|
from PIL import Image
|
||||||
|
scr = self.screen_text()
|
||||||
|
img = Image.new("RGB", (1280, 1024))
|
||||||
|
px = img.load()
|
||||||
|
lay = bytearray(self.gfx)
|
||||||
|
for s in reversed(self.spr): # sprite 0 in front
|
||||||
|
x0, y0, shape, ctl = s
|
||||||
|
if not ctl & 1:
|
||||||
|
continue
|
||||||
|
for r in range(16):
|
||||||
|
for c in range(16):
|
||||||
|
rr = 15 - r if ctl & 4 else r
|
||||||
|
cc = 15 - c if ctl & 2 else c
|
||||||
|
b = self.pat[shape * 128 + rr * 8 + cc // 2]
|
||||||
|
col = b & 15 if cc & 1 else b >> 4
|
||||||
|
x, y = (x0 + c) & 511, (y0 + r) & 255
|
||||||
|
if col and x < 320 and y < 240:
|
||||||
|
lay[y * 320 + x] = col | 16
|
||||||
|
for y in range(1024):
|
||||||
|
for x in range(1280):
|
||||||
|
gx, gy = x >> 2, y >> 2
|
||||||
|
c = lay[gy * 320 + gx] & 15 if gy < 240 else 0
|
||||||
|
px[x, y] = PAL[c]
|
||||||
|
names = ["black", "red", "green", "brown", "blue", "magenta", "cyan", "white"]
|
||||||
|
for r in range(32):
|
||||||
|
for c in range(80):
|
||||||
|
ch = scr.buffer[r][c]
|
||||||
|
code = ord(ch.data[0]) if ch.data else 32
|
||||||
|
if code == 32 and ch.bg == "default":
|
||||||
|
continue
|
||||||
|
def colour(n, d):
|
||||||
|
if n in names: return PAL[names.index(n)]
|
||||||
|
if n.startswith("bright") and n[6:] in names: return PAL[names.index(n[6:]) + 8]
|
||||||
|
try:
|
||||||
|
v = int(n, 16); return ((v >> 16) & 255, (v >> 8) & 255, v & 255)
|
||||||
|
except ValueError:
|
||||||
|
return d
|
||||||
|
fg = colour(ch.fg, PAL[10])
|
||||||
|
bg = colour(ch.bg, None)
|
||||||
|
for y in range(16):
|
||||||
|
bits = font[(code if code < 256 else 63) * 16 + y]
|
||||||
|
for x in range(8):
|
||||||
|
on = bits & (0x80 >> x)
|
||||||
|
for dy in (0, 1):
|
||||||
|
for dx in (0, 1):
|
||||||
|
X, Y = c * 16 + 2 * x + dx, r * 32 + 2 * y + dy
|
||||||
|
if on: px[X, Y] = fg
|
||||||
|
elif bg is not None and px[X, Y] == (0, 0, 0): px[X, Y] = bg
|
||||||
|
img.save(path)
|
||||||
|
|
||||||
|
|
||||||
|
def play_through(b, a, check, font):
|
||||||
|
"""Walk the castle by breadth-first search over gen.py's map: both keys
|
||||||
|
nearest the throne room, the crown behind its locked door, then the
|
||||||
|
stairs. The bot can't be seen or hurt (it keeps inv set), so this tests
|
||||||
|
the castle and the game's rules, not the bot's skill."""
|
||||||
|
sys.path.insert(0, HERE)
|
||||||
|
import gen
|
||||||
|
from collections import deque
|
||||||
|
sym = {}
|
||||||
|
for line in open(os.path.join(HERE, "out", "keep.map")):
|
||||||
|
f = line.split()
|
||||||
|
if len(f) >= 2 and f[1].startswith("_"):
|
||||||
|
try: sym[f[1]] = int(f[0], 16)
|
||||||
|
except ValueError: pass
|
||||||
|
big = gen.BIG
|
||||||
|
W, H = len(big[0]), len(big)
|
||||||
|
where = {ch: [(x, y) for y in range(H) for x in range(W) if big[y][x] == ch] for ch in "KCX"}
|
||||||
|
def room_of(p): return (p[1] // 14) * 4 + p[0] // 20
|
||||||
|
keys = sorted(where["K"], key=lambda p: room_of(p) not in (1, 7))[:2]
|
||||||
|
targets = keys + where["C"] + where["X"][:1]
|
||||||
|
names = ["key", "key", "crown", "stairs"]
|
||||||
|
|
||||||
|
def i16(addr):
|
||||||
|
v = b.m[addr] | b.m[addr + 1] << 8
|
||||||
|
return v - 65536 if v & 0x8000 else v
|
||||||
|
|
||||||
|
def path(s, g):
|
||||||
|
prev = {s: None}
|
||||||
|
q = deque([s])
|
||||||
|
while q:
|
||||||
|
p = q.popleft()
|
||||||
|
if p == g:
|
||||||
|
break
|
||||||
|
for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
|
||||||
|
n = (p[0] + dx, p[1] + dy)
|
||||||
|
if 0 <= n[0] < W and 0 <= n[1] < H and n not in prev and big[n[1]][n[0]] != "#":
|
||||||
|
prev[n] = p; q.append(n)
|
||||||
|
out = [g]
|
||||||
|
while prev[out[-1]] is not None:
|
||||||
|
out.append(prev[out[-1]])
|
||||||
|
return out[::-1]
|
||||||
|
|
||||||
|
t = 0
|
||||||
|
joy = 0
|
||||||
|
for frame in range(30000):
|
||||||
|
b.m[sym["_inv"]] = 2
|
||||||
|
if b.m[sym["_over"]]:
|
||||||
|
break
|
||||||
|
px, py, room = i16(sym["_px"]), i16(sym["_py"]), b.m[sym["_room"]]
|
||||||
|
if px % 16 == 0 and (py - 16) % 16 == 0:
|
||||||
|
here = ((room % 4) * 20 + px // 16, (room // 4) * 14 + (py - 16) // 16)
|
||||||
|
while t < len(targets) and here == targets[t]:
|
||||||
|
print("bot reached the %s at frame %d" % (names[t], frame))
|
||||||
|
t += 1
|
||||||
|
if t == len(targets):
|
||||||
|
joy = 0
|
||||||
|
else:
|
||||||
|
p = path(here, targets[t])
|
||||||
|
n = p[1]
|
||||||
|
joy = RIGHT if n[0] > here[0] else LEFT if n[0] < here[0] else DOWN if n[1] > here[1] else UP
|
||||||
|
elif joy == 0: # between tiles: line up with one
|
||||||
|
joy = LEFT if px % 16 else UP
|
||||||
|
if frame % 2000 == 0:
|
||||||
|
print("frame %d: room %d at %d,%d, heading for the %s" % (frame, room, px, py, names[min(t, 3)]))
|
||||||
|
b.run_frames(1, joy)
|
||||||
|
check("bot collected %d keys and the crown" % b.m[sym["_keys"]], b.m[sym["_crown"]] == 1)
|
||||||
|
check("taking the crown down the stairs wins", b.m[sym["_over"]] == 1 and b.m[sym["_won"]] == 1)
|
||||||
|
b.run_frames(80)
|
||||||
|
check("end screen", "YOU ESCAPED WITH THE CROWN" in "\n".join(b.screen_text().display))
|
||||||
|
if a.shots: b.shot(os.path.join(a.shots, "5-escaped.png"), font)
|
||||||
|
b.run_frames(10, ESC)
|
||||||
|
b.run_frames(5)
|
||||||
|
check("Esc returns to BASIC", b.pc == 0)
|
||||||
|
|
||||||
|
|
||||||
|
def load(path):
|
||||||
|
mem = bytearray(65536)
|
||||||
|
hi = 0
|
||||||
|
for line in open(path):
|
||||||
|
n, a, t = int(line[1:3], 16), int(line[3:7], 16), int(line[7:9], 16)
|
||||||
|
if t == 0:
|
||||||
|
mem[a:a + n] = bytes.fromhex(line[9:9 + 2 * n])
|
||||||
|
hi = max(hi, a + n)
|
||||||
|
return mem, hi
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
ap = argparse.ArgumentParser()
|
||||||
|
ap.add_argument("--shots", help="write PNG screenshots here")
|
||||||
|
ap.add_argument("--fuzz", type=int, default=0, help="random frames to play")
|
||||||
|
ap.add_argument("--play", action="store_true",
|
||||||
|
help="then let a bot play the game through: keys, door, crown, stairs")
|
||||||
|
a = ap.parse_args()
|
||||||
|
mem, hi = load(os.path.join(HERE, "out", "keep.ihx"))
|
||||||
|
b = Board(mem)
|
||||||
|
b.code_end = hi
|
||||||
|
b.m[0] = 0x76 # HALT: where main returns to
|
||||||
|
b.pc, b.sp = 0x8600, 0xFFF0
|
||||||
|
b.push(0x0000)
|
||||||
|
font = None
|
||||||
|
if a.shots:
|
||||||
|
os.makedirs(a.shots, exist_ok=True)
|
||||||
|
root = os.path.join(HERE, "..", "..")
|
||||||
|
font = [int(l.split("//")[0], 16) for l in open(os.path.join(root, "font", "font.mem"))
|
||||||
|
if l.split("//")[0].strip()]
|
||||||
|
errors = 0
|
||||||
|
|
||||||
|
def check(what, ok):
|
||||||
|
nonlocal errors
|
||||||
|
print(("PASS " if ok else "FAIL ") + what)
|
||||||
|
errors += not ok
|
||||||
|
|
||||||
|
def status():
|
||||||
|
return "\n".join(b.screen_text().display[:2])
|
||||||
|
|
||||||
|
b.run_frames(20)
|
||||||
|
check("title screen", "T H E I R O N K E E P" in "\n".join(b.screen_text().display))
|
||||||
|
if a.shots: b.shot(os.path.join(a.shots, "1-title.png"), font)
|
||||||
|
b.run_frames(5, FIRE)
|
||||||
|
b.run_frames(10)
|
||||||
|
check("game starts in the gatehouse", "GATEHOUSE" in status() and "LIVES 3" in status())
|
||||||
|
check("player sprite shown", b.spr[0][3] & 1 == 1)
|
||||||
|
if a.shots: b.shot(os.path.join(a.shots, "2-gatehouse.png"), font)
|
||||||
|
# east along the top, down to the east doorway's rows, then through it
|
||||||
|
x0, y0 = b.spr[0][0], b.spr[0][1]
|
||||||
|
b.run_frames(30, DOWN)
|
||||||
|
check("moving down moves the player", b.spr[0][1] == (y0 + 60) & 255)
|
||||||
|
b.run_frames(30, UP)
|
||||||
|
b.run_frames(8, FIRE)
|
||||||
|
check("a shot uses ammunition", "AMMO 9" in status())
|
||||||
|
b.run_frames(130, RIGHT)
|
||||||
|
check("walls stop the player", b.spr[0][0] == 290)
|
||||||
|
b.run_frames(32, DOWN)
|
||||||
|
b.run_frames(30, RIGHT)
|
||||||
|
check("east doorway leads to the guard room", "GUARD ROOM" in status())
|
||||||
|
if a.shots: b.shot(os.path.join(a.shots, "3-guardroom.png"), font)
|
||||||
|
b.run_frames(60)
|
||||||
|
print(status())
|
||||||
|
if a.play:
|
||||||
|
play_through(b, a, check, font)
|
||||||
|
if a.fuzz:
|
||||||
|
rnd = random.Random(1)
|
||||||
|
j = 0
|
||||||
|
for f in range(a.fuzz):
|
||||||
|
if f % 10 == 0:
|
||||||
|
j = rnd.choice([UP, DOWN, LEFT, RIGHT, UP | FIRE, DOWN | FIRE, LEFT | FIRE,
|
||||||
|
RIGHT | FIRE, FIRE, 0, UP | LEFT, DOWN | RIGHT])
|
||||||
|
b.run_frames(1, j)
|
||||||
|
if b.pc == 0:
|
||||||
|
break
|
||||||
|
if f % 500 == 499:
|
||||||
|
print("frame", f + 1, "-", b.screen_text().display[0].strip())
|
||||||
|
check("random play for %d frames without a crash" % a.fuzz, True)
|
||||||
|
if a.shots: b.shot(os.path.join(a.shots, "4-fuzz.png"), font)
|
||||||
|
sys.exit(1 if errors else 0)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Binary file not shown.
+39
-1
@@ -392,7 +392,7 @@ static u16 bp; /* the user's breakpoint */
|
|||||||
static u8 bp_set;
|
static u8 bp_set;
|
||||||
static u8 go_after; /* stepping off a breakpoint, then G */
|
static u8 go_after; /* stepping off a breakpoint, then G */
|
||||||
static u16 steps; /* more single steps to do */
|
static u16 steps; /* more single steps to do */
|
||||||
static char cmd[40];
|
static char cmd[80];
|
||||||
static u8 msg_err;
|
static u8 msg_err;
|
||||||
static const char *msg;
|
static const char *msg;
|
||||||
static u8 why_in; /* why the monitor was entered */
|
static u8 why_in; /* why the monitor was entered */
|
||||||
@@ -997,6 +997,43 @@ static u8 set_reg(void)
|
|||||||
return 1;
|
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). */
|
/* Returns 1 when the monitor should be left (u.exit set). */
|
||||||
static u8 command(void)
|
static u8 command(void)
|
||||||
{
|
{
|
||||||
@@ -1005,6 +1042,7 @@ static u8 command(void)
|
|||||||
cp = cmd;
|
cp = cmd;
|
||||||
skip_sp();
|
skip_sp();
|
||||||
msg = 0; msg_err = 0;
|
msg = 0; msg_err = 0;
|
||||||
|
if (*cp == ':') { hex_record(); return 0; }
|
||||||
if (!memcmp(cp, "ASM", 3)) {
|
if (!memcmp(cp, "ASM", 3)) {
|
||||||
cp += 3;
|
cp += 3;
|
||||||
if (setjmp(fs_jmp)) { msg = fs_msg; msg_err = 1; return 0; }
|
if (setjmp(fs_jmp)) { msg = fs_msg; msg_err = 1; return 0; }
|
||||||
|
|||||||
+1301
-1301
File diff suppressed because it is too large.
Load diff
@@ -117,6 +117,12 @@ module basys3_terminal #(
|
|||||||
.ascii(key), .ascii_valid(key_valid), .caps(caps), .cad(cad)
|
.ascii(key), .ascii_valid(key_valid), .caps(caps), .cad(cad)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// keys held down, for the Z-80's game ports (nothing is held outside Z-80 mode)
|
||||||
|
wire [255:0] keys_down;
|
||||||
|
ps2_keystate kbd_state (
|
||||||
|
.clk(clk), .rst(rst | ~z80_mode), .code(scan), .code_valid(scan_valid), .down(keys_down)
|
||||||
|
);
|
||||||
|
|
||||||
// Ctrl-Alt-Del in Z-80 mode restarts the Z-80, like BTND (held 1 us)
|
// Ctrl-Alt-Del in Z-80 mode restarts the Z-80, like BTND (held 1 us)
|
||||||
reg [6:0] cad_t = 7'd0;
|
reg [6:0] cad_t = 7'd0;
|
||||||
always @(posedge clk) cad_t <= cad && z80_mode ? 7'd100 : cad_t - (cad_t != 0);
|
always @(posedge clk) cad_t <= cad && z80_mode ? 7'd100 : cad_t - (cad_t != 0);
|
||||||
@@ -338,7 +344,7 @@ module basys3_terminal #(
|
|||||||
.seg_val(z80_seg), .halted(), .brk_key(brk_s[2] ^ brk_s[1]),
|
.seg_val(z80_seg), .halted(), .brk_key(brk_s[2] ^ brk_s[1]),
|
||||||
.vclk(pix_clk), .gfx_vaddr(gfx_addr), .gfx_vpix(gfx_pix),
|
.vclk(pix_clk), .gfx_vaddr(gfx_addr), .gfx_vpix(gfx_pix),
|
||||||
.sp_go(sp_go), .sp_line(sp_line), .sp_buf(sp_buf), .sp_x(sp_x), .sp_on(sp_on),
|
.sp_go(sp_go), .sp_line(sp_line), .sp_buf(sp_buf), .sp_x(sp_x), .sp_on(sp_on),
|
||||||
.sp_pix(sp_pix), .sp_ftick(pix_frame),
|
.sp_pix(sp_pix), .sp_ftick(pix_frame), .keys(keys_down),
|
||||||
.fl_cs_n(QspiCSn), .fl_sck(fl_sck), .fl_mosi(QspiDB[0]), .fl_miso(QspiDB[1])
|
.fl_cs_n(QspiCSn), .fl_sck(fl_sck), .fl_mosi(QspiDB[0]), .fl_miso(QspiDB[1])
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -237,3 +237,32 @@ module ps2_keymap (
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
endmodule
|
endmodule
|
||||||
|
|
||||||
|
// Which keys are held down, for games: one bit per set-2 scan code, 128 plain
|
||||||
|
// codes ({0, code}) and 128 after the E0 prefix ({1, code}). The Pause key's
|
||||||
|
// E1 sequence is skipped.
|
||||||
|
module ps2_keystate (
|
||||||
|
input clk,
|
||||||
|
input rst,
|
||||||
|
input [7:0] code,
|
||||||
|
input code_valid,
|
||||||
|
output reg [255:0] down
|
||||||
|
);
|
||||||
|
reg ext, brk, pause;
|
||||||
|
reg [2:0] skip;
|
||||||
|
always @(posedge clk)
|
||||||
|
if (rst) begin
|
||||||
|
down <= 256'd0;
|
||||||
|
ext <= 1'b0; brk <= 1'b0; skip <= 3'd0;
|
||||||
|
end else if (code_valid) begin
|
||||||
|
if (skip != 3'd0) skip <= skip - 1'b1; // rest of E1 14 77 E1 F0 14 F0 77
|
||||||
|
else if (code == 8'hE1) skip <= 3'd7;
|
||||||
|
else if (code == 8'hE0) ext <= 1'b1;
|
||||||
|
else if (code == 8'hF0) brk <= 1'b1;
|
||||||
|
else begin
|
||||||
|
if (!code[7]) down[{ext, code[6:0]}] <= !brk;
|
||||||
|
ext <= 1'b0;
|
||||||
|
brk <= 1'b0;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
endmodule
|
||||||
@@ -24,6 +24,11 @@
|
|||||||
// 65 out breakpoint 0 low 66 high 68 out breakpoint 1 low 69 high
|
// 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
|
// 67 out bit 0 = breakpoint 0 on, bit 1 = breakpoint 1 on
|
||||||
// 70-78, 80-87 sprites (see sprites.v)
|
// 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)
|
// 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
|
// 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,
|
input sp_on,
|
||||||
output [3:0] sp_pix,
|
output [3:0] sp_pix,
|
||||||
input sp_ftick,
|
input sp_ftick,
|
||||||
|
// keys held down (one bit per scan code, from the keyboard's clock)
|
||||||
|
input [255:0] keys,
|
||||||
// configuration flash (SPI)
|
// configuration flash (SPI)
|
||||||
output fl_cs_n,
|
output fl_cs_n,
|
||||||
output fl_sck,
|
output fl_sck,
|
||||||
@@ -164,6 +171,22 @@ module z80_system #(
|
|||||||
.rd_on(sp_on), .pix(sp_pix), .gfx_pix(gfx_vpix), .ftick(sp_ftick)
|
.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
|
// --------------------------------------------------------------- flash
|
||||||
wire [7:0] fl_ctl_q, fl_dat_q;
|
wire [7:0] fl_ctl_q, fl_dat_q;
|
||||||
flash_spi flash (
|
flash_spi flash (
|
||||||
@@ -256,6 +279,8 @@ module z80_system #(
|
|||||||
8'h64: io_din = dbg_q;
|
8'h64: io_din = dbg_q;
|
||||||
8'h78, 8'h80, 8'h81, 8'h82, 8'h83, 8'h84, 8'h85, 8'h86, 8'h87:
|
8'h78, 8'h80, 8'h81, 8'h82, 8'h83, 8'h84, 8'h85, 8'h86, 8'h87:
|
||||||
io_din = spr_q;
|
io_din = spr_q;
|
||||||
|
8'h88: io_din = joy;
|
||||||
|
8'h89: io_din = {7'd0, keys[key_sel]};
|
||||||
default: io_din = 8'hFF;
|
default: io_din = 8'hFF;
|
||||||
endcase
|
endcase
|
||||||
|
|
||||||
|
|||||||
@@ -398,6 +398,17 @@ module tb_terminal;
|
|||||||
errors = errors + 1;
|
errors = errors + 1;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
// ---- held keys: Ctrl and right Shift (they type nothing) read on
|
||||||
|
// port 136 as fire (16) + shift (64), and right Shift on port 137
|
||||||
|
ps2_send(8'h14); ps2_send(8'h59);
|
||||||
|
#2_000_000;
|
||||||
|
uart_str("CLS:OUT 137,89:LOCATE 30,1:PRINT INP(136);INP(137)\015");
|
||||||
|
wait_row(29, " 80 1");
|
||||||
|
ps2_send(8'hF0); ps2_send(8'h14); ps2_send(8'hF0); ps2_send(8'h59);
|
||||||
|
#2_000_000;
|
||||||
|
uart_str("CLS:LOCATE 30,1:PRINT INP(136);INP(137)\015");
|
||||||
|
wait_row(29, " 0 0");
|
||||||
|
|
||||||
// ---- files in the flash, and the bitstream protection
|
// ---- files in the flash, and the bitstream protection
|
||||||
uart_str({"CLS:DATE \"2026-11-28 09:30\":NEW\01510 PRINT \"SAVED\";6*7\015SAVE \"TEST1\"\015NEW\015",
|
uart_str({"CLS:DATE \"2026-11-28 09:30\":NEW\01510 PRINT \"SAVED\";6*7\015SAVE \"TEST1\"\015NEW\015",
|
||||||
"LOAD \"TEST1\"\015RUN\015DIR\015"});
|
"LOAD \"TEST1\"\015RUN\015DIR\015"});
|
||||||
@@ -504,6 +515,15 @@ module tb_terminal;
|
|||||||
wait_at(29, 40, "ASSEMBLED F000-F019");
|
wait_at(29, 40, "ASSEMBLED F000-F019");
|
||||||
uart_str("A F100\015LD A,42H\015\015");
|
uart_str("A F100\015LD A,42H\015\015");
|
||||||
wait_at(5, 2, "F100 3E 42");
|
wait_at(5, 2, "F100 3E 42");
|
||||||
|
// an Intel HEX record and the end record
|
||||||
|
uart_str(":03F10000AABBCCDB\015:00000001FF\015");
|
||||||
|
wait_at(29, 40, "HEX LOADED F100-F102");
|
||||||
|
if (dut.z80.ram[16'hF100] == 8'hAA && dut.z80.ram[16'hF101] == 8'hBB && dut.z80.ram[16'hF102] == 8'hCC)
|
||||||
|
$display("PASS hex record in memory");
|
||||||
|
else begin
|
||||||
|
$display("FAIL hex record: %h %h %h", dut.z80.ram[16'hF100], dut.z80.ram[16'hF101], dut.z80.ram[16'hF102]);
|
||||||
|
errors = errors + 1;
|
||||||
|
end
|
||||||
uart_str("X\015");
|
uart_str("X\015");
|
||||||
#3_000_000;
|
#3_000_000;
|
||||||
uart_str("CLS:CALL 61440\015");
|
uart_str("CLS:CALL 61440\015");
|
||||||
|
|||||||
@@ -0,0 +1,108 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Load an Intel HEX file (as SDCC writes it) into the Basys 3 Z-80's memory
|
||||||
|
through the monitor, and optionally save it as a memory file in flash.
|
||||||
|
|
||||||
|
The board needs SW15 and SW14 up and BASIC at READY; nothing else may be
|
||||||
|
using the serial port, and the baud rate must match SW1:0. The tool types
|
||||||
|
MONITOR, sends every record (the monitor writes each one into memory),
|
||||||
|
saves the loaded range if asked, and leaves the monitor again.
|
||||||
|
|
||||||
|
tools/send-hex.py games/keep/keep.ihx --save KEEPGAME --baud 3000000
|
||||||
|
|
||||||
|
Code must go at 8000h or above. Memory files are loaded back with BLOAD in
|
||||||
|
BASIC or LOAD in the monitor.
|
||||||
|
"""
|
||||||
|
import argparse
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import select
|
||||||
|
import termios
|
||||||
|
import time
|
||||||
|
|
||||||
|
BAUDS = {9600: termios.B9600, 115200: termios.B115200, 921600: termios.B921600,
|
||||||
|
3000000: termios.B3000000}
|
||||||
|
|
||||||
|
ap = argparse.ArgumentParser()
|
||||||
|
ap.add_argument("file", help="Intel HEX file")
|
||||||
|
ap.add_argument("--save", metavar="NAME", help="save the loaded bytes in flash under this name")
|
||||||
|
ap.add_argument("--port", default="/dev/ttyUSB1")
|
||||||
|
ap.add_argument("--baud", type=int, default=115200, choices=sorted(BAUDS))
|
||||||
|
a = ap.parse_args()
|
||||||
|
|
||||||
|
records = [l.strip() for l in open(a.file) if l.startswith(":")]
|
||||||
|
if not records or not records[-1].upper().startswith(":00000001"):
|
||||||
|
records.append(":00000001FF")
|
||||||
|
for r in records:
|
||||||
|
if len(r) > 79:
|
||||||
|
raise SystemExit("record too long for the monitor (79 characters): " + r[:20])
|
||||||
|
if a.save and not re.fullmatch(r"[A-Za-z][A-Za-z0-9]{0,7}", a.save):
|
||||||
|
raise SystemExit("a file name is 1-8 letters and digits, starting with a letter")
|
||||||
|
|
||||||
|
fd = os.open(a.port, os.O_RDWR | os.O_NOCTTY)
|
||||||
|
t = termios.tcgetattr(fd)
|
||||||
|
t[0] = termios.IXON
|
||||||
|
t[1] = 0
|
||||||
|
t[2] = termios.CS8 | termios.CREAD | termios.CLOCAL
|
||||||
|
t[3] = 0
|
||||||
|
t[4] = t[5] = BAUDS[a.baud]
|
||||||
|
t[6][termios.VMIN] = 0
|
||||||
|
t[6][termios.VTIME] = 0
|
||||||
|
termios.tcsetattr(fd, termios.TCSANOW, t)
|
||||||
|
termios.tcflush(fd, termios.TCIFLUSH)
|
||||||
|
|
||||||
|
buf = b""
|
||||||
|
|
||||||
|
|
||||||
|
def send(s):
|
||||||
|
os.write(fd, s.encode("ascii"))
|
||||||
|
|
||||||
|
|
||||||
|
def wait_for(pattern, timeout=10.0):
|
||||||
|
"""Read until the output since the last call matches; return it."""
|
||||||
|
global buf
|
||||||
|
end = time.time() + timeout
|
||||||
|
while time.time() < end:
|
||||||
|
m = re.search(pattern, buf, re.S)
|
||||||
|
if m:
|
||||||
|
out, buf = buf[:m.end()], buf[m.end():]
|
||||||
|
return out
|
||||||
|
r, _, _ = select.select([fd], [], [], 0.05)
|
||||||
|
if r:
|
||||||
|
buf += os.read(fd, 65536)
|
||||||
|
raise SystemExit("no answer from the board (waiting for %r); last output: %r" % (pattern, buf[-200:]))
|
||||||
|
|
||||||
|
|
||||||
|
# the monitor's command line, redrawn after each command; its message comes
|
||||||
|
# after the prompt, and the cursor is turned back on last
|
||||||
|
PROMPT = rb"\x1b\[30;1H> .*?\x1b\[\?25h"
|
||||||
|
send("\r")
|
||||||
|
time.sleep(0.3)
|
||||||
|
send("MONITOR\r")
|
||||||
|
wait_for(rb"Z-80 MONITOR")
|
||||||
|
wait_for(PROMPT)
|
||||||
|
n = 0
|
||||||
|
for r in records:
|
||||||
|
send(r.upper() + "\r")
|
||||||
|
out = wait_for(PROMPT)
|
||||||
|
if re.search(rb"BAD HEX|CHECKSUM|ROM: NOT|NO HEX", out):
|
||||||
|
send("X\r")
|
||||||
|
raise SystemExit("the monitor refused record %d: %s" % (n + 1, r))
|
||||||
|
n += 1
|
||||||
|
if n % 50 == 0:
|
||||||
|
print("\r%d/%d records" % (n, len(records)), end="", flush=True)
|
||||||
|
m = re.search(rb"HEX LOADED ([0-9A-F]{4})-([0-9A-F]{4})", out)
|
||||||
|
if not m:
|
||||||
|
send("X\r")
|
||||||
|
raise SystemExit("the monitor did not report the loaded range")
|
||||||
|
lo, hi = m.group(1).decode(), m.group(2).decode()
|
||||||
|
print("\rloaded %s-%s (%d bytes) from %d records" % (lo, hi, int(hi, 16) - int(lo, 16) + 1, len(records)))
|
||||||
|
if a.save:
|
||||||
|
send('SAVE "%s" %s %s\r' % (a.save.upper(), lo, hi))
|
||||||
|
out = wait_for(PROMPT, 30)
|
||||||
|
if b"SAVED" not in out:
|
||||||
|
send("X\r")
|
||||||
|
raise SystemExit("saving failed: %r" % out[-120:])
|
||||||
|
print('saved as "%s"; BLOAD "%s" in BASIC loads it at %sh' % (a.save.upper(), a.save.upper(), lo))
|
||||||
|
send("X\r")
|
||||||
|
wait_for(rb"\x1b\[\?47l", 5) # the monitor's screen goes away
|
||||||
|
os.close(fd)
|
||||||
Reference in new issue
Block a user