-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvtetris-save.asm
251 lines (224 loc) · 4.83 KB
/
vtetris-save.asm
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
!CONST SKIP_INTRO, 0
!IF SKIP_INTRO
; skip printing auto-pause menu
!SEEK 0x099B2
?db 0x00, 0x00, 0x00, 0x00
!SEEK 0x099CE
?db 0x00, 0x00, 0x00, 0x00
!SEEK 0x099E8
?db 0x00, 0x00, 0x00, 0x00
; instruction manual and IPD
!SEEK 0x09E88
?db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
; skip auto-pause selection
!ORG 0xFFFA7726
!SEEK 0x27726
jr BPS_LOGO ; jal fff0a0e8, CHECK_INPUT
!ORG 0xFFFA7ABC
BPS_LOGO:
!ENDIF
; Read and/or init SRAM
!ORG 0xFFF89050
!SEEK 0x09050
jal CHECK_SRAM ; movea 0x4000, r0, r7
!ORG 0xFFF8908C
RESET_SCORES:
; Load initials from save
!ORG 0xFFF89C0A
!SEEK 0x09C0A
br SKIP_INITIALS
.NEXT_BYTE:
ld.w 0x0014[sp], r10
shl 2, r10
mov r10, r30
shl 1, r30
add r30, r10
ld.w 0x0018[sp], r11
add r11, r10
ld.w 0x0014[sp], r11
shl 3, r11
mov r11, r30
shl 1, r30
add r30, r11
ld.w 0x0018[sp], r12
shl 1, r12
add r12, r11
movhi 0x600, r11, r1
ld.b 0x0010[r1], r11
movhi 0x500, r10, r1
st.b r11, 0x2898[r1]
ld.w 0x0018[sp], r10
add 1, r10
st.w r10, 0x0018[sp]
ld.w 0x0018[sp], r10
cmp 3, r10
blt .NEXT_BYTE
!ORG 0xFFF89C4C
SKIP_INITIALS:
; Load scores from save
!SEEK 0x09C78
shl 3, r11
!ORG 0xFFF89C80
!SEEK 0x09C80
jr LOAD_SCORES
?db 0x00, 0x00, 0x00, 0x00
LOAD_SCORES_RETURN:
; Load levels from save
!SEEK 0x09CA0
shl 3, r11 ; only actually changing this
!SEEK 0x09CA8
movhi 0x600, r11, r1; this
ld.b 0x0020[r1], r11; and this
; Move initials down
!ORG 0xFFF8E3E8
!SEEK 0x0E3E8
jr MOVE_INITIALS ; st.b r11, 0x0000[r10]
MOVE_INITIALS_RETURN:
; Move score down
!ORG 0xFFF8E428
!SEEK 0xE428
jr MOVE_SCORE ; st.w r11, 0x0004[r10]
MOVE_SCORE_RETURN:
; Move level down
!ORG 0xFFF8E456
!SEEK 0x0E456
jr MOVE_LEVEL ; st.b r11, 0x0008[r10]
MOVE_LEVEL_RETURN:
; Write new initials
!ORG 0xFFF8EEC6
!SEEK 0x0EEC6
jr NEW_INITIALS ; st.b r11, 0x0000[r10]
NEW_INITIALS_RETURN:
; Write new score
!ORG 0xFFF8EEFE
!SEEK 0x0EEFE
jr NEW_SCORE ; st.w r11, 0x0004[r10]
NEW_SCORE_RETURN:
; Write new level
!ORG 0xFFF8EF56
!SEEK 0x0EF56
jr NEW_LEVEL ; st.b r11, 0x0008[r10]
NEW_LEVEL_RETURN:
; Erase SRAM if user presses L + R + Left Down + Right Down on the title screen
!ORG 0xFFFACD20
!SEEK 0x2CD20
jr ERASE_CHECK ; ld.h 0x001C[sp], r10
ERASE_CHECK_RETURN:
!ORG 0xFFFCF2D4
ROM_SCORES:
!ORG 0xFFF81624
!SEEK 0x01624
CHECKWORD:
?STRING "VTSV"
CHECK_SRAM:
?push r8, lp ; r1, r6 and r7 are free
jal VALIDATE_CHECKWORD
cmp 0, r6
be .CHECKWORD_OK
movhi 0x600, r0, r6
?mov ROM_SCORES, r1
movea 0x0168, r0, r8
.NEXT_SCORE_BYTE:
ld.b 0x0000[r1], r7
st.b r7, 0x0010[r6]
add 1, r1
add 2, r6
add -1, r8
bne .NEXT_SCORE_BYTE
.CHECKWORD_OK:
movea 0x4000, r0, r7 ; restored from original
?pop r8, lp
jmp [lp]
; Boilerplate SRAM functions
!CONST SRAM_CHECKWORD, 0
!INCLUDE "include/boot.asm"
LOAD_SCORES: ; r12 is free
movhi 0x600, r11, r1
ld.b 0x001E[r1], r11
shl 8, r11
ld.b 0x001C[r1], r12
andi 0xFF, r12, r12
or r12, r11
shl 8, r11
ld.b 0x001A[r1], r12
andi 0xFF, r12, r12
or r12, r11
shl 8, r11
ld.b 0x0018[r1], r12
andi 0xFF, r12, r12
or r12, r11
jr LOAD_SCORES_RETURN
MOVE_INITIALS:
?push lp
jal STORE_BYTE
?pop lp
st.b r11, 0x0010[r13]
st.b r11, 0x0000[r10]
jr MOVE_INITIALS_RETURN
MOVE_SCORE:
?push lp
jal STORE_WORD
?pop lp
jr MOVE_SCORE_RETURN
MOVE_LEVEL:
?push lp
jal STORE_BYTE
?pop lp
st.b r11, 0x0020[r13]
st.b r11, 0x0008[r10]
jr MOVE_LEVEL_RETURN
NEW_INITIALS:
?push lp
jal STORE_BYTE
?pop lp
st.b r11, 0x0010[r13]
st.b r11, 0x0000[r10]
jr NEW_INITIALS_RETURN
NEW_SCORE:
?push lp
jal STORE_WORD
?pop lp
jr NEW_SCORE_RETURN
NEW_LEVEL:
?push lp
jal STORE_BYTE
?pop lp
st.b r11, 0x0020[r13]
st.b r11, 0x0008[r10]
jr NEW_LEVEL_RETURN
STORE_BYTE:
andi 0x01FF, r10, r13
movea 0x98, r0, r14
sub r14, r13
shl 1, r13
movhi 0x600, r13, r13
jmp [lp]
STORE_WORD:
andi 0x01FF, r10, r13
movea 0x98, r0, r14
sub r14, r13
shl 1, r13
movhi 0x600, r13, r13
st.w r11, 0x0004[r10]
st.b r11, 0x0018[r13]
shr 8, r11
st.b r11, 0x001A[r13]
shr 8, r11
st.b r11, 0x001C[r13]
shr 8, r11
st.b r11, 0x001E[r13]
jmp [lp]
ERASE_CHECK:
?push r7
ld.h 0x0028[sp], r10
movea 0x8430, r0, r7
cmp r7, r10
bne .NO_ERASE
movhi 0x600, r0, r7
st.w r0, 0x0000[r7]
jal CHECK_SRAM
jal RESET_SCORES
.NO_ERASE:
?pop r7
ld.h 0x001C[sp], r10
jr ERASE_CHECK_RETURN