From 8ef462f5c41a16005d49bdefe62876bb4dd51488 Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Wed, 4 Mar 2026 16:37:25 +0000 Subject: [PATCH] Fix some more timing issues --- Z80/inc/Z80.h | 2 +- Z80/src/Z80.cpp | 14 +++++++------- inc/IntelProcessor.h | 1 + src/IntelProcessor.cpp | 6 +++++- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Z80/inc/Z80.h b/Z80/inc/Z80.h index ad87314..073dd07 100644 --- a/Z80/inc/Z80.h +++ b/Z80/inc/Z80.h @@ -142,7 +142,7 @@ namespace EightBit { void jumpRelative(int8_t offset) noexcept final; - void call(register16_t destination) override; + void call(register16_t destination) final; private: bool m_interruptPending = false; diff --git a/Z80/src/Z80.cpp b/Z80/src/Z80.cpp index c50ddff..f8b2870 100644 --- a/Z80/src/Z80.cpp +++ b/Z80/src/Z80.cpp @@ -300,7 +300,6 @@ EightBit::register16_t EightBit::Z80::sbc(const register16_t operand, const regi MEMPTR() = operand + 1; - tick(7); return intermediate(); } @@ -455,7 +454,7 @@ void EightBit::Z80::adjustBlockRepeatFlagsIO() { void EightBit::Z80::adjustBlockInputOutputFlags(int basis) noexcept { setBit(HC | CF, basis > 0xff); - adjustParity(((basis & (int)Mask::Mask3) ^ B())); + adjustParity(((basis & Mask::Mask3) ^ B())); } void EightBit::Z80::adjustBlockInFlagsIncrement() noexcept { @@ -476,19 +475,21 @@ void EightBit::Z80::blockIn() noexcept { tick(); readPort(BC()); BUS().ADDRESS() = HL(); - memoryWrite(); + memoryUpdate(1); adjustSZXY(--B()); - F() = setBit(F(), NF); + setBit(NF, BUS().DATA() & SF); } void EightBit::Z80::ini() noexcept { blockIn(); + adjustBlockInFlagsIncrement(); ++HL(); ++MEMPTR(); } void EightBit::Z80::ind() noexcept { blockIn(); + adjustBlockInFlagsDecrement(); --HL(); --MEMPTR(); } @@ -607,7 +608,6 @@ void EightBit::Z80::readPort(const uint8_t port) noexcept { void EightBit::Z80::readPort() noexcept { MEMPTR() = BUS().ADDRESS(); tick(2); - tick(); lowerIORQ(); lowerRD(); BUS().DATA() = m_ports.read(BUS().ADDRESS()); @@ -674,7 +674,6 @@ void EightBit::Z80::readInternalRegister(reader_t reader) noexcept { adjustSZXY(A() = reader()); clearBit(NF | HC); setBit(PF, IFF2()); - tick(); } EightBit::register16_t& EightBit::Z80::HL2() noexcept { @@ -905,7 +904,7 @@ void EightBit::Z80::executeCB(const int x, const int y, const int z) noexcept { if (!memoryZ) R2(z, operand); } else { - R(z, operand); + R(z, operand, 2); } } } @@ -1002,6 +1001,7 @@ void EightBit::Z80::executeED(const int x, const int y, const int z, const int p break; case 2: // LD A,I readInternalRegister([this]() { return IV(); }); + tick(); break; case 3: // LD A,R readInternalRegister([this]() { return REFRESH(); }); diff --git a/inc/IntelProcessor.h b/inc/IntelProcessor.h index 8fa04c4..930b350 100644 --- a/inc/IntelProcessor.h +++ b/inc/IntelProcessor.h @@ -169,6 +169,7 @@ namespace EightBit { virtual void jump(); void callIndirect(); void call(); + virtual void call(register16_t destination); virtual void jumpRelative(int8_t offset) noexcept; void jumpRelative(uint8_t offset) noexcept { jumpRelative((int8_t)offset); } void ret() override; diff --git a/src/IntelProcessor.cpp b/src/IntelProcessor.cpp index e2328c6..3db15d8 100644 --- a/src/IntelProcessor.cpp +++ b/src/IntelProcessor.cpp @@ -133,7 +133,11 @@ void EightBit::IntelProcessor::callIndirect() { } void EightBit::IntelProcessor::call() { - Processor::call(MEMPTR()); + call(MEMPTR()); +} + +void EightBit::IntelProcessor::call(register16_t destination) { + Processor::call(destination); } bool EightBit::IntelProcessor::operator==(const EightBit::IntelProcessor& rhs) const noexcept {