summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorluckytyphlosion <alan.rj.huang@gmail.com>2015-07-03 14:28:37 -0400
committerluckytyphlosion <alan.rj.huang@gmail.com>2015-07-03 14:28:37 -0400
commit9facc162f3b750a35ed10ad0fa00e5a17e260adf (patch)
treebb94721a2ea524e9d76165c10ea1540396089d6d
parentb12cc6d02a759fa8696bfc3b740696cfa19cb389 (diff)
More bank3d documentation.
Move some functions from main.asm and engine/battle/core.asm to bank3d, some additional functions too.
-rw-r--r--engine/bank3d/bank3d_battle.asm169
-rw-r--r--engine/bank3d/main.asm274
-rwxr-xr-xengine/battle/core.asm161
-rwxr-xr-xmain.asm152
4 files changed, 443 insertions, 313 deletions
diff --git a/engine/bank3d/bank3d_battle.asm b/engine/bank3d/bank3d_battle.asm
new file mode 100644
index 00000000..aef04d9d
--- /dev/null
+++ b/engine/bank3d/bank3d_battle.asm
@@ -0,0 +1,169 @@
+InitBattle: ; f5ff2 (3d:f5ff2)
+ ld a, [W_CUROPPONENT]
+ and a
+ jr z, asm_f6003
+
+InitOpponent: ; f5ff8 (3d:5ff8)
+ ld a, [W_CUROPPONENT]
+ ld [wcf91], a
+ ld [wEnemyMonSpecies2], a
+ jr asm_f601d
+asm_f6003: ; f6003 (3d:6003)
+ ld a, [wd732]
+ bit 1, a
+ jr z, .asm_f600f
+ ld a, [hJoyHeld]
+ bit 1, a ; B button pressed?
+ ret nz
+.asm_f600f
+ ld a, [wNumberOfNoRandomBattleStepsLeft]
+ and a
+ ret nz
+ callab TryDoWildEncounter
+ ret nz
+asm_f601d: ; 3ef3d (f:6f3d)
+ ld a, [wMapPalOffset]
+ push af
+ ld hl, wd358
+ ld a, [hl]
+ push af
+ res 1, [hl]
+ call InitBattleVariables ; 3d:6236
+ ld a, [wEnemyMonSpecies2]
+ sub $c8
+ jp c, InitWildBattle
+ ld [W_TRAINERCLASS], a
+ call GetTrainerInformation
+ callab ReadTrainer
+ callab DoBattleTransitionAndInitBattleVariables
+ call _LoadTrainerPic ; 3d:615a
+ xor a
+ ld [wEnemyMonSpecies2], a
+ ld [$ffe1], a
+ dec a
+ ld [wAICount], a
+ hlCoord 12, 0
+ predef Func_3f0c6
+ ld a, $ff
+ ld [wEnemyMonPartyPos], a
+ ld a, $2
+ ld [W_ISINBATTLE], a
+ ld a,[W_LONEATTACKNO]
+ and a
+ jp z,InitBattle_Common
+ ld hl,Func_f430a
+ ld b,BANK(Func_f430a)
+ ld d,$4
+ call Bankswitch ; useless since already in bank3d
+ jp InitBattle_Common
+
+InitWildBattle: ; f607c (3d:607c)
+ ld a, $1
+ ld [W_ISINBATTLE], a
+ callab LoadEnemyMonData
+ callab DoBattleTransitionAndInitBattleVariables
+ ld a, [W_CUROPPONENT]
+ cp MAROWAK
+ jr z, .isGhost
+ callab IsGhostBattle
+ jr nz, .isNoGhost
+.isGhost
+ ld hl, W_MONHSPRITEDIM
+ ld a, $66
+ ld [hli], a ; write sprite dimensions
+ ld bc, GhostPic
+ ld a, c
+ ld [hli], a ; write front sprite pointer
+ ld [hl], b
+ ld hl, wEnemyMonNick ; set name to "GHOST"
+ ld a, "G"
+ ld [hli], a
+ ld a, "H"
+ ld [hli], a
+ ld a, "O"
+ ld [hli], a
+ ld a, "S"
+ ld [hli], a
+ ld a, "T"
+ ld [hli], a
+ ld [hl], "@"
+ ld a, [wcf91]
+ push af
+ ld a, MON_GHOST
+ ld [wcf91], a
+ ld de, vFrontPic
+ call LoadMonFrontSprite ; load ghost sprite
+ pop af
+ ld [wcf91], a
+ jr .spriteLoaded
+.isNoGhost
+ ld de, vFrontPic
+ call LoadMonFrontSprite ; load mon sprite
+.spriteLoaded
+ xor a
+ ld [W_TRAINERCLASS], a
+ ld [$ffe1], a
+ hlCoord 12, 0
+ predef Func_3f0c6
+
+; common code that executes after init battle code specific to trainer or wild battles
+InitBattle_Common: ; f60eb (3d:60eb)
+ ld b, $0
+ call GoPAL_SET
+ callab SlidePlayerAndEnemySilhouettesOnScreen
+ xor a
+ ld [H_AUTOBGTRANSFERENABLED], a
+ ld hl, .emptyString
+ call PrintText
+ call SaveScreenTilesToBuffer1
+ call ClearScreen
+ ld a, $98
+ ld [$ffbd], a
+ ld a, $1
+ ld [H_AUTOBGTRANSFERENABLED], a
+ call Delay3
+ ld a, $9c
+ ld [$ffbd], a
+ call LoadScreenTilesFromBuffer1
+ hlCoord 9, 7
+ ld bc, $50a
+ call ClearScreenArea
+ hlCoord 1, 0
+ ld bc, $40a
+ call ClearScreenArea
+ call ClearSprites
+ ld a, [W_ISINBATTLE]
+ dec a ; is it a wild battle?
+ ld hl, DrawEnemyHUDAndHPBar
+ ld b,BANK(DrawEnemyHUDAndHPBar)
+ call z, Bankswitch ; draw enemy HUD and HP bar if it's a wild battle
+ callab StartBattle
+ callab EndOfBattle
+ pop af
+ ld [wd358], a
+ pop af
+ ld [wMapPalOffset], a
+ ld a, [wd0d4]
+ ld [hTilesetType], a
+ scf
+ ret
+.emptyString
+ db "@"
+
+_LoadTrainerPic: ; f615a (3d:615a)
+; wd033-wd034 contain pointer to pic
+ ld a, [wTrainerPicPointer] ; wd033
+ ld e, a
+ ld a, [wTrainerPicPointer + 1] ; wd034
+ ld d, a ; de contains pointer to trainer pic
+ ld a, [wLinkState]
+ and a
+ ld a, Bank(TrainerPics) ; this is where all the trainer pics are (not counting Red's)
+ jr z, .loadSprite
+ ld a, Bank(RedPicFront)
+.loadSprite
+ call UncompressSpriteFromDE
+ ld de, vFrontPic
+ ld a, $77
+ ld c, a
+ jp LoadUncompressedSpriteData \ No newline at end of file
diff --git a/engine/bank3d/main.asm b/engine/bank3d/main.asm
index 9cf96ccd..d5ce0c5e 100644
--- a/engine/bank3d/main.asm
+++ b/engine/bank3d/main.asm
@@ -395,4 +395,276 @@ Func_f5ab0:: ; f5ab0 (3d:5ab0)
ld [wMenuCursorLocation+1],a
ld a,[wCurrentMenuItem]
ld [wLastMenuItem],a
- ret \ No newline at end of file
+ ret
+
+Func_f5b06:: ; f5b06 (3d:5b06)
+ ld hl,wd728
+ set 0,[hl]
+ ld hl,Text_f5b17
+ call PrintText
+ ld hl,Text_f5b28
+ jp PrintText
+
+Text_f5b17:: ; f5b17 (3d:5b17)
+ TX_FAR _Text_f5b17 ; 2d:417e
+ db $08 ; asm
+ ld a,[wcf91]
+ call PlayCry
+ call Delay3
+ jp TextScriptEnd
+
+Text_f5b28:: ; f5b28 (3d:5b28)
+ TX_FAR _Text_f5b28 ; 2d:4193
+ db "@"
+
+Func_f5b2d:: ; f5b2d (3d:5b2d)
+ ld hl,wd728
+ set 1,[hl]
+ ld a,[wd732]
+ bit 5,a
+ jr nz,.asm_f5b59
+ ld a,[W_CURMAP]
+ cp SEAFOAM_ISLANDS_5
+ ret nz
+ ld a,[wd881]
+ and $3
+ cp $3
+ ret z
+ ld hl,CoordsData_f5b64
+ call ArePlayerCoordsInArray
+ ret nc
+ ld hl,wd728
+ res 1,[hl]
+ ld hl,Text_f5b67
+ jp PrintText
+.asm_f5b59
+ ld hl,wd728
+ res 1,[hl]
+ ld hl,Text_f5b6c
+ jp PrintText
+
+CoordsData_f5b64:: ; f5b64 (3d:5b64)
+ db 13,07
+ db $ff
+
+Text_f5b67:: ; f5b67 (3d:5b67)
+ TX_FAR _Text_f5b67 ; 2d:41ab
+ db "@"
+
+Text_f5b6c:: ; f5b6c (3d:5b6c)
+ TX_FAR _Text_f5b6c
+ db "@"
+
+AddItemToInventory_:: ; f5b70 (3d:5b70)
+ ld a,[wcf96] ; a = item quantity
+ push af
+ push bc
+ push de
+ push hl
+ push hl
+ ld d,50 ; PC box can hold 50 items
+ ld a,wNumBagItems & $FF
+ cp l
+ jr nz,.checkIfInventoryFull
+ ld a,wNumBagItems >> 8
+ cp h
+ jr nz,.checkIfInventoryFull
+; if the destination is the bag
+ ld d,20 ; bag can hold 20 items
+.checkIfInventoryFull
+ ld a,[hl]
+ sub d
+ ld d,a
+ ld a,[hli]
+ and a
+ jr z,.addNewItem
+.loop
+ ld a,[hli]
+ ld b,a ; b = ID of current item in table
+ ld a,[wcf91] ; a = ID of item being added
+ cp b ; does the current item in the table match the item being added?
+ jp z,.increaseItemQuantity ; if so, increase the item's quantity
+ inc hl
+ ld a,[hl]
+ cp a,$ff ; is it the end of the table?
+ jr nz,.loop
+.addNewItem ; add an item not yet in the inventory
+ pop hl
+ ld a,d
+ and a ; is there room for a new item slot?
+ jr z,.done
+; if there is room
+ inc [hl] ; increment the number of items in the inventory
+ ld a,[hl] ; the number of items will be the index of the new item
+ add a
+ dec a
+ ld c,a
+ ld b,0
+ add hl,bc ; hl = address to store the item
+ ld a,[wcf91]
+ ld [hli],a ; store item ID
+ ld a,[wcf96]
+ ld [hli],a ; store item quantity
+ ld [hl],$ff ; store terminator
+ jp .success
+.increaseItemQuantity ; increase the quantity of an item already in the inventory
+ ld a,[wcf96]
+ ld b,a ; b = quantity to add
+ ld a,[hl] ; a = existing item quantity
+ add b ; a = new item quantity
+ cp a,100
+ jp c,.storeNewQuantity ; if the new quantity is less than 100, store it
+; if the new quantity is greater than or equal to 100,
+; try to max out the current slot and add the rest in a new slot
+ sub a,99
+ ld [wcf96],a ; a = amount left over (to put in the new slot)
+ ld a,d
+ and a ; is there room for a new item slot?
+ jr z,.increaseItemQuantityFailed
+; if so, store 99 in the current slot and store the rest in a new slot
+ ld a,99
+ ld [hli],a
+ jp .loop
+.increaseItemQuantityFailed
+ pop hl
+ and a
+ jr .done
+.storeNewQuantity
+ ld [hl],a
+ pop hl
+.success
+ scf
+.done
+ pop hl
+ pop de
+ pop bc
+ pop bc
+ ld a,b
+ ld [wcf96],a ; restore the initial value from when the function was called
+ ret
+
+; function to remove an item (in varying quantities) from the player's bag or PC box
+; INPUT:
+; hl = address of inventory (either wNumBagItems or wNumBoxItems)
+; [wWhichPokemon] = index (within the inventory) of the item to remove
+; [wcf96] = quantity to remove
+RemoveItemFromInventory_: ; f5be1 (3d:5be1)
+ push hl
+ inc hl
+ ld a,[wWhichPokemon] ; index (within the inventory) of the item being removed
+ add a
+ add l
+ ld l,a
+ jr nc,.noCarry
+ inc h
+.noCarry
+ inc hl
+ ld a,[wcf96] ; quantity being removed
+ ld e,a
+ ld a,[hl] ; a = current quantity
+ sub e
+ ld [hld],a ; store new quantity
+ ld [wcf97],a
+ and a
+ jr nz,.skipMovingUpSlots
+; if the remaining quantity is 0,
+; remove the emptied item slot and move up all the following item slots
+.moveSlotsUp
+ ld e,l
+ ld d,h
+ inc de
+ inc de ; de = address of the slot following the emptied one
+.loop ; loop to move up the following slots
+ ld a,[de]
+ inc de
+ ld [hli],a
+ cp a,$ff
+ jr nz,.loop
+; update menu info
+ xor a
+ ld [wListScrollOffset],a
+ ld [wCurrentMenuItem],a
+ ld [wcc2c],a
+ ld [wd07e],a
+ pop hl
+ ld a,[hl] ; a = number of items in inventory
+ dec a ; decrement the number of items
+ ld [hl],a ; store new number of items
+ ld [wd12a],a
+ cp a,2
+ jr c,.done
+ ld [wMaxMenuItem],a
+ jr .done
+.skipMovingUpSlots
+ pop hl
+.done
+ ret
+
+TrainerInfoTextBoxTileGraphics: INCBIN "gfx/trainer_info.2bpp"
+BlankLeaderNames: INCBIN "gfx/blank_leader_names.2bpp"
+CircleTile: INCBIN "gfx/circle_tile.2bpp"
+BadgeNumbersTileGraphics: INCBIN "gfx/badge_numbers.2bpp"
+
+Func_f5ea4:: ; f5ea4 (3d:f5ea4)
+ ld a,[W_CURMAP]
+ ld c,a
+ ld hl,Pointer_f5eda
+.loop
+ ld a,[hli]
+ cp $ff
+ jr z,.notfound
+ cp c
+ jr z,.found
+ ld de,$8
+ add hl,de
+ jr .loop
+.found
+ call Func_f5ec1
+.notfound
+ ld de,$0
+ ret
+
+Func_f5ec1:: ; f5ec1
+ call Random
+ cp $66
+ jr c,.asm_f5ed6
+ inc hl
+ inc hl
+ cp $b2
+ jr c,.asm_f5ed6
+ inc hl
+ inc hl
+ cp $e5
+ jr c,.asm_f5ed6
+ inc hl
+ inc hl
+.asm_f5ed6
+ ld e,[hl]
+ inc hl
+ ld d,[hl]
+ ret
+
+Pointer_f5eda:: ; f5eda (3d:f5eda)
+ db PALLET_TOWN,$1b,$a,$18,$a,$1b,$5,$18,$14
+ db VIRIDIAN_CITY,$47,$5,$47,$a,$47,$f,$47,$a
+ db CERULEAN_CITY,$9d,$19,$9d,$1e,$9e,$1e,$9e,$28
+ ; ... rest of data TBA
+
+SECTION "temp_f5ff2" ROMX[$5ff2],BANK[$3c]
+INCLUDE "engine/bank3d/bank3d_battle.asm"
+
+InitBattle:: ; f5ff2 (3d:5ff2)
+ ld a,[W_CUROPPONENT]
+ and a
+ jr z,.asm_f6003
+ ld a,[W_CUROPPONENT]
+ ld [wcf91],a
+ ld [wEnemyMonSpecies2],a
+ jr .asm_f601d
+ ld a,[wd732]
+ bit 1,a ; debug mode?
+ jr z,.notdebugmode
+ ld a,[hJoyHeld]
+ bit 1,a ; holding b button?
+ ret nz
+ \ No newline at end of file
diff --git a/engine/battle/core.asm b/engine/battle/core.asm
index 04a6de1c..c335eeb3 100755
--- a/engine/battle/core.asm
+++ b/engine/battle/core.asm
@@ -6815,167 +6815,6 @@ PlayMoveAnimation: ; 3ef07 (f:6f07)
call Delay3
predef_jump MoveAnimation
-InitBattle: ; 3ef12 (f:6f12)
- ld a, [W_CUROPPONENT]
- and a
- jr z, asm_3ef23
-
-InitOpponent: ; 3ef18 (f:6f18)
- ld a, [W_CUROPPONENT]
- ld [wcf91], a
- ld [wEnemyMonSpecies2], a
- jr asm_3ef3d
-asm_3ef23: ; 3ef23 (f:6f23)
- ld a, [wd732]
- bit 1, a
- jr z, .asm_3ef2f
- ld a, [hJoyHeld]
- bit 1, a ; B button pressed?
- ret nz
-.asm_3ef2f
- ld a, [wNumberOfNoRandomBattleStepsLeft]
- and a
- ret nz
- callab TryDoWildEncounter
- ret nz
-asm_3ef3d: ; 3ef3d (f:6f3d)
- ld a, [wMapPalOffset]
- push af
- ld hl, wd358
- ld a, [hl]
- push af
- res 1, [hl]
- callab InitBattleVariables
- ld a, [wEnemyMonSpecies2]
- sub $c8
- jp c, InitWildBattle
- ld [W_TRAINERCLASS], a
- call GetTrainerInformation
- callab ReadTrainer
- call DoBattleTransitionAndInitBattleVariables
- call _LoadTrainerPic
- xor a
- ld [wEnemyMonSpecies2], a
- ld [$ffe1], a
- dec a
- ld [wAICount], a
- hlCoord 12, 0
- predef Func_3f0c6
- ld a, $ff
- ld [wEnemyMonPartyPos], a
- ld a, $2
- ld [W_ISINBATTLE], a
- jp InitBattle_Common
-
-InitWildBattle: ; 3ef8b (f:6f8b)
- ld a, $1
- ld [W_ISINBATTLE], a
- call LoadEnemyMonData
- call DoBattleTransitionAndInitBattleVariables
- ld a, [W_CUROPPONENT]
- cp MAROWAK
- jr z, .isGhost
- call IsGhostBattle
- jr nz, .isNoGhost
-.isGhost
- ld hl, W_MONHSPRITEDIM
- ld a, $66
- ld [hli], a ; write sprite dimensions
- ld bc, GhostPic
- ld a, c
- ld [hli], a ; write front sprite pointer
- ld [hl], b
- ld hl, wEnemyMonNick ; set name to "GHOST"
- ld a, "G"
- ld [hli], a
- ld a, "H"
- ld [hli], a
- ld a, "O"
- ld [hli], a
- ld a, "S"
- ld [hli], a
- ld a, "T"
- ld [hli], a
- ld [hl], "@"
- ld a, [wcf91]
- push af
- ld a, MON_GHOST
- ld [wcf91], a
- ld de, vFrontPic
- call LoadMonFrontSprite ; load ghost sprite
- pop af
- ld [wcf91], a
- jr .spriteLoaded
-.isNoGhost
- ld de, vFrontPic
- call LoadMonFrontSprite ; load mon sprite
-.spriteLoaded
- xor a
- ld [W_TRAINERCLASS], a
- ld [$ffe1], a
- hlCoord 12, 0
- predef Func_3f0c6
-
-; common code that executes after init battle code specific to trainer or wild battles
-InitBattle_Common: ; 3efeb (f:6feb)
- ld b, $0
- call GoPAL_SET
- call SlidePlayerAndEnemySilhouettesOnScreen
- xor a
- ld [H_AUTOBGTRANSFERENABLED], a
- ld hl, .emptyString
- call PrintText
- call SaveScreenTilesToBuffer1
- call ClearScreen
- ld a, $98
- ld [$ffbd], a
- ld a, $1
- ld [H_AUTOBGTRANSFERENABLED], a
- call Delay3
- ld a, $9c
- ld [$ffbd], a
- call LoadScreenTilesFromBuffer1
- hlCoord 9, 7
- ld bc, $50a
- call ClearScreenArea
- hlCoord 1, 0
- ld bc, $40a
- call ClearScreenArea
- call ClearSprites
- ld a, [W_ISINBATTLE]
- dec a ; is it a wild battle?
- call z, DrawEnemyHUDAndHPBar ; draw enemy HUD and HP bar if it's a wild battle
- call StartBattle
- callab EndOfBattle
- pop af
- ld [wd358], a
- pop af
- ld [wMapPalOffset], a
- ld a, [wd0d4]
- ld [hTilesetType], a
- scf
- ret
-.emptyString
- db "@"
-
-_LoadTrainerPic: ; 3f04b (f:704b)
-; wd033-wd034 contain pointer to pic
- ld a, [wTrainerPicPointer] ; wd033
- ld e, a
- ld a, [wTrainerPicPointer + 1] ; wd034
- ld d, a ; de contains pointer to trainer pic
- ld a, [wLinkState]
- and a
- ld a, Bank(TrainerPics) ; this is where all the trainer pics are (not counting Red's)
- jr z, .loadSprite
- ld a, Bank(RedPicFront)
-.loadSprite
- call UncompressSpriteFromDE
- ld de, vFrontPic
- ld a, $77
- ld c, a
- jp LoadUncompressedSpriteData
-
; unreferenced
Func_3f069: ; 3f069 (f:7069)
xor a
diff --git a/main.asm b/main.asm
index f900571b..0fdc5b76 100755
--- a/main.asm
+++ b/main.asm
@@ -2725,157 +2725,7 @@ CyclingIsFunText: ; cdff (3:4dff)
TX_FAR _CyclingIsFunText
db "@"
-; function to add an item (in varying quantities) to the player's bag or PC box
-; INPUT:
-; hl = address of inventory (either wNumBagItems or wNumBoxItems)
-; [wcf91] = item ID
-; [wcf96] = item quantity
-; sets carry flag if successful, unsets carry flag if unsuccessful
-AddItemToInventory_: ; ce04 (3:4e04)
- ld a,[wcf96] ; a = item quantity
- push af
- push bc
- push de
- push hl
- push hl
- ld d,50 ; PC box can hold 50 items
- ld a,wNumBagItems & $FF
- cp l
- jr nz,.checkIfInventoryFull
- ld a,wNumBagItems >> 8
- cp h
- jr nz,.checkIfInventoryFull
-; if the destination is the bag
- ld d,20 ; bag can hold 20 items
-.checkIfInventoryFull
- ld a,[hl]
- sub d
- ld d,a
- ld a,[hli]
- and a
- jr z,.addNewItem
-.loop
- ld a,[hli]
- ld b,a ; b = ID of current item in table
- ld a,[wcf91] ; a = ID of item being added
- cp b ; does the current item in the table match the item being added?
- jp z,.increaseItemQuantity ; if so, increase the item's quantity
- inc hl
- ld a,[hl]
- cp a,$ff ; is it the end of the table?
- jr nz,.loop
-.addNewItem ; add an item not yet in the inventory
- pop hl
- ld a,d
- and a ; is there room for a new item slot?
- jr z,.done
-; if there is room
- inc [hl] ; increment the number of items in the inventory
- ld a,[hl] ; the number of items will be the index of the new item
- add a
- dec a
- ld c,a
- ld b,0
- add hl,bc ; hl = address to store the item
- ld a,[wcf91]
- ld [hli],a ; store item ID
- ld a,[wcf96]
- ld [hli],a ; store item quantity
- ld [hl],$ff ; store terminator
- jp .success
-.increaseItemQuantity ; increase the quantity of an item already in the inventory
- ld a,[wcf96]
- ld b,a ; b = quantity to add
- ld a,[hl] ; a = existing item quantity
- add b ; a = new item quantity
- cp a,100
- jp c,.storeNewQuantity ; if the new quantity is less than 100, store it
-; if the new quantity is greater than or equal to 100,
-; try to max out the current slot and add the rest in a new slot
- sub a,99
- ld [wcf96],a ; a = amount left over (to put in the new slot)
- ld a,d
- and a ; is there room for a new item slot?
- jr z,.increaseItemQuantityFailed
-; if so, store 99 in the current slot and store the rest in a new slot
- ld a,99
- ld [hli],a
- jp .loop
-.increaseItemQuantityFailed
- pop hl
- and a
- jr .done
-.storeNewQuantity
- ld [hl],a
- pop hl
-.success
- scf
-.done
- pop hl
- pop de
- pop bc
- pop bc
- ld a,b
- ld [wcf96],a ; restore the initial value from when the function was called
- ret
-
-; function to remove an item (in varying quantities) from the player's bag or PC box
-; INPUT:
-; hl = address of inventory (either wNumBagItems or wNumBoxItems)
-; [wWhichPokemon] = index (within the inventory) of the item to remove
-; [wcf96] = quantity to remove
-RemoveItemFromInventory_: ; ce74 (3:4e74)
- push hl
- inc hl
- ld a,[wWhichPokemon] ; index (within the inventory) of the item being removed
- sla a
- add l
- ld l,a
- jr nc,.noCarry
- inc h
-.noCarry
- inc hl
- ld a,[wcf96] ; quantity being removed
- ld e,a
- ld a,[hl] ; a = current quantity
- sub e
- ld [hld],a ; store new quantity
- ld [wcf97],a
- and a
- jr nz,.skipMovingUpSlots
-; if the remaining quantity is 0,
-; remove the emptied item slot and move up all the following item slots
-.moveSlotsUp
- ld e,l
- ld d,h
- inc de
- inc de ; de = address of the slot following the emptied one
-.loop ; loop to move up the following slots
- ld a,[de]
- inc de
- ld [hli],a
- cp a,$ff
- jr nz,.loop
-; update menu info
- xor a
- ld [wListScrollOffset],a
- ld [wCurrentMenuItem],a
- ld [wcc2c],a
- ld [wd07e],a
- pop hl
- ld a,[hl] ; a = number of items in inventory
- dec a ; decrement the number of items
- ld [hl],a ; store new number of items
- ld [wd12a],a
- cp a,2
- jr c,.done
- ld [wMaxMenuItem],a
- jr .done
-.skipMovingUpSlots
- pop hl
-.done
- ret
-
+
; wild pokemon data: from 4EB8 to 55C7
LoadWildData: ; ceb8 (3:4eb8)