Sort out why cycle counting wasn't working as I thought it should on the MC6809

Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon 2018-10-28 13:34:34 +00:00
parent fc7b6e49ca
commit edbc2784d9
2 changed files with 8 additions and 6 deletions

View File

@ -15,9 +15,9 @@ void EightBit::mc6809::powerOn() {
int EightBit::mc6809::step() {
resetCycles();
ExecutingInstruction.fire(*this);
if (LIKELY(powered())) {
m_prefix10 = m_prefix11 = false;
ExecutingInstruction.fire(*this);
if (UNLIKELY(lowered(HALT())))
handleHALT();
else if (UNLIKELY(lowered(RESET())))
@ -30,8 +30,8 @@ int EightBit::mc6809::step() {
handleIRQ();
else
execute(fetchByte());
ExecutedInstruction.fire(*this);
}
ExecutedInstruction.fire(*this);
return cycles();
}
@ -51,6 +51,7 @@ void EightBit::mc6809::handleRESET() {
setFlag(CC(), IF); // Disable IRQ
setFlag(CC(), FF); // Disable FIRQ
jump(getWordPaged(0xff, RESETvector));
addCycles(10);
}
void EightBit::mc6809::handleNMI() {

View File

@ -44,7 +44,7 @@ void Board::initialise() {
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));
CPU().ExecutedInstruction.connect(std::bind(&Board::Cpu_ExecutedInstruction_Terminator, this, std::placeholders::_1));
}
void Board::Cpu_ExecutingInstruction_Debug(EightBit::mc6809&) {
@ -95,14 +95,15 @@ void Board::updateAciaPins(const EightBit::Chip::PinLevel rw) {
}
void Board::Cpu_ExecutedInstruction_Terminator(EightBit::mc6809&) {
assert(CPU().cycles() > 0);
m_totalCycleCount += CPU().cycles();
if (m_totalCycleCount > Configuration::TerminationCycles)
CPU().powerOff();
}
void Board::Cpu_ExecutedInstruction_Acia(EightBit::mc6809&) {
const auto cycles = CPU().cycles();
m_totalCycleCount += cycles;
m_frameCycleCount -= cycles;
assert(CPU().cycles() > 0);
m_frameCycleCount -= CPU().cycles();
if (m_frameCycleCount < 0) {
if (_kbhit()) {
ACIA().RDR() = _getch();