From 1804ea6849180ff45d522cf59a61d80e5d10d279 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Wed, 7 Mar 2018 17:00:18 -0500 Subject: [PATCH] Ensures the ColecoVision and MSX account for instruction lengths in advance when timing secondary components. --- Machines/ColecoVision/ColecoVision.cpp | 6 +++--- Machines/MSX/MSX.cpp | 22 +++++++++++----------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Machines/ColecoVision/ColecoVision.cpp b/Machines/ColecoVision/ColecoVision.cpp index 4814aba6e..b92656ba7 100644 --- a/Machines/ColecoVision/ColecoVision.cpp +++ b/Machines/ColecoVision/ColecoVision.cpp @@ -192,6 +192,9 @@ class ConcreteMachine: // MARK: Z80::BusHandler forceinline HalfCycles perform_machine_cycle(const CPU::Z80::PartialMachineCycle &cycle) { + time_since_vdp_update_ += cycle.length; + time_since_sn76489_update_ += cycle.length; + uint16_t address = cycle.address ? *cycle.address : 0x0000; switch(cycle.operation) { case CPU::Z80::PartialMachineCycle::ReadOpcode: @@ -313,9 +316,6 @@ class ConcreteMachine: default: break; } - time_since_vdp_update_ += cycle.length; - time_since_sn76489_update_ += cycle.length; - if(time_until_interrupt_ > 0) { time_until_interrupt_ -= cycle.length; if(time_until_interrupt_ <= HalfCycles(0)) { diff --git a/Machines/MSX/MSX.cpp b/Machines/MSX/MSX.cpp index 5b50349e2..8e589a102 100644 --- a/Machines/MSX/MSX.cpp +++ b/Machines/MSX/MSX.cpp @@ -282,6 +282,17 @@ class ConcreteMachine: // MARK: Z80::BusHandler forceinline HalfCycles perform_machine_cycle(const CPU::Z80::PartialMachineCycle &cycle) { + // Per the best information I currently have, the MSX inserts an extra cycle into each opcode read, + // but otherwise runs without pause. + const HalfCycles addition((cycle.operation == CPU::Z80::PartialMachineCycle::ReadOpcode) ? 2 : 0); + const HalfCycles total_length = addition + cycle.length; + time_since_vdp_update_ += total_length; + time_since_ay_update_ += total_length; + memory_slots_[0].cycles_since_update += total_length; + memory_slots_[1].cycles_since_update += total_length; + memory_slots_[2].cycles_since_update += total_length; + memory_slots_[3].cycles_since_update += total_length; + uint16_t address = cycle.address ? *cycle.address : 0x0000; switch(cycle.operation) { case CPU::Z80::PartialMachineCycle::ReadOpcode: @@ -459,23 +470,12 @@ class ConcreteMachine: if(!tape_player_is_sleeping_) tape_player_.run_for(cycle.length.as_int()); - // Per the best information I currently have, the MSX inserts an extra cycle into each opcode read, - // but otherwise runs without pause. - const HalfCycles addition((cycle.operation == CPU::Z80::PartialMachineCycle::ReadOpcode) ? 2 : 0); - const HalfCycles total_length = addition + cycle.length; - if(time_until_interrupt_ > 0) { time_until_interrupt_ -= total_length; if(time_until_interrupt_ <= HalfCycles(0)) { z80_.set_interrupt_line(true, time_until_interrupt_); } } - time_since_vdp_update_ += total_length; - time_since_ay_update_ += total_length; - memory_slots_[0].cycles_since_update += total_length; - memory_slots_[1].cycles_since_update += total_length; - memory_slots_[2].cycles_since_update += total_length; - memory_slots_[3].cycles_since_update += total_length; return addition; }