diff --git a/Components/AY38910/AY38910.cpp b/Components/AY38910/AY38910.cpp index 313a3391c..08a8dacac 100644 --- a/Components/AY38910/AY38910.cpp +++ b/Components/AY38910/AY38910.cpp @@ -10,8 +10,9 @@ using namespace GI; -AY38910::AY38910() : _selected_register(0) +AY38910::AY38910() : _selected_register(0), _channel_ouput{0, 0, 0} { + _output_registers[8] = _output_registers[9] = _output_registers[10] = 0; } void AY38910::set_clock_rate(double clock_rate) @@ -19,17 +20,39 @@ void AY38910::set_clock_rate(double clock_rate) set_input_rate((float)clock_rate); } +#define step(c) \ + _channel_dividers[c] -= resulting_steps; \ + if(!_channel_dividers[c]) \ + { \ + _channel_dividers[c] = (int)_tone_generator_controls[c] + 1; \ + _channel_ouput[c] ^= 1; \ + } + void AY38910::get_samples(unsigned int number_of_samples, int16_t *target) { - printf("%d\n", number_of_samples); for(int c = 0; c < number_of_samples; c++) { - *target++ = (c & 64) * 64; + // a master divider divides the clock by 16 + int former_master_divider = _master_divider; + _master_divider++; + int resulting_steps = ((_master_divider ^ former_master_divider) >> 4) & 1; + + // from that the three channels count down + step(0); + step(1); + step(2); + + *target++ = (int16_t)(( + ((_output_registers[8]&0xf) * _channel_ouput[0]) + + ((_output_registers[9]&0xf) * _channel_ouput[1]) + + ((_output_registers[10]&0xf) * _channel_ouput[2]) + ) * 512); } } void AY38910::skip_samples(unsigned int number_of_samples) { + // TODO } void AY38910::select_register(uint8_t r) diff --git a/Components/AY38910/AY38910.hpp b/Components/AY38910/AY38910.hpp index 888a3763a..ddef6e134 100644 --- a/Components/AY38910/AY38910.hpp +++ b/Components/AY38910/AY38910.hpp @@ -33,6 +33,10 @@ class AY38910: public ::Outputs::Filter { uint16_t _tone_generator_controls[3]; uint16_t _envelope_period; + + int _master_divider; + int _channel_dividers[3]; + int _channel_ouput[3]; }; }; diff --git a/Machines/Oric/Oric.cpp b/Machines/Oric/Oric.cpp index 4a5cc855c..bf172d8ac 100644 --- a/Machines/Oric/Oric.cpp +++ b/Machines/Oric/Oric.cpp @@ -61,6 +61,7 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin void Machine::synchronise() { update_video(); + _via.synchronise(); } void Machine::update_video() diff --git a/Machines/Oric/Oric.hpp b/Machines/Oric/Oric.hpp index c7315fb81..132f09d14 100644 --- a/Machines/Oric/Oric.hpp +++ b/Machines/Oric/Oric.hpp @@ -138,6 +138,8 @@ class Machine: std::shared_ptr ay8910; std::shared_ptr keyboard; + inline void synchronise() { update_ay(); } + private: void update_ay() {