added debug output on exceptions
[mdlife] / src / vdp.S
index b794d21..1d62565 100644 (file)
--- a/src/vdp.S
+++ b/src/vdp.S
@@ -1,12 +1,12 @@
        .text
 
-#define ASM
 #include "hwregs.h"
 
        .globl vdp_init
 vdp_init:
+       | initialize registers
        move.l #def_reg_tab, %a0
-       move.w #0, %d1
+       clr.w %d1
 0:     move.w %d1, %d0
        lsl.w #8, %d0
        or.w #0x8000, %d0
@@ -15,8 +15,19 @@ vdp_init:
        add.w #1, %d1
        cmp.w def_reg_tab_size, %d1
        bne.s 0b
+
+       | clear VRAM
+       clr.l %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
 
+
        | address in d0, type in d1
 setup_addr:
        lsl.l #2, %d0
@@ -31,6 +42,7 @@ vdp_setcolor:
        move.l 4(%sp), %d0      | palette number
        lsl.l #4, %d0
        add.l 8(%sp), %d0       | add index
+       lsl.l #1, %d0
        move.l #VDP_CRAM, %d1
        bsr setup_addr
        move.w 22(%sp), %d0     | blue
@@ -42,12 +54,12 @@ vdp_setcolor:
        move.w %d0, VDP_DATA_PORT
        rts
 
-       .data
+       .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 0                                 | 3: window 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