| The third pass: access costs, VDP write throughput, interrupts, YM timers, DMA fill and copy, | sprite overflow. Small C-callable pieces; the plans are in main.c. Resolutions in README.md. .equ VDATA, 0xC00000 .equ VCTRL, 0xC00004 .equ VHV, 0xC00008 .equ VCOUNT, 0xFF3F00 .equ HPTR, 0xFF3F10 .equ HCNT, 0xFF3F14 .equ HBUF, 0xFF1C00 .equ HMAX, 256 .equ YM, 0xA04000 .equ DST, 0x4000 .globl acc_count, hint_isr, ym_w, ym_flag_hv, dma_fc, status_hv, z80_go .text | acc_count(body, address, frames): from the start of a frame, how many turns of a loop | doing one access of kind `body` at `address` fit in `frames` frames. Bodies: 0 read byte, | 1 read word, 2 read long, 3 write byte, 4 write word, 5 write long, 6 none (a NOP). | Interrupts on for VCOUNT; the loop runs from ROM. Writes write $9F9F9F9F (PSG: silence). acc_count: movem.l d2-d7/a2-a6,-(sp) move.l 48(sp),d0 movea.l 52(sp),a2 move.l 56(sp),d3 lea .Lbodies(pc),a0 add.w d0,d0 move.w 0(a0,d0.w),d0 lea 0(a0,d0.w),a4 move.l #0x9F9F9F9F,d5 lea VCOUNT,a1 move #0x2000,sr move.w (a1),d0 1: cmp.w (a1),d0 beq.s 1b move.w (a1),d2 add.w d3,d2 moveq #0,d0 jsr (a4) move #0x2700,sr movem.l (sp)+,d2-d7/a2-a6 rts .Lbodies: .word b_rdb-.Lbodies, b_rdw-.Lbodies, b_rdl-.Lbodies, b_wrb-.Lbodies, b_wrw-.Lbodies .word b_wrl-.Lbodies, b_nop-.Lbodies b_rdb: addq.l #1,d0 move.b (a2),d6 cmp.w (a1),d2 bne.s b_rdb rts b_rdw: addq.l #1,d0 move.w (a2),d6 cmp.w (a1),d2 bne.s b_rdw rts b_rdl: addq.l #1,d0 move.l (a2),d6 cmp.w (a1),d2 bne.s b_rdl rts b_wrb: addq.l #1,d0 move.b d5,(a2) cmp.w (a1),d2 bne.s b_wrb rts b_wrw: addq.l #1,d0 move.w d5,(a2) cmp.w (a1),d2 bne.s b_wrw rts b_wrl: addq.l #1,d0 move.l d5,(a2) cmp.w (a1),d2 bne.s b_wrl rts b_nop: addq.l #1,d0 nop cmp.w (a1),d2 bne.s b_nop rts | Level 4: HV at each HINT into HBUF, at most HMAX, and a count. hint_isr: move.l a0,-(sp) cmpi.w #HMAX,HCNT bcc.s 1f movea.l HPTR,a0 move.w VHV,(a0)+ move.l a0,HPTR 1: addq.w #1,HCNT movea.l (sp)+,a0 rte | ym_w(reg, value): a YM2612 part-1 register write, with the bus already held. ym_w: movem.l d2-d7/a2-a6,-(sp) lea YM,a0 move.l 48(sp),d0 move.l 52(sp),d1 bsr ym_write movem.l (sp)+,d2-d7/a2-a6 rts | ym_flag_hv(mask): HV as soon as status & mask is set (bus held). Gives up after about 64k | reads and returns $FFFF. ym_flag_hv: movem.l d2-d7/a2-a6,-(sp) move.l 48(sp),d2 lea YM,a0 moveq #-1,d3 1: move.b (a0),d1 and.b d2,d1 bne.s 2f dbf d3,1b move.l #0xFFFF,d0 bra.s 3f 2: moveq #0,d0 move.w VHV,d0 3: movem.l (sp)+,d2-d7/a2-a6 rts | dma_fc(copy, bytes, line): a VRAM fill (copy 0) or VRAM copy (1) of `bytes` to DST from | line `line`, the source $5000. Returns HV just before the start << 16 | HV when the | status's DMA busy bit first reads clear. dma_fc: movem.l d2-d7/a2-a6,-(sp) move.l 48(sp),d5 move.l 52(sp),d4 move.l 56(sp),d3 lea VCTRL,a0 move #0x2700,sr 1: cmp.b VHV,d3 | out of the line, then into it beq.s 1b 2: cmp.b VHV,d3 bne.s 2b move.w #0x8F01,(a0) move.w d4,d1 andi.w #0xFF,d1 ori.w #0x9300,d1 move.w d1,(a0) move.w d4,d1 lsr.w #8,d1 ori.w #0x9400,d1 move.w d1,(a0) tst.w d5 bne.s 5f move.w #0x9780,(a0) move.w #0x4000+(DST&0x3FFF),(a0) move.w #0x0080+(DST>>14),(a0) move.w VHV,d6 move.w #0xA5A5,VDATA | the fill starts here bra.s 6f 5: move.w #0x9500,(a0) | source $5000 move.w #0x9650,(a0) move.w #0x97C0,(a0) move.w #0x0000+(DST&0x3FFF),(a0) move.w VHV,d6 move.w #0x00C0+(DST>>14),(a0) | the copy starts here 6: btst #1,1(a0) bne.s 6b move.w VHV,d7 moveq #0,d0 move.w d6,d0 swap d0 move.w d7,d0 move.w #0x8F02,(a0) movem.l (sp)+,d2-d7/a2-a6 rts | status_hv(mask, from_line, to_line): from line `from`, HV when the VDP status & mask is | first set (reading clears the sprite flags, so the first set is the one seen); $FFFF if not | by line `to`. status_hv: movem.l d2-d7/a2-a6,-(sp) move.l 48(sp),d2 move.l 52(sp),d3 move.l 56(sp),d4 lea VCTRL,a0 move #0x2700,sr 1: cmp.b VHV,d3 bne.s 1b tst.w (a0) | clear the flags 2: move.w (a0),d1 and.w d2,d1 bne.s 3f cmp.b VHV,d4 bne.s 2b move.l #0xFFFF,d0 bra.s 4f 3: moveq #0,d0 move.w VHV,d0 4: movem.l (sp)+,d2-d7/a2-a6 rts | z80_go(code, length): load the Z80 and let it run (tests.s z80_start). z80_go: movem.l d2-d7/a2-a6,-(sp) movea.l 48(sp),a3 move.l 52(sp),d4 bsr z80_start movem.l (sp)+,d2-d7/a2-a6 rts