SPC700 to get notified when ports are written
This commit is contained in:
@@ -61,7 +61,7 @@ class APU : public Observer {
|
||||
|
||||
void Notify(uint32_t address, uint8_t data) override {
|
||||
if (address >= 0x2140 && address <= 0x2143) {
|
||||
// Handle communication with the APU
|
||||
spc700_.Notify(address, data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,12 +176,12 @@ class APU : public Observer {
|
||||
void WriteDSPMemory(uint16_t address, uint8_t value);
|
||||
|
||||
// Member variables to store internal APU state and resources
|
||||
Memory &memory_;
|
||||
AudioRam &aram_;
|
||||
Clock &clock_;
|
||||
Memory &memory_;
|
||||
|
||||
DigitalSignalProcessor dsp_;
|
||||
SPC700 spc700_{aram_};
|
||||
Dsp dsp_;
|
||||
std::vector<int16_t> audioSamples_;
|
||||
};
|
||||
|
||||
|
||||
@@ -6,9 +6,9 @@ namespace yaze {
|
||||
namespace app {
|
||||
namespace emu {
|
||||
|
||||
void Dsp::Reset() {}
|
||||
void DigitalSignalProcessor::Reset() {}
|
||||
|
||||
uint8_t Dsp::ReadVoiceReg(uint8_t voice, uint8_t reg) const {
|
||||
uint8_t DigitalSignalProcessor::ReadVoiceReg(uint8_t voice, uint8_t reg) const {
|
||||
voice %= kNumVoices;
|
||||
switch (reg % kNumVoiceRegs) {
|
||||
case 0:
|
||||
@@ -37,7 +37,7 @@ uint8_t Dsp::ReadVoiceReg(uint8_t voice, uint8_t reg) const {
|
||||
}
|
||||
}
|
||||
|
||||
void Dsp::WriteVoiceReg(uint8_t voice, uint8_t reg, uint8_t value) {
|
||||
void DigitalSignalProcessor::WriteVoiceReg(uint8_t voice, uint8_t reg, uint8_t value) {
|
||||
voice %= kNumVoices;
|
||||
switch (reg % kNumVoiceRegs) {
|
||||
case 0:
|
||||
@@ -69,11 +69,11 @@ void Dsp::WriteVoiceReg(uint8_t voice, uint8_t reg, uint8_t value) {
|
||||
}
|
||||
|
||||
// Set the callbacks
|
||||
void Dsp::SetSampleFetcher(SampleFetcher fetcher) { sample_fetcher_ = fetcher; }
|
||||
void DigitalSignalProcessor::SetSampleFetcher(SampleFetcher fetcher) { sample_fetcher_ = fetcher; }
|
||||
|
||||
void Dsp::SetSamplePusher(SamplePusher pusher) { sample_pusher_ = pusher; }
|
||||
void DigitalSignalProcessor::SetSamplePusher(SamplePusher pusher) { sample_pusher_ = pusher; }
|
||||
|
||||
int16_t Dsp::DecodeSample(uint8_t voice_num) {
|
||||
int16_t DigitalSignalProcessor::DecodeSample(uint8_t voice_num) {
|
||||
Voice const& voice = voices_[voice_num];
|
||||
uint16_t sample_address = voice.source_number;
|
||||
|
||||
@@ -82,7 +82,7 @@ int16_t Dsp::DecodeSample(uint8_t voice_num) {
|
||||
return sample;
|
||||
}
|
||||
|
||||
int16_t Dsp::ProcessSample(uint8_t voice_num, int16_t sample) {
|
||||
int16_t DigitalSignalProcessor::ProcessSample(uint8_t voice_num, int16_t sample) {
|
||||
Voice const& voice = voices_[voice_num];
|
||||
|
||||
// Adjust the pitch (for simplicity, we're just adjusting the sample value)
|
||||
@@ -96,7 +96,7 @@ int16_t Dsp::ProcessSample(uint8_t voice_num, int16_t sample) {
|
||||
return (left_sample + right_sample) / 2;
|
||||
}
|
||||
|
||||
void Dsp::MixSamples() {
|
||||
void DigitalSignalProcessor::MixSamples() {
|
||||
int16_t mixed_sample = 0;
|
||||
|
||||
for (uint8_t i = 0; i < kNumVoices; i++) {
|
||||
@@ -116,7 +116,7 @@ void Dsp::MixSamples() {
|
||||
sample_pusher_(mixed_sample);
|
||||
}
|
||||
|
||||
void Dsp::UpdateEnvelope(uint8_t voice) {
|
||||
void DigitalSignalProcessor::UpdateEnvelope(uint8_t voice) {
|
||||
uint8_t adsr1 = ReadVoiceReg(voice, 0x05);
|
||||
uint8_t adsr2 = ReadVoiceReg(voice, 0x06);
|
||||
uint8_t gain = ReadVoiceReg(voice, 0x07);
|
||||
@@ -216,7 +216,7 @@ void Dsp::UpdateEnvelope(uint8_t voice) {
|
||||
}
|
||||
}
|
||||
|
||||
void Dsp::update_voice_state(uint8_t voice_num) {
|
||||
void DigitalSignalProcessor::update_voice_state(uint8_t voice_num) {
|
||||
if (voice_num >= kNumVoices) return;
|
||||
|
||||
Voice& voice = voices_[voice_num];
|
||||
@@ -261,7 +261,7 @@ void Dsp::update_voice_state(uint8_t voice_num) {
|
||||
}
|
||||
}
|
||||
|
||||
void Dsp::process_envelope(uint8_t voice_num) {
|
||||
void DigitalSignalProcessor::process_envelope(uint8_t voice_num) {
|
||||
if (voice_num >= kNumVoices) return;
|
||||
|
||||
Voice& voice = voices_[voice_num];
|
||||
|
||||
@@ -51,7 +51,7 @@ using SamplePusher = std::function<void(int16_t)>;
|
||||
*
|
||||
*/
|
||||
|
||||
class Dsp {
|
||||
class DigitalSignalProcessor {
|
||||
private:
|
||||
static const size_t kNumVoices = 8;
|
||||
static const size_t kNumVoiceRegs = 10;
|
||||
@@ -130,12 +130,12 @@ class Dsp {
|
||||
180, 150, 110, 92, 55, 37, 18}};
|
||||
|
||||
// DSP Period Table
|
||||
const std::vector<std::vector<uint16_t>> DspPeriodTable = {
|
||||
const std::vector<std::vector<uint16_t>> DigitalSignalProcessorPeriodTable = {
|
||||
// ... Your DSP period table here ...
|
||||
};
|
||||
|
||||
// DSP Period Offset
|
||||
const std::vector<uint16_t> DspPeriodOffset = {
|
||||
const std::vector<uint16_t> DigitalSignalProcessorPeriodOffset = {
|
||||
// ... Your DSP period offsets here ...
|
||||
};
|
||||
|
||||
@@ -156,7 +156,7 @@ class Dsp {
|
||||
SamplePusher sample_pusher_;
|
||||
|
||||
public:
|
||||
Dsp() = default;
|
||||
DigitalSignalProcessor() = default;
|
||||
|
||||
void Reset();
|
||||
|
||||
|
||||
@@ -9,6 +9,24 @@ namespace emu {
|
||||
|
||||
void SPC700::Reset() {}
|
||||
|
||||
void SPC700::Notify(uint32_t address, uint8_t data) {
|
||||
// Check if the address corresponds to the APU's I/O ports
|
||||
if (address >= 0x2140 && address <= 0x2143) {
|
||||
// Handle the IPL process based on the address and data
|
||||
if (address == 0x2140) {
|
||||
// ... Handle data sent to APUIO0 ...
|
||||
// For instance, checking for the $CC signal to start the APU program
|
||||
} else if (address == 0x2141) {
|
||||
// ... Handle data sent to APUIO1 ...
|
||||
// This might involve storing data for the APU or signaling the DSP, etc.
|
||||
} else if (address == 0x2142) {
|
||||
// ... Handle data sent to APUIO2 ...
|
||||
} else if (address == 0x2143) {
|
||||
// ... Handle data sent to APUIO3 ...
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SPC700::ExecuteInstructions(uint8_t opcode) {
|
||||
switch (opcode) {
|
||||
// 8-bit Move Memory to Register
|
||||
|
||||
@@ -70,6 +70,8 @@ class SPC700 {
|
||||
|
||||
void Reset();
|
||||
|
||||
void Notify(uint32_t address, uint8_t data);
|
||||
|
||||
void ExecuteInstructions(uint8_t opcode);
|
||||
|
||||
// Read a byte from the memory-mapped registers
|
||||
|
||||
Reference in New Issue
Block a user