summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPokeglitch <pokeglitchx@gmail.com>2018-06-04 20:33:25 -0400
committerPokeglitch <pokeglitchx@gmail.com>2018-06-04 20:33:25 -0400
commit2873751d31331d5ffb0e6b3539a62d1ad264d063 (patch)
tree50e112095e8ada615b3dc6da60469fd45685e6fa
parenta02f7c334808b18570484d060fa758377a47d8cb (diff)
Removed unnecessary comments
-rwxr-xr-xengine/items/inventory.asm448
-rwxr-xr-xhome/tables.asm30
2 files changed, 235 insertions, 243 deletions
diff --git a/engine/items/inventory.asm b/engine/items/inventory.asm
index eb0ff51..99eb0ea 100755
--- a/engine/items/inventory.asm
+++ b/engine/items/inventory.asm
@@ -4,12 +4,12 @@ SECTION "AddItemToInventory_", ROMX[$4AA1], BANK[$03]
_ReceiveItem: ; 03:4AA1
call DoesHLEqualwNumBagItems
- jp nz, PutItemInPocket ; If its not bag, then its the PC, so jump down
+ jp nz, PutItemInPocket
push hl
ld hl, CheckItemPocket
ld a, BANK( CheckItemPocket )
call FarCall_hl
- ld a, [wItemAttributeParamBuffer] ; a = PocketType
+ ld a, [wItemAttributeParamBuffer]
dec a
ld hl, .Pockets
jp CallJumptable
@@ -32,24 +32,25 @@ _ReceiveItem: ; 03:4AA1
pop hl
ld a, [wCurItem]
ld c, a
- call GetBallIndex ; get the index of the ball being added
- jp ReceiveBall ; increase the quantity at that index
+ call GetBallIndex
+ jp ReceiveBall
.TMHM: ; 03:4AD5
pop hl
ld a, [wCurItem]
ld c, a
- call GetTMHMNumber ; get the index of the TMHM being added
- jp ReceiveTMHM ; increase the quantity at that index
+ call GetTMHMNumber
+ jp ReceiveTMHM
+
_TossItem: ; 03:4AE0
call DoesHLEqualwNumBagItems
- jr nz, .removeItem ; If its not bag, then its the PC, so jump down
+ jr nz, .removeItem
push hl
ld hl, CheckItemPocket
ld a, BANK( CheckItemPocket )
call FarCall_hl
- ld a, [wItemAttributeParamBuffer] ; a = PocketType
+ ld a, [wItemAttributeParamBuffer]
dec a
ld hl, .Pockets
jp CallJumptable
@@ -64,15 +65,15 @@ _TossItem: ; 03:4AE0
pop hl
ld a, [wCurItem]
ld c, a
- call GetBallIndex ; get the index of the ball being removed
- jp TossBall ; and decrease the quantity at that index
+ call GetBallIndex
+ jp TossBall
.TMHM ; 03:4B0B
pop hl
ld a, [wCurItem]
ld c, a
- call GetTMHMNumber ; get the index of the TMHM being removed
- jp TossTMHM ; and decrease the quantity at that index
+ call GetTMHMNumber
+ jp TossTMHM
.KeyItem ; 03:4B16
pop hl
@@ -84,14 +85,15 @@ _TossItem: ; 03:4AE0
.removeItem ; 03:4B1B
jp RemoveItemFromPocket
-_CheckItem:: ; 03:4B1E
+
+_CheckItem: ; 03:4B1E
call DoesHLEqualwNumBagItems
- jr nz, .checkItem ; If its not bag, then its the PC, so jump down
+ jr nz, .checkItem
push hl
ld hl, CheckItemPocket
ld a, BANK( CheckItemPocket )
call FarCall_hl
- ld a, [wItemAttributeParamBuffer] ; a = PocketType
+ ld a, [wItemAttributeParamBuffer]
dec a
ld hl, .Pockets
jp CallJumptable
@@ -106,15 +108,15 @@ _CheckItem:: ; 03:4B1E
pop hl
ld a, [wCurItem]
ld c, a
- call GetBallIndex ; get the index of the ball being checked
- jp CheckBall ; and check that index
+ call GetBallIndex
+ jp CheckBall
.TMHM ; 03:4B49
pop hl
ld a, [wCurItem]
ld c, a
- call GetTMHMNumber ; get the index of the TMHM being checked
- jp CheckTMHM ; and check that index
+ call GetTMHMNumber
+ jp CheckTMHM
.KeyItem ; 03:4B54
pop hl
@@ -126,7 +128,7 @@ _CheckItem:: ; 03:4B1E
.checkItem
jp CheckTheItem
-; Zero flag is set if hl = wNumBagItems
+
DoesHLEqualwNumBagItems: ; 03:4B5C
ld a, l
cp LOW(wNumBagItems)
@@ -135,86 +137,91 @@ DoesHLEqualwNumBagItems: ; 03:4B5C
cp HIGH(wNumBagItems)
ret
+
PutItemInPocket: ; 03:4B64
ld d, h
- ld e, l ; de = address of start of inventory
+ ld e, l
inc hl
ld a, [wCurItem]
ld c, a
- ld b, 0 ; b = available space for slots already containing this item, initialize to 0
+ ld b, 0
+; will add the item once the total
+; available space (b) exceeds the
+; amount being added
.findItemLoop
ld a, [hli]
- cp $FF ; was the end of the list reached?
- jr z, .checkIfInventoryFull ; if so, see if there are empty slots
- cp c ; does the item match?
- jr nz, .checkNextItem ; if not, move to the next item
- ld a, 99 ; max amount of an item
- sub [hl] ; subtract the current amount of items, so a = the available space for this item slot
- add b ; combine with the available space from previous slots for this item, so a = the total available space in all slots for this item
- ld b, a ; store the total available space into b (for future iterations)
- ld a, [wItemQuantity] ; a = quantity to add
- cp b ; compare the quantity to add to the available space
- jr z, .itemCanBeAdded ; if the numbers are equal, then add the item
- jr c, .itemCanBeAdded ; if the number to add is less than the available space, then add the item
+ cp $FF
+ jr z, .checkIfInventoryFull
+ cp c
+ jr nz, .checkNextItem
+ ld a, 99
+ sub [hl]
+ add b
+ ld b, a
+ ld a, [wItemQuantity]
+ cp b
+ jr z, .itemCanBeAdded
+ jr c, .itemCanBeAdded
.checkNextItem
- inc hl ; move to the next item in the list
+ inc hl
jr .findItemLoop
.checkIfInventoryFull
- call GetPocketCapacity ; c = maximum size for this inventory
- ld a, [de] ; get the current size of the inventory
- cp c ; compare to the maximum
- jr c, .itemCanBeAdded ; if its not at the maximum, then an item can be added
+ call GetPocketCapacity
+ ld a, [de]
+ cp c
+ jr c, .itemCanBeAdded
- and a ; unset the carry flag to indicate failure
+ and a
ret
.itemCanBeAdded
ld h, d
- ld l, e ; hl = address of start of pocket
+ ld l, e
ld a, [wCurItem]
- ld c, a ; c = item id
+ ld c, a
.findItemToAddLoop
inc hl
ld a, [hli]
- cp a, $FF ; was the end of the list reached?
- jr z, .addNewItem ; if so, add the item to the end
- cp c ; is this the item to add?
- jr nz, .findItemToAddLoop ;if not, then move to the next item
+ cp a, $FF
+ jr z, .addNewItem
+ cp c
+ jr nz, .findItemToAddLoop
ld a, [wItemQuantity]
- add [hl] ; a = new item quantity
- cp a, 100 ; does it exceed 99?
- jr nc, .setMax ; if it exceeds, then only increase quantity to the max
- ld [hl], a ; otherwise, store the new item quantity
+ add [hl]
+ cp a, 100
+ jr nc, .setMax
+ ld [hl], a
jr .success
-; set the inventory quantity to 99, and then add the remainder to the list
+; set this slot's quantity to 99,
+; and keep iterating through list
+; to add remaining amount
.setMax
- ld [hl], 99 ; set the quantity to be the maximum
- sub 99 ; a = remaining quantity
- ld [wItemQuantity], a ; update the item quantity
- jr .findItemToAddLoop ; continue iterating through the list
+ ld [hl], 99
+ sub 99
+ ld [wItemQuantity], a
+ jr .findItemToAddLoop
-; add the item to the end of the list
.addNewItem
dec hl
ld a, [wCurItem]
- ld [hli], a ; store the id
+ ld [hli], a
ld a, [wItemQuantity]
- ld [hli], a ; store the quantity
- ld [hl], $FF ; add the terminator
+ ld [hli], a
+ ld [hl], $FF
ld h, d
- ld l, e ; hl = inventory size
- inc [hl] ; increase the size
+ ld l, e
+ inc [hl]
.success
- scf ; set the carry flag to indicate success
+ scf
ret
-; Store the inventory size into c
+
GetPocketCapacity: ; 03:4BC1
ld c, MAX_ITEMS
ld a, e
@@ -223,135 +230,139 @@ GetPocketCapacity: ; 03:4BC1
ld a, d
cp HIGH(wNumBagItems)
ret z
+
.notBag
ld c, MAX_PC_ITEMS
ret
+
RemoveItemFromPocket: ;03:4BCF
ld d, h
ld e, l
- inc hl ; hl = start of item list
+ inc hl
ld a, [wItemIndex]
- ld c, a ; c = item index
+ ld c, a
ld b, 0
add hl, bc
- add hl, bc ; hl = address of item at given index
+ add hl, bc
inc hl
ld a, [wItemQuantity]
- ld b, a ; b = amount to remove
- ld a, [hl] ; a = current amount
- sub b ; a = remaining amount
- jr c, .fail ; if trying to remove too many, then fail
+ ld b, a
+ ld a, [hl]
+ sub b
+ jr c, .fail
- ld [hl], a ; store new amount
+ ld [hl], a
ld [wItemQuantityBuffer], a
- and a ; is the new amount 0?
- jr nz, .success ; if not, then dont shift items upwards
+ and a
+ jr nz, .dontEraseSlot
+; if the remaining quantity is zero
+; then erase the slot by shifting
+; the subsequent data upwards
dec hl
ld b, h
- ld c, l ; bc = item to remove
+ ld c, l
+ inc hl
inc hl
- inc hl ; hl = next item in list
.shift
ld a, [hli]
ld [bc], a
- inc bc ; overwrite the previous item value with the next item value
- cp $FF ; reached the end of the list?
- jr nz, .shift ; if not, shift the next value
+ inc bc
+ cp $FF
+ jr nz, .shift
ld h, d
- ld l, e ; hl = inventory size
+ ld l, e
- dec [hl] ; decrease the inventory size
+ dec [hl]
-.success
- scf ; set carry flag to indicate success
+.dontEraseSlot
+ scf
ret
.fail
- and a ; unset carry flag to indicate fail
+ and a
ret
-; sets carry flag if item is in the list
+
CheckTheItem: ; 03:4BFD
ld a, [wCurItem]
ld c, a
.loop
inc hl
- ld a, [hli] ; a = next item in list
- cp $FF ; is it the terminator?
- jr z, .fail ; if so, then fail
- cp c ; is it the item?
- jr nz, .loop ; if not, check the next item
+ ld a, [hli]
+ cp $FF
+ jr z, .fail
+ cp c
+ jr nz, .loop
- scf ; set carry flag to indicate success
+ scf
ret
.fail
- and a ; unset carry flag to indicate fail
+ and a
ret
+
ReceiveKeyItem: ; 03:4C0E
ld hl, wNumKeyItems
- ld a, [hli] ; a = size of bag
- cp a, MAX_KEY_ITEMS ; is the bag full
- jr nc, .fail ; then fail
+ ld a, [hli]
+ cp a, MAX_KEY_ITEMS
+ jr nc, .fail
ld c, a
ld b, 0
- add hl, bc ; hl = address to store the item ( the end of the list )
+ add hl, bc
ld a, [wCurItem]
- ld [hli], a ; store item ID
- ld [hl], $FF ; store terminator
+ ld [hli], a
+ ld [hl], $FF
ld hl, wNumKeyItems
- inc [hl] ; increase the inventory size
- scf ; set the carry flag to indicate success
+ inc [hl]
+ scf
ret
-; unset the carry flag to indicate failure
.fail
and a
ret
-; Remove key item with list index of wItemIndex
+
TossKeyItem: ; 03:4C28
ld hl, wNumKeyItems
- dec [hl] ; decrease the size
+ dec [hl]
inc hl
ld a, [wItemIndex]
ld e, a
ld d, 0
- add hl, de ; hl = address of item to remove
+ add hl, de
ld d, h
- ld e, l ; store hl into de
+ ld e, l
inc hl
.shift
ld a, [hli]
- ld [de], a ; shift item up one slot
+ ld [de], a
inc de
- cp $FF ; end of list reached?
- jr nz, .shift ; shift the next item if not
+ cp $FF
+ jr nz, .shift
scf
ret
-; Checks to see if the given item is in D1C8
-; carry = item is in list
+
CheckKeyItems: ; 03:4C40
ld a, [wCurItem]
- ld c, a ; c = item id
+ ld c, a
ld hl, wKeyItems
.loop
- ld a, [hli] ; a = next item in list
- cp c ; does it match the input item?
- jr z, .matchFound ; if so, set the carry flag
- cp $FF ; was the end of the list reached?
- jr nz, .loop ; if not, go to the next item
-
+ ld a, [hli]
+ cp c
+ jr z, .matchFound
+ cp $FF
+ jr nz, .loop
+
and a
ret
@@ -359,43 +370,38 @@ CheckKeyItems: ; 03:4C40
scf
ret
-; Returns the index of the given item in the Ball Items List
-; Input:
-; c = item to search for
-; Output:
-; c = index of item in table
+
+; get index of ball item id c from BallItems
GetBallIndex: ; 03:4C53
ld a, c
push hl
push de
push bc
ld hl, BallItems
- ld de, 1 ; size of each row in the table
+ ld de, 1
call FindItemInTable
- ld a, b ; store the row index into a
+ ld a, b
pop bc
pop de
pop hl
- ld c, a ; store the row index to c
+ ld c, a
ret
-; Returns the item at the given index in the Ball Items List
-; Inputs:
-; c = index in table
-; Outputs:
-; c = value in table
+
+; get ball item id at index c in BallItems
GetBallByIndex: ; 03:4c66
push bc
push hl
ld b, 0
ld hl, BallItems
- add hl, bc ; hl = address of row in table
- ld a, [hl] ; a = item at that index
+ add hl, bc
+ ld a, [hl]
pop hl
pop bc
- ld c, a ; c = item at that index
+ ld c, a
ret
+
BallItems: ; 03:4C73
db ITEM_MASTER_BALL
db ITEM_ULTRA_BALL
@@ -404,130 +410,123 @@ BallItems: ; 03:4C73
db $FF
-; To empty out the ball pocket
-; Note - Is this buggy?
-; The ball pocket is a fixed length, not $FF terminated
+; empties the ball pocket by setting the
+; terminator immediately after wNumBallItems
+
+ ; Note, the ball pocket appears to be
+ ; a fixed length, not $FF terminated
EmptyBallPocket: ; 03:4C78
ld hl, wNumBallItems
xor a
- ld [hli], a ; set size to 0
- ld [hl], $FF ; add terminator
+ ld [hli], a
+ ld [hl], $FF
ret
-; The Ball pocket is a list of quantities, which directly map to BallItems
-; c = item index in table
-; wItemQuantity = amount to add
-; Sets carry flag if successful
+
ReceiveBall: ; 03:4C80
ld hl, wBallQuantities
ld b, 0
- add hl, bc ; hl = address of item quantity in table
- ld a, [wItemQuantity] ; a = quantity to add
- add [hl] ; combine with the current quantity, so a = new quantity
- cp 100 ; does it exceed 99?
- jr nc, .fail ; if so, fail
- ld b, a ; b = new quantity
- ld a, [hl] ; a = current quantity
- and a ; is current quantity zero?
- jr nz, .dontIncreaseInventorySize ; if not, dont increase the inventory size
+ add hl, bc
+ ld a, [wItemQuantity]
+ add [hl]
+ cp 100
+ jr nc, .fail
+ ld b, a
+ ld a, [hl]
+ and a
+ jr nz, .skipIncreasingNumItems
+
ld a, [wNumBallItems]
inc a
- ld [wNumBallItems], a ; increase the inventory size
+ ld [wNumBallItems], a
-.dontIncreaseInventorySize
- ld [hl], b ; store the new quantity
- scf ; set the carry flag to indicate success
+.skipIncreasingNumItems
+ ld [hl], b
+ scf
ret
.fail
- and a ; unset the carry flag to indicate failure
+ and a
ret
-; Inputs:
-; c = index of item in table
-; wItemQuantity = amount to remove
-; Sets carry flag if successful
+
TossBall: ; 03:4C9F
ld hl, wBallQuantities
ld b, 0
- add hl, bc ; hl = index for this item
+ add hl, bc
ld a, [wItemQuantity]
- ld b, a ; b = quantity to remove
- ld a, [hl] ; a = current quantity
- sub b ; a = remaining quantity
- jr c, .fail ; if quantity to remove exceeds the current quantity, then fail
- jr nz, .dontDecreaseInventorySize ; if the new quantity is not 0, then dont decrease the inventory size
+ ld b, a
+ ld a, [hl]
+ sub b
+ jr c, .fail
+ jr nz, .skipDecreasingNumItems
ld b, a
ld a, [wNumBallItems]
dec a
- ld [wNumBallItems], a ; decrease the inventory size
+ ld [wNumBallItems], a
ld a, b
-.dontDecreaseInventorySize
- ld [hl], a ; store the new quantity
+.skipDecreasingNumItems
+ ld [hl], a
ld [wItemQuantityBuffer], a
- scf ; set carry flag to indicate success
+ scf
ret
.fail
- and a ; unset the carry flag to indicate fail
+ and a
ret
-; Inputs
-; c = index of item
-; Outputs
-; carry if ball has a non zero quantity
+
CheckBall: ; 03:4CC0
ld hl, wBallQuantities
ld b, 0
- add hl, bc ; hl = address of item quantity
- ld a, [hl] ; get the quantity for this item
+ add hl, bc
+ ld a, [hl]
and a
ret z
scf
ret
-; Inputs:
-; c = TMHM index
-; carry if success
+
ReceiveTMHM: ; 03:4CCB
ld b, 0
ld hl, wTMsHMs
- add hl, bc ; hl = address of TMHM quantity
- ld a, [wItemQuantity] ; a = quantity to add
- add [hl] ; a = new item quantity
- cp 100 ; does it exceed 99?
- jr nc, .fail ; if so, fail
- ld [hl], a ; store the new quantity
- scf ; set carry flag to indicate success
+ add hl, bc
+ ld a, [wItemQuantity]
+ add [hl]
+ cp 100
+ jr nc, .fail
+ ld [hl], a
+ scf
ret
.fail
- and a ; unset carry flag to indicate failure
+ and a
ret
+
TossTMHM: ; 03:4CDE
ld b, 0
ld hl, wTMsHMs
add hl, bc
ld a, [wItemQuantity]
- ld b, a ; b = amount to remove
- ld a, [hl] ; a = current amount
- sub b ; a = remaining amount
- jr c, .fail ; if the amount to remove exceeds the current amount, then fail
- ld [hl], a ; store the new item count
- ld [wItemQuantityBuffer], a
+ ld b, a
+ ld a, [hl]
+ sub b
+ jr c, .fail
- scf ; set carry flag to indicate success
+ ld [hl], a
+ ld [wItemQuantityBuffer], a
+ scf
ret
.fail
- and a ; unset carry flag to indicate failure
+ and a
ret
+
CheckTMHM: ; 03:4CF4
-; Returns whether or not inventory contains TMHM in c
ld b, 0
ld hl, wTMsHMs
add hl, bc
@@ -538,37 +537,39 @@ CheckTMHM: ; 03:4CF4
ret
GetTMHMNumber: ; 03:4CFF
-; Return the item id of a TM/HM by number c.
ld a, c
- ld c, 0 ; initialize the non-TM count to 0
+ ld c, 0
- sub ITEM_TM01 ; a = TM index (if TM)
+ sub ITEM_TM01
jr c, .notMachine
- cp ITEM_C8 - ITEM_TM01 ; is the item ITEM_C8 ?
- jr z, .notMachine ; If so, fail
- jr c, .finish ; If the TM index is below, then finish
- inc c ; increase the non-TM count
- cp ITEM_E1 - ITEM_TM01 ; is the item ITEM_E1?
- jr z, .notMachine ; if so, fail
+ cp ITEM_C8 - ITEM_TM01
+ jr z, .notMachine
+ jr c, .finish
+
+ inc c
+ cp ITEM_E1 - ITEM_TM01
+ jr z, .notMachine
- jr c, .finish ; If the TM index is below, then finish
- inc c ; otherwise, increase the non-TM count
+ jr c, .finish
+ inc c
+; c represents the amount of non-TMs which
+; appear ahead of this item in the list
+; so subtract that value before exiting
.finish
- sub c ; subtract the amount of non TM-items that appear before this to get the true TM index
- ld c, a ; store into c
-
- scf ; set the carry flag to indicate success
+ sub c
+ ld c, a
+ scf
ret
.notMachine
- and a ; unset the carry flag to indicate failure
+ and a
ret
SECTION "_CheckTossableItem", ROMX[$53AD], BANK[$03]
-_CheckTossableItem:: ; 03:53AD
+_CheckTossableItem: ; 03:53AD
; Return 1 in wItemAttributeParamBuffer and carry if wCurItem can't be removed from the bag.
ld a, ITEMATTR_PERMISSIONS
call GetItemAttr
@@ -615,24 +616,19 @@ GetItemAttr: ; 03:53E6
; Get attribute a of wCurItem.
push hl
push bc
-
ld hl, ItemAttributes
- ld c, a ; c = item data byte index to retrieve
+ ld c, a
ld b, 0
- add hl, bc ; hl = address for item
-
+ add hl, bc
xor a
- ld [wItemAttributeParamBuffer], a ; set the item param value to 0
-
- ld a, [wCurItem] ; a = item id
+ ld [wItemAttributeParamBuffer], a
+ ld a, [wCurItem]
dec a
- ld c, a ; c = item id - 1
- ld a, ITEMATTR_STRUCT_LENGTH ; size of each item attribute data set
- call AddNTimes ; Go to the row for this item
-
+ ld c, a
+ ld a, ITEMATTR_STRUCT_LENGTH
+ call AddNTimes
ld a, BANK( ItemAttributes )
- call GetFarByte ; Get the byte from the table
-
+ call GetFarByte
pop bc
pop hl
ret
diff --git a/home/tables.asm b/home/tables.asm
index 6831d10..dc0a7a2 100755
--- a/home/tables.asm
+++ b/home/tables.asm
@@ -2,31 +2,27 @@ INCLUDE "constants.asm"
SECTION "FindItemInTable", ROM0[$35F8]
-; Inputs:
-; hl = start of table to check
-; de = row size
-; a = item to search for
-; Outputs:
-; carry = item found
-; b = row index of item
+; find value a from table hl with row length de
+; returns carry and row index b if successful
+
FindItemInTable: ; 00:35F8
ld b, 0
ld c, a
.nextItem
- ld a, [hl] ; load the next item
- cp $FF ; is the list finished?
- jr z, .fail ; if so, then fail
- cp c ; does this item match?
- jr z, .success ; if so, then set the carry flag
- inc b ; increase the row index count
- add hl, de ; move the next row
- jr .nextItem ; check the next item
+ ld a, [hl]
+ cp $FF
+ jr z, .fail
+ cp c
+ jr z, .success
+ inc b
+ add hl, de
+ jr .nextItem
.fail
- and a ; unset the carry flag to indicate failure
+ and a
ret
.success
- scf ; set the carry flag to indicate success
+ scf
ret \ No newline at end of file