diff --git a/Intel8080/inc/Intel8080.h b/Intel8080/inc/Intel8080.h index d0dd064..711a529 100644 --- a/Intel8080/inc/Intel8080.h +++ b/Intel8080/inc/Intel8080.h @@ -38,12 +38,7 @@ namespace EightBit { const std::array& getInstructions() const { return instructions; } - register16_t& AF() { - af.low &= ~(Bit5 | Bit3); - af.low |= Bit1; - return af; - } - + register16_t& AF() { return af; } uint8_t& A() { return AF().high; } uint8_t& F() { return AF().low; } @@ -105,6 +100,11 @@ namespace EightBit { return cycles + instruction.count; } + void adjustReservedFlags() { + AF().low &= ~(Bit5 | Bit3); + AF().low |= Bit1; + } + void adjustSign(uint8_t value) { setFlag(SF, value & SF); } void adjustZero(uint8_t value) { clearFlag(ZF, value);} @@ -343,7 +343,11 @@ namespace EightBit { void pop_b() { popWord(BC()); } void pop_d() { popWord(DE()); } void pop_h() { popWord(HL()); } - void pop_psw() { popWord(AF()); } + + void pop_psw() { + popWord(AF()); + adjustReservedFlags(); + } void xhtl() { auto tos = m_memory.getWord(sp.word);