clear vram/cram/vsram on init
[mdlife] / src / vdp.S
1         .text
2
3 #define ASM
4 #include "hwregs.h"
5
6         .globl vdp_init
7 vdp_init:
8         movea.l #def_reg_tab, %a0
9         move.w #0, %d1
10 0:      move.w %d1, %d0
11         lsl.w #8, %d0
12         or.w #0x8000, %d0
13         move.b (%a0)+, %d0
14         move.w %d0, VDP_CTL_PORT        | VDP_CTL = 0x8000 | (reg << 8) | val
15         add.w #1, %d1
16         cmp.w def_reg_tab_size, %d1
17         bne.s 0b
18
19         | clear vram
20         movea.l #VDP_DATA_PORT, %a0
21         moveq #0, %d0
22         move.l #VDP_VRAM, %d1
23         bsr setup_addr
24         moveq #0, %d0
25         move.l #0x7fff, %d1     | 64k / 2 - 1
26 0:      move.w %d0, (%a0)
27         dbra %d1, 0b
28
29         | clear colormaps
30         move.l #VDP_CRAM, %d1
31         bsr setup_addr
32         moveq #0, %d0
33         move.l #63, %d1         | 4 palettes * 16 col * 2 bytes / 2 - 1
34 0:      move.w %d0, (%a0)
35         dbra %d1, 0b
36
37         | clear vscroll
38         move.l #VDP_VSRAM, %d1
39         bsr setup_addr
40         moveq #0, %d0
41         move.l #39, %d1         | 80 bytes / 2 - 1
42 0:      move.w %d0, (%a0)
43         dbra %d1, 0b
44         rts
45
46         | address in d0, type in d1
47 setup_addr:
48         lsl.l #2, %d0
49         lsr.w #2, %d0
50         swap %d0
51         or.l %d1, %d0
52         move.l %d0, VDP_CTL_PORT
53         rts
54
55         .globl vdp_setcolor
56 vdp_setcolor:
57         move.l 4(%sp), %d0      | palette number
58         lsl.l #5, %d0
59         add.l 8(%sp), %d0       | add index
60         move.l #VDP_CRAM, %d1
61         bsr setup_addr
62         move.w 22(%sp), %d0     | blue
63         lsl.w #4, %d0
64         or.w 18(%sp), %d0       | green
65         lsl.w #4, %d0
66         or.w 14(%sp), %d0       | red
67         and.w #0x0eee, %d0
68         move.w %d0, VDP_DATA_PORT
69         rts
70
71         .data
72 def_reg_tab:
73         .byte VDP_M1_INIT                       | 0: mode 1
74         .byte VDP_M2_INIT + VDP_M2_DISP         | 1: mode 2
75         .byte VDP_NA_ADDR(0xc000)               | 2: scroll A nametable addr.
76         .byte 0                                 | 3: window nametable addr.
77         .byte VDP_NB_ADDR(0xd000)               | 4: scroll B nametable addr.
78         .byte VDP_SPRTAB_ADDR(0xe000)           | 5: sprite table addr.
79         .byte 0
80         .byte 0                                 | 7: bg color
81         .byte 0, 0
82         .byte 0                                 | 10: horiz. interrupt interval
83         .byte 0                                 | 11: mode 3
84         .byte VDP_M4_H40                        | 12: mode 4
85         .byte VDP_HSTAB_ADDR(0xf000)            | 13: hscroll table addr.
86         .byte 0
87         .byte 2                                 | 15: autoincrement 2 bytes
88         .byte VDP_SCR_H64                       | 16: scroll size (64x32)
89         .byte 0, 0                              | 17,18: win x/y pos
90         .byte 0, 0, 0, 0, 0                     | 19-23: DMA regs
91 def_reg_tab_end:
92         .align 2
93 def_reg_tab_size:
94         .word def_reg_tab_end - def_reg_tab
95
96         
97 | vi:ft=gas68k: