From 1eb127ed72c5b9e7ea46d92343948b6c545d75d0 Mon Sep 17 00:00:00 2001 From: "Adrian.Conlon" Date: Thu, 31 Aug 2017 12:13:00 +0100 Subject: [PATCH] Add power support to processor base class. Signed-off-by: Adrian.Conlon --- LR35902/fusetest_LR35902/FuseTestRunner.cpp | 1 + Z80/fusetest_Z80/FuseTestRunner.cpp | 1 + inc/Processor.h | 7 +++++++ inc/TestHarness.h | 2 ++ src/Processor.cpp | 3 ++- 5 files changed, 13 insertions(+), 1 deletion(-) diff --git a/LR35902/fusetest_LR35902/FuseTestRunner.cpp b/LR35902/fusetest_LR35902/FuseTestRunner.cpp index c887c37..11cf5f2 100644 --- a/LR35902/fusetest_LR35902/FuseTestRunner.cpp +++ b/LR35902/fusetest_LR35902/FuseTestRunner.cpp @@ -19,6 +19,7 @@ void Fuse::TestRunner::initialise() { m_bus.disableGameRom(); initialiseRegisters(); initialiseMemory(); + m_cpu.powerOn(); } void Fuse::TestRunner::initialiseRegisters() { diff --git a/Z80/fusetest_Z80/FuseTestRunner.cpp b/Z80/fusetest_Z80/FuseTestRunner.cpp index de6932a..8bb13f3 100644 --- a/Z80/fusetest_Z80/FuseTestRunner.cpp +++ b/Z80/fusetest_Z80/FuseTestRunner.cpp @@ -18,6 +18,7 @@ Fuse::TestRunner::TestRunner(const Test& test, const ExpectedTestResult& expecte void Fuse::TestRunner::initialise() { initialiseRegisters(); initialiseMemory(); + m_cpu.powerOn(); } void Fuse::TestRunner::initialiseRegisters() { diff --git a/inc/Processor.h b/inc/Processor.h index bff86f0..3d3f713 100644 --- a/inc/Processor.h +++ b/inc/Processor.h @@ -61,6 +61,10 @@ namespace EightBit { void halt() { --PC().word; m_halted = true; } void proceed() { ++PC().word; m_halted = false; } + bool powered() const { return m_power; } + void powerOn() { m_power = true; } + void powerOff() { m_power = false; } + virtual void initialise(); void reset(); @@ -102,6 +106,8 @@ namespace EightBit { } virtual int fetchExecute() { + if (!powered()) + return 0; return execute(fetchByte()); } @@ -142,5 +148,6 @@ namespace EightBit { register16_t pc; register16_t m_memptr; bool m_halted; + bool m_power; }; } \ No newline at end of file diff --git a/inc/TestHarness.h b/inc/TestHarness.h index 2d5667c..4dfead1 100644 --- a/inc/TestHarness.h +++ b/inc/TestHarness.h @@ -55,6 +55,8 @@ namespace EightBit { m_startHostCycles = currentHostCycles(); auto& cpu = m_board.CPU(); + cpu.powerOn(); + while (!cpu.isHalted()) { m_totalCycles += cpu.step(); ++m_instructions; diff --git a/src/Processor.cpp b/src/Processor.cpp index 53f10fa..655b4a7 100644 --- a/src/Processor.cpp +++ b/src/Processor.cpp @@ -4,7 +4,8 @@ EightBit::Processor::Processor(Memory& memory) : m_memory(memory), cycles(0), - m_halted(false) { + m_halted(false), + m_power(false) { PC().word = 0; }