per-line scrolling test
[mdlife] / src / vdp.S
index 1d62565..c1cf6a2 100644 (file)
--- a/src/vdp.S
+++ b/src/vdp.S
@@ -4,29 +4,39 @@
 
        .globl vdp_init
 vdp_init:
-       | initialize registers
-       move.l #def_reg_tab, %a0
-       clr.w %d1
-0:     move.w %d1, %d0
-       lsl.w #8, %d0
+       movea.l #def_reg_tab, %a0
+       moveq #14, %d1
+0:     move.w (%a0)+, %d0
        or.w #0x8000, %d0
-       move.b (%a0)+, %d0
        move.w %d0, VDP_CTL_PORT        | VDP_CTL = 0x8000 | (reg << 8) | val
-       add.w #1, %d1
-       cmp.w def_reg_tab_size, %d1
-       bne.s 0b
+       dbra %d1, 0b
 
-       | clear VRAM
-       clr.l %d0
+       | clear vram
+       movea.l #VDP_DATA_PORT, %a0
+       moveq #0, %d0
        move.l #VDP_VRAM, %d1
        bsr setup_addr
-       clr.w %d0
-       move.w #0xffff, %d1
-0:     move.w %d0, VDP_DATA_PORT
-       dbra.w %d1, 0b
-       
-       rts
+       moveq #0, %d0
+       move.l #0x7fff, %d1     | 64k / 2 - 1
+0:     move.w %d0, (%a0)
+       dbra %d1, 0b
 
+       | clear colormaps
+       move.l #VDP_CRAM, %d1
+       bsr setup_addr
+       moveq #0, %d0
+       move.l #63, %d1         | 4 palettes * 16 col * 2 bytes / 2 - 1
+0:     move.w %d0, (%a0)
+       dbra %d1, 0b
+
+       | clear vscroll
+       move.l #VDP_VSRAM, %d1
+       bsr setup_addr
+       moveq #0, %d0
+       move.l #39, %d1         | 80 bytes / 2 - 1
+0:     move.w %d0, (%a0)
+       dbra %d1, 0b
+       rts
 
        | address in d0, type in d1
 setup_addr:
@@ -56,28 +66,24 @@ vdp_setcolor:
 
        .section .rodata
 def_reg_tab:
-       .byte VDP_M1_INIT                       | 0: mode 1
-       .byte VDP_M2_INIT + VDP_M2_DISP         | 1: mode 2
-       .byte VDP_NA_ADDR(0xc000)               | 2: scroll A nametable addr.
-       .byte VDP_NW_ADDR(VDP_ADDR_INVAL)       | 3: window nametable addr.
-       .byte VDP_NB_ADDR(0xd000)               | 4: scroll B nametable addr.
-       .byte VDP_SPRTAB_ADDR(0xe000)           | 5: sprite table addr.
-       .byte 0
-       .byte 0                                 | 7: bg color
-       .byte 0, 0
-       .byte 0                                 | 10: horiz. interrupt interval
-       .byte 0                                 | 11: mode 3
-       .byte VDP_M4_H40                        | 12: mode 4
-       .byte 0                                 | 13: hscroll table addr.
-       .byte 0
-       .byte 2                                 | 15: autoincrement 2 bytes
-       .byte VDP_SCR_H64                       | 16: scroll size (64x32)
-       .byte 0, 0                              | 17,18: win x/y pos
-       .byte 0, 0, 0, 0, 0                     | 19-23: DMA regs
-def_reg_tab_end:
-       .align 2
-def_reg_tab_size:
-       .word def_reg_tab_end - def_reg_tab
+       .byte VDP_REG_MODE1, VDP_M1_INIT                | 0: mode 1
+       .byte VDP_REG_MODE2, VDP_M2_INIT + VDP_M2_DISP  | 1: mode 2
+       .byte VDP_REG_NAMEA, VDP_NA_ADDR(0xc000)        | 2: scroll A nametable addr.
+       .byte VDP_REG_NAMEW, 0                          | 3: window nametable addr.
+       .byte VDP_REG_NAMEB, VDP_NB_ADDR(0xe000)        | 4: scroll B nametable addr.
+       .byte VDP_REG_SPR, VDP_SPRTAB_ADDR(0xd000)      | 5: sprite table addr.
+       .byte VDP_REG_BGCOL, 0                          | 7: bg color
+       .byte VDP_REG_HINTR, 0                          | 10: horiz. interrupt interval
+       .byte VDP_REG_MODE3, 0                          | 11: mode 3
+       .byte VDP_REG_MODE4, VDP_M4_H40                 | 12: mode 4
+       .byte VDP_REG_HSCROLL, VDP_HSTAB_ADDR(0xf000)   | 13: hscroll table addr.
+       .byte VDP_REG_AUTOINC, 2                        | 15: autoincrement 2 bytes
+       .byte VDP_REG_SCROLLSZ, VDP_SCR_H64             | 16: scroll size (64x32)
+       .byte VDP_REG_WINX, 0, VDP_REG_WINY, 0          | 17,18: win x/y pos
+       | zeroing the DMA registers at this point causes the real machine to
+       | hang, so skip them.
+       |.byte VDP_REG_DMACNTL, 0, VDP_REG_DMACNTH, 0   | 19-23: DMA regs
+       |.byte VDP_REG_DMASRCL, 0, VDP_REG_DMASRCM, 0, VDP_REG_DMASRCH, 0       
 
        
 | vi:ft=gas68k: