-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.S
146 lines (122 loc) · 3.36 KB
/
main.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
#include "base.h"
#include "regs.h"
#include "color.h"
.section .text
.global main
main:
/* stack */
mov sp, #IWRAM
b minmin
.global minmin_ret
minmin_ret:
/* palettes */
mov r0, #PRAM_BG
add r0, r0, #32 /* palette 1 */
add r0, r0, #2
mov r1, #BLACK
strh r1, [r0], #2
ldr r1, =#WHITE
strh r1, [r0], #2
mov r1, #0x8 /* red */
strh r1, [r0], #2
/* tiles */
mov r0, #VRAM
add r0, r0, #0x8000 /* tile base block 2 */
bl copy_glyphs
/* fill screen */
mov r0, #VRAM
add r0, r0, #0xf000 /* screen base block 30 */
add r1, r0, #0x800
mov r2, #0x10
orr r2, r2, #SCREEN_TEXT_PALETTE(1)
_fill_loop:
strh r2, [r0], #2
cmp r0, r1
bne _fill_loop
/* screen */
mov r0, #VRAM
add r0, r0, #0xf000 /* screen base block 30 */
mov r1, #SCREEN_TEXT_PALETTE(1)
ldr r2, =#0xda1
bl draw_base16
add r0, r0, #2
mov r2, r10
bl draw_base16
/* set text mode */
mov r0, #IO_REG
mov r1, #0x0
orr r1, r1, #BG_CNT__COLOR_16_16
orr r1, r1, #BG_CNT__SCREEN_SIZE(0)
orr r1, r1, #BG_CNT__CHAR_BASE_BLOCK(2)
orr r1, r1, #BG_CNT__SCREEN_BASE_BLOCK(30)
orr r1, r1, #BG_CNT__PRIORITY(0)
strh r1, [r0, #BG1CNT]
/* */
mov r0, #IO_REG
mov r1, #0x0
orr r1, r1, #DISPCNT__BG0
orr r1, r1, #DISPCNT__BG1
orr r1, r1, #DISPCNT__BG_MODE_0
strh r1, [r0, #DISPCNT]
.global int
int:
mov r9, #0 /* dx[1] */
mov r10, #0 /* dx[0] */
mov r11, #0 /* dy[0] */
mov r2, #1
/* enable int */
ldr r0, =#0x3007ffc
ldr r1, =sound_isr
str r1, [r0]
mov r0, #IO_REG
mov r1, #160
lsl r1, r1, #8
/*orr r1, r1, #DISPSTAT__V_COUNT_INT_ENABLE*/
orr r1, r1, #DISPSTAT__V_BLANK_INT_ENABLE
strh r1, [r0, #DISPSTAT]
mov r1, #0
/*orr r1, r1, #IE__RENDER_BLANK_V*/
/*orr r1, r1, #IE__V_COUNTER_MATCH*/
orr r1, r1, #IE__TIMER_1
mov r2, #IE
strh r1, [r0, r2]
mov r1, #(KEYCNT__ALL_KEYS + 1)
sub r1, r1, #1
orr r1, r1, #KEYCNT__INT_ENABLE
ldr r2, =#KEYCNT
strh r1, [r0, r2]
mov r1, #IME
mov r2, #IME__INT_MASTER_ENABLE
strh r2, [r0, r1]
mov r9, #16
strh r9, [r0, #BG0VOFS]
b sound
_stop:
b _stop
/* input ISR */
_input_isr:
mov r0, #IO_REG
mov r1, #KEY_INPUT
ldrh r2, [r0, r1]
mov r1, #1
ands r3, r2, r1, LSL #KEY_INPUT__RIGHT
addeq r10, r10, #1
ands r3, r2, r1, LSL #KEY_INPUT__LEFT
addeq r10, r10, #-1
ands r3, r2, r1, LSL #KEY_INPUT__UP
addeq r11, r11, #-1
ands r3, r2, r1, LSL #KEY_INPUT__DOWN
addeq r11, r11, #1
ands r3, r2, r1, LSL #KEY_INPUT__L
addeq r9, r9, #-1
ands r3, r2, r1, LSL #KEY_INPUT__R
addeq r9, r9, #1
strh r10, [r0, #BG1HOFS]
strh r11, [r0, #BG1VOFS]
strh r9, [r0, #BG0VOFS]
/* clear interrupt */
mov r1, #(IF - 2)
add r1, r1, #2
mov r2, #IE__V_BLANK
strh r2, [r0, r1]
bx lr