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