c2b2fbe1dd31ed612341bfe18219005cc5f3e8fa
[swan-dev] / src / init.s
1
2 %include "WonderSwan.inc"
3
4 extern  _main
5
6 MYSEGMENT       equ     0xF000
7
8 ; Set Maps and Sprite Table at the end of first part of ram
9 fgmap           equ     WSC_TILE_BANK1-MAP_SIZE
10 bgmap           equ     fgmap-MAP_SIZE
11 sprtable        equ     bgmap-SPR_TABLE_SIZE
12
13
14         cpu     186
15         bits    16
16
17         ;PADDING        15              ; Pad 15 Sections
18
19         section .text
20
21         ;ORG    0x0000
22
23 ..start:
24         cli                     ; Disable Interrupts
25         cld                     ; Offset in Increment mode
26
27         xor     ax,ax           ; Clear all registers
28         mov     bx,ax
29         mov     cx,ax
30         mov     dx,ax
31         mov     si,ax
32         mov     di,ax
33         mov     ds,ax           ; Clear Segments
34         mov     es,ax
35
36         mov     bp,ax           ; Setup stack
37         mov     ss,ax
38         mov     sp,WS_STACK
39
40         in      al,IO_HARDWARE_TYPE     ; Check Wonderswan Mono/Color
41         test    al,WS_COLOR
42 .mono:  jz      .mono           ; We loop forever if Mono
43
44         mov     sp,WSC_STACK    ; New stack
45
46         xor     ax,ax           ; Clear Ram
47         mov     di,0x100
48         mov     cx,0x7E80
49         rep     stosw
50
51         out     IO_SRAM_BANK,al
52
53         ; Video Init
54         in      al,IO_VIDEO_MODE
55         or      al,VMODE_16C_CHK | VMODE_CLEANINIT
56         out     IO_VIDEO_MODE,al
57
58         xor     ax,ax
59
60         out     IO_BG_X,al
61         out     IO_BG_Y,al
62         out     IO_FG_X,al
63         out     IO_FG_Y,al
64
65         out     IO_SPR_START,al
66         out     IO_SPR_STOP,al
67
68         mov     al,BG_MAP(bgmap) | FG_MAP(fgmap)
69         out     IO_FGBG_MAP,al
70
71         mov     al,SPR_TABLE(sprtable)
72         out     IO_SPR_TABLE,al
73
74         in      al,IO_LCD_CTRL
75         or      al,LCD_ON
76         out     IO_LCD_CTRL,al
77
78         xor     al,al
79         out     IO_LCD_ICONS,al
80
81         ; Setup VBlank Int
82         mov     ax,INT_BASE
83         out     IO_INT_BASE,al
84
85         mov     di,INTVEC_VBLANK_START
86         add     di,ax
87         shl     di,2                    ; *4
88         mov     word [es:di],VBlank
89         mov     word [es:di+0x2],MYSEGMENT
90
91         xor     ax,ax                   ; Clear HBL & Timer
92         out     IOw_HBLANK_FREQ,ax
93         out     IO_TIMER_CTRL,al
94
95         dec     al                      ; Ack all Int
96         out     IO_INT_ACK,al
97
98         mov     al,INT_VBLANK_START     ; Enable VBL Int
99         out     IO_INT_ENABLE,al
100
101         sti                             ; Enable Interrupts !
102
103 ;--------------------------------
104
105         ; Set Segments for Copy
106         mov     ax,MYSEGMENT
107         mov     ds,ax
108         xor     ax,ax
109         mov     es,ax
110
111         ; Make BG
112
113         mov     si,TileGfx
114         mov     di,WSC_TILE_BANK1
115         mov     cx,(TileGfxE-TileGfx)/2
116         rep     movsw
117
118         mov     si,TilePal
119         mov     di,WSC_PALETTES
120         mov     cx,16
121         rep     movsw
122
123         mov     ax,BG_CHR(0,0,0,0,0)    ; Initial Tile, Pal 0, Bank 0
124         mov     di,bgmap
125         mov     cx,MAP_TWIDTH*MAP_THEIGHT
126         rep     stosw
127
128         ; Display !
129         mov     al,BG_ON | FG_ON
130         out     IO_DISPLAY_CTRL,al
131
132         ; Loop Read Buttons
133 loop:
134         mov     al,KEYPAD_READ_BUTTONS
135         out     IO_KEYPAD,al
136         nop
137         nop
138         nop
139         nop
140         in      al,IO_KEYPAD
141
142         test    al,PAD_A        ; Press A for Audio
143         jz      loop
144
145         ;call   _main
146         jmp     loop
147
148 ;******************************************
149
150 VBlank:
151         push    ax
152
153         mov     al,[es:VBLcnt]
154         inc     al
155         mov     [es:VBLcnt],al
156         and     al,3
157         jnz     .noscroll
158
159         in      al,IO_BG_X      ; Infinite Scroll
160         inc     al
161         out     IO_BG_X,al
162
163         in      al,IO_BG_Y
164         inc     al
165         out     IO_BG_Y,al
166
167 .noscroll:
168         in      al,IO_INT_ACK
169         or      al,INT_VBLANK_START
170         out     IO_INT_ACK,al
171
172         pop     ax
173         iret
174
175 ;******************************************
176
177         align   2
178
179 TilePal:        incbin  "gfx/bgtile.pal"
180 TileGfx:        incbin  "gfx/bgtile.gfx"
181 TileGfxE:
182
183 ;******************************************
184
185         ROM_HEADER      ..start, MYSEGMENT, 0x42, RH_WS_COLOR, RH_ROM_8MBITS, RH_NO_SRAM, RH_HORIZONTAL
186
187 ;******************************************
188
189         ;section .bss   
190
191         ;start=0x0100   ; Keep space for Int Vectors
192
193 VBLcnt:         resb    0       ; Our datas in RAM
194