#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Build test cartridges for Sim2600 die traces (docs/handoff-brief.md, milestone 2). tia-fpga's eleven traces cover the TIA broadly; these cartridges cover what they leave out. Each is a 4K image written straight as 6502 machine code by the small emitter below, so nothing third-party is involved in building them. Like tia-fpga's, every cartridge starts by clearing zero page, which writes every TIA register, RSYNC included, so the trace does not depend on the phase the die powered up in. python scripts/die_carts.py --out tests/die_carts # build all python reference/src/tia-fpga/sim/gen_trace.py --sim2600 reference/build-sim2600/Sim2600-phi2 \\ --rom tests/die_carts/retrigger.bin --skip 0 --count N --quiet --out tests/die_traces/phi2/retrigger.trace Cartridges: - ``retrigger``: RESP0 strobed twice in a line, the gap swept across 18, 33, 66 and 162 colour clocks (6, 11, 22 and 54 CPU cycles) and their neighbours, from four starting phases; NUSIZ0 = 3 copies close, so the close and medium copies show what each strobe started (Towers 895-939: a START lost or delayed up to 3 clocks when the ring is reset mid-decode). - ``vblank_collisions``: the two players drawn on top of each other on lines with VBLANK D1 off and on, collisions cleared before each line and CXPPMM read after it, so the die's drive pins show whether VBLANK gates the collision latches (docs/undocumented-behavior.md C24). - ``hmove_cycles``: HMOVE written on every cycle of the line, 0 to 75, with HMP0 = $80 (+8) and then $70 (-7), the player drawn on the lines after, so the pins show how far each HMOVE moved it. ale-79's ``early_HMOVE`` table (Stella #699) from six PAL/SECAM consoles covers the same ground; the ends of HMOVE's window (cycles 21-22 and 75-76 in its numbering) are where the board first disagreed with them. - ``hmove_resp0``: RESP0 struck 3 to 24 cycles after an HMOVE written on cycles 72-75 and 0-2, with HMP0 = $70: the RESxx/HMOVE race, as ale-79's ``HMOVE_RESPx`` measures it on six consoles (Stella #699; C10). - ``grp_mid_draw``: GRP0 cleared on cycles 20-28 while player 0 draws $FF, the player at three positions a colour clock apart so the write meets every pixel phase; then the same through VDELP0, where the GRP1 write that copies the new GRP0 into the old one does the clearing. No tia-fpga trace writes a player's graphics while it draws; Crystal Castles does, and the board and Gopher2600 disagree there by one pixel (milestone 4). - ``hmove_playfield``: an aperiodic playfield (a shift by whole bits must show), plain and reflected, on lines with an HMOVE at cycle 2 (the comb), at cycle 75 of the line before (the comb without a strobe in the line), and none, so the pins show whether HMOVE's longer blank delays the playfield or only hides it. No tia-fpga trace draws a playfield on an HMOVE line; Pitfall! does, every line (milestone 4). - ``ball_score``: the ball in the left half and the right half, with CTRLPF $00, $02 (SCORE) and $06 (SCORE and priority) and a playfield beside it, to show which colour the ball takes in score mode (the board gave it the half's player colour, Stella COLUPF: Alpha Beam with Ernie, milestone 4; no tia-fpga cartridge shows the ball under SCORE). - ``enable_mid_draw``: an 8-clock missile 0 and ball, each disabled on cycles 20-28 while it draws, at three positions a colour clock apart; then the ball through VDELBL, where the GRP1 write that copies the new enable into the old one does the disabling. Twenty-four sweep dumps (Space Invaders, Warlords, Midnight Magic...) agree with Stella only once the board acts on these writes three half clocks late (milestone 4). - ``hmove_wrap``: a quad- and a double-width player started so far right that it runs past the end of the line, at seven positions, the next lines with and without an HMOVE on cycle 2 (HMP0 $00, $80, $70): whether the extra motion clocks under the comb shift out the player's last pixels or the comb only delays them (Sea Hawk: the board drew the wrapped tail from visible clock 8, Stella hid it; milestone 4). - ``resp_start``: a 1x, 2x and 4x player reset by RESP0 on cycles 36-44, around the start of the copy its earlier RESP0 placed: what the reset does to a copy whose start is already decoded (hmove_wrap: the die drew a 2x copy two pixels short there, and a 4x one not at all). - ``hm_late``: HMP0 changed from $70 to $90 on cycles 18-30 after an HMOVE on cycle 2, as the motion runs out (BASIC Programming and Stellar Track write HMxx there; Stella agrees with the board only with those writes made three half clocks late; milestone 4). - ``refp_mid_draw``: REFP0 set and cleared on cycles 36-45 while an asymmetric player draws (Strawberry Shortcake; the same three half clocks for REFP; milestone 4). - ``hmove_wrap_end``: a 2x, 4x and 1x player started at the last positions of the line (RESP0 on cycles 70-73), the next lines with and without an HMOVE on cycle 2 and HMP0 $00: ``hmove_wrap`` for starts past 143, where Meteor Defense and Missile War's double-width player 1 wraps (the board drew its last pixels at visible clocks 8-13 after the comb; both detectors hide them; milestone 4). - ``resm_end``: missile 0 reset on cycles 70-73, 1, 2, 4 and 8 wide, on lines with and without an HMOVE on cycle 2 and HMM0 $00 (Raumpatrouille resets its 4-wide missile 0 at visible clock 150: the board draws it at 155-158, both detectors do not draw it; milestone 4). - ``starfield``: StarMaster's star: an HMOVE on cycle 2 of every line, HMBL written on cycle 43, RESBL on cycle 33, HMBL rewritten on cycles 41 and 27 between the HMOVEs, then the ball enabled for two lines, for 16 pairs of HMBL values (StarMaster's stars sit elsewhere on the board than on both detectors; milestone 4). - ``resmp_release``: missile 1 locked to player 1 by RESMP1 and released on cycle 26, with player sizes and copies $30, $36, $06, $00, $35 and $37 (missile 8 or 1 wide), on lines with an HMOVE on cycle 2 and HMM1 $C0 written after the release, then the same without HMOVEs, then GRP1 cleared after the release to show the missile alone at every missile width with 1x, 2x and 4x players. Frostbite's ice floes do this every frame and the board draws the missile two pixels right of where Stella does; tia-fpga's ``missiles`` releases RESMP only with a 1-wide missile and no HMOVE (milestone 4). """ from __future__ import annotations import argparse from pathlib import Path # TIA write addresses. VSYNC, VBLANK, WSYNC, RSYNC, NUSIZ0, COLUP0, COLUBK, RESP0, GRP0 = ( 0x00, 0x01, 0x02, 0x03, 0x04, 0x06, 0x09, 0x10, 0x1B, ) # fmt: skip COLUP1, RESP1, GRP1, CXCLR = 0x07, 0x11, 0x1C, 0x2C HMP0, HMOVE, HMCLR, VDELP0 = 0x20, 0x2A, 0x2B, 0x25 COLUPF, CTRLPF, PF0, PF1, PF2 = 0x08, 0x0A, 0x0D, 0x0E, 0x0F RESBL, ENABL = 0x14, 0x1F RESM0, ENAM0, HMM0, HMBL, VDELBL = 0x12, 0x1D, 0x22, 0x24, 0x27 REFP0 = 0x0B NUSIZ1, ENAM1, HMM1, RESMP1 = 0x05, 0x1E, 0x23, 0x29 CXPPMM_READ = 0x37 # read address 7, through the $30 mirror class Code: """A 6502 emitter for the few instructions these cartridges need.""" def __init__(self, origin: int = 0xF000) -> None: self.origin = origin self.bytes = bytearray() @property def here(self) -> int: return self.origin + len(self.bytes) def emit(self, *values: int) -> None: self.bytes.extend(values) def sei(self): self.emit(0x78) def cld(self): self.emit(0xD8) def lda_imm(self, v): self.emit(0xA9, v) def ldx_imm(self, v): self.emit(0xA2, v) def txa(self): self.emit(0x8A) def txs(self): self.emit(0x9A) def inx(self): self.emit(0xE8) def sta_zp(self, a): # 3 cycles, the write on the last self.emit(0x85, a) def sta_zpx(self, a): self.emit(0x95, a) def sta_abs(self, a): # 4 cycles, the write on the last self.emit(0x8D, a & 0xFF, a >> 8) def nop(self): # 2 cycles self.emit(0xEA) def bit_zp(self, a): # 3 cycles, a read self.emit(0x24, a) def lda_zp(self, a): self.emit(0xA5, a) def bne(self, target: int): offset = target - (self.here + 2) self.emit(0xD0, offset & 0xFF) def jmp(self, target: int): self.emit(0x4C, target & 0xFF, target >> 8) def delay(self, cycles: int) -> None: """Exactly ``cycles`` CPU cycles (any number but 1) of NOPs and one BIT $80.""" if cycles == 1 or cycles < 0: raise ValueError(f"cannot delay {cycles} cycles") if cycles % 2: self.bit_zp(0x80) cycles -= 3 for _ in range(cycles // 2): self.nop() def dex(self): self.emit(0xCA) def long_delay(self, cycles: int) -> None: """Exactly ``cycles`` CPU cycles in few bytes: LDX #n, then DEX/BNE n times (5n + 1 cycles), the rest as :meth:`delay`. The loop is kept within a page, so its taken branches cost 3 cycles each.""" while cycles >= 14 and (self.here + 2) >> 8 != (self.here + 5) >> 8: self.nop() # move the loop off the page boundary cycles -= 2 if cycles < 14: self.delay(cycles) return n = (cycles - 1) // 5 if cycles - (5 * n + 1) == 1: n -= 1 # leave 6, not 1 self.ldx_imm(n) loop = self.here self.dex() self.bne(loop) self.delay(cycles - (5 * n + 1)) def image(self) -> bytes: if len(self.bytes) > 0xFFA: raise ValueError("cartridge code does not fit in 4K") rom = bytearray(self.bytes) + bytes(0x1000 - len(self.bytes)) rom[0xFFC:0xFFE] = bytes((self.origin & 0xFF, (self.origin >> 8) & 0xFF)) return bytes(rom) def start(code: Code) -> None: """Clear zero page, every TIA register and RSYNC with it.""" code.sei() code.cld() code.ldx_imm(0) code.txa() loop = code.here code.sta_zpx(0) code.txs() code.inx() code.bne(loop) def retrigger() -> bytes: code = Code() start(code) code.lda_imm(0x0E) code.sta_zp(COLUP0) code.lda_imm(0x84) code.sta_zp(COLUBK) code.lda_imm(0xFF) code.sta_zp(GRP0) code.lda_imm(0x03) # three copies close code.sta_zp(NUSIZ0) gaps = (5, 6, 7, 10, 11, 12, 21, 22, 23, 53, 54, 55) for lead in (24, 25, 26, 27): # four phases of the object counter for gap in gaps: for _ in range(2): # the second line shows the main copy too code.sta_zp(WSYNC) code.delay(lead) code.sta_zp(RESP0) code.delay(gap - 3) code.sta_zp(RESP0) end = code.here code.sta_zp(WSYNC) code.jmp(end) return code.image() def vblank_collisions() -> bytes: code = Code() start(code) for register, value in ((COLUP0, 0x1A), (COLUP1, 0x7C), (GRP0, 0xFF), (GRP1, 0xFF)): code.lda_imm(value) code.sta_zp(register) for strobe in (RESP0, RESP1): # both players at the same position code.sta_zp(WSYNC) code.delay(30) code.sta_zp(strobe) loop = code.here for vblank in (0x00, 0x02, 0x00, 0x02): code.lda_imm(vblank) code.sta_zp(VBLANK) code.sta_zp(WSYNC) code.sta_zp(CXCLR) # early in the line, before the players are drawn code.sta_zp(WSYNC) # the line the players overlap on code.lda_zp(CXPPMM_READ) # the die drives D7 = P0/P1 on the pins code.lda_zp(CXPPMM_READ) code.sta_zp(WSYNC) code.jmp(loop) return code.image() def write_at(code: Code, address: int, cycle: int, now: int) -> None: """From an instruction starting on cycle ``now``, a store to ``address`` that writes on ``cycle`` (cycle k of a line writes on step 6k + 4; after a WSYNC the next instruction starts on cycle 0).""" gap = cycle - now # a zero-page store writes on its third cycle, now + 2 if gap == 3: code.sta_abs(address) elif gap == 2 or gap >= 4: code.long_delay(gap - 2) code.sta_zp(address) else: raise ValueError(f"cannot write {gap} cycles ahead") def hmove_cycles() -> bytes: code = Code() start(code) code.lda_imm(0x0E) code.sta_zp(COLUP0) code.lda_imm(0x84) code.sta_zp(COLUBK) code.lda_imm(0xFF) code.sta_zp(GRP0) # After a WSYNC the next instruction starts on cycle 0 of the line. for motion in (0x80, 0x70): for cycle in range(76): code.sta_zp(WSYNC) code.sta_zp(RESP0) # writes on cycle 2: the same start every time code.lda_imm(motion) # cycles 3-4 code.sta_zp(HMP0) # writes on cycle 7 # Early cycles are reached by counting on into the next line. write_at(code, HMOVE, cycle if cycle >= 11 else 76 + cycle, 8) code.sta_zp(WSYNC) code.sta_zp(HMCLR) # no more motion; two lines show where it ended code.sta_zp(WSYNC) end = code.here code.sta_zp(WSYNC) code.jmp(end) return code.image() def hmove_resp0() -> bytes: code = Code() start(code) code.lda_imm(0x0E) code.sta_zp(COLUP0) code.lda_imm(0x84) code.sta_zp(COLUBK) code.lda_imm(0xFF) code.sta_zp(GRP0) code.lda_imm(0x70) code.sta_zp(HMP0) # the same motion for every HMOVE for cycle in (72, 73, 74, 75, 0, 1, 2): for gap in range(3, 25): code.sta_zp(WSYNC) at = cycle if cycle >= 11 else 76 + cycle write_at(code, HMOVE, at, 0) write_at(code, RESP0, at + gap, at + 1) code.sta_zp(WSYNC) code.sta_zp(WSYNC) # a whole line shows where the player ended end = code.here code.sta_zp(WSYNC) code.jmp(end) return code.image() def grp_mid_draw() -> bytes: code = Code() start(code) code.lda_imm(0x0E) code.sta_zp(COLUP0) code.lda_imm(0x84) code.sta_zp(COLUBK) code.sta_zp(WSYNC) code.sta_zp(RESP0) # writes on cycle 2: the player starts at visible clock 3 for motion in (0x00, 0xF0, 0xF0): # then one and two clocks further right code.lda_imm(motion) code.sta_zp(HMP0) code.sta_zp(WSYNC) code.sta_zp(HMOVE) code.sta_zp(WSYNC) code.sta_zp(HMCLR) for vdel in (0, 1): code.lda_imm(vdel) code.sta_zp(VDELP0) for cycle in range(20, 29): code.sta_zp(WSYNC) code.lda_imm(0xFF) # cycles 0-1 code.sta_zp(GRP0) # writes on cycle 4: new P0 = $FF code.lda_imm(0x00) # cycles 5-6 if not vdel: write_at(code, GRP0, cycle, 7) # clears it while it draws else: code.sta_zp(GRP1) # cycle 9: old P0 = $FF code.sta_zp(GRP0) # cycle 12: new P0 = $00, old still $FF write_at(code, GRP1, cycle, 13) # copies new to old while it draws end = code.here code.sta_zp(WSYNC) code.jmp(end) return code.image() def hmove_playfield() -> bytes: code = Code() start(code) for register, value in ((COLUPF, 0x1E), (COLUBK, 0x84), (PF0, 0x30), (PF1, 0xE4), (PF2, 0x9D)): code.lda_imm(value) code.sta_zp(register) for ctrlpf in (0x00, 0x01): # plain, then reflected code.lda_imm(ctrlpf) code.sta_zp(CTRLPF) for _ in range(2): code.sta_zp(WSYNC) code.sta_zp(HMOVE) # writes on cycle 2: the comb on this line code.sta_zp(WSYNC) # a line without write_at(code, HMOVE, 75, 0) # the comb on the next line (74 is the C27 tie) code.sta_zp(WSYNC) code.sta_zp(WSYNC) end = code.here code.sta_zp(WSYNC) code.jmp(end) return code.image() def ball_score() -> bytes: code = Code() start(code) for register, value in ((COLUP0, 0x1E), (COLUP1, 0x7C), (COLUPF, 0x4E), (COLUBK, 0x84), (PF1, 0x0F), (ENABL, 0x02)): # fmt: skip code.lda_imm(value) code.sta_zp(register) for ctrlpf in (0x00, 0x02, 0x06): code.lda_imm(ctrlpf | 0x20) # a 4-clock ball code.sta_zp(CTRLPF) for cycle in (30, 60): # the left half, then the right code.sta_zp(WSYNC) write_at(code, RESBL, cycle, 0) code.sta_zp(WSYNC) code.sta_zp(WSYNC) end = code.here code.sta_zp(WSYNC) code.jmp(end) return code.image() def enable_mid_draw() -> bytes: code = Code() start(code) for register, value in ((COLUP0, 0x0E), (COLUPF, 0x4E), (COLUBK, 0x84), (NUSIZ0, 0x30), (CTRLPF, 0x30)): # fmt: skip code.lda_imm(value) # an 8-clock missile and ball code.sta_zp(register) code.sta_zp(WSYNC) code.sta_zp(RESM0) # writes on cycle 2 code.sta_zp(WSYNC) code.sta_zp(RESBL) # writes on cycle 2 for motion in (0x00, 0xF0, 0xF0): # then one and two clocks further right code.lda_imm(motion) code.sta_zp(HMM0) code.sta_zp(HMBL) code.sta_zp(WSYNC) code.sta_zp(HMOVE) code.sta_zp(WSYNC) code.sta_zp(HMCLR) for register in (ENAM0, ENABL, VDELBL): for cycle in range(20, 29): code.sta_zp(WSYNC) code.lda_imm(0x02) # cycles 0-1 if register != VDELBL: code.sta_zp(register) # writes on cycle 4: enabled code.lda_imm(0x00) # cycles 5-6 write_at(code, register, cycle, 7) # disabled while it draws else: code.sta_zp(VDELBL) # cycle 4: the ball shows the old enable code.sta_zp(ENABL) # cycle 7: new on code.sta_zp(GRP1) # cycle 10: old on code.lda_imm(0x00) # cycles 11-12 code.sta_zp(ENABL) # cycle 15: new off, old still on write_at(code, GRP1, cycle, 16) # copies new to old while it draws code.lda_imm(0x00) code.sta_zp(VDELBL) code.sta_zp(ENAM0) code.sta_zp(ENABL) end = code.here code.sta_zp(WSYNC) code.jmp(end) return code.image() def hmove_wrap() -> bytes: code = Code() start(code) for register, value in ((COLUP0, 0x0E), (COLUBK, 0x84), (GRP0, 0xFF)): code.lda_imm(value) code.sta_zp(register) for size in (0x07, 0x05): # quad, then double width code.lda_imm(size) code.sta_zp(NUSIZ0) for cycle in (63, 65, 66, 67, 68, 69, 70): # starts from 121 to 143 or so code.sta_zp(WSYNC) write_at(code, RESP0, cycle, 0) for motion in (0x00, 0x80, 0x70): # none, eight right (the most), seven left code.lda_imm(motion) code.sta_zp(HMP0) for hmove in (False, True, True, False): code.sta_zp(WSYNC) if hmove: code.sta_zp(HMOVE) # writes on cycle 2 code.sta_zp(WSYNC) code.sta_zp(HMCLR) end = code.here code.sta_zp(WSYNC) code.jmp(end) return code.image() def resp_start() -> bytes: code = Code() start(code) for register, value in ((COLUP0, 0x0E), (COLUBK, 0x84), (GRP0, 0xFF)): code.lda_imm(value) code.sta_zp(register) for size in (0x00, 0x05, 0x07): code.lda_imm(size) code.sta_zp(NUSIZ0) for cycle in range(36, 45): # around the copy's start, 57 or so code.sta_zp(WSYNC) write_at(code, RESP0, 40, 0) # the copy, drawn from the next line code.sta_zp(WSYNC) code.sta_zp(WSYNC) write_at(code, RESP0, cycle, 0) # a reset as that copy starts code.sta_zp(WSYNC) end = code.here code.sta_zp(WSYNC) code.jmp(end) return code.image() def hm_late() -> bytes: code = Code() start(code) for register, value in ((COLUP0, 0x0E), (COLUBK, 0x84), (GRP0, 0xFF)): code.lda_imm(value) code.sta_zp(register) for cycle in range(18, 31): # around the end of the motion an HMOVE on cycle 2 starts code.sta_zp(WSYNC) write_at(code, RESP0, 40, 0) # the same start each time code.lda_imm(0x70) code.sta_zp(HMP0) code.sta_zp(WSYNC) code.sta_zp(HMOVE) # writes on cycle 2 code.lda_imm(0x90) # cycles 3-4 write_at(code, HMP0, cycle, 5) # a new motion as the old one runs out code.sta_zp(WSYNC) code.sta_zp(HMCLR) code.sta_zp(WSYNC) # the player where the motion left it end = code.here code.sta_zp(WSYNC) code.jmp(end) return code.image() def refp_mid_draw() -> bytes: code = Code() start(code) for register, value in ((COLUP0, 0x0E), (COLUBK, 0x84), (GRP0, 0xE4)): # an asymmetric shape code.lda_imm(value) code.sta_zp(register) code.sta_zp(WSYNC) write_at(code, RESP0, 40, 0) for value in (0x08, 0x00): # reflect on, then off for cycle in range(36, 46): # the player draws from about clock 57 code.sta_zp(WSYNC) code.lda_imm(value ^ 0x08) code.sta_zp(REFP0) code.lda_imm(value) write_at(code, REFP0, cycle, 7) end = code.here code.sta_zp(WSYNC) code.jmp(end) return code.image() def hmove_wrap_end() -> bytes: code = Code() start(code) for register, value in ((COLUP0, 0x0E), (COLUBK, 0x84), (GRP0, 0xFF)): code.lda_imm(value) code.sta_zp(register) for size in (0x05, 0x07, 0x00): # double, quad, then single width code.lda_imm(size) code.sta_zp(NUSIZ0) for cycle in (70, 71, 72, 73): # starts from about 145 to the line's end code.sta_zp(WSYNC) write_at(code, RESP0, cycle, 0) for hmove in (False, True, True, False): code.sta_zp(WSYNC) if hmove: code.sta_zp(HMOVE) # writes on cycle 2, HMP0 $00 end = code.here code.sta_zp(WSYNC) code.jmp(end) return code.image() def resm_end() -> bytes: code = Code() start(code) for register, value in ((COLUP0, 0x0E), (COLUBK, 0x84), (ENAM0, 0x02)): code.lda_imm(value) code.sta_zp(register) for size in (0x25, 0x05, 0x35, 0x15): # missile 4, 1, 8 and 2 wide (2x player) code.lda_imm(size) code.sta_zp(NUSIZ0) for cycle in (70, 71, 72, 73): # resets from about 142 to the line's end code.sta_zp(WSYNC) write_at(code, RESM0, cycle, 0) for hmove in (False, True, False, True, False): code.sta_zp(WSYNC) if hmove: code.sta_zp(HMOVE) # writes on cycle 2, HMM0 $00 end = code.here code.sta_zp(WSYNC) code.jmp(end) return code.image() def starfield() -> bytes: code = Code() start(code) for register, value in ((COLUPF, 0x0E), (COLUBK, 0x84), (CTRLPF, 0x00)): code.lda_imm(value) code.sta_zp(register) def hmove_line() -> None: code.sta_zp(WSYNC) code.sta_zp(HMOVE) # writes on cycle 2; the next instruction starts on 3 for first in (0x11, 0x33, 0xF0, 0x70): for then in (0x07, 0x06, 0xF9, 0x80): hmove_line() code.lda_imm(first) write_at(code, HMBL, 43, 5) hmove_line() write_at(code, RESBL, 33, 3) for cycle in (41, 27, 41, 27): # HMBL rewritten between the HMOVEs hmove_line() code.lda_imm(then) write_at(code, HMBL, cycle, 5) hmove_line() code.lda_imm(0x02) write_at(code, ENABL, 14, 5) hmove_line() # the ball drawn on these two lines hmove_line() code.lda_imm(0x00) write_at(code, ENABL, 13, 5) end = code.here code.sta_zp(WSYNC) code.jmp(end) return code.image() def resmp_release() -> bytes: code = Code() start(code) for register, value in ((COLUP1, 0x0E), (COLUBK, 0x84), (GRP1, 0xFF), (ENAM1, 0x02)): code.lda_imm(value) code.sta_zp(register) for hmove in (True, False): for size in (0x30, 0x36, 0x06, 0x00, 0x35, 0x37): code.lda_imm(size) code.sta_zp(NUSIZ1) code.sta_zp(WSYNC) write_at(code, RESP1, 47, 0) # Frostbite's position code.lda_imm(0x02) code.sta_zp(RESMP1) # locked from here for _ in range(2): code.sta_zp(WSYNC) if hmove: code.sta_zp(HMOVE) # writes on cycle 2, HMxx all clear code.sta_zp(WSYNC) if hmove: code.sta_zp(HMOVE) code.lda_imm(0x00) write_at(code, RESMP1, 26, 5 if hmove else 2) # released mid-line code.lda_imm(0xC0) # four right code.sta_zp(HMM1) # cycles 29-31 code.sta_zp(WSYNC) if hmove: code.sta_zp(HMOVE) code.sta_zp(HMCLR) for _ in range(3): code.sta_zp(WSYNC) # the missile where it was left # The missile alone: GRP1 cleared after the release, every missile width # with a 1x, 2x and 4x player (a 1-wide missile hides inside a $FF player). for size in (0x00, 0x10, 0x20, 0x30, 0x05, 0x25, 0x35, 0x07, 0x27, 0x37): code.lda_imm(size) code.sta_zp(NUSIZ1) code.lda_imm(0xFF) code.sta_zp(GRP1) code.sta_zp(WSYNC) write_at(code, RESP1, 47, 0) code.lda_imm(0x02) code.sta_zp(RESMP1) code.sta_zp(WSYNC) code.sta_zp(WSYNC) code.lda_imm(0x00) write_at(code, RESMP1, 26, 2) code.sta_zp(GRP1) # cycles 29-31 for _ in range(3): code.sta_zp(WSYNC) end = code.here code.sta_zp(WSYNC) code.jmp(end) return code.image() CARTRIDGES = { "retrigger": retrigger, "vblank_collisions": vblank_collisions, "hmove_cycles": hmove_cycles, "hmove_resp0": hmove_resp0, "grp_mid_draw": grp_mid_draw, "hmove_playfield": hmove_playfield, "ball_score": ball_score, "enable_mid_draw": enable_mid_draw, "hmove_wrap": hmove_wrap, "resp_start": resp_start, "hm_late": hm_late, "refp_mid_draw": refp_mid_draw, "resmp_release": resmp_release, "hmove_wrap_end": hmove_wrap_end, "resm_end": resm_end, "starfield": starfield, } def main() -> int: parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0]) parser.add_argument("names", nargs="*", default=sorted(CARTRIDGES)) parser.add_argument("--out", type=Path, default=Path("tests/die_carts")) args = parser.parse_args() args.out.mkdir(parents=True, exist_ok=True) for name in args.names: image = CARTRIDGES[name]() (args.out / f"{name}.bin").write_bytes(image) print(f"{name}.bin") return 0 if __name__ == "__main__": raise SystemExit(main())