diff --git a/Components/AY38910/AY38910.hpp b/Components/AY38910/AY38910.hpp index 34a8302fd..4f7c226f0 100644 --- a/Components/AY38910/AY38910.hpp +++ b/Components/AY38910/AY38910.hpp @@ -164,6 +164,31 @@ template class AY38910: public ::Outputs::Speaker::SampleSource uint8_t c_left_ = 255, c_right_ = 255; }; +/*! + Provides helper code, to provide something closer to the interface exposed by many + AY-deploying machines of the era. +*/ +struct Utility { + template static void select_register(AY &ay, uint8_t reg) { + ay.set_control_lines(GI::AY38910::ControlLines(GI::AY38910::BDIR | GI::AY38910::BC2 | GI::AY38910::BC1)); + ay.set_data_input(reg); + ay.set_control_lines(GI::AY38910::ControlLines(0)); + } + + template static void write_data(AY &ay, uint8_t reg) { + ay.set_control_lines(GI::AY38910::ControlLines(GI::AY38910::BDIR | GI::AY38910::BC2)); + ay.set_data_input(reg); + ay.set_control_lines(GI::AY38910::ControlLines(0)); + } + + template static uint8_t read_data(AY &ay) { + ay.set_control_lines(GI::AY38910::ControlLines(GI::AY38910::BC2 | GI::AY38910::BC1)); + const uint8_t result = ay.get_data_output(); + ay.set_control_lines(GI::AY38910::ControlLines(0)); + return result; + } + +}; } } diff --git a/Machines/Sinclair/ZXSpectrum/ZXSpectrum.cpp b/Machines/Sinclair/ZXSpectrum/ZXSpectrum.cpp index ba63515f0..eecf0a86a 100644 --- a/Machines/Sinclair/ZXSpectrum/ZXSpectrum.cpp +++ b/Machines/Sinclair/ZXSpectrum/ZXSpectrum.cpp @@ -213,17 +213,13 @@ template class ConcreteMachine: case 0xfffd: // Select AY register. update_audio(); - ay_.set_control_lines(GI::AY38910::ControlLines(GI::AY38910::BDIR | GI::AY38910::BC2 | GI::AY38910::BC1)); - ay_.set_data_input(*cycle.value); - ay_.set_control_lines(GI::AY38910::ControlLines(0)); + GI::AY38910::Utility::select_register(ay_, *cycle.value); break; case 0xbffd: // Write to AY register. update_audio(); - ay_.set_control_lines(GI::AY38910::ControlLines(GI::AY38910::BDIR | GI::AY38910::BC2)); - ay_.set_data_input(*cycle.value); - ay_.set_control_lines(GI::AY38910::ControlLines(0)); + GI::AY38910::Utility::write_data(ay_, *cycle.value); break; } break; @@ -265,9 +261,7 @@ template class ConcreteMachine: case 0xfffd: // Read from AY register. update_audio(); - ay_.set_control_lines(GI::AY38910::ControlLines(GI::AY38910::BC2 | GI::AY38910::BC1)); - *cycle.value &= ay_.get_data_output(); - ay_.set_control_lines(GI::AY38910::ControlLines(0)); + *cycle.value &= GI::AY38910::Utility::read_data(ay_); break; } break;