forked from gameboyadvancesp/understanding-pokemon-red
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathevolution.asm
160 lines (155 loc) · 2.73 KB
/
evolution.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
EvolveMon:
push hl
push de
push bc
ld a, [wcf91]
push af
ld a, [wd0b5]
push af
xor a
ld [wLowHealthAlarm], a
ld [wChannelSoundIDs + Ch5], a
dec a
ld [wNewSoundID], a
call PlaySound
ld a, $1
ld [H_AUTOBGTRANSFERENABLED], a
ld a, SFX_TINK
call PlaySound
call Delay3
xor a
ld [H_AUTOBGTRANSFERENABLED], a
ld [hTilesetType], a
ld a, [wEvoOldSpecies]
ld [wWholeScreenPaletteMonSpecies], a
ld c, 0
call EvolutionSetWholeScreenPalette
ld a, [wEvoNewSpecies]
ld [wcf91], a
ld [wd0b5], a
call Evolution_LoadPic
ld de, vFrontPic
ld hl, vBackPic
ld bc, 7 * 7
call CopyVideoData
ld a, [wEvoOldSpecies]
ld [wcf91], a
ld [wd0b5], a
call Evolution_LoadPic
ld a, $1
ld [H_AUTOBGTRANSFERENABLED], a
ld a, [wEvoOldSpecies]
call PlayCry
call WaitForSoundToFinish
ld c, BANK(Music_SafariZone)
ld a, MUSIC_SAFARI_ZONE
call PlayMusic
ld c, 80
call DelayFrames
ld c, 1 ; set PAL_BLACK instead of mon palette
call EvolutionSetWholeScreenPalette
lb bc, $1, $10
.animLoop
push bc
call Evolution_CheckForCancel
jr c, .evolutionCancelled
call Evolution_BackAndForthAnim
pop bc
inc b
dec c
dec c
jr nz, .animLoop
xor a
ld [wEvoCancelled], a
ld a, $31
ld [wEvoMonTileOffset], a
call Evolution_ChangeMonPic ; show the new species pic
ld a, [wEvoNewSpecies]
.done
ld [wWholeScreenPaletteMonSpecies], a
ld a, $ff
ld [wNewSoundID], a
call PlaySound
ld a, [wWholeScreenPaletteMonSpecies]
call PlayCry
ld c, 0
call EvolutionSetWholeScreenPalette
pop af
ld [wd0b5], a
pop af
ld [wcf91], a
pop bc
pop de
pop hl
ld a, [wEvoCancelled]
and a
ret z
scf
ret
.evolutionCancelled
pop bc
ld a, 1
ld [wEvoCancelled], a
ld a, [wEvoOldSpecies]
jr .done
EvolutionSetWholeScreenPalette:
ld b, SET_PAL_POKEMON_WHOLE_SCREEN
jp RunPaletteCommand
Evolution_LoadPic:
call GetMonHeader
coord hl, 7, 2
jp LoadFlippedFrontSpriteByMonIndex
Evolution_BackAndForthAnim:
; show the mon change back and forth between the new and old species b times
ld a, $31
ld [wEvoMonTileOffset], a
call Evolution_ChangeMonPic
ld a, -$31
ld [wEvoMonTileOffset], a
call Evolution_ChangeMonPic
dec b
jr nz, Evolution_BackAndForthAnim
ret
Evolution_ChangeMonPic:
push bc
xor a
ld [H_AUTOBGTRANSFERENABLED], a
coord hl, 7, 2
lb bc, 7, 7
ld de, SCREEN_WIDTH - 7
.loop
push bc
.innerLoop
ld a, [wEvoMonTileOffset]
add [hl]
ld [hli], a
dec c
jr nz, .innerLoop
pop bc
add hl, de
dec b
jr nz, .loop
ld a, 1
ld [H_AUTOBGTRANSFERENABLED], a
call Delay3
pop bc
ret
Evolution_CheckForCancel:
call DelayFrame
push bc
call JoypadLowSensitivity
ld a, [hJoy5]
pop bc
and B_BUTTON
jr nz, .pressedB
.notAllowedToCancel
dec c
jr nz, Evolution_CheckForCancel
and a
ret
.pressedB
ld a, [wForceEvolution]
and a
jr nz, .notAllowedToCancel
scf
ret