Copy constructor and equality operations added.

This commit is contained in:
Adrian Conlon 2021-12-27 22:07:30 +00:00
parent 945fcefb36
commit 1f5dc54c40
13 changed files with 95 additions and 13 deletions

View File

@ -71,6 +71,7 @@ namespace EightBit {
Z80(Bus& bus);
Z80(const Z80& rhs);
bool operator==(const Z80& rhs) const;
Signal<Z80> ExecutingInstruction;

View File

@ -34,33 +34,77 @@ EightBit::Z80::Z80(Bus& bus)
});
}
EightBit::Z80::Z80(const Z80& rhs)
: IntelProcessor(rhs) {
m_registers = rhs.m_registers;
m_registerSet = rhs.m_registerSet;
m_accumulatorFlags = rhs.m_accumulatorFlags;
m_accumulatorFlagsSet = rhs.m_accumulatorFlagsSet;
m_ix = rhs.m_ix;
m_iy = rhs.m_iy;
m_refresh = rhs.m_refresh;
iv = rhs.iv;
m_interruptMode = rhs.m_interruptMode;
m_iff1 = rhs.m_iff1;
m_iff2 = rhs.m_iff2;
RFSH() = rhs.RFSH();
NMI() = rhs.NMI();
M1() = rhs.M1();
MREQ() = rhs.MREQ();
IORQ() = rhs.IORQ();
RD() = rhs.RD();
WR() = rhs.WR();
}
bool EightBit::Z80::operator==(const EightBit::Z80& rhs) const {
const auto base = IntelProcessor::operator==(rhs);
auto* z80 = const_cast<Z80*>(this);
z80->exxAF();
z80->exx();
return base
&& RFSH() == rhs.RFSH()
const auto pins =
RFSH() == rhs.RFSH()
&& NMI() == rhs.NMI()
&& M1() == rhs.M1()
&& MREQ() == rhs.MREQ()
&& IORQ() == rhs.IORQ()
&& RD() == rhs.RD()
&& WR() == rhs.WR()
&& AF() == rhs.AF()
&& BC() == rhs.BC()
&& WR() == rhs.WR();
auto* z80 = const_cast<Z80*>(this);
auto& z80_rhs = const_cast<Z80&>(rhs);
z80->exxAF();
z80_rhs.exxAF();
const auto af = AF() == rhs.AF();
z80->exxAF();
z80_rhs.exxAF();
z80->exx();
z80_rhs.exx();
const auto pairs =
BC() == rhs.BC()
&& DE() == rhs.DE()
&& HL() == rhs.HL()
&& IX() == rhs.IX()
&& IY() == rhs.IY()
&& REFRESH() == rhs.REFRESH()
&& HL() == rhs.HL();
z80->exx();
z80_rhs.exx();
const auto indices =
IX() == rhs.IX()
&& IY() == rhs.IY();
const auto miscellaneous =
REFRESH() == rhs.REFRESH()
&& IV() == rhs.IV()
&& IM() == rhs.IM()
&& IFF1() == rhs.IFF1()
&& IFF2() == rhs.IFF2();
return base && pins && af && pairs && indices && miscellaneous;
}
DEFINE_PIN_LEVEL_CHANGERS(NMI, Z80);

View File

@ -68,6 +68,9 @@ namespace EightBit {
virtual ~Chip() {}
Chip(const Chip& rhs)
: Device(rhs) {}
protected:
Chip() noexcept = default;
};

View File

@ -9,6 +9,7 @@ namespace EightBit {
public:
virtual ~ClockedChip() noexcept {};
ClockedChip(const ClockedChip& rhs);
bool operator==(const ClockedChip& rhs) const;
Signal<EventArgs> Ticked;

View File

@ -108,6 +108,7 @@ namespace EightBit {
virtual ~Device() noexcept {};
Device(const Device& rhs);
bool operator==(const Device& rhs) const;
[[nodiscard]] constexpr bool powered() const noexcept { return raised(POWER()); }

View File

@ -46,6 +46,7 @@ namespace EightBit {
virtual ~IntelProcessor() {};
IntelProcessor(const IntelProcessor& rhs);
bool operator==(const IntelProcessor& rhs) const;
[[nodiscard]] constexpr const auto& getDecodedOpcode(const size_t i) const noexcept {

View File

@ -9,6 +9,7 @@ namespace EightBit {
class LittleEndianProcessor : public Processor {
public:
virtual ~LittleEndianProcessor() {};
LittleEndianProcessor(const LittleEndianProcessor& rhs);
[[nodiscard]] register16_t peekWord(register16_t address) noexcept final;
void pokeWord(register16_t address, register16_t value) noexcept final;

View File

@ -23,6 +23,7 @@ namespace EightBit {
virtual ~Processor() noexcept {}
Processor(const Processor& rhs);
bool operator==(const Processor& rhs) const;
[[nodiscard]] constexpr auto& PC() noexcept { return m_pc; }

View File

@ -1,6 +1,11 @@
#include "stdafx.h"
#include "../inc/ClockedChip.h"
EightBit::ClockedChip::ClockedChip(const ClockedChip& rhs)
: Chip(rhs) {
m_cycles = rhs.m_cycles;
}
void EightBit::ClockedChip::tick(const int extra) {
for (int i = 0; i < extra; ++i)
tick();

View File

@ -3,6 +3,10 @@
DEFINE_PIN_LEVEL_CHANGERS(POWER, Device);
EightBit::Device::Device(const Device& rhs) {
POWER() = rhs.POWER();
}
bool EightBit::Device::operator==(const EightBit::Device& rhs) const {
return POWER() == rhs.POWER();
}

View File

@ -19,6 +19,15 @@ EightBit::IntelProcessor::IntelProcessor(Bus& bus)
});
}
EightBit::IntelProcessor::IntelProcessor(const IntelProcessor& rhs)
: LittleEndianProcessor(rhs) {
m_sp = rhs.m_sp;
m_memptr = rhs.m_memptr;
HALT() = rhs.HALT();
}
void EightBit::IntelProcessor::resetWorkingRegisters() {
AF() = BC() = DE() = HL() = Mask16;
}

View File

@ -4,6 +4,9 @@
EightBit::LittleEndianProcessor::LittleEndianProcessor(Bus& memory)
: Processor(memory) {}
EightBit::LittleEndianProcessor::LittleEndianProcessor(const LittleEndianProcessor& rhs)
: Processor(rhs) {}
EightBit::register16_t EightBit::LittleEndianProcessor::getWord() {
const auto low = memoryRead();
++BUS().ADDRESS();

View File

@ -5,6 +5,14 @@ EightBit::Processor::Processor(Bus& bus) noexcept
: m_bus(bus) {
}
EightBit::Processor::Processor(const Processor& rhs)
: ClockedChip(rhs),
m_bus(rhs.m_bus) {
RESET() = rhs.RESET();
INT() = rhs.INT();
PC() = rhs.PC();
}
DEFINE_PIN_LEVEL_CHANGERS(RESET, Processor);
DEFINE_PIN_LEVEL_CHANGERS(INT, Processor);