mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2025-01-03 09:29:50 +00:00
Merge branch 'master' of https://github.com/MoleskiCoder/EightBit
This commit is contained in:
commit
e2e7fd0e00
@ -10,6 +10,17 @@ Board::Board(const Configuration& configuration)
|
|||||||
m_disassembler(*this) {
|
m_disassembler(*this) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Board::powerOn() {
|
||||||
|
EightBit::Bus::powerOn();
|
||||||
|
CPU().powerOn();
|
||||||
|
CPU().reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Board::powerOff() {
|
||||||
|
CPU().powerOff();
|
||||||
|
EightBit::Bus::powerOff();
|
||||||
|
}
|
||||||
|
|
||||||
void Board::initialise() {
|
void Board::initialise() {
|
||||||
|
|
||||||
auto romDirectory = m_configuration.getRomDirectory();
|
auto romDirectory = m_configuration.getRomDirectory();
|
||||||
@ -29,9 +40,6 @@ void Board::initialise() {
|
|||||||
m_cpu.ExecutingInstruction.connect(std::bind(&Board::Cpu_ExecutingInstruction_Debug, this, std::placeholders::_1));
|
m_cpu.ExecutingInstruction.connect(std::bind(&Board::Cpu_ExecutingInstruction_Debug, this, std::placeholders::_1));
|
||||||
}
|
}
|
||||||
|
|
||||||
CPU().powerOn();
|
|
||||||
CPU().reset();
|
|
||||||
|
|
||||||
poke(0, 0xc3); // JMP
|
poke(0, 0xc3); // JMP
|
||||||
CPU().pokeWord(1, m_configuration.getStartAddress());
|
CPU().pokeWord(1, m_configuration.getStartAddress());
|
||||||
|
|
||||||
@ -42,7 +50,7 @@ void Board::Cpu_ExecutingInstruction_Cpm(EightBit::Intel8080& cpu) {
|
|||||||
switch (cpu.PC().word) {
|
switch (cpu.PC().word) {
|
||||||
case 0x0: // CP/M warm start
|
case 0x0: // CP/M warm start
|
||||||
if (++m_warmstartCount == 3) {
|
if (++m_warmstartCount == 3) {
|
||||||
CPU().powerOff();
|
powerOff();
|
||||||
if (m_configuration.isProfileMode()) {
|
if (m_configuration.isProfileMode()) {
|
||||||
m_profiler.dump();
|
m_profiler.dump();
|
||||||
}
|
}
|
||||||
|
@ -17,9 +17,11 @@ public:
|
|||||||
EightBit::Intel8080& CPU() { return m_cpu; }
|
EightBit::Intel8080& CPU() { return m_cpu; }
|
||||||
const EightBit::Intel8080& CPU() const { return m_cpu; }
|
const EightBit::Intel8080& CPU() const { return m_cpu; }
|
||||||
|
|
||||||
void initialise();
|
virtual void powerOn() final;
|
||||||
|
virtual void powerOff() final;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual void initialise() final;
|
||||||
virtual EightBit::MemoryMapping mapping(uint16_t address) final {
|
virtual EightBit::MemoryMapping mapping(uint16_t address) final {
|
||||||
return { m_ram, 0x0000, 0xffff, EightBit::MemoryMapping::ReadWrite };
|
return { m_ram, 0x0000, 0xffff, EightBit::MemoryMapping::ReadWrite };
|
||||||
}
|
}
|
||||||
|
@ -8,14 +8,12 @@ int main(int, char*[]) {
|
|||||||
Configuration configuration;
|
Configuration configuration;
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
//configuration.setDebugMode(true);
|
configuration.setDebugMode(true);
|
||||||
configuration.setProfileMode(true);
|
configuration.setProfileMode(true);
|
||||||
#endif
|
#endif
|
||||||
//configuration.setDebugMode(true);
|
|
||||||
|
|
||||||
EightBit::TestHarness<Configuration, Board> harness(configuration);
|
EightBit::TestHarness<Configuration, Board> harness(configuration);
|
||||||
harness.initialise();
|
harness.run();
|
||||||
harness.runLoop();
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -4,34 +4,39 @@
|
|||||||
|
|
||||||
Fuse::TestRunner::TestRunner(const Test& test, const ExpectedTestResult& expected)
|
Fuse::TestRunner::TestRunner(const Test& test, const ExpectedTestResult& expected)
|
||||||
: m_test(test),
|
: m_test(test),
|
||||||
m_expected(expected),
|
m_expected(expected) {
|
||||||
m_ram(0x10000),
|
|
||||||
m_cpu(*this),
|
|
||||||
m_failed(false),
|
|
||||||
m_unimplemented(false) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
void Fuse::TestRunner::initialise() {
|
void Fuse::TestRunner::powerOn() {
|
||||||
m_cpu.powerOn();
|
EightBit::Bus::powerOn();
|
||||||
disableGameRom();
|
CPU().powerOn();
|
||||||
initialiseRegisters();
|
initialiseRegisters();
|
||||||
initialiseMemory();
|
initialiseMemory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Fuse::TestRunner::powerOff() {
|
||||||
|
CPU().powerOff();
|
||||||
|
EightBit::Bus::powerOff();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Fuse::TestRunner::initialise() {
|
||||||
|
disableGameRom();
|
||||||
|
}
|
||||||
|
|
||||||
void Fuse::TestRunner::initialiseRegisters() {
|
void Fuse::TestRunner::initialiseRegisters() {
|
||||||
|
|
||||||
const auto& testState = m_test.registerState;
|
const auto& testState = m_test.registerState;
|
||||||
const auto& inputRegisters = testState.registers;
|
const auto& inputRegisters = testState.registers;
|
||||||
|
|
||||||
m_cpu.AF() = inputRegisters[Fuse::RegisterState::AF];
|
CPU().AF() = inputRegisters[Fuse::RegisterState::AF];
|
||||||
m_cpu.BC() = inputRegisters[Fuse::RegisterState::BC];
|
CPU().BC() = inputRegisters[Fuse::RegisterState::BC];
|
||||||
m_cpu.DE() = inputRegisters[Fuse::RegisterState::DE];
|
CPU().DE() = inputRegisters[Fuse::RegisterState::DE];
|
||||||
m_cpu.HL() = inputRegisters[Fuse::RegisterState::HL];
|
CPU().HL() = inputRegisters[Fuse::RegisterState::HL];
|
||||||
|
|
||||||
m_cpu.SP() = inputRegisters[Fuse::RegisterState::SP];
|
CPU().SP() = inputRegisters[Fuse::RegisterState::SP];
|
||||||
m_cpu.PC() = inputRegisters[Fuse::RegisterState::PC];
|
CPU().PC() = inputRegisters[Fuse::RegisterState::PC];
|
||||||
}
|
}
|
||||||
|
|
||||||
void Fuse::TestRunner::initialiseMemory() {
|
void Fuse::TestRunner::initialiseMemory() {
|
||||||
@ -82,13 +87,13 @@ void Fuse::TestRunner::checkregisters() {
|
|||||||
const auto& expectedState = m_expected.registerState;
|
const auto& expectedState = m_expected.registerState;
|
||||||
const auto& expectedRegisters = expectedState.registers;
|
const auto& expectedRegisters = expectedState.registers;
|
||||||
|
|
||||||
auto af = m_cpu.AF() == expectedRegisters[Fuse::RegisterState::AF];
|
auto af = CPU().AF() == expectedRegisters[Fuse::RegisterState::AF];
|
||||||
auto bc = m_cpu.BC() == expectedRegisters[Fuse::RegisterState::BC];
|
auto bc = CPU().BC() == expectedRegisters[Fuse::RegisterState::BC];
|
||||||
auto de = m_cpu.DE() == expectedRegisters[Fuse::RegisterState::DE];
|
auto de = CPU().DE() == expectedRegisters[Fuse::RegisterState::DE];
|
||||||
auto hl = m_cpu.HL() == expectedRegisters[Fuse::RegisterState::HL];
|
auto hl = CPU().HL() == expectedRegisters[Fuse::RegisterState::HL];
|
||||||
|
|
||||||
auto sp = m_cpu.SP() == expectedRegisters[Fuse::RegisterState::SP];
|
auto sp = CPU().SP() == expectedRegisters[Fuse::RegisterState::SP];
|
||||||
auto pc = m_cpu.PC() == expectedRegisters[Fuse::RegisterState::PC];
|
auto pc = CPU().PC() == expectedRegisters[Fuse::RegisterState::PC];
|
||||||
|
|
||||||
auto success =
|
auto success =
|
||||||
af && bc && de && hl
|
af && bc && de && hl
|
||||||
@ -100,12 +105,12 @@ void Fuse::TestRunner::checkregisters() {
|
|||||||
|
|
||||||
if (!af) {
|
if (!af) {
|
||||||
auto expectedA = expectedRegisters[Fuse::RegisterState::AF].high;
|
auto expectedA = expectedRegisters[Fuse::RegisterState::AF].high;
|
||||||
auto gotA = m_cpu.A();
|
auto gotA = CPU().A();
|
||||||
if (expectedA != gotA)
|
if (expectedA != gotA)
|
||||||
dumpDifference("A", gotA, expectedA);
|
dumpDifference("A", gotA, expectedA);
|
||||||
|
|
||||||
auto expectedF = expectedRegisters[Fuse::RegisterState::AF].low;
|
auto expectedF = expectedRegisters[Fuse::RegisterState::AF].low;
|
||||||
auto gotF = m_cpu.F();
|
auto gotF = CPU().F();
|
||||||
if (expectedF != gotF) {
|
if (expectedF != gotF) {
|
||||||
std::cerr
|
std::cerr
|
||||||
<< "**** F, Expected: "
|
<< "**** F, Expected: "
|
||||||
@ -118,31 +123,31 @@ void Fuse::TestRunner::checkregisters() {
|
|||||||
|
|
||||||
if (!bc) {
|
if (!bc) {
|
||||||
auto expectedWord = expectedRegisters[Fuse::RegisterState::BC];
|
auto expectedWord = expectedRegisters[Fuse::RegisterState::BC];
|
||||||
auto actualWord = m_cpu.BC();
|
auto actualWord = CPU().BC();
|
||||||
dumpDifference("B", "C", actualWord, expectedWord);
|
dumpDifference("B", "C", actualWord, expectedWord);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!de) {
|
if (!de) {
|
||||||
auto expectedWord = expectedRegisters[Fuse::RegisterState::DE];
|
auto expectedWord = expectedRegisters[Fuse::RegisterState::DE];
|
||||||
auto actualWord = m_cpu.DE();
|
auto actualWord = CPU().DE();
|
||||||
dumpDifference("D", "E", actualWord, expectedWord);
|
dumpDifference("D", "E", actualWord, expectedWord);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hl) {
|
if (!hl) {
|
||||||
auto expectedWord = expectedRegisters[Fuse::RegisterState::HL];
|
auto expectedWord = expectedRegisters[Fuse::RegisterState::HL];
|
||||||
auto actualWord = m_cpu.HL();
|
auto actualWord = CPU().HL();
|
||||||
dumpDifference("H", "L", actualWord, expectedWord);
|
dumpDifference("H", "L", actualWord, expectedWord);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sp) {
|
if (!sp) {
|
||||||
auto expectedWord = expectedRegisters[Fuse::RegisterState::SP];
|
auto expectedWord = expectedRegisters[Fuse::RegisterState::SP];
|
||||||
auto actualWord = m_cpu.SP();
|
auto actualWord = CPU().SP();
|
||||||
dumpDifference("SPH", "SPL", actualWord, expectedWord);
|
dumpDifference("SPH", "SPL", actualWord, expectedWord);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pc) {
|
if (!pc) {
|
||||||
auto expectedWord = expectedRegisters[Fuse::RegisterState::PC];
|
auto expectedWord = expectedRegisters[Fuse::RegisterState::PC];
|
||||||
auto actualWord = m_cpu.PC();
|
auto actualWord = CPU().PC();
|
||||||
dumpDifference("PCH", "PCL", actualWord, expectedWord);
|
dumpDifference("PCH", "PCL", actualWord, expectedWord);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -177,10 +182,10 @@ void Fuse::TestRunner::checkMemory() {
|
|||||||
|
|
||||||
void Fuse::TestRunner::run() {
|
void Fuse::TestRunner::run() {
|
||||||
|
|
||||||
initialise();
|
powerOn();
|
||||||
auto allowedCycles = m_test.registerState.tstates;
|
auto allowedCycles = m_test.registerState.tstates;
|
||||||
try {
|
try {
|
||||||
m_cpu.run(allowedCycles);
|
CPU().run(allowedCycles);
|
||||||
check();
|
check();
|
||||||
} catch (std::logic_error& error) {
|
} catch (std::logic_error& error) {
|
||||||
m_unimplemented = true;
|
m_unimplemented = true;
|
||||||
|
@ -16,11 +16,10 @@ namespace Fuse {
|
|||||||
const Test& m_test;
|
const Test& m_test;
|
||||||
const ExpectedTestResult& m_expected;
|
const ExpectedTestResult& m_expected;
|
||||||
|
|
||||||
bool m_failed;
|
bool m_failed = false;
|
||||||
bool m_unimplemented;
|
bool m_unimplemented = false;
|
||||||
|
|
||||||
EightBit::Ram m_ram;
|
EightBit::Ram m_ram = 0x10000;
|
||||||
EightBit::GameBoy::LR35902 m_cpu;
|
|
||||||
|
|
||||||
void initialise();
|
void initialise();
|
||||||
void initialiseRegisters();
|
void initialiseRegisters();
|
||||||
@ -47,5 +46,8 @@ namespace Fuse {
|
|||||||
void run();
|
void run();
|
||||||
bool failed() const { return m_failed; }
|
bool failed() const { return m_failed; }
|
||||||
bool unimplemented() const { return m_unimplemented; }
|
bool unimplemented() const { return m_unimplemented; }
|
||||||
|
|
||||||
|
virtual void powerOn() final;
|
||||||
|
virtual void powerOff() final;
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -36,6 +36,9 @@ namespace EightBit {
|
|||||||
|
|
||||||
Bus() noexcept;
|
Bus() noexcept;
|
||||||
|
|
||||||
|
virtual void powerOn() override;
|
||||||
|
virtual void powerOff() override;
|
||||||
|
|
||||||
auto& CPU() { return m_cpu; }
|
auto& CPU() { return m_cpu; }
|
||||||
auto& VRAM() { return m_videoRam; }
|
auto& VRAM() { return m_videoRam; }
|
||||||
auto& OAMRAM() { return m_oamRam; }
|
auto& OAMRAM() { return m_oamRam; }
|
||||||
|
@ -8,6 +8,17 @@ EightBit::GameBoy::Bus::Bus() noexcept
|
|||||||
WrittenByte.connect(std::bind(&GameBoy::Bus::Bus_WrittenByte, this, std::placeholders::_1));
|
WrittenByte.connect(std::bind(&GameBoy::Bus::Bus_WrittenByte, this, std::placeholders::_1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EightBit::GameBoy::Bus::powerOn() {
|
||||||
|
EightBit::Bus::powerOn();
|
||||||
|
CPU().powerOn();
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
void EightBit::GameBoy::Bus::powerOff() {
|
||||||
|
CPU().powerOff();
|
||||||
|
EightBit::Bus::powerOff();
|
||||||
|
}
|
||||||
|
|
||||||
void EightBit::GameBoy::Bus::reset() {
|
void EightBit::GameBoy::Bus::reset() {
|
||||||
IO().reset();
|
IO().reset();
|
||||||
LR35902::lower(CPU().RESET());
|
LR35902::lower(CPU().RESET());
|
||||||
|
@ -13,6 +13,16 @@ Board::Board(const Configuration& configuration)
|
|||||||
m_disassembler(*this, m_cpu, m_symbols),
|
m_disassembler(*this, m_cpu, m_symbols),
|
||||||
m_profiler(m_cpu, m_disassembler, m_symbols) {}
|
m_profiler(m_cpu, m_disassembler, m_symbols) {}
|
||||||
|
|
||||||
|
void Board::powerOn() {
|
||||||
|
EightBit::Bus::powerOn();
|
||||||
|
CPU().powerOn();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Board::powerOff() {
|
||||||
|
CPU().powerOff();
|
||||||
|
EightBit::Bus::powerOff();
|
||||||
|
}
|
||||||
|
|
||||||
void Board::initialise() {
|
void Board::initialise() {
|
||||||
|
|
||||||
auto programFilename = m_configuration.getProgram();
|
auto programFilename = m_configuration.getProgram();
|
||||||
@ -57,8 +67,6 @@ void Board::initialise() {
|
|||||||
m_pollCounter = 0;
|
m_pollCounter = 0;
|
||||||
m_pollInterval = m_configuration.getPollInterval();
|
m_pollInterval = m_configuration.getPollInterval();
|
||||||
|
|
||||||
CPU().powerOn();
|
|
||||||
|
|
||||||
poke(0x00, 0x4c);
|
poke(0x00, 0x4c);
|
||||||
CPU().pokeWord(1, m_configuration.getStartAddress());
|
CPU().pokeWord(1, m_configuration.getStartAddress());
|
||||||
}
|
}
|
||||||
@ -77,7 +85,7 @@ void Board::Cpu_ExecutedInstruction_StopLoop(EightBit::MOS6502& cpu) {
|
|||||||
if (m_oldPC != pc) {
|
if (m_oldPC != pc) {
|
||||||
m_oldPC = pc;
|
m_oldPC = pc;
|
||||||
} else {
|
} else {
|
||||||
CPU().powerOff();
|
powerOff();
|
||||||
auto test = peek(0x0200);
|
auto test = peek(0x0200);
|
||||||
std::cout << std::endl << "** Test=" << std::hex << (int)test;
|
std::cout << std::endl << "** Test=" << std::hex << (int)test;
|
||||||
}
|
}
|
||||||
|
@ -17,9 +17,11 @@ public:
|
|||||||
|
|
||||||
EightBit::MOS6502& CPU() { return m_cpu; }
|
EightBit::MOS6502& CPU() { return m_cpu; }
|
||||||
|
|
||||||
void initialise();
|
virtual void powerOn() final;
|
||||||
|
virtual void powerOff() final;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual void initialise() final;
|
||||||
virtual EightBit::MemoryMapping mapping(uint16_t address) final {
|
virtual EightBit::MemoryMapping mapping(uint16_t address) final {
|
||||||
return { m_ram, 0x0000, 0xffff, EightBit::MemoryMapping::ReadWrite };
|
return { m_ram, 0x0000, 0xffff, EightBit::MemoryMapping::ReadWrite };
|
||||||
}
|
}
|
||||||
|
@ -16,8 +16,7 @@ int main(int argc, char* argv[]) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
EightBit::TestHarness<Configuration, Board> harness(configuration);
|
EightBit::TestHarness<Configuration, Board> harness(configuration);
|
||||||
harness.initialise();
|
harness.run();
|
||||||
harness.runLoop();
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -274,11 +274,11 @@ namespace EightBit {
|
|||||||
auto carry() const { return CC() & CF; }
|
auto carry() const { return CC() & CF; }
|
||||||
auto halfCarry() const { return CC() & HF; }
|
auto halfCarry() const { return CC() & HF; }
|
||||||
|
|
||||||
auto LS() const { return carry() | (zero() >> 2); } // (C OR Z)
|
auto LS() const { return carry() || zero(); } // (C OR Z)
|
||||||
auto HI() const { return !LS(); } // !(C OR Z)
|
auto HI() const { return !LS(); } // !(C OR Z)
|
||||||
auto LT() const { return (negative() >> 3) ^ (overflow() >> 1); } // (N XOR V)
|
auto LT() const { return (negative() >> 3) ^ (overflow() >> 1); } // (N XOR V)
|
||||||
auto GE() const { return !LT(); } // !(N XOR V)
|
auto GE() const { return !LT(); } // !(N XOR V)
|
||||||
auto LE() const { return (zero() >> 2) | ((negative() >> 3) ^ (overflow() >> 1)); } // (Z OR (N XOR V))
|
auto LE() const { return zero() || LT(); } // (Z OR (N XOR V))
|
||||||
auto GT() const { return !LE(); } // !(Z OR (N XOR V))
|
auto GT() const { return !LE(); } // !(Z OR (N XOR V))
|
||||||
|
|
||||||
// Branching
|
// Branching
|
||||||
|
@ -7,11 +7,9 @@ Board::Board(const Configuration& configuration)
|
|||||||
m_disassembler(*this, m_cpu) {
|
m_disassembler(*this, m_cpu) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Board::initialise() {
|
void Board::powerOn() {
|
||||||
|
|
||||||
// Load our BASIC interpreter
|
EightBit::Bus::powerOn();
|
||||||
const auto directory = m_configuration.getRomDirectory() + "\\";
|
|
||||||
loadHexFile(directory + "ExBasROM.hex");
|
|
||||||
|
|
||||||
// Get the CPU ready for action
|
// Get the CPU ready for action
|
||||||
CPU().powerOn();
|
CPU().powerOn();
|
||||||
@ -26,6 +24,19 @@ void Board::initialise() {
|
|||||||
ACIA().lower(ACIA().CTS());
|
ACIA().lower(ACIA().CTS());
|
||||||
ACIA().powerOn();
|
ACIA().powerOn();
|
||||||
accessAcia();
|
accessAcia();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Board::powerOff() {
|
||||||
|
ACIA().powerOff();
|
||||||
|
CPU().powerOff();
|
||||||
|
EightBit::Bus::powerOff();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Board::initialise() {
|
||||||
|
|
||||||
|
// Load our BASIC interpreter
|
||||||
|
const auto directory = m_configuration.getRomDirectory() + "\\";
|
||||||
|
loadHexFile(directory + "ExBasROM.hex");
|
||||||
|
|
||||||
// Once the reset has completed, we can wire the ACIA event handlers...
|
// Once the reset has completed, we can wire the ACIA event handlers...
|
||||||
ACIA().Transmitting.connect(std::bind(&Board::Acia_Transmitting, this, std::placeholders::_1));
|
ACIA().Transmitting.connect(std::bind(&Board::Acia_Transmitting, this, std::placeholders::_1));
|
||||||
@ -95,7 +106,7 @@ void Board::Cpu_ExecutedInstruction_Terminator(EightBit::mc6809&) {
|
|||||||
assert(CPU().cycles() > 0);
|
assert(CPU().cycles() > 0);
|
||||||
m_totalCycleCount += CPU().cycles();
|
m_totalCycleCount += CPU().cycles();
|
||||||
if (m_totalCycleCount > Configuration::TerminationCycles)
|
if (m_totalCycleCount > Configuration::TerminationCycles)
|
||||||
CPU().powerOff();
|
powerOff();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Board::Cpu_ExecutedInstruction_Acia(EightBit::mc6809&) {
|
void Board::Cpu_ExecutedInstruction_Acia(EightBit::mc6809&) {
|
||||||
|
@ -19,9 +19,11 @@ public:
|
|||||||
auto& CPU() { return m_cpu; }
|
auto& CPU() { return m_cpu; }
|
||||||
auto& ACIA() { return m_acia; }
|
auto& ACIA() { return m_acia; }
|
||||||
|
|
||||||
void initialise();
|
virtual void powerOn() final;
|
||||||
|
virtual void powerOff() final;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual void initialise() final;
|
||||||
virtual EightBit::MemoryMapping mapping(uint16_t address) final;
|
virtual EightBit::MemoryMapping mapping(uint16_t address) final;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -13,11 +13,9 @@ int main(int argc, char* argv[]) {
|
|||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
configuration.setDebugMode(true);
|
configuration.setDebugMode(true);
|
||||||
#endif
|
#endif
|
||||||
//configuration.setDebugMode(true);
|
|
||||||
|
|
||||||
EightBit::TestHarness<Configuration, Board> harness(configuration);
|
EightBit::TestHarness<Configuration, Board> harness(configuration);
|
||||||
harness.initialise();
|
harness.run();
|
||||||
harness.runLoop();
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -2,16 +2,38 @@
|
|||||||
#include "Board.h"
|
#include "Board.h"
|
||||||
|
|
||||||
Board::Board()
|
Board::Board()
|
||||||
: m_cpu(EightBit::mc6809(*this)) {
|
: m_cpu(EightBit::mc6809(*this)),
|
||||||
|
m_disassembler(*this, m_cpu) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Board::initialise() {
|
void Board::powerOn() {
|
||||||
|
EightBit::Bus::powerOn();
|
||||||
CPU().powerOn();
|
CPU().powerOn();
|
||||||
CPU().raise(CPU().NMI());
|
CPU().raise(CPU().NMI());
|
||||||
CPU().raise(CPU().FIRQ());
|
CPU().raise(CPU().FIRQ());
|
||||||
CPU().reset();
|
CPU().reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Board::powerOff() {
|
||||||
|
CPU().powerOff();
|
||||||
|
EightBit::Bus::powerOff();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Board::initialise() {
|
||||||
|
//CPU().ExecutingInstruction.connect(std::bind(&Board::Cpu_ExecutingInstruction_Debug, this, std::placeholders::_1));
|
||||||
|
//CPU().ExecutedInstruction.connect(std::bind(&Board::Cpu_ExecutedInstruction_Debug, this, std::placeholders::_1));
|
||||||
|
}
|
||||||
|
|
||||||
EightBit::MemoryMapping Board::mapping(uint16_t) {
|
EightBit::MemoryMapping Board::mapping(uint16_t) {
|
||||||
return { m_ram, 0x0000, 0xffff, EightBit::MemoryMapping::ReadWrite };
|
return { m_ram, 0x0000, 0xffff, EightBit::MemoryMapping::ReadWrite };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Board::Cpu_ExecutingInstruction_Debug(EightBit::mc6809&) {
|
||||||
|
m_disassembleAt = CPU().PC();
|
||||||
|
m_ignoreDisassembly = m_disassembler.ignore();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Board::Cpu_ExecutedInstruction_Debug(EightBit::mc6809&) {
|
||||||
|
if (!m_ignoreDisassembly)
|
||||||
|
std::cout << m_disassembler.trace(m_disassembleAt) << " " << std::endl;
|
||||||
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <Ram.h>
|
#include <Ram.h>
|
||||||
#include <Bus.h>
|
#include <Bus.h>
|
||||||
#include <mc6809.h>
|
#include <mc6809.h>
|
||||||
|
#include <Disassembly.h>
|
||||||
|
|
||||||
class Board : public EightBit::Bus {
|
class Board : public EightBit::Bus {
|
||||||
public:
|
public:
|
||||||
@ -10,12 +11,22 @@ public:
|
|||||||
|
|
||||||
EightBit::mc6809& CPU() { return m_cpu; }
|
EightBit::mc6809& CPU() { return m_cpu; }
|
||||||
|
|
||||||
void initialise();
|
virtual void powerOn() final;
|
||||||
|
virtual void powerOff() final;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual void initialise() final;
|
||||||
virtual EightBit::MemoryMapping mapping(uint16_t address) final;
|
virtual EightBit::MemoryMapping mapping(uint16_t address) final;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EightBit::Ram m_ram = 0x10000; // 0000 - FFFF, 64K RAM
|
EightBit::Ram m_ram = 0x10000; // 0000 - FFFF, 64K RAM
|
||||||
EightBit::mc6809 m_cpu;
|
EightBit::mc6809 m_cpu;
|
||||||
|
EightBit::Disassembly m_disassembler;
|
||||||
|
|
||||||
|
// The m_disassembleAt and m_ignoreDisassembly are used to skip pin events
|
||||||
|
EightBit::register16_t m_disassembleAt = 0x0000;
|
||||||
|
bool m_ignoreDisassembly = false;
|
||||||
|
|
||||||
|
void Cpu_ExecutingInstruction_Debug(EightBit::mc6809&);
|
||||||
|
void Cpu_ExecutedInstruction_Debug(EightBit::mc6809&);
|
||||||
};
|
};
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
TEST_CASE("Add Accumulator B to Index Register X Unsigned", "[ABX]") {
|
TEST_CASE("Add Accumulator B to Index Register X Unsigned", "[ABX]") {
|
||||||
|
|
||||||
Board board;
|
Board board;
|
||||||
board.initialise();
|
board.powerOn();
|
||||||
auto& cpu = board.CPU();
|
auto& cpu = board.CPU();
|
||||||
cpu.step(); // Step over the reset
|
cpu.step(); // Step over the reset
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ TEST_CASE("Add Accumulator B to Index Register X Unsigned", "[ABX]") {
|
|||||||
TEST_CASE("Add Memory Plus Carry to Accumulator", "[ADC][ADCA]") {
|
TEST_CASE("Add Memory Plus Carry to Accumulator", "[ADC][ADCA]") {
|
||||||
|
|
||||||
Board board;
|
Board board;
|
||||||
board.initialise();
|
board.powerOn();
|
||||||
auto& cpu = board.CPU();
|
auto& cpu = board.CPU();
|
||||||
cpu.step(); // Step over the reset
|
cpu.step(); // Step over the reset
|
||||||
|
|
||||||
@ -153,7 +153,7 @@ TEST_CASE("Add Memory Plus Carry to Accumulator", "[ADC][ADCA]") {
|
|||||||
TEST_CASE("Add Memory to Accumulator", "[ADD][ADDA][ADDB][ADDD]") {
|
TEST_CASE("Add Memory to Accumulator", "[ADD][ADDA][ADDB][ADDD]") {
|
||||||
|
|
||||||
Board board;
|
Board board;
|
||||||
board.initialise();
|
board.powerOn();
|
||||||
auto& cpu = board.CPU();
|
auto& cpu = board.CPU();
|
||||||
cpu.step(); // Step over the reset
|
cpu.step(); // Step over the reset
|
||||||
|
|
||||||
@ -350,7 +350,7 @@ TEST_CASE("Add Memory to Accumulator", "[ADD][ADDA][ADDB][ADDD]") {
|
|||||||
TEST_CASE("Logical AND Accumulator", "[AND][ANDA]") {
|
TEST_CASE("Logical AND Accumulator", "[AND][ANDA]") {
|
||||||
|
|
||||||
Board board;
|
Board board;
|
||||||
board.initialise();
|
board.powerOn();
|
||||||
auto& cpu = board.CPU();
|
auto& cpu = board.CPU();
|
||||||
cpu.step(); // Step over the reset
|
cpu.step(); // Step over the reset
|
||||||
|
|
||||||
@ -370,7 +370,7 @@ TEST_CASE("Logical AND Accumulator", "[AND][ANDA]") {
|
|||||||
TEST_CASE("Shift Accumulator or Memory Byte Left", "[ASL][ASLA]") {
|
TEST_CASE("Shift Accumulator or Memory Byte Left", "[ASL][ASLA]") {
|
||||||
|
|
||||||
Board board;
|
Board board;
|
||||||
board.initialise();
|
board.powerOn();
|
||||||
auto& cpu = board.CPU();
|
auto& cpu = board.CPU();
|
||||||
cpu.step(); // Step over the reset
|
cpu.step(); // Step over the reset
|
||||||
|
|
||||||
@ -389,7 +389,7 @@ TEST_CASE("Shift Accumulator or Memory Byte Left", "[ASL][ASLA]") {
|
|||||||
TEST_CASE("Shift Accumulator or Memory Byte Right", "[ASR][ASRA]") {
|
TEST_CASE("Shift Accumulator or Memory Byte Right", "[ASR][ASRA]") {
|
||||||
|
|
||||||
Board board;
|
Board board;
|
||||||
board.initialise();
|
board.powerOn();
|
||||||
auto& cpu = board.CPU();
|
auto& cpu = board.CPU();
|
||||||
cpu.step(); // Step over the reset
|
cpu.step(); // Step over the reset
|
||||||
|
|
||||||
@ -408,7 +408,7 @@ TEST_CASE("Shift Accumulator or Memory Byte Right", "[ASR][ASRA]") {
|
|||||||
TEST_CASE("Bit Test", "[BIT][BITA]") {
|
TEST_CASE("Bit Test", "[BIT][BITA]") {
|
||||||
|
|
||||||
Board board;
|
Board board;
|
||||||
board.initialise();
|
board.powerOn();
|
||||||
auto& cpu = board.CPU();
|
auto& cpu = board.CPU();
|
||||||
cpu.step(); // Step over the reset
|
cpu.step(); // Step over the reset
|
||||||
|
|
||||||
@ -427,7 +427,7 @@ TEST_CASE("Bit Test", "[BIT][BITA]") {
|
|||||||
TEST_CASE("Clear Accumulator or Memory", "[CLR][CLRA]") {
|
TEST_CASE("Clear Accumulator or Memory", "[CLR][CLRA]") {
|
||||||
|
|
||||||
Board board;
|
Board board;
|
||||||
board.initialise();
|
board.powerOn();
|
||||||
auto& cpu = board.CPU();
|
auto& cpu = board.CPU();
|
||||||
cpu.step(); // Step over the reset
|
cpu.step(); // Step over the reset
|
||||||
|
|
||||||
@ -447,7 +447,7 @@ TEST_CASE("Clear Accumulator or Memory", "[CLR][CLRA]") {
|
|||||||
TEST_CASE("Compare Memory with a Register", "[CMP][CMPA][CMPB][CMPX]") {
|
TEST_CASE("Compare Memory with a Register", "[CMP][CMPA][CMPB][CMPX]") {
|
||||||
|
|
||||||
Board board;
|
Board board;
|
||||||
board.initialise();
|
board.powerOn();
|
||||||
auto& cpu = board.CPU();
|
auto& cpu = board.CPU();
|
||||||
cpu.step(); // Step over the reset
|
cpu.step(); // Step over the reset
|
||||||
|
|
||||||
@ -544,7 +544,7 @@ TEST_CASE("Compare Memory with a Register", "[CMP][CMPA][CMPB][CMPX]") {
|
|||||||
TEST_CASE("Decrement Accumulator or Memory", "[DEC][DECA]") {
|
TEST_CASE("Decrement Accumulator or Memory", "[DEC][DECA]") {
|
||||||
|
|
||||||
Board board;
|
Board board;
|
||||||
board.initialise();
|
board.powerOn();
|
||||||
auto& cpu = board.CPU();
|
auto& cpu = board.CPU();
|
||||||
cpu.step(); // Step over the reset
|
cpu.step(); // Step over the reset
|
||||||
|
|
||||||
@ -593,7 +593,7 @@ TEST_CASE("Decrement Accumulator or Memory", "[DEC][DECA]") {
|
|||||||
TEST_CASE("Increment Accumulator or Memory Location by 1", "[INC][INCA]") {
|
TEST_CASE("Increment Accumulator or Memory Location by 1", "[INC][INCA]") {
|
||||||
|
|
||||||
Board board;
|
Board board;
|
||||||
board.initialise();
|
board.powerOn();
|
||||||
auto& cpu = board.CPU();
|
auto& cpu = board.CPU();
|
||||||
cpu.step(); // Step over the reset
|
cpu.step(); // Step over the reset
|
||||||
|
|
||||||
@ -640,7 +640,7 @@ TEST_CASE("Increment Accumulator or Memory Location by 1", "[INC][INCA]") {
|
|||||||
TEST_CASE("Subtract Memory from Accumulator with Borrow (8-bit)", "[SBC][SBCA][SBCB]") {
|
TEST_CASE("Subtract Memory from Accumulator with Borrow (8-bit)", "[SBC][SBCA][SBCB]") {
|
||||||
|
|
||||||
Board board;
|
Board board;
|
||||||
board.initialise();
|
board.powerOn();
|
||||||
auto& cpu = board.CPU();
|
auto& cpu = board.CPU();
|
||||||
cpu.step(); // Step over the reset
|
cpu.step(); // Step over the reset
|
||||||
|
|
||||||
@ -729,7 +729,7 @@ TEST_CASE("Subtract Memory from Accumulator with Borrow (8-bit)", "[SBC][SBCA][S
|
|||||||
TEST_CASE("Subtract Memory from Register", "[SUB][SUBA]") {
|
TEST_CASE("Subtract Memory from Register", "[SUB][SUBA]") {
|
||||||
|
|
||||||
Board board;
|
Board board;
|
||||||
board.initialise();
|
board.powerOn();
|
||||||
auto& cpu = board.CPU();
|
auto& cpu = board.CPU();
|
||||||
cpu.step(); // Step over the reset
|
cpu.step(); // Step over the reset
|
||||||
|
|
||||||
@ -822,3 +822,166 @@ TEST_CASE("Subtract Memory from Register", "[SUB][SUBA]") {
|
|||||||
REQUIRE(cpu.cycles() == 4);
|
REQUIRE(cpu.cycles() == 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE(" Branch if Greater Than Zero", "[BGT]") {
|
||||||
|
|
||||||
|
Board board;
|
||||||
|
board.powerOn();
|
||||||
|
auto& cpu = board.CPU();
|
||||||
|
cpu.step(); // Step over the reset
|
||||||
|
|
||||||
|
board.poke(0, 0x2e); // BGT
|
||||||
|
board.poke(1, 0x03);
|
||||||
|
board.poke(2, 0x86); // LDA #1
|
||||||
|
board.poke(3, 0x01);
|
||||||
|
board.poke(4, 0x12); // NOP
|
||||||
|
board.poke(5, 0x86); // LDA #2
|
||||||
|
board.poke(6, 0x02);
|
||||||
|
board.poke(7, 0x12); // NOP
|
||||||
|
|
||||||
|
SECTION("BGT1") {
|
||||||
|
cpu.A() = 0;
|
||||||
|
cpu.CC() = EightBit::mc6809::ZF;
|
||||||
|
cpu.step();
|
||||||
|
cpu.step();
|
||||||
|
REQUIRE(cpu.A() == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
cpu.reset();
|
||||||
|
cpu.step();
|
||||||
|
|
||||||
|
SECTION("BGT2") {
|
||||||
|
REQUIRE(cpu.PC() == 0);
|
||||||
|
cpu.CC() = 0;
|
||||||
|
cpu.step();
|
||||||
|
cpu.step();
|
||||||
|
REQUIRE(cpu.A() == 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
cpu.reset();
|
||||||
|
cpu.step();
|
||||||
|
|
||||||
|
SECTION("BGT3") {
|
||||||
|
REQUIRE(cpu.PC() == 0);
|
||||||
|
cpu.CC() = EightBit::mc6809::NF;
|
||||||
|
cpu.step();
|
||||||
|
cpu.step();
|
||||||
|
REQUIRE(cpu.A() == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
cpu.reset();
|
||||||
|
cpu.step();
|
||||||
|
|
||||||
|
SECTION("BGT4") {
|
||||||
|
REQUIRE(cpu.PC() == 0);
|
||||||
|
cpu.CC() = EightBit::mc6809::NF | EightBit::mc6809::VF;
|
||||||
|
cpu.step();
|
||||||
|
cpu.step();
|
||||||
|
REQUIRE(cpu.A() == 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
cpu.reset();
|
||||||
|
cpu.step();
|
||||||
|
|
||||||
|
SECTION("BGT5") {
|
||||||
|
REQUIRE(cpu.PC() == 0);
|
||||||
|
cpu.CC() = EightBit::mc6809::ZF | EightBit::mc6809::NF;
|
||||||
|
cpu.step();
|
||||||
|
cpu.step();
|
||||||
|
REQUIRE(cpu.A() == 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE(" Branch if Higher", "[BHI]") {
|
||||||
|
|
||||||
|
Board board;
|
||||||
|
board.powerOn();
|
||||||
|
auto& cpu = board.CPU();
|
||||||
|
cpu.step(); // Step over the reset
|
||||||
|
|
||||||
|
board.poke(0, 0x22); // BHI
|
||||||
|
board.poke(1, 0x03);
|
||||||
|
board.poke(2, 0x86); // LDA #1
|
||||||
|
board.poke(3, 0x01);
|
||||||
|
board.poke(4, 0x12); // NOP
|
||||||
|
board.poke(5, 0x86); // LDA #2
|
||||||
|
board.poke(6, 0x02);
|
||||||
|
board.poke(7, 0x12); // NOP
|
||||||
|
|
||||||
|
SECTION("BHI1") {
|
||||||
|
cpu.A() = 0;
|
||||||
|
cpu.CC() = EightBit::mc6809::ZF;
|
||||||
|
cpu.step();
|
||||||
|
cpu.step();
|
||||||
|
REQUIRE(cpu.A() == 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Branch on Less than or Equal to Zero", "[BLE]") {
|
||||||
|
|
||||||
|
Board board;
|
||||||
|
board.powerOn();
|
||||||
|
auto& cpu = board.CPU();
|
||||||
|
cpu.step(); // Step over the reset
|
||||||
|
|
||||||
|
board.poke(0, 0x2f); // BLE
|
||||||
|
board.poke(1, 0x03);
|
||||||
|
board.poke(2, 0x86); // LDA #1
|
||||||
|
board.poke(3, 0x01);
|
||||||
|
board.poke(4, 0x12); // NOP
|
||||||
|
board.poke(5, 0x86); // LDA #2
|
||||||
|
board.poke(6, 0x02);
|
||||||
|
board.poke(7, 0x12); // NOP
|
||||||
|
|
||||||
|
SECTION("BLE1") {
|
||||||
|
cpu.A() = 0;
|
||||||
|
cpu.CC() = EightBit::mc6809::ZF;
|
||||||
|
cpu.step();
|
||||||
|
cpu.step();
|
||||||
|
REQUIRE(cpu.A() == 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
cpu.reset();
|
||||||
|
cpu.step();
|
||||||
|
|
||||||
|
SECTION("BLE2") {
|
||||||
|
cpu.A() = 0;
|
||||||
|
cpu.CC() = 0;
|
||||||
|
cpu.step();
|
||||||
|
cpu.step();
|
||||||
|
REQUIRE(cpu.A() == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
cpu.reset();
|
||||||
|
cpu.step();
|
||||||
|
|
||||||
|
SECTION("BLE3") {
|
||||||
|
cpu.A() = 0;
|
||||||
|
cpu.CC() = EightBit::mc6809::NF;
|
||||||
|
cpu.step();
|
||||||
|
cpu.step();
|
||||||
|
REQUIRE(cpu.A() == 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
cpu.reset();
|
||||||
|
cpu.step();
|
||||||
|
|
||||||
|
SECTION("BLE4") {
|
||||||
|
cpu.A() = 0;
|
||||||
|
cpu.CC() = EightBit::mc6809::NF | EightBit::mc6809::VF;
|
||||||
|
cpu.step();
|
||||||
|
cpu.step();
|
||||||
|
REQUIRE(cpu.A() == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
cpu.reset();
|
||||||
|
cpu.step();
|
||||||
|
|
||||||
|
SECTION("BLE5") {
|
||||||
|
cpu.A() = 0;
|
||||||
|
cpu.CC() = EightBit::mc6809::ZF | EightBit::mc6809::NF;
|
||||||
|
cpu.step();
|
||||||
|
cpu.step();
|
||||||
|
REQUIRE(cpu.A() == 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -46,7 +46,7 @@ namespace EightBit {
|
|||||||
// +--------+------------------+------------------+--------------------+-----------------------+
|
// +--------+------------------+------------------+--------------------+-----------------------+
|
||||||
// * Leading bit = LSB = Bit 0
|
// * Leading bit = LSB = Bit 0
|
||||||
// ** Data bit will be zero in 7-bit plus parity modes
|
// ** Data bit will be zero in 7-bit plus parity modes
|
||||||
// *** Data bit is "don't case" in 7-bit plus parity modes
|
// *** Data bit is "don't care" in 7-bit plus parity modes
|
||||||
|
|
||||||
enum ControlRegisters {
|
enum ControlRegisters {
|
||||||
CR0 = 0b1, // Counter divide
|
CR0 = 0b1, // Counter divide
|
||||||
|
@ -10,9 +10,18 @@ Fuse::TestRunner::TestRunner(const Test& test, const ExpectedTestResult& expecte
|
|||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
void Fuse::TestRunner::initialise() {
|
void Fuse::TestRunner::powerOn() {
|
||||||
|
EightBit::Bus::powerOn();
|
||||||
m_cpu.powerOn();
|
m_cpu.powerOn();
|
||||||
initialiseRegisters();
|
initialiseRegisters();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Fuse::TestRunner::powerOff() {
|
||||||
|
m_cpu.powerOff();
|
||||||
|
EightBit::Bus::powerOff();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Fuse::TestRunner::initialise() {
|
||||||
initialiseMemory();
|
initialiseMemory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -319,7 +328,7 @@ void Fuse::TestRunner::checkMemory() {
|
|||||||
|
|
||||||
void Fuse::TestRunner::run() {
|
void Fuse::TestRunner::run() {
|
||||||
|
|
||||||
initialise();
|
powerOn();
|
||||||
auto allowedCycles = m_test.registerState.tstates;
|
auto allowedCycles = m_test.registerState.tstates;
|
||||||
try {
|
try {
|
||||||
m_cpu.run(allowedCycles);
|
m_cpu.run(allowedCycles);
|
||||||
|
@ -21,7 +21,6 @@ namespace Fuse {
|
|||||||
EightBit::InputOutput m_ports;
|
EightBit::InputOutput m_ports;
|
||||||
EightBit::Z80 m_cpu;
|
EightBit::Z80 m_cpu;
|
||||||
|
|
||||||
void initialise();
|
|
||||||
void initialiseRegisters();
|
void initialiseRegisters();
|
||||||
void initialiseMemory();
|
void initialiseMemory();
|
||||||
|
|
||||||
@ -36,6 +35,7 @@ namespace Fuse {
|
|||||||
EightBit::register16_t actual, EightBit::register16_t expected) const;
|
EightBit::register16_t actual, EightBit::register16_t expected) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual void initialise() final;
|
||||||
virtual EightBit::MemoryMapping mapping(uint16_t address) final {
|
virtual EightBit::MemoryMapping mapping(uint16_t address) final {
|
||||||
return { m_ram, 0x0000, 0xffff, EightBit::MemoryMapping::ReadWrite };
|
return { m_ram, 0x0000, 0xffff, EightBit::MemoryMapping::ReadWrite };
|
||||||
}
|
}
|
||||||
@ -46,5 +46,8 @@ namespace Fuse {
|
|||||||
void run();
|
void run();
|
||||||
bool failed() const { return m_failed; }
|
bool failed() const { return m_failed; }
|
||||||
bool unimplemented() const { return m_unimplemented; }
|
bool unimplemented() const { return m_unimplemented; }
|
||||||
|
|
||||||
|
virtual void powerOn() final;
|
||||||
|
virtual void powerOff() final;
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -10,6 +10,19 @@ Board::Board(const Configuration& configuration)
|
|||||||
m_profiler(m_cpu, m_disassembler) {
|
m_profiler(m_cpu, m_disassembler) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Board::powerOn() {
|
||||||
|
|
||||||
|
EightBit::Bus::powerOn();
|
||||||
|
|
||||||
|
CPU().powerOn();
|
||||||
|
CPU().reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Board::powerOff() {
|
||||||
|
CPU().powerOff();
|
||||||
|
EightBit::Bus::powerOff();
|
||||||
|
}
|
||||||
|
|
||||||
void Board::initialise() {
|
void Board::initialise() {
|
||||||
|
|
||||||
auto romDirectory = m_configuration.getRomDirectory();
|
auto romDirectory = m_configuration.getRomDirectory();
|
||||||
@ -29,23 +42,18 @@ void Board::initialise() {
|
|||||||
m_cpu.ExecutingInstruction.connect(std::bind(&Board::Cpu_ExecutingInstruction_Debug, this, std::placeholders::_1));
|
m_cpu.ExecutingInstruction.connect(std::bind(&Board::Cpu_ExecutingInstruction_Debug, this, std::placeholders::_1));
|
||||||
}
|
}
|
||||||
|
|
||||||
CPU().powerOn();
|
|
||||||
CPU().reset();
|
|
||||||
|
|
||||||
poke(0, 0xc3); // JMP
|
poke(0, 0xc3); // JMP
|
||||||
poke(1, m_configuration.getStartAddress().low);
|
CPU().pokeWord(1, m_configuration.getStartAddress());
|
||||||
poke(2, m_configuration.getStartAddress().high);
|
|
||||||
|
|
||||||
poke(5, 0xc9); // ret
|
poke(5, 0xc9); // ret
|
||||||
}
|
}
|
||||||
|
|
||||||
void Board::Cpu_ExecutingInstruction_Cpm(EightBit::Z80& cpu) {
|
void Board::Cpu_ExecutingInstruction_Cpm(EightBit::Z80& cpu) {
|
||||||
if (UNLIKELY(EightBit::Chip::lowered(cpu.HALT())))
|
if (UNLIKELY(EightBit::Chip::lowered(cpu.HALT())))
|
||||||
CPU().powerOff();
|
powerOff();
|
||||||
switch (cpu.PC().word) {
|
switch (cpu.PC().word) {
|
||||||
case 0x0: // CP/M warm start
|
case 0x0: // CP/M warm start
|
||||||
if (++m_warmstartCount == 3) {
|
if (++m_warmstartCount == 3) {
|
||||||
CPU().powerOff();
|
powerOff();
|
||||||
if (m_configuration.isProfileMode()) {
|
if (m_configuration.isProfileMode()) {
|
||||||
m_profiler.dump();
|
m_profiler.dump();
|
||||||
}
|
}
|
||||||
|
@ -18,9 +18,11 @@ public:
|
|||||||
|
|
||||||
EightBit::Z80& CPU() { return m_cpu; }
|
EightBit::Z80& CPU() { return m_cpu; }
|
||||||
|
|
||||||
void initialise();
|
virtual void powerOn() final;
|
||||||
|
virtual void powerOff() final;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual void initialise() final;
|
||||||
virtual EightBit::MemoryMapping mapping(uint16_t address) final {
|
virtual EightBit::MemoryMapping mapping(uint16_t address) final {
|
||||||
return { m_ram, 0x0000, 0xffff, EightBit::MemoryMapping::ReadWrite };
|
return { m_ram, 0x0000, 0xffff, EightBit::MemoryMapping::ReadWrite };
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,7 @@ int main(int, char*[]) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
EightBit::TestHarness<Configuration, Board> harness(configuration);
|
EightBit::TestHarness<Configuration, Board> harness(configuration);
|
||||||
harness.initialise();
|
harness.run();
|
||||||
harness.runLoop();
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -48,7 +48,12 @@ namespace EightBit {
|
|||||||
write(value);
|
write(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void powerOn();
|
||||||
|
virtual void powerOff();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual void initialise() = 0;
|
||||||
|
|
||||||
virtual MemoryMapping mapping(uint16_t address) = 0;
|
virtual MemoryMapping mapping(uint16_t address) = 0;
|
||||||
uint8_t& reference(uint16_t address);
|
uint8_t& reference(uint16_t address);
|
||||||
auto& reference(const register16_t address) { return reference(address.word); }
|
auto& reference(const register16_t address) { return reference(address.word); }
|
||||||
@ -57,6 +62,8 @@ namespace EightBit {
|
|||||||
static std::map<uint16_t, std::vector<uint8_t>> parseHexFile(std::string path);
|
static std::map<uint16_t, std::vector<uint8_t>> parseHexFile(std::string path);
|
||||||
void loadHexFile(std::string path);
|
void loadHexFile(std::string path);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint8_t m_data = Chip::Mask8;
|
uint8_t m_data = Chip::Mask8;
|
||||||
register16_t m_address = Chip::Mask16;
|
register16_t m_address = Chip::Mask16;
|
||||||
|
@ -55,11 +55,13 @@ namespace EightBit {
|
|||||||
return (long long)floating;
|
return (long long)floating;
|
||||||
}
|
}
|
||||||
|
|
||||||
void runLoop() {
|
void run() {
|
||||||
m_startTime = now();
|
m_startTime = now();
|
||||||
m_totalCycles = m_instructions = 0L;
|
m_totalCycles = m_instructions = 0L;
|
||||||
m_startHostCycles = currentHostCycles();
|
m_startHostCycles = currentHostCycles();
|
||||||
|
|
||||||
|
m_board.powerOn();
|
||||||
|
|
||||||
auto& cpu = m_board.CPU();
|
auto& cpu = m_board.CPU();
|
||||||
|
|
||||||
while (LIKELY(cpu.powered())) {
|
while (LIKELY(cpu.powered())) {
|
||||||
@ -71,10 +73,6 @@ namespace EightBit {
|
|||||||
m_finishTime = now();
|
m_finishTime = now();
|
||||||
}
|
}
|
||||||
|
|
||||||
void initialise() {
|
|
||||||
m_board.initialise();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BoardT m_board;
|
BoardT m_board;
|
||||||
long long m_totalCycles = 0;
|
long long m_totalCycles = 0;
|
||||||
|
@ -8,6 +8,12 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
|
void EightBit::Bus::powerOn() {
|
||||||
|
initialise();
|
||||||
|
}
|
||||||
|
|
||||||
|
void EightBit::Bus::powerOff() {}
|
||||||
|
|
||||||
uint8_t EightBit::Bus::read() {
|
uint8_t EightBit::Bus::read() {
|
||||||
ReadingByte.fire(EventArgs::empty());
|
ReadingByte.fire(EventArgs::empty());
|
||||||
const auto returned = DATA() = reference();
|
const auto returned = DATA() = reference();
|
||||||
|
Loading…
Reference in New Issue
Block a user