Move board termination and cycle count etc. into the configuration class.

Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon 2018-10-21 10:28:33 +01:00
parent 4d09da1541
commit 54e0dcfe36
3 changed files with 23 additions and 14 deletions

View File

@ -42,6 +42,9 @@ 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));
}
if (m_configuration.terminatesEarly())
CPU().ExecutingInstruction.connect(std::bind(&Board::Cpu_ExecutedInstruction_Terminator, this, std::placeholders::_1));
}
void Board::Cpu_ExecutingInstruction_Debug(EightBit::mc6809&) {
@ -91,20 +94,21 @@ void Board::updateAciaPins(const EightBit::Chip::PinLevel rw) {
ADDRESS().word & EightBit::Chip::Bit14 ? ACIA().raise(ACIA().CS2()) : ACIA().lower(ACIA().CS2());
}
void Board::Cpu_ExecutedInstruction_Terminator(EightBit::mc6809&) {
if (m_totalCycleCount > Configuration::TerminationCycles)
CPU().powerOff();
}
void Board::Cpu_ExecutedInstruction_Acia(EightBit::mc6809&) {
const auto cycles = CPU().cycles();
m_totalCycleCount += cycles;
if (m_totalCycleCount < TerminationCycles) {
m_frameCycleCount -= cycles;
if (m_frameCycleCount < 0) {
if (_kbhit()) {
ACIA().RDR() = _getch();
ACIA().markReceiveStarting();
}
m_frameCycleCount = FrameCycleInterval;
m_frameCycleCount -= cycles;
if (m_frameCycleCount < 0) {
if (_kbhit()) {
ACIA().RDR() = _getch();
ACIA().markReceiveStarting();
}
} else {
CPU().powerOff();
m_frameCycleCount = Configuration::FrameCycleInterval;
}
}

View File

@ -36,9 +36,6 @@ private:
uint64_t m_totalCycleCount = 0UL;
int64_t m_frameCycleCount = 0UL;
static constexpr uint64_t CyclesPerSecond = 2 * 1024 * 1024;
static constexpr uint64_t FrameCycleInterval = CyclesPerSecond / 60;
static constexpr uint64_t TerminationCycles = CyclesPerSecond * 10 * 10;
// The m_disassembleAt and m_ignoreDisassembly are used to skip pin events
EightBit::register16_t m_disassembleAt = 0x0000;
@ -49,7 +46,7 @@ private:
void Cpu_ExecutingInstruction_Debug(EightBit::mc6809&);
void Cpu_ExecutedInstruction_Debug(EightBit::mc6809&);
// Allows us to step the ACIA
void Cpu_ExecutedInstruction_Terminator(EightBit::mc6809&);
void Cpu_ExecutedInstruction_Acia(EightBit::mc6809&);
// Bus events

View File

@ -6,14 +6,22 @@
class Configuration {
public:
static constexpr uint64_t CyclesPerSecond = 2 * 1024 * 1024;
static constexpr uint64_t FrameCycleInterval = CyclesPerSecond / 60;
static constexpr uint64_t TerminationCycles = CyclesPerSecond * 10 * 10;
Configuration() = default;
bool isDebugMode() const { return m_debugMode; }
void setDebugMode(bool value) { m_debugMode = value; }
bool terminatesEarly() const { return m_terminatesEarly; }
void setTerminatesEarly(bool value) { m_terminatesEarly = value; }
std::string getRomDirectory() const { return m_romDirectory; }
private:
bool m_debugMode = false;
bool m_terminatesEarly = true;
std::string m_romDirectory = "roms\\searle";
};