mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2025-01-03 09:29:50 +00:00
A few modifications:
1) Simplify REFRESH register handling via bit fields. 2) Use static methods in the Z80 emulator, if at all possible 3) Use a decoded opcode lookup, rather than decoding per instruction Signed-off-by: Adrian.Conlon <adrian.conlon@gmail.com>
This commit is contained in:
parent
d22b695682
commit
c803387023
@ -45,7 +45,7 @@ void Fuse::TestRunner::initialiseRegisters() {
|
|||||||
m_cpu.MEMPTR() = inputRegisters[Fuse::RegisterState::MEMPTR];
|
m_cpu.MEMPTR() = inputRegisters[Fuse::RegisterState::MEMPTR];
|
||||||
|
|
||||||
m_cpu.IV() = testState.i;
|
m_cpu.IV() = testState.i;
|
||||||
m_cpu.REFRESH() = testState.r;
|
m_cpu.REFRESH() = EightBit::Z80::refresh_t::fromUint8(testState.r);
|
||||||
m_cpu.IFF1() = testState.iff1;
|
m_cpu.IFF1() = testState.iff1;
|
||||||
m_cpu.IFF2() = testState.iff2;
|
m_cpu.IFF2() = testState.iff2;
|
||||||
m_cpu.IM() = testState.im;
|
m_cpu.IM() = testState.im;
|
||||||
@ -121,7 +121,7 @@ void Fuse::TestRunner::checkregisters() {
|
|||||||
auto memptr = m_cpu.MEMPTR().word == expectedRegisters[Fuse::RegisterState::MEMPTR].word;
|
auto memptr = m_cpu.MEMPTR().word == expectedRegisters[Fuse::RegisterState::MEMPTR].word;
|
||||||
|
|
||||||
auto iv = m_cpu.IV() == expectedState.i;
|
auto iv = m_cpu.IV() == expectedState.i;
|
||||||
auto refresh = m_cpu.REFRESH() == expectedState.r;
|
auto refresh = m_cpu.REFRESH().asUint8() == expectedState.r;
|
||||||
auto iff1 = m_cpu.IFF1() == expectedState.iff1;
|
auto iff1 = m_cpu.IFF1() == expectedState.iff1;
|
||||||
auto iff2 = m_cpu.IFF2() == expectedState.iff2;
|
auto iff2 = m_cpu.IFF2() == expectedState.iff2;
|
||||||
auto im = m_cpu.IM() == expectedState.im;
|
auto im = m_cpu.IM() == expectedState.im;
|
||||||
@ -263,7 +263,7 @@ void Fuse::TestRunner::checkregisters() {
|
|||||||
<< "**** R, Expected: "
|
<< "**** R, Expected: "
|
||||||
<< EightBit::Disassembler::hex((uint8_t)expectedState.r)
|
<< EightBit::Disassembler::hex((uint8_t)expectedState.r)
|
||||||
<< ", Got: "
|
<< ", Got: "
|
||||||
<< EightBit::Disassembler::hex(m_cpu.REFRESH())
|
<< EightBit::Disassembler::hex(m_cpu.REFRESH().variable)
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
105
Z80/inc/Z80.h
105
Z80/inc/Z80.h
@ -9,6 +9,42 @@
|
|||||||
namespace EightBit {
|
namespace EightBit {
|
||||||
class Z80 : public IntelProcessor {
|
class Z80 : public IntelProcessor {
|
||||||
public:
|
public:
|
||||||
|
struct refresh_t {
|
||||||
|
|
||||||
|
bool high : 1;
|
||||||
|
uint8_t variable : 7;
|
||||||
|
|
||||||
|
uint8_t asUint8() const {
|
||||||
|
return (high << 7) | variable;
|
||||||
|
}
|
||||||
|
|
||||||
|
static refresh_t fromUint8(uint8_t value) {
|
||||||
|
refresh_t returned;
|
||||||
|
returned.high = (value & Bit7) != 0;
|
||||||
|
returned.variable = value & Mask7;
|
||||||
|
return returned;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct opcode_decoded_t {
|
||||||
|
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
int z;
|
||||||
|
int p;
|
||||||
|
int q;
|
||||||
|
|
||||||
|
static opcode_decoded_t decode(uint8_t opcode) {
|
||||||
|
opcode_decoded_t returned;
|
||||||
|
returned.x = (opcode & 0b11000000) >> 6;
|
||||||
|
returned.y = (opcode & 0b00111000) >> 3;
|
||||||
|
returned.z = (opcode & 0b00000111);
|
||||||
|
returned.p = (returned.y & 0b110) >> 1;
|
||||||
|
returned.q = (returned.y & 1);
|
||||||
|
return returned;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
enum StatusBits {
|
enum StatusBits {
|
||||||
SF = Bit7,
|
SF = Bit7,
|
||||||
ZF = Bit6,
|
ZF = Bit6,
|
||||||
@ -63,7 +99,7 @@ namespace EightBit {
|
|||||||
uint8_t& IYH() { return IY().high; }
|
uint8_t& IYH() { return IY().high; }
|
||||||
uint8_t& IYL() { return IY().low; }
|
uint8_t& IYL() { return IY().low; }
|
||||||
|
|
||||||
uint8_t& REFRESH() { return m_refresh; }
|
refresh_t& REFRESH() { return m_refresh; }
|
||||||
uint8_t& IV() { return iv; }
|
uint8_t& IV() { return iv; }
|
||||||
int& IM() { return m_interruptMode; }
|
int& IM() { return m_interruptMode; }
|
||||||
bool& IFF1() { return m_iff1; }
|
bool& IFF1() { return m_iff1; }
|
||||||
@ -96,7 +132,8 @@ namespace EightBit {
|
|||||||
register16_t m_ix;
|
register16_t m_ix;
|
||||||
register16_t m_iy;
|
register16_t m_iy;
|
||||||
|
|
||||||
uint8_t m_refresh;
|
refresh_t m_refresh;
|
||||||
|
|
||||||
uint8_t iv;
|
uint8_t iv;
|
||||||
int m_interruptMode;
|
int m_interruptMode;
|
||||||
bool m_iff1;
|
bool m_iff1;
|
||||||
@ -112,13 +149,15 @@ namespace EightBit {
|
|||||||
int8_t m_displacement;
|
int8_t m_displacement;
|
||||||
bool m_displaced;
|
bool m_displaced;
|
||||||
|
|
||||||
|
std::array<opcode_decoded_t, 0x100> m_decodedOpcodes;
|
||||||
|
|
||||||
int fetchExecute() {
|
int fetchExecute() {
|
||||||
M1() = true;
|
M1() = true;
|
||||||
return execute(fetchByte());
|
return execute(fetchByte());
|
||||||
}
|
}
|
||||||
|
|
||||||
void incrementRefresh() {
|
void incrementRefresh() {
|
||||||
REFRESH() = (REFRESH() & Bit7) | (REFRESH() + 1) & Mask7;
|
REFRESH().variable++;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t& DISPLACED() {
|
uint8_t& DISPLACED() {
|
||||||
@ -191,8 +230,8 @@ namespace EightBit {
|
|||||||
if (m_displaced) {
|
if (m_displaced) {
|
||||||
if (m_prefixDD)
|
if (m_prefixDD)
|
||||||
return IX();
|
return IX();
|
||||||
else if (m_prefixFD)
|
// Must be FD prefix
|
||||||
return IY();
|
return IY();
|
||||||
}
|
}
|
||||||
return HL();
|
return HL();
|
||||||
}
|
}
|
||||||
@ -249,47 +288,49 @@ namespace EightBit {
|
|||||||
setFlag(f, VF, overflow);
|
setFlag(f, VF, overflow);
|
||||||
}
|
}
|
||||||
|
|
||||||
void executeCB(int x, int y, int z, int p, int q);
|
static void subtract(uint8_t& f, uint8_t& operand, uint8_t value, int carry = 0);
|
||||||
|
|
||||||
|
void executeCB(int x, int y, int z);
|
||||||
void executeED(int x, int y, int z, int p, int q);
|
void executeED(int x, int y, int z, int p, int q);
|
||||||
void executeOther(int x, int y, int z, int p, int q);
|
void executeOther(int x, int y, int z, int p, int q);
|
||||||
|
|
||||||
void postIncrement(uint8_t& f, uint8_t value);
|
static void postIncrement(uint8_t& f, uint8_t value);
|
||||||
void postDecrement(uint8_t& f, uint8_t value);
|
static void postDecrement(uint8_t& f, uint8_t value);
|
||||||
|
|
||||||
void retn();
|
void retn();
|
||||||
void reti();
|
void reti();
|
||||||
|
|
||||||
bool jrConditionalFlag(int flag);
|
bool jrConditionalFlag(uint8_t& f, int flag);
|
||||||
bool returnConditionalFlag(int flag);
|
bool returnConditionalFlag(uint8_t& f, int flag);
|
||||||
bool jumpConditionalFlag(int flag);
|
bool jumpConditionalFlag(uint8_t& f, int flag);
|
||||||
bool callConditionalFlag(int flag);
|
bool callConditionalFlag(uint8_t& f, int flag);
|
||||||
|
|
||||||
void sbc(register16_t& operand, register16_t value);
|
void sbc(register16_t& operand, register16_t value);
|
||||||
void adc(register16_t& operand, register16_t value);
|
void adc(register16_t& operand, register16_t value);
|
||||||
|
|
||||||
void add(register16_t& operand, register16_t value);
|
void add(register16_t& operand, register16_t value);
|
||||||
|
|
||||||
void add(uint8_t& operand, uint8_t value, int carry = 0);
|
static void add(uint8_t& f, uint8_t& operand, uint8_t value, int carry = 0);
|
||||||
void adc(uint8_t& operand, uint8_t value);
|
void adc(uint8_t& operand, uint8_t value);
|
||||||
void sub(uint8_t& operand, uint8_t value, int carry = 0);
|
static void sub(uint8_t& f, uint8_t& operand, uint8_t value, int carry = 0);
|
||||||
void sbc(uint8_t& operand, uint8_t value);
|
void sbc(uint8_t& operand, uint8_t value);
|
||||||
void andr(uint8_t& operand, uint8_t value);
|
static void andr(uint8_t& f, uint8_t& operand, uint8_t value);
|
||||||
void xorr(uint8_t& operand, uint8_t value);
|
static void xorr(uint8_t& f, uint8_t& operand, uint8_t value);
|
||||||
void orr(uint8_t& operand, uint8_t value);
|
static void orr(uint8_t& f, uint8_t& operand, uint8_t value);
|
||||||
void compare(uint8_t value);
|
static void compare(uint8_t& f, uint8_t check, uint8_t value);
|
||||||
|
|
||||||
uint8_t& rlc(uint8_t& operand);
|
static uint8_t& rlc(uint8_t& f, uint8_t& operand);
|
||||||
uint8_t& rrc(uint8_t& operand);
|
static uint8_t& rrc(uint8_t& f, uint8_t& operand);
|
||||||
uint8_t& rl(uint8_t& operand);
|
static uint8_t& rl(uint8_t& f, uint8_t& operand);
|
||||||
uint8_t& rr(uint8_t& operand);
|
static uint8_t& rr(uint8_t& f, uint8_t& operand);
|
||||||
uint8_t& sla(uint8_t& operand);
|
static uint8_t& sla(uint8_t& f, uint8_t& operand);
|
||||||
uint8_t& sra(uint8_t& operand);
|
static uint8_t& sra(uint8_t& f, uint8_t& operand);
|
||||||
uint8_t& sll(uint8_t& operand);
|
static uint8_t& sll(uint8_t& f, uint8_t& operand);
|
||||||
uint8_t& srl(uint8_t& operand);
|
static uint8_t& srl(uint8_t& f, uint8_t& operand);
|
||||||
|
|
||||||
uint8_t& bit(int n, uint8_t& operand);
|
static uint8_t& bit(uint8_t& f, int n, uint8_t& operand);
|
||||||
uint8_t& res(int n, uint8_t& operand);
|
static uint8_t& res(int n, uint8_t& operand);
|
||||||
uint8_t& set(int nit, uint8_t& operand);
|
static uint8_t& set(int nit, uint8_t& operand);
|
||||||
|
|
||||||
void daa();
|
void daa();
|
||||||
|
|
||||||
@ -300,12 +341,12 @@ namespace EightBit {
|
|||||||
void xhtl(register16_t& operand);
|
void xhtl(register16_t& operand);
|
||||||
void xhtl();
|
void xhtl();
|
||||||
|
|
||||||
void blockCompare();
|
void blockCompare(uint8_t a, uint8_t& f);
|
||||||
|
|
||||||
void cpi();
|
void cpi(uint8_t a, uint8_t& f);
|
||||||
bool cpir();
|
bool cpir();
|
||||||
|
|
||||||
void cpd();
|
void cpd(uint8_t a, uint8_t& f);
|
||||||
bool cpdr();
|
bool cpdr();
|
||||||
|
|
||||||
void blockLoad(register16_t source, register16_t destination);
|
void blockLoad(register16_t source, register16_t destination);
|
||||||
|
@ -31,7 +31,7 @@ std::string EightBit::Disassembler::state(Z80& cpu) {
|
|||||||
auto l = cpu.L();
|
auto l = cpu.L();
|
||||||
|
|
||||||
auto i = cpu.IV();
|
auto i = cpu.IV();
|
||||||
auto r = cpu.REFRESH();
|
auto r = cpu.REFRESH().asUint8();
|
||||||
|
|
||||||
auto im = cpu.IM();
|
auto im = cpu.IM();
|
||||||
|
|
||||||
|
329
Z80/src/Z80.cpp
329
Z80/src/Z80.cpp
@ -9,7 +9,6 @@ EightBit::Z80::Z80(Memory& memory, InputOutput& ports)
|
|||||||
m_ports(ports),
|
m_ports(ports),
|
||||||
m_registerSet(0),
|
m_registerSet(0),
|
||||||
m_accumulatorFlagsSet(0),
|
m_accumulatorFlagsSet(0),
|
||||||
m_refresh(0x7f),
|
|
||||||
iv(0xff),
|
iv(0xff),
|
||||||
m_interruptMode(0),
|
m_interruptMode(0),
|
||||||
m_iff1(false),
|
m_iff1(false),
|
||||||
@ -21,8 +20,11 @@ EightBit::Z80::Z80(Memory& memory, InputOutput& ports)
|
|||||||
m_prefixFD(false),
|
m_prefixFD(false),
|
||||||
m_displacement(0),
|
m_displacement(0),
|
||||||
m_displaced(false) {
|
m_displaced(false) {
|
||||||
|
|
||||||
IX().word = 0xffff;
|
IX().word = 0xffff;
|
||||||
IY().word = 0xffff;
|
IY().word = 0xffff;
|
||||||
|
|
||||||
|
REFRESH() = refresh_t::fromUint8(0x7f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EightBit::Z80::reset() {
|
void EightBit::Z80::reset() {
|
||||||
@ -34,6 +36,10 @@ void EightBit::Z80::initialise() {
|
|||||||
|
|
||||||
IntelProcessor::initialise();
|
IntelProcessor::initialise();
|
||||||
|
|
||||||
|
for (int i = 0; i < 0x100; ++i) {
|
||||||
|
m_decodedOpcodes[i] = opcode_decoded_t::decode(i);
|
||||||
|
}
|
||||||
|
|
||||||
IM() = 0;
|
IM() = 0;
|
||||||
|
|
||||||
AF().word = 0xffff;
|
AF().word = 0xffff;
|
||||||
@ -54,7 +60,7 @@ void EightBit::Z80::initialise() {
|
|||||||
IX().word = 0xffff;
|
IX().word = 0xffff;
|
||||||
IY().word = 0xffff;
|
IY().word = 0xffff;
|
||||||
|
|
||||||
REFRESH() = 0x7f;
|
REFRESH() = refresh_t::fromUint8(0x7f);
|
||||||
IV() = 0xff;
|
IV() = 0xff;
|
||||||
|
|
||||||
m_prefixCB = false;
|
m_prefixCB = false;
|
||||||
@ -126,46 +132,46 @@ void EightBit::Z80::postDecrement(uint8_t& f, uint8_t value) {
|
|||||||
|
|
||||||
#pragma region PC manipulation: call/ret/jp/jr
|
#pragma region PC manipulation: call/ret/jp/jr
|
||||||
|
|
||||||
bool EightBit::Z80::jrConditionalFlag(int flag) {
|
bool EightBit::Z80::jrConditionalFlag(uint8_t& f, int flag) {
|
||||||
switch (flag) {
|
switch (flag) {
|
||||||
case 0: // NZ
|
case 0: // NZ
|
||||||
return jrConditional(!(F() & ZF));
|
return jrConditional(!(f & ZF));
|
||||||
case 1: // Z
|
case 1: // Z
|
||||||
return jrConditional(F() & ZF);
|
return jrConditional(f & ZF);
|
||||||
case 2: // NC
|
case 2: // NC
|
||||||
return jrConditional(!(F() & CF));
|
return jrConditional(!(f & CF));
|
||||||
case 3: // C
|
case 3: // C
|
||||||
return jrConditional(F() & CF);
|
return jrConditional(f & CF);
|
||||||
case 4: // PO
|
case 4: // PO
|
||||||
return jrConditional(!(F() & PF));
|
return jrConditional(!(f & PF));
|
||||||
case 5: // PE
|
case 5: // PE
|
||||||
return jrConditional(F() & PF);
|
return jrConditional(f & PF);
|
||||||
case 6: // P
|
case 6: // P
|
||||||
return jrConditional(!(F() & SF));
|
return jrConditional(!(f & SF));
|
||||||
case 7: // M
|
case 7: // M
|
||||||
return jrConditional(F() & SF);
|
return jrConditional(f & SF);
|
||||||
}
|
}
|
||||||
throw std::logic_error("Unhandled JR conditional");
|
throw std::logic_error("Unhandled JR conditional");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EightBit::Z80::jumpConditionalFlag(int flag) {
|
bool EightBit::Z80::jumpConditionalFlag(uint8_t& f, int flag) {
|
||||||
switch (flag) {
|
switch (flag) {
|
||||||
case 0: // NZ
|
case 0: // NZ
|
||||||
return jumpConditional(!(F() & ZF));
|
return jumpConditional(!(f & ZF));
|
||||||
case 1: // Z
|
case 1: // Z
|
||||||
return jumpConditional(F() & ZF);
|
return jumpConditional(f & ZF);
|
||||||
case 2: // NC
|
case 2: // NC
|
||||||
return jumpConditional(!(F() & CF));
|
return jumpConditional(!(f & CF));
|
||||||
case 3: // C
|
case 3: // C
|
||||||
return jumpConditional(F() & CF);
|
return jumpConditional(f & CF);
|
||||||
case 4: // PO
|
case 4: // PO
|
||||||
return jumpConditional(!(F() & PF));
|
return jumpConditional(!(f & PF));
|
||||||
case 5: // PE
|
case 5: // PE
|
||||||
return jumpConditional(F() & PF);
|
return jumpConditional(f & PF);
|
||||||
case 6: // P
|
case 6: // P
|
||||||
return jumpConditional(!(F() & SF));
|
return jumpConditional(!(f & SF));
|
||||||
case 7: // M
|
case 7: // M
|
||||||
return jumpConditional(F() & SF);
|
return jumpConditional(f & SF);
|
||||||
}
|
}
|
||||||
throw std::logic_error("Unhandled JP conditional");
|
throw std::logic_error("Unhandled JP conditional");
|
||||||
}
|
}
|
||||||
@ -179,46 +185,46 @@ void EightBit::Z80::reti() {
|
|||||||
retn();
|
retn();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EightBit::Z80::returnConditionalFlag(int flag) {
|
bool EightBit::Z80::returnConditionalFlag(uint8_t& f, int flag) {
|
||||||
switch (flag) {
|
switch (flag) {
|
||||||
case 0: // NZ
|
case 0: // NZ
|
||||||
return returnConditional(!(F() & ZF));
|
return returnConditional(!(f & ZF));
|
||||||
case 1: // Z
|
case 1: // Z
|
||||||
return returnConditional(F() & ZF);
|
return returnConditional(f & ZF);
|
||||||
case 2: // NC
|
case 2: // NC
|
||||||
return returnConditional(!(F() & CF));
|
return returnConditional(!(f & CF));
|
||||||
case 3: // C
|
case 3: // C
|
||||||
return returnConditional(F() & CF);
|
return returnConditional(f & CF);
|
||||||
case 4: // PO
|
case 4: // PO
|
||||||
return returnConditional(!(F() & PF));
|
return returnConditional(!(f & PF));
|
||||||
case 5: // PE
|
case 5: // PE
|
||||||
return returnConditional(F() & PF);
|
return returnConditional(f & PF);
|
||||||
case 6: // P
|
case 6: // P
|
||||||
return returnConditional(!(F() & SF));
|
return returnConditional(!(f & SF));
|
||||||
case 7: // M
|
case 7: // M
|
||||||
return returnConditional(F() & SF);
|
return returnConditional(f & SF);
|
||||||
}
|
}
|
||||||
throw std::logic_error("Unhandled RET conditional");
|
throw std::logic_error("Unhandled RET conditional");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EightBit::Z80::callConditionalFlag(int flag) {
|
bool EightBit::Z80::callConditionalFlag(uint8_t& f, int flag) {
|
||||||
switch (flag) {
|
switch (flag) {
|
||||||
case 0: // NZ
|
case 0: // NZ
|
||||||
return callConditional(!(F() & ZF));
|
return callConditional(!(f & ZF));
|
||||||
case 1: // Z
|
case 1: // Z
|
||||||
return callConditional(F() & ZF);
|
return callConditional(f & ZF);
|
||||||
case 2: // NC
|
case 2: // NC
|
||||||
return callConditional(!(F() & CF));
|
return callConditional(!(f & CF));
|
||||||
case 3: // C
|
case 3: // C
|
||||||
return callConditional(F() & CF);
|
return callConditional(f & CF);
|
||||||
case 4: // PO
|
case 4: // PO
|
||||||
return callConditional(!(F() & PF));
|
return callConditional(!(f & PF));
|
||||||
case 5: // PE
|
case 5: // PE
|
||||||
return callConditional(F() & PF);
|
return callConditional(f & PF);
|
||||||
case 6: // P
|
case 6: // P
|
||||||
return callConditional(!(F() & SF));
|
return callConditional(!(f & SF));
|
||||||
case 7: // M
|
case 7: // M
|
||||||
return callConditional(F() & SF);
|
return callConditional(f & SF);
|
||||||
}
|
}
|
||||||
throw std::logic_error("Unhandled CALL conditional");
|
throw std::logic_error("Unhandled CALL conditional");
|
||||||
}
|
}
|
||||||
@ -231,15 +237,15 @@ void EightBit::Z80::sbc(register16_t& operand, register16_t value) {
|
|||||||
|
|
||||||
auto& f = F();
|
auto& f = F();
|
||||||
|
|
||||||
auto before = operand;
|
const auto before = operand;
|
||||||
|
|
||||||
auto beforeNegative = before.high & SF;
|
const auto beforeNegative = before.high & SF;
|
||||||
auto valueNegative = value.high & SF;
|
const auto valueNegative = value.high & SF;
|
||||||
|
|
||||||
auto result = before.word - value.word - (f & CF);
|
const auto result = before.word - value.word - (f & CF);
|
||||||
operand.word = result;
|
operand.word = result;
|
||||||
|
|
||||||
auto afterNegative = operand.high & SF;
|
const auto afterNegative = operand.high & SF;
|
||||||
|
|
||||||
setFlag(f, SF, afterNegative);
|
setFlag(f, SF, afterNegative);
|
||||||
clearFlag(f, ZF, operand.word);
|
clearFlag(f, ZF, operand.word);
|
||||||
@ -254,18 +260,18 @@ void EightBit::Z80::adc(register16_t& operand, register16_t value) {
|
|||||||
|
|
||||||
auto& f = F();
|
auto& f = F();
|
||||||
|
|
||||||
auto before = operand;
|
const auto before = operand;
|
||||||
|
|
||||||
auto beforeNegative = before.high & SF;
|
const auto beforeNegative = before.high & SF;
|
||||||
auto valueNegative = value.high & SF;
|
const auto valueNegative = value.high & SF;
|
||||||
|
|
||||||
auto result = before.word + value.word + (f & CF);
|
const auto result = before.word + value.word + (f & CF);
|
||||||
operand.word = result;
|
operand.word = result;
|
||||||
|
|
||||||
auto afterNegative = operand.high & SF;
|
auto afterNegative = operand.high & SF;
|
||||||
|
|
||||||
setFlag(f, SF, afterNegative);
|
setFlag(f, SF, afterNegative);
|
||||||
clearFlag(f, ZF, result);
|
clearFlag(f, ZF, operand.word);
|
||||||
adjustHalfCarryAdd(f, before.high, value.high, operand.high);
|
adjustHalfCarryAdd(f, before.high, value.high, operand.high);
|
||||||
adjustOverflowAdd(f, beforeNegative, valueNegative, afterNegative);
|
adjustOverflowAdd(f, beforeNegative, valueNegative, afterNegative);
|
||||||
clearFlag(f, NF);
|
clearFlag(f, NF);
|
||||||
@ -277,9 +283,9 @@ void EightBit::Z80::add(register16_t& operand, register16_t value) {
|
|||||||
|
|
||||||
auto& f = F();
|
auto& f = F();
|
||||||
|
|
||||||
auto before = operand;
|
const auto before = operand;
|
||||||
|
|
||||||
auto result = before.word + value.word;
|
const auto result = before.word + value.word;
|
||||||
|
|
||||||
operand.word = result;
|
operand.word = result;
|
||||||
|
|
||||||
@ -293,9 +299,7 @@ void EightBit::Z80::add(register16_t& operand, register16_t value) {
|
|||||||
|
|
||||||
#pragma region ALU
|
#pragma region ALU
|
||||||
|
|
||||||
void EightBit::Z80::add(uint8_t& operand, uint8_t value, int carry) {
|
void EightBit::Z80::add(uint8_t& f, uint8_t& operand, uint8_t value, int carry) {
|
||||||
|
|
||||||
auto& f = F();
|
|
||||||
|
|
||||||
register16_t result;
|
register16_t result;
|
||||||
result.word = operand + value + carry;
|
result.word = operand + value + carry;
|
||||||
@ -311,12 +315,11 @@ void EightBit::Z80::add(uint8_t& operand, uint8_t value, int carry) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void EightBit::Z80::adc(uint8_t& operand, uint8_t value) {
|
void EightBit::Z80::adc(uint8_t& operand, uint8_t value) {
|
||||||
add(operand, value, F() & CF);
|
auto& f = F();
|
||||||
|
add(f, operand, value, f & CF);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EightBit::Z80::sub(uint8_t& operand, uint8_t value, int carry) {
|
void EightBit::Z80::subtract(uint8_t& f, uint8_t& operand, uint8_t value, int carry) {
|
||||||
|
|
||||||
auto& f = F();
|
|
||||||
|
|
||||||
register16_t result;
|
register16_t result;
|
||||||
result.word = operand - value - carry;
|
result.word = operand - value - carry;
|
||||||
@ -328,71 +331,68 @@ void EightBit::Z80::sub(uint8_t& operand, uint8_t value, int carry) {
|
|||||||
|
|
||||||
setFlag(f, NF);
|
setFlag(f, NF);
|
||||||
setFlag(f, CF, result.word & Bit8);
|
setFlag(f, CF, result.word & Bit8);
|
||||||
adjustSZXY<Z80>(f, operand);
|
adjustSZ<Z80>(f, operand);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EightBit::Z80::sub(uint8_t& f, uint8_t& operand, uint8_t value, int carry) {
|
||||||
|
subtract(f, operand, value, carry);
|
||||||
|
adjustXY<Z80>(f, operand);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EightBit::Z80::sbc(uint8_t& operand, uint8_t value) {
|
void EightBit::Z80::sbc(uint8_t& operand, uint8_t value) {
|
||||||
sub(operand, value, F() & CF);
|
auto& f = F();
|
||||||
|
sub(f, operand, value, f & CF);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EightBit::Z80::andr(uint8_t& operand, uint8_t value) {
|
void EightBit::Z80::andr(uint8_t& f, uint8_t& operand, uint8_t value) {
|
||||||
auto& f = F();
|
|
||||||
operand &= value;
|
operand &= value;
|
||||||
setFlag(f, HC);
|
setFlag(f, HC);
|
||||||
clearFlag(f, CF | NF);
|
clearFlag(f, CF | NF);
|
||||||
adjustSZPXY<Z80>(f, operand);
|
adjustSZPXY<Z80>(f, operand);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EightBit::Z80::xorr(uint8_t& operand, uint8_t value) {
|
void EightBit::Z80::xorr(uint8_t& f, uint8_t& operand, uint8_t value) {
|
||||||
auto& f = F();
|
|
||||||
operand ^= value;
|
operand ^= value;
|
||||||
clearFlag(f, HC | CF | NF);
|
clearFlag(f, HC | CF | NF);
|
||||||
adjustSZPXY<Z80>(f, operand);
|
adjustSZPXY<Z80>(f, operand);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EightBit::Z80::orr(uint8_t& operand, uint8_t value) {
|
void EightBit::Z80::orr(uint8_t& f, uint8_t& operand, uint8_t value) {
|
||||||
auto& f = F();
|
|
||||||
operand |= value;
|
operand |= value;
|
||||||
clearFlag(f, HC | CF | NF);
|
clearFlag(f, HC | CF | NF);
|
||||||
adjustSZPXY<Z80>(f, operand);
|
adjustSZPXY<Z80>(f, operand);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EightBit::Z80::compare(uint8_t value) {
|
void EightBit::Z80::compare(uint8_t& f, uint8_t check, uint8_t value) {
|
||||||
auto check = A();
|
subtract(f, check, value);
|
||||||
sub(check, value);
|
adjustXY<Z80>(f, value);
|
||||||
adjustXY<Z80>(F(), value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma endregion ALU
|
#pragma endregion ALU
|
||||||
|
|
||||||
#pragma region Shift and rotate
|
#pragma region Shift and rotate
|
||||||
|
|
||||||
uint8_t& EightBit::Z80::rlc(uint8_t& operand) {
|
uint8_t& EightBit::Z80::rlc(uint8_t& f, uint8_t& operand) {
|
||||||
auto& f = F();
|
const auto carry = operand & Bit7;
|
||||||
auto carry = operand & Bit7;
|
operand = _rotl8(operand, 1);
|
||||||
operand <<= 1;
|
|
||||||
carry ? operand |= Bit0 : operand &= ~Bit0;
|
|
||||||
setFlag(f, CF, carry);
|
setFlag(f, CF, carry);
|
||||||
clearFlag(f, NF | HC);
|
clearFlag(f, NF | HC);
|
||||||
adjustXY<Z80>(f, operand);
|
adjustXY<Z80>(f, operand);
|
||||||
return operand;
|
return operand;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t& EightBit::Z80::rrc(uint8_t& operand) {
|
uint8_t& EightBit::Z80::rrc(uint8_t& f, uint8_t& operand) {
|
||||||
auto& f = F();
|
const auto carry = operand & Bit0;
|
||||||
auto carry = operand & Bit0;
|
operand = _rotr8(operand, 1);
|
||||||
operand >>= 1;
|
|
||||||
carry ? operand |= Bit7 : operand &= ~Bit7;
|
|
||||||
setFlag(f, CF, carry);
|
setFlag(f, CF, carry);
|
||||||
clearFlag(f, NF | HC);
|
clearFlag(f, NF | HC);
|
||||||
adjustXY<Z80>(f, operand);
|
adjustXY<Z80>(f, operand);
|
||||||
return operand;
|
return operand;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t& EightBit::Z80::rl(uint8_t& operand) {
|
uint8_t& EightBit::Z80::rl(uint8_t& f, uint8_t& operand) {
|
||||||
auto& f = F();
|
const auto oldCarry = f & CF;
|
||||||
auto oldCarry = f & CF;
|
const auto newCarry = operand & Bit7;
|
||||||
auto newCarry = operand & Bit7;
|
|
||||||
operand <<= 1;
|
operand <<= 1;
|
||||||
oldCarry ? operand |= Bit0 : operand &= ~Bit0;
|
oldCarry ? operand |= Bit0 : operand &= ~Bit0;
|
||||||
setFlag(f, CF, newCarry);
|
setFlag(f, CF, newCarry);
|
||||||
@ -401,10 +401,9 @@ uint8_t& EightBit::Z80::rl(uint8_t& operand) {
|
|||||||
return operand;
|
return operand;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t& EightBit::Z80::rr(uint8_t& operand) {
|
uint8_t& EightBit::Z80::rr(uint8_t& f, uint8_t& operand) {
|
||||||
auto& f = F();
|
const auto oldCarry = f & CF;
|
||||||
auto oldCarry = f & CF;
|
const auto newCarry = operand & Bit0;
|
||||||
auto newCarry = operand & Bit0;
|
|
||||||
operand >>= 1;
|
operand >>= 1;
|
||||||
operand |= oldCarry << 7;
|
operand |= oldCarry << 7;
|
||||||
setFlag(f, CF, newCarry);
|
setFlag(f, CF, newCarry);
|
||||||
@ -415,9 +414,8 @@ uint8_t& EightBit::Z80::rr(uint8_t& operand) {
|
|||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
uint8_t& EightBit::Z80::sla(uint8_t& operand) {
|
uint8_t& EightBit::Z80::sla(uint8_t& f, uint8_t& operand) {
|
||||||
auto& f = F();
|
const auto newCarry = operand & Bit7;
|
||||||
auto newCarry = operand & Bit7;
|
|
||||||
operand <<= 1;
|
operand <<= 1;
|
||||||
setFlag(f, CF, newCarry);
|
setFlag(f, CF, newCarry);
|
||||||
clearFlag(f, NF | HC);
|
clearFlag(f, NF | HC);
|
||||||
@ -425,10 +423,9 @@ uint8_t& EightBit::Z80::sla(uint8_t& operand) {
|
|||||||
return operand;
|
return operand;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t& EightBit::Z80::sra(uint8_t& operand) {
|
uint8_t& EightBit::Z80::sra(uint8_t& f, uint8_t& operand) {
|
||||||
auto& f = F();
|
const auto new7 = operand & Bit7;
|
||||||
auto new7 = operand & Bit7;
|
const auto newCarry = operand & Bit0;
|
||||||
auto newCarry = operand & Bit0;
|
|
||||||
operand >>= 1;
|
operand >>= 1;
|
||||||
operand |= new7;
|
operand |= new7;
|
||||||
setFlag(f, CF, newCarry);
|
setFlag(f, CF, newCarry);
|
||||||
@ -437,9 +434,8 @@ uint8_t& EightBit::Z80::sra(uint8_t& operand) {
|
|||||||
return operand;
|
return operand;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t& EightBit::Z80::sll(uint8_t& operand) {
|
uint8_t& EightBit::Z80::sll(uint8_t& f, uint8_t& operand) {
|
||||||
auto& f = F();
|
const auto newCarry = operand & Bit7;
|
||||||
auto newCarry = operand & Bit7;
|
|
||||||
operand <<= 1;
|
operand <<= 1;
|
||||||
operand |= 1;
|
operand |= 1;
|
||||||
setFlag(f, CF, newCarry);
|
setFlag(f, CF, newCarry);
|
||||||
@ -448,9 +444,8 @@ uint8_t& EightBit::Z80::sll(uint8_t& operand) {
|
|||||||
return operand;
|
return operand;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t& EightBit::Z80::srl(uint8_t& operand) {
|
uint8_t& EightBit::Z80::srl(uint8_t& f, uint8_t& operand) {
|
||||||
auto& f = F();
|
const auto newCarry = operand & Bit0;
|
||||||
auto newCarry = operand & Bit0;
|
|
||||||
operand >>= 1;
|
operand >>= 1;
|
||||||
operand &= ~Bit7; // clear bit 7
|
operand &= ~Bit7; // clear bit 7
|
||||||
setFlag(f, CF, newCarry);
|
setFlag(f, CF, newCarry);
|
||||||
@ -464,24 +459,23 @@ uint8_t& EightBit::Z80::srl(uint8_t& operand) {
|
|||||||
|
|
||||||
#pragma region BIT/SET/RES
|
#pragma region BIT/SET/RES
|
||||||
|
|
||||||
uint8_t& EightBit::Z80::bit(int n, uint8_t& operand) {
|
uint8_t& EightBit::Z80::bit(uint8_t& f, int n, uint8_t& operand) {
|
||||||
auto& f = F();
|
const uint8_t discarded = operand & (1 << n);
|
||||||
auto carry = f & CF;
|
setFlag(f, HC);
|
||||||
uint8_t discarded = operand;
|
clearFlag(f, NF);
|
||||||
andr(discarded, 1 << n);
|
adjustSZXY<Z80>(f, discarded);
|
||||||
clearFlag(f, PF, discarded);
|
clearFlag(f, PF, discarded);
|
||||||
setFlag(f, CF, carry);
|
|
||||||
return operand;
|
return operand;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t& EightBit::Z80::res(int n, uint8_t& operand) {
|
uint8_t& EightBit::Z80::res(int n, uint8_t& operand) {
|
||||||
auto bit = 1 << n;
|
const auto bit = 1 << n;
|
||||||
operand &= ~bit;
|
operand &= ~bit;
|
||||||
return operand;
|
return operand;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t& EightBit::Z80::set(int n, uint8_t& operand) {
|
uint8_t& EightBit::Z80::set(int n, uint8_t& operand) {
|
||||||
auto bit = 1 << n;
|
const auto bit = 1 << n;
|
||||||
operand |= bit;
|
operand |= bit;
|
||||||
return operand;
|
return operand;
|
||||||
}
|
}
|
||||||
@ -493,9 +487,9 @@ uint8_t& EightBit::Z80::set(int n, uint8_t& operand) {
|
|||||||
void EightBit::Z80::neg() {
|
void EightBit::Z80::neg() {
|
||||||
auto& a = A();
|
auto& a = A();
|
||||||
auto& f = F();
|
auto& f = F();
|
||||||
auto original = a;
|
const auto original = a;
|
||||||
a = 0;
|
a = 0;
|
||||||
sub(a, original);
|
sub(f, a, original);
|
||||||
setFlag(f, PF, original == Bit7);
|
setFlag(f, PF, original == Bit7);
|
||||||
setFlag(f, CF, original);
|
setFlag(f, CF, original);
|
||||||
}
|
}
|
||||||
@ -533,7 +527,7 @@ void EightBit::Z80::cpl() {
|
|||||||
auto& a = A();
|
auto& a = A();
|
||||||
auto& f = F();
|
auto& f = F();
|
||||||
a = ~a;
|
a = ~a;
|
||||||
adjustXY<Z80>(f, A());
|
adjustXY<Z80>(f, a);
|
||||||
setFlag(f, HC | NF);
|
setFlag(f, HC | NF);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -546,7 +540,7 @@ void EightBit::Z80::scf() {
|
|||||||
|
|
||||||
void EightBit::Z80::ccf() {
|
void EightBit::Z80::ccf() {
|
||||||
auto& f = F();
|
auto& f = F();
|
||||||
auto carry = f & CF;
|
const auto carry = f & CF;
|
||||||
setFlag(f, HC, carry);
|
setFlag(f, HC, carry);
|
||||||
clearFlag(f, CF, carry);
|
clearFlag(f, CF, carry);
|
||||||
clearFlag(f, NF);
|
clearFlag(f, NF);
|
||||||
@ -574,14 +568,11 @@ void EightBit::Z80::xhtl() {
|
|||||||
|
|
||||||
#pragma region Block compare instructions
|
#pragma region Block compare instructions
|
||||||
|
|
||||||
void EightBit::Z80::blockCompare() {
|
void EightBit::Z80::blockCompare(uint8_t a, uint8_t& f) {
|
||||||
|
|
||||||
const auto& a = A();
|
|
||||||
auto& f = F();
|
|
||||||
|
|
||||||
m_memory.ADDRESS() = HL();
|
m_memory.ADDRESS() = HL();
|
||||||
|
|
||||||
auto value = m_memory.reference();
|
const auto value = m_memory.reference();
|
||||||
uint8_t result = a - value;
|
uint8_t result = a - value;
|
||||||
|
|
||||||
setFlag(f, PF, --BC().word);
|
setFlag(f, PF, --BC().word);
|
||||||
@ -597,31 +588,35 @@ void EightBit::Z80::blockCompare() {
|
|||||||
setFlag(f, XF, result & Bit3);
|
setFlag(f, XF, result & Bit3);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EightBit::Z80::cpi() {
|
void EightBit::Z80::cpi(uint8_t a, uint8_t& f) {
|
||||||
blockCompare();
|
blockCompare(a, f);
|
||||||
HL().word++;
|
HL().word++;
|
||||||
MEMPTR().word++;
|
MEMPTR().word++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EightBit::Z80::cpd() {
|
void EightBit::Z80::cpd(uint8_t a, uint8_t& f) {
|
||||||
blockCompare();
|
blockCompare(a, f);
|
||||||
HL().word--;
|
HL().word--;
|
||||||
MEMPTR().word--;
|
MEMPTR().word--;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EightBit::Z80::cpir() {
|
bool EightBit::Z80::cpir() {
|
||||||
cpi();
|
const auto a = A();
|
||||||
|
auto& f = F();
|
||||||
|
cpi(a, f);
|
||||||
MEMPTR() = PC();
|
MEMPTR() = PC();
|
||||||
auto again = (F() & PF) && !(F() & ZF); // See CPI
|
auto again = (f & PF) && !(f & ZF); // See CPI
|
||||||
if (again)
|
if (again)
|
||||||
MEMPTR().word--;
|
MEMPTR().word--;
|
||||||
return again;
|
return again;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EightBit::Z80::cpdr() {
|
bool EightBit::Z80::cpdr() {
|
||||||
cpd();
|
const auto a = A();
|
||||||
|
auto& f = F();
|
||||||
|
cpd(a, f);
|
||||||
MEMPTR().word = PC().word - 1;
|
MEMPTR().word = PC().word - 1;
|
||||||
auto again = (F() & PF) && !(F() & ZF); // See CPD
|
auto again = (f & PF) && !(f & ZF); // See CPD
|
||||||
if (!again)
|
if (!again)
|
||||||
MEMPTR().word--;
|
MEMPTR().word--;
|
||||||
return again;
|
return again;
|
||||||
@ -789,12 +784,14 @@ int EightBit::Z80::execute(uint8_t opcode) {
|
|||||||
if (!M1())
|
if (!M1())
|
||||||
throw std::logic_error("M1 cannot be high");
|
throw std::logic_error("M1 cannot be high");
|
||||||
|
|
||||||
auto x = (opcode & 0b11000000) >> 6;
|
const auto& decoded = m_decodedOpcodes[opcode];
|
||||||
auto y = (opcode & 0b111000) >> 3;
|
|
||||||
auto z = (opcode & 0b111);
|
|
||||||
|
|
||||||
auto p = (y & 0b110) >> 1;
|
auto x = decoded.x;
|
||||||
auto q = (y & 1);
|
auto y = decoded.y;
|
||||||
|
auto z = decoded.z;
|
||||||
|
|
||||||
|
auto p = decoded.p;
|
||||||
|
auto q = decoded.q;
|
||||||
|
|
||||||
if (!(m_prefixCB && m_displaced)) {
|
if (!(m_prefixCB && m_displaced)) {
|
||||||
incrementRefresh();
|
incrementRefresh();
|
||||||
@ -802,7 +799,7 @@ int EightBit::Z80::execute(uint8_t opcode) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (m_prefixCB)
|
if (m_prefixCB)
|
||||||
executeCB(x, y, z, p, q);
|
executeCB(x, y, z);
|
||||||
else if (m_prefixED)
|
else if (m_prefixED)
|
||||||
executeED(x, y, z, p, q);
|
executeED(x, y, z, p, q);
|
||||||
else
|
else
|
||||||
@ -814,34 +811,34 @@ int EightBit::Z80::execute(uint8_t opcode) {
|
|||||||
return cycles;
|
return cycles;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EightBit::Z80::executeCB(int x, int y, int z, int p, int q) {
|
void EightBit::Z80::executeCB(int x, int y, int z) {
|
||||||
auto& f = F();
|
auto& f = F();
|
||||||
switch (x) {
|
switch (x) {
|
||||||
case 0: // rot[y] r[z]
|
case 0: // rot[y] r[z]
|
||||||
switch (y) {
|
switch (y) {
|
||||||
case 0:
|
case 0:
|
||||||
adjustSZP<Z80>(f, m_displaced ? R2(z) = rlc(DISPLACED()) : rlc(R(z)));
|
adjustSZP<Z80>(f, m_displaced ? R2(z) = rlc(f, DISPLACED()) : rlc(f, R(z)));
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
adjustSZP<Z80>(f, m_displaced ? R2(z) = rrc(DISPLACED()) : rrc(R(z)));
|
adjustSZP<Z80>(f, m_displaced ? R2(z) = rrc(f, DISPLACED()) : rrc(f, R(z)));
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
adjustSZP<Z80>(f, m_displaced ? R2(z) = rl(DISPLACED()) : rl(R(z)));
|
adjustSZP<Z80>(f, m_displaced ? R2(z) = rl(f, DISPLACED()) : rl(f, R(z)));
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
adjustSZP<Z80>(f, m_displaced ? R2(z) = rr(DISPLACED()) : rr(R(z)));
|
adjustSZP<Z80>(f, m_displaced ? R2(z) = rr(f, DISPLACED()) : rr(f, R(z)));
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
adjustSZP<Z80>(f, m_displaced ? R2(z) = sla(DISPLACED()) : sla(R(z)));
|
adjustSZP<Z80>(f, m_displaced ? R2(z) = sla(f, DISPLACED()) : sla(f, R(z)));
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
adjustSZP<Z80>(f, m_displaced ? R2(z) = sra(DISPLACED()) : sra(R(z)));
|
adjustSZP<Z80>(f, m_displaced ? R2(z) = sra(f, DISPLACED()) : sra(f, R(z)));
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
adjustSZP<Z80>(f, m_displaced ? R2(z) = sll(DISPLACED()) : sll(R(z)));
|
adjustSZP<Z80>(f, m_displaced ? R2(z) = sll(f, DISPLACED()) : sll(f, R(z)));
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
adjustSZP<Z80>(f, m_displaced ? R2(z) = srl(DISPLACED()) : srl(R(z)));
|
adjustSZP<Z80>(f, m_displaced ? R2(z) = srl(f, DISPLACED()) : srl(f, R(z)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (m_displaced) {
|
if (m_displaced) {
|
||||||
@ -854,11 +851,11 @@ void EightBit::Z80::executeCB(int x, int y, int z, int p, int q) {
|
|||||||
break;
|
break;
|
||||||
case 1: // BIT y, r[z]
|
case 1: // BIT y, r[z]
|
||||||
if (m_displaced) {
|
if (m_displaced) {
|
||||||
bit(y, DISPLACED());
|
bit(f, y, DISPLACED());
|
||||||
adjustXY<Z80>(f, MEMPTR().high);
|
adjustXY<Z80>(f, MEMPTR().high);
|
||||||
cycles += 20;
|
cycles += 20;
|
||||||
} else {
|
} else {
|
||||||
auto operand = bit(y, R(z));
|
auto operand = bit(f, y, R(z));
|
||||||
cycles += 8;
|
cycles += 8;
|
||||||
if (z == 6) {
|
if (z == 6) {
|
||||||
adjustXY<Z80>(f, MEMPTR().high);
|
adjustXY<Z80>(f, MEMPTR().high);
|
||||||
@ -988,7 +985,7 @@ void EightBit::Z80::executeED(int x, int y, int z, int p, int q) {
|
|||||||
cycles += 9;
|
cycles += 9;
|
||||||
break;
|
break;
|
||||||
case 1: // LD R,A
|
case 1: // LD R,A
|
||||||
REFRESH() = A();
|
REFRESH() = refresh_t::fromUint8(A());
|
||||||
cycles += 9;
|
cycles += 9;
|
||||||
break;
|
break;
|
||||||
case 2: // LD A,I
|
case 2: // LD A,I
|
||||||
@ -999,7 +996,7 @@ void EightBit::Z80::executeED(int x, int y, int z, int p, int q) {
|
|||||||
cycles += 9;
|
cycles += 9;
|
||||||
break;
|
break;
|
||||||
case 3: // LD A,R
|
case 3: // LD A,R
|
||||||
A() = REFRESH();
|
A() = REFRESH().asUint8();
|
||||||
adjustSZXY<Z80>(f, A());
|
adjustSZXY<Z80>(f, A());
|
||||||
clearFlag(f, NF | HC);
|
clearFlag(f, NF | HC);
|
||||||
setFlag(f, PF, IFF2());
|
setFlag(f, PF, IFF2());
|
||||||
@ -1048,10 +1045,10 @@ void EightBit::Z80::executeED(int x, int y, int z, int p, int q) {
|
|||||||
case 1: // CP
|
case 1: // CP
|
||||||
switch (y) {
|
switch (y) {
|
||||||
case 4: // CPI
|
case 4: // CPI
|
||||||
cpi();
|
cpi(A(), f);
|
||||||
break;
|
break;
|
||||||
case 5: // CPD
|
case 5: // CPD
|
||||||
cpd();
|
cpd(A(), f);
|
||||||
break;
|
break;
|
||||||
case 6: // CPIR
|
case 6: // CPIR
|
||||||
if (cpir()) {
|
if (cpir()) {
|
||||||
@ -1141,7 +1138,7 @@ void EightBit::Z80::executeOther(int x, int y, int z, int p, int q) {
|
|||||||
cycles += 12;
|
cycles += 12;
|
||||||
break;
|
break;
|
||||||
default: // JR cc,d
|
default: // JR cc,d
|
||||||
if (jrConditionalFlag(y - 4))
|
if (jrConditionalFlag(f, y - 4))
|
||||||
cycles += 5;
|
cycles += 5;
|
||||||
cycles += 5;
|
cycles += 5;
|
||||||
break;
|
break;
|
||||||
@ -1242,16 +1239,16 @@ void EightBit::Z80::executeOther(int x, int y, int z, int p, int q) {
|
|||||||
} case 7: // Assorted operations on accumulator/flags
|
} case 7: // Assorted operations on accumulator/flags
|
||||||
switch (y) {
|
switch (y) {
|
||||||
case 0:
|
case 0:
|
||||||
rlc(A());
|
rlc(f, A());
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
rrc(A());
|
rrc(f, A());
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
rl(A());
|
rl(f, A());
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
rr(A());
|
rr(f, A());
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
daa();
|
daa();
|
||||||
@ -1311,28 +1308,28 @@ void EightBit::Z80::executeOther(int x, int y, int z, int p, int q) {
|
|||||||
case 2: // Operate on accumulator and register/memory location
|
case 2: // Operate on accumulator and register/memory location
|
||||||
switch (y) {
|
switch (y) {
|
||||||
case 0: // ADD A,r
|
case 0: // ADD A,r
|
||||||
add(A(), R(z));
|
add(f, A(), R(z));
|
||||||
break;
|
break;
|
||||||
case 1: // ADC A,r
|
case 1: // ADC A,r
|
||||||
adc(A(), R(z));
|
adc(A(), R(z));
|
||||||
break;
|
break;
|
||||||
case 2: // SUB r
|
case 2: // SUB r
|
||||||
sub(A(), R(z));
|
sub(f, A(), R(z));
|
||||||
break;
|
break;
|
||||||
case 3: // SBC A,r
|
case 3: // SBC A,r
|
||||||
sbc(A(), R(z));
|
sbc(A(), R(z));
|
||||||
break;
|
break;
|
||||||
case 4: // AND r
|
case 4: // AND r
|
||||||
andr(A(), R(z));
|
andr(f, A(), R(z));
|
||||||
break;
|
break;
|
||||||
case 5: // XOR r
|
case 5: // XOR r
|
||||||
xorr(A(), R(z));
|
xorr(f, A(), R(z));
|
||||||
break;
|
break;
|
||||||
case 6: // OR r
|
case 6: // OR r
|
||||||
orr(A(), R(z));
|
orr(f, A(), R(z));
|
||||||
break;
|
break;
|
||||||
case 7: // CP r
|
case 7: // CP r
|
||||||
compare(R(z));
|
compare(f, A(), R(z));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
cycles += 4;
|
cycles += 4;
|
||||||
@ -1342,7 +1339,7 @@ void EightBit::Z80::executeOther(int x, int y, int z, int p, int q) {
|
|||||||
case 3:
|
case 3:
|
||||||
switch (z) {
|
switch (z) {
|
||||||
case 0: // Conditional return
|
case 0: // Conditional return
|
||||||
if (returnConditionalFlag(y))
|
if (returnConditionalFlag(f, y))
|
||||||
cycles += 6;
|
cycles += 6;
|
||||||
cycles += 5;
|
cycles += 5;
|
||||||
break;
|
break;
|
||||||
@ -1374,7 +1371,7 @@ void EightBit::Z80::executeOther(int x, int y, int z, int p, int q) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 2: // Conditional jump
|
case 2: // Conditional jump
|
||||||
jumpConditionalFlag(y);
|
jumpConditionalFlag(f, y);
|
||||||
cycles += 10;
|
cycles += 10;
|
||||||
break;
|
break;
|
||||||
case 3: // Assorted operations
|
case 3: // Assorted operations
|
||||||
@ -1427,7 +1424,7 @@ void EightBit::Z80::executeOther(int x, int y, int z, int p, int q) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 4: // Conditional call: CALL cc[y], nn
|
case 4: // Conditional call: CALL cc[y], nn
|
||||||
if (callConditionalFlag(y))
|
if (callConditionalFlag(f, y))
|
||||||
cycles += 7;
|
cycles += 7;
|
||||||
cycles += 10;
|
cycles += 10;
|
||||||
break;
|
break;
|
||||||
@ -1462,28 +1459,28 @@ void EightBit::Z80::executeOther(int x, int y, int z, int p, int q) {
|
|||||||
case 6: // Operate on accumulator and immediate operand: alu[y] n
|
case 6: // Operate on accumulator and immediate operand: alu[y] n
|
||||||
switch (y) {
|
switch (y) {
|
||||||
case 0: // ADD A,n
|
case 0: // ADD A,n
|
||||||
add(A(), fetchByte());
|
add(f, A(), fetchByte());
|
||||||
break;
|
break;
|
||||||
case 1: // ADC A,n
|
case 1: // ADC A,n
|
||||||
adc(A(), fetchByte());
|
adc(A(), fetchByte());
|
||||||
break;
|
break;
|
||||||
case 2: // SUB n
|
case 2: // SUB n
|
||||||
sub(A(), fetchByte());
|
sub(f, A(), fetchByte());
|
||||||
break;
|
break;
|
||||||
case 3: // SBC A,n
|
case 3: // SBC A,n
|
||||||
sbc(A(), fetchByte());
|
sbc(A(), fetchByte());
|
||||||
break;
|
break;
|
||||||
case 4: // AND n
|
case 4: // AND n
|
||||||
andr(A(), fetchByte());
|
andr(f, A(), fetchByte());
|
||||||
break;
|
break;
|
||||||
case 5: // XOR n
|
case 5: // XOR n
|
||||||
xorr(A(), fetchByte());
|
xorr(f, A(), fetchByte());
|
||||||
break;
|
break;
|
||||||
case 6: // OR n
|
case 6: // OR n
|
||||||
orr(A(), fetchByte());
|
orr(f, A(), fetchByte());
|
||||||
break;
|
break;
|
||||||
case 7: // CP n
|
case 7: // CP n
|
||||||
compare(fetchByte());
|
compare(f, A(), fetchByte());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
cycles += 7;
|
cycles += 7;
|
||||||
|
@ -107,7 +107,7 @@ namespace EightBit {
|
|||||||
m_memory.reference() = value;
|
m_memory.reference() = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pushWord(register16_t value) {
|
void pushWord(const register16_t& value) {
|
||||||
push(value.high);
|
push(value.high);
|
||||||
push(value.low);
|
push(value.low);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user