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