; The probe suite: every console measurement in one ROM, results to battery RAM. ; ; Aubrey's Super Famicom is the tier-1 judge (handoff-brief.md), and reading ; screens off a phone photo is where mistakes creep in. So this ROM runs every ; test the CPU can measure for itself, one after another, and writes raw ; results to its 32 KiB of battery RAM; scripts/suite_results.py decodes the ; .srm the EverDrive writes back. The tester starts it, holds a button when the ; screen asks, and powers off when it says ALL DONE. ; ; Battery RAM ($70:0000) holds a header, a boot log, a directory and one slot ; per test: ; ; $0000 "SNESUITE", format byte, run state (0 idle, 1 running, 2 complete), ; boot count (16), run count (16), test count ; $0010 one status byte per test: 0 not run, 1 started, 2 done, 3 hung ; $0100 boot log: 16 entries of 16 bytes (see SramBoot) ; $0200 directory: per test, tag (4), slot offset (16), length (16) ; $0400 the slots, in table order ; ; A test is marked started before it runs and done after its results are ; copied. If a test hangs the console, the tester presses reset (or restarts ; the ROM from the EverDrive menu): the boot finds the run unfinished, marks ; the started test hung and carries on with the next one. Every boot also ; latches the H/V counters as its first act, so the boot log records where the ; PPU was when reset let go (undisbeliever's reset-position test). ; ; Tests are called with 8-bit A, 16-bit X/Y, DP = DB = 0, interrupts off, the ; progress screen showing (display on), and fill RES; the framework copies ; RES to their slot. The NMI and IRQ vectors jump through WRAM pointers ; (NMI_VEC, IRQ_VEC) so a test can install a handler; the indirection costs a ; fixed 5 CPU cycles (JML [abs]) on top of the hardware's. .include "common.inc" FORMAT = 2 ; 2: AJIR offsets past 255, MRFS window at HTIME 10 SRAM_SIZE = $8000 S_MAGIC = $0000 S_FORMAT = $0008 S_STATE = $0009 S_BOOTS = $000A S_RUNS = $000C S_NTESTS = $000E S_STATUS = $0010 S_BOOTLOG = $0100 S_DIR = $0200 S_SLOTS = $0400 ST_DONE = 2 ST_HUNG = 3 ; Test table entry: tag (4), routine (2), slot (2), length (2), label (2), flags (1), pad (1) TE_TAG = 0 TE_ROUTINE = 4 TE_SLOT = 6 TE_LEN = 8 TE_LABEL = 10 TE_FLAGS = 12 ENTRY = 14 F_HOLD_B = $01 ; the tester holds B on pad 1 throughout F_HANDS_OFF= $02 ; no button may be held (checked before the test) F_RESUME = $04 ; started but unfinished at boot: run again, not hung F_DIRECT = $08 ; writes its slot itself (cur_slot); RES is not copied RES = $1000 ; WRAM result buffer, RES_MAX bytes RES_MAX = $0D00 NMI_VEC = $1E00 ; 24-bit handler address for NmiTrampoline IRQ_VEC = $1E03 PROMPT = $1E10 ; the running test's flags, for emulator scripts to press buttons BRK_VEC = $1E06 ; 24-bit handler for BRK, COP, ABORT and emulation-mode vectors MDMAEN = $420B HDMAEN = $420C MEMSEL = $420D JOY1L = $4218 JOY1H = $4219 OBSEL = $2101 TMW = $212E WMDATA = $2180 WMADDL = $2181 WMADDM = $2182 WMADDH = $2183 RDOAM_ = RDOAM WRMPYA = $4202 WRMPYB = $4203 WRDIVL = $4204 WRDIVH = $4205 WRDIVB = $4206 RDDIVL = $4214 RDDIVH = $4215 RDMPYL = $4216 RDMPYH = $4217 JOYSER0 = $4016 JOYSER1 = $4017 ; Framework direct page $20-$3F; tests use $40-$FF. test_i = $20 ; 16-bit test_ptr = $22 ; 16-bit, offset of the entry in TestTable held = $24 ; 16-bit frame counter for prompts tmp = $26 ; 16-bit hval = $28 ; 16-bit, from ReadCounters vval = $2A ; 16-bit boot_rdnmi = $2C boot_s77 = $2D boot_s78 = $2E boot_h = $30 ; 16-bit boot_v = $32 ; 16-bit row = $34 ; 16-bit ndone = $36 ; 16-bit nhung = $38 ; 16-bit dec_tmp = $3A cur_slot = $3C ; 16-bit: the running test's slot offset in battery RAM resumed = $3E ; 1 when the running test was started on an earlier boot .segment "CODE" Reset: sei clc xce rep #$38 .a16 .i16 ldx #$1FFF txs lda #$0000 tcd sep #$20 .a8 pha plb ; Where the PPU was when reset let go: latch first (WRIO is $FF after ; reset, so the $2137 read latches), then the version registers. lda SLHV lda RDNMI sta boot_rdnmi lda STAT77 sta boot_s77 lda STAT78 ; also resets the OPHCT/OPVCT flip-flops sta boot_s78 lda OPHCT sta boot_h lda OPHCT and #$01 sta boot_h+1 lda OPVCT sta boot_v lda OPVCT and #$01 sta boot_v+1 lda #$80 sta INIDISP stz NMITIMEN jsr ResetRegisters jsr InitPPU jsr SramBoot Main: lda f:SRAM+S_STATE cmp #2 bne :+ jsr DoneScreen ; returns when the tester asks for a new run lda #$00 sta f:SRAM+S_STATE : lda f:SRAM+S_STATE bne :+ jsr NewRun : jsr MarkHung rep #$20 .a16 stz test_i stz test_ptr @loop: ldx test_ptr lda TestTable+TE_ROUTINE,x beq @finished ldx test_i sep #$20 .a8 stz resumed lda f:SRAM+S_STATUS,x beq @run cmp #1 bne :+ inc resumed ; F_RESUME tests stay at 1 through MarkHung @run: jsr RunTest : rep #$20 .a16 inc test_i lda test_ptr clc adc #ENTRY sta test_ptr bra @loop @finished: sep #$20 .a8 lda #2 sta f:SRAM+S_STATE bra Main ; One test: mark started, show progress, prompt, run, copy, mark done. RunTest: .a8 ldx test_i lda #1 sta f:SRAM+S_STATUS,x jsr ResetRegisters jsr InitPPU jsr ProgressScreen ldx test_ptr lda TestTable+TE_FLAGS,x jsr Prompt jsr ClearRes ldx test_ptr lda TestTable+TE_SLOT,x sta cur_slot lda TestTable+TE_SLOT+1,x sta cur_slot+1 jsr (TestTable+TE_ROUTINE,x) sep #$20 rep #$10 .a8 .i16 lda #$00 pha plb stz PROMPT rep #$20 .a16 lda #$0000 tcd ldx test_ptr lda TestTable+TE_FLAGS,x and #F_DIRECT bne @copied lda TestTable+TE_LEN,x beq @copied dec a pha lda TestTable+TE_SLOT,x tay pla ldx #RES phb .byte $54, $70, $00 ; mvn: to bank $70 from bank $00 (A+1 bytes, X -> Y) plb @copied: sep #$20 .a8 ldx test_i lda #ST_DONE sta f:SRAM+S_STATUS,x rts ; Every register the tests touch, to its power-on value; force blank. ResetRegisters: .a8 lda #$80 sta INIDISP stz NMITIMEN stz MDMAEN stz HDMAEN stz MEMSEL lda #$FF sta WRIO ldx #$2101 : stz a:$0000,x ; twice: clears the write-twice latches too stz a:$0000,x inx cpx #$2134 bne :- lda #$80 sta VMAIN rep #$20 .a16 lda #.loword(EmptyHandler) sta NMI_VEC sta IRQ_VEC sta BRK_VEC sep #$20 .a8 lda #^EmptyHandler sta NMI_VEC+2 sta IRQ_VEC+2 sta BRK_VEC+2 stz PROMPT lda TIMEUP lda RDNMI rts ClearRes: rep #$20 .a16 ldx #$0000 : stz RES,x inx inx cpx #RES_MAX bne :- sep #$20 .a8 rts ; Check the header (format if it is not ours), count the boot, log it. SramBoot: .a8 ldx #$0000 : lda f:SRAM+S_MAGIC,x cmp Magic,x bne @format inx cpx #8 bne :- lda f:SRAM+S_FORMAT cmp #FORMAT beq @ours @format: rep #$20 .a16 lda #$0000 tax : sta f:SRAM,x inx inx cpx #SRAM_SIZE bne :- sep #$20 .a8 ldx #$0000 : lda Magic,x sta f:SRAM+S_MAGIC,x inx cpx #8 bne :- lda #FORMAT sta f:SRAM+S_FORMAT @ours: ; Boot log entry: boot number (16), run state at boot, first test marked ; started ($FF none), $4210, $213E, $213F, 0, H (16), V (16), run count ; (16), 0, 0. rep #$20 .a16 lda f:SRAM+S_BOOTS inc a sta f:SRAM+S_BOOTS dec a and #$000F asl a asl a asl a asl a tax lda f:SRAM+S_BOOTS sta f:SRAM+S_BOOTLOG,x lda boot_h sta f:SRAM+S_BOOTLOG+8,x lda boot_v sta f:SRAM+S_BOOTLOG+10,x lda f:SRAM+S_RUNS sta f:SRAM+S_BOOTLOG+12,x sep #$20 .a8 lda f:SRAM+S_STATE sta f:SRAM+S_BOOTLOG+2,x lda boot_rdnmi sta f:SRAM+S_BOOTLOG+4,x lda boot_s77 sta f:SRAM+S_BOOTLOG+5,x lda boot_s78 sta f:SRAM+S_BOOTLOG+6,x lda #$FF sta f:SRAM+S_BOOTLOG+3,x txy ; Y = log entry ldx #$0000 : lda f:SRAM+S_STATUS,x cmp #1 beq @started inx cpx #$00F0 bne :- rts @started: txa tyx sta f:SRAM+S_BOOTLOG+3,x rts ; A fresh run: statuses and slots cleared, the directory written. NewRun: .a8 rep #$20 .a16 lda #$0000 ldx #S_STATUS : sta f:SRAM,x inx inx cpx #S_BOOTLOG bne :- ldx #S_DIR : sta f:SRAM,x inx inx cpx #SRAM_SIZE bne :- lda f:SRAM+S_RUNS inc a sta f:SRAM+S_RUNS ; directory: tag, slot, length per test stz test_i ldx #$0000 ; table offset ldy #S_DIR ; SRAM offset @dir: lda TestTable+TE_ROUTINE,x beq @dirdone lda TestTable+TE_TAG,x phx tyx sta f:SRAM,x plx lda TestTable+TE_TAG+2,x phx tyx sta f:SRAM+2,x plx lda TestTable+TE_SLOT,x phx tyx sta f:SRAM+4,x plx lda TestTable+TE_LEN,x phx tyx sta f:SRAM+6,x plx tya clc adc #8 tay txa clc adc #ENTRY tax inc test_i bra @dir @dirdone: lda test_i sep #$20 .a8 sta f:SRAM+S_NTESTS lda #1 sta f:SRAM+S_STATE rts ; Any test still marked started never finished: it hung (unless it resumes). MarkHung: .a8 ldx #$0000 ; status index ldy #$0000 ; table offset @test: lda TestTable+TE_ROUTINE,y ora TestTable+TE_ROUTINE+1,y beq @done lda f:SRAM+S_STATUS,x cmp #1 bne @next lda TestTable+TE_FLAGS,y and #F_RESUME bne @next lda #ST_HUNG sta f:SRAM+S_STATUS,x @next: inx rep #$20 .a16 tya clc adc #ENTRY tay sep #$20 .a8 bra @test @done: rts ; --- Screens --------------------------------------------------------------- ; X = screen row: VMADD = that row, column 2. SetRow: rep #$20 .a16 txa asl a asl a asl a asl a asl a clc adc #MAP + 2 sta VMADD sep #$20 .a8 rts ; A = 0-255, printed in decimal without leading zeros. PrintDec: .a8 stz dec_tmp ; nonzero once a digit has been printed ldy #$0000 : cmp #100 bcc :+ sbc #100 iny bra :- : jsr @digit ldy #$0000 : cmp #10 bcc :+ sbc #10 iny bra :- : jsr @digit clc adc #'0' jmp PutChar @digit: ; Y = digit, A = remainder (kept) pha tya ora dec_tmp beq :+ tya clc adc #'0' jsr PutChar lda #$01 sta dec_tmp : pla rts ProgressScreen: .a8 lda #$80 sta INIDISP PrintAt 2, TitleText PrintAt 4, TestText rep #$20 .a16 lda test_i inc a sep #$20 .a8 jsr PrintDec ldy #OfText jsr PrintHere lda f:SRAM+S_NTESTS jsr PrintDec ldx #6 jsr SetRow ldx test_ptr lda TestTable+TE_TAG,x jsr PutChar ldx test_ptr lda TestTable+TE_TAG+1,x jsr PutChar ldx test_ptr lda TestTable+TE_TAG+2,x jsr PutChar ldx test_ptr lda TestTable+TE_TAG+3,x jsr PutChar lda #' ' jsr PutChar ldx test_ptr ldy TestTable+TE_LABEL,x jsr PrintHere jsr ProgressBar PrintAt 12, Wait1Text PrintAt 14, Wait2Text PrintAt 15, Wait3Text PrintAt 16, Wait4Text PrintAt 17, Wait5Text lda #$0F sta INIDISP rts ; Row 8: one block per test, filled for those finished. ProgressBar: ldx #8 jsr SetRow ldx #$0000 : lda f:SRAM+S_STATUS,x cmp #ST_DONE bcc @open lda #'=' bra @put @open: lda #'-' @put: phx jsr PutChar plx inx txa cmp f:SRAM+S_NTESTS bne :- rts ; A = flags. Waits until the tester does what the screen asks. Prompt: .a8 sta PROMPT bit #F_HOLD_B bne @hold_b bit #F_HANDS_OFF bne @hands_off rts @hold_b: lda #$80 sta INIDISP PrintAt 20, HoldB1Text PrintAt 21, HoldB2Text PrintAt 22, HoldB3Text lda #$0F sta INIDISP lda #$80 ; B bra @wait @hands_off: lda #$80 sta INIDISP PrintAt 20, HandsOffText lda #$0F sta INIDISP lda #$00 @wait: sta tmp ; $80: B must be held; 0: nothing may be lda #$01 sta NMITIMEN ; auto-joypad on rep #$20 .a16 stz held sep #$20 .a8 @frame: jsr WaitJoypad lda tmp bne @want_b lda JOY1L ora JOY1H beq @good bra @bad @want_b: lda JOY1H and #$80 bne @good @bad: rep #$20 .a16 stz held sep #$20 .a8 bra @frame @good: rep #$20 .a16 inc held lda held cmp #60 sep #$20 .a8 bne @frame stz NMITIMEN rts DoneScreen: .a8 jsr ResetRegisters jsr InitPPU PrintAt 2, TitleText PrintAt 4, DoneText rep #$20 .a16 stz ndone stz nhung sep #$20 .a8 ldx #$0000 @count: lda f:SRAM+S_STATUS,x cmp #ST_DONE bne :+ inc ndone : cmp #ST_HUNG bne :+ inc nhung : inx txa cmp f:SRAM+S_NTESTS bne @count PrintAt 6, FinishedText lda ndone jsr PrintDec PrintAt 7, HungText lda nhung jsr PrintDec jsr ProgressBar PrintAt 11, Done1Text PrintAt 12, Done2Text PrintAt 13, Done3Text PrintAt 14, Done4Text PrintAt 20, Again1Text PrintAt 21, Again2Text lda #$0F sta INIDISP ; START + SELECT held for 3 seconds starts a new run. lda #$01 sta NMITIMEN rep #$20 .a16 stz held sep #$20 .a8 @frame: jsr WaitJoypad lda JOY1H and #$30 cmp #$30 beq :+ rep #$20 .a16 stz held sep #$20 .a8 bra @frame : rep #$20 .a16 inc held lda held cmp #180 sep #$20 .a8 bne @frame stz NMITIMEN rts ; --- Shared helpers for tests ----------------------------------------------- ; Latched counters into hval/vval (9 bits each). Call right after the latch. ReadCounters: .a8 lda STAT78 lda OPHCT sta hval lda OPHCT and #$01 sta hval+1 lda OPVCT sta vval lda OPVCT and #$01 sta vval+1 rts ; The next auto-joypad read: vblank start, then $4212 bit 0 set and clear ; again (it starts some dots into the line; JOY1 read before that can catch ; the read starting). Gives up on either wait after ~10 frames. WaitJoypad: .a8 jsr WaitVblankStart ldx #$FFFF : lda HVBJOY and #$01 bne :+ dex bne :- : ldx #$FFFF : lda HVBJOY and #$01 beq :+ dex bne :- : rts WaitVblankEnd: : bit HVBJOY bpl :- : bit HVBJOY bmi :- rts NmiTrampoline: jml [NMI_VEC] BrkTrampoline: jml [BRK_VEC] IrqTrampoline: jml [IRQ_VEC] .include "macros.inc" .include "tests_ours.inc" .include "tests_autojoy.inc" .include "tests_muldiv.inc" .include "tests_timing.inc" .include "tests_ppu.inc" .include "tests_dma.inc" .segment "RODATA" Magic: .byte "SNESUITE" TitleText: .byte "SNES CONSOLE TEST SUITE", 0 TestText: .byte "TEST ", 0 OfText: .byte " OF ", 0 Wait1Text: .byte "RUNNING. PLEASE WAIT.", 0 Wait2Text: .byte "IF THIS SCREEN DOES NOT", 0 Wait3Text: .byte "CHANGE FOR 2 MINUTES, PRESS", 0 Wait4Text: .byte "RESET (START THE ROM AGAIN", 0 Wait5Text: .byte "IF THE MENU COMES UP).", 0 HoldB1Text: .byte "HOLD B ON CONTROLLER 1", 0 HoldB2Text: .byte "AND KEEP HOLDING IT UNTIL", 0 HoldB3Text: .byte "THIS TEST FINISHES.", 0 HandsOffText: .byte "LET GO OF ALL BUTTONS.", 0 DoneText: .byte "ALL DONE.", 0 FinishedText: .byte "TESTS FINISHED ", 0 HungText: .byte "TESTS HUNG ", 0 Done1Text: .byte "POWER OFF, POWER ON AGAIN", 0 Done2Text: .byte "SO THE EVERDRIVE SAVES,", 0 Done3Text: .byte "THEN SEND THE .SRM FILE", 0 Done4Text: .byte "FROM THE SD CARD SAVE FOLDER.", 0 Again1Text: .byte "TO RUN EVERYTHING AGAIN,", 0 Again2Text: .byte "HOLD START+SELECT 3 SECONDS.", 0 .include "table.inc" ; Header and vectors: LoROM, 64 KiB, 32 KiB battery RAM, Japan. .segment "HEADER" .byte "SNES CONSOLE SUITE " .byte $20 ; LoROM, SlowROM .byte $02 ; ROM + RAM + battery .byte $06 ; ROM 64 KiB .byte $05 ; SRAM 32 KiB .byte $00 ; region Japan (NTSC) .byte $00 ; developer .byte $00 ; version .word $FFFF ; checksum complement, fixed by the build .word $0000 ; checksum, fixed by the build .segment "VECTORS" ; native: -, -, COP, BRK, ABORT, NMI, -, IRQ .word 0, 0, BrkTrampoline, BrkTrampoline, BrkTrampoline, NmiTrampoline, 0, IrqTrampoline ; emulation: -, -, COP, -, ABORT, NMI, RESET, IRQ/BRK .word 0, 0, BrkTrampoline, 0, BrkTrampoline, BrkTrampoline, Reset, BrkTrampoline