summaryrefslogtreecommitdiff
path: root/engine
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 /engine
parentf7f29000a85389291798ec5d97b51dc65e7b500e (diff)
Extracted a few more bank 3 routines
Diffstat (limited to 'engine')
-rwxr-xr-xengine/items/inventory.asm23
-rwxr-xr-xengine/smallflag.asm72
2 files changed, 95 insertions, 0 deletions
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