| The brief's first timing tests. Each states its resolution in README.md. t2_run(id) from C. .equ VDATA, 0xC00000 .equ VCTRL, 0xC00004 .equ VHV, 0xC00008 .equ VCOUNT, 0xFF3F00 .equ VDMA, 0xFF3F02 .equ VHVI, 0xFF3F06 .equ RAMTWO, 0xFF3100 .equ SHADOW, 0xFF4000 .equ BUSREQ, 0xA11100 .equ ZRESET, 0xA11200 .equ YM, 0xA04000 .equ SAT, 0xD800 .equ R1_OFF, 0x8134 .equ R1_ON, 0x8174 .equ WALK, 32 .equ STEPS, 16 .equ DMA_DST, 0x4000 .globl t2_run, wait_f0, dma_from, dma_regs, ym_write, sprite_arm, sizes .text t2_run: movem.l d2-d7/a2-a6,-(sp) move.l 48(sp),d3 move.w #R1_ON,VCTRL move #0x2700,sr cmpi.w #10,d3 bne.s 1f move.l #DSRC,d4 move.w #200,d3 bsr t_dmap bra .Lend 1: cmpi.w #11,d3 bne.s 1f move.l #SHADOW,d4 move.w #300,d3 bsr t_dmap bra .Lend 1: cmpi.w #12,d3 bne.s 1f bsr t_vpos bra .Lend 1: cmpi.w #13,d3 bne.s 1f move.w #R1_OFF,VCTRL move.w #710,d3 bsr t_read bra .Lend 1: cmpi.w #14,d3 bne.s 1f move.w #711,d3 bsr t_read bra .Lend 1: cmpi.w #15,d3 bne.s 1f moveq #0,d4 move.w #400,d3 bsr t_busack bra .Lend 1: cmpi.w #16,d3 bne.s 1f moveq #1,d4 move.w #401,d3 bsr t_busack bra .Lend 1: cmpi.w #17,d3 bne.s 1f lea idle_loop(pc),a2 move.w #800,d3 bsr t_idle bra .Lend 1: cmpi.w #18,d3 bne.s 1f lea idle_loop(pc),a0 lea RAMTWO,a2 moveq #(idle_end-idle_loop)/2-1,d0 2: move.w (a0)+,(a2)+ dbf d0,2b lea RAMTWO,a2 move.w #801,d3 bsr t_idle bra .Lend 1: cmpi.w #19,d3 bne.s 1f bsr t_ym bra .Lend 1: cmpi.w #20,d3 bcs .Lend cmpi.w #23,d3 bhi .Lend | 20 Y line 100, 21 X line 100, 22 Y line 0, 23 X line 0 move.w d3,d0 subi.w #20,d0 moveq #0,d4 btst #0,d0 beq.s 2f moveq #6,d4 2: moveq #100,d5 btst #1,d0 beq.s 2f moveq #0,d5 2: move.w #500,d3 add.w d0,d3 bsr t_sprite .Lend: move #0x2700,sr move.w #R1_ON,VCTRL movem.l (sp)+,d2-d7/a2-a6 rts | -- DMA start-up and pace: 1 to 512 words, from d4, HV before and after --------------------- | One H step is 16 MCLK in H40, about 2.3 68000 clocks, so the pace comes from the fit over | the sizes, and the repeats dither the start. t_dmap: lea sizes(pc),a3 moveq #(sizes_end-sizes)/2-1,d5 1: move.w (a3)+,a4 moveq #3,d6 2: bsr wait_f0 move.w d6,d0 3: dbf d0,3b move.w VHV,d7 move.w a4,d0 bsr dma_from swap d7 move.w VHV,d7 move.l d7,d0 moveq #3,d1 sub.w d6,d1 move.w d3,-(sp) add.w a4,d3 bsr record move.w (sp)+,d3 dbf d6,2b dbf d5,1b rts wait_f0: moveq #-0x10,d1 1: cmp.b VHV,d1 beq.s 1b 2: cmp.b VHV,d1 bne.s 2b rts | d0 words from d4 to VRAM. dma_from: bsr dma_regs move.w #0x4000+(DMA_DST&0x3FFF),VCTRL move.w #0x0080+(DMA_DST>>14),VCTRL rts dma_regs: move.w #0x8F02,VCTRL move.w d0,d1 andi.w #0xFF,d1 ori.w #0x9300,d1 move.w d1,VCTRL move.w d0,d1 lsr.w #8,d1 ori.w #0x9400,d1 move.w d1,VCTRL move.l d4,d1 lsr.l #1,d1 andi.w #0xFF,d1 ori.w #0x9500,d1 move.w d1,VCTRL move.l d4,d1 lsr.l #8,d1 lsr.l #1,d1 andi.w #0xFF,d1 ori.w #0x9600,d1 move.w d1,VCTRL move.l d4,d1 swap d1 lsr.w #1,d1 andi.w #0x7F,d1 ori.w #0x9700,d1 move.w d1,VCTRL rts | -- where interrupts land: HV in the handler, and HV when F shows in the status ------------- t_vpos: move.w #0xFFFF,VDMA move.w #700,d3 moveq #7,d6 move #0x2000,sr 1: lea VCOUNT,a1 move.w (a1),d0 2: cmp.w (a1),d0 beq.s 2b move.w VHVI,d0 moveq #7,d1 sub.w d6,d1 bsr record dbf d6,1b move #0x2700,sr clr.w VDMA move.w #701,d3 moveq #7,d6 1: btst #7,VCTRL+1 beq.s 1b move.w VHV,d0 moveq #7,d1 sub.w d6,d1 bsr record move #0x2000,sr | taken here, which clears F nop nop move #0x2700,sr dbf d6,1b rts | -- reads of VRAM held by the release: loops in 16 frames, reading the data port ------------ t_read: move.l #0x00000000,VCTRL lea VDATA,a3 moveq #2,d6 move #0x2000,sr 1: lea VCOUNT,a1 move.w (a1),d0 2: cmp.w (a1),d0 beq.s 2b move.w (a1),d2 addi.w #16,d2 moveq #0,d0 3: addq.l #1,d0 tst.w (a3) cmp.w (a1),d2 bne.s 3b moveq #2,d1 sub.w d6,d1 bsr record dbf d6,1b move #0x2700,sr rts | -- BUSACK by a phase walk ------------------------------------------------------------------ | A single read of $A11100, k NOPs and a jump (8 clocks) after the request. A bit set in the mask means the bus was | granted at that delay: resolution one NOP, 28 MCLK. d4 = 1 with the Z80 held in reset. t_busack: lea BUSREQ,a0 tst.w d4 bne.s 1f lea z80_ram,a3 moveq #11,d4 bsr z80_start moveq #0,d4 bra.s 2f 1: move.w #0,ZRESET 2: lea BUSREQ,a0 moveq #3,d6 3: moveq #0,d7 moveq #0,d5 4: move.w #0,(a0) move.w #60,d0 5: dbf d0,5b move.w d5,d0 add.w d0,d0 lea sled_end(pc),a5 suba.w d0,a5 move.w #0x100,d0 move.w d0,(a0) jmp (a5) sled: .rept WALK nop .endr sled_end: move.w (a0),d0 btst #8,d0 bne.s 6f bset d5,d7 6: addq.w #1,d5 cmpi.w #WALK,d5 bne.s 4b move.l d7,d0 moveq #3,d1 sub.w d6,d1 bsr record dbf d6,3b move.w #0x100,BUSREQ move.w #0,ZRESET rts | -- no RAM at all: a fixed loop, timed by frames and H counter ------------------------------ | A 68000 that leaves work RAM alone should pay no work-RAM refresh. t_idle: moveq #2,d6 move #0x2000,sr 1: lea VCOUNT,a1 move.w (a1),d0 2: cmp.w (a1),d0 beq.s 2b move.w (a1),d5 jsr (a2) move.w VHV,d0 swap d0 move.w (a1),d0 sub.w d5,d0 swap d0 moveq #2,d1 sub.w d6,d1 bsr record dbf d6,1b move #0x2700,sr rts idle_loop: move.w #59999,d0 1: dbf d0,1b rts idle_end: | -- what the YM2612's four ports read ---------------------------------------------------- t_ym: move.w #0x100,BUSREQ move.w #0x100,ZRESET 1: btst #0,BUSREQ bne.s 1b lea YM,a0 moveq #0x27,d0 moveq #0x30,d1 bsr ym_write moveq #0,d6 bsr ym_ports moveq #0x24,d0 moveq #-1,d1 bsr ym_write moveq #0x25,d0 moveq #3,d1 bsr ym_write moveq #0x27,d0 moveq #0x15,d1 bsr ym_write move.w #2000,d0 1: dbf d0,1b moveq #1,d6 bsr ym_ports moveq #0x27,d0 moveq #0x30,d1 bsr ym_write | straight after a data write, for BUSY moveq #0x30,d0 move.b d0,(a0) moveq #20,d0 1: dbf d0,1b move.b #0,1(a0) moveq #2,d6 bsr ym_ports move.w #0,ZRESET rts ym_write: move.b d0,(a0) moveq #20,d2 1: dbf d2,1b move.b d1,1(a0) moveq #40,d2 1: dbf d2,1b rts ym_ports: moveq #3,d5 moveq #0,d4 1: moveq #0,d0 move.b 0(a0,d4.w),d0 move.w #600,d3 add.w d4,d3 move.w d6,d1 bsr record addq.w #1,d4 dbf d5,1b rts | -- sprite phases, seen through the collision flag ----------------------------------------- | Two sprites overlap on line d5. A write to the second, d4 = 0 its Y in the cache, 6 its X in | the table, moves it away at a walked point on the two lines before and on the line itself. | Bit d set: they still collided, so the write came too late. One step is 30 68000 clocks. t_sprite: move.w #SAT+8,d0 add.w d4,d0 move.w d0,d1 andi.w #0x3FFF,d0 ori.w #0x4000,d0 swap d0 move.w d1,d0 lsr.w #8,d0 lsr.w #6,d0 movea.l d0,a3 move.w d5,d2 subq.w #2,d2 movea.w d2,a4 moveq #0,d6 1: moveq #0,d7 moveq #0,d2 2: bsr sprite_arm move.l a3,VCTRL move.w a4,d0 add.w d6,d0 | the line to wait for 3: cmp.b VHV,d0 bne.s 3b move.w d2,d0 add.w d0,d0 add.w d2,d0 4: dbf d0,4b move.w #0x0001,d1 tst.w d4 bne.s 5f move.w #0x01F0,d1 5: move.w d1,VDATA moveq #-0x20,d0 6: cmp.b VHV,d0 bne.s 6b move.w VCTRL,d0 btst #5,d0 beq.s 7f bset d2,d7 7: addq.w #1,d2 cmpi.w #STEPS,d2 bne.s 2b move.l d7,d0 move.w d6,d1 move.l d2,-(sp) bsr record move.l (sp)+,d2 addq.w #1,d6 cmpi.w #3,d6 bne.s 1b | leave nothing on screen bsr wait_f0 move.l #0x58000003,VCTRL move.w #0,VDATA move.w #0,VDATA move.w #0,VDATA move.w #0,VDATA rts | In the blank at $F0: both sprites on line d5, collision cleared. sprite_arm: bsr wait_f0 move.l #0x58000003,VCTRL move.w d5,d0 addi.w #128,d0 move.w d0,VDATA move.w #0x0001,VDATA move.w #0x0021,VDATA move.w #0x0100,VDATA move.w d0,VDATA move.w #0x0000,VDATA move.w #0x0021,VDATA move.w #0x0100,VDATA move.w VCTRL,d0 rts sizes: .word 1, 2, 3, 4, 8, 16, 32, 64, 128, 256, 512 sizes_end: