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
|
; initializes a screen animation from wTempAnimation
; loads a function pointer for updating a frame
; and initializes the duration of the animation.
InitScreenAnimation:
ld a, [wAnimationsDisabled]
or a
jr nz, .skip
ld a, [wTempAnimation]
ld [wd42a], a
sub DUEL_SCREEN_ANIMS
add a
add a
ld c, a
ld b, $00
ld hl, Data_1cc9f
add hl, bc
ld a, [hli]
ld [wScreenAnimUpdatePtr], a
ld c, a
ld a, [hli]
ld [wScreenAnimUpdatePtr + 1], a
ld b, a
ld a, [hl]
ld [wScreenAnimDuration], a
call CallBC
.skip
ret
; for the following animations, these functions
; are run with the corresponding duration.
; this duration decides different effects,
; depending on which function runs
; and is decreased by one each time.
; when it is down to 0, the animation is done.
screen_effect: MACRO
dw \1 ; function pointer
db \2 ; duration
db $00 ; padding
ENDM
Data_1cc9f:
; function pointer, duration
screen_effect ShakeScreenX_Small, 24 ; DUEL_ANIM_SMALL_SHAKE_X
screen_effect ShakeScreenX_Big, 32 ; DUEL_ANIM_BIG_SHAKE_X
screen_effect ShakeScreenY_Small, 24 ; DUEL_ANIM_SMALL_SHAKE_Y
screen_effect ShakeScreenY_Big, 32 ; DUEL_ANIM_BIG_SHAKE_Y
screen_effect WhiteFlashScreen, 8 ; DUEL_ANIM_FLASH
screen_effect DistortScreen, 63 ; DUEL_ANIM_DISTORT
; checks if screen animation duration is over
; and if so, loads the default update function
LoadDefaultScreenAnimationUpdateWhenFinished:
ld a, [wScreenAnimDuration]
or a
ret nz
; fallthrough
; function called for the screen animation update when it is over
DefaultScreenAnimationUpdate:
ld a, $ff
ld [wd42a], a
call DisableInt_LYCoincidence
xor a
ldh [hSCX], a
ldh [rSCX], a
ldh [hSCY], a
ld hl, wScreenAnimUpdatePtr
ld [hl], LOW(DefaultScreenAnimationUpdate)
inc hl
ld [hl], HIGH(DefaultScreenAnimationUpdate)
ret
; runs the screen update function set in wScreenAnimUpdatePtr
DoScreenAnimationUpdate:
ld a, 1
ld [wScreenAnimDuration], a
ld hl, wScreenAnimUpdatePtr
ld a, [hli]
ld h, [hl]
ld l, a
call CallHL2
jr DefaultScreenAnimationUpdate
ShakeScreenX_Small:
ld hl, SmallShakeOffsets
jr ShakeScreenX
ShakeScreenX_Big:
ld hl, BigShakeOffsets
jr ShakeScreenX
ShakeScreenX:
ld a, l
ld [wd4bc], a
ld a, h
ld [wd4bc + 1], a
ld hl, wScreenAnimUpdatePtr
ld [hl], LOW(.Update)
inc hl
ld [hl], HIGH(.Update)
ret
.Update
call DecrementScreenAnimDuration
call UpdateShakeOffset
jp nc, LoadDefaultScreenAnimationUpdateWhenFinished
ldh a, [hSCX]
add [hl]
ldh [hSCX], a
jp LoadDefaultScreenAnimationUpdateWhenFinished
ShakeScreenY_Small:
ld hl, SmallShakeOffsets
jr ShakeScreenY
ShakeScreenY_Big:
ld hl, BigShakeOffsets
jr ShakeScreenY
ShakeScreenY:
ld a, l
ld [wd4bc], a
ld a, h
ld [wd4bc + 1], a
ld hl, wScreenAnimUpdatePtr
ld [hl], LOW(.Update)
inc hl
ld [hl], HIGH(.Update)
ret
.Update
call DecrementScreenAnimDuration
call UpdateShakeOffset
jp nc, LoadDefaultScreenAnimationUpdateWhenFinished
ldh a, [hSCY]
add [hl]
ldh [hSCY], a
jp LoadDefaultScreenAnimationUpdateWhenFinished
; get the displacement of the current frame
; depending on the value of wScreenAnimDuration
; returns carry if displacement was updated
UpdateShakeOffset:
ld hl, wd4bc
ld a, [hli]
ld h, [hl]
ld l, a
ld a, [wScreenAnimDuration]
cp [hl]
ret nc
inc hl
push hl
inc hl
ld a, l
ld [wd4bc], a
ld a, h
ld [wd4bc + 1], a
pop hl
scf
ret
SmallShakeOffsets:
db 21, 2
db 17, -2
db 13, 2
db 9, -2
db 5, 1
db 1, -1
BigShakeOffsets:
db 29, 4
db 25, -4
db 21, 4
db 17, -4
db 13, 3
db 9, -3
db 5, 2
db 1, -2
DecrementScreenAnimDuration:
ld hl, wScreenAnimDuration
dec [hl]
ret
WhiteFlashScreen:
ld hl, wScreenAnimUpdatePtr
ld [hl], LOW(.Update)
inc hl
ld [hl], HIGH(.Update)
ld a, [wBGP]
ld [wd4bc], a
; backup the current background pals
ld hl, wBackgroundPalettesCGB
ld de, wTempBackgroundPalettesCGB
ld bc, 8 palettes
call CopyDataHLtoDE_SaveRegisters
ld de, PALRGB_WHITE
ld hl, wBackgroundPalettesCGB
ld bc, (8 palettes) / 2
call FillMemoryWithDE
xor a
call SetBGP
call FlushAllPalettes
.Update
call DecrementScreenAnimDuration
ld a, [wScreenAnimDuration]
or a
ret nz
; retrieve the previous background pals
ld hl, wTempBackgroundPalettesCGB
ld de, wBackgroundPalettesCGB
ld bc, 8 palettes
call CopyDataHLtoDE_SaveRegisters
ld a, [wd4bc]
call SetBGP
call FlushAllPalettes
jp DefaultScreenAnimationUpdate
DistortScreen:
ld hl, wScreenAnimUpdatePtr
ld [hl], LOW(.Update)
inc hl
ld [hl], HIGH(.Update)
xor a
ld [wApplyBGScroll], a
ld hl, wLCDCFunctionTrampoline + 1
ld [hl], LOW(ApplyBackgroundScroll)
inc hl
ld [hl], HIGH(ApplyBackgroundScroll)
ld a, 1
ld [wBGScrollMod], a
call EnableInt_LYCoincidence
.Update
ld a, [wScreenAnimDuration]
srl a
srl a
srl a
and %00000111
ld c, a
ld b, $00
ld hl, .BGScrollModData
add hl, bc
ld a, [hl]
ld [wBGScrollMod], a
call DecrementScreenAnimDuration
jp LoadDefaultScreenAnimationUpdateWhenFinished
; each value is applied for 8 "ticks" of wScreenAnimDuration
; starting from the last and running backwards
.BGScrollModData
db 4, 3, 2, 1, 1, 1, 1, 2
Func_1ce03:
cp DUEL_ANIM_158
jr z, .asm_1ce17
sub $96
add a
ld c, a
ld b, $00
ld hl, .pointer_table
add hl, bc
ld a, [hli]
ld h, [hl]
ld l, a
jp Func_3bb5
.asm_1ce17
ld a, [wDuelAnimDamage]
ld l, a
ld a, [wDuelAnimDamage + 1]
ld h, a
jp Func_3bb5
.pointer_table
dw Func_190f4 ; DUEL_ANIM_150
dw PrintDamageText ; DUEL_ANIM_PRINT_DAMAGE
dw UpdateMainSceneHUD ; DUEL_ANIM_UPDATE_HUD
dw Func_191a3 ; DUEL_ANIM_153
dw Func_191a3 ; DUEL_ANIM_154
dw Func_191a3 ; DUEL_ANIM_155
dw Func_191a3 ; DUEL_ANIM_156
dw Func_191a3 ; DUEL_ANIM_157
|