Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pret
GitHub Repository: pret/pokered
Path: blob/master/engine/pokemon/remove_mon.asm
2018 views
1
_RemovePokemon::
2
ld hl, wPartyCount
3
ld a, [wRemoveMonFromBox]
4
and a
5
jr z, .gotCount
6
ld hl, wBoxCount
7
.gotCount
8
ld a, [hl]
9
dec a
10
ld [hli], a
11
12
ld a, [wWhichPokemon]
13
ld c, a
14
ld b, 0
15
add hl, bc
16
ld e, l
17
ld d, h
18
inc de
19
.shiftMonSpeciesLoop
20
ld a, [de]
21
inc de
22
ld [hli], a
23
inc a ; reached terminator?
24
jr nz, .shiftMonSpeciesLoop ; if not, continue shifting species
25
26
ld hl, wPartyMonOT
27
ld d, PARTY_LENGTH - 1 ; max number of pokemon to shift
28
ld a, [wRemoveMonFromBox]
29
and a
30
jr z, .gotOTsPointer
31
ld hl, wBoxMonOT
32
ld d, MONS_PER_BOX - 1
33
.gotOTsPointer
34
ld a, [wWhichPokemon]
35
call SkipFixedLengthTextEntries
36
ld a, [wWhichPokemon]
37
cp d ; are we removing the last pokemon?
38
jr nz, .notRemovingLastMon ; if not, shift the pokemon below
39
40
; bug: to erase a string, this should be ld [hl], '@'
41
; This is not needed, as wBoxSpecies/wPartySpecies determine if a slot is used.
42
; Besides, existing mon nick is left untouched
43
ld [hl], $ff
44
ret
45
46
.notRemovingLastMon
47
ld d, h
48
ld e, l
49
ld bc, NAME_LENGTH
50
add hl, bc
51
ld bc, wPartyMonNicks
52
ld a, [wRemoveMonFromBox]
53
and a
54
jr z, .gotNicksPointer
55
ld bc, wBoxMonNicks
56
.gotNicksPointer
57
call CopyDataUntil
58
59
ld hl, wPartyMons
60
ld bc, PARTYMON_STRUCT_LENGTH
61
ld a, [wRemoveMonFromBox]
62
and a
63
jr z, .gotMonStructs
64
ld hl, wBoxMons
65
ld bc, BOXMON_STRUCT_LENGTH
66
.gotMonStructs
67
ld a, [wWhichPokemon]
68
call AddNTimes ; get address of the pokemon removed
69
70
ld d, h ; de = start address for CopyDataUntil
71
ld e, l
72
ld a, [wRemoveMonFromBox]
73
and a
74
jr z, .copyUntilPartyMonOT
75
; copy until wBoxMonOT
76
ld bc, BOXMON_STRUCT_LENGTH
77
add hl, bc ; get address of next slot
78
ld bc, wBoxMonOT
79
jr .shiftOTs
80
.copyUntilPartyMonOT
81
ld bc, PARTYMON_STRUCT_LENGTH
82
add hl, bc ; get address of next slot
83
ld bc, wPartyMonOT
84
.shiftOTs
85
call CopyDataUntil ; shift all pokemon data up one slot
86
87
ld hl, wPartyMonNicks
88
ld a, [wRemoveMonFromBox]
89
and a
90
jr z, .gotNicksPointer2
91
ld hl, wBoxMonNicks
92
.gotNicksPointer2
93
ld bc, NAME_LENGTH
94
ld a, [wWhichPokemon]
95
call AddNTimes
96
97
ld d, h
98
ld e, l
99
ld bc, NAME_LENGTH
100
add hl, bc
101
ld bc, wPartyMonNicksEnd
102
ld a, [wRemoveMonFromBox]
103
and a
104
jr z, .shiftMonNicks
105
ld bc, wBoxMonNicksEnd
106
.shiftMonNicks
107
jp CopyDataUntil ; shift all pokemon nicknames up one slot
108
109