diff options
| author | James Barnett <noreply@jamesbarnett.xyz> | 2018-06-28 21:38:42 +0100 |
|---|---|---|
| committer | James Barnett <noreply@jamesbarnett.xyz> | 2018-06-28 21:38:42 +0100 |
| commit | dfbf83a9a42907063aa5b3789f1ce9606de32e84 (patch) | |
| tree | eea8e2232f9f6b8841bcf4a3a740cf895afdd629 /src/main/kotlin/cpu/Registers.kt | |
| parent | 6f87feb0c835589adcd566323e058a9158860071 (diff) | |
| download | KGB-dfbf83a9a42907063aa5b3789f1ce9606de32e84.tar.xz KGB-dfbf83a9a42907063aa5b3789f1ce9606de32e84.zip | |
Add register flags and set from LDHL SP,n op
Diffstat (limited to 'src/main/kotlin/cpu/Registers.kt')
| -rw-r--r-- | src/main/kotlin/cpu/Registers.kt | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/main/kotlin/cpu/Registers.kt b/src/main/kotlin/cpu/Registers.kt index 70c7f06..54539a8 100644 --- a/src/main/kotlin/cpu/Registers.kt +++ b/src/main/kotlin/cpu/Registers.kt @@ -131,4 +131,36 @@ class Registers { return currentSP } + fun getFlag(flag: Flag): Int { + return (F shr flag.bitPosition) and 0x01 + } + + fun setFlag(flag: Flag) { + F = F or (1 shl flag.bitPosition) + } + + fun clearFlag(flag: Flag) { + F = F and (1 shl flag.bitPosition).inv() + } + + fun setFlagFromBool(flag: Flag, isSet: Boolean) { + if(isSet) { + setFlag(flag) + } + else { + clearFlag(flag) + } + } + + fun clearFlags() { + F = 0x00 + } + + enum class Flag(val bitPosition: Int) { + ZERO(7), + SUBTRACT(6), + HALF_CARRY(5), + CARRY(4), + } + }
\ No newline at end of file |