mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2025-02-21 13:29:04 +00:00
Apply the concept of powered components to the "board"
Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
parent
f29c571226
commit
fdbb28828f
@ -10,6 +10,17 @@ Board::Board(const Configuration& configuration)
|
||||
m_disassembler(*this) {
|
||||
}
|
||||
|
||||
void Board::powerOn() {
|
||||
EightBit::Bus::powerOn();
|
||||
CPU().powerOn();
|
||||
CPU().reset();
|
||||
}
|
||||
|
||||
void Board::powerOff() {
|
||||
CPU().powerOff();
|
||||
EightBit::Bus::powerOff();
|
||||
}
|
||||
|
||||
void Board::initialise() {
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
CPU().powerOn();
|
||||
CPU().reset();
|
||||
|
||||
poke(0, 0xc3); // JMP
|
||||
CPU().pokeWord(1, m_configuration.getStartAddress());
|
||||
|
||||
@ -42,7 +50,7 @@ void Board::Cpu_ExecutingInstruction_Cpm(EightBit::Intel8080& cpu) {
|
||||
switch (cpu.PC().word) {
|
||||
case 0x0: // CP/M warm start
|
||||
if (++m_warmstartCount == 3) {
|
||||
CPU().powerOff();
|
||||
powerOff();
|
||||
if (m_configuration.isProfileMode()) {
|
||||
m_profiler.dump();
|
||||
}
|
||||
|
@ -17,9 +17,11 @@ public:
|
||||
EightBit::Intel8080& CPU() { return m_cpu; }
|
||||
const EightBit::Intel8080& CPU() const { return m_cpu; }
|
||||
|
||||
void initialise();
|
||||
virtual void powerOn() final;
|
||||
virtual void powerOff() final;
|
||||
|
||||
protected:
|
||||
virtual void initialise() final;
|
||||
virtual EightBit::MemoryMapping mapping(uint16_t address) final {
|
||||
return { m_ram, 0x0000, 0xffff, EightBit::MemoryMapping::ReadWrite };
|
||||
}
|
||||
|
@ -8,14 +8,12 @@ int main(int, char*[]) {
|
||||
Configuration configuration;
|
||||
|
||||
#ifdef _DEBUG
|
||||
//configuration.setDebugMode(true);
|
||||
configuration.setDebugMode(true);
|
||||
configuration.setProfileMode(true);
|
||||
#endif
|
||||
//configuration.setDebugMode(true);
|
||||
|
||||
EightBit::TestHarness<Configuration, Board> harness(configuration);
|
||||
harness.initialise();
|
||||
harness.runLoop();
|
||||
harness.run();
|
||||
|
||||
return 0;
|
||||
}
|
@ -4,34 +4,39 @@
|
||||
|
||||
Fuse::TestRunner::TestRunner(const Test& test, const ExpectedTestResult& expected)
|
||||
: m_test(test),
|
||||
m_expected(expected),
|
||||
m_ram(0x10000),
|
||||
m_cpu(*this),
|
||||
m_failed(false),
|
||||
m_unimplemented(false) {
|
||||
m_expected(expected) {
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
void Fuse::TestRunner::initialise() {
|
||||
m_cpu.powerOn();
|
||||
disableGameRom();
|
||||
void Fuse::TestRunner::powerOn() {
|
||||
EightBit::Bus::powerOn();
|
||||
CPU().powerOn();
|
||||
initialiseRegisters();
|
||||
initialiseMemory();
|
||||
}
|
||||
|
||||
void Fuse::TestRunner::powerOff() {
|
||||
CPU().powerOff();
|
||||
EightBit::Bus::powerOff();
|
||||
}
|
||||
|
||||
void Fuse::TestRunner::initialise() {
|
||||
disableGameRom();
|
||||
}
|
||||
|
||||
void Fuse::TestRunner::initialiseRegisters() {
|
||||
|
||||
const auto& testState = m_test.registerState;
|
||||
const auto& inputRegisters = testState.registers;
|
||||
|
||||
m_cpu.AF() = inputRegisters[Fuse::RegisterState::AF];
|
||||
m_cpu.BC() = inputRegisters[Fuse::RegisterState::BC];
|
||||
m_cpu.DE() = inputRegisters[Fuse::RegisterState::DE];
|
||||
m_cpu.HL() = inputRegisters[Fuse::RegisterState::HL];
|
||||
CPU().AF() = inputRegisters[Fuse::RegisterState::AF];
|
||||
CPU().BC() = inputRegisters[Fuse::RegisterState::BC];
|
||||
CPU().DE() = inputRegisters[Fuse::RegisterState::DE];
|
||||
CPU().HL() = inputRegisters[Fuse::RegisterState::HL];
|
||||
|
||||
m_cpu.SP() = inputRegisters[Fuse::RegisterState::SP];
|
||||
m_cpu.PC() = inputRegisters[Fuse::RegisterState::PC];
|
||||
CPU().SP() = inputRegisters[Fuse::RegisterState::SP];
|
||||
CPU().PC() = inputRegisters[Fuse::RegisterState::PC];
|
||||
}
|
||||
|
||||
void Fuse::TestRunner::initialiseMemory() {
|
||||
@ -82,13 +87,13 @@ void Fuse::TestRunner::checkregisters() {
|
||||
const auto& expectedState = m_expected.registerState;
|
||||
const auto& expectedRegisters = expectedState.registers;
|
||||
|
||||
auto af = m_cpu.AF() == expectedRegisters[Fuse::RegisterState::AF];
|
||||
auto bc = m_cpu.BC() == expectedRegisters[Fuse::RegisterState::BC];
|
||||
auto de = m_cpu.DE() == expectedRegisters[Fuse::RegisterState::DE];
|
||||
auto hl = m_cpu.HL() == expectedRegisters[Fuse::RegisterState::HL];
|
||||
auto af = CPU().AF() == expectedRegisters[Fuse::RegisterState::AF];
|
||||
auto bc = CPU().BC() == expectedRegisters[Fuse::RegisterState::BC];
|
||||
auto de = CPU().DE() == expectedRegisters[Fuse::RegisterState::DE];
|
||||
auto hl = CPU().HL() == expectedRegisters[Fuse::RegisterState::HL];
|
||||
|
||||
auto sp = m_cpu.SP() == expectedRegisters[Fuse::RegisterState::SP];
|
||||
auto pc = m_cpu.PC() == expectedRegisters[Fuse::RegisterState::PC];
|
||||
auto sp = CPU().SP() == expectedRegisters[Fuse::RegisterState::SP];
|
||||
auto pc = CPU().PC() == expectedRegisters[Fuse::RegisterState::PC];
|
||||
|
||||
auto success =
|
||||
af && bc && de && hl
|
||||
@ -100,12 +105,12 @@ void Fuse::TestRunner::checkregisters() {
|
||||
|
||||
if (!af) {
|
||||
auto expectedA = expectedRegisters[Fuse::RegisterState::AF].high;
|
||||
auto gotA = m_cpu.A();
|
||||
auto gotA = CPU().A();
|
||||
if (expectedA != gotA)
|
||||
dumpDifference("A", gotA, expectedA);
|
||||
|
||||
auto expectedF = expectedRegisters[Fuse::RegisterState::AF].low;
|
||||
auto gotF = m_cpu.F();
|
||||
auto gotF = CPU().F();
|
||||
if (expectedF != gotF) {
|
||||
std::cerr
|
||||
<< "**** F, Expected: "
|
||||
@ -118,31 +123,31 @@ void Fuse::TestRunner::checkregisters() {
|
||||
|
||||
if (!bc) {
|
||||
auto expectedWord = expectedRegisters[Fuse::RegisterState::BC];
|
||||
auto actualWord = m_cpu.BC();
|
||||
auto actualWord = CPU().BC();
|
||||
dumpDifference("B", "C", actualWord, expectedWord);
|
||||
}
|
||||
|
||||
if (!de) {
|
||||
auto expectedWord = expectedRegisters[Fuse::RegisterState::DE];
|
||||
auto actualWord = m_cpu.DE();
|
||||
auto actualWord = CPU().DE();
|
||||
dumpDifference("D", "E", actualWord, expectedWord);
|
||||
}
|
||||
|
||||
if (!hl) {
|
||||
auto expectedWord = expectedRegisters[Fuse::RegisterState::HL];
|
||||
auto actualWord = m_cpu.HL();
|
||||
auto actualWord = CPU().HL();
|
||||
dumpDifference("H", "L", actualWord, expectedWord);
|
||||
}
|
||||
|
||||
if (!sp) {
|
||||
auto expectedWord = expectedRegisters[Fuse::RegisterState::SP];
|
||||
auto actualWord = m_cpu.SP();
|
||||
auto actualWord = CPU().SP();
|
||||
dumpDifference("SPH", "SPL", actualWord, expectedWord);
|
||||
}
|
||||
|
||||
if (!pc) {
|
||||
auto expectedWord = expectedRegisters[Fuse::RegisterState::PC];
|
||||
auto actualWord = m_cpu.PC();
|
||||
auto actualWord = CPU().PC();
|
||||
dumpDifference("PCH", "PCL", actualWord, expectedWord);
|
||||
}
|
||||
}
|
||||
@ -177,10 +182,10 @@ void Fuse::TestRunner::checkMemory() {
|
||||
|
||||
void Fuse::TestRunner::run() {
|
||||
|
||||
initialise();
|
||||
powerOn();
|
||||
auto allowedCycles = m_test.registerState.tstates;
|
||||
try {
|
||||
m_cpu.run(allowedCycles);
|
||||
CPU().run(allowedCycles);
|
||||
check();
|
||||
} catch (std::logic_error& error) {
|
||||
m_unimplemented = true;
|
||||
|
@ -16,11 +16,10 @@ namespace Fuse {
|
||||
const Test& m_test;
|
||||
const ExpectedTestResult& m_expected;
|
||||
|
||||
bool m_failed;
|
||||
bool m_unimplemented;
|
||||
bool m_failed = false;
|
||||
bool m_unimplemented = false;
|
||||
|
||||
EightBit::Ram m_ram;
|
||||
EightBit::GameBoy::LR35902 m_cpu;
|
||||
EightBit::Ram m_ram = 0x10000;
|
||||
|
||||
void initialise();
|
||||
void initialiseRegisters();
|
||||
@ -47,5 +46,8 @@ namespace Fuse {
|
||||
void run();
|
||||
bool failed() const { return m_failed; }
|
||||
bool unimplemented() const { return m_unimplemented; }
|
||||
|
||||
virtual void powerOn() final;
|
||||
virtual void powerOff() final;
|
||||
};
|
||||
}
|
@ -13,6 +13,16 @@ Board::Board(const Configuration& configuration)
|
||||
m_disassembler(*this, m_cpu, 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() {
|
||||
|
||||
auto programFilename = m_configuration.getProgram();
|
||||
@ -57,8 +67,6 @@ void Board::initialise() {
|
||||
m_pollCounter = 0;
|
||||
m_pollInterval = m_configuration.getPollInterval();
|
||||
|
||||
CPU().powerOn();
|
||||
|
||||
poke(0x00, 0x4c);
|
||||
CPU().pokeWord(1, m_configuration.getStartAddress());
|
||||
}
|
||||
@ -77,7 +85,7 @@ void Board::Cpu_ExecutedInstruction_StopLoop(EightBit::MOS6502& cpu) {
|
||||
if (m_oldPC != pc) {
|
||||
m_oldPC = pc;
|
||||
} else {
|
||||
CPU().powerOff();
|
||||
powerOff();
|
||||
auto test = peek(0x0200);
|
||||
std::cout << std::endl << "** Test=" << std::hex << (int)test;
|
||||
}
|
||||
|
@ -17,9 +17,11 @@ public:
|
||||
|
||||
EightBit::MOS6502& CPU() { return m_cpu; }
|
||||
|
||||
void initialise();
|
||||
virtual void powerOn() final;
|
||||
virtual void powerOff() final;
|
||||
|
||||
protected:
|
||||
virtual void initialise() final;
|
||||
virtual EightBit::MemoryMapping mapping(uint16_t address) final {
|
||||
return { m_ram, 0x0000, 0xffff, EightBit::MemoryMapping::ReadWrite };
|
||||
}
|
||||
|
@ -16,8 +16,7 @@ int main(int argc, char* argv[]) {
|
||||
#endif
|
||||
|
||||
EightBit::TestHarness<Configuration, Board> harness(configuration);
|
||||
harness.initialise();
|
||||
harness.runLoop();
|
||||
harness.run();
|
||||
|
||||
return 0;
|
||||
}
|
@ -7,11 +7,9 @@ Board::Board(const Configuration& configuration)
|
||||
m_disassembler(*this, m_cpu) {
|
||||
}
|
||||
|
||||
void Board::initialise() {
|
||||
void Board::powerOn() {
|
||||
|
||||
// Load our BASIC interpreter
|
||||
const auto directory = m_configuration.getRomDirectory() + "\\";
|
||||
loadHexFile(directory + "ExBasROM.hex");
|
||||
EightBit::Bus::powerOn();
|
||||
|
||||
// Get the CPU ready for action
|
||||
CPU().powerOn();
|
||||
@ -26,6 +24,19 @@ void Board::initialise() {
|
||||
ACIA().lower(ACIA().CTS());
|
||||
ACIA().powerOn();
|
||||
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...
|
||||
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);
|
||||
m_totalCycleCount += CPU().cycles();
|
||||
if (m_totalCycleCount > Configuration::TerminationCycles)
|
||||
CPU().powerOff();
|
||||
powerOff();
|
||||
}
|
||||
|
||||
void Board::Cpu_ExecutedInstruction_Acia(EightBit::mc6809&) {
|
||||
|
@ -19,9 +19,11 @@ public:
|
||||
auto& CPU() { return m_cpu; }
|
||||
auto& ACIA() { return m_acia; }
|
||||
|
||||
void initialise();
|
||||
virtual void powerOn() final;
|
||||
virtual void powerOff() final;
|
||||
|
||||
protected:
|
||||
virtual void initialise() final;
|
||||
virtual EightBit::MemoryMapping mapping(uint16_t address) final;
|
||||
|
||||
private:
|
||||
|
@ -13,11 +13,9 @@ int main(int argc, char* argv[]) {
|
||||
#ifdef _DEBUG
|
||||
configuration.setDebugMode(true);
|
||||
#endif
|
||||
//configuration.setDebugMode(true);
|
||||
|
||||
EightBit::TestHarness<Configuration, Board> harness(configuration);
|
||||
harness.initialise();
|
||||
harness.runLoop();
|
||||
harness.run();
|
||||
|
||||
return 0;
|
||||
}
|
@ -6,12 +6,20 @@ Board::Board()
|
||||
m_disassembler(*this, m_cpu) {
|
||||
}
|
||||
|
||||
void Board::initialise() {
|
||||
void Board::powerOn() {
|
||||
EightBit::Bus::powerOn();
|
||||
CPU().powerOn();
|
||||
CPU().raise(CPU().NMI());
|
||||
CPU().raise(CPU().FIRQ());
|
||||
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));
|
||||
}
|
||||
|
@ -11,9 +11,11 @@ public:
|
||||
|
||||
EightBit::mc6809& CPU() { return m_cpu; }
|
||||
|
||||
void initialise();
|
||||
virtual void powerOn() final;
|
||||
virtual void powerOff() final;
|
||||
|
||||
protected:
|
||||
virtual void initialise() final;
|
||||
virtual EightBit::MemoryMapping mapping(uint16_t address) final;
|
||||
|
||||
private:
|
||||
|
@ -9,7 +9,7 @@
|
||||
TEST_CASE("Add Accumulator B to Index Register X Unsigned", "[ABX]") {
|
||||
|
||||
Board board;
|
||||
board.initialise();
|
||||
board.powerOn();
|
||||
auto& cpu = board.CPU();
|
||||
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]") {
|
||||
|
||||
Board board;
|
||||
board.initialise();
|
||||
board.powerOn();
|
||||
auto& cpu = board.CPU();
|
||||
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]") {
|
||||
|
||||
Board board;
|
||||
board.initialise();
|
||||
board.powerOn();
|
||||
auto& cpu = board.CPU();
|
||||
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]") {
|
||||
|
||||
Board board;
|
||||
board.initialise();
|
||||
board.powerOn();
|
||||
auto& cpu = board.CPU();
|
||||
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]") {
|
||||
|
||||
Board board;
|
||||
board.initialise();
|
||||
board.powerOn();
|
||||
auto& cpu = board.CPU();
|
||||
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]") {
|
||||
|
||||
Board board;
|
||||
board.initialise();
|
||||
board.powerOn();
|
||||
auto& cpu = board.CPU();
|
||||
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]") {
|
||||
|
||||
Board board;
|
||||
board.initialise();
|
||||
board.powerOn();
|
||||
auto& cpu = board.CPU();
|
||||
cpu.step(); // Step over the reset
|
||||
|
||||
@ -427,7 +427,7 @@ TEST_CASE("Bit Test", "[BIT][BITA]") {
|
||||
TEST_CASE("Clear Accumulator or Memory", "[CLR][CLRA]") {
|
||||
|
||||
Board board;
|
||||
board.initialise();
|
||||
board.powerOn();
|
||||
auto& cpu = board.CPU();
|
||||
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]") {
|
||||
|
||||
Board board;
|
||||
board.initialise();
|
||||
board.powerOn();
|
||||
auto& cpu = board.CPU();
|
||||
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]") {
|
||||
|
||||
Board board;
|
||||
board.initialise();
|
||||
board.powerOn();
|
||||
auto& cpu = board.CPU();
|
||||
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]") {
|
||||
|
||||
Board board;
|
||||
board.initialise();
|
||||
board.powerOn();
|
||||
auto& cpu = board.CPU();
|
||||
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]") {
|
||||
|
||||
Board board;
|
||||
board.initialise();
|
||||
board.powerOn();
|
||||
auto& cpu = board.CPU();
|
||||
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]") {
|
||||
|
||||
Board board;
|
||||
board.initialise();
|
||||
board.powerOn();
|
||||
auto& cpu = board.CPU();
|
||||
cpu.step(); // Step over the reset
|
||||
|
||||
@ -826,7 +826,7 @@ TEST_CASE("Subtract Memory from Register", "[SUB][SUBA]") {
|
||||
TEST_CASE(" Branch if Greater Than Zero", "[BGT]") {
|
||||
|
||||
Board board;
|
||||
board.initialise();
|
||||
board.powerOn();
|
||||
auto& cpu = board.CPU();
|
||||
cpu.step(); // Step over the reset
|
||||
|
||||
@ -895,7 +895,7 @@ TEST_CASE(" Branch if Greater Than Zero", "[BGT]") {
|
||||
TEST_CASE(" Branch if Higher", "[BHI]") {
|
||||
|
||||
Board board;
|
||||
board.initialise();
|
||||
board.powerOn();
|
||||
auto& cpu = board.CPU();
|
||||
cpu.step(); // Step over the reset
|
||||
|
||||
@ -920,7 +920,7 @@ TEST_CASE(" Branch if Higher", "[BHI]") {
|
||||
TEST_CASE("Branch on Less than or Equal to Zero", "[BLE]") {
|
||||
|
||||
Board board;
|
||||
board.initialise();
|
||||
board.powerOn();
|
||||
auto& cpu = board.CPU();
|
||||
cpu.step(); // Step over the reset
|
||||
|
||||
|
@ -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();
|
||||
initialiseRegisters();
|
||||
}
|
||||
|
||||
void Fuse::TestRunner::powerOff() {
|
||||
m_cpu.powerOff();
|
||||
EightBit::Bus::powerOff();
|
||||
}
|
||||
|
||||
void Fuse::TestRunner::initialise() {
|
||||
initialiseMemory();
|
||||
}
|
||||
|
||||
@ -319,7 +328,7 @@ void Fuse::TestRunner::checkMemory() {
|
||||
|
||||
void Fuse::TestRunner::run() {
|
||||
|
||||
initialise();
|
||||
powerOn();
|
||||
auto allowedCycles = m_test.registerState.tstates;
|
||||
try {
|
||||
m_cpu.run(allowedCycles);
|
||||
|
@ -21,7 +21,6 @@ namespace Fuse {
|
||||
EightBit::InputOutput m_ports;
|
||||
EightBit::Z80 m_cpu;
|
||||
|
||||
void initialise();
|
||||
void initialiseRegisters();
|
||||
void initialiseMemory();
|
||||
|
||||
@ -36,6 +35,7 @@ namespace Fuse {
|
||||
EightBit::register16_t actual, EightBit::register16_t expected) const;
|
||||
|
||||
protected:
|
||||
virtual void initialise() final;
|
||||
virtual EightBit::MemoryMapping mapping(uint16_t address) final {
|
||||
return { m_ram, 0x0000, 0xffff, EightBit::MemoryMapping::ReadWrite };
|
||||
}
|
||||
@ -46,5 +46,8 @@ namespace Fuse {
|
||||
void run();
|
||||
bool failed() const { return m_failed; }
|
||||
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) {
|
||||
}
|
||||
|
||||
void Board::powerOn() {
|
||||
|
||||
EightBit::Bus::powerOn();
|
||||
|
||||
CPU().powerOn();
|
||||
CPU().reset();
|
||||
}
|
||||
|
||||
void Board::powerOff() {
|
||||
CPU().powerOff();
|
||||
EightBit::Bus::powerOff();
|
||||
}
|
||||
|
||||
void Board::initialise() {
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
CPU().powerOn();
|
||||
CPU().reset();
|
||||
|
||||
poke(0, 0xc3); // JMP
|
||||
poke(1, m_configuration.getStartAddress().low);
|
||||
poke(2, m_configuration.getStartAddress().high);
|
||||
|
||||
CPU().pokeWord(1, m_configuration.getStartAddress());
|
||||
poke(5, 0xc9); // ret
|
||||
}
|
||||
|
||||
void Board::Cpu_ExecutingInstruction_Cpm(EightBit::Z80& cpu) {
|
||||
if (UNLIKELY(EightBit::Chip::lowered(cpu.HALT())))
|
||||
CPU().powerOff();
|
||||
powerOff();
|
||||
switch (cpu.PC().word) {
|
||||
case 0x0: // CP/M warm start
|
||||
if (++m_warmstartCount == 3) {
|
||||
CPU().powerOff();
|
||||
powerOff();
|
||||
if (m_configuration.isProfileMode()) {
|
||||
m_profiler.dump();
|
||||
}
|
||||
|
@ -18,9 +18,11 @@ public:
|
||||
|
||||
EightBit::Z80& CPU() { return m_cpu; }
|
||||
|
||||
void initialise();
|
||||
virtual void powerOn() final;
|
||||
virtual void powerOff() final;
|
||||
|
||||
protected:
|
||||
virtual void initialise() final;
|
||||
virtual EightBit::MemoryMapping mapping(uint16_t address) final {
|
||||
return { m_ram, 0x0000, 0xffff, EightBit::MemoryMapping::ReadWrite };
|
||||
}
|
||||
|
@ -14,8 +14,7 @@ int main(int, char*[]) {
|
||||
#endif
|
||||
|
||||
EightBit::TestHarness<Configuration, Board> harness(configuration);
|
||||
harness.initialise();
|
||||
harness.runLoop();
|
||||
harness.run();
|
||||
|
||||
return 0;
|
||||
}
|
@ -47,7 +47,12 @@ namespace EightBit {
|
||||
write(value);
|
||||
}
|
||||
|
||||
virtual void powerOn();
|
||||
virtual void powerOff();
|
||||
|
||||
protected:
|
||||
virtual void initialise() = 0;
|
||||
|
||||
virtual MemoryMapping mapping(uint16_t address) = 0;
|
||||
uint8_t& reference(uint16_t address);
|
||||
auto& reference(const register16_t address) { return reference(address.word); }
|
||||
@ -56,6 +61,8 @@ namespace EightBit {
|
||||
static std::map<uint16_t, std::vector<uint8_t>> parseHexFile(std::string path);
|
||||
void loadHexFile(std::string path);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
uint8_t m_data = 0xff;
|
||||
register16_t m_address = 0xffff;
|
||||
|
@ -55,11 +55,13 @@ namespace EightBit {
|
||||
return (long long)floating;
|
||||
}
|
||||
|
||||
void runLoop() {
|
||||
void run() {
|
||||
m_startTime = now();
|
||||
m_totalCycles = m_instructions = 0L;
|
||||
m_startHostCycles = currentHostCycles();
|
||||
|
||||
m_board.powerOn();
|
||||
|
||||
auto& cpu = m_board.CPU();
|
||||
|
||||
while (LIKELY(cpu.powered())) {
|
||||
@ -71,10 +73,6 @@ namespace EightBit {
|
||||
m_finishTime = now();
|
||||
}
|
||||
|
||||
void initialise() {
|
||||
m_board.initialise();
|
||||
}
|
||||
|
||||
private:
|
||||
BoardT m_board;
|
||||
long long m_totalCycles = 0;
|
||||
|
@ -8,6 +8,12 @@
|
||||
#include <stdexcept>
|
||||
#include <cassert>
|
||||
|
||||
void EightBit::Bus::powerOn() {
|
||||
initialise();
|
||||
}
|
||||
|
||||
void EightBit::Bus::powerOff() {}
|
||||
|
||||
uint8_t EightBit::Bus::read() {
|
||||
ReadingByte.fire(EventArgs::empty());
|
||||
const auto returned = DATA() = reference();
|
||||
|
Loading…
x
Reference in New Issue
Block a user