1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-29 12:50:28 +00:00

Allows SN76489 consumers to apply an additional divider that reduces computation.

This commit is contained in:
Thomas Harte 2018-03-01 18:51:05 -05:00
parent 7890506b16
commit 86239469e7
3 changed files with 15 additions and 8 deletions

View File

@ -8,11 +8,12 @@
#include "SN76489.hpp" #include "SN76489.hpp"
#include <cassert>
#include <cmath> #include <cmath>
using namespace TI; using namespace TI;
SN76489::SN76489(Personality personality, Concurrency::DeferringAsyncTaskQueue &task_queue) : task_queue_(task_queue) { SN76489::SN76489(Personality personality, Concurrency::DeferringAsyncTaskQueue &task_queue, int additional_divider) : task_queue_(task_queue) {
// Build a volume table. // Build a volume table.
double multiplier = pow(10.0, -0.1); double multiplier = pow(10.0, -0.1);
double volume = 8191.0f; double volume = 8191.0f;
@ -37,6 +38,10 @@ SN76489::SN76489(Personality personality, Concurrency::DeferringAsyncTaskQueue &
shifter_is_16bit_ = true; shifter_is_16bit_ = true;
break; break;
} }
assert((master_divider_period_ % additional_divider) == 0);
assert(additional_divider < master_divider_period_);
master_divider_period_ /= additional_divider;
} }
void SN76489::set_register(uint8_t value) { void SN76489::set_register(uint8_t value) {

View File

@ -23,7 +23,7 @@ class SN76489: public Outputs::Speaker::SampleSource {
}; };
/// Creates a new SN76489. /// Creates a new SN76489.
SN76489(Personality personality, Concurrency::DeferringAsyncTaskQueue &task_queue); SN76489(Personality personality, Concurrency::DeferringAsyncTaskQueue &task_queue, int additional_divider = 1);
/// Writes a new value to the SN76489. /// Writes a new value to the SN76489.
void set_register(uint8_t value); void set_register(uint8_t value);

View File

@ -21,6 +21,10 @@
#include "../../Outputs/Speaker/Implementation/LowpassSpeaker.hpp" #include "../../Outputs/Speaker/Implementation/LowpassSpeaker.hpp"
namespace {
const int sn76489_divider = 4;
}
namespace Coleco { namespace Coleco {
namespace Vision { namespace Vision {
@ -107,10 +111,9 @@ class ConcreteMachine:
public: public:
ConcreteMachine() : ConcreteMachine() :
z80_(*this), z80_(*this),
sn76489_(TI::SN76489::Personality::SN76489, audio_queue_), sn76489_(TI::SN76489::Personality::SN76489, audio_queue_, sn76489_divider),
speaker_(sn76489_) { speaker_(sn76489_) {
// speaker_.set_input_rate(3579545.0f); speaker_.set_input_rate(3579545.0f / static_cast<float>(sn76489_divider));
speaker_.set_input_rate(3579545.0f / 2.0f);
set_clock_rate(3579545); set_clock_rate(3579545);
joysticks_.emplace_back(new Joystick); joysticks_.emplace_back(new Joystick);
joysticks_.emplace_back(new Joystick); joysticks_.emplace_back(new Joystick);
@ -176,7 +179,7 @@ class ConcreteMachine:
case CPU::Z80::PartialMachineCycle::ReadOpcode: case CPU::Z80::PartialMachineCycle::ReadOpcode:
case CPU::Z80::PartialMachineCycle::Read: case CPU::Z80::PartialMachineCycle::Read:
if(address < 0x2000) { if(address < 0x2000) {
*cycle.value = bios_[address]; *cycle.value = bios_[address & 0x1fff];
} else if(address >= 0x6000 && address < 0x8000) { } else if(address >= 0x6000 && address < 0x8000) {
*cycle.value = ram_[address & 1023]; *cycle.value = ram_[address & 1023];
} else if(address >= 0x8000) { } else if(address >= 0x8000) {
@ -264,8 +267,7 @@ class ConcreteMachine:
private: private:
void update_audio() { void update_audio() {
speaker_.run_for(audio_queue_, time_since_sn76489_update_.divide_cycles(Cycles(2))); speaker_.run_for(audio_queue_, time_since_sn76489_update_.divide_cycles(Cycles(sn76489_divider)));
// speaker_.run_for(audio_queue_, time_since_sn76489_update_.cycles());
} }
void update_video() { void update_video() {
vdp_->run_for(time_since_vdp_update_.flush()); vdp_->run_for(time_since_vdp_update_.flush());