fixed nametab.B invalid address, and spr_submit with 0 sprites
[mdlife] / src / vdp.S
1         .text
2
3 #include "hwregs.h"
4
5         .globl vdp_init
6 vdp_init:
7         movea.l #def_reg_tab, %a0
8         moveq #14, %d1
9 0:      move.w (%a0)+, %d0
10         or.w #0x8000, %d0
11         move.w %d0, VDP_CTL_PORT        | VDP_CTL = 0x8000 | (reg << 8) | val
12         dbra %d1, 0b
13
14         | clear vram
15         movea.l #VDP_DATA_PORT, %a0
16         moveq #0, %d0
17         move.l #VDP_VRAM, %d1
18         bsr setup_addr
19         moveq #0, %d0
20         move.l #0x7fff, %d1     | 64k / 2 - 1
21 0:      move.w %d0, (%a0)
22         dbra %d1, 0b
23
24         | clear colormaps
25         move.l #VDP_CRAM, %d1
26         bsr setup_addr
27         moveq #0, %d0
28         move.l #63, %d1         | 4 palettes * 16 col * 2 bytes / 2 - 1
29 0:      move.w %d0, (%a0)
30         dbra %d1, 0b
31
32         | clear vscroll
33         move.l #VDP_VSRAM, %d1
34         bsr setup_addr
35         moveq #0, %d0
36         move.l #39, %d1         | 80 bytes / 2 - 1
37 0:      move.w %d0, (%a0)
38         dbra %d1, 0b
39         rts
40
41         | address in d0, type in d1
42 setup_addr:
43         lsl.l #2, %d0
44         lsr.w #2, %d0
45         swap %d0
46         or.l %d1, %d0
47         move.l %d0, VDP_CTL_PORT
48         rts
49
50         .globl vdp_setcolor
51 vdp_setcolor:
52         move.l 4(%sp), %d0      | palette number
53         lsl.l #4, %d0
54         add.l 8(%sp), %d0       | add index
55         lsl.l #1, %d0
56         move.l #VDP_CRAM, %d1
57         bsr setup_addr
58         move.w 22(%sp), %d0     | blue
59         lsl.w #4, %d0
60         or.w 18(%sp), %d0       | green
61         lsl.w #4, %d0
62         or.w 14(%sp), %d0       | red
63         and.w #0x0eee, %d0
64         move.w %d0, VDP_DATA_PORT
65         rts
66
67         .section .rodata
68 def_reg_tab:
69         .byte VDP_REG_MODE1, VDP_M1_INIT                | 0: mode 1
70         .byte VDP_REG_MODE2, VDP_M2_INIT + VDP_M2_DISP  | 1: mode 2
71         .byte VDP_REG_NAMEA, VDP_NA_ADDR(0xc000)        | 2: scroll A nametable addr.
72         .byte VDP_REG_NAMEW, 0                          | 3: window nametable addr.
73         .byte VDP_REG_NAMEB, VDP_NB_ADDR(0xe000)        | 4: scroll B nametable addr.
74         .byte VDP_REG_SPR, VDP_SPRTAB_ADDR(0xd000)      | 5: sprite table addr.
75         .byte VDP_REG_BGCOL, 0                          | 7: bg color
76         .byte VDP_REG_HINTR, 0                          | 10: horiz. interrupt interval
77         .byte VDP_REG_MODE3, 0                          | 11: mode 3
78         .byte VDP_REG_MODE4, VDP_M4_H40                 | 12: mode 4
79         .byte VDP_REG_HSCROLL, VDP_HSTAB_ADDR(0xf000)   | 13: hscroll table addr.
80         .byte VDP_REG_AUTOINC, 2                        | 15: autoincrement 2 bytes
81         .byte VDP_REG_SCROLLSZ, VDP_SCR_H64             | 16: scroll size (64x32)
82         .byte VDP_REG_WINX, 0, VDP_REG_WINY, 0          | 17,18: win x/y pos
83         | zeroing the DMA registers at this point causes the real machine to
84         | hang, so skip them.
85         |.byte VDP_REG_DMACNTL, 0, VDP_REG_DMACNTH, 0   | 19-23: DMA regs
86         |.byte VDP_REG_DMASRCL, 0, VDP_REG_DMASRCM, 0, VDP_REG_DMASRCH, 0       
87
88         
89 | vi:ft=gas68k: