Star Swarm: a swooping alien shooter; boardemu frame counter fix

games/swarm: an original Galaxian-style game in C for the Z-80 - a
46-alien formation sways overhead and peels off in looping, firing dives,
flagships bring escorts. With more aliens than sprites, the formation is
drawn into the graphics and swayed by the hardware X scroll; a diver is
wiped out of the graphics and becomes a sprite until it flies back.
test-swarm.py has an autopilot destroy a whole swarm.

tools/boardemu.py: the frame counter now moves on once per wait, not on
every read (it had been running two frames per wait, so anything done on
odd frames never happened in tests). The other games' tests still pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
brad ArantandClaude Opus 5.5 committed 2026-11-29 20:13:18 -08:00
1 parent 0b16e1dce0
commit e1daf27891
12 files changed
+1312 -5

No files matched your search

+1
View File
@@ -11,3 +11,4 @@ monitor/out/
games/keep/out/ games/keep/out/
games/raid/out/ games/raid/out/
games/warden/out/ games/warden/out/
games/swarm/out/
+9
View File
@@ -274,6 +274,14 @@ scrolling into view are drawn (about 5-10% of the Z-80's time). Install it as
`WARDGAME` with its loader saved as `WARDEN`; `test-warden.py --play` has an `WARDGAME` with its loader saved as `WARDEN`; `test-warden.py --play` has an
autopilot clear a wave. autopilot clear a wave.
**Star Swarm** (`games/swarm/`) is a swooping alien shooter: a 46-alien
formation sways overhead and peels off in looping, firing dives; flagships
bring escorts. `RUN "SWARM"`. With more aliens than sprites, the formation is
drawn into the graphics and swayed by the hardware X scroll; a diving alien is
wiped out of the graphics and becomes a sprite until it flies back into its
place. Install it as `SWARMGAM` with its loader saved as `SWARM`;
`test-swarm.py --play` has an autopilot destroy a whole swarm.
`tools/boardemu.py` models the board's game hardware (graphics, scrolling, `tools/boardemu.py` models the board's game hardware (graphics, scrolling,
sprites, held keys, terminal) around `tools/z80emu.py` for both tests. sprites, held keys, terminal) around `tools/z80emu.py` for both tests.
@@ -568,6 +576,7 @@ which Vivado needs on newer distros.
| `games/keep/` | The Iron Keep: game (C), art and map generator, loader, emulator test | | `games/keep/` | The Iron Keep: game (C), art and map generator, loader, emulator test |
| `games/raid/` | Bastion Raid: game (C), art and level generator, loader, emulator test with autopilot | | `games/raid/` | Bastion Raid: game (C), art and level generator, loader, emulator test with autopilot |
| `games/warden/` | Star Warden: game (C), art and mountain generator, loader, emulator test with autopilot | | `games/warden/` | Star Warden: game (C), art and mountain generator, loader, emulator test with autopilot |
| `games/swarm/` | Star Swarm: game (C), art generator, loader, emulator test with autopilot |
| `tools/boardemu.py` | Model of the board's game hardware around `z80emu.py`, with screenshots | | `tools/boardemu.py` | Model of the board's game hardware around `z80emu.py`, with screenshots |
| `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 |
+27
View File
@@ -1201,6 +1201,33 @@ round, four times the graphics' width, so the game scrolls the graphics and
draws each column of mountains and stars as it comes into view draws each column of mountains and stars as it comes into view
(`games/warden/` on the PC). (`games/warden/` on the PC).
### Star Swarm
An alien swarm sways in formation across the top of the screen, and its
members peel off in looping dives at your ship, firing as they come. Those
that miss loop round and fly back into their places.
```
RUN "SWARM"
```
- **Left and right** move the ship; **Space** or **Ctrl** fires. You have one
shot in the air at a time, so make it count.
- **The swarm:** blue drones, purple warriors, red escorts and two yellow
flagships at the top. A flagship dives with up to two escorts; shoot both
escorts before the flagship for 800.
- **Score:** each alien is worth twice as much diving as in formation:
drones 30 / 60, warriors 40 / 80, escorts 50 / 100, flagships 60 / 150
(300 with an escort still flying). A new ship every 7,000.
- **Waves:** clear the swarm and a new one arrives, diving more often and
more of them at once.
- **P** pauses; **Esc** gives up, and Esc at the title goes back to BASIC.
`SWARM` loads the memory file `SWARMGAM` at 8600h. The 46 aliens are more than
the 32 sprites, so the formation is drawn into the graphics, and its sway is
the hardware scroll; a diving alien is wiped from the graphics and flies as a
sprite until it is back in its place (`games/swarm/` on the PC).
## 15. Limits at a glance ## 15. Limits at a glance
| Item | Limit | | Item | Limit |
Binary file not shown.
+25
View File
@@ -0,0 +1,25 @@
#!/bin/bash
# Build Star Swarm: swarm.ihx, Intel HEX for tools/send-hex.py.
# The program runs at 8600h with its variables at D000h, inside BASIC's
# program area (8482h-D6D5h) and clear of the SWARM 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/swarm.rel swarm.c
sdcc -mz80 --no-std-crt0 --code-loc 0x8620 --data-loc 0xD000 -o out/swarm.ihx out/crt0.rel out/swarm.rel
python3 - <<'EOF'
import re
m = open("out/swarm.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/swarm.ihx swarm.ihx
+37
View File
@@ -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
+135
View File
@@ -0,0 +1,135 @@
#!/usr/bin/env python3
"""Make data.h for swarm.c: the sprite shapes (also drawn into the graphics
for the aliens waiting in formation) and a sine table for the dives.
Shapes are 16 rows of 16 hex digits, one colour per pixel (0 is see-through).
"""
import math
import random
import sys
Z = "0" * 16
DRONE_A = [Z, Z,
"000C00000000C000",
"0000C000000C0000",
"00000CCCCCC00000",
"0000CC4CC4CC0000",
"000CCCCCCCCCC000",
"0CCCCCCCCCCCCCC0",
"0C0CCCCCCCCCC0C0",
"0C0C00000000C0C0",
"0000CC0000CC0000",
] + [Z] * 5
DRONE_B = [Z, Z,
"0000C000000C0000",
"0000C000000C0000",
"00000CCCCCC00000",
"0000CC4CC4CC0000",
"000CCCCCCCCCC000",
"00CCCCCCCCCCCC00",
"0CCCCCCCCCCCCCC0",
"C00C00000000C00C",
"000CC000000CC000",
] + [Z] * 5
FLAG_A = [Z,
"0000000BB0000000",
"000000BBBB000000",
"00B00BB99BB00B00",
"00BB0BBBBBB0BB00",
"00BBBBBBBBBBBB00",
"000BB9BBBB9BB000",
"0000BBBBBBBB0000",
"00000B9BB9B00000",
"0000B000000B0000",
"000B00000000B000",
] + [Z] * 5
FLAG_B = [Z,
"0000000BB0000000",
"000000BBBB000000",
"00000BB99BB00000",
"B0BB0BBBBBB0BB0B",
"0BBBBBBBBBBBBBB0",
"000BB9BBBB9BB000",
"0000BBBBBBBB0000",
"00000B9BB9B00000",
"00000B0000B00000",
"0000B000000B0000",
] + [Z] * 5
def recolour(img, table):
return [row.translate(str.maketrans(table)) for row in img]
WARRIOR_A, WARRIOR_B = recolour(DRONE_A, {"C": "D", "4": "B"}), recolour(DRONE_B, {"C": "D", "4": "B"})
ESCORT_A, ESCORT_B = recolour(DRONE_A, {"C": "9", "4": "F"}), recolour(DRONE_B, {"C": "9", "4": "F"})
SHIP = [Z,
"0000000FF0000000",
"0000000FF0000000",
"000000FFFF000000",
"000000F99F000000",
"00F00FFFFFF00F00",
"00F0FFFFFFFF0F00",
"00FFFFFFFFFFFF00",
"00FFF99FF99FFF00",
"00FF00FFFF00FF00",
] + [Z] * 6
SHOT = [Z] * 5 + ["0000000BB0000000"] * 6 + [Z] * 5
BULLET = [Z] * 6 + ["00000009F0000000", "0000000F90000000", "000000099000000" + "0"] + [Z] * 7
def burst(seed, cols, size):
r = random.Random(seed)
img = [["0"] * 16 for _ in range(16)]
for _ in range(80):
a = r.uniform(0, 2 * math.pi)
d = r.uniform(0, size)
x, y = int(8 + d * math.cos(a)), int(8 + d * math.sin(a))
if 0 <= x < 16 and 0 <= y < 16:
img[y][x] = cols[0] if d < size / 3 else cols[1] if d < 2 * size / 3 else cols[2]
return ["".join(row) for row in img]
BOOM1 = burst(21, "FB9", 5)
BOOM2 = burst(23, "B91", 7.5)
SHIPBOOM = burst(25, "FFB", 7.9)
def stars(seed):
r = random.Random(seed)
img = [["0"] * 16 for _ in range(16)]
for _ in range(2):
img[r.randrange(16)][r.randrange(16)] = r.choice("FE7BD6")
return ["".join(row) for row in img]
SHAPES = [("S_DRONE", DRONE_A), ("S_DRONE2", DRONE_B), ("S_WARRIOR", WARRIOR_A), ("S_WARRIOR2", WARRIOR_B),
("S_ESCORT", ESCORT_A), ("S_ESCORT2", ESCORT_B), ("S_FLAG", FLAG_A), ("S_FLAG2", FLAG_B),
("S_SHIP", SHIP), ("S_SHOT", SHOT), ("S_BULLET", BULLET),
("S_BOOM1", BOOM1), ("S_BOOM2", BOOM2), ("S_SHIPBOOM", SHIPBOOM),
("S_STARS1", stars(1)), ("S_STARS2", stars(2)), ("S_STARS3", stars(3))]
def main(out):
L = ["/* made by gen.py - edit that instead */", ""]
for i, (name, img) in enumerate(SHAPES):
assert len(img) == 16 and all(len(row) == 16 for row in img), name
L.append("#define %s %d" % (name, i))
L.append("#define N_SHAPES %d" % len(SHAPES))
L.append("static const u8 shape_data[N_SHAPES * 128] = {")
for name, img in SHAPES:
b = [int(row[x], 16) << 4 | int(row[x + 1], 16) for row in img for x in range(0, 16, 2)]
L.append(" " + ",".join(str(v) for v in b) + ", /* %s */" % name)
L.append("};")
# 64 steps round the circle, 0 = right, 16 = down; scaled by 64
L.append("static const i8 sin64[64] = {")
L.append(" " + ",".join(str(int(round(64 * math.sin(2 * math.pi * k / 64)))) for k in range(64)))
L.append("};")
open(out, "w").write("\n".join(L) + "\n")
print("data.h: %d shapes" % len(SHAPES))
if __name__ == "__main__":
main(sys.argv[1] if len(sys.argv) > 1 else "data.h")
+4
View File
@@ -0,0 +1,4 @@
10 REM STAR SWARM: LOAD THE GAME (MEMORY FILE SWARMGAM) AND PLAY IT
20 REM THE GAME RUNS AT 8600H, PAST THIS PROGRAM, AND COMES BACK HERE
30 BLOAD "SWARMGAM": CALL 34304
40 CLS
+653
View File
@@ -0,0 +1,653 @@
/* Star Swarm: a swooping alien shooter for the Basys 3 Z-80.
An alien swarm sways across the top of the screen in formation: drones,
warriors, escorts and two flagships. They peel off in looping dives,
firing as they come, and loop back into place if they miss. A flagship
brings its escorts; shoot the escorts first for a bonus. Your ship has one
shot in the air at a time.
There are 46 aliens and only 32 sprites, so the formation is drawn into the
graphics layer and sways by the hardware X scroll (ports 35h-36h). An alien
that dives is wiped from the graphics and becomes a sprite; when it gets
back to its place it is drawn in again. The stars are sprites too, a couple
of dots each, falling down the screen. It runs at 8600h, loaded by the
SWARM program in BASIC. */
typedef unsigned char u8;
typedef signed char i8;
typedef unsigned int u16;
typedef int i16;
__sfr __at 0x00 con_stat;
__sfr __at 0x01 con_data;
__sfr __at 0x30 gx_lo;
__sfr __at 0x31 gx_hi;
__sfr __at 0x32 gy_p;
__sfr __at 0x33 gpix;
__sfr __at 0x34 gfill;
__sfr __at 0x35 scr_xlo;
__sfr __at 0x36 scr_xhi;
__sfr __at 0x37 scr_y;
__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_LEFT 4
#define J_RIGHT 8
#define J_FIRE 16
#define J_ENTER 32
#define J_ESC 128
#define COLS 10
#define ROWS 6
#define FX0 60 /* buffer x of column 0 */
#define CW 20
#define FY0 36 /* top row */
#define RH 16
#define SHIP_Y 214
/* sprites: lower numbers in front */
#define SP_SHIP 0
#define SP_SHOT 1
#define SP_DIVER 2 /* 8 */
#define SP_BUL 10 /* 6 */
#define SP_BOOM 16 /* 4 */
#define SP_STAR 20 /* 10 */
#define ND 8
#define NB 6
#define NX 4
#define NST 10
#define C_EMPTY 0
#define C_HOME 1
#define C_AWAY 2
#define P_LOOP 0
#define P_ATTACK 1
#define P_RETURN 2
/* which alien is where: 0 none, else 1 drone, 2 warrior, 3 escort, 4 flagship */
static const u8 layout[ROWS][COLS] = {
{ 0, 0, 0, 4, 0, 0, 4, 0, 0, 0 },
{ 0, 0, 3, 3, 3, 3, 3, 3, 0, 0 },
{ 0, 2, 2, 2, 2, 2, 2, 2, 2, 0 },
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
};
static const u8 kind_shape[5] = { 0, S_DRONE, S_WARRIOR, S_ESCORT, S_FLAG };
static const u8 home_score[5] = { 0, 30, 40, 50, 60 };
static const u8 dive_score[5] = { 0, 60, 80, 100, 150 };
/* ---------------------------------------------------------------- state */
/* not static: test-swarm.py reads these from the link map */
u8 cell[ROWS][COLS];
i16 ship_x;
u8 lives, wave, dead, shield;
u16 score;
u8 dv_on[ND];
i16 dv_x[ND], dv_y[ND]; /* 1/16 pixels, screen */
static u8 dv_row[ND], dv_col[ND], dv_ang[ND], dv_spd[ND], dv_phase[ND], dv_cool[ND], dv_shots[ND];
static i8 dv_turn[ND];
static u8 dv_lead[ND]; /* escorts: the flagship's diver, else 255 */
static u8 dv_escorts[ND], dv_esc_hit[ND];
static i16 shot_x, shot_y;
static u8 shot_on;
static i16 bx[NB], by[NB];
static i8 bvx[NB];
static u8 b_on[NB];
static i16 xx[NX], xy[NX];
static u8 xt[NX], xship[NX];
static u8 st_x[NST], st_y[NST], st_v[NST];
static i16 sway;
static i8 sway_dir;
static u8 flap, flap_timer, dive_timer, attacks, dead_time, fire_held;
static u16 next_extra;
static u8 last_frame, quit, hud_dirty;
static u16 rnd_state;
static const char *msg;
static u8 msg_time;
/* ----------------------------------------------------------------- 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, u8 width)
{
char b[6];
u8 i = 0;
do { b[i++] = '0' + n % 10; n /= 10; } while (n);
while (width > i) { putch('0'); width--; }
while (i) putch(b[--i]);
}
static void at(u8 r, u8 c) { putch(27); putch('['); putn(r, 0); putch(';'); putn(c, 0); 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;
}
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;
}
static void say(const char *s) { msg = s; msg_time = 120; hud_dirty = 1; }
static i16 absd(i16 v) { return v < 0 ? -v : v; }
/* ------------------------------------------------------------ graphics */
/* Draw shape (or nothing) into the graphics with its top left at buffer (x, y). */
static void blit(u16 x, u8 y, u8 shape, u8 erase)
{
const u8 *p = shape_data + ((u16)shape << 7);
u8 r, i, b;
for (r = 0; r < 16; r++) {
gx_lo = (u8)x; gx_hi = (u8)(x >> 8); gy_p = y + r;
for (i = 0; i < 8; i++) {
b = erase ? 0 : *p++;
gpix = b >> 4; gpix = b & 15;
}
}
}
static u16 cell_bx(u8 c) { return FX0 + c * CW + 2; }
static u8 cell_by(u8 r) { return FY0 + r * RH; }
static void draw_cell(u8 r, u8 c)
{
blit(cell_bx(c), cell_by(r), kind_shape[layout[r][c]] + flap, cell[r][c] != C_HOME);
}
static void draw_formation(void)
{
u8 r, c;
for (r = 0; r < ROWS; r++)
for (c = 0; c < COLS; c++)
if (layout[r][c]) draw_cell(r, c);
}
static void set_scroll(void)
{
/* the picture moves right by sway: show buffer column -sway at the left */
i16 s = -sway;
if (s < 0) s += 320;
scr_xlo = (u8)s; scr_xhi = (u8)(s >> 8); scr_y = 0;
}
/* -------------------------------------------------------------- sprites */
static void spr_at(u8 n, i16 x, i16 y, u8 shape, u8 ctl)
{
sp_sel = n;
if (x < -15 || x > 319 || y < -15 || y > 239) { sp_ctl = 0; return; }
sp_xlo = (u8)x; sp_xhi = (u8)(x >> 8) & 1; sp_y = (u8)y;
sp_shape = shape; sp_ctl = ctl;
}
static void spr_off(u8 n) { sp_sel = n; sp_ctl = 0; }
static void all_off(void) { u8 i; for (i = 0; i < 32; i++) spr_off(i); }
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++;
}
}
static void boom(i16 x, i16 y, u8 ship)
{
u8 i, best = 0;
for (i = 0; i < NX; i++) if (xt[i] < xt[best]) best = i;
xx[best] = x; xy[best] = y; xt[best] = ship ? 60 : 18; xship[best] = ship;
}
/* ------------------------------------------------------------------ HUD */
static void hud(void)
{
hud_dirty = 0;
at(1, 1); ink("0;93"); puts_("STAR SWARM ");
ink("0;37"); puts_("SCORE "); ink("0;97"); putn(score, 6);
ink("0;37"); puts_(" SHIPS "); ink("0;97"); putn(lives, 0);
ink("0;37"); puts_(" WAVE "); ink("0;97"); putn(wave, 0);
if (msg && msg_time) { ink("0;96"); puts_(" "); puts_(msg); }
puts_("\033[K");
ink("0");
}
static void add_score(u16 n)
{
score += n;
if (score >= next_extra) { next_extra += 7000; lives++; say("BONUS SHIP"); }
hud_dirty = 1;
}
/* --------------------------------------------------------------- stars */
static void stars(void)
{
u8 i;
for (i = 0; i < NST; i++) {
st_y[i] += st_v[i];
if (st_y[i] >= 240) { st_y[i] -= 240; st_x[i] = rnd() % 304; }
spr_at(SP_STAR + i, st_x[i], st_y[i], S_STARS1 + i % 3, 1);
}
}
/* -------------------------------------------------------------- divers */
static void dive(u8 r, u8 c, u8 lead, i8 turn)
{
u8 d;
for (d = 0; d < ND && dv_on[d]; d++);
if (d == ND) return;
dv_on[d] = 1; dv_row[d] = r; dv_col[d] = c;
dv_x[d] = (i16)(cell_bx(c) + sway) << 4;
dv_y[d] = (i16)cell_by(r) << 4;
dv_ang[d] = 48; /* straight up */
dv_turn[d] = turn;
dv_spd[d] = 22;
dv_phase[d] = P_LOOP;
dv_cool[d] = 20 + (rnd() & 31);
dv_shots[d] = wave < 3 ? 2 : 3;
dv_lead[d] = lead;
dv_escorts[d] = 0; dv_esc_hit[d] = 0;
if (lead != 255) dv_escorts[lead]++;
cell[r][c] = C_AWAY;
draw_cell(r, c);
}
static u8 divers_out(void)
{
u8 d, n = 0;
for (d = 0; d < ND; d++) if (dv_on[d]) n++;
return n;
}
static void launch(void)
{
u8 r, c, k, side, lead;
i8 turn;
u8 most = 2 + wave; if (most > ND) most = ND;
if (divers_out() >= most) return;
attacks++;
/* every fourth attack, a flagship with the escorts beside it */
if ((attacks & 3) == 0) {
c = (rnd() & 1) ? 3 : 6;
if (cell[0][c] != C_HOME) c = 9 - c;
if (cell[0][c] == C_HOME) {
turn = c < 5 ? 1 : -1;
dive(0, c, 255, turn);
for (lead = 0; lead < ND; lead++)
if (dv_on[lead] && dv_row[lead] == 0 && dv_col[lead] == c) break;
if (lead < ND)
for (r = c - 1; r <= c + 1 && dv_escorts[lead] < 2; r++)
if (cell[1][r] == C_HOME) dive(1, r, lead, turn);
return;
}
}
/* otherwise one from the end of a row, from a random side */
side = rnd() & 1;
for (k = 0; k < COLS; k++) {
c = side ? COLS - 1 - k : k;
for (r = ROWS; r-- > 1;) {
if (cell[r][c] == C_HOME && !(rnd() & 1)) {
dive(r, c, 255, c < 5 ? 1 : -1);
return;
}
}
}
}
static void bullet_from(i16 x, i16 y)
{
u8 b;
for (b = 0; b < NB && b_on[b]; b++);
if (b == NB) return;
b_on[b] = 1; bx[b] = x << 4; by[b] = y << 4;
bvx[b] = ship_x + 8 > x ? 6 : -6;
if (absd(ship_x + 8 - x) < 20) bvx[b] = 0;
}
static void kill_diver(u8 d)
{
u8 r = dv_row[d], c = dv_col[d], k = layout[r][c], lead = dv_lead[d];
u16 pts = dive_score[k];
if (k == 4) {
if (dv_escorts[d] && dv_esc_hit[d] == dv_escorts[d]) { pts = 800; say("FLAGSHIP AND ESCORTS: 800"); }
else if (dv_escorts[d]) pts = 300;
}
if (lead != 255 && dv_on[lead]) dv_esc_hit[lead]++;
add_score(pts);
boom((dv_x[d] >> 4), dv_y[d] >> 4, 0);
dv_on[d] = 0;
cell[r][c] = C_EMPTY;
spr_off(SP_DIVER + d);
}
static void kill_ship(void)
{
u8 d, b;
if (dead || shield) return;
dead = 1; dead_time = 130;
boom(ship_x, SHIP_Y, 1);
spr_off(SP_SHIP);
for (b = 0; b < NB; b++) { b_on[b] = 0; spr_off(SP_BUL + b); }
for (d = 0; d < ND; d++)
if (dv_on[d] && dv_phase[d] != P_RETURN) dv_phase[d] = P_ATTACK;
}
static void divers(void)
{
u8 d, r, c, s;
i16 x, y, tx;
for (d = 0; d < ND; d++) {
if (!dv_on[d]) continue;
r = dv_row[d]; c = dv_col[d];
switch (dv_phase[d]) {
case P_LOOP: /* up and over, out to the side */
dv_ang[d] = (dv_ang[d] - dv_turn[d]) & 63;
if (dv_ang[d] == 16) { dv_phase[d] = P_ATTACK; dv_spd[d] = 30 + 2 * (wave < 8 ? wave : 8); }
break;
case P_ATTACK: /* down at the ship, firing */
if (!(last_frame & 3) && !dead) {
tx = ship_x + 8 - (dv_x[d] >> 4);
if (tx > 6 && dv_ang[d] > 9) dv_ang[d]--;
else if (tx < -6 && dv_ang[d] < 23) dv_ang[d]++;
}
y = dv_y[d] >> 4;
if (dv_cool[d]) dv_cool[d]--;
else if (dv_shots[d] && y > 70 && y < 170 && !dead) {
bullet_from((dv_x[d] >> 4) + 8, y + 12);
dv_shots[d]--;
dv_cool[d] = 16 + (rnd() & 15);
}
if (y > 244) { /* gone past: come back in at the top */
dv_phase[d] = P_RETURN;
dv_y[d] = -16 << 4;
dv_spd[d] = 24;
}
break;
case P_RETURN: /* drop back into place */
dv_x[d] = (i16)(cell_bx(c) + sway) << 4;
dv_y[d] += dv_spd[d];
if (dv_y[d] >= (i16)cell_by(r) << 4) {
dv_on[d] = 0;
cell[r][c] = C_HOME;
draw_cell(r, c);
spr_off(SP_DIVER + d);
continue;
}
break;
}
if (dv_phase[d] != P_RETURN) {
dv_x[d] += (sin64[(dv_ang[d] + 16) & 63] * dv_spd[d]) >> 6;
dv_y[d] += (sin64[dv_ang[d]] * dv_spd[d]) >> 6;
}
x = dv_x[d] >> 4; y = dv_y[d] >> 4;
if (!dead && absd(x - ship_x) < 11 && absd(y - SHIP_Y) < 10) {
kill_diver(d); kill_ship(); continue;
}
if (shot_on && absd(shot_x - (x + 8)) < 8 && absd(shot_y - (y + 7)) < 8) {
shot_on = 0; spr_off(SP_SHOT);
kill_diver(d);
continue;
}
s = kind_shape[layout[r][c]] + ((last_frame >> 3) & 1);
spr_at(SP_DIVER + d, x, y, s, 1);
}
}
static void bullets(void)
{
u8 b;
i16 x, y;
for (b = 0; b < NB; b++) {
if (!b_on[b]) continue;
bx[b] += bvx[b];
by[b] += 48;
x = bx[b] >> 4; y = by[b] >> 4;
if (y > 240) { b_on[b] = 0; spr_off(SP_BUL + b); continue; }
if (!dead && absd(x - (ship_x + 8)) < 7 && y > SHIP_Y + 2 && y < SHIP_Y + 13) {
b_on[b] = 0; spr_off(SP_BUL + b);
kill_ship();
continue;
}
spr_at(SP_BUL + b, x - 8, y - 8, S_BULLET, 1);
}
}
/* The ship's shot against the formation: which cell is it in? */
static void shot_vs_formation(void)
{
i16 bxp = shot_x - sway - FX0, byp = shot_y - FY0;
u8 r, c, ix, iy;
if (bxp < 0 || byp < 0) return;
c = (u8)(bxp / CW); ix = (u8)(bxp % CW);
r = (u8)(byp / RH); iy = (u8)(byp % RH);
if (c >= COLS || r >= ROWS || ix < 3 || ix > 16 || iy < 2 || iy > 11) return;
if (cell[r][c] != C_HOME) return;
cell[r][c] = C_EMPTY;
draw_cell(r, c);
add_score(home_score[layout[r][c]]);
boom(cell_bx(c) + sway, cell_by(r), 0);
shot_on = 0; spr_off(SP_SHOT);
}
static void ship(u8 j)
{
if (dead) return;
if ((j & J_LEFT) && ship_x > 6) ship_x -= 2;
if ((j & J_RIGHT) && ship_x < 298) ship_x += 2;
if (j & J_FIRE) {
if (!shot_on && !fire_held) {
shot_on = 1; shot_x = ship_x + 8; shot_y = SHIP_Y;
}
fire_held = 1;
} else fire_held = 0;
spr_at(SP_SHIP, ship_x, SHIP_Y, S_SHIP, 1);
}
static void shot(void)
{
if (!shot_on) return;
shot_y -= 6;
if (shot_y < 16) { shot_on = 0; spr_off(SP_SHOT); return; }
shot_vs_formation();
if (shot_on) spr_at(SP_SHOT, shot_x - 8, shot_y - 8, S_SHOT, 1);
}
static void booms(void)
{
u8 i;
for (i = 0; i < NX; i++) {
if (!xt[i]) { spr_off(SP_BOOM + i); continue; }
xt[i]--;
spr_at(SP_BOOM + i, xx[i], xy[i],
xship[i] ? S_SHIPBOOM : (xt[i] & 4) ? S_BOOM1 : S_BOOM2, xt[i] ? 1 : 0);
}
}
static u8 aliens_left(void)
{
u8 r, c, n = 0;
for (r = 0; r < ROWS; r++) for (c = 0; c < COLS; c++) if (cell[r][c]) n++;
return n;
}
static void new_wave(void)
{
u8 r, c, i;
for (r = 0; r < ROWS; r++)
for (c = 0; c < COLS; c++) cell[r][c] = layout[r][c] ? C_HOME : C_EMPTY;
for (i = 0; i < ND; i++) { dv_on[i] = 0; spr_off(SP_DIVER + i); }
for (i = 0; i < NB; i++) { b_on[i] = 0; spr_off(SP_BUL + i); }
shot_on = 0; spr_off(SP_SHOT);
sway = 0; sway_dir = 1; flap = 0; flap_timer = 24;
dive_timer = 120; attacks = 0;
draw_formation();
}
/* ------------------------------------------------------------- screens */
static void clear_all(void)
{
gfill = 0;
while (gfill & 1);
all_off();
}
static u8 wait_fire(void)
{
u8 j;
while (joy & (J_FIRE | J_ENTER | J_ESC)) { wait_frame(); drain_keys(); stars(); }
for (;;) {
wait_frame(); drain_keys(); rnd(); stars();
j = joy;
if (j & J_ESC) return 0;
if (j & (J_FIRE | J_ENTER)) return 1;
}
}
static u8 title(void)
{
clear_all();
puts_("\033[0m\033[2J");
sway = 0;
set_scroll();
blit(112, 150, S_FLAG, 0); blit(136, 150, S_ESCORT, 0);
blit(160, 150, S_WARRIOR, 0); blit(184, 150, S_DRONE, 0);
spr_at(SP_SHIP, 152, 200, S_SHIP, 1);
ink("1;93"); centre(7, "S T A R S W A R M");
ink("0;97");
centre(10, "The swarm sways overhead, and peels off to dive at you.");
centre(11, "A flagship dives with its escorts: shoot them first for a bonus.");
centre(13, "LEFT / RIGHT move SPACE fire P pause ESC give up");
ink("0;37");
centre(16, " 60 / 150 50 / 100 40 / 80 30 / 60 ");
centre(17, " IN FORMATION / DIVING");
ink("1;96"); centre(28, "PRESS SPACE TO BEGIN");
ink("0");
return wait_fire();
}
static void play(void)
{
u8 j, i;
lives = 3; score = 0; wave = 1; next_extra = 7000;
ship_x = 152; dead = 0; fire_held = 1;
for (i = 0; i < NX; i++) xt[i] = 0;
clear_all();
puts_("\033[2J");
new_wave();
msg = 0; say("HERE THEY COME");
hud();
for (;;) {
wait_frame();
set_scroll();
if (drain_keys()) {
at(1, 60); ink("0;93"); puts_("PAUSED - P TO GO ON\033[K"); ink("0");
for (;;) {
wait_frame();
if (joy & J_ESC) { quit = 1; return; }
if (drain_keys()) break;
}
hud_dirty = 1;
}
j = joy;
if (j & J_ESC) return;
/* sway: a pixel every other frame, turning at the ends */
if (last_frame & 1) {
sway += sway_dir;
if (sway >= 44 || sway <= -44) sway_dir = -sway_dir;
}
if (!--flap_timer) {
flap_timer = 24; flap ^= 1;
draw_formation();
}
if (!dead && !--dive_timer) {
i = aliens_left();
dive_timer = (i < 8 ? 30 : 100 - (wave < 6 ? wave * 10 : 60)) + (rnd() & 31);
launch();
}
ship(j);
shot();
divers();
bullets();
booms();
stars();
if (msg_time && !--msg_time) hud_dirty = 1;
if (hud_dirty) hud();
if (dead && !--dead_time) {
if (!--lives) {
hud();
ink("0;44;97");
centre(14, " ");
centre(15, " GAME OVER ");
centre(16, " ");
ink("0");
for (i = 0; i < 150; i++) { wait_frame(); drain_keys(); stars(); }
return;
}
dead = 0; ship_x = 152; fire_held = 1;
hud_dirty = 1;
}
if (!aliens_left() && !dead) {
say("SWARM DESTROYED");
hud();
for (i = 0; i < 120; i++) { wait_frame(); drain_keys(); stars(); booms(); }
wave++;
new_wave();
hud_dirty = 1;
}
}
}
void main(void)
{
u8 i;
rnd_state = 0x1979 ^ frame_ctr;
last_frame = frame_ctr;
puts_("\033[?3l\033[?25l");
load_shapes();
for (i = 0; i < NST; i++) { st_x[i] = rnd() % 304; st_y[i] = rnd() % 240; st_v[i] = 1 + (i & 1); }
quit = 0;
while (!quit) {
if (!title()) break;
play();
}
clear_all();
puts_("\033[0m\033[2J\033[H\033[?25h");
while (con_stat & 1) (void)con_data;
}
+285
View File
@@ -0,0 +1,285 @@
:198600002100D001360178B1280C36000B78B12805545D13EDB0C31FA859
:208620004FDB00CB4F28FA79D301C900000000000000000000000000000000000C000000B2
:2086400000C0000000C000000C000000000CCCCCC000000000CC4CC4CC0000000CCCCCCC12
:20866000CCC0000CCCCCCCCCCCCCC00C0CCCCCCCCCC0C00C0C00000000C0C00000CC0000AE
:20868000CC000000000000000000000000000000000000000000000000000000000000000E
:2086A0000000000000000000000000000000000000000000000000000000000000C00000FA
:2086C0000C00000000C000000C000000000CCCCCC000000000CC4CC4CC0000000CCCCCCC46
:2086E000CCC00000CCCCCCCCCCCC000CCCCCCCCCCCCCC0C00C00000000C00C000CC000002E
:208700000CC00000000000000000000000000000000000000000000000000000000000008D
:20872000000000000000000000000000000000000000000000000000000000000D0000002C
:2087400000D0000000D000000D000000000DDDDDD000000000DDBDDBDD0000000DDDDDDDDF
:20876000DDD0000DDDDDDDDDDDDDD00D0DDDDDDDDDD0D00D0D00000000D0D00000DD00007C
:20878000DD00000000000000000000000000000000000000000000000000000000000000FC
:2087A0000000000000000000000000000000000000000000000000000000000000D00000E9
:2087C0000D00000000D000000D000000000DDDDDD000000000DDBDDBDD0000000DDDDDDD22
:2087E000DDD00000DDDDDDDDDDDD000DDDDDDDDDDDDDD0D00D00000000D00D000DD00000FC
:208800000DD00000000000000000000000000000000000000000000000000000000000007B
:2088200000000000000000000000000000000000000000000000000000000000090000002F
:2088400000900000009000000900000000099999900000000099F99F990000000999999986
:2088600099900009999999999999900909999999999090090900000000909000009900003F
:2088800099000000000000000000000000000000000000000000000000000000000000003F
:2088A000000000000000000000000000000000000000000000000000000000000090000028
:2088C00009000000009000000900000000099999900000000099F99F99000000099999998D
:2088E0009990000099999999999900099999999999999090090000000090090009900000BF
:208900000990000000000000000000000000000000000000000000000000000000000000BE
:20892000000000000000000000000000000000000000000000000BB0000000000000BBBB06
:2089400000000000B00BB99BB00B0000BB0BBBBBB0BB0000BBBBBBBBBBBB00000BB9BBBB0A
:208960009BB0000000BBBBBBBB000000000B9BB9B000000000B000000B0000000B000000EB
:2089800000B000000000000000000000000000000000000000000000000000000000000027
:2089A000000000000000000000000000000000000000000000000BB0000000000000BBBB86
:2089C00000000000000BB99BB00000B0BB0BBBBBB0BB0B0BBBBBBBBBBBBBB0000BB9BBBBCF
:2089E0009BB0000000BBBBBBBB000000000B9BB9B0000000000B0000B000000000B00000C6
:208A00000B000000000000000000000000000000000000000000000000000000000000004B
:208A2000000000000000000000000000000000000000000000000FF00000000000000FF038
:208A4000000000000000FFFF000000000000F99F00000000F00FFFFFF00F0000F0FFFFFF97
:208A6000FF0F0000FFFFFFFFFFFF0000FFF99FF99FFF0000FF00FFFF00FF000000000000C4
:208A80000000000000000000000000000000000000000000000000000000000000000000D6
:208AA0000000000000000000000000000000000000000000000000000000000000000000B6
:208AC000000000000000000000000000000000000000000000000BB00000000000000BB020
:208AE0000000000000000BB00000000000000BB00000000000000BB00000000000000BB08A
:208B0000000000000000000000000000000000000000000000000000000000000000000055
:208B2000000000000000000000000000000000000000000000000000000000000000000035
:208B400000000000000000000000000000000000000000000000000000000000000009F01C
:208B60000000000000000F90000000000000099000000000000000000000000000000000BD
:208B80000000000000000000000000000000000000000000000000000000000000000000D5
:208BA0000000000000000000000000000000000000000000000000000000000000000000B5
:208BC000000000000000990000000000000990909000000000000BB0B9000000009BB0FB89
:208BE000000000000090FFFBB9900000000BFFFFB0000000000B0F0B090000000999B0B9B0
:208C0000000000000009009099000000000009000000000000000000000000000000000019
:208C2000000000000000000000000000000000000000000000010000100000000001000121
:208C4000000000000000001000000000100999000000100019009990900010111099BBB03B
:208C6000900000001000BBB0900000001090BBB0B00010000000000090000000000099095C
:208C800009000000000909990001000001000091000000000010000000100000000110005C
:208CA00001000000000000000000000000000B00000000000000B000000000000000B00048
:208CC000000000000000F00F00B000000000F00F0B0B000B00FF00000000000000FFFFFFC9
:208CE0000000000000F0FF0FF000000000FFFFFFF0FB000000F0FFF00F000B000FFF0F0088
:208D00000FB0B000B00F0F00FFB0B00B0000000000B0B000B00000000B0000000B00B000D6
:208D20000000000000000B000000000000000000000000000000000000000000000000E048
:208D4000000000000000000000000000000000000000000000000000000000000000000013
:208D60000000000000000000000000000000000000000000000000000000000000000000F3
:208D80000000000000000000000000000000000000000000000000000000000000000000D3
:208DA00000000000000000000000F00000000000000000000000000000000000F0000000D3
:208DC00000000000000000000000000000000000000000000000000700000000000000008C
:208DE000000000000000000000000000000000000000000000000000000000000000000073
:208E0000000000000000000000000000000000000000000000000000000000000000000052
:208E2000000000000000000000000000000000000000000000000000000000000000000032
:208E4000000000000000000000000000000000000E00000000000000000000000000000004
:208E60000000000000000000000000000000000000000000000000000000000000000000F2
:208E80000000000000000000000000000000000000000000000000000000000000000000D2
:208EA00000000000D000000000000000060C13181E24292D3135383B3D3F4040403F3D3B41
:208EC0003835312D29241E18130C0600FAF4EDE8E2DCD7D3CFCBC8C5C3C1C0C0C0C1C3C5C0
:208EE000C8CBCFD3D7DCE2E8EDF4FA000000040000040000000000030303030303000000CB
:208F000002020202020202020001010101010101010101010101010101010101010101012A
:208F2000010101010101010000020406001E28323C003C5064967EB7C823E5CD2086E11873
:208F4000F5DDE5DD210000DD39F5F5F53B4D44DD36FF00DD5EFF16002100003919DD34FFB6
:208F6000E5C5110A006960CDF8A8C1E17BC63077110A006960CDC2A84B4278B120D5DD4E7B
:208F8000FFDD46047990300AC53E30CD2086C10518F279B728110D59160021000039197E1C
:208FA000C5CD2086C118EBDDF9DDE1E133E967E53E1BCD20863E5BCD2086E14C2600E5AF19
:208FC000F53369CD418F3E3BCD2086E1AF67F533CD418F3E48C32086E53E1BCD20863E5B82
:208FE000CD2086E1CD368F3E6DC32086470E00692600197EB728030C18F52E00CB2DCB19F7
:209000003E2991D56F78CDAE8FD1EBC3368F2A31D1292929292929293A31D1AD3231D13AAC
:2090200032D1AC3232D1CB3F4F3A31D1A93231D12132D1AE3232D1ED5B31D1C9DB78212E1E
:20904000D19628F8DB78322ED1C90E00DB000F300EDB01FE702804D65020F10E0118ED79CC
:20906000C92233D12135D136782130D13601C9CB7C2807AF955F9F9457C9EBC9DDE5DD212A
:209080000000DD39F53BDD75FEDD74FF012B86DD6605AF6FCB3CCB1D094D44DD7EFFDD779B
:2090A000FD1E00DD7EFED330DD7EFDD3317BDD8604D3321600DD7E06B72803AF18020A03C7
:2090C0006F07070707E60FD3337DE60FD333147AD60838E11C7BD61038C9DDF9DDE1E1F129
:2090E00033E94F060069602929092929013E0009EBC987878787C624C9DDE5DD210000DD21
:20910000393B474D5816006B6229291929EB2100D0197D816F7CCE00677E3D3E012801AF93
:20912000EE01DD77FF21EB8E19591600195E21278F1600197E2126D18667E5C578CDF2905A
:209140006FC1F167E579CDE290E1DD7EFFF533E5337DF533EBCD7C9033DDE1C90E00060038
:20916000696029290929EB21EB8E19EB0600682600197EB72809C5D56879CDF990D1C1049F
:2091800078D60A38E90C79D60638D3C92123D1AF96235F9F9657CB7A280521400119EB7B66
:2091A000D3357AD336AFD337C9D3707BD6F17A173F1FDE7F38353E3FBB3E019AE2C191EE31
:2091C00080FAEB91FD210200FD39FD7E00D6F1FD7E01173F1FDE7F38123EEFFDBE003E0043
:2091E000FD9E01E2E891EE80F2F091AFD37518237BD3717AE601D372FD210200FD39FD7E2F
:2092000000D373FD7E02FD23FD23D374FD7E01FD23D375E1F1F1E9D370AFD375C90E00C59E
:2092200079CD1792C10C79D62038F4C9012B861E007BD37616000AD37703147AD68038F6FB
:209240001C7BD61138EBC9DDE5DD210000DD39F5F5DD75FEDD74FF3333D51E004B79C6FD64
:209260006F3E00CED0674621FDD016001978963001590C79D60438E56B2600294D4421ED6C
:20928000D009DD7EFE7723DD7EFF7721F5D009DD7EFC7723DD7EFD7721FDD0160019DD7E0A
:2092A00004B73E3C20023E12772101D1160019DD7E0477DDF9DDE1E133E9AF3230D13E01E6
:2092C0006FCDAE8F215393CDD88F215893CD368F216693CDD88F216B93CD368F217293CD4A
:2092E000D88F3E06F5332A42D0CD418F216693CDD88F217793CD368F217293CDD88F3A3EE5
:20930000D06FAF67F533CD418F216693CDD88F218193CD368F217293CDD88F3A3FD06FAF5D
:2093200067F533CD418F3A34D12133D1B628183A35D1B72812218A93CDD88F218F93CD36BE
:209340008F2A33D1CD368F219393CD368F219793C3D88F303B393300535441522053574154
:20936000524D20202000303B33370053434F52452000303B3937002020205348495053209B
:2093800000202020574156452000303B393600202020001B5B4B003000EB2142D07E837759
:2093A000237E8A77212CD13A42D096233A43D09E3816212CD17EC65877237ECE1B77213E1E
:2093C000D03421CE93CD61902130D13601C9424F4E5553205348495000CD2CA9F50E00792E
:2093E000C60FDD77FE3E00CED1DD77FFE1E55E2119D10600097E83E1E577D6F0381DE1E5B9
:209400007EC610E1E5772105D1060009E5C5CD0E90EB113001CDF8A8C1E17379C52E03CDB5
:20942000F1A87BC1C60E47E1E55E16003E05816F3ED1CE00676E260079C614C5E52601E3F0
:2094400033C533EBE5CDA991C10C79D60A3890F1DDE1C9DDE5DD210000DD39F5F53B4FDD7D
:2094600075FEDD36FF003E44DD86FFDD77FC3ED0CE00DD77FDDD7EFFD608300FDD6EFCDD6B
:2094800066FD7EB72805DD34FF18DBDD7EFFDD77FBDD7EFFD608CABA95DD6EFCDD66FD364D
:2094A00001116CD0DD6EFF260019711174D0DD6EFF260019DD7EFE77114CD0DD6EFF260019
:2094C00029DD75FCDD74FDDD6EFC260019E5C5DD7EFECDE290C1E1FD2A23D1FD19FDE5D179
:2094E000EB29292929EB732372115CD0DD6EFC260019E5C579CDF290C1E116005FEB292961
:209500002929EB732372117CD0DD6EFF260019363011A4D0DD6EFF260019DD7E0577118440
:20952000D0DD6EFF2600193616118CD0DD6EFF26001936001194D0DD6EFF260019E5C5CDE5
:209540000E90C1E17BE61FC61477DD7EFFC69CDD77FC3E00CED0DD77FD3A3FD0D60330046B
:209560003E0218023E03DD6EFCDD66FD7711ACD0DD6EFB260019DD7E047711B4D0DD6EFB8F
:209580002600193600DD7EFBC6BC6F3E00CED0673600DD7E043C2807DD6E04260019340604
:2095A000006960292909291100D019DD5EFE1600193602DD6EFE79CDF990DDF9DDE1E1F146
:2095C000E90E00592144D01600197EB728010C1C7BD60838EF79C9CD2CA921FBFF39F93A66
:2095E0003FD0C6024F3E089130020E08C5CDC195C191D226972129D1343A29D1E603C2C46B
:2096000096CD0E90CB433E0320023E06DD77FBC6006F3E00CED0677E3D2809DD4EFB3E0974
:2096200091DD77FBDD7EFBC6006F3E00CED0677E3DC2C496DD7EFBD60530043E0118023EA9
:20964000FFDD77FC672EFFE5DD6EFBAFCD53941144D00E00692600197EB72816216CD006E8
:2096600000097EB7200C2174D00600097EDD96FB28060C79D60838DCDD71FD79D608D226E1
:2096800097DD5EFB1D79C6B4DD77FE3E00CED0DD77FFDD4EFB0C437990DA2697DD6EFEDD31
:2096A00066FF7ED602D22697210AD01600197E3D200FD5DD66FCDD6EFDE56B3E01CD5394AD
:2096C000D11C18CECD0E907BE601DD77FF0600DD7EFFB72807483E09914F1801481E067BE2
:2096E0001D53FE02383AD516006B62292919291100D019D17D816F3001247E3D20E1C5D559
:20970000CD0E90EBD1C1CB4520D579D60530043E0118023EFF672EFFE5697ACD5394180610
:209720000478D60A38A9DDF9DDE1C9DDE5DD210000DD39F5F53B4D44DD73FDDD72FEDD3656
:20974000FF003EE7DD86FFDD77FB3ED0CE00DD77FCDD7EFFD606300BE1E57EB72805DD345E
:20976000FF18DFDD7EFFD606CAE997E13601E511C9D0DD6EFF260029E3E1E5195950EB29B4
:20978000292929EB73237211D5D0E1E519DD5EFDDD56FEEB29292929EB732372DD7EFFC6BB
:2097A000E15F3E00CED0573A3CD0C6086F3A3DD0CE00677995789CE2BC97EE80F2C3973EE8
:2097C0000618023EFA123A3CD0C6086F3A3DD0CE0067BFED42D5CD6F904B42D179D6147858
:2097E000173F1FDE803002AF12DDF9DDE1C9CD2CA921FBFF39F9DD77FF016CD0DD6EFF2657
:2098000000095E0174D0DD6EFF2600097EDD77FB01EB8E16006B6229291929DD75FCDD74C6
:20982000FD09DD5EFB1600194E11ACD0DD6EFF2600197EDD77FE11318F692600195E16009C
:2098400079D604203101B4D0DD6EFF2600094E79B7281CDD7EFFC6BC6F3E00CED0677E9107
:20986000200D112003D521EF98CD6190D1180779B72803112C01DD7EFE3C28170144D0DDFD
:209880006EFE2600097EB7280A01BCD0DD6EFE26000934EBCD9993DD6EFF2600294D44215E
:2098A0005CD0095E23563E04CB2ACB1B3D20F9214CD0097E23666F0604CB2CCB1D10FAAFCB
:2098C000F533CD47920144D0DD6EFF26000936000100D0DD6EFCDD66FD09DD5EFB16001930
:2098E0003600DD7EFFC602CD1792DDF9DDE1C9464C41475348495020414E44204553434FB2
:209900005254533A20383030003A40D0B7C03A41D0B7C02140D03601212AD136823E01F569
:209920003311D6002A3CD0CD4792AFCD17920E0021E7D0060009360079C60AC5CD1792C19C
:209940000C79D60638EA0E002144D00600097EB7280D218CD00600097ED602280236010C79
:2099600079D60838E3C9CD2CA921EDFF39F9DD36FF00DD7EFFC644DD77FC3E00CED0DD77D5
:20998000FDDD6EFCDD66FD7EB7CA979EDD6EFF2600116CD0197EDD77FE3E74DD86FF6F3EA8
:2099A000D0CE00677EDD77ED3E8CDD86FFDD77F73ED0CE00DD77F8DD6EF7DD66F84EDD5E3E
:2099C000FF1600D5DD5EFE16006B6229291929D1DD75EEDD74EFDD7EFFEB29EBDD73F0DD26
:2099E00072F1C602DD77F279B7280D793D285F79D602CABE9BC34E9C3E7CDD86FF6F3ED09A
:209A0000CE006746FD21A4D0DD5EFF1600FD19FD4E007891E63F77D610C24E9CDD6EF7DD32
:209A200066F836013E84DD86FFDD77FD3ED0CE00DD77FE3A3FD0D60830053A3FD018023EF1
:209A40000887C61EDD6EFDDD66FE77C34E9C3A2ED1E603206F3A40D0B720693A3CD0C60897
:209A60004F3A3DD0CE005F3E4CDD86F06F3ED0DD8EF1677E23666F0604CB2CCB1D10FA7924
:209A8000954F7B9C473E06B93E0098E2909AEE80F2A79A3E7CDD86FF6F3ED0CE00677EFEBA
:209AA0000A38043D77181D79D6FA78173F1FDE7F30123E7CDD86FF6F3ED0CE00677EFE1741
:209AC00030023C773E5CDD86F0DD77F93ED0DD8EF1DD77FADD6EF9DD66FA4E2346DD71FB2E
:209AE000DD70FC0604DDCBFC2EDDCBFB1E10F63E94DD86FF4F3ED0CE00470AB728053D02A7
:209B0000C3899B3E9CDD86FFDD77FD3ED0CE00DD77FEDD6EFDDD66FE7EB7286D3E46DDBE31
:209B2000FB3E00DD9EFCE22B9BEE80F2899BDD7EFBD6AADD7EFCDE00304F3A40D0B7204955
:209B4000DD7EFBC60C5F3E00CE00573E4CDD86F06F3ED0DD8EF1677E23666F3E04CB2CCB84
:209B60001D3D20F9D511080019D1C5CD2B97C1DD6EFDDD66FE7E3DDD6EFDDD66FE77C5CDAF
:209B80000E90C17BE60FC610023EF4DDBEFB3E00DD9EFCE2989BEE80F24E9CDD6EF7DD66BD
:209BA000F83602DD6EF9DD66FA36002336FF3E84DD86FF6F3ED0CE00673618C34E9C3E4C0B
:209BC000DD86F04F3ED0DD8EF147C5DD7EEDCDE290C12A23D119292929297D02037C023E0C
:209BE0005CDD86F06F3ED0DD8EF1674E23462B3E84DD86FF5F3ED0CE00571A1E00814F7B5B
:209C00008847712370C5DD7EFECDF290C126006F292929297995789CE21D9CEE80FA4E9CFB
:209C2000DD6EFCDD66FD36003E00DD86EE4F3ED0DD8EEF47DD6EED2600093601DD6EEDDD27
:209C40007EFECDF990DD7EF2CD1792C3979EDD6EF7DD66F87ED602CA919D3E4CDD86F0DDF2
:209C600077F33ED0DD8EF1DD77F4DD6EF3DD66F47EDD77F5237EDD77F63E7CDD86FFDD7731
:209C8000F73ED0CE00DD77F8DD6EF7DD66F87EDD77FEC610DD77FEDD77FD079FDD77FEDD0A
:209CA0007EFDE63FDD77FBDD36FC003EABDD86FBDD77FD3E8EDD8EFCDD77FEDD6EFDDD66FE
:209CC000FE4E3E84DD86FFDD77F93ED0CE00DD77FADD6EF9DD66FA6E79CDFDA8DD73FDDD99
:209CE00072FEDD7EFDDD77FBDD7EFEDD77FC0606DDCBFC2EDDCBFB1E10F6DD7EF5DD86FB51
:209D0000DD77FDDD7EF6DD8EFCDD77FEDD6EF3DD66F4DD7EFD7723DD7EFE773E5CDD86F0C4
:209D2000DD77FB3ED0DD8EF1DD77FCDD6EFBDD66FC7EDD77FD237EDD77FEDD6EF7DD66F856
:209D40004E21AB8E0600097EDD6EF9DD66FA6ECDFDA8DD73F9DD72FADD7EF9DD77F7DD7EE1
:209D6000FADD77F80606DDCBF82EDDCBF71E10F6DD7EFDDD86F7DD77F9DD7EFEDD8EF8DD68
:209D800077FADD6EFBDD66FCDD7EF97723DD7EFA77DD6EF02600114CD0194E2346DD71FD6A
:209DA000DD70FE0604DDCBFE2EDDCBFD1E10F6DD6EF02600115CD0194E23463E04CB28CB43
:209DC000193D20F93A40D0B72043213CD0DD7EFD965FDD7EFE239E57C5EBCD6F90C17BD637
:209DE0000B7A173F1FDE80302479C62A6F78CEFFC567CD6F90C17BD60A7A173F1FDE803009
:209E00000CDD7EFFCDEE97CD0999C3979E3AC8D0B7284EDD7EFDC6085FDD7EFECE00572AF7
:209E2000C4D0BFED52C5CD6F90C17BD6087A173F1FDE80302C21070009EB2AC6D0BFED5262
:209E4000C5CD6F90C17BD6087A173F1FDE803011AF32C8D03E01CD1792DD7EFFCDEE9718D7
:209E600036DD7EEEC6EB5FDD7EEFCE8E57DD6EED2600196E260011278F195E3A2ED10F0FB6
:209E80000FE601832601E533F533C5DD5EFDDD56FEDD7EF2CDA991DD34FFDD7EFFD608DA3E
:209EA0007299DDF9DDE1C9CD2CA921FBFF39F9DD36FF00DD7EFFC6E74F3E00CED0470AB7FF
:209EC000CAC39FDD6EFF260029E3DD7EFBC6C9DD77FD3E00CED0DD77FEDD6EFDDD66FE5E8F
:209EE00023563EE1DD86FF6F3ED0CE00677E6F079F6719EBDD6EFDDD66FE732372E1E51150
:209F0000D5D0197E23562BC6305F300114732372DD6EFDDD66FE7E2366DD77FCDD74FD3E53
:209F200004DDCBFD2EDDCBFC1E3D20F53E04CB2ACB1B3D20F9DD7EFFC60ADD77FE3EF0BB5E
:209F40003E009AE2489FEE80F2559FAF02DD7EFECD1792186E3A40D0B720493A3CD0C60888
:209F60006F3A3DD0CE0067DD7EFC956FDD7EFD9CC5D567CD6F90EBD1C17DD6077C173F1F12
:209F8000DE8030203ED8BB3E009AE28F9FEE80F2A49F7BD6E3300DAF02DD7EFECD1792CDF9
:209FA0000999181F7BC6F84F7ACEFF47DD7EFCC6F85FDD7EFDCEFF57210A01E5C5DD7EFE93
:209FC000CDA991DD34FFDD7EFFD606DAB39EDDF9DDE1C9CD2CA9F53BED4B23D12AC4D0BF31
:209FE000ED427DC6C44F7CCEFF473AC6D0C6DCDD77FD3AC7D0CEFFDD77FECB78C2C5A0DD52
:20A000007EFE07E6016FB7C2C5A0E5C51114006960CD4EA9C1DD73FF1114006960CD3EA97B
:20A02000E14BD1D57DB72803110F000604CB2ACB1B10FA43C5111000DD6EFDDD66FECD3E23
:20A04000A9C1DD7EFFD60A307C78D606307779D60338723E1091386D7BD60238683E0B9366
:20A0600038635816006B6229291929EB2100D0197DDD86FF6F3001247E3D204977C5D5DDCC
:20A080006EFF78CDF990D1C121EB8E19DD5EFF1600196E2600112C8F196E2600C5CD99930C
:20A0A000C178CDF2904F0600C5DD7EFFCDE290C12A23D119AFF5335950CD4792AF32C8D0CE
:20A0C0003E01CD1792DDF9DDE1C94F3A40D0B7C0CB51281E3E06FD213CD0FDBE003E00FD98
:20A0E0009E01E2E7A0EE80F2F2A02A3CD02B2B223CD0CB5928173A3CD0D62A3A3DD0173F66
:20A100001FDE8130082A3CD02323223CD0CB61282E3AC8D0B720213A2BD1B7201B21C8D0B2
:20A12000360121C4D03A3CD0C60877233A3DD0CE007721D60022C6D0212BD136011804AF2B
:20A14000322BD1210801E521D600E5ED5B3CD0AFCDA991C93AC8D0B7C821C6D07EC6FA7756
:20A16000237ECEFF773AC6D0D6103AC7D0173F1FDE803009AF32C8D03E01C31792CDD39F04
:20A180003AC8D0B7C83AC6D0C6F84F3AC7D0CEFF473AC4D0C6F85F3AC5D0CEFF57210901A3
:20A1A000E5C53E01CDA991C9CD2CA9F5F5DD36FF00DD7EFFC6FDDD77FD3E00CED0DD77FEAC
:20A1C000DD6EFDDD66FE4EDD7EFFC610DD77FC79B72008DD7EFCCD179218610DDD6EFDDD58
:20A1E00066FE7977B70E0120020E003E01DD86FF6F3ED1CE00677EB72804060D1810DD6EDA
:20A20000FDDD66FECB562804060B1802060CDD5EFF1600EB29EB21F5D0197EDD77FD237EB8
:20A22000DD77FE21EDD0195E235679F533C533DD6EFDDD66FEE5DD7EFCCDA991DD34FFDDAC
:20A240007EFFD604DAB1A1DDF9DDE1C9CD2CA93B0100005816006B6229291929EB2100D095
:20A2600019EBDD71FF0E00692600197EB72803DD34FF0C79D60A38EFDD4EFF0478D6063821
:20A28000D2DD7EFF33DDE1C9CD2CA921F9FF39F911EB8EDD36FF00DD4EFF06006960292904
:20A2A00009297DC600DD77F97CCED0DD77FA19DD75FBDD74FC0E00DD7EF981DD77FDDD7E32
:20A2C000FACE00DD77FEDD6EFBDD66FC0600097EB73E012001AFDD6EFDDD66FE770C79D631
:20A2E0000A38D4DD34FFDD7EFFD60638AA0E002144D0060009360079C602C5CD1792C10C4F
:20A3000079D60838EA0E0021E7D0060009360079C60AC5CD1792C10C79D60638EAAF32C828
:20A32000D03E01CD17922100002223D12125D13601AF3226D12127D136182128D13678AF5D
:20A340003229D1CD5C91DDF9DDE1C93E00D334DB340FD21D9218F8DB88E6B0280BCD3C9001
:20A36000CD4A90CDD99318EFCD3C90CD4A90CD0E90CDD993DB88CB7F2802AFC9E63028E89D
:20A380003E01C9CD4BA32137A4CD368F2100002223D1CD8C91AF672E06E53E96F53321708F
:20A3A00000CD7C90AF672E04E53E96F533218800CD7C90AF672E02E53E96F53321A000CD64
:20A3C0007C90AFF533219600E521B800CD7C90210801E521C800E5119800AFCDA9912140AF
:20A3E000A4CDD88F1145A43E07CDEC8F2159A4CDD88F115EA43E0ACDEC8F1196A43E0BCDA8
:20A40000EC8F11D7A43E0DCDEC8F2114A5CDD88F1119A53E10CDEC8F1154A53E11CDEC8F8E
:20A42000216EA5CDD88F1173A53E1CCDEC8F2188A5CDD88FC357A31B5B306D1B5B324A00A5
:20A44000313B3933005320542041205220202053205720412052204D00303B393700546889
:20A460006520737761726D207377617973206F766572686561642C20616E64207065656C23
:20A4800073206F666620746F206469766520617420796F752E004120666C616773686970D4
:20A4A000206469766573207769746820697473206573636F7274733A2073686F6F742074D7
:20A4C00068656D20666972737420666F72206120626F6E75732E004C454654202F20524968
:20A4E000474854206D6F7665202020202053504143452066697265202020202050207061EF
:20A500007573652020202020455343206769766520757000303B33370020203630202F20B9
:20A5200031353020202020202020203530202F2031303020202020202020203430202F204D
:20A54000383020202020202020203330202F20363020200020202020494E20464F524D416F
:20A5600054494F4E202F20444956494E4700313B3936005052455353205350414345205409
:20A580004F20424547494E003000213ED036032100002242D0213FD0360121581B222CD1E0
:20A5A000219800223CD0AF3240D0212BD1360101FDD01E006B26000936001C7BD60438F416
:20A5C000CD4BA32197A7CD368FCD88A22100002233D1219CA7CD6190CDBA92CD3C90CD8C64
:20A5E00091CD4A90B728322E3C3E01CDAE8F21ABA7CDD88F21B0A7CD368F21C7A7CDD88FEB
:20A60000CD3C90DB88073006212FD13601C9CD4A90B728EC2130D13601DB884FCB79C03A25
:20A620002ED10F303C3A25D15F079F477B2123D1867723788E773A23D1D62C3A24D1173F42
:20A640001FDE8030163ED4FD2123D1FDBE003EFFFD9E01E258A6EE80FA61A62125D1AF96D4
:20A6600077FD2127D1FD35003A27D1B72011FD3600183A26D1EE013226D1C5CD5C91C13AF3
:20A6800040D0B720442128D1353A28D1B7203AC5CD4CA2C1D6083004061E181C3A3FD0D632
:20A6A00006300E3A3FD05F16006B62292919291803213C003E649547C5CD0E90C17BE61FD0
:20A6C000803228D1C5CDD795C179CDCAA0CD54A1CD6699CDA79ECDA8A1CDD9933A35D1B77A
:20A6E000280F2135D1353A35D1B720052130D136013A30D1B72803CDBA923A40D0B7285F94
:20A70000212AD1353A2AD1B72055213ED0353A3ED0B72037CDBA9221C9A7CDD88F11D1A766
:20A720003E0ECDEC8F11F0A73E0FCDEC8F11D1A73E10CDEC8F21C7A7CDD88F0696C5CD3CFC
:20A7400090CD4A90CDD993C110F3C9AF3240D0219800223CD0212BD136012130D13601CDAA
:20A760004CA2B7C2DBA53A40D0B7C2DBA5210FA8CD6190CDBA920678C5CD3C90CD4A90CDB0
:20A78000D993CDA8A1C110F0213FD034CD88A22130D13601C3DBA51B5B324A004845524569
:20A7A000205448455920434F4D4500303B393300504155534544202D205020544F20474F2C
:20A7C000204F4E1B5B4B003000303B34343B3937002020202020202020202020202020206D
:20A7E000202020202020202020202020202020002020202020202020202047414D45204FB0
:20A80000564552202020202020202020202000535741524D2044455354524F59454400DBB3
:20A82000780E00EE793231D179EE193232D1DB78322ED1219FA8CD368FCD2C920E00210505
:20A84000D1060009E5C5CD0E90EB113001CDF8A8C1E173210FD1060009E5C5CD0E90EB1133
:20A86000F000CDF8A8C1E1732119D106000979E6013C770C79D60A38C5AF322FD13A2FD1BC
:20A88000B7200BCD83A3B72805CD8AA518EFCD4BA321ABA8CD368FDB000FD0DB0118F81B7A
:20A8A0005B3F336C1B5B3F32356C001B5B306D1B5B324A1B5B481B5B3F323568005D6F269E
:20A8C00000547BE680B220110610ED6A17933001833FED6A10F65FEBC906097D6C2600CBFD
:20A8E0001DED6AED523001193F1710F5CB10505FC95D6FCDBFA8EBC9CDC2A8EBC95F4D065C
:20A9000000180B4F06005D18055D4F179F477B179F57C317A94D44AF6FB0061020040608EA
:20A920007929CB111730011910F7EBC9E1DDE5DD210000DD39E95D6FCD46A9C374A9CD4E5A
:20A94000A9C374A95D6F7D079F677B079F577CAA177CF517300697956F9F9467CB7A2806FD
:1EA9600097935F9F9257CDC2A8F1D04797935F9F925778C917EBD097935F9F9257C98B
:00000001FF
+126
View File
@@ -0,0 +1,126 @@
#!/usr/bin/env python3
"""Run Star Swarm in tools/z80emu.py on a model of the board (tools/boardemu.py)
and take screenshots.
python3 test-swarm.py [--shots DIR] [--play]
It checks the title screen, measures the Z-80 instructions each frame takes
(a 60 Hz frame has about 550,000 at 90 MHz), checks that the formation sways
and that aliens dive, shoots one out of the formation, and with --play lets an
autopilot clear the whole swarm. The autopilot can't be killed (it keeps the
ship shielded), so this checks the rules and the waves, not its skill.
"""
import argparse
import os
import sys
HERE = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.join(HERE, "..", "..", "tools"))
from boardemu import Board, load_ihx, load_font # noqa: E402
LEFT, RIGHT, FIRE, ESC = 4, 8, 16, 128
FX0, CW = 60, 20
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--shots", help="write PNG screenshots here")
ap.add_argument("--play", action="store_true", help="let the autopilot clear a wave")
a = ap.parse_args()
mem, hi = load_ihx(os.path.join(HERE, "out", "swarm.ihx"))
b = Board(mem, code_end=hi)
font = load_font() if a.shots else None
if a.shots:
os.makedirs(a.shots, exist_ok=True)
sym = {}
for line in open(os.path.join(HERE, "out", "swarm.map")):
f = line.split()
if len(f) >= 2 and f[1].startswith("_"):
try: sym[f[1]] = int(f[0], 16)
except ValueError: pass
errors = 0
def check(what, ok):
nonlocal errors
print(("PASS " if ok else "FAIL ") + what)
errors += not ok
def s16(n, k=0):
v = b.m[sym[n] + 2 * k] | b.m[sym[n] + 2 * k + 1] << 8
return v - 65536 if v & 0x8000 else v
def u8(n, k=0):
return b.m[sym[n] + k]
def screen():
return b.screen_text().display
b.run_frames(5)
check("title screen", "S T A R S W A R M" in "\n".join(screen()))
if a.shots: b.shot(os.path.join(a.shots, "1-title.png"), font)
b.run_frames(3, FIRE)
b.run_frames(5)
check("game starts", "WAVE 1" in screen()[0] and "SHIPS 3" in screen()[0])
check("46 aliens in formation", sum(1 for k in range(60) if b.m[sym["_cell"] + k] == 1) == 46)
s0 = b.scroll_x
c0 = b.steps
worst = 0
for f in range(240):
c1 = b.steps
b.run_frames(1)
worst = max(worst, b.steps - c1)
per = (b.steps - c0) / 240
print("%.0f instructions a frame on average, %d at most (%.0f%%)" % (per, worst, worst / 5500))
check("every frame fits in a 60th of a second", worst < 550000)
check("the formation sways", b.scroll_x != s0)
check("aliens dive", any(u8("_dv_on", k) for k in range(8)))
if a.shots: b.shot(os.path.join(a.shots, "2-dive.png"), font)
sc = s16("_score")
b.m[sym["_shield"]] = 1
b.run_frames(2, RIGHT) # off the gap between two columns
b.run_frames(3, FIRE)
b.run_frames(40)
check("a shot into the formation scores", s16("_score") > sc)
if a.play:
frame = 0
while frame < 20000 and b.pc != 0:
b.m[sym["_shield"]] = 1
sx = s16("_ship_x") + 8
# aim at a diver low down if there is one, else the nearest column
target = None
for k in range(8):
if u8("_dv_on", k) and s16("_dv_y", k) >> 4 > 60:
target = (s16("_dv_x", k) >> 4) + 8
break
if target is None:
sway = (320 - b.scroll_x) % 320
if sway > 160: sway -= 320
best = None
for c in range(10):
if any(b.m[sym["_cell"] + r * 10 + c] == 1 for r in range(6)):
x = FX0 + c * CW + 2 + 8 + sway
if best is None or abs(x - sx) < abs(best - sx):
best = x
target = best if best is not None else sx
j = FIRE if frame % 2 else 0
if target > sx + 1: j |= RIGHT
elif target < sx - 1: j |= LEFT
b.run_frames(1, j)
frame += 1
if frame == 600 and a.shots: b.shot(os.path.join(a.shots, "3-battle.png"), font)
if "WAVE 2" in screen()[0]:
break
print(screen()[0])
check("autopilot cleared the swarm in %d frames" % frame, "WAVE 2" in screen()[0])
b.run_frames(5, ESC)
b.run_frames(5)
check("Esc gives up the game", "PRESS SPACE TO BEGIN" in "\n".join(screen()))
b.run_frames(5, ESC)
b.run_frames(5)
check("Esc returns to BASIC", b.pc == 0)
sys.exit(1 if errors else 0)
if __name__ == "__main__":
main()
+10 -5
View File
@@ -9,8 +9,10 @@ scrolling (30h-37h), the sprites (70h-78h) and the held-key port (88h).
b.run_frames(60, joy=FIRE) b.run_frames(60, joy=FIRE)
b.shot("screen.png", load_font()) b.shot("screen.png", load_font())
Each read of the frame counter (78h) counts as a new frame, so a program that The frame counter (78h) moves on when the program comes back to read it after
waits for the counter to change runs one frame per wait. Screenshots need doing some work (more than 100 instructions since it last moved), so a program
that waits for it to change runs one frame per wait, however long its frames
take, and two reads close together see the same frame. Screenshots need
pyte and Pillow, and are drawn the way the board's video combines the layers: pyte and Pillow, and are drawn the way the board's video combines the layers:
text over sprites over graphics. text over sprites over graphics.
""" """
@@ -38,6 +40,7 @@ class Board(Z80):
self.pc, self.sp = start, 0xFFF0 self.pc, self.sp = start, 0xFFF0
self.push(0x0000) self.push(0x0000)
self.frame = 0 self.frame = 0
self.frame_at = -1000
self.joy = 0 self.joy = 0
self.gfx = bytearray(320 * 240) self.gfx = bytearray(320 * 240)
self.gxv = self.gyv = 0 self.gxv = self.gyv = 0
@@ -55,8 +58,10 @@ class Board(Z80):
return (1 if self.keys_in else 0) | 2 return (1 if self.keys_in else 0) | 2
if p == 1: if p == 1:
return self.keys_in.pop(0) if self.keys_in else 0 return self.keys_in.pop(0) if self.keys_in else 0
if p == 0x78: # each read is a new frame if p == 0x78:
self.frame += 1 if self.steps - self.frame_at > 100:
self.frame += 1
self.frame_at = self.steps
return self.frame & 0xFF return self.frame & 0xFF
if p == 0x88: if p == 0x88:
return self.joy return self.joy
@@ -102,7 +107,7 @@ class Board(Z80):
def run_frames(self, n, joy=0): def run_frames(self, n, joy=0):
"""Run until the program has waited for n more frames (or returned).""" """Run until the program has waited for n more frames (or returned)."""
self.joy = joy self.joy = joy
end = self.frame + 2 * n # wait_frame reads the counter twice end = self.frame + n
while self.frame < end and self.pc != 0: while self.frame < end and self.pc != 0:
self.step() self.step()
self.steps += 1 self.steps += 1