-
Notifications
You must be signed in to change notification settings - Fork 801
/
correct_party_errors.asm
226 lines (207 loc) · 2.9 KB
/
correct_party_errors.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
216
217
218
219
220
221
222
223
224
225
226
CorrectPartyErrors: ; unreferenced
ld hl, wPartyCount
ld a, [hl]
and a
ret z
cp PARTY_LENGTH + 1
jr c, .party_length_okay
ld a, PARTY_LENGTH
ld [hl], a
.party_length_okay
inc hl
ld b, a
ld c, 0
.loop1
ld a, [hl]
and a
jr z, .invalid_species
cp NUM_POKEMON + 1
jr z, .invalid_species
cp EGG + 1
jr c, .next_species
.invalid_species
ld [hl], SMEARGLE
push hl
push bc
ld a, c
ld hl, wPartyMon1Species
call GetPartyLocation
ld [hl], SMEARGLE
pop bc
pop hl
.next_species
inc hl
inc c
dec b
jr nz, .loop1
ld [hl], $ff
ld hl, wPartyMon1
ld a, [wPartyCount]
ld d, a
ld e, 0
.loop2
push de
push hl
ld b, h
ld c, l
ld a, [hl]
and a
jr z, .invalid_species_2
cp NUM_POKEMON + 1
jr c, .check_level
.invalid_species_2
ld [hl], SMEARGLE
push de
ld d, 0
ld hl, wPartySpecies
add hl, de
pop de
ld a, SMEARGLE
ld [hl], a
.check_level
ld [wCurSpecies], a
call GetBaseData
ld hl, MON_LEVEL
add hl, bc
ld a, [hl]
cp MIN_LEVEL
ld a, MIN_LEVEL
jr c, .invalid_level
ld a, [hl]
cp MAX_LEVEL
jr c, .load_level
ld a, MAX_LEVEL
.invalid_level
ld [hl], a
.load_level
ld [wCurPartyLevel], a
ld hl, MON_MAXHP
add hl, bc
ld d, h
ld e, l
ld hl, MON_STAT_EXP - 1
add hl, bc
ld b, TRUE
predef CalcMonStats
pop hl
ld bc, PARTYMON_STRUCT_LENGTH
add hl, bc
pop de
inc e
dec d
jr nz, .loop2
ld de, wPartyMonNicknames
ld a, [wPartyCount]
ld b, a
ld c, 0
.loop3
push bc
call .GetLengthOfStringWith6CharCap
push de
farcall CheckStringForErrors
pop hl
pop bc
jr nc, .valid_nickname
push bc
push hl
ld hl, wPartySpecies
push bc
ld b, 0
add hl, bc
pop bc
ld a, [hl]
cp EGG
ld hl, .TAMAGO
jr z, .got_nickname
ld [wNamedObjectIndex], a
call GetPokemonName
ld hl, wStringBuffer1
.got_nickname
pop de
ld bc, MON_NAME_LENGTH
call CopyBytes
pop bc
.valid_nickname
inc c
dec b
jr nz, .loop3
ld de, wPartyMonOTs
ld a, [wPartyCount]
ld b, a
ld c, 0
.loop4
push bc
call .GetLengthOfStringWith6CharCap
push de
farcall CheckStringForErrors
pop hl
jr nc, .valid_ot_name
ld d, h
ld e, l
ld hl, wPlayerName
ld bc, NAME_LENGTH
call CopyBytes
.valid_ot_name
pop bc
inc c
dec b
jr nz, .loop4
ld hl, wPartyMon1Moves
ld a, [wPartyCount]
ld b, a
.loop5
push hl
ld c, NUM_MOVES
ld a, [hl]
and a
jr z, .invalid_move
cp NUM_ATTACKS + 1
jr c, .moves_loop
.invalid_move
ld [hl], POUND
.moves_loop
ld a, [hl]
and a
jr z, .fill_invalid_moves
cp NUM_ATTACKS + 1
jr c, .next_move
.fill_invalid_moves
xor a
ld [hli], a
dec c
jr nz, .fill_invalid_moves
jr .next_pokemon
.next_move
inc hl
dec c
jr nz, .moves_loop
.next_pokemon
pop hl
push bc
ld bc, PARTYMON_STRUCT_LENGTH
add hl, bc
pop bc
dec b
jr nz, .loop5
ret
.TAMAGO:
db "タマゴ@@@"
.GetLengthOfStringWith6CharCap:
push de
ld c, 1
ld b, NAME_LENGTH_JAPANESE
.search_loop
ld a, [de]
cp "@"
jr z, .done
inc de
inc c
dec b
jr nz, .search_loop
dec c
dec de
ld a, "@"
ld [de], a
.done
pop de
ret