; Probe 04: where CGRAM and OAM writes land outside V-Blank (U2; Q15, Q16). ; ; The documents (fullsnes "SNES Timing PPU Memory Accesses"; wiki/Errata) say ; a CGRAM write during rendering lands at the address the PPU is reading, not ; at CGADD; that H-Blank palette writes work "only during a few clock cycles"; ; and that the OAM address "is scattered during drawing period". No console ; result is pinned. This probe writes a tag and reports where it landed: ; ; CGRAM: CGADD = $80, CGDATA = $5A, $25 (colour $255A). The rest of CGRAM is ; $0000, so the probe reports the first index holding $255A and how ; many colours are non-zero (1 if the write landed whole). ; OAM: OAMADD = $0040 (byte $80), OAMDATA = $A5, $5A. The rest of OAM is ; $F0 (every sprite below the screen), so the probe reports the first ; byte holding $A5 and how many bytes changed from a read-back of ; the fill taken just before (2 if whole). ; ; Each write follows a WAI on an H+V IRQ (interrupts disabled, no handler), ; with the display on and BG1 + OBJ enabled: at line 100 dot 100 (active ; display), line 100 dot 280 (H-Blank: the writes end ~60 dots ; later, before the next line's dot 22) and line 230 dot 100 (V-Blank, the ; control, which must read 080/1 for CGRAM and 080/2 for OAM). Three runs per ; case; the memory is refilled in forced blank before each. The H counter ; latched right after each write goes to battery RAM with the results. .include "common.inc" NCASES = 6 NREPS = 3 SLOT = 5 ; bytes per result: found (16), count, H (16) case = $10 ; 16-bit, high byte 0 run = $12 ; 16-bit, high byte 0 found = $14 ; 16-bit, $FFFF = not found count = $16 ; 16-bit hval = $18 ; 16-bit slot = $1A ; 16-bit tmp = $1C ; 16-bit OAM_BASE = $0800 ; WRAM: OAM as read back after the fill .segment "CODE" Reset: ProbeStart jsr InitPPU lda #$80 sta WRIO ; lets $2137 latch the counters ldx #$0000 : lda Magic,x sta RESULTS,x inx cpx #8 bne :- rep #$20 .a16 stz case @case: stz run @run: sep #$20 .a8 jsr RunOne jsr SlotIndex lda found sta RESULTS+8,x lda found+1 sta RESULTS+9,x lda count sta RESULTS+10,x lda hval sta RESULTS+11,x lda hval+1 sta RESULTS+12,x rep #$20 .a16 inc run lda run cmp #NREPS bne @run inc case lda case cmp #NCASES bne @case sep #$20 .a8 ldy #8 + NCASES*NREPS*SLOT jsr SaveResults jsr InitPPU ; text colours back, OBJ off PrintAt 1, TitleText PrintAt 2, SubtitleText PrintAt 4, HeadText rep #$20 .a16 stz case @row: lda case ; screen row 6 + 2*case: (case + 3) * 64 words clc adc #3 asl a asl a asl a asl a asl a asl a clc adc #MAP + 2 sta VMADD lda case asl a tax lda Labels,x tay sep #$20 .a8 jsr PrintHere rep #$20 .a16 stz run @col: jsr SlotIndex sep #$20 .a8 lda #' ' jsr PutChar lda RESULTS+9,x cmp #$FF bne :+ ldy #NoneText jsr PrintHere bra :++ : jsr PutNibble lda RESULTS+8,x jsr PrintHex : lda #'/' jsr PutChar lda RESULTS+10,x cmp #$10 bcc :+ lda #$0F ; 15 or more : jsr PutNibble rep #$20 .a16 inc run lda run cmp #NREPS bne @col inc case lda case cmp #NCASES bne @row sep #$20 .a8 PrintAt 19, Note1Text PrintAt 20, Note2Text PrintAt 21, Note3Text PrintAt 23, Help1Text jmp ShowAndHalt ; X = RESULTS offset of (case, run): (case*NREPS + run) * SLOT. Keeps A's width. SlotIndex: php rep #$20 .a16 lda case asl a clc adc case clc adc run sta tmp asl a asl a clc adc tmp tax plp rts ; One write: refill, display on, wait for the case's line and dot, write the ; tag, latch H, blank, search. RunOne: .a8 lda #$80 sta INIDISP jsr FillCgram jsr FillOam jsr ReadOamBase lda #$11 ; BG1 + OBJ on the main screen sta TM rep #$20 .a16 lda case asl a tax lda VTimes,x sta VTIMEL lda HTimes,x sta HTIMEL sep #$20 .a8 lda #$30 ; H+V IRQ sta NMITIMEN jsr WaitVblankStart lda #$0F sta INIDISP lda TIMEUP wai lda 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 lda STAT78 lda OPHCT sta hval lda OPHCT and #$01 sta hval+1 stz NMITIMEN lda TIMEUP lda #$80 sta INIDISP lda case cmp #3 bcs SearchOam ; fall through ; found = first colour equal to $255A, count = non-zero colours. SearchCgram: 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 ; read right after the fill (MAME 0.285 reads every Y byte back one higher than ; written, so comparing with $F0 itself would count 128 bytes on MAME). SearchOam: 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 ; Keep the first match only. FoundAtX: lda found+1 cmp #$FF bne :+ stx found : rts FillCgram: 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 FillOam: stz OAMADDL stz OAMADDH lda #$F0 ldx #544 : sta OAMDATA dex bne :- rts .segment "RODATA" VTimes: .word 100, 100, 230, 100, 100, 230 HTimes: .word 100, 280, 100, 100, 280, 100 Labels: .word L0, L1, L2, L3, L4, L5 L0: .byte "CG ACTIVE", 0 L1: .byte "CG HBLANK", 0 L2: .byte "CG VBLANK", 0 L3: .byte "OAM ACTIVE", 0 L4: .byte "OAM HBLANK", 0 L5: .byte "OAM VBLANK", 0 Magic: .byte "SNESPRB4" TitleText: .byte "SNES PROBE PACK", 0 SubtitleText: .byte "04 MID-FRAME CGRAM AND OAM", 0 HeadText: .byte "WROTE WHERE/COUNT, 3 RUNS", 0 NoneText: .byte "---", 0 Note1Text: .byte "WRITES WENT TO CG $080 AND", 0 Note2Text: .byte "OAM $080. VBLANK ROWS MUST", 0 Note3Text: .byte "READ 080/1 AND 080/2.", 0 Help1Text: .byte "PHOTOGRAPH THIS SCREEN.", 0 ProbeTail "SNES PROBE MIDFRAME "