Start correcting Z80 T-cycle counts (DJNZ, JR cc, ADD HL,rp, INC/DEC rp, INC/DEC (HL))

Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon 2020-02-16 09:18:34 +00:00
parent a37601df67
commit b89d2cf15c
3 changed files with 20 additions and 7 deletions

View File

@ -128,6 +128,17 @@ namespace EightBit {
void busWrite() final;
uint8_t busRead() final;
void jr(int8_t offset) final {
IntelProcessor::jr(offset);
tick(5);
}
int jrConditional(const int condition) final {
if (!IntelProcessor::jrConditional(condition))
tick(3);
return condition;
}
private:
enum { BC_IDX, DE_IDX, HL_IDX };

View File

@ -1048,9 +1048,7 @@ void EightBit::Z80::executeOther(const int x, const int y, const int z, const in
break;
case 2: // DJNZ d
tick();
if (jrConditional(--B()))
tick(2);
tick(3);
jrConditional(--B());
break;
case 3: // JR d
jr(fetchByte());
@ -1072,6 +1070,7 @@ void EightBit::Z80::executeOther(const int x, const int y, const int z, const in
break;
case 1: // ADD HL,rp
HL2() = add(F(), HL2(), RP(p));
tick(7);
break;
default:
UNREACHABLE;
@ -1141,6 +1140,7 @@ void EightBit::Z80::executeOther(const int x, const int y, const int z, const in
default:
UNREACHABLE;
}
tick(2);
break;
case 4: { // 8-bit INC
if (memoryY && m_displaced) {
@ -1148,7 +1148,8 @@ void EightBit::Z80::executeOther(const int x, const int y, const int z, const in
tick(5);
}
const auto original = R(y);
tick();
if (memoryY)
tick();
R(y, increment(F(), original));
break;
}
@ -1158,7 +1159,8 @@ void EightBit::Z80::executeOther(const int x, const int y, const int z, const in
tick(5);
}
const auto original = R(y);
tick();
if (memoryY)
tick();
R(y, decrement(F(), original));
break;
}

View File

@ -154,11 +154,11 @@ namespace EightBit {
return condition;
}
void jr(const int8_t offset) noexcept {
virtual void jr(const int8_t offset) {
jump(MEMPTR() = PC() + offset);
}
auto jrConditional(const int condition) {
virtual int jrConditional(const int condition) {
const auto offsetAddress = PC()++;
if (condition) {
const auto offset = memoryRead(offsetAddress);