summaryrefslogtreecommitdiff
path: root/main.asm
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 /main.asm
parentb12cc6d02a759fa8696bfc3b740696cfa19cb389 (diff)
More bank3d documentation.
Move some functions from main.asm and engine/battle/core.asm to bank3d, some additional functions too.
Diffstat (limited to 'main.asm')
-rwxr-xr-xmain.asm152
1 files changed, 1 insertions, 151 deletions
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)