; SPDX-License-Identifier: MIT ; Probe 05: what a program finds in memory when it starts, and WAI with /IRQ held. ; ; Part 1, memory at start (build-status.md console probe 1). Before anything writes ; WRAM (no stack use until the copies are done), MVN copies WRAM $7E:0000-$3FFF and ; $7F:F000-$FFFF into battery RAM; then, before any PPU write, the PPU's readable ; latches ($2134-$2136 multiply result, $213E, $213F) and the CPU's $4210-$4212 are ; kept raw; then, in force blank, 1 KiW of VRAM, all of OAM and all of CGRAM are read ; back. The board assumes zeros everywhere (HYPOTHESIS). CAUTION: the flash cart's own ; menu runs on the console before this ROM, so a region its menu used holds the menu's ; leftovers, not power-on contents; regions the menu leaves alone show the console's. ; ; Part 2, WAI with /IRQ held (docs/mame-oracle.md "The lockstep", DKC): V-IRQ at line ; 10, NMI on (its handler only returns), P.I set. Row A: eight times WAI, then latch V. ; If WAI resumes while /IRQ stays low (WDC's datasheet, and the board), row A reads ; about line 10 eight times; if it waits for a new event (MAME 0.285), it reads 225 ; (the NMI) and 10 alternately or so. Row B, the control: the same with TIMEUP read ; after each WAI, which releases /IRQ, so each WAI waits for the next event. ; ; Battery RAM (32 KiB at $70:0000; scripts/probe_results.py decodes it): ; $0000 "SNESPRB5" ; $0008 run count, 16-bit ; $0010 raw $2134 $2135 $2136 $213E $213F $4210 $4211 $4212 ; $0020 row A: 8 x V, 16-bit $0030 row B: 8 x V, 16-bit ; $0100 WRAM $7E:0000-$3FFF (16 KiB) ; $4100 WRAM $7F:F000-$FFFF (4 KiB) ; $5100 VRAM words $0000-$03FF, low byte then high (2 KiB) ; $5900 OAM, 544 bytes $5C00 CGRAM, 512 bytes .include "common.inc" VMAINR = $2115 RDVRAML = $2139 RDVRAMH = $213A S_COUNT = $0008 S_LATCH = $0010 S_ROWA = $0020 S_ROWB = $0030 S_WRAMLO = $0100 S_WRAMHI = $4100 S_VRAM = $5100 S_OAM = $5900 S_CGRAM = $5C00 count = $10 ; 16-bit .segment "CODE" Reset: sei clc xce rep #$30 .a16 .i16 ; MVN: opcode $54, then the destination bank, then the source bank. No stack. ldx #$0000 ldy #S_WRAMLO lda #$3FFF .byte $54, $70, $7E ldx #$F000 ldy #S_WRAMHI lda #$0FFF .byte $54, $70, $7F sep #$20 .a8 ; MVN left DB at the destination bank ($70): back to $00 for the registers. The ; push lands on the stack after the WRAM copies are done. lda #$00 pha plb ; The latches, raw, before any PPU write. lda MPYL sta f:SRAM+S_LATCH+0 lda MPYL+1 sta f:SRAM+S_LATCH+1 lda MPYL+2 sta f:SRAM+S_LATCH+2 lda STAT77 sta f:SRAM+S_LATCH+3 lda STAT78 sta f:SRAM+S_LATCH+4 lda RDNMI sta f:SRAM+S_LATCH+5 lda TIMEUP sta f:SRAM+S_LATCH+6 lda HVBJOY sta f:SRAM+S_LATCH+7 ; VRAM, OAM, CGRAM in force blank. lda #$80 sta INIDISP sta VMAINR ; increment after the high byte ldx #$0000 stx VMADD lda RDVRAML ; the prefetch was loaded by the address write : lda RDVRAML sta f:SRAM+S_VRAM,x lda RDVRAMH sta f:SRAM+S_VRAM+1,x inx inx cpx #$0800 bne :- ldx #$0000 stx OAMADDL : lda RDOAM sta f:SRAM+S_OAM,x inx cpx #544 bne :- stz CGADD ldx #$0000 : lda RDCGRAM sta f:SRAM+S_CGRAM,x inx cpx #512 bne :- ProbeStart ; the stack and direct page from here on ; Part 2. NMI and V-IRQ at line 10; I stays set (ProbeStart's SEI). lda #10 sta VTIMEL stz VTIMEH lda TIMEUP lda #$A0 sta NMITIMEN ldx #$0000 @rowa: wai jsr LatchV sta f:SRAM+S_ROWA,x xba sta f:SRAM+S_ROWA+1,x inx inx cpx #16 bne @rowa ldx #$0000 @rowb: wai lda TIMEUP ; releases /IRQ jsr LatchV sta f:SRAM+S_ROWB,x xba sta f:SRAM+S_ROWB+1,x inx inx cpx #16 bne @rowb stz NMITIMEN ; The magic and the run count last, so a save without them is a run that froze. ldx #$0000 : lda Magic,x sta f:SRAM,x inx cpx #8 bne :- rep #$20 .a16 lda f:SRAM+S_COUNT inc a sta f:SRAM+S_COUNT sta count sep #$20 .a8 jsr InitPPU PrintAt 2, TitleText PrintAt 3, SubtitleText PrintAt 5, RowAText ldx #MAP + 6*32 + 2 stx VMADD ldx #S_ROWA jsr PrintRow ldx #MAP + 7*32 + 2 stx VMADD ldx #S_ROWA+8 jsr PrintRow PrintAt 8, RowBText ldx #MAP + 9*32 + 2 stx VMADD ldx #S_ROWB jsr PrintRow ldx #MAP + 10*32 + 2 stx VMADD ldx #S_ROWB+8 jsr PrintRow PrintAt 12, LatchText ldx #MAP + 13*32 + 2 stx VMADD ldx #$0000 : lda f:SRAM+S_LATCH,x jsr PrintHex lda #' ' jsr PutChar jsr PutChar inx cpx #5 bne :- PrintAt 15, CountText lda count+1 jsr PrintHex lda count jsr PrintHex PrintAt 17, Help1Text PrintAt 18, Help2Text PrintAt 20, Help3Text PrintAt 21, Help4Text PrintAt 22, Help5Text jmp ShowAndHalt ; A = V (low), B = V bit 8, latched now. LatchV: lda SLHV ; latch H and V lda STAT78 ; reset the counters' read flip-flop lda OPVCT xba lda OPVCT and #$01 xba rts ; Print four 16-bit V values at SRAM+X as "VVV " at the current VRAM address. PrintRow: ldy #4 : lda f:SRAM+1,x jsr PutNibble lda f:SRAM,x jsr PrintHex lda #' ' jsr PutChar inx inx dey bne :- rts .segment "RODATA" Magic: .byte "SNESPRB5" TitleText: .byte "SNES PROBE PACK", 0 SubtitleText: .byte "05 MEMORY AT START, WAI", 0 RowAText: .byte "WAI, IRQ HELD: V AFTER EACH", 0 RowBText: .byte "WAI, IRQ RELEASED (CONTROL)", 0 LatchText: .byte "2134 2135 2136 213E 213F", 0 CountText: .byte "RUN COUNT $", 0 Help1Text: .byte "PHOTOGRAPH THIS SCREEN.", 0 Help2Text: .byte "THE MEMORY IS IN THE SAVE.", 0 Help3Text: .byte "POWER OFF FOR 10 SECONDS,", 0 Help4Text: .byte "ON, RUN AGAIN; THEN SEND", 0 Help5Text: .byte "SAVE/05-POWERON.SRM", 0 ProbeTail "SNES PROBE POWERON ", $05