diff options
author | YamaArashi <shadow962@live.com> | 2016-12-31 17:23:54 -0800 |
---|---|---|
committer | YamaArashi <shadow962@live.com> | 2016-12-31 17:23:54 -0800 |
commit | bf67f7174d8e3f1348c786618ee5a3a076d1eff8 (patch) | |
tree | 41dfcd420ce30d4b077d2055e096ea40e4a229a5 /engine/flag_action.asm | |
parent | 10289bf7ddac46d0188da06f2714dbce0dece59c (diff) |
split code out of main.asm
Diffstat (limited to 'engine/flag_action.asm')
-rw-r--r-- | engine/flag_action.asm | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/engine/flag_action.asm b/engine/flag_action.asm new file mode 100644 index 00000000..dc516887 --- /dev/null +++ b/engine/flag_action.asm @@ -0,0 +1,73 @@ +FlagActionPredef: + call GetPredefRegisters + +FlagAction: +; Perform action b on bit c +; in the bitfield at hl. +; 0: reset +; 1: set +; 2: read +; Return the result in c. + + push hl + push de + push bc + + ; bit + ld a, c + ld d, a + and 7 + ld e, a + + ; byte + ld a, d + srl a + srl a + srl a + add l + ld l, a + jr nc, .ok + inc h +.ok + + ; d = 1 << e (bitmask) + inc e + ld d, 1 +.shift + dec e + jr z, .shifted + sla d + jr .shift +.shifted + + ld a, b + and a + jr z, .reset + cp 2 + jr z, .read + +.set + ld b, [hl] + ld a, d + or b + ld [hl], a + jr .done + +.reset + ld b, [hl] + ld a, d + xor $ff + and b + ld [hl], a + jr .done + +.read + ld b, [hl] + ld a, d + and b +.done + pop bc + pop de + pop hl + ld c, a + ret |