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