Bastion Raid: isometric scrolling shooter, graphics scroll and border
Ports 35h-37h scroll the graphics layer (wrapping at 320 x 240); bit 1 of 36h hides a border (4 columns, 2 rows) where a program draws the strip coming into view unseen. The video loads its own column/row counters from the scroll registers each line and frame. CLS resets both. Testbench checks scroll, wrap and border. games/raid: an original Zaxxon-style game in C - fly over a fortress that scrolls diagonally, climb over low walls and through doorways in tall ones, shoot turrets, fuel tanks, radar and fighters, destroy the reactor. The world is drawn pixel by pixel from a formula, two columns and a row a frame (about 40% of the Z-80). test-raid.py flies the level with an autopilot and checks the frame budget; tools/boardemu.py is now shared by both games' tests. send-hex.py sets the date before saving. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
743071cff3
commit
62d0883a7f
19 files changed
+1807
-163
No files matched your search
+4
-151
@@ -16,141 +16,11 @@ 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
|
||||
from boardemu import Board, load_ihx, load_font # 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
|
||||
@@ -226,17 +96,6 @@ def play_through(b, a, check, font):
|
||||
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")
|
||||
@@ -244,18 +103,12 @@ def main():
|
||||
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)
|
||||
mem, hi = load_ihx(os.path.join(HERE, "out", "keep.ihx"))
|
||||
b = Board(mem, code_end=hi)
|
||||
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()]
|
||||
font = load_font()
|
||||
errors = 0
|
||||
|
||||
def check(what, ok):
|
||||
|
||||
Reference in new issue
Block a user