| The brief's top ten, second pass: edges the first pass could only bound. Resolutions in README.md. | t3_run(id) from C, id 0 up in the order of the table below. .equ VDATA, 0xC00000 .equ VCTRL, 0xC00004 .equ VHV, 0xC00008 .equ VDMA, 0xFF3F02 .equ VHVI, 0xFF3F06 .equ RAMTWO, 0xFF3100 .equ BUSREQ, 0xA11100 .equ ZRESET, 0xA11200 .equ YM, 0xA04000 .equ SAT, 0xD800 .equ R1_OFF, 0x8134 .equ R1_ON, 0x8174 .equ WALK, 32 .equ z80_rom_size, 27 .equ sizes_len, 22 .globl t3_run, ym_probe .text t3_run: movem.l d2-d7/a2-a6,-(sp) move.l 48(sp),d3 move.w #R1_ON,VCTRL move #0x2700,sr add.w d3,d3 lea .Ltab(pc),a0 move.w 0(a0,d3.w),d3 jsr 0(a0,d3.w) move #0x2700,sr clr.w VDMA move.w #R1_ON,VCTRL movem.l (sp)+,d2-d7/a2-a6 rts .Ltab: .word t_vstep-.Ltab, t_rdln-.Ltab, t_fflg-.Ltab, t_intf-.Ltab, t_bsk3-.Ltab, t_bsk4-.Ltab .word t_bsk5-.Ltab, t_bsk6-.Ltab, t_ym2-.Ltab, t_ymby-.Ltab, t_spfy1-.Ltab, t_spfx1-.Ltab .word t_spfy0-.Ltab, t_spfx0-.Ltab, t_dmb0-.Ltab, t_dmpc-.Ltab, t_dmps-.Ltab, t_wedge-.Ltab .word t_ymdk-.Ltab | Returns just as V turns to d1. wait_v: 1: cmp.b VHV,d1 beq.s 1b 2: cmp.b VHV,d1 bne.s 2b rts | -- where V steps: HV either side of the step, 32 starts a NOP apart ---------------------- | One read each 12 clocks, 5.2 H steps; the starts walk that gap in steps of 1.7. In the picture | (900) and in the blank (903). t_vstep: moveq #0x50,d4 move.w #900,d3 bsr.s vstep move.l #0xFFFFFFF4,d4 move.w #903,d3 vstep: lea VHV,a0 moveq #0,d6 1: move.b d4,d1 bsr wait_v moveq #25,d0 2: dbf d0,2b move.w d6,d0 bsr nopk lea RAMTWO,a2 .rept 16 move.w (a0),(a2)+ .endr lea RAMTWO,a2 moveq #14,d5 moveq #0,d0 3: move.w (a2)+,d1 move.b (a2),d2 cmp.b -2(a2),d2 beq.s 4f move.w d1,d0 swap d0 move.w (a2),d0 bra.s 5f 4: dbf d5,3b 5: move.w d6,d1 bsr record addq.w #1,d6 cmpi.w #32,d6 bne.s 1b rts | d0 NOPs, 0 to 63, and the call. nopk: add.w d0,d0 lea nops_end(pc),a5 suba.w d0,a5 jmp (a5) .rept 63 nop .endr nops_end: rts | -- VRAM reads by region: 100 active lines and 15 blank lines, display on then off --------- t_rdln: lea VDATA,a3 lea VHV,a2 move.l #0x00000000,VCTRL moveq #20,d4 moveq #120,d5 move.w #720,d3 bsr rd_span move.l #0xFFFFFFF0,d4 moveq #-1,d5 move.w #721,d3 bsr rd_span move.w #R1_OFF,VCTRL move.l #0x00000000,VCTRL moveq #20,d4 moveq #120,d5 move.w #722,d3 bsr rd_span move.l #0xFFFFFFF0,d4 moveq #-1,d5 move.w #723,d3 bsr rd_span rts rd_span: moveq #2,d6 1: move.b d4,d1 bsr wait_v moveq #0,d0 2: addq.l #1,d0 tst.w (a3) cmp.b (a2),d5 bne.s 2b moveq #2,d1 sub.w d6,d1 bsr record dbf d6,1b rts | -- F flag and the interrupt --------------------------------------------------------------- | HV and status read back to back, 16 clocks apart, a NOP later each frame: the step where F shows | is placed by the HV beside it, so jitter in the start costs nothing. Resolution 1.7 H steps. | Then NOPs with the interrupt open: HV in the handler, and which NOP the stacked PC names. t_fflg: moveq #0,d6 1: moveq #-0x21,d1 bsr wait_v moveq #36,d0 2: dbf d0,2b move.w d6,d0 bsr nopk move.w VHV,d7 swap d7 move.w VCTRL,d7 move #0x2000,sr | taken here, or by the next line moveq #-0x1F,d1 bsr wait_v move #0x2700,sr move.l d7,d0 move.w #901,d3 move.w d6,d1 bsr record addq.w #1,d6 cmpi.w #64,d6 bne.s 1b rts t_intf: move.w #0xFFFF,VDMA move #0x2000,sr | any F left pending moveq #-0x1F,d1 bsr wait_v move #0x2700,sr moveq #7,d6 1: moveq #-0x20,d1 bsr wait_v move #0x2000,sr isled: .rept 128 nop .endr move #0x2700,sr move.l -4(sp),d0 | the frame the interrupt stacked lea isled(pc),a5 sub.l a5,d0 lsr.w #1,d0 swap d0 move.w VHVI,d0 swap d0 move.w #902,d3 moveq #7,d1 sub.w d6,d1 bsr record dbf d6,1b clr.w VDMA rts | -- BUSACK ----------------------------------------------------------------------------------- | 402: asked for in reset, walked from the reset's release: one NOP, 28 MCLK, the first read | about 84 MCLK after. Mask bit set: granted. t_bsk3: lea BUSREQ,a0 lea ZRESET,a1 moveq #3,d6 1: moveq #0,d7 moveq #0,d5 2: move.w #0,(a1) move.w #0,(a0) move.w #60,d0 3: dbf d0,3b move.w #0x100,(a0) move.w #60,d0 3: dbf d0,3b move.w d5,d0 add.w d0,d0 lea b3end(pc),a5 suba.w d0,a5 move.w #0x100,d0 move.w d0,(a1) jmp (a5) .rept WALK nop .endr b3end: move.w (a0),d0 btst #8,d0 bne.s 4f bset d5,d7 4: addq.w #1,d5 cmpi.w #WALK,d5 bne.s 2b move.l d7,d0 move.w #402,d3 moveq #3,d1 sub.w d6,d1 bsr record dbf d6,1b bra z80_off | 403: the same walk as BSK1, with the Z80 reading ROM through the bank window. t_bsk4: lea z80_rom,a3 moveq #z80_rom_size,d4 bsr z80_start lea BUSREQ,a0 moveq #3,d6 1: moveq #0,d7 moveq #0,d5 2: move.w #0,(a0) move.w #60,d0 3: dbf d0,3b move.w d5,d0 add.w d0,d0 lea b4end(pc),a5 suba.w d0,a5 move.w #0x100,d0 move.w d0,(a0) jmp (a5) .rept WALK nop .endr b4end: move.w (a0),d0 btst #8,d0 bne.s 4f bset d5,d7 4: addq.w #1,d5 cmpi.w #WALK,d5 bne.s 2b move.l d7,d0 move.w #403,d3 moveq #3,d1 sub.w d6,d1 bsr record dbf d6,1b bra z80_off | 404 Z80 in RAM, 405 Z80 on ROM: a read straight after the write, the earliest a 68000 can look, | about 42 MCLK. 32 tries with the Z80 free for a varying while before each. t_bsk5: lea z80_ram,a3 moveq #11,d4 move.w #404,a4 bra.s bsk_now t_bsk6: lea z80_rom,a3 moveq #z80_rom_size,d4 move.w #405,a4 bsk_now: bsr z80_start lea BUSREQ,a0 moveq #3,d6 1: moveq #0,d7 moveq #0,d5 2: move.w #0,(a0) move.w #60,d0 add.w d5,d0 add.w d6,d0 3: dbf d0,3b move.w #0x100,d0 move.w d0,(a0) move.w (a0),d1 btst #8,d1 bne.s 4f bset d5,d7 4: addq.w #1,d5 cmpi.w #WALK,d5 bne.s 2b move.l d7,d0 move.w a4,d3 moveq #3,d1 sub.w d6,d1 bsr record dbf d6,1b z80_off: move.w #0x100,BUSREQ move.w #0,ZRESET rts | -- YM2612 ports 1-3: live, or a latch of the last status? ---------------------------------- ym_setup: move.w #0x100,BUSREQ move.w #0x100,ZRESET 1: btst #0,BUSREQ bne.s 1b lea YM,a0 rts ym_flag: moveq #0x27,d0 moveq #0x30,d1 bsr ym_write 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 rts ym_off: moveq #0x27,d0 moveq #0x30,d1 bra ym_write frames: bsr wait_f0 dbf d6,frames rts ym_rec: moveq #0,d1 move.b d0,d1 exg d0,d1 move.w d4,d1 bra record | 610 rep 1-3: flag set, a second since any status read. 613: port 0 after that. | 612: flag cleared straight after, port 1 then port 0. 611 rep p: port p right after a data | write, each time fresh. 614: a status of 1 read from port 0, the flag cleared, port 1 after | 0, 20 and 60 frames: a latch shows 1, a live port 0. t_ym2: bsr ym_setup bsr ym_off moveq #59,d6 bsr frames bsr ym_flag moveq #59,d6 bsr frames moveq #1,d5 1: move.b 0(a0,d5.w),d0 move.w #610,d3 move.w d5,d4 bsr ym_rec addq.w #1,d5 cmpi.w #4,d5 bne.s 1b move.b (a0),d0 move.w #613,d3 moveq #0,d4 bsr ym_rec bsr ym_off move.b 1(a0),d0 move.w #612,d3 moveq #0,d4 bsr ym_rec move.b (a0),d0 move.w #612,d3 moveq #1,d4 bsr ym_rec moveq #0,d5 2: moveq #0x30,d0 move.b d0,(a0) moveq #20,d0 3: dbf d0,3b move.b #0,1(a0) move.b 0(a0,d5.w),d0 move.w #611,d3 move.w d5,d4 bsr ym_rec move.w #400,d0 3: dbf d0,3b addq.w #1,d5 cmpi.w #4,d5 bne.s 2b moveq #0,d5 4: bsr ym_flag move.b (a0),d7 bsr ym_off move.w .Lgap(pc,d5.w),d6 bmi.s 5f bsr frames 5: move.b 1(a0),d0 move.w #614,d3 move.w d5,d4 lsr.w #1,d4 bsr ym_rec addq.w #2,d5 cmpi.w #6,d5 bne.s 4b bra z80_off .Lgap: .word -1, 19, 59 | 630 rep k and 631 rep k: how long ports 1-3 keep a status: a 1 read from port 0, the flag | cleared, then port 1 after a wait. 630: 0, 1, 2, 4 ... 128 lines (49 dbf a line). 631: port 0 | read as F turns off, then .Lfr+1 whole frames: 1-7, 9, 13, 18. Runs 4 and 6 (unsynced, | 0,1,2,3,5... frames) kept it 3-4 frames on and lost it by 5-6. t_ymdk: bsr ym_setup moveq #0,d5 1: bsr ym_flag move.b (a0),d7 bsr ym_off move.w .Lln(pc,d5.w),d0 2: dbf d0,2b move.b 1(a0),d0 move.w #630,d3 move.w d5,d4 lsr.w #1,d4 bsr ym_rec addq.w #2,d5 cmpi.w #18,d5 bne.s 1b moveq #0,d5 3: bsr ym_flag bsr wait_f0 move.b (a0),d7 bsr ym_off move.w .Lfr(pc,d5.w),d6 bsr frames move.b 1(a0),d0 move.w #631,d3 move.w d5,d4 lsr.w #1,d4 bsr ym_rec addq.w #2,d5 cmpi.w #20,d5 bne.s 3b bra z80_off .Lln: .word 0, 49, 98, 196, 392, 784, 1568, 3136, 6272 .Lfr: .word 0, 1, 2, 3, 4, 5, 6, 8, 12, 17 | 620 and 621: BUSY after a data write, a NOP a step from about 1,000 MCLK, 64 steps. Bit set: | still busy. The chip's own 42-MCLK cycle runs free against this, hence the repeats. t_ymby: bsr ym_setup moveq #3,d6 1: moveq #0,d4 moveq #0,d7 moveq #0,d5 2: moveq #0x30,d0 move.b d0,(a0) moveq #20,d0 3: dbf d0,3b move.w d5,d0 add.w d0,d0 lea yend(pc),a5 suba.w d0,a5 moveq #12,d0 move.b #0,1(a0) 3: dbf d0,3b jmp (a5) .rept 64 nop .endr yend: move.b (a0),d0 bpl.s 5f move.w d5,d0 cmpi.w #32,d0 bcc.s 4f bset d0,d4 bra.s 5f 4: bset d0,d7 5: move.w #400,d0 3: dbf d0,3b addq.w #1,d5 cmpi.w #64,d5 bne 2b moveq #3,d1 sub.w d6,d1 move.l d4,d0 move.w #620,d3 bsr record moveq #3,d1 sub.w d6,d1 move.l d7,d0 move.w #621,d3 bsr record dbf d6,1b bra z80_off | -- the sprite edges at one NOP a step, 28 MCLK, across steps 11 to 15 of the coarse walk --- t_spfy1: moveq #0,d4 moveq #100,d5 moveq #1,d6 move.w #510,d3 bra.s t_spf t_spfx1: moveq #6,d4 moveq #100,d5 moveq #1,d6 move.w #511,d3 bra.s t_spf t_spfy0: moveq #0,d4 moveq #0,d5 moveq #0,d6 move.w #512,d3 bra.s t_spf t_spfx0: moveq #6,d4 moveq #0,d5 moveq #1,d6 move.w #513,d3 t_spf: 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,d0 subq.w #2,d0 add.w d6,d0 movea.w d0,a4 moveq #0,d7 moveq #0,d2 2: bsr sprite_arm move.l a3,VCTRL move.w a4,d0 3: cmp.b VHV,d0 bne.s 3b moveq #24,d0 4: dbf d0,4b move.w d2,d0 bsr nopk 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 #WALK,d2 bne.s 2b move.l d7,d0 moveq #0,d1 bsr record bsr wait_f0 move.l #0x58000003,VCTRL move.w #0,VDATA move.w #0,VDATA move.w #0,VDATA move.w #0,VDATA rts | -- DMA: a start with no DMA in it, for the code's own cost; then CRAM and VSRAM ------------- t_dmb0: movea.l #0x8F028F02,a6 | harmless, and the same writes move.w #910,d3 move.l #DSRC,d4 lea one(pc),a3 moveq #0,d5 bra.s dmp t_dmpc: movea.l #0xC0000080,a6 move.w #1000,d3 bra.s dmps t_dmps: movea.l #0x40000090,a6 move.w #1100,d3 dmps: move.l #DSRC,d4 lea sizes,a3 moveq #(sizes_len/2)-1,d5 dmp: 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_regs move.l a6,d1 swap d1 move.w d1,VCTRL swap d1 move.w d1,VCTRL 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 one: .word 1 | -- last on purpose: DMA registers, then an ordinary command in two word writes ------------- | The die's 68000 never finishes the second write here, DMA enabled or not, by word or by long. | A console that hangs here has lost nothing, and the boot after marks it hung. 1 means it came back. t_wedge: bsr wait_f0 moveq #1,d0 move.l #DSRC,d4 bsr dma_regs move.w #0x6000,VCTRL move.w #0x0000,VCTRL moveq #1,d0 moveq #0,d1 move.w #911,d3 bra record | ym_probe(lines) from C, for YMFT: a 1 read from port 0, the flag cleared, then port 1 | after that many V counter steps (one a line, wherever the frame is). Returns port 0's | byte << 8 | port 1's. ym_probe: movem.l d2-d7/a2-a6,-(sp) move.l 48(sp),d5 move #0x2700,sr bsr ym_setup bsr ym_flag move.b (a0),d7 bsr ym_off tst.l d5 beq.s 3f move.b VHV,d1 1: cmp.b VHV,d1 beq.s 1b move.b VHV,d1 subq.l #1,d5 bne.s 1b 3: moveq #0,d0 move.b 1(a0),d0 moveq #0,d1 move.b d7,d1 lsl.w #8,d1 or.w d1,d0 bsr z80_off movem.l (sp)+,d2-d7/a2-a6 rts