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:
1 parent
0b16e1dce0
commit
e1daf27891
12 files changed
+1312
-5
No files matched your search
+10
-5
@@ -9,8 +9,10 @@ scrolling (30h-37h), the sprites (70h-78h) and the held-key port (88h).
|
||||
b.run_frames(60, joy=FIRE)
|
||||
b.shot("screen.png", load_font())
|
||||
|
||||
Each read of the frame counter (78h) counts as a new frame, so a program that
|
||||
waits for the counter to change runs one frame per wait. Screenshots need
|
||||
The frame counter (78h) moves on when the program comes back to read it after
|
||||
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:
|
||||
text over sprites over graphics.
|
||||
"""
|
||||
@@ -38,6 +40,7 @@ class Board(Z80):
|
||||
self.pc, self.sp = start, 0xFFF0
|
||||
self.push(0x0000)
|
||||
self.frame = 0
|
||||
self.frame_at = -1000
|
||||
self.joy = 0
|
||||
self.gfx = bytearray(320 * 240)
|
||||
self.gxv = self.gyv = 0
|
||||
@@ -55,8 +58,10 @@ class Board(Z80):
|
||||
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
|
||||
if p == 0x78:
|
||||
if self.steps - self.frame_at > 100:
|
||||
self.frame += 1
|
||||
self.frame_at = self.steps
|
||||
return self.frame & 0xFF
|
||||
if p == 0x88:
|
||||
return self.joy
|
||||
@@ -102,7 +107,7 @@ class Board(Z80):
|
||||
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
|
||||
end = self.frame + n
|
||||
while self.frame < end and self.pc != 0:
|
||||
self.step()
|
||||
self.steps += 1
|
||||
|
||||
Reference in new issue
Block a user