1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-10-04 01:57:54 +00:00
CLK/Machines/Enterprise/Dave.hpp

75 lines
1.7 KiB
C++
Raw Normal View History

2021-06-22 23:33:41 +00:00
//
// Dave.hpp
// Clock Signal
//
// Created by Thomas Harte on 22/06/2021.
// Copyright © 2021 Thomas Harte. All rights reserved.
//
#ifndef Dave_hpp
#define Dave_hpp
#include <cstdint>
#include "../../Concurrency/AsyncTaskQueue.hpp"
2021-06-22 23:33:41 +00:00
#include "../../Numeric/LFSR.hpp"
#include "../../Outputs/Speaker/Implementation/SampleSource.hpp"
2021-06-22 23:33:41 +00:00
namespace Enterprise {
/*!
Models a subset of Dave's behaviour; memory mapping and interrupt status
is integrated into the main Enterprise machine.
*/
class Dave: public Outputs::Speaker::SampleSource {
2021-06-22 23:33:41 +00:00
public:
Dave(Concurrency::DeferringAsyncTaskQueue &audio_queue);
2021-06-22 23:33:41 +00:00
void write(uint16_t address, uint8_t value);
// MARK: - SampleSource.
void set_sample_volume_range(int16_t range);
static constexpr bool get_is_stereo() { return true; } // Dave produces stereo sound.
void get_samples(std::size_t number_of_samples, int16_t *target);
2021-06-22 23:33:41 +00:00
private:
Concurrency::DeferringAsyncTaskQueue &audio_queue_;
struct Channel {
// User-set values.
uint16_t reload = 0;
bool high_pass = false;
bool ring_modulate = false;
enum class Distortion {
None = 0,
FourBit = 1,
FiveBit = 2,
SevenBit = 3,
} distortion = Distortion::None;
uint8_t amplitude[2]{};
// Current state.
uint16_t count = 0;
int output = 0;
} channels_[3];
int16_t volume_ = 0;
2021-06-22 23:33:41 +00:00
// Polynomials that are always running.
2021-06-22 23:33:41 +00:00
Numeric::LFSRv<0xc> poly4_;
Numeric::LFSRv<0x14> poly5_;
Numeric::LFSRv<0x60> poly7_;
// The selectable, noise-related polynomial.
2021-06-22 23:33:41 +00:00
Numeric::LFSRv<0x110> poly9_;
Numeric::LFSRv<0x500> poly11_;
Numeric::LFSRv<0x6000> poly15_;
Numeric::LFSRv<0x12000> poly17_;
// Current state of the active polynomials.
uint8_t poly_state_[4];
2021-06-22 23:33:41 +00:00
};
}
#endif /* Dave_hpp */