1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-06-25 18:30:07 +00:00

Uses GI::AY38910::Utility far and wide.

This commit is contained in:
Thomas Harte 2021-03-26 23:19:47 -04:00
parent 53ba0e67d1
commit 8a11a5832c
6 changed files with 20 additions and 42 deletions

View File

@ -169,19 +169,21 @@ template <bool is_stereo> class AY38910: public ::Outputs::Speaker::SampleSource
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);
template <typename AY> 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 <typename AY> static void select_register(AY &ay, uint8_t reg) {
write(ay, false, reg);
}
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));
write(ay, true, reg);
}
template <typename AY> static uint8_t read_data(AY &ay) {
template <typename AY> 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));

View File

@ -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);

View File

@ -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);

View File

@ -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:

View File

@ -472,22 +472,15 @@ template<bool is_zx81> 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)));

View File

@ -336,7 +336,7 @@ template<Model model> 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