2018-06-24 14:09:41 +00:00
|
|
|
EngineFlagAction::
|
2015-11-19 23:07:20 +00:00
|
|
|
; Do action b on engine flag de
|
|
|
|
;
|
|
|
|
; b = 0: reset flag
|
|
|
|
; = 1: set flag
|
|
|
|
; > 1: check flag, result in c
|
|
|
|
;
|
|
|
|
; Setting/resetting does not return a result.
|
|
|
|
|
|
|
|
; 16-bit flag ids are considered invalid, but it's nice
|
|
|
|
; to know that the infrastructure is there.
|
|
|
|
|
|
|
|
ld a, d
|
2018-12-23 08:45:41 +00:00
|
|
|
cp HIGH(NUM_ENGINE_FLAGS)
|
2015-11-19 23:07:20 +00:00
|
|
|
jr z, .ceiling
|
|
|
|
jr c, .read ; cp 0 can't set carry!
|
|
|
|
jr .invalid
|
|
|
|
|
2018-12-23 08:45:41 +00:00
|
|
|
; There are only NUM_ENGINE_FLAGS engine flags, so
|
2015-11-19 23:07:20 +00:00
|
|
|
; anything beyond that is invalid too.
|
|
|
|
|
|
|
|
.ceiling
|
|
|
|
ld a, e
|
2018-12-23 08:45:41 +00:00
|
|
|
cp LOW(NUM_ENGINE_FLAGS)
|
2015-11-19 23:07:20 +00:00
|
|
|
jr c, .read
|
|
|
|
|
|
|
|
; Invalid flags are treated as flag 00.
|
|
|
|
|
|
|
|
.invalid
|
|
|
|
xor a
|
|
|
|
ld e, a
|
|
|
|
ld d, a
|
|
|
|
|
|
|
|
; Get this flag's location.
|
|
|
|
|
|
|
|
.read
|
|
|
|
ld hl, EngineFlags
|
|
|
|
; location
|
|
|
|
add hl, de
|
2015-12-27 02:59:03 +00:00
|
|
|
add hl, de
|
2015-11-19 23:07:20 +00:00
|
|
|
; bit
|
|
|
|
add hl, de
|
|
|
|
|
|
|
|
; location
|
|
|
|
ld e, [hl]
|
|
|
|
inc hl
|
|
|
|
ld d, [hl]
|
|
|
|
inc hl
|
|
|
|
; bit
|
|
|
|
ld c, [hl]
|
|
|
|
|
|
|
|
; What are we doing with this flag?
|
|
|
|
|
|
|
|
ld a, b
|
|
|
|
cp 1
|
|
|
|
jr c, .reset ; b = 0
|
|
|
|
jr z, .set ; b = 1
|
|
|
|
|
|
|
|
; Return the given flag in c.
|
|
|
|
.check
|
|
|
|
ld a, [de]
|
|
|
|
and c
|
|
|
|
ld c, a
|
|
|
|
ret
|
|
|
|
|
|
|
|
; Set the given flag.
|
|
|
|
.set
|
|
|
|
ld a, [de]
|
|
|
|
or c
|
|
|
|
ld [de], a
|
|
|
|
ret
|
|
|
|
|
|
|
|
; Reset the given flag.
|
|
|
|
.reset
|
|
|
|
ld a, c
|
|
|
|
cpl ; AND all bits except the one in question
|
|
|
|
ld c, a
|
|
|
|
ld a, [de]
|
|
|
|
and c
|
|
|
|
ld [de], a
|
|
|
|
ret
|
|
|
|
|
2020-07-22 19:22:58 +00:00
|
|
|
INCLUDE "data/events/engine_flags.asm"
|