summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorluckytyphlosion <alan.rj.huang@gmail.com>2015-11-13 15:24:43 -0500
committerluckytyphlosion <alan.rj.huang@gmail.com>2015-11-13 15:24:43 -0500
commitb683526d7041fccf8d6c74090e814e4b47698890 (patch)
tree11af29339ea0b4007eec496394721fabfa03f3a3
parentc71faf165981fd39e14810604894f894bc00b803 (diff)
_RemovePokemon and _DisplayPokedex
-rwxr-xr-xmain.asm70
-rwxr-xr-xwram.asm5
-rwxr-xr-xyellow/main.asm117
3 files changed, 151 insertions, 41 deletions
diff --git a/main.asm b/main.asm
index 13a6292b..2ecf5f63 100755
--- a/main.asm
+++ b/main.asm
@@ -1875,13 +1875,13 @@ INCLUDE "engine/battle/moveEffects/drain_hp_effect.asm"
INCLUDE "engine/menu/players_pc.asm"
-_RemovePokemon: ; 7b68 (1:7b68)
+_RemovePokemon: ; 7a0f (1:7a0f)
ld hl, wPartyCount
ld a, [wRemoveMonFromBox]
and a
- jr z, .asm_7b74
+ jr z, .usePartyCount
ld hl, wNumInBox
-.asm_7b74
+.usePartyCount
ld a, [hl]
dec a
ld [hli], a
@@ -1892,28 +1892,28 @@ _RemovePokemon: ; 7b68 (1:7b68)
ld e, l
ld d, h
inc de
-.asm_7b81
+.shiftMonSpeciesLoop
ld a, [de]
inc de
ld [hli], a
- inc a
- jr nz, .asm_7b81
+ inc a ; reached terminator?
+ jr nz, .shiftMonSpeciesLoop ; if not, continue shifting species
ld hl, wPartyMonOT
- ld d, $5
+ ld d, PARTY_LENGTH - 1 ; max number of pokemon to shift
ld a, [wRemoveMonFromBox]
and a
- jr z, .asm_7b97
+ jr z, .usePartyMonOTs
ld hl, wBoxMonOT
- ld d, $13
-.asm_7b97
+ ld d, MONS_PER_BOX - 1
+.usePartyMonOTs
ld a, [wWhichPokemon]
call SkipFixedLengthTextEntries
ld a, [wWhichPokemon]
- cp d
- jr nz, .asm_7ba6
- ld [hl], $ff
+ cp d ; are we removing the last pokemon?
+ jr nz, .notRemovingLastMon ; if not, shift the pokemon below
+ ld [hl], $ff ; else, write the terminator and return
ret
-.asm_7ba6
+.notRemovingLastMon
ld d, h
ld e, l
ld bc, NAME_LENGTH
@@ -1921,41 +1921,41 @@ _RemovePokemon: ; 7b68 (1:7b68)
ld bc, wPartyMonNicks
ld a, [wRemoveMonFromBox]
and a
- jr z, .asm_7bb8
+ jr z, .usePartyMonNicks
ld bc, wBoxMonNicks
-.asm_7bb8
+.usePartyMonNicks
call CopyDataUntil
ld hl, wPartyMons
ld bc, wPartyMon2 - wPartyMon1
ld a, [wRemoveMonFromBox]
and a
- jr z, .asm_7bcd
+ jr z, .usePartyMonStructs
ld hl, wBoxMons
ld bc, wBoxMon2 - wBoxMon1
-.asm_7bcd
+.usePartyMonStructs
ld a, [wWhichPokemon]
- call AddNTimes
- ld d, h
+ call AddNTimes ; get address of the pokemon removed
+ ld d, h ; store in de for CopyDataUntil
ld e, l
ld a, [wRemoveMonFromBox]
and a
- jr z, .asm_7be4
+ jr z, .copyUntilPartyMonOTs
ld bc, wBoxMon2 - wBoxMon1
- add hl, bc
- ld bc, wBoxMonOT
- jr .asm_7beb
-.asm_7be4
+ add hl, bc ; get address of pokemon after the pokemon removed
+ ld bc, wBoxMonOT ; address of when to stop copying
+ jr .continue
+.copyUntilPartyMonOTs
ld bc, wPartyMon2 - wPartyMon1
- add hl, bc
- ld bc, wPartyMonOT
-.asm_7beb
- call CopyDataUntil
+ add hl, bc ; get address of pokemon after the pokemon removed
+ ld bc, wPartyMonOT ; address of when to stop copying
+.continue
+ call CopyDataUntil ; shift all pokemon data after the removed mon to the removed mon's location
ld hl, wPartyMonNicks
ld a, [wRemoveMonFromBox]
and a
- jr z, .asm_7bfa
+ jr z, .usePartyMonNicks2
ld hl, wBoxMonNicks
-.asm_7bfa
+.usePartyMonNicks2
ld bc, NAME_LENGTH
ld a, [wWhichPokemon]
call AddNTimes
@@ -1963,15 +1963,15 @@ _RemovePokemon: ; 7b68 (1:7b68)
ld e, l
ld bc, NAME_LENGTH
add hl, bc
- ld bc, wPokedexOwned
+ ld bc, wPartyMonNicksEnd
ld a, [wRemoveMonFromBox]
and a
- jr z, .asm_7c15
+ jr z, .copyUntilPartyMonNicksEnd
ld bc, wBoxMonNicksEnd
-.asm_7c15
+.copyUntilPartyMonNicksEnd
jp CopyDataUntil
-_DisplayPokedex: ; 7c18 (1:7c18)
+_DisplayPokedex: ; 7abf (1:7abf)
ld hl, wd730
set 6, [hl]
predef ShowPokedexData
diff --git a/wram.asm b/wram.asm
index 4015f894..ebcc559b 100755
--- a/wram.asm
+++ b/wram.asm
@@ -423,9 +423,7 @@ wUnknownSerialCounter:: ; cc47
; 2 bytes
wEnteringCableClub:: ; cc47
- ds 1
-wcc48:: ; cc48
- ds 1
+ ds 2
wWhichTradeMonSelectionMenu:: ; cc49
; $00 = player mons
@@ -2256,6 +2254,7 @@ wPartyMon6:: party_struct wPartyMon6 ; d247
wPartyMonOT:: ds NAME_LENGTH * PARTY_LENGTH ; d273
wPartyMonNicks:: ds NAME_LENGTH * PARTY_LENGTH ; d2b5
+wPartyMonNicksEnd::
wPartyDataEnd::
diff --git a/yellow/main.asm b/yellow/main.asm
index 50d56a7e..e7a0e8a4 100755
--- a/yellow/main.asm
+++ b/yellow/main.asm
@@ -1095,9 +1095,120 @@ INCLUDE "engine/battle/moveEffects/drain_hp_effect.asm"
INCLUDE "engine/menu/players_pc.asm"
_RemovePokemon: ; 7a0f (1:7a0f)
- dr $7a0f,$7abf
-_DisplayPokedex: ; 7c18 (1:7abf)
- dr $7abf,$8000
+ ld hl, wPartyCount
+ ld a, [wRemoveMonFromBox]
+ and a
+ jr z, .usePartyCount
+ ld hl, wNumInBox
+.usePartyCount
+ ld a, [hl]
+ dec a
+ ld [hli], a
+ ld a, [wWhichPokemon]
+ ld c, a
+ ld b, $0
+ add hl, bc
+ ld e, l
+ ld d, h
+ inc de
+.shiftMonSpeciesLoop
+ ld a, [de]
+ inc de
+ ld [hli], a
+ inc a ; reached terminator?
+ jr nz, .shiftMonSpeciesLoop ; if not, continue shifting species
+ ld hl, wPartyMonOT
+ ld d, PARTY_LENGTH - 1 ; max number of pokemon to shift
+ ld a, [wRemoveMonFromBox]
+ and a
+ jr z, .usePartyMonOTs
+ ld hl, wBoxMonOT
+ ld d, MONS_PER_BOX - 1
+.usePartyMonOTs
+ ld a, [wWhichPokemon]
+ call SkipFixedLengthTextEntries
+ ld a, [wWhichPokemon]
+ cp d ; are we removing the last pokemon?
+ jr nz, .notRemovingLastMon ; if not, shift the pokemon below
+ ld [hl], $ff ; else, write the terminator and return
+ ret
+.notRemovingLastMon
+ ld d, h
+ ld e, l
+ ld bc, NAME_LENGTH
+ add hl, bc
+ ld bc, wPartyMonNicks
+ ld a, [wRemoveMonFromBox]
+ and a
+ jr z, .usePartyMonNicks
+ ld bc, wBoxMonNicks
+.usePartyMonNicks
+ call CopyDataUntil
+ ld hl, wPartyMons
+ ld bc, wPartyMon2 - wPartyMon1
+ ld a, [wRemoveMonFromBox]
+ and a
+ jr z, .usePartyMonStructs
+ ld hl, wBoxMons
+ ld bc, wBoxMon2 - wBoxMon1
+.usePartyMonStructs
+ ld a, [wWhichPokemon]
+ call AddNTimes ; get address of the pokemon removed
+ ld d, h ; store in de for CopyDataUntil
+ ld e, l
+ ld a, [wRemoveMonFromBox]
+ and a
+ jr z, .copyUntilPartyMonOTs
+ ld bc, wBoxMon2 - wBoxMon1
+ add hl, bc ; get address of pokemon after the pokemon removed
+ ld bc, wBoxMonOT ; address of when to stop copying
+ jr .continue
+.copyUntilPartyMonOTs
+ ld bc, wPartyMon2 - wPartyMon1
+ add hl, bc ; get address of pokemon after the pokemon removed
+ ld bc, wPartyMonOT ; address of when to stop copying
+.continue
+ call CopyDataUntil ; shift all pokemon data after the removed mon to the removed mon's location
+ ld hl, wPartyMonNicks
+ ld a, [wRemoveMonFromBox]
+ and a
+ jr z, .usePartyMonNicks2
+ ld hl, wBoxMonNicks
+.usePartyMonNicks2
+ ld bc, NAME_LENGTH
+ ld a, [wWhichPokemon]
+ call AddNTimes
+ ld d, h
+ ld e, l
+ ld bc, NAME_LENGTH
+ add hl, bc
+ ld bc, wPartyMonNicksEnd
+ ld a, [wRemoveMonFromBox]
+ and a
+ jr z, .copyUntilPartyMonNicksEnd
+ ld bc, wBoxMonNicksEnd
+.copyUntilPartyMonNicksEnd
+ jp CopyDataUntil
+
+_DisplayPokedex: ; 7abf (1:7abf)
+ ld hl, wd730
+ set 6, [hl]
+ predef ShowPokedexData
+ ld hl, wd730
+ res 6, [hl]
+ call ReloadMapData
+ ld c, 10
+ call DelayFrames
+ predef IndexToPokedex
+ ld a, [wd11e]
+ dec a
+ ld c, a
+ ld b, FLAG_SET
+ ld hl, wPokedexSeen
+ predef FlagActionPredef
+ ld a, $1
+ ld [wDoNotWaitForButtonPressAfterDisplayingText], a
+ ret
SECTION "bank03",ROMX,BANK[$03]