summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPokeglitch <pokeglitchx@gmail.com>2018-06-13 21:05:24 -0400
committerPokeglitch <pokeglitchx@gmail.com>2018-06-13 21:05:24 -0400
commitb84c9c4974c6e9fecfab0cbdee9879815c62dff0 (patch)
treef6cd5ba969dc6b7fd790a634780e8cce431612d2
parentf7f29000a85389291798ec5d97b51dc65e7b500e (diff)
Extracted a few more bank 3 routines
-rw-r--r--constants/item_constants.asm2
-rwxr-xr-xengine/items/inventory.asm23
-rwxr-xr-xengine/smallflag.asm72
-rwxr-xr-xhome/items.asm24
4 files changed, 117 insertions, 4 deletions
diff --git a/constants/item_constants.asm b/constants/item_constants.asm
index 30af41c..ebc3aee 100644
--- a/constants/item_constants.asm
+++ b/constants/item_constants.asm
@@ -261,6 +261,8 @@ NUM_TMS = const_value - ITEM_TM01 - 2 ; discount ITEM_C8 and ITEM_E1
const ITEM_HM07 ; fe *
NUM_HMS = const_value - ITEM_HM01
+ const ITEM_FF
+
NUM_TMS_HMS = NUM_TMS + NUM_HMS
; leftovers from pokered
diff --git a/engine/items/inventory.asm b/engine/items/inventory.asm
index 4a95bac..3a397eb 100755
--- a/engine/items/inventory.asm
+++ b/engine/items/inventory.asm
@@ -570,6 +570,29 @@ GetTMHMNumber: ; 03:4CFF
.not_machine
and a
ret
+
+GetNumberedTMHM: ; 03:4D1A
+; Return the item id of a TM/HM by number c.
+ ld a, c
+ ld c, 0
+; Adjust for any dummy items.
+ cp ITEM_C8 - ITEM_TM01 ; TM01-04
+ jr c, .adjust
+ inc c
+ cp ITEM_E1 - ITEM_TM01 - 1 ; TM28 - TM05
+ jr c, .adjust
+ inc c
+ cp ITEM_FF - ITEM_TM01 - 2 ; End of list
+ jr nc, .dont_adjust
+.adjust
+ add c
+ add ITEM_TM01
+ ld c, a
+ scf
+ ret
+.dont_adjust
+ and a
+ ret
SECTION "_CheckTossableItem", ROMX[$53AD], BANK[$03]
diff --git a/engine/smallflag.asm b/engine/smallflag.asm
new file mode 100755
index 0000000..f95dfb9
--- /dev/null
+++ b/engine/smallflag.asm
@@ -0,0 +1,72 @@
+SECTION "SmallFarFlagAction", ROMX[$4d33], BANK[$03]
+
+SmallFarFlagAction: ; 4d7c1
+; Perform action b on bit c in flag array hl.
+; If checking a flag, check flag array d:hl unless d is 0.
+
+; For longer flag arrays, see FlagAction.
+
+ push hl
+ push bc
+
+; Divide by 8 to get the byte we want.
+ push bc
+ srl c
+ srl c
+ srl c
+ ld b, 0
+ add hl, bc
+ pop bc
+
+; Which bit we want from the byte
+ ld a, c
+ and 7
+ ld c, a
+
+; Shift left until we can mask the bit
+ ld a, 1
+ jr z, .shifted
+.shift
+ add a
+ dec c
+ jr nz, .shift
+.shifted
+ ld c, a
+
+; What are we doing to this flag?
+ dec b
+ jr z, .set ; 1
+ dec b
+ jr z, .check ; 2
+
+.reset
+ ld a, c
+ cpl
+ and [hl]
+ ld [hl], a
+ jr .done
+
+.set
+ ld a, [hl]
+ or c
+ ld [hl], a
+ jr .done
+
+.check
+ ld a, d
+ cp 0
+ jr nz, .farcheck
+
+ ld a, [hl]
+ and c
+ jr .done
+
+.farcheck
+ call GetFarByte
+ and c
+
+.done
+ pop bc
+ pop hl
+ ld c, a
+ ret \ No newline at end of file
diff --git a/home/items.asm b/home/items.asm
index 498edc6..46f510c 100755
--- a/home/items.asm
+++ b/home/items.asm
@@ -1,12 +1,28 @@
INCLUDE "constants.asm"
if DEBUG
-SECTION "AddItemToInventory", ROM0[$3259]
+SECTION "TossItem", ROM0[$3243]
else
-SECTION "AddItemToInventory", ROM0[$321D]
+SECTION "TossItem", ROM0[$3207]
endc
-AddItemToInventory:: ; 3259
+TossItem: ; 00:3243
+ ldh a, [hROMBank]
+ push af
+ ld a, BANK(_TossItem)
+ call Bankswitch
+ push hl
+ push de
+ push bc
+ call _TossItem
+ pop bc
+ pop de
+ pop hl
+ pop af
+ call Bankswitch
+ ret
+
+ReceiveItem:: ; 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)
@@ -45,7 +61,7 @@ GiveItem::
ld a, c
ld [wItemQuantity], a
ld hl, wNumBagItems
- call AddItemToInventory
+ call ReceiveItem
ret nc
call GetItemName
call CopyStringToCD31