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
|
; clear [SOMETHING] - something relating to animations
Func_3ca0:
xor a
ld [wd5d7], a
; fallthrough
Func_3ca4:
ldh a, [hBankROM]
push af
ld a, BANK(Func_1296e)
call BankswitchROM
call Func_1296e
pop af
call BankswitchROM
ret
HandleAllSpriteAnimations:
ldh a, [hBankROM]
push af
ld a, BANK(_HandleAllSpriteAnimations)
call BankswitchROM
call _HandleAllSpriteAnimations
pop af
call BankswitchROM
ret
; hl - pointer to animation frame
; wd5d6 - bank of animation frame
DrawSpriteAnimationFrame:
ldh a, [hBankROM]
push af
ld a, [wd5d6]
call BankswitchROM
ld a, [wCurrSpriteXPos]
cp $f0
ld a, 0
jr c, .notNearRight
dec a
.notNearRight
ld [wCurrSpriteRightEdgeCheck], a
ld a, [wCurrSpriteYPos]
cp $f0
ld a, 0
jr c, .setBottomEdgeCheck
dec a
.setBottomEdgeCheck
ld [wCurrSpriteBottomEdgeCheck], a
ld a, [hli]
or a
jp z, .done
ld c, a
.loop
push bc
push hl
ld b, 0
bit 7, [hl]
jr z, .beginY
dec b
.beginY
ld a, [wCurrSpriteAttributes]
bit OAM_Y_FLIP, a
jr z, .unflippedY
ld a, [hl]
add 8 ; size of a tile
ld c, a
ld a, 0
adc b
ld b, a
ld a, [wCurrSpriteYPos]
sub c
ld e, a
ld a, [wCurrSpriteBottomEdgeCheck]
sbc b
jr .finishYPosition
.unflippedY
ld a, [wCurrSpriteYPos]
add [hl]
ld e, a
ld a, [wCurrSpriteBottomEdgeCheck]
adc b
.finishYPosition
or a
jr nz, .endCurrentIteration
inc hl
ld b, 0
bit 7, [hl]
jr z, .beginX
dec b
.beginX
ld a, [wCurrSpriteAttributes]
bit OAM_X_FLIP, a
jr z, .unflippedX
ld a, [hl]
add 8 ; size of a tile
ld c, a
ld a, 0
adc b
ld b, a
ld a, [wCurrSpriteXPos]
sub c
ld d, a
ld a, [wCurrSpriteRightEdgeCheck]
sbc b
jr .finishXPosition
.unflippedX
ld a, [wCurrSpriteXPos]
add [hl]
ld d, a
ld a, [wCurrSpriteRightEdgeCheck]
adc b
.finishXPosition
or a
jr nz, .endCurrentIteration
inc hl
ld a, [wCurrSpriteTileID]
add [hl]
ld c, a
inc hl
ld a, [wCurrSpriteAttributes]
add [hl]
and OAM_PALETTE | (1 << OAM_OBP_NUM)
ld b, a
ld a, [wCurrSpriteAttributes]
xor [hl]
and (1 << OAM_X_FLIP) | (1 << OAM_Y_FLIP) | (1 << OAM_PRIORITY)
or b
ld b, a
inc hl ; unnecessary
call SetOneObjectAttributes
.endCurrentIteration
pop hl
ld bc, 4 ; size of info for one sub tile
add hl, bc
pop bc
dec c
jr nz, .loop
.done
pop af
call BankswitchROM
ret
; Loads a pointer to the current animation frame into SPRITE_ANIM_FRAME_DATA_POINTER using
; the current frame's offset
; [wd4ca] - current frame offset
; wTempPointer* - Pointer to current Animation
GetAnimationFramePointer:
ldh a, [hBankROM]
push af
push hl
push hl
ld a, [wd4ca]
cp $ff
jr nz, .useLoadedOffset
ld de, SpriteNullAnimationPointer
xor a
jr .loadPointer
.useLoadedOffset
ld a, [wTempPointer]
ld l, a
ld a, [wTempPointer + 1]
ld h, a
ld a, [wTempPointerBank]
call BankswitchROM
ld a, [hli]
push af
ld a, [wd4ca]
rlca
ld e, [hl]
add e
ld e, a
inc hl
ld a, [hl]
adc 0
ld d, a
pop af
.loadPointer
add BANK(SpriteNullAnimationPointer)
pop hl
ld bc, SPRITE_ANIM_FRAME_BANK
add hl, bc
ld [hli], a
call BankswitchROM
ld a, [de]
ld [hli], a
inc de
ld a, [de]
ld [hl], a
pop hl
pop af
call BankswitchROM
ret
; return hl pointing to the start of a sprite in wSpriteAnimBuffer.
; the sprite is identified by its index in wWhichSprite.
GetFirstSpriteAnimBufferProperty:
push bc
ld c, SPRITE_ANIM_ENABLED
call GetSpriteAnimBufferProperty
pop bc
ret
; return hl pointing to the property (byte) c of a sprite in wSpriteAnimBuffer.
; the sprite is identified by its index in wWhichSprite.
GetSpriteAnimBufferProperty:
ld a, [wWhichSprite]
; fallthrough
GetSpriteAnimBufferProperty_SpriteInA:
cp SPRITE_ANIM_BUFFER_CAPACITY
jr c, .got_sprite
debug_nop
ld a, SPRITE_ANIM_BUFFER_CAPACITY - 1 ; default to last sprite
.got_sprite
push bc
swap a ; a *= SPRITE_ANIM_LENGTH
push af
and $f
ld b, a
pop af
and $f0
or c ; add the property offset
ld c, a
ld hl, wSpriteAnimBuffer
add hl, bc
pop bc
ret
Func_3ddb:
push hl
push bc
ld c, SPRITE_ANIM_FLAGS
call GetSpriteAnimBufferProperty_SpriteInA
res 2, [hl]
pop bc
pop hl
ret
Func_3de7:
push hl
push bc
ld c, SPRITE_ANIM_FLAGS
call GetSpriteAnimBufferProperty_SpriteInA
set 2, [hl]
pop bc
pop hl
ret
LoadScene:
push af
ldh a, [hBankROM]
push af
push hl
ld a, BANK(_LoadScene)
call BankswitchROM
ld hl, sp+$5
ld a, [hl]
call _LoadScene
call FlushAllPalettes
pop hl
pop af
call BankswitchROM
pop af
ld a, [wSceneSpriteIndex]
ret
; draws player's portrait at b,c
DrawPlayerPortrait:
ld a, $1
ld [wd61e], a
ld a, TILEMAP_PLAYER
; fallthrough
DrawPortrait:
ld [wCurTilemap], a
ldh a, [hBankROM]
push af
ld a, BANK(Func_12fc6)
call BankswitchROM
call Func_12fc6
pop af
call BankswitchROM
ret
; draws opponent's portrait given in a at b,c
DrawOpponentPortrait:
ld [wd61e], a
ld a, TILEMAP_OPPONENT
jr DrawPortrait
Func_3e31:
ldh a, [hBankROM]
push af
call HandleAllSpriteAnimations
ld a, BANK(DoLoadedFramesetSubgroupsFrame)
call BankswitchROM
call DoLoadedFramesetSubgroupsFrame
pop af
call BankswitchROM
ret
|