From 68fe19818e7c8fd81a42f6a0db1e5d0c6c4cb597 Mon Sep 17 00:00:00 2001
From: Thomas Harte <thomas.harte@gmail.com>
Date: Fri, 23 Jul 2021 19:22:00 -0400
Subject: [PATCH] Expose more information about the E clock state.

---
 Processors/68000/68000.hpp                              | 7 +++++++
 Processors/68000/Implementation/68000Implementation.hpp | 6 ++++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/Processors/68000/68000.hpp b/Processors/68000/68000.hpp
index 61bfa2ede..5e525ecc6 100644
--- a/Processors/68000/68000.hpp
+++ b/Processors/68000/68000.hpp
@@ -451,6 +451,13 @@ template <class T, bool dtack_is_implicit, bool signal_will_perform = false> cla
 			halt_ = halt;
 		}
 
+		/// @returns The current phase of the E clock; this will be a number of
+		/// half-cycles between 0 and 19 inclusive, indicating how far the 68000
+		/// is into the current E cycle.
+		HalfCycles get_e_clock_phase() {
+			return e_clock_phase_;
+		}
+
 	private:
 		T &bus_handler_;
 };
diff --git a/Processors/68000/Implementation/68000Implementation.hpp b/Processors/68000/Implementation/68000Implementation.hpp
index 92fc359b6..87f0aba13 100644
--- a/Processors/68000/Implementation/68000Implementation.hpp
+++ b/Processors/68000/Implementation/68000Implementation.hpp
@@ -139,7 +139,9 @@ template <class T, bool dtack_is_implicit, bool signal_will_perform> void Proces
 							// Extend length by: (i) distance to next E low, plus (ii) difference between
 							// current length and a whole E cycle.
 							cycle_copy.length = HalfCycles(20);	// i.e. one E cycle in length.
-							cycle_copy.length += (e_clock_phase_ + cycles_run_for) % 10;
+							cycle_copy.length += (e_clock_phase_ + cycles_run_for) % 20;
+
+							// TODO: verify logic above; I'm not persuaded.
 
 							cycles_run_for +=
 								cycle_copy.length +
@@ -2191,7 +2193,7 @@ template <class T, bool dtack_is_implicit, bool signal_will_perform> void Proces
 #undef destination_address
 
 	bus_handler_.flush();
-	e_clock_phase_ = (e_clock_phase_ + cycles_run_for) % 10;
+	e_clock_phase_ = (e_clock_phase_ + cycles_run_for) % 20;
 	half_cycles_left_to_run_ = remaining_duration - cycles_run_for;
 }