-
Notifications
You must be signed in to change notification settings - Fork 59
/
home.asm
215 lines (174 loc) · 4.71 KB
/
home.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
SECTION "NULL", ROM0
NULL::
INCLUDE "home/header.asm"
SECTION "High Home", ROM0
INCLUDE "home/lcd.asm"
INCLUDE "home/clear_sprites.asm"
INCLUDE "home/copy.asm"
SECTION "ColorizationHome", ROM0
InitializeColor:
cp $11
jr nz, .IsNotGBC
call _InitGbcMode
jp _Start
.IsNotGBC
jpfar RunDmgError
; Indirect function callers for color code
_InitGbcMode:
jpfar InitGbcMode
; Called once for each sprite. This needs to preserve variables, so it can't use
; BankSwitch.
_ColorOverworldSprite::
ldh [hColorHackTmp], a ; Need to preserve value of 'a'
ldh a, [hLoadedROMBank]
push af
ld a, BANK(ColorOverworldSprite)
call SetRomBank
ldh a, [hColorHackTmp]
call ColorOverworldSprite
ldh [hColorHackTmp], a
pop af
call SetRomBank
ldh a, [hColorHackTmp]
ret
; Soft reset code (clears memory then goes to normal code)
SoftReset::
CALL_INDIRECT ClearGbcMemory
jp SoftReset_orig
SECTION "Home", ROM0
INCLUDE "home/start.asm"
INCLUDE "home/joypad.asm"
INCLUDE "data/maps/map_header_pointers.asm"
INCLUDE "home/overworld.asm"
INCLUDE "home/pokemon.asm"
INCLUDE "home/print_bcd.asm"
INCLUDE "home/pics.asm"
INCLUDE "data/tilesets/collision_tile_ids.asm"
INCLUDE "home/copy2.asm"
INCLUDE "home/text.asm"
INCLUDE "home/vcopy.asm"
INCLUDE "home/init.asm"
INCLUDE "home/vblank.asm"
INCLUDE "home/fade.asm"
INCLUDE "home/serial.asm"
INCLUDE "home/timer.asm"
INCLUDE "home/audio.asm"
INCLUDE "home/update_sprites.asm"
INCLUDE "data/items/marts.asm"
INCLUDE "home/overworld_text.asm"
INCLUDE "home/uncompress.asm"
INCLUDE "home/reset_player_sprite.asm"
INCLUDE "home/text_script.asm"
INCLUDE "home/start_menu.asm"
INCLUDE "home/count_set_bits.asm"
INCLUDE "home/inventory.asm"
INCLUDE "home/list_menu.asm"
INCLUDE "home/names.asm"
INCLUDE "home/reload_tiles.asm"
INCLUDE "home/item.asm"
INCLUDE "home/textbox.asm"
INCLUDE "home/npc_movement.asm"
INCLUDE "home/trainers.asm"
INCLUDE "home/map_objects.asm"
INCLUDE "home/trainers2.asm"
INCLUDE "home/money.asm"
INCLUDE "home/bankswitch.asm"
INCLUDE "home/yes_no.asm"
INCLUDE "home/pathfinding.asm"
INCLUDE "home/load_font.asm"
INCLUDE "home/tilemap.asm"
INCLUDE "home/delay.asm"
INCLUDE "home/names2.asm"
INCLUDE "home/item_price.asm"
INCLUDE "home/copy_string.asm"
INCLUDE "home/joypad2.asm"
INCLUDE "home/math.asm"
INCLUDE "home/print_text.asm"
INCLUDE "home/move_mon.asm"
INCLUDE "home/array.asm"
INCLUDE "home/compare.asm"
INCLUDE "home/oam.asm"
INCLUDE "home/window.asm"
INCLUDE "home/print_num.asm"
INCLUDE "home/array2.asm"
INCLUDE "home/palettes.asm"
INCLUDE "home/reload_sprites.asm"
INCLUDE "home/give.asm"
INCLUDE "home/random.asm"
INCLUDE "home/predef.asm"
INCLUDE "home/hidden_objects.asm"
INCLUDE "home/predef_text.asm"
; Note: this saves rSVBK before calling an interrupt. It would also make sense to save
; rVBK. However, doing that would break the code that fixes the ss anne's palettes on
; departure. Instead, just be careful not to set the vram bank to 1 while interrupts are
; enabled...? (Or better yet do the ss anne fix properly...)
InterruptWrapper:
push af
push bc
push de
ldh a, [rSVBK]
ld b, a
ldh a, [hLoadedROMBank]
ld c, a
; Change ROM bank if an interrupt occurred in the middle of DelayFrameHook
ldh a, [hDelayFrameHookBank]
and a
jr z, .notInDelayFrame
; Change rom bank
dec a
call SetRomBank
.notInDelayFrame
xor a
ldh [rSVBK], a
ld de, .ret
push de
jp hl
.ret
ld a, b
ldh [rSVBK], a
ld a, c
call SetRomBank
pop de
pop bc
pop af
pop hl
reti
; Whenever DelayFrame is called, update the sprites.
; This is done here instead of at vblank to prevent sprite wobbliness when scrolling.
; In some situations, DelayFrame is not called every frame, and this could be problematic.
; But I think when sprites are being animated or moved around, it is always called.
DelayFrameHook:
push bc
push de
push hl
ldh a, [rSVBK]
ld b, a
xor a
ldh [rSVBK], a
push bc ; Save wram bank
; Save the current rom bank to a variable. This is important because the game does
; not expect the "DelayFrame" function to change the rom bank. If an interrupt
; occurs in the middle of this hook, the interrupt wrapper will know to restore
; the rom bank.
; An alternative solution would be to use "di/ei", but that was the cause of
; graphical corruption in the pokemart when getting oak's parcel.
ldh a, [hLoadedROMBank]
inc a
ldh [hDelayFrameHookBank], a
; Calling "PrepareOAMData" here instead of at vblank to prevent sprite wobbliness
CALL_INDIRECT PrepareOAMData
jr z, .spritesDrawn
CALL_INDIRECT ColorNonOverworldSprites
.spritesDrawn
; Clear hDelayFrameHookBank. (No need to reload the bank; that's done
; automatically by CALL_INDIRECT.)
xor a
ldh [hDelayFrameHookBank], a
pop af
ldh [rSVBK], a ; Restore wram bank
ld a, 1
ldh [hVBlankOccurred], a
pop hl
pop de
pop bc
ret