; Our probes (probes/open_bus, hv_latch, midframe, clock_ratio), ported to ; the suite, and the OAM/CGRAM sweeps that follow from the console's ; 04-midframe result (2026-10-24: OAM writes during rendering land, near the ; PPU's position, and touch 3-4 bytes). Each fills RES; the layouts are in ; scripts/suite_results.py. ; --- OBUS: PPU open bus (probes/open_bus/open_bus.s), 11 bytes ------------- TestOpenBus: .a8 lda #$80 sta INIDISP lda #2 ; colour 2 = $7FFF, colour 3 = $0000 sta CGADD lda #$FF sta CGDATA lda #$7F sta CGDATA stz CGDATA stz CGDATA lda $2100 ; 0: write-only, absolute sta RES+0 lda f:$002100 ; 1: write-only, long sta RES+1 jsr PrimePpu1FF ; 2 lda STAT77 sta RES+2 jsr PrimePpu100 ; 3 lda STAT77 sta RES+3 jsr PrimePpu2FF ; 4 lda STAT78 sta RES+4 jsr PrimePpu200 ; 5 lda STAT78 sta RES+5 lda #2 ; 6: CGRAM high byte after a $FF low byte sta CGADD lda RDCGRAM lda RDCGRAM sta RES+6 jsr PrimePpu1FF ; 7 jsr PrimePpu200 lda STAT77 sta RES+7 jsr PrimePpu1FF ; 8 jsr PrimePpu200 lda STAT78 sta RES+8 jsr PrimePpu100 ; 9 jsr PrimePpu2FF lda STAT77 sta RES+9 jsr PrimePpu100 ; 10 jsr PrimePpu2FF lda STAT78 sta RES+10 rts PrimePpu1FF: lda #$FF sta M7A stz M7A lda #$01 sta M7B lda MPYL rts PrimePpu100: lda #$FF sta M7A stz M7A stz M7B lda MPYL rts PrimePpu2FF: lda #2 sta CGADD lda RDCGRAM rts PrimePpu200: lda #3 sta CGADD lda RDCGRAM rts ; --- HVLT: $2137 latch against WRIO latch (probes/hv_latch) ---------------- ; ; Per H-IRQ dot in HvDots: 16 (H, V) pairs latched by `lda $2137` right after ; the WAI wake, then 16 by `stz $4201`, interleaved; 128 bytes per dot. HV_SAMPLES = 16 hv_dot = $40 ; 16-bit index into HvDots hv_sample = $42 ; 16-bit hv_out = $44 ; 16-bit RES offset of this dot's block TestHvLatch: .a8 rep #$20 .a16 stz hv_dot stz hv_out @dot: ldx hv_dot lda HvDots,x sta HTIMEL sep #$20 .a8 lda #$10 ; H-IRQ only, every line sta NMITIMEN ldx #$0000 @loop: stx hv_sample lda #$80 sta WRIO lda TIMEUP wai lda SLHV jsr ReadCounters jsr @store_a lda #$80 sta WRIO lda TIMEUP wai stz WRIO jsr ReadCounters lda #$80 sta WRIO jsr @store_b ldx hv_sample inx cpx #HV_SAMPLES bne @loop stz NMITIMEN lda TIMEUP rep #$20 .a16 lda hv_out clc adc #HV_SAMPLES*8 sta hv_out inc hv_dot inc hv_dot lda hv_dot cmp #HvDotsEnd-HvDots bne @dot sep #$20 .a8 rts @store_a: ; RES[out + 4*sample] = H, V rep #$20 .a16 lda hv_sample asl a asl a clc adc hv_out tax bra @store @store_b: ; RES[out + 64 + 4*sample] = H, V rep #$20 .a16 lda hv_sample asl a asl a clc adc hv_out adc #HV_SAMPLES*4 tax @store: lda hval sta RES,x lda vval sta RES+2,x sep #$20 .a8 rts ; --- MIDF: CGRAM/OAM write landing (probes/midframe), 90 bytes -------------- ; ; Six cases x three runs x (found 16, count 8, H 16), as the probe saved them. mf_case = $40 ; 16-bit mf_run = $42 ; 16-bit found = $44 ; 16-bit, $FFFF = not found count = $46 ; 16-bit OAM_BASE = $0800 ; WRAM: OAM as read back after the fill TestMidframe: .a8 rep #$20 .a16 stz mf_case @case: stz mf_run @run: sep #$20 .a8 jsr MidframeOne rep #$20 .a16 lda mf_case ; X = (case*3 + run) * 5 asl a adc mf_case adc mf_run sta tmp asl a asl a adc tmp tax lda found sta RES,x sep #$20 .a8 lda count sta RES+2,x rep #$20 .a16 lda hval sta RES+3,x inc mf_run lda mf_run cmp #3 bne @run inc mf_case lda mf_case cmp #6 bne @case sep #$20 .a8 rts MidframeOne: .a8 lda #$80 sta INIDISP jsr ZeroCgram jsr FillOamF0 jsr ReadOamBase lda #$11 ; BG1 + OBJ on the main screen sta TM rep #$20 .a16 lda mf_case asl a tax lda MfVTimes,x sta VTIMEL lda MfHTimes,x sta HTIMEL sep #$20 .a8 lda #$30 ; H+V IRQ sta NMITIMEN jsr WaitVblankStart lda #$0F sta INIDISP lda TIMEUP wai lda mf_case cmp #3 bcs @oam lda #$80 sta CGADD lda #$5A sta CGDATA lda #$25 sta CGDATA bra @written @oam: lda #$40 sta OAMADDL stz OAMADDH lda #$A5 sta OAMDATA lda #$5A sta OAMDATA @written: lda SLHV jsr ReadCounters stz NMITIMEN lda TIMEUP lda #$80 sta INIDISP lda mf_case cmp #3 bcs MfSearchOam ; fall through ; found = first colour equal to $255A, count = non-zero colours. MfSearchCgram: stz CGADD jsr ClearFound ldx #$0000 @next: lda RDCGRAM sta tmp lda RDCGRAM and #$7F ; bit 7 is PPU2 open bus sta tmp+1 ora tmp beq @skip inc count lda tmp+1 cmp #$25 bne @skip lda tmp cmp #$5A bne @skip jsr FoundAtX @skip: inx cpx #256 bne @next rts ; found = first byte equal to $A5, count = bytes that differ from the baseline. MfSearchOam: stz OAMADDL stz OAMADDH jsr ClearFound ldx #$0000 @next: lda RDOAM cmp OAM_BASE,x beq @skip inc count cmp #$A5 bne @skip jsr FoundAtX @skip: inx cpx #544 bne @next rts ClearFound: lda #$FF sta found sta found+1 stz count stz count+1 rts FoundAtX: lda found+1 cmp #$FF bne :+ stx found : rts ZeroCgram: stz CGADD ldx #512 : stz CGDATA dex bne :- rts ReadOamBase: stz OAMADDL stz OAMADDH ldx #$0000 : lda RDOAM sta OAM_BASE,x inx cpx #544 bne :- rts FillOamF0: stz OAMADDL stz OAMADDH lda #$F0 ldx #544 : sta OAMDATA dex bne :- rts ; Byte i = i & $FF: a read or a landed write names its own address. FillOamIdentity: stz OAMADDL stz OAMADDH ldx #$0000 : txa sta OAMDATA inx cpx #544 bne :- rts ; --- CLKR: S-SMP clock against the master clock (probes/clock_ratio) ------- ; ; The SPC700 program adds timer 2's ticks into a 24-bit total on ports 0-2. ; Three runs of 600 frames; each records the total at every 60th vblank ; start (11 samples x 3 bytes). Then port 3 = $A5 sends the S-SMP back to ; its IPL ROM, so a later test can upload again. RES: runs, samples, frames ; per sample (16), then 3 x 33 bytes. CK_RUNS = 3 CK_SAMPLES = 11 CK_STEP = 60 SPC_ORG = $0200 ck_run = $40 ; 16-bit ck_sample = $42 ; 16-bit ck_out = $44 ; 16-bit probe = $46 ; 3 bytes TestClockRatio: .a8 lda #CK_RUNS sta RES+0 lda #CK_SAMPLES sta RES+1 lda #CK_STEP sta RES+2 stz RES+3 jsr UploadSpc bcs @failed ldx #10 ; let the program start and the count settle : jsr WaitVblankStart dex bne :- rep #$20 .a16 lda #4 sta ck_out stz ck_run @run: stz ck_sample @sample: sep #$20 .a8 jsr WaitVblankStart jsr ReadTicks ldx ck_out lda probe sta RES,x lda probe+1 sta RES+1,x lda probe+2 sta RES+2,x rep #$20 .a16 txa clc adc #3 sta ck_out inc ck_sample lda ck_sample cmp #CK_SAMPLES beq @next_run sep #$20 .a8 ldx #CK_STEP-1 : jsr WaitVblankStart dex bne :- rep #$20 .a16 bra @sample @next_run: inc ck_run lda ck_run cmp #CK_RUNS bne @run sep #$20 .a8 lda #$A5 ; back to the IPL ROM sta APUIO3 jsr WaitIpl stz APUIO3 rts @failed: lda #$FF sta RES+0 rts ; probe = ports 0-2, read until two reads agree. ReadTicks: lda APUIO0 sta probe lda APUIO1 sta probe+1 lda APUIO2 sta probe+2 lda APUIO0 cmp probe bne ReadTicks lda APUIO1 cmp probe+1 bne ReadTicks lda APUIO2 cmp probe+2 bne ReadTicks rts ; Carry set if the IPL ROM's $BBAA did not show within a few seconds. WaitIpl: ldy #8 @frame: ldx #$0000 : rep #$20 .a16 lda APUIO0 cmp #$BBAA sep #$20 .a8 beq @ok dex bne :- dey bne @frame sec rts @ok: clc rts ; The IPL ROM's transfer protocol (wiki/Booting the SPC700). Carry set if ; the S-SMP never answered. UploadSpc: jsr WaitIpl bcc :+ rts : rep #$20 .a16 lda #SPC_ORG sta APUIO2 sep #$20 .a8 lda #$01 sta APUIO1 lda #$CC sta APUIO0 : cmp APUIO0 bne :- ldx #$0000 @byte: lda SpcProgram,x sta APUIO1 txa sta APUIO0 : cmp APUIO0 bne :- inx cpx #SpcProgramEnd - SpcProgram bne @byte rep #$20 .a16 lda #SPC_ORG sta APUIO2 sep #$20 .a8 stz APUIO1 ; 0: jump to the entry point txa clc adc #2 bne :+ inc a : sta APUIO0 clc rts ; --- IPLS: an IPL transfer's speed (undisbeliever's ipl-speed-test) ----------- ; ; 32768 bytes (byte j = j >> 7, his `fill 128, i`) to ARAM $0200 through the ; IPL ROM's protocol, three blocks back to back from the FastROM mirror, each ; started at an NMI. Per block 9 bytes: frames counted by the NMI handler, ; the H/V latch at the start and at the last byte's echo (H lo, H hi raw, V ; lo, V hi raw each). The S-SMP side is the IPL ROM's fixed loop, so the time ; follows the S-SMP clock against the master clock (U8), coarsely. Then the ; S-SMP is sent back to $FFC0. Run 0 = $FF: the S-SMP never answered. IPL_FRAMES = $1E44 ; 16-bit, counted by IplNmi ip_run = $40 ; 16-bit ip_out = $42 ; 16-bit ip_kick = $44 ; the port 0 value that starts the next block TestIplSpeed: .a8 jsr WaitIpl bcc :+ lda #$FF sta RES rts : GO_FAST rep #$20 .a16 lda #.loword(IplNmi) sta NMI_VEC sep #$20 .a8 stz NMI_VEC+2 ldx #$0000 stx ip_run stx ip_out stx IPL_FRAMES lda #$CC sta ip_kick lda RDNMI lda #$80 sta NMITIMEN @block: rep #$20 .a16 lda #$0200 sta APUIO2 sep #$20 .a8 lda #$01 sta APUIO1 wai wai lda a:SLHV ldx ip_out lda STAT78 jsr TmStoreRaw4 stx ip_out lda IPL_FRAMES sta tmp lda ip_kick sta APUIO0 : cmp APUIO0 bne :- ldx #$0000 @byte: rep #$20 .a16 txa asl a xba sep #$20 .a8 sta APUIO1 txa sta APUIO0 : cmp APUIO0 bne :- inx cpx #$8000 bne @byte lda a:SLHV lda IPL_FRAMES sec sbc tmp ldx ip_out sta RES,x inx lda STAT78 jsr TmStoreRaw4 stx ip_out lda #$01 ; the next kick: last index ($FF) + 2 sta ip_kick rep #$20 .a16 inc ip_run lda ip_run cmp #3 sep #$20 .a8 bne @block stz NMITIMEN rep #$20 ; home: jump to the IPL ROM .a16 lda #$FFC0 sta APUIO2 sep #$20 .a8 stz APUIO1 lda #$01 sta APUIO0 GO_SLOW jsr WaitIpl rts IplNmi: ; A is the echo being waited for: keep it rep #$20 inc a:IPL_FRAMES sep #$20 bit a:RDNMI rti ; --- OAWA, OAWB: where an OAM write lands, swept across line 100 ---------- ; ; At each H-IRQ dot 0, 4, ..., 336 on line 100 (display on, BG1 + OBJ), the ; midframe write: OAMADD = $0040, OAMDATA = $A5, $5A; then H latched. The ; whole of OAM is compared with a read-back taken before, and up to six ; changed bytes are kept. OAWA fills OAM with $F0 (no sprite on the line, as ; 04-midframe did); OAWB with byte i = i (sprites on every line, so the PPU ; also fetches). Per dot 21 bytes: H (16), changed count (8, capped at 255), ; six (index 16, new value 8). SW_DOTS = 85 SW_STEP = 4 sw_i = $40 ; 16-bit dot index sw_out = $42 ; 16-bit RES offset of this dot's record rec_ptr = $44 ; 16-bit RES offset of the next change record variant = $46 sw_size = $48 ; 16-bit record size TestOamWriteF0: .a8 stz variant bra OamWriteSweep TestOamWriteIdentity: .a8 lda #1 sta variant OamWriteSweep: ; variant bit 0: identity fill; bit 1: no OAMADD write rep #$20 .a16 stz sw_i stz sw_out @dot: sep #$20 .a8 jsr OamPrepare lda variant ; chosen before the wake: the timed code and #$02 ; after it is format 1's bne @no_address jsr SweepArm lda #$40 sta OAMADDL stz OAMADDH lda #$A5 sta OAMDATA lda #$5A sta OAMDATA lda SLHV bra @written @no_address: jsr SweepArm lda #$A5 sta OAMDATA lda #$5A sta OAMDATA lda SLHV @written: jsr SweepDisarm jsr OamRecord lda #21 jsr SweepNext beq :+ jmp @dot : rts ; Force blank, the variant's fill, the read-back baseline, BG1 + OBJ on; ; for OAWC, OAMADD = $0040 (the V-Blank reload makes it byte $080; OAWA and ; OAWB leave it where the read-back left it, as format 1 did). OamPrepare: .a8 lda #$80 sta INIDISP lda variant and #$01 bne :+ jsr FillOamF0 bra :++ : jsr FillOamIdentity : jsr ReadOamBase lda variant and #$02 beq :+ lda #$40 ; OAWC: the address the V-Blank reload gives sta OAMADDL stz OAMADDH : lda #$11 sta TM rts ; RES at sw_out: H (16), changed count (8), up to six (index 16, value 8), ; comparing OAM with OAM_BASE. OamRecord: .a8 rep #$20 .a16 ldx sw_out lda hval sta RES,x txa clc adc #3 sta rec_ptr sep #$20 .a8 stz count stz OAMADDL stz OAMADDH ldy #$0000 @cmp: lda RDOAM cmp OAM_BASE,y beq @same xba ; B = new value lda count cmp #6 bcs @counted ldx rec_ptr xba sta RES+2,x rep #$20 .a16 tya sta RES,x txa clc adc #3 sta rec_ptr sep #$20 .a8 @counted: lda count cmp #$FF beq @same inc count @same: iny cpy #544 bne @cmp ldx sw_out lda count sta RES+2,x rts ; --- OAWC: the OAM write sweep with no OAMADD write (format 2) ---------------- ; ; As OAWA (OAM $F0, no sprite on the line) but the two OAMDATA writes come ; straight after the wake: where the PPU's own address is, without the ; CPU's OAMADD write feeding it. 85 x 21 bytes. TestOamWriteNoAddress: .a8 lda #$02 sta variant jmp OamWriteSweep ; --- OAWD: the gap between the OAMADD write and the data writes (format 2) ---- ; ; At line 100 dot 100, OAMADD = $0040, then a delay loop of g = 0..31 passes ; (36 master clocks each), then OAMDATA $A5, $5A. On the console (format 1, ; OAWA) the landing address looked like sprite 32 (OAMADD's) plus one sprite ; per 2 dots since that write; this sweeps the gap to see it. 32 x 21 bytes. og_gap = $4A ; 16-bit TestOamWriteGap: .a8 stz variant rep #$20 .a16 stz sw_out stz og_gap @gap: sep #$20 .a8 jsr OamPrepare rep #$20 .a16 lda #100 sta VTIMEL sta HTIMEL sep #$20 .a8 lda #$30 sta NMITIMEN jsr WaitVblankStart lda #$0F sta INIDISP lda TIMEUP wai lda #$40 sta OAMADDL stz OAMADDH ldx og_gap beq @write : dex bne :- @write: lda #$A5 sta OAMDATA lda #$5A sta OAMDATA lda SLHV jsr SweepDisarm jsr OamRecord rep #$20 .a16 lda sw_out clc adc #21 sta sw_out inc og_gap lda og_gap cmp #32 sep #$20 .a8 beq :+ jmp @gap : rts ; Display on at the next vblank start; H+V IRQ at line 100, dot 4*sw_i; WAI. SweepArm: .a8 rep #$20 .a16 lda #100 sta VTIMEL lda sw_i asl a asl a sta HTIMEL sep #$20 .a8 lda #$30 sta NMITIMEN jsr WaitVblankStart lda #$0F sta INIDISP lda TIMEUP wai rts ; After the latch: counters read, IRQ off, force blank. SweepDisarm: .a8 jsr ReadCounters stz NMITIMEN lda TIMEUP lda #$80 sta INIDISP rts ; A = record size: sw_out += A, sw_i += 1. Z clear while dots remain. SweepNext: .a8 sta sw_size stz sw_size+1 rep #$20 .a16 lda sw_out clc adc sw_size sta sw_out inc sw_i lda sw_i cmp #SW_DOTS sep #$20 .a8 rts ; --- OAMR: what an OAM read returns, swept across line 100 ----------------- ; ; OAM filled with byte i = i, OAMADD = $0040 set in force blank (the vblank ; reload makes it byte $080). At each dot two reads of $2138, then H. Per dot ; 4 bytes: two values, H (16). TestOamRead: .a8 rep #$20 .a16 stz sw_i stz sw_out @dot: sep #$20 .a8 lda #$80 sta INIDISP jsr FillOamIdentity lda #$40 sta OAMADDL stz OAMADDH lda #$11 sta TM jsr SweepArm lda RDOAM xba lda RDOAM sta tmp+1 xba sta tmp lda SLHV jsr SweepDisarm rep #$20 .a16 ldx sw_out lda tmp sta RES,x lda hval sta RES+2,x sep #$20 .a8 lda #4 jsr SweepNext beq :+ jmp @dot : rts ; --- CGWS: where a CGRAM write lands, swept across line 100 ---------------- ; ; CGRAM zeroed; at each dot CGADD = $80, CGDATA = $5A, $25, then H. Per dot ; 15 bytes: H (16), non-zero colour count (8), up to four (index 8, colour 16). TestCgramWrite: .a8 rep #$20 .a16 stz sw_i stz sw_out @dot: sep #$20 .a8 lda #$80 sta INIDISP jsr ZeroCgram lda #$01 sta TM jsr SweepArm lda #$80 sta CGADD lda #$5A sta CGDATA lda #$25 sta CGDATA lda SLHV jsr SweepDisarm rep #$20 .a16 ldx sw_out lda hval sta RES,x txa clc adc #3 sta rec_ptr sep #$20 .a8 stz count stz CGADD ldy #$0000 @next: lda RDCGRAM sta tmp lda RDCGRAM and #$7F sta tmp+1 ora tmp beq @skip lda count cmp #4 bcs @counted ldx rec_ptr tya sta RES,x lda tmp sta RES+1,x lda tmp+1 sta RES+2,x rep #$20 .a16 txa clc adc #3 sta rec_ptr sep #$20 .a8 @counted: inc count @skip: iny cpy #256 bne @next ldx sw_out lda count sta RES+2,x lda #15 jsr SweepNext beq :+ jmp @dot : rts ; --- CGRS: what a CGRAM read returns, swept across line 100 ---------------- ; ; Colour i = i | ((i ^ $5A) & $7F) << 8; CGADD = $80 in force blank. At each ; dot two reads of $213B, then H. Per dot 4 bytes: two values, H (16). TestCgramRead: .a8 rep #$20 .a16 stz sw_i stz sw_out @dot: sep #$20 .a8 lda #$80 sta INIDISP stz CGADD ldx #$0000 : txa sta CGDATA eor #$5A and #$7F sta CGDATA inx cpx #256 bne :- lda #$80 sta CGADD lda #$01 sta TM jsr SweepArm lda RDCGRAM xba lda RDCGRAM sta tmp+1 xba sta tmp lda SLHV jsr SweepDisarm rep #$20 .a16 ldx sw_out lda tmp sta RES,x lda hval sta RES+2,x sep #$20 .a8 lda #4 jsr SweepNext beq :+ jmp @dot : rts .segment "RODATA" HvDots: .word 40, 150, 300 HvDotsEnd: MfVTimes: .word 100, 100, 230, 100, 100, 230 MfHTimes: .word 100, 280, 100, 100, 280, 100 ; SPC700 machine code at $0200 (probes/clock_ratio, plus the way home): timer ; 2 at 64 kHz, its 4-bit counter summed into $00-$02 and copied to ports 0-2; ; port 3 = $A5 jumps back to the IPL ROM, which stays mapped ($F1 bit 7). SpcProgram: .byte $8F, $01, $FC ; 0200 mov $FC,#1 timer 2 divider 1 (64 kHz) .byte $8F, $00, $00 ; 0203 mov $00,#0 .byte $8F, $00, $01 ; 0206 mov $01,#0 .byte $8F, $00, $02 ; 0209 mov $02,#0 .byte $8F, $84, $F1 ; 020C mov $F1,#$84 timer 2 on, IPL ROM on, ports kept .byte $E4, $FF ; 020F mov a,$FF discard the first count .byte $E4, $FF ; 0211 loop: mov a,$FF ticks since last read (cleared) .byte $60 ; 0213 clrc .byte $84, $00 ; 0214 adc a,$00 .byte $C4, $00 ; 0216 mov $00,a .byte $E4, $01 ; 0218 mov a,$01 .byte $88, $00 ; 021A adc a,#0 .byte $C4, $01 ; 021C mov $01,a .byte $E4, $02 ; 021E mov a,$02 .byte $88, $00 ; 0220 adc a,#0 .byte $C4, $02 ; 0222 mov $02,a .byte $FA, $00, $F4 ; 0224 mov $F4,$00 .byte $FA, $01, $F5 ; 0227 mov $F5,$01 .byte $FA, $02, $F6 ; 022A mov $F6,$02 .byte $E4, $F7 ; 022D mov a,$F7 .byte $68, $A5 ; 022F cmp a,#$A5 .byte $D0, $DE ; 0231 bne $0211 .byte $5F, $C0, $FF ; 0233 jmp $FFC0 SpcProgramEnd: .segment "CODE"