summaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authorRemy Oukaour <remy.oukaour@gmail.com>2017-12-16 12:49:43 -0500
committerRemy Oukaour <remy.oukaour@gmail.com>2017-12-16 12:49:43 -0500
commit05d49f7d752b03cbccb2fdcca2781a8a5de85425 (patch)
tree9b6e329d55c252e16555891fad8f694f97e8e7f7 /engine
parentaa44ecfc4ff7e85629825c7068a014794b206463 (diff)
Move more code out of main.asm
Diffstat (limited to 'engine')
-rw-r--r--engine/flag_predef.asm70
-rw-r--r--engine/item_effects.asm1
2 files changed, 71 insertions, 0 deletions
diff --git a/engine/flag_predef.asm b/engine/flag_predef.asm
new file mode 100644
index 000000000..bd4f37882
--- /dev/null
+++ b/engine/flag_predef.asm
@@ -0,0 +1,70 @@
+FlagPredef: ; 4d7c1
+; Perform action b on flag 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
diff --git a/engine/item_effects.asm b/engine/item_effects.asm
index cc2132034..d1b5e7161 100644
--- a/engine/item_effects.asm
+++ b/engine/item_effects.asm
@@ -14,6 +14,7 @@ _DoItemEffect:: ; e722
ItemEffects: ; e73c
+; entries correspond to item ids (see constants/item_constants.asm)
dw MasterBall
dw UltraBall
dw Brightpowder