From 8a11a5832c4a81ae4fa05c17ed8323696cff5f71 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Fri, 26 Mar 2021 23:19:47 -0400 Subject: [PATCH] Uses `GI::AY38910::Utility` far and wide. --- Components/AY38910/AY38910.hpp | 16 +++++++++------- Machines/Atari/ST/AtariST.cpp | 11 ++--------- Machines/ColecoVision/ColecoVision.cpp | 12 +++--------- Machines/MSX/MSX.cpp | 8 ++------ Machines/Sinclair/ZX8081/ZX8081.cpp | 13 +++---------- Machines/Sinclair/ZXSpectrum/ZXSpectrum.cpp | 2 +- 6 files changed, 20 insertions(+), 42 deletions(-) diff --git a/Components/AY38910/AY38910.hpp b/Components/AY38910/AY38910.hpp index 4f7c226f0..f13a00810 100644 --- a/Components/AY38910/AY38910.hpp +++ b/Components/AY38910/AY38910.hpp @@ -169,19 +169,21 @@ template class AY38910: public ::Outputs::Speaker::SampleSource 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); + template static void write(AY &ay, bool is_data_write, uint8_t data) { + ay.set_control_lines(GI::AY38910::ControlLines(GI::AY38910::BDIR | GI::AY38910::BC2 | (is_data_write ? 0 : GI::AY38910::BC1))); + ay.set_data_input(data); ay.set_control_lines(GI::AY38910::ControlLines(0)); } + template static void select_register(AY &ay, uint8_t reg) { + write(ay, false, reg); + } + 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)); + write(ay, true, reg); } - template static uint8_t read_data(AY &ay) { + template static uint8_t read(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)); diff --git a/Machines/Atari/ST/AtariST.cpp b/Machines/Atari/ST/AtariST.cpp index 6e55a6d4b..17800a525 100644 --- a/Machines/Atari/ST/AtariST.cpp +++ b/Machines/Atari/ST/AtariST.cpp @@ -347,18 +347,11 @@ class ConcreteMachine: update_audio(); if(cycle.operation & Microcycle::Read) { - ay_.set_control_lines(GI::AY38910::ControlLines(GI::AY38910::BC2 | GI::AY38910::BC1)); - cycle.set_value8_high(ay_.get_data_output()); - ay_.set_control_lines(GI::AY38910::ControlLines(0)); + cycle.set_value8_high(GI::AY38910::Utility::read(ay_)); } else { // Net effect here: addresses with bit 1 set write to a register, // addresses with bit 1 clear select a register. - ay_.set_control_lines(GI::AY38910::ControlLines( - GI::AY38910::BC2 | GI::AY38910::BDIR - | ((address&2) ? 0 : GI::AY38910::BC1) - )); - ay_.set_data_input(cycle.value8_high()); - ay_.set_control_lines(GI::AY38910::ControlLines(0)); + GI::AY38910::Utility::write(ay_, address&2, cycle.value8_high()); } return delay + HalfCycles(2); diff --git a/Machines/ColecoVision/ColecoVision.cpp b/Machines/ColecoVision/ColecoVision.cpp index c8ebd9074..7f048d1ba 100644 --- a/Machines/ColecoVision/ColecoVision.cpp +++ b/Machines/ColecoVision/ColecoVision.cpp @@ -287,9 +287,7 @@ class ConcreteMachine: case 0x52: // Read AY data. 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(ay_); break; } break; @@ -324,16 +322,12 @@ class ConcreteMachine: case 0x50: // Set AY address. update_audio(); - ay_.set_control_lines(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 0x51: // Set AY data. update_audio(); - ay_.set_control_lines(GI::AY38910::ControlLines(GI::AY38910::BC2 | GI::AY38910::BDIR)); - ay_.set_data_input(*cycle.value); - ay_.set_control_lines(GI::AY38910::ControlLines(0)); + GI::AY38910::Utility::write_data(ay_, *cycle.value); break; case 0x53: super_game_module_.replace_ram = !!((*cycle.value)&0x1); diff --git a/Machines/MSX/MSX.cpp b/Machines/MSX/MSX.cpp index 2adc8f38b..4b1ca673d 100644 --- a/Machines/MSX/MSX.cpp +++ b/Machines/MSX/MSX.cpp @@ -525,9 +525,7 @@ class ConcreteMachine: case 0xa2: 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(ay_); break; case 0xa8: case 0xa9: @@ -552,9 +550,7 @@ class ConcreteMachine: case 0xa0: case 0xa1: update_audio(); - ay_.set_control_lines(GI::AY38910::ControlLines(GI::AY38910::BDIR | GI::AY38910::BC2 | ((port == 0xa0) ? GI::AY38910::BC1 : 0))); - ay_.set_data_input(*cycle.value); - ay_.set_control_lines(GI::AY38910::ControlLines(0)); + GI::AY38910::Utility::write(ay_, port == 0xa1, *cycle.value); break; case 0xa8: case 0xa9: diff --git a/Machines/Sinclair/ZX8081/ZX8081.cpp b/Machines/Sinclair/ZX8081/ZX8081.cpp index c57e39f35..74eae2a16 100644 --- a/Machines/Sinclair/ZX8081/ZX8081.cpp +++ b/Machines/Sinclair/ZX8081/ZX8081.cpp @@ -472,22 +472,15 @@ template class ConcreteMachine: HalfCycles time_since_ay_update_; inline void ay_set_register(uint8_t value) { update_audio(); - ay_.set_control_lines(GI::AY38910::BC1); - ay_.set_data_input(value); - ay_.set_control_lines(GI::AY38910::ControlLines(0)); + GI::AY38910::Utility::select_register(ay_, value); } inline void ay_set_data(uint8_t value) { update_audio(); - ay_.set_control_lines(GI::AY38910::ControlLines(GI::AY38910::BC2 | GI::AY38910::BDIR)); - ay_.set_data_input(value); - ay_.set_control_lines(GI::AY38910::ControlLines(0)); + GI::AY38910::Utility::write_data(ay_, value); } inline uint8_t ay_read_data() { update_audio(); - ay_.set_control_lines(GI::AY38910::ControlLines(GI::AY38910::BC2 | GI::AY38910::BC1)); - const uint8_t value = ay_.get_data_output(); - ay_.set_control_lines(GI::AY38910::ControlLines(0)); - return value; + return GI::AY38910::Utility::read(ay_); } inline void update_audio() { speaker_.run_for(audio_queue_, time_since_ay_update_.divide_cycles(Cycles(2))); diff --git a/Machines/Sinclair/ZXSpectrum/ZXSpectrum.cpp b/Machines/Sinclair/ZXSpectrum/ZXSpectrum.cpp index e16fa633d..34985a6d0 100644 --- a/Machines/Sinclair/ZXSpectrum/ZXSpectrum.cpp +++ b/Machines/Sinclair/ZXSpectrum/ZXSpectrum.cpp @@ -336,7 +336,7 @@ template class ConcreteMachine: if((address & 0xc002) == 0xc000) { // Read from AY register. update_audio(); - *cycle.value &= GI::AY38910::Utility::read_data(ay_); + *cycle.value &= GI::AY38910::Utility::read(ay_); } // Check for a floating bus read; these are particularly arcane