| The timing tests. t_run(id) is called from C; everything records through `record`. .equ VDATA, 0xC00000 .equ VCTRL, 0xC00004 .equ VHV, 0xC00008 .equ RECS, 0xFF0000 .equ VCOUNT, 0xFF3F00 .equ VDMA, 0xFF3F02 .equ NREC, 0xFF3F04 .equ RAMCODE, 0xFF3000 .equ FRAMES, 16 .equ REPS, 3 .equ DMAREPS, 4 .equ R1_OFF, 0x8134 .equ R1_ON, 0x8174 .equ DMA_DST, 0x4000 .globl dma_clean, zsw_measure, vint, t_run, vdp_init, wait_vint, record, z80_start, z80_ram, z80_ram_end, z80_rom .text vint: tst.w VDMA beq.s 1f bmi.s 2f movem.l d0-d1,-(sp) move.w VDMA,d0 bsr dma_start movem.l (sp)+,d0-d1 1: addq.w #1,VCOUNT rte 2: move.w VHV,0xFF3F06 bra.s 1b vdp_init: tst.w VCTRL lea regs(pc),a0 moveq #(regs_end-regs)/2-1,d0 1: move.w (a0)+,VCTRL dbf d0,1b lea count_loop(pc),a0 lea RAMCODE,a1 moveq #(count_end-count_loop)/2-1,d0 1: move.w (a0)+,(a1)+ dbf d0,1b rts wait_vint: move #0x2000,sr lea VCOUNT,a1 move.w (a1),d0 1: cmp.w (a1),d0 beq.s 1b rts t_run: movem.l d2-d7/a2-a6,-(sp) move.l 48(sp),d3 move d3,d0 move.w #R1_ON,VCTRL cmpi.w #1,d3 beq .Lrom0 cmpi.w #3,d3 beq .Lram0 cmpi.w #2,d3 beq .Lrom1 cmpi.w #4,d3 beq .Lram1 cmpi.w #5,d3 beq .Ldma cmpi.w #6,d3 beq .Lt6 cmpi.w #7,d3 beq .Lt7 cmpi.w #8,d3 beq .Lt8 cmpi.w #9,d3 beq .Lt9 cmpi.w #10,d3 beq .Lt10 cmpi.w #14,d3 bhi .Ldone move.w d3,d0 subi.w #11,d0 lea count_loop(pc),a2 btst #0,d0 beq.s 1f lea RAMCODE,a2 1: lea z80_ram(pc),a3 moveq #z80_ram_end-z80_ram,d4 btst #1,d0 beq.s 1f lea z80_rom(pc),a3 moveq #z80_rom_end-z80_rom,d4 1: bsr run_zcount bra .Ldone .Lrom0: move.w #R1_OFF,VCTRL .Lrom1: lea count_loop(pc),a2 bra.s .Lcount .Lram0: move.w #R1_OFF,VCTRL .Lram1: lea RAMCODE,a2 .Lcount: bsr run_count bra .Ldone .Ldma: move.w #1024,VDMA lea count_loop(pc),a2 bsr run_count clr.w VDMA bra .Ldone .Lt6: moveq #16,d4 bra.s .Lvb .Lt7: moveq #64,d4 bra.s .Lvb .Lt8: move.w #256,d4 bra.s .Lvb .Lt9: move.w #1024,d4 .Lvb: moveq #-1,d5 bra.s .Ld .Lt10: moveq #64,d4 moveq #0x40,d5 .Ld: bsr dma_time .Ldone: move #0x2700,sr movem.l (sp)+,d2-d7/a2-a6 rts | Count for FRAMES frames, REPS times, with code at a2, under id d3. run_count: moveq #REPS-1,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 #FRAMES,d2 moveq #0,d0 jsr (a2) moveq #REPS-1,d1 sub.w d6,d1 bsr record dbf d6,1b move #0x2700,sr rts count_loop: 1: addq.l #1,d0 cmp.w (a1),d2 bne.s 1b rts count_end: | The same count with a division in the loop: the 68000 mostly off the bus. divu_loop: 1: addq.l #1,d0 moveq #127,d5 divu.w #3,d5 cmp.w (a1),d2 bne.s 1b rts | zsw_measure(id, mode, z80 code, length) from C, for ZSW: run_zcount with the 68000 in | count_loop from ROM (mode 0), from RAM (1), or in divu_loop (2), display on. zsw_measure: movem.l d2-d7/a2-a6,-(sp) move.l 48(sp),d3 move.l 52(sp),d0 movea.l 56(sp),a3 move.l 60(sp),d4 lea count_loop(pc),a2 cmpi.w #1,d0 bne.s 1f lea RAMCODE,a2 1: cmpi.w #2,d0 bne.s 1f lea divu_loop(pc),a2 1: move.w #R1_ON,VCTRL bsr run_zcount move #0x2700,sr movem.l (sp)+,d2-d7/a2-a6 rts | DMAREPS transfers of d4 words starting at line d5 (-1: line $F0, which NTSC does not | repeat), held to two HV reads. dma_time: moveq #DMAREPS-1,d6 1: move.b d5,d1 cmpi.b #0xFF,d1 bne.s 2f move.b #0xF0,d1 2: cmp.b VHV,d1 beq.s 2b 3: cmp.b VHV,d1 bne.s 3b | a different start in each repeat move.w d6,d0 4: dbf d0,4b move.w VHV,d7 move.w d4,d0 bsr dma_start swap d7 move.w VHV,d7 move.l d7,d0 moveq #DMAREPS-1,d1 sub.w d6,d1 bsr record dbf d6,1b rts | dma_clean() from C, before any screen: a real one-word DMA to DMA_DST. A test may leave the | DMA registers set with no DMA after them (DMB0 does on purpose), and on the console the next | ordinary VRAM command then locks the 68000 for good, as WEDG showed. A DMA command after | them is safe, as DMPC after DMB0 always was. DMA enabled in register 1 first. dma_clean: move.w #0x8174,VCTRL moveq #1,d0 bsr.s dma_start rts | 68000 to VRAM DMA of d0 words, from ROM at DSRC to DMA_DST. dma_start: 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.w #0x9500+((DSRC>>1)&0xFF),VCTRL move.w #0x9600+((DSRC>>9)&0xFF),VCTRL move.w #0x9700,VCTRL move.w #0x4000+(DMA_DST&0x3FFF),VCTRL move.w #0x0080+(DMA_DST>>14),VCTRL rts | One record: id d3, repeat d1, value d0. record: move.l a0,-(sp) move.w NREC,d2 lea RECS,a0 lsl.w #3,d2 move.w d3,0(a0,d2.w) move.w d1,2(a0,d2.w) move.l d0,4(a0,d2.w) addq.w #1,NREC movea.l (sp)+,a0 rts | As run_count, with the Z80 running a3 (d4 bytes). The Z80 starts just after a frame | begins, and runs to the end of the count; its own count goes under id+10. run_zcount: moveq #REPS-1,d6 move #0x2000,sr 1: lea VCOUNT,a1 move.w (a1),d0 2: cmp.w (a1),d0 beq.s 2b bsr z80_start lea VCOUNT,a1 move.w (a1),d0 2: cmp.w (a1),d0 beq.s 2b move.w (a1),d2 addi.w #FRAMES,d2 moveq #0,d0 jsr (a2) moveq #REPS-1,d1 sub.w d6,d1 bsr record bsr z80_stop moveq #REPS-1,d1 sub.w d6,d1 addi.w #10,d3 bsr record subi.w #10,d3 dbf d6,1b move #0x2700,sr rts | Load a3 (d4 bytes) into the Z80 and let it go. z80_start: move.w #0x100,0xA11200 move.w #0x100,0xA11100 1: btst #0,0xA11100 bne.s 1b lea 0xA00000,a0 movea.l a3,a1 move.w d4,d0 subq.w #1,d0 1: move.b (a1)+,(a0)+ dbf d0,1b move.b #0,0xA01000 move.b #0,0xA01001 move.w #0,0xA11200 nop nop move.w #0,0xA11100 move.w #0x100,0xA11200 rts | Stop the Z80; d0 = its count. z80_stop: move.w #0x100,0xA11100 1: btst #0,0xA11100 bne.s 1b moveq #0,d0 move.b 0xA01001,d0 lsl.w #8,d0 move.b 0xA01000,d0 move.w #0,0xA11200 rts | The Z80 counts in its own RAM. z80_ram: .byte 0xF3, 0x21, 0x00, 0x00 | di; ld hl,0 .byte 0x23, 0x22, 0x00, 0x10 | inc hl; ld (1000h),hl .byte 0xC3, 0x04, 0x00 | jp 4 z80_ram_end: | The same with a read of cartridge ROM through the bank window on each turn. z80_rom: .byte 0xF3, 0x21, 0x00, 0x60, 0xAF | di; ld hl,6000h; xor a .byte 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77 | bank 0 .byte 0x21, 0x00, 0x00 | ld hl,0 .byte 0x3A, 0x00, 0x80 | ld a,(8000h) .byte 0x23, 0x22, 0x00, 0x10 | inc hl; ld (1000h),hl .byte 0xC3, 0x11, 0x00 | jp 11h z80_rom_end: .align 2 regs: .word 0x8004, 0x8134, 0x8230, 0x832C, 0x8407, 0x856C, 0x8600, 0x8700 .word 0x8A00, 0x8B00, 0x8C81, 0x8D34, 0x8E00, 0x8F02, 0x9001, 0x9100, 0x9200 regs_end: