1d62565be51705d4c6a41d44f928e8602f6d06fb
[mdlife] / src / vdp.S
1         .text
2
3 #include "hwregs.h"
4
5         .globl vdp_init
6 vdp_init:
7         | initialize registers
8         move.l #def_reg_tab, %a0
9         clr.w %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         clr.l %d0
21         move.l #VDP_VRAM, %d1
22         bsr setup_addr
23         clr.w %d0
24         move.w #0xffff, %d1
25 0:      move.w %d0, VDP_DATA_PORT
26         dbra.w %d1, 0b
27         
28         rts
29
30
31         | address in d0, type in d1
32 setup_addr:
33         lsl.l #2, %d0
34         lsr.w #2, %d0
35         swap %d0
36         or.l %d1, %d0
37         move.l %d0, VDP_CTL_PORT
38         rts
39
40         .globl vdp_setcolor
41 vdp_setcolor:
42         move.l 4(%sp), %d0      | palette number
43         lsl.l #4, %d0
44         add.l 8(%sp), %d0       | add index
45         lsl.l #1, %d0
46         move.l #VDP_CRAM, %d1
47         bsr setup_addr
48         move.w 22(%sp), %d0     | blue
49         lsl.w #4, %d0
50         or.w 18(%sp), %d0       | green
51         lsl.w #4, %d0
52         or.w 14(%sp), %d0       | red
53         and.w #0x0eee, %d0
54         move.w %d0, VDP_DATA_PORT
55         rts
56
57         .section .rodata
58 def_reg_tab:
59         .byte VDP_M1_INIT                       | 0: mode 1
60         .byte VDP_M2_INIT + VDP_M2_DISP         | 1: mode 2
61         .byte VDP_NA_ADDR(0xc000)               | 2: scroll A nametable addr.
62         .byte VDP_NW_ADDR(VDP_ADDR_INVAL)       | 3: window nametable addr.
63         .byte VDP_NB_ADDR(0xd000)               | 4: scroll B nametable addr.
64         .byte VDP_SPRTAB_ADDR(0xe000)           | 5: sprite table addr.
65         .byte 0
66         .byte 0                                 | 7: bg color
67         .byte 0, 0
68         .byte 0                                 | 10: horiz. interrupt interval
69         .byte 0                                 | 11: mode 3
70         .byte VDP_M4_H40                        | 12: mode 4
71         .byte 0                                 | 13: hscroll table addr.
72         .byte 0
73         .byte 2                                 | 15: autoincrement 2 bytes
74         .byte VDP_SCR_H64                       | 16: scroll size (64x32)
75         .byte 0, 0                              | 17,18: win x/y pos
76         .byte 0, 0, 0, 0, 0                     | 19-23: DMA regs
77 def_reg_tab_end:
78         .align 2
79 def_reg_tab_size:
80         .word def_reg_tab_end - def_reg_tab
81
82         
83 | vi:ft=gas68k: