summaryrefslogtreecommitdiff
path: root/home
diff options
context:
space:
mode:
Diffstat (limited to 'home')
-rwxr-xr-xhome/items.asm8
-rwxr-xr-xhome/tables.asm32
2 files changed, 36 insertions, 4 deletions
diff --git a/home/items.asm b/home/items.asm
index 496b685..0edd72b 100755
--- a/home/items.asm
+++ b/home/items.asm
@@ -10,17 +10,17 @@ AddItemToInventory:: ; 3259
; 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)
-; [wcd76] = item ID
+; [wCurItem] = item ID
; [wItemQuantity] = item quantity
; sets carry flag if successful, unsets carry flag if unsuccessful
push bc
ldh a, [hROMBank]
push af
- ld a, BANK(AddItemToInventory_)
+ ld a, BANK(_ReceiveItem)
call Bankswitch
push hl
push de
- call AddItemToInventory_
+ call _ReceiveItem
pop de
pop hl
pop bc
@@ -41,7 +41,7 @@ GiveItem::
; Return carry on success.
ld a, b
ld [wce37], a
- ld [wcd76], a
+ ld [wCurItem], a
ld a, c
ld [wItemQuantity], a
ld hl, wNumBagItems
diff --git a/home/tables.asm b/home/tables.asm
new file mode 100755
index 0000000..6831d10
--- /dev/null
+++ b/home/tables.asm
@@ -0,0 +1,32 @@
+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
+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
+
+.fail
+ and a ; unset the carry flag to indicate failure
+ ret
+
+.success
+ scf ; set the carry flag to indicate success
+ ret \ No newline at end of file