summaryrefslogtreecommitdiff
path: root/engine/events/engine_flags.asm
diff options
context:
space:
mode:
authormid-kid <esteve.varela@gmail.com>2018-03-25 16:18:33 +0200
committermid-kid <esteve.varela@gmail.com>2018-03-25 16:18:33 +0200
commit0d9241889fc8a2f047b9fd6db25e55de1e721877 (patch)
tree4ae588ae9d97639b456e6d2ba64a94676ddcf703 /engine/events/engine_flags.asm
parent60e21a86638cad5fd25133cda1c545461304d902 (diff)
Organize the engine/ directory, take 3
Renamed `title` to `movies`. Moved some functions from `engine/routines/` to their fitting directories, and cleaned up the base `engine/` directory. Moved `engine/pokemon/tmhm.asm` back to `engine/items/`. Made a new subdirectory: * engine/tilesets: Contains all map-related graphics routines.
Diffstat (limited to 'engine/events/engine_flags.asm')
-rw-r--r--engine/events/engine_flags.asm86
1 files changed, 86 insertions, 0 deletions
diff --git a/engine/events/engine_flags.asm b/engine/events/engine_flags.asm
new file mode 100644
index 000000000..acda9ede7
--- /dev/null
+++ b/engine/events/engine_flags.asm
@@ -0,0 +1,86 @@
+EngineFlagAction:: ; 80430
+; 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
+ cp 0
+ jr z, .ceiling
+ jr c, .read ; cp 0 can't set carry!
+ jr .invalid
+
+; There are only $a2 engine flags, so
+; anything beyond that is invalid too.
+
+.ceiling
+ ld a, e
+ cp NUM_ENGINE_FLAGS
+ 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
+ add hl, de
+; 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
+; 80462
+
+
+INCLUDE "data/engine_flags.asm"