From 9c04d851e4877e72bdb5b0e42f163bb49da0886d Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Mon, 31 Jul 2017 07:29:50 -0400 Subject: [PATCH] Added the basics necessary to get the CPU ticking over, at a nominal 4Mhz but with the wait states that I currently believe to be accurate. --- ClockReceiver/ClockReceiver.hpp | 8 ++++++++ Machines/AmstradCPC/AmstradCPC.cpp | 10 ++++++++++ Machines/AmstradCPC/AmstradCPC.hpp | 3 +++ 3 files changed, 21 insertions(+) diff --git a/ClockReceiver/ClockReceiver.hpp b/ClockReceiver/ClockReceiver.hpp index 515d3216b..893ce2875 100644 --- a/ClockReceiver/ClockReceiver.hpp +++ b/ClockReceiver/ClockReceiver.hpp @@ -95,9 +95,17 @@ template class WrappedInt { return *static_cast(this); } + inline T &operator &=(const T &rhs) { + length_ &= rhs.length_; + return *static_cast(this); + } + inline T operator +(const T &rhs) const { return T(length_ + rhs.length_); } inline T operator -(const T &rhs) const { return T(length_ - rhs.length_); } + inline T operator %(const T &rhs) const { return T(length_ % rhs.length_); } + inline T operator &(const T &rhs) const { return T(length_ & rhs.length_); } + inline T operator -() const { return T(- length_); } inline bool operator <(const T &rhs) const { return length_ < rhs.length_; } diff --git a/Machines/AmstradCPC/AmstradCPC.cpp b/Machines/AmstradCPC/AmstradCPC.cpp index 01cf8bec6..424328fef 100644 --- a/Machines/AmstradCPC/AmstradCPC.cpp +++ b/Machines/AmstradCPC/AmstradCPC.cpp @@ -10,7 +10,16 @@ using namespace AmstradCPC; +Machine::Machine() { + // primary clock is 4Mhz + set_clock_rate(4000000); +} + HalfCycles Machine::perform_machine_cycle(const CPU::Z80::PartialMachineCycle &cycle) { + // Amstrad CPC timing scheme: assert WAIT for three out of four cycles + clock_offset_ = (clock_offset_ + cycle.length) & HalfCycles(7); + set_wait_line(clock_offset_ >= HalfCycles(2)); + return HalfCycles(0); } @@ -38,6 +47,7 @@ std::shared_ptr Machine::get_speaker() { } void Machine::run_for(const Cycles cycles) { + CPU::Z80::Processor::run_for(cycles); } void Machine::configure_as_target(const StaticAnalyser::Target &target) { diff --git a/Machines/AmstradCPC/AmstradCPC.hpp b/Machines/AmstradCPC/AmstradCPC.hpp index 905f16cea..293ca06f7 100644 --- a/Machines/AmstradCPC/AmstradCPC.hpp +++ b/Machines/AmstradCPC/AmstradCPC.hpp @@ -22,6 +22,8 @@ class Machine: public CRTMachine::Machine, public ConfigurationTarget::Machine { public: + Machine(); + HalfCycles perform_machine_cycle(const CPU::Z80::PartialMachineCycle &cycle); void flush(); @@ -37,6 +39,7 @@ class Machine: private: std::shared_ptr crt_; + HalfCycles clock_offset_; }; }