diff --git a/Intel8080/inc/Intel8080.h b/Intel8080/inc/Intel8080.h index aa1866c..fc12d3b 100644 --- a/Intel8080/inc/Intel8080.h +++ b/Intel8080/inc/Intel8080.h @@ -177,7 +177,7 @@ namespace EightBit { void stc(); void cmc(); - void xhtl(); + void xhtl(register16_t& exchange); void writePort(uint8_t port); void writePort(); diff --git a/Intel8080/src/Intel8080.cpp b/Intel8080/src/Intel8080.cpp index 22a1c78..d0d4244 100644 --- a/Intel8080/src/Intel8080.cpp +++ b/Intel8080/src/Intel8080.cpp @@ -237,14 +237,15 @@ void EightBit::Intel8080::cmc() { clearFlag(F(), CF, F() & CF); } -void EightBit::Intel8080::xhtl() { +void EightBit::Intel8080::xhtl(register16_t& exchange) { MEMPTR().low = busRead(SP()); - busWrite(L()); - L() = MEMPTR().low; ++BUS().ADDRESS(); MEMPTR().high = busRead(); - busWrite(H()); - H() = MEMPTR().high; + busWrite(exchange.high); + exchange.high = MEMPTR().high; + --BUS().ADDRESS(); + busWrite(exchange.low); + exchange.low = MEMPTR().low; } void EightBit::Intel8080::writePort(const uint8_t port) { @@ -543,7 +544,7 @@ void EightBit::Intel8080::execute(const int x, const int y, const int z, const i tick(11); break; case 4: // EX (SP),HL - xhtl(); + xhtl(HL()); tick(19); break; case 5: // EX DE,HL diff --git a/Z80/inc/Z80.h b/Z80/inc/Z80.h index 53838eb..a41c75b 100644 --- a/Z80/inc/Z80.h +++ b/Z80/inc/Z80.h @@ -343,7 +343,7 @@ namespace EightBit { void ccf(); void cpl(); - void xhtl(); + void xhtl(register16_t& exchange); void blockCompare(register16_t source, register16_t& counter); diff --git a/Z80/src/Z80.cpp b/Z80/src/Z80.cpp index 049763a..dbc689f 100644 --- a/Z80/src/Z80.cpp +++ b/Z80/src/Z80.cpp @@ -487,14 +487,15 @@ void EightBit::Z80::ccf() { adjustXY(F(), A()); } -void EightBit::Z80::xhtl() { +void EightBit::Z80::xhtl(register16_t& exchange) { MEMPTR().low = busRead(SP()); - busWrite(HL2().low); - HL2().low = MEMPTR().low; ++BUS().ADDRESS(); MEMPTR().high = busRead(); - busWrite(HL2().high); - HL2().high = MEMPTR().high; + busWrite(exchange.high); + exchange.high = MEMPTR().high; + --BUS().ADDRESS(); + busWrite(exchange.low); + exchange.low = MEMPTR().low; } void EightBit::Z80::blockCompare(const register16_t source, register16_t& counter) { @@ -592,9 +593,9 @@ bool EightBit::Z80::indr() { void EightBit::Z80::blockOut(const register16_t source, register16_t& destination) { const auto value = busRead(source); + destination.high = decrement(destination.high); BUS().ADDRESS() = destination; writePort(); - destination.high = decrement(destination.high); MEMPTR() = destination; setFlag(F(), NF, value & Bit7); setFlag(F(), HC | CF, (L() + value) > 0xff); @@ -790,7 +791,8 @@ void EightBit::Z80::executeCB(const int x, const int y, const int z) { tick(7); } else { busWrite(operand); - R2(z, operand); + if (LIKELY(!memoryZ)) + R2(z, operand); tick(15); } } @@ -1377,7 +1379,7 @@ void EightBit::Z80::executeOther(const int x, const int y, const int z, const in tick(11); break; case 4: // EX (SP),HL - xhtl(); + xhtl(HL2()); tick(19); break; case 5: // EX DE,HL diff --git a/inc/IntelProcessor.h b/inc/IntelProcessor.h index 538cccf..e2c34bf 100644 --- a/inc/IntelProcessor.h +++ b/inc/IntelProcessor.h @@ -161,9 +161,11 @@ namespace EightBit { } auto jrConditional(const int condition) { - const int8_t offset = fetchByte(); - if (condition) + const auto offsetAddress = PC()++; + if (condition) { + const auto offset = busRead(offsetAddress); jr(offset); + } return !!condition; }