-
Notifications
You must be signed in to change notification settings - Fork 0
/
vert-j-save.asm
278 lines (255 loc) · 6.99 KB
/
vert-j-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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
!CONST SKIP_INTRO, 0
!CONST INVINCIBLE, 0
!IF SKIP_INTRO
!ORG 0x0700B33E
!SEEK 0x0B33E
movea 0x14, r0, r14
!ENDIF
!IF INVINCIBLE
; No damage for player
!SEEK 0x0F11C
mov r0, r0
; No damage for drone
!SEEK 0x0F14A
mov r0, r0
; No weapon downgrades
!SEEK 0x16D7C
mov r0, r0
; No collision damage
!SEEK 0x1878E
mov r0, r0
!ENDIF
!CONST RAM_SCORE, -0x610C
!CONST RAM_COUNTER, -0x6108
!CONST RAM_TIME, -0x60D8
!CONST RAM_DIFFICULTY, -0x60C2
!CONST RAM_CONTROLS, 0xC020
!CONST DEF_BRIGHT, 0xDC0C
; Check and (if necessary) init SRAM; load in brightness and scores
!ORG 0x070016D2
!SEEK 0x016D2
jal CHECK_SRAM ; jal 0701BF0C, brightness nuller
?db 0x00, 0x00, 0x00, 0x00 ; jal 0701BF1E, high score nuller
; Load the difficulty and control settings
!ORG 0x07007966
!SEEK 0x07966
jr LOAD_SETTINGS ; st.b r0, RAM_DIFFICULTY[gp]
jal SET_RIGHTY ; these both ...
movea RAM_CONTROLS, gp, r11 ; ... get skipped
LOAD_SETTINGS_RETURN:
st.b r7, 0x0018[r11]
!ORG 0x07007842
SET_RIGHTY:
!ORG 0x070078D0
SET_LEFTY:
; Save controls selected on the Config screen
!ORG 0x0700863A
!SEEK 0x0863A
jr SAVE_HAND ; st.b r12, 0x0018[r11]
SAVE_HAND_RETURN:
; Save difficulty selected on the Config screen
!ORG 0x07008A50
!SEEK 0x08A50
cmp 3, r10
bge INVALID_DIFFICULTY
br SAVE_DIFFICULTY
INVALID_DIFFICULTY:
mov 2, r10
SAVE_DIFFICULTY:
movhi 0x600, r0, r6
st.b r10, 0x0042[r6]
st.b r10, RAM_DIFFICULTY[gp]
br DIFFICULTY_SAVED
!ORG 0x07008A72
DIFFICULTY_SAVED:
; Write debug flag to protect saved high scores when in use
!ORG 0x0700B5B0
!SEEK 0x0B5B0
jr WRITE_DEBUG_FLAG ; jr SET_DEBUG_SCENE
!ORG 0x0700B776
SET_DEBUG_SCENE:
; Update high score/best time
!ORG 0x0700BC6E
!SEEK 0x0BC6E
; Setting up our read/write offsets based on current difficulty
ld.b -0x5001[gp], r10 ; debug mode
cmp 0, r10
bne END_SCORE_UPDATES
ld.b RAM_DIFFICULTY[gp], r10
cmp 3, r10 ; if beyond valid range, branch out
bge END_SCORE_UPDATES
shl 3, r10
movhi 0x600, r10, r16 ; save RAM, offset by difficulty
mov gp, r17
add r10, r17
; Check and write new score
ld.w RAM_SCORE[gp], r14 ; current score
ld.w -0x7FFC[r17], r15 ; best score, offset by difficulty
cmp r15, r14
ble END_SCORE_UPDATES
st.w r14, -0x7FFC[r17]
st.b r14, 0x0010[r16]
shr 8, r14
st.b r14, 0x0012[r16]
shr 8, r14
st.b r14, 0x0014[r16]
shr 8, r14
st.b r14, 0x0016[r16]
; Check and write new time
ld.w RAM_TIME[gp], r14 ; current time
cmp 0, r14
be END_SCORE_UPDATES
ld.w -0x7FF0[r17], r15 ; best time, offset by difficulty
cmp r15, r14
bge END_SCORE_UPDATES
st.w r14, -0x7FF0[r17]
st.b r14, 0x0028[r16]
shr 8, r14
st.b r14, 0x002A[r16]
shr 8, r14
st.b r14, 0x002C[r16]
shr 8, r14
st.b r14, 0x002E[r16]
br END_SCORE_UPDATES
!ORG 0x0700BD24
END_SCORE_UPDATES:
; Erase SRAM when L + R + Left Down + Right Down pressed on title screen
!ORG 0x0701C842
!SEEK 0x1C842
jr ERASE_SRAM ; ld.w RAM_COUNTER[gp], r12
ERASE_SRAM_RETURN:
!ORG 0x07FFFFF0
SOFT_RESET:
; Save brightness when increasing
!ORG 0x0701CF7A
!SEEK 0x1CF7A
jr BRIGHTNESS_UP ; ld.b 0x0000[r13], r17
!ORG 0x0701CF8A
BRIGHTNESS_UP_RETURN:
; Save brightness when decreasing
!ORG 0x0701CFF8
!SEEK 0x1CFF8
jr BRIGHTNESS_DOWN ; ld.b 0x0000[r17], r11
!ORG 0x0701D008
BRIGHTNESS_DOWN_RETURN:
!ORG 0x07021294 ; 0x07021294 looks good for Japan
!SEEK 0x21294
CHECKWORD:
?STRING "VFSV"
CHECK_SRAM:
movhi 0x501, r0, sp
?push lp
jal VALIDATE_CHECKWORD
cmp 0, r6
be .CHECKWORD_OK
movhi 0x600, r0, r6
movhi 0x704, r0, r7 ; initializing brightness
movea DEF_BRIGHT, r7, r7
ld.w 0x0000[r7], r7
st.b r7, 0x0008[r6]
shr 8, r7
st.b r7, 0x000A[r6]
shr 8, r7
st.b r7, 0x000C[r6]
shr 8, r7
st.b r7, 0x000E[r6]
movhi 0x113, r0, r7 ; initializing best times
movea 0xA87F, r7, r7 ; once for each difficulty
st.b r7, 0x0028[r6]
st.b r7, 0x0030[r6]
st.b r7, 0x0038[r6]
shr 8, r7
st.b r7, 0x002A[r6]
st.b r7, 0x0032[r6]
st.b r7, 0x003A[r6]
shr 8, r7
st.b r7, 0x002C[r6]
st.b r7, 0x0034[r6]
st.b r7, 0x003C[r6]
shr 8, r7
st.b r7, 0x002E[r6]
st.b r7, 0x0036[r6]
st.b r7, 0x003E[r6]
mov 1, r7 ; usa difficulty defaults to 0 (easy)
st.b r7, 0x003A[r6] ; japan defaults to 1 (normal)
.CHECKWORD_OK:
movhi 0x600, r0, r6 ; brightness
ld.b 0x0008[r6], r7
st.b r7, -0x8000[gp]
ld.b 0x000A[r6], r7
st.b r7, -0x7FFF[gp]
ld.b 0x000C[r6], r7
st.b r7, -0x7FFE[gp]
ld.b 0x000E[r6], r7
st.b r7, -0x7FFD[gp]
movea 0x0018, r0, r8
.NEXT_SCORE_BYTE:
ld.b 0x0010[r6], r7
st.b r7, -0x7FFC[gp]
add 1, gp
add 2, r6
add -1, r8
bne .NEXT_SCORE_BYTE
?pop lp
jmp [lp]
; Boilerplate SRAM functions
!CONST SRAM_CHECKWORD, 0
!INCLUDE "include/boot.asm"
LOAD_SETTINGS:
movhi 0x600, r0, r6
ld.b 0x0042[r6], r7 ; difficulty
st.b r7, RAM_DIFFICULTY[gp]
movea RAM_CONTROLS, gp, r11
ld.b 0x0040[r6], r7
cmp 1, r7
be START_LEFTY
jal SET_RIGHTY
jr LOAD_SETTINGS_RETURN
START_LEFTY:
jal SET_LEFTY
jr LOAD_SETTINGS_RETURN
SAVE_HAND:
st.b r12, 0x0018[r11]
movhi 0x600, r0, r10
st.b r12, 0x0040[r10]
jr SAVE_HAND_RETURN
WRITE_DEBUG_FLAG:
mov 1, r6
st.b r6, -0x5001[gp]
jr SET_DEBUG_SCENE
ERASE_SRAM:
st.b r0, -0x5001[gp] ; clear debug flag
ld.h 0x0000[r14], r9
movea 0x8432, r0, r12
cmp r9, r12
bne NO_ERASE
movhi 0x600, r0, r9
st.w r0, 0x0000[r9]
jal SOFT_RESET
NO_ERASE:
ld.w RAM_COUNTER[gp], r12 ; restored from original
jr ERASE_SRAM_RETURN
BRIGHTNESS_UP:
movhi 0x600, r0, r6
BRIGHTNESS_UP_NEXT:
ld.b 0x0000[r13], r17
add 1, r13
st.b r17, 0x0008[r6]
add 2, r6
st.b r17, 0x0000[r15]
add 1, r15
add -1, r16
bne BRIGHTNESS_UP_NEXT
jr BRIGHTNESS_UP_RETURN
BRIGHTNESS_DOWN: ; about to use r6 anyway
movhi 0x600, r0, r6
BRIGHTNESS_DOWN_NEXT:
ld.b 0x0000[r17], r11
add 1, r17
st.b r11, 0x0008[r6]
add 2, r6
st.b r11, 0x0000[r19]
add 1, r19
add -1, r10
bne BRIGHTNESS_DOWN_NEXT
jr BRIGHTNESS_DOWN_RETURN