1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-12-24 12:30:17 +00:00

Factors out some boilerplate.

When I'm confident this is correct, I can fix up the other call sites.
This commit is contained in:
Thomas Harte 2021-03-21 00:14:48 -04:00
parent 1b0f45649e
commit 58be770eaa
2 changed files with 28 additions and 9 deletions

View File

@ -164,6 +164,31 @@ template <bool is_stereo> 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 <typename AY> 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 <typename AY> 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 <typename AY> 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;
}
};
}
}

View File

@ -213,17 +213,13 @@ template<Model model> 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<Model model> 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;