-
Notifications
You must be signed in to change notification settings - Fork 2
/
animalhack.asm
351 lines (283 loc) · 9.21 KB
/
animalhack.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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
; Written for tniasm 0.45
incbin "../Animal Land (1987) (Enix) (J).rom"
ds $20000, $ff ; expand ROM to 256 KB
cpu z80
include "multibank.sym"
; Set up banks at program start
forg $00084
org $6084, $6086
call SetUpBanks ; Replaces ld ($6000), a
; Use the free space at the end of the $6000-7fff bank to set up banks
forg $01f90
org $7f90, $7fff
SetUpBanks:
ld ($6000), a
ld a, $11 ; Put the $22000-$23fff bank into $a000-bfff
ld ($7800), a
ld ($f2dd), a ; Tell game to restore $8000-bfff to bank $11
; after temporarily switching banks in the intro
ret
; Replace the original game's password table with ours
forg $0044d
org $644d, $648a
include "passwords.out.inc"
forg $00378
org $6378, $637b
jp HandlePasswordChar
nop
; Code that switches banks
; This code is sensitive! It can be jumped into at multiple places,
; and the script will overwrite several pointers. We must take care not
; to change anything but pointers and bank numbers.
forg $02bb8
org $4bb8, $4c31
; Chapter 1
xor a
ld h, $10 ; bank number
ld de, 0 ; command table pointer
; (will be overwritten by script)
; (file offset for this operand is $02bbc)
ld bc, $8000 ; text pointer
call $4c3a
jp $68a0
; Chapter 2
xor a
ld h, $12
ld de, 0 ; $02bcb (file offset for this operand)
ld bc, $8000
call $4c3a
jp $6f30
; Chapter 3
ld a, 3
ld h, $14
ld de, 0 ; $02bdb
ld bc, $8000
call $4c3a
jp $6000
; Chapter 4
ld a, 1
ld h, $16
ld de, 0 ; $02beb
ld bc, $8000
call $4c3a
jp $7640
; Chapter 5
ld a, 2
ld h, $18
ld de, 0 ; $02bfb
ld bc, $8000
call $4c3a
jp $7800
; Chapter 6
ld a, 3
ld h, $1a
ld de, 0 ; $02c0b
ld bc, $8000
call $4c3a
jp $6b20
; Chapter 7
xor a
ld h, $1c
ld de, 0 ; $02c1a
ld bc, $8000
call $4c3a
jp $7840
; Ending
ld a, $0f
ld h, $1e
ld bc, $8000
call $4c3a
jp $7970
; Set pixel_offset to 0 before printing "What's the file's name, boss?"
forg $002ef
org $62ef, $62f1
call ClearPixelOffsetAndPrintString
; Clear password dialogue when printing "No such file, boss."
forg $00434
org $6434, $6436
call ClearPasswordDialogueAndPrintString
; Clear password dialogue when printing "OK, let's go."
forg $0043f
org $643f, $6441
call ClearPasswordDialogueAndPrintString
; Set pixel_offset to 0 before printing "Password:"
forg $00302
org $6302, $6304
call ClearPixelOffsetAndPrintString
; Replace the code that displays prompts ("What to do?" etc.)
forg $029a2
org $49a2, $49a4
jp DisplayPrompt
; This code originally called PrintChar (where PrintChar8 is now) and bumped the VRAM pointer in the dialogue routine
forg $028b7
org $48b7, $48bf
call PrintChar64
nop ; push bc
nop ; ld bc, 64
nop
nop
nop ; add hl, bc
nop ; pop bc
; Prints "PRESS SPACE" (formerly "PUSH SPACE KEY !")
forg $02a56
org $4a56, $4a6a
xor a
ld (pixel_offset), a
ld hl, $13b8 ; VRAM address
ld de, PressSpace
ld b, PressSpaceLen
.loop:
ld a, (de)
call PrintChar64
inc de
djnz .loop
jr $4a6b
; The "PRESS SPACE" string, unencoded
forg $02aa4
org $4aa4, $4ab3
PressSpace:
db $82, $83, $84, $85, $86
PressSpaceLen: equ $ - PressSpace
; Splash screen text
forg $000b3
org $60b3, $60b5
ld hl, SplashScreenText
; The code that prints the title screen text ("START", "CONTINUE", copyright notice)
forg $0020e
org $620e, $6227
jp PrintTitleScreenText
; Removes the VRAM bump in title screen code
forg $002a7
org $62a7, $62ab
call $4018
jr $62a2
; @TODO@ -- look for more instances of "call/jp $47ba/$4018" ($4018 jumps to $47ba)
; This erases the "PUSH SPACE KEY !" message.
; The original routine just wrote over it with spaces. No good with our VWF.
forg $02a7e
org $4a7e, $4a80
jp ErasePushSpaceKey
; Since we use colon instead of Japanese open-quote for dialogue tags now
; This code is used to scan the list of dialogue tags
forg $025cc
org $45cc, $45cd
cp CHAR_BOLD_COLON
; Hook for first line of dialogue
forg $0275d
org $475d, $47ef
call HandleFirstLineOfDialogue
; Hook for newlines in main script
forg $02771
org $4771, $477a
jp HandleNewline
; Draws the command menu ("1. TABLE", etc.)
; This is partially rewritten from the original game
forg $0291f
org $491f, $4980
DrawCmdMenu:
ld hl, $0600 ; VRAM address
ld iy, $f302
ld d, 1 ; Digit to display (e.g. the '1' in "1. TABLE")
.draw_menu_item:
ld a, 3
ld (pixel_offset), a
ld a, (iy+0)
inc iy
ld ix, ($f2f6) ; Load IX with addr of char in the script
or a
jr z, .first_menu_item ; Skip next line if already pointing to the first menu item
call $4b11 ; Adjust text pointer to Nth menu item
.first_menu_item:
ld a, $6b ; Set text color to orange
ld (text_color), a
ld a, d ; Number of menu item (in screen encoding)
call PrintChar8 ; Display it
ld a, CHAR_BOLD_PERIOD
call PrintChar8
ld bc, 8 ; Need to align text so first letter starts on third tile
add hl, bc ; (if we don't, colors will be wrong)
xor a
ld (pixel_offset), a
push hl
call DrawMenuLetters
pop hl ; HL now points to after the '.' in VRAM
ld bc, $70 ; Bump VRAM to start of next menu item
add hl, bc
xor a
ld (pixel_offset), a
inc d
ld a, 5 ; Need to adjust VRAM addr after drawing 4th item
cp d
jr nz, .dont_adjust
ld hl, $0e00
.dont_adjust:
ld a, (iy+00) ; Is this the last menu entry?
cp $ff
jr nz, .draw_menu_item ; Nope
jp $4981
; This tells the name tag routine to check for a colon, not a Japanese open-quote mark, as the end-of-nametag marker
forg $2795
org $4795, $4796
cp CHAR_BOLD_COLON
forg $02792
org $4792, $4794
jp DisplayNameTag
; This is where the original game's PrintChar routine was. We'll just hook it to PrintChar8
forg $027ba
org $47ba, $4846
jp PrintChar8
; This is our hook for linewrapping
; This is at the start of the original FetchAndPrintChar
forg $025e7
org $45e7
call FetchCharWithLinewrapping
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Graphics
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Animal Land Police Department
forg $0b8ef
org $98ef, $a0dd
db 1
incbin "gfx/alpd-e.comp.1.bin"
db 1
incbin "gfx/alpd.comp.2.bin"
db 1
incbin "gfx/alpd.comp.3.bin"
db 1
incbin "gfx/alpd.comp.4.bin"
incbin "gfx/alpd.map"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Banks
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Chapter 1
forg $20000 + MULTIBANK_OFFSET
org $a000, $bfff
incbin "multibank.out"
; Chapter 2
forg $24000 + MULTIBANK_OFFSET
org $a000, $bfff
incbin "multibank.out"
; Chapter 3
forg $28000 + MULTIBANK_OFFSET
org $a000, $bfff
incbin "multibank.out"
; Chapter 4
forg $2c000 + MULTIBANK_OFFSET
org $a000, $bfff
incbin "multibank.out"
; Chapter 5
forg $30000 + MULTIBANK_OFFSET
org $a000, $bfff
incbin "multibank.out"
; Chapter 6
forg $34000 + MULTIBANK_OFFSET
org $a000, $bfff
incbin "multibank.out"
; Chapter 7
forg $38000 + MULTIBANK_OFFSET
org $a000, $bfff
incbin "multibank.out"
; Ending
forg $3c000 + MULTIBANK_OFFSET
org $a000, $bfff
incbin "multibank.out"