diff --git a/LR35902/src/LR35902.cpp b/LR35902/src/LR35902.cpp index 693352d..f6b7937 100644 --- a/LR35902/src/LR35902.cpp +++ b/LR35902/src/LR35902.cpp @@ -13,7 +13,7 @@ EightBit::LR35902::LR35902(Bus& memory) void EightBit::LR35902::reset() { IntelProcessor::reset(); - SP().word = 0xfffe; + SP().word = Mask16 - 1; di(); } @@ -21,11 +21,10 @@ void EightBit::LR35902::initialise() { IntelProcessor::initialise(); - AF().word = 0xffff; - - BC().word = 0xffff; - DE().word = 0xffff; - HL().word = 0xffff; + AF().word = Mask16; + BC().word = Mask16; + DE().word = Mask16; + HL().word = Mask16; m_prefixCB = false; } @@ -687,13 +686,13 @@ void EightBit::LR35902::executeOther(int x, int y, int z, int p, int q) { break; case 5: { // GB: ADD SP,dd auto before = SP().word; - auto value = fetchByte(); - auto result = before + (int8_t)value; + int8_t value = fetchByte(); + auto result = before + value; SP().word = result; - auto carried = before ^ value ^ result; + auto carried = before ^ value ^ (result & Mask16); clearFlag(f, ZF | NF); - setFlag(f, CF, carried & 0x100); - setFlag(f, HC, carried & 0x10); + setFlag(f, CF, carried & Bit8); + setFlag(f, HC, carried & Bit4); } cycles += 4; break; @@ -703,13 +702,13 @@ void EightBit::LR35902::executeOther(int x, int y, int z, int p, int q) { break; case 7: { // GB: LD HL,SP + dd auto before = SP().word; - auto value = fetchByte(); - auto result = before + (int8_t)value; + int8_t value = fetchByte(); + auto result = before + value; HL().word = result; - auto carried = before ^ value ^ result; + auto carried = before ^ value ^ (result & Mask16); clearFlag(f, ZF | NF); - setFlag(f, CF, carried & 0x100); - setFlag(f, HC, carried & 0x10); + setFlag(f, CF, carried & Bit8); + setFlag(f, HC, carried & Bit4); } cycles += 3; break; diff --git a/inc/Processor.h b/inc/Processor.h index 94b4bdb..32a931f 100644 --- a/inc/Processor.h +++ b/inc/Processor.h @@ -36,6 +36,14 @@ namespace EightBit { Mask6 = Bit6 - 1, Mask7 = Bit7 - 1, Mask8 = Bit8 - 1, + Mask9 = Bit9 - 1, + Mask10 = Bit10 - 1, + Mask11 = Bit11 - 1, + Mask12 = Bit12 - 1, + Mask13 = Bit13 - 1, + Mask14 = Bit14 - 1, + Mask15 = Bit15 - 1, + Mask16 = Bit16 - 1, }; static int highNibble(int value) { return value >> 4; }