Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pret
GitHub Repository: pret/pokered
Path: blob/master/home/move_mon.asm
1270 views
1
; Copies [hl, bc) to [de, de + bc - hl).
2
; In other words, the source data is from hl up to but not including bc,
3
; and the destination is de.
4
CopyDataUntil::
5
ld a, [hli]
6
ld [de], a
7
inc de
8
ld a, h
9
cp b
10
jr nz, CopyDataUntil
11
ld a, l
12
cp c
13
jr nz, CopyDataUntil
14
ret
15
16
; Function to remove a pokemon from the party or the current box.
17
; wWhichPokemon determines the pokemon.
18
; [wRemoveMonFromBox] == 0 specifies the party.
19
; [wRemoveMonFromBox] != 0 specifies the current box.
20
RemovePokemon::
21
jpfar _RemovePokemon
22
23
AddPartyMon::
24
push hl
25
push de
26
push bc
27
farcall _AddPartyMon
28
pop bc
29
pop de
30
pop hl
31
ret
32
33
; calculates all 5 stats of current mon and writes them to [de]
34
CalcStats::
35
ld c, $0
36
.statsLoop
37
inc c
38
call CalcStat
39
ldh a, [hMultiplicand+1]
40
ld [de], a
41
inc de
42
ldh a, [hMultiplicand+2]
43
ld [de], a
44
inc de
45
ld a, c
46
cp NUM_STATS
47
jr nz, .statsLoop
48
ret
49
50
; calculates stat c of current mon
51
; c: stat to calc (HP=1,Atk=2,Def=3,Spd=4,Spc=5)
52
; b: consider stat exp?
53
; hl: base ptr to stat exp values ([hl + 2*c - 1] and [hl + 2*c])
54
CalcStat::
55
push hl
56
push de
57
push bc
58
ld a, b
59
ld d, a
60
push hl
61
ld hl, wMonHeader
62
ld b, $0
63
add hl, bc
64
ld a, [hl] ; read base value of stat
65
ld e, a
66
pop hl
67
push hl
68
sla c
69
ld a, d
70
and a
71
jr z, .statExpDone ; consider stat exp?
72
add hl, bc ; skip to corresponding stat exp value
73
.statExpLoop ; calculates ceil(Sqrt(stat exp)) in b
74
xor a
75
ldh [hMultiplicand], a
76
ldh [hMultiplicand+1], a
77
inc b ; increment current stat exp bonus
78
ld a, b
79
cp $ff
80
jr z, .statExpDone
81
ldh [hMultiplicand+2], a
82
ldh [hMultiplier], a
83
call Multiply
84
ld a, [hld]
85
ld d, a
86
ldh a, [hProduct + 3]
87
sub d
88
ld a, [hli]
89
ld d, a
90
ldh a, [hProduct + 2]
91
sbc d ; test if (current stat exp bonus)^2 < stat exp
92
jr c, .statExpLoop
93
.statExpDone
94
srl c
95
pop hl
96
push bc
97
ld bc, wPartyMon1DVs - (wPartyMon1HPExp - 1) ; also wEnemyMonDVs - wEnemyMonHP
98
add hl, bc
99
pop bc
100
ld a, c
101
cp $2
102
jr z, .getAttackIV
103
cp $3
104
jr z, .getDefenseIV
105
cp $4
106
jr z, .getSpeedIV
107
cp $5
108
jr z, .getSpecialIV
109
.getHpIV
110
push bc
111
ld a, [hl] ; Atk IV
112
swap a
113
and $1
114
sla a
115
sla a
116
sla a
117
ld b, a
118
ld a, [hli] ; Def IV
119
and $1
120
sla a
121
sla a
122
add b
123
ld b, a
124
ld a, [hl] ; Spd IV
125
swap a
126
and $1
127
sla a
128
add b
129
ld b, a
130
ld a, [hl] ; Spc IV
131
and $1
132
add b ; HP IV: LSB of the other 4 IVs
133
pop bc
134
jr .calcStatFromIV
135
.getAttackIV
136
ld a, [hl]
137
swap a
138
and $f
139
jr .calcStatFromIV
140
.getDefenseIV
141
ld a, [hl]
142
and $f
143
jr .calcStatFromIV
144
.getSpeedIV
145
inc hl
146
ld a, [hl]
147
swap a
148
and $f
149
jr .calcStatFromIV
150
.getSpecialIV
151
inc hl
152
ld a, [hl]
153
and $f
154
.calcStatFromIV
155
ld d, $0
156
add e
157
ld e, a
158
jr nc, .noCarry
159
inc d ; de = Base + IV
160
.noCarry
161
sla e
162
rl d ; de = (Base + IV) * 2
163
srl b
164
srl b ; b = ceil(Sqrt(stat exp)) / 4
165
ld a, b
166
add e
167
jr nc, .noCarry2
168
inc d ; de = (Base + IV) * 2 + ceil(Sqrt(stat exp)) / 4
169
.noCarry2
170
ldh [hMultiplicand+2], a
171
ld a, d
172
ldh [hMultiplicand+1], a
173
xor a
174
ldh [hMultiplicand], a
175
ld a, [wCurEnemyLevel]
176
ldh [hMultiplier], a
177
call Multiply ; ((Base + IV) * 2 + ceil(Sqrt(stat exp)) / 4) * Level
178
ldh a, [hMultiplicand]
179
ldh [hDividend], a
180
ldh a, [hMultiplicand+1]
181
ldh [hDividend+1], a
182
ldh a, [hMultiplicand+2]
183
ldh [hDividend+2], a
184
ld a, $64
185
ldh [hDivisor], a
186
ld a, $3
187
ld b, a
188
call Divide ; (((Base + IV) * 2 + ceil(Sqrt(stat exp)) / 4) * Level) / 100
189
ld a, c
190
cp $1
191
ld a, 5 ; + 5 for non-HP stat
192
jr nz, .notHPStat
193
ld a, [wCurEnemyLevel]
194
ld b, a
195
ldh a, [hMultiplicand+2]
196
add b
197
ldh [hMultiplicand+2], a
198
jr nc, .noCarry3
199
ldh a, [hMultiplicand+1]
200
inc a
201
ldh [hMultiplicand+1], a ; HP: (((Base + IV) * 2 + ceil(Sqrt(stat exp)) / 4) * Level) / 100 + Level
202
.noCarry3
203
ld a, 10 ; +10 for HP stat
204
.notHPStat
205
ld b, a
206
ldh a, [hMultiplicand+2]
207
add b
208
ldh [hMultiplicand+2], a
209
jr nc, .noCarry4
210
ldh a, [hMultiplicand+1]
211
inc a ; non-HP: (((Base + IV) * 2 + ceil(Sqrt(stat exp)) / 4) * Level) / 100 + 5
212
ldh [hMultiplicand+1], a ; HP: (((Base + IV) * 2 + ceil(Sqrt(stat exp)) / 4) * Level) / 100 + Level + 10
213
.noCarry4
214
ldh a, [hMultiplicand+1] ; check for overflow (>999)
215
cp HIGH(MAX_STAT_VALUE) + 1
216
jr nc, .overflow
217
cp HIGH(MAX_STAT_VALUE)
218
jr c, .noOverflow
219
ldh a, [hMultiplicand+2]
220
cp LOW(MAX_STAT_VALUE) + 1
221
jr c, .noOverflow
222
.overflow
223
ld a, HIGH(MAX_STAT_VALUE) ; overflow: cap at 999
224
ldh [hMultiplicand+1], a
225
ld a, LOW(MAX_STAT_VALUE)
226
ldh [hMultiplicand+2], a
227
.noOverflow
228
pop bc
229
pop de
230
pop hl
231
ret
232
233
AddEnemyMonToPlayerParty::
234
homecall_sf _AddEnemyMonToPlayerParty
235
ret
236
237
MoveMon::
238
homecall_sf _MoveMon
239
ret
240
241