From 49412da7db0fda0b5c23cc29dd2b4e8db427d062 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Fri, 20 Mar 2026 10:32:19 -0400 Subject: [PATCH] Establish a two-stage setup. --- Components/6821/6821.hpp | 28 +++++++++++++++++++++++----- Machines/Thomson/MO5/MO5.cpp | 2 +- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Components/6821/6821.hpp b/Components/6821/6821.hpp index d3a8d8fb3..a1e3eaa91 100644 --- a/Components/6821/6821.hpp +++ b/Components/6821/6821.hpp @@ -34,7 +34,7 @@ public: ports_[port].direction = value; } - const uint8_t output = ports_[port].data | (~ports_[port].direction); + const uint8_t output = ports_[port].output(); if(output != ports_[port].previous_output) { ports_[port].previous_output = output; port_handler_.template output(output); @@ -49,9 +49,7 @@ public: return ports_[port].control; } else { if(ports_[port].control & Control::DataVisible) { - return - (ports_[port].data & ports_[port].direction) | - (port_handler_.template input() & ~ports_[port].direction); + return ports_[port].input(port_handler_.template input()); } else { return ports_[port].direction; } @@ -59,6 +57,11 @@ public: return 0; } + void refresh() const { + refresh(); + refresh(); + } + private: PortHandlerT &port_handler_; @@ -75,8 +78,23 @@ private: uint8_t data = 0; uint8_t direction = 0; // Per bit: 0 = input; 1 = output. - uint8_t previous_output = 0x00; + uint8_t output() const { + return data | ~direction; + } + uint8_t input(const uint8_t bus) const { + return (data & direction) | (bus & ~direction); + } + mutable uint8_t previous_output = 0x00; } ports_[2]; + + template + void refresh() const { + static constexpr auto index = int(port); + + const uint8_t output = ports_[index].output(); + ports_[index].previous_output = output; + port_handler_.template output(output); + } }; }; diff --git a/Machines/Thomson/MO5/MO5.cpp b/Machines/Thomson/MO5/MO5.cpp index 62a2f64c7..b0980784f 100644 --- a/Machines/Thomson/MO5/MO5.cpp +++ b/Machines/Thomson/MO5/MO5.cpp @@ -46,7 +46,7 @@ struct ConcreteMachine: const auto &rom = roms.find(ROM::Name::ThomasonMO5v11)->second; std::copy_n(rom.begin(), rom.size(), rom_.begin()); - page_lower(false); + system_pia_.refresh(); } void run_for(const Cycles cycles) final {