Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pret
GitHub Repository: pret/pokered
Path: blob/master/engine/pokemon/remove_mon.asm
1271 views
1
_RemovePokemon::
2
ld hl, wPartyCount
3
ld a, [wRemoveMonFromBox]
4
and a
5
jr z, .usePartyCount
6
ld hl, wBoxCount
7
.usePartyCount
8
ld a, [hl]
9
dec a
10
ld [hli], a
11
ld a, [wWhichPokemon]
12
ld c, a
13
ld b, $0
14
add hl, bc
15
ld e, l
16
ld d, h
17
inc de
18
.shiftMonSpeciesLoop
19
ld a, [de]
20
inc de
21
ld [hli], a
22
inc a ; reached terminator?
23
jr nz, .shiftMonSpeciesLoop ; if not, continue shifting species
24
ld hl, wPartyMonOT
25
ld d, PARTY_LENGTH - 1 ; max number of pokemon to shift
26
ld a, [wRemoveMonFromBox]
27
and a
28
jr z, .usePartyMonOTs
29
ld hl, wBoxMonOT
30
ld d, MONS_PER_BOX - 1
31
.usePartyMonOTs
32
ld a, [wWhichPokemon]
33
call SkipFixedLengthTextEntries
34
ld a, [wWhichPokemon]
35
cp d ; are we removing the last pokemon?
36
jr nz, .notRemovingLastMon ; if not, shift the pokemon below
37
ld [hl], $ff ; else, write the terminator and return
38
ret
39
.notRemovingLastMon
40
ld d, h
41
ld e, l
42
ld bc, NAME_LENGTH
43
add hl, bc
44
ld bc, wPartyMonNicks
45
ld a, [wRemoveMonFromBox]
46
and a
47
jr z, .usePartyMonNicks
48
ld bc, wBoxMonNicks
49
.usePartyMonNicks
50
call CopyDataUntil
51
ld hl, wPartyMons
52
ld bc, wPartyMon2 - wPartyMon1
53
ld a, [wRemoveMonFromBox]
54
and a
55
jr z, .usePartyMonStructs
56
ld hl, wBoxMons
57
ld bc, wBoxMon2 - wBoxMon1
58
.usePartyMonStructs
59
ld a, [wWhichPokemon]
60
call AddNTimes ; get address of the pokemon removed
61
ld d, h ; store in de for CopyDataUntil
62
ld e, l
63
ld a, [wRemoveMonFromBox]
64
and a
65
jr z, .copyUntilPartyMonOTs
66
ld bc, wBoxMon2 - wBoxMon1
67
add hl, bc ; get address of pokemon after the pokemon removed
68
ld bc, wBoxMonOT ; address of when to stop copying
69
jr .continue
70
.copyUntilPartyMonOTs
71
ld bc, wPartyMon2 - wPartyMon1
72
add hl, bc ; get address of pokemon after the pokemon removed
73
ld bc, wPartyMonOT ; address of when to stop copying
74
.continue
75
call CopyDataUntil ; shift all pokemon data after the removed mon to the removed mon's location
76
ld hl, wPartyMonNicks
77
ld a, [wRemoveMonFromBox]
78
and a
79
jr z, .usePartyMonNicks2
80
ld hl, wBoxMonNicks
81
.usePartyMonNicks2
82
ld bc, NAME_LENGTH
83
ld a, [wWhichPokemon]
84
call AddNTimes
85
ld d, h
86
ld e, l
87
ld bc, NAME_LENGTH
88
add hl, bc
89
ld bc, wPartyMonNicksEnd
90
ld a, [wRemoveMonFromBox]
91
and a
92
jr z, .copyUntilPartyMonNicksEnd
93
ld bc, wBoxMonNicksEnd
94
.copyUntilPartyMonNicksEnd
95
jp CopyDataUntil
96
97