; SPDX-License-Identifier: MIT ; dliprobe.s: which DLL entries raise a display-list interrupt. ; ; The program runs eight phases. In each it points DPP at one display list list ; (in ROM), sets CTRL, lets two frames pass, then counts NMIs (DLIs) over 16 ; frames, from one VBLANK rising edge to the 17th. Every zone's display list ; is empty (a null header), so DMA does nothing but read the DLL. ; ; The zones are 16 lines, except one short zone, chosen so the zones fill the ; DMA lines exactly: NTSC 242 lines = 15 x 16 + 2 (entries 0-14, then entry 15 ; of 2 lines); PAL 292 = 18 x 16 + 4 (entries 0-17, then entry 18 of 4). LAST ; is that short zone's entry. The [SG] rule: "The interrupt will actually ; occur following DMA on the last line of the PREVIOUS zone", so entry k's DLI ; comes at the end of zone k-1, entry 0's has no previous zone, and entry ; LAST+1 is read at the end of the last DMA line, after which there is no ; zone. ; ; phase 0: DLI bit on entry 0 only (the first zone: read at VBLANK's end) ; phase 1: DLI bit on entry 5 only (a middle zone: the control) ; phase 2: DLI bit on entry LAST+1 only (read on the last DMA line; no zone follows) ; phase 3: DLI bit on entry LAST+2 only (never read) ; phase 4: DLI bit on every entry, DMA off (CTRL $7F) ; phase 5: DLI bit on every entry, DMA on ; phase 6: as 2, the short zone one line shorter (entry LAST+1 is read on the ; last line but one, and its zone has one DMA line) ; phase 7: as 2, the short zone one line longer (its last line is past the ; DMA lines, so entry LAST+1 is never read) ; ; In phase 6 the handler also counts passes of an 11-cycle loop until VBLANK ; rises and leaves the last count at $2220: about one line (10-11 passes) and ; the rest of the DLI's own line if the DMA lines end where the board's do, ; under one line if they end a line earlier. ; ; Results: phase n's count over 16 frames, little-endian, at $2200 + 2n; $2280 = ; $A5 when all eight are stored. Assemble with -DPAL=1 for the PAL zone layout. .setcpu "6502" INPTCTRL = $01 MSTAT = $28 DPPH = $2C DPPL = $30 CTRL = $3C RESULTS = $2200 DONE = $2280 MEAS = $2220 ; phase 6: passes of an 11-cycle loop from the DLI to VBLANK CNT = $80 ; zero page (RAM shadow at $2080) PH = $82 NPHASES = 8 .ifndef PAL PAL = 0 .endif .if PAL FULLZ = 18 ; entries 0-17 are 16 lines PARTIAL = 3 ; entry 18: 4 lines .else FULLZ = 15 PARTIAL = 1 .endif LAST = FULLZ .segment "CODE" reset: sei cld lda #$07 ; lock: MARIA on, cartridge mapped sta INPTCTRL ldx #$FF txs lda #$7F sta CTRL ; DMA off lda #0 tax clear: sta RESULTS,x inx bne clear sta PH phase: jsr vrise ldx PH lda dpph_tab,x sta DPPH lda dppl_tab,x sta DPPL lda ctrl_tab,x sta CTRL jsr vrise jsr vrise jsr vrise lda #0 sta CNT sta CNT+1 ldy #16 frames: jsr vrise dey bne frames lda PH asl a tax lda CNT sta RESULTS,x lda CNT+1 sta RESULTS+1,x inc PH lda PH cmp #NPHASES bne phase lda #$7F sta CTRL lda #$A5 sta DONE idle: jmp idle vrise: bit MSTAT ; wait for VBLANK's rising edge bmi vrise vr2: bit MSTAT bpl vr2 rts nmi: inc CNT bne nmi_count inc CNT+1 nmi_count: pha lda PH ; phase 6: how long from this DLI to VBLANK's rise cmp #6 bne nmi_done txa pha ldx #0 nmi_wait: bit MSTAT ; 11 cycles a pass (BIT abs 4, BMI 2, INX 2, BNE 3) bmi nmi_vb inx bne nmi_wait nmi_vb: stx MEAS pla tax nmi_done: pla rti ; one DLL of 24 entries: mode 0 = the DLI bit on entry WHICH only, 1 = on every entry .macro DLLTAB mode, which, part .repeat 24, I .if I = FULLZ OFS .set part .else OFS .set 15 .endif .if (mode = 1) .or (I = which) .byte $80 | OFS .else .byte OFS .endif .byte >nulldl, dll0, >dll1, >dll2, >dll3, >dllall, >dllall, >dllm1, >dllp1 dppl_tab: .byte