; SPDX-License-Identifier: MIT ; dmaprobe.s: a DMA-timing probe in the manner of RevEng's "7800 hardware facts" ; tests (AtariAge 224025, [HF]): the program counts iterations of a fixed loop ; between two MSTAT edges and stores one count per frame, so the cycles left to ; the CPU in a frame can be compared across display-list configurations. ; ; Assembled with ca65/ld65 from cc65 2.19 (scripts/build_probes.py). Variants ; are chosen with -D on the ca65 command line: ; ; DMA 0: CTRL $7F (DMA off) 1: CTRL $40 (DMA on, 160A) ; NOBJ headers per display list (0 = only the terminator) ; KIND 0: 4-byte header, direct 1: 5-byte, direct ; 2: 5-byte, indirect 3: 5-byte, indirect, CWIDTH = 1 ; WIDTH graphics bytes (direct) or characters (indirect) per object ; ZONEH lines per zone (DLL OFFSET + 1) ; DLI 1: the DLI bit in every DLL entry (the handler is a bare RTI) ; TIALOOP 1: the counting loop reads the TIA (a slow cycle) each pass ; WHOLE 1: count from VBLANK's rising edge to the next (whole frame); ; 0: from its falling edge to its rising edge (the DMA lines) ; ; Results: frame n's count, little-endian, at $2200 + 2n, n = 0..31; $2280 = $A5 ; when all 32 are stored. The loop body is 14 cycles with TIALOOP = 0 (BIT abs 4, ; BMI 2, INC zp 5, BNE 3; the carry pass adds 6) and 3.5 more with TIALOOP = 1 ; (LDA zp from the TIA: 3 cycles, one of them slow). .setcpu "6502" INPTCTRL = $01 INPT4 = $0C MSTAT = $28 DPPH = $2C DPPL = $30 CHARBASE = $34 CTRL = $3C DLL = $1800 ; 32 entries DLIST = $1900 ; one display list, shared by every zone CMAP = $1A00 ; character map (zeros) RESULTS = $2200 DONE = $2280 COUNT = $80 ; zero page (RAM shadow at $2080) FRAME = $82 .ifndef DMA DMA = 1 .endif .ifndef NOBJ NOBJ = 0 .endif .ifndef KIND KIND = 0 .endif .ifndef WIDTH WIDTH = 1 .endif .ifndef ZONEH ZONEH = 16 .endif .ifndef DLI DLI = 0 .endif .ifndef TIALOOP TIALOOP = 0 .endif .ifndef WHOLE WHOLE = 0 .endif .segment "CODE" reset: sei cld lda #$07 ; lock: MARIA on, cartridge mapped sta INPTCTRL ldx #$FF txs lda #$7F sta CTRL ; DMA off while building lda #0 tax clear: sta $1800,x ; clear $1800-$1BFF and the results page sta $1900,x sta $1A00,x sta $1B00,x sta RESULTS,x inx bne clear ; the DLL: 32 zones of ZONEH lines, every one pointing at DLIST ldx #0 dll: lda #((DLI << 7) | (ZONEH - 1)) sta DLL,x lda #>DLIST sta DLL+1,x lda #gfx ; address high sta DLIST+2,x lda #$10 ; horizontal position sta DLIST+3,x txa clc adc #4 tax .else .if KIND = 1 lda #$00 .else lda #gfx .else lda #>CMAP .endif sta DLIST+2,x lda #(((32 - WIDTH) & $1F) | $20) sta DLIST+3,x lda #$10 sta DLIST+4,x txa clc adc #5 tax .endif dey bne header built: lda #>gfx sta CHARBASE lda #>DLL sta DPPH lda #