From 243553acbadbe5cdddce3c7ea6ba8c188d48963a Mon Sep 17 00:00:00 2001 From: MadMaurice Date: Fri, 1 Sep 2023 23:43:24 +0200 Subject: [PATCH] cpu/cpu - Fix F register --- cpu/cpu.cpp | 22 +++++++++------------- cpu/cpu.h | 8 ++++---- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/cpu/cpu.cpp b/cpu/cpu.cpp index 11e37a0..dd84094 100644 --- a/cpu/cpu.cpp +++ b/cpu/cpu.cpp @@ -8,27 +8,23 @@ void Cpu_state::setAF(u16 v) { A = (u8)(v >> 8); - zero = (v & 0x80 != 0); - subtract = (v & 0x40 != 0); - halfcarry = (v & 0x20 != 0); - carry = (v & 0x10 != 0); + zero = ((v & F_ZERO) != 0); + subtract = ((v & F_SUB) != 0); + halfcarry = ((v & F_HALF) != 0); + carry = ((v & F_CARRY) != 0); } u16 Cpu_state::getAF() { - return ((u16)A << 8) | - (zero ? 0x80 : 0) | - (subtract ? 0x40 : 0) | - (halfcarry ? 0x20 : 0) | - (carry ? 0x10 : 0); + return ((u16)A << 8) | getF(); } u8 Cpu_state::getF() { - return (zero ? 0x80 : 0) | - (subtract ? 0x40 : 0) | - (halfcarry ? 0x20 : 0) | - (carry ? 0x10 : 0); + return (zero ? F_ZERO : 0) | + (subtract ? F_SUB : 0) | + (halfcarry ? F_HALF : 0) | + (carry ? F_CARRY : 0); } u8& Cpu_state::reg8(Cpu& cpu, u8 idx) diff --git a/cpu/cpu.h b/cpu/cpu.h index 46d749c..9ef67ec 100644 --- a/cpu/cpu.h +++ b/cpu/cpu.h @@ -8,10 +8,10 @@ typedef u8 opcode_t; enum Flags { - F_ZERO = 0x8, - F_SUB = 0x4, - F_HALF = 0x2, - F_CARRY = 0x1, + F_ZERO = 0x80, + F_SUB = 0x40, + F_HALF = 0x20, + F_CARRY = 0x10, }; enum AluOp : int {