-
Notifications
You must be signed in to change notification settings - Fork 0
/
main2.S
213 lines (180 loc) · 4.49 KB
/
main2.S
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#include "base.h"
#include "regs.h"
#include "snake.h"
#include "input.h"
.section .text
.global main
main:
/*
stack
*/
ldr sp, =#IWRAM_SP_USR
/*
palettes
*/
mov r0, #PRAM_BG
bl palette$basic /* pallete 0 */
/*
tiles
*/
mov r0, #VRAM
bl tile$basic
mov r1, #1
bl tile$arrows
/*
screens
*/
ldr r0, =#SCREEN_BASE_BLOCK(31)
add r0, r0, #VRAM
mov r1, #15
bl screen$text_fill
ldr r0, =#SCREEN_BASE_BLOCK(30)
add r0, r0, #VRAM
mov r1, #0
bl screen$text_fill
/*
ldr r0, =#SCREEN_BASE_BLOCK(30)
add r0, r0, #VRAM
mov r1, #SCREEN_TEXT_PALETTE(0)
mov r3, #7
_loop:
orr r2, r1, r3
strh r2, [r0], #2
subs r3, r3, #1
bne _loop
*/
/* allocate (GRID_SIZE + head + tail + xorshift + snake_len from sp */
/* 0 4 8 12 */
ldr r1, =#-(GRID_SIZE + 4 + 4 + 4 + 4)
add sp, sp, r1
mov r0, sp
bl snake$init
mov r11, sp
/*
BG modes
*/
mov r0, #IO_REG
mov r2, #0x0
orr r2, r2, #BG_CNT__COLOR_16_16
orr r2, r2, #BG_CNT__SCREEN_SIZE(0)
orr r2, r2, #BG_CNT__CHAR_BASE_BLOCK(0)
orr r2, r2, #BG_CNT__SCREEN_BASE_BLOCK(31)
orr r2, r2, #BG_CNT__PRIORITY(1)
strh r2, [r0, #BG1CNT]
mov r0, #IO_REG
mov r2, #0x0
orr r2, r2, #BG_CNT__COLOR_16_16
orr r2, r2, #BG_CNT__SCREEN_SIZE(0)
orr r2, r2, #BG_CNT__CHAR_BASE_BLOCK(0)
orr r2, r2, #BG_CNT__SCREEN_BASE_BLOCK(30)
orr r2, r2, #BG_CNT__PRIORITY(0)
strh r2, [r0, #BG0CNT]
mov r0, #IO_REG
mov r2, #0x0
orr r2, r2, #DISPCNT__BG0
orr r2, r2, #DISPCNT__BG1
orr r2, r2, #DISPCNT__BG_MODE_0
strh r2, [r0, #DISPCNT]
/*
interrupts
*/
ldr r0, =#IWRAM_USER_ISR
ldr r2, =_user_isr
str r2, [r0]
mov r0, #IO_REG
mov r1, #TM1CNT_L
ldr r2, =#-4096
strh r2, [r0, r1]
ldr r1, =#TM1CNT_H
mov r2, #0
orr r2, r2, #TM_CNT_H__ENABLE
orr r2, r2, #TM_CNT_H__INT_ENABLE
orr r2, r2, #TM_CNT_H__PRESCALAR_1024
strh r2, [r0, r1]
ldr r1, =#KEYCNT
mov r2, #0
orr r2, r2, #KEYCNT_INPUT__RIGHT
orr r2, r2, #KEYCNT_INPUT__LEFT
orr r2, r2, #KEYCNT_INPUT__UP
orr r2, r2, #KEYCNT_INPUT__DOWN
orr r2, r2, #KEYCNT__INT_ENABLE
strh r2, [r0, r1]
mov r0, #IO_REG
mov r1, #IE
mov r2, #0
orr r2, r2, #IE__TIMER_1
orr r2, r2, #IE__KEY
strh r2, [r0, r1]
ldr r1, =#IF
mov r2, #0
add r2, r2, #-1
strh r2, [r0, r1]
mov r0, #IO_REG
mov r1, #IME
mov r2, #IME__INT_MASTER_ENABLE
strh r2, [r0, r1]
_forever:
mov r0, #IO_REG
ldr r1, =#HALTCNT
mov r2, #0
/*strb r2, [r0, r1]*/
b _forever
_user_isr:
mov r0, #IO_REG
mov r1, #IME
mov r2, #0
strh r2, [r0, r1]
mov r12, lr
/*
input poll
*/
bl input$poll /* return r1: dir */
mov r3, r1
mov r0, #IO_REG
ldr r1, =#IF
ldrh r2, [r0, r1]
tst r2, #IE__KEY
bne _update_dir
_update:
/*
update
*/
/* r11: grid base address */
/* r1 dir */
mov r0, r11
mov r1, r3
bl snake$update
b _isr_return
_update_dir:
mov r0, r11
mov r1, r3
cmp r1, #DIR_NONE
beq _isr_return
bl snake$update_dir
_isr_return:
mov r0, #IO_REG
ldr r1, =#IF
mov r2, #0
orr r2, #IE__KEY
orr r2, #IE__TIMER_1
strh r2, [r0, r1]
/*
render
*/
mov r0, r11
ldr r1, =#SCREEN_BASE_BLOCK(29)
add r1, r1, #VRAM
bl snake$render
/* r0 dest, r1 src, r2 length */
ldr r0, =#SCREEN_BASE_BLOCK(30)
add r0, r0, #VRAM
ldr r1, =#SCREEN_BASE_BLOCK(29)
add r1, r1, #VRAM
mov r2, #(SCREEN_BASE_BLOCK_LENGTH / 4)
bl dma0$transfer
mov lr, r12
mov r0, #IO_REG
mov r1, #IME
mov r2, #IME__INT_MASTER_ENABLE
strh r2, [r0, r1]
bx lr