Add SignalReady to APU init

This commit is contained in:
scawful
2023-08-26 04:51:50 -04:00
parent b9d06f43bc
commit 559c2e4830
8 changed files with 16 additions and 12 deletions

View File

@@ -27,7 +27,7 @@ void APU::Init() {
[this](int16_t sample) { this->PushToAudioBuffer(sample); });
// Initialize registers
// ...
SignalReady();
}
void APU::Reset() {

View File

@@ -40,8 +40,8 @@ const int apuClocksPerSample = 64; // 64 clocks per sample
class APU : public Observer {
public:
// Initializes the APU with the necessary resources and dependencies
APU(Memory &memory, AudioRam &aram, Clock &clock)
: memory_(memory), aram_(aram), clock_(clock) {}
APU(MemoryImpl &memory, AudioRam &aram, Clock &clock)
: aram_(aram), clock_(clock), memory_(memory) {}
void Init();
@@ -68,7 +68,9 @@ class APU : public Observer {
void UpdateClock(int delta_time) { clock_.UpdateClock(delta_time); }
// Method to fetch a sample from AudioRam
uint8_t FetchSampleFromRam(uint16_t address) { return aram_.read(address); }
uint8_t FetchSampleFromRam(uint16_t address) const {
return aram_.read(address);
}
// Method to push a processed sample to the audio buffer
void PushToAudioBuffer(int16_t sample) { audioSamples_.push_back(sample); }
@@ -94,13 +96,15 @@ class APU : public Observer {
// Set Port 0 = $AA and Port 1 = $BB
ports_[0] = READY_SIGNAL_0;
ports_[1] = READY_SIGNAL_1;
memory_.WriteByte(0x2140, READY_SIGNAL_0);
memory_.WriteByte(0x2141, READY_SIGNAL_1);
}
bool IsReadySignalReceived() const {
return ports_[0] == READY_SIGNAL_0 && ports_[1] == READY_SIGNAL_1;
}
void WaitForSignal() {
void WaitForSignal() const {
// This might be an active wait or a passive state where APU does nothing
// until it's externally triggered by the main CPU writing to its ports.
while (ports_[0] != BEGIN_SIGNAL)
@@ -178,7 +182,7 @@ class APU : public Observer {
// Member variables to store internal APU state and resources
AudioRam &aram_;
Clock &clock_;
Memory &memory_;
MemoryImpl &memory_;
DigitalSignalProcessor dsp_;
SPC700 spc700_{aram_};

View File

@@ -1530,7 +1530,7 @@ void CPU::LDA(uint16_t address, bool isImmediate) {
SetZeroFlag(A == 0);
SetNegativeFlag(A & 0x80);
} else {
A = isImmediate ? memory.ReadWord(PC) : memory.ReadWord(address);
A = isImmediate ? address : memory.ReadWord(address);
SetZeroFlag(A == 0);
SetNegativeFlag(A & 0x8000);
}

View File

@@ -7,7 +7,7 @@
#include <vector>
#include "app/emu/clock.h"
#include "app/emu/log.h"
#include "app/emu/debug/log.h"
#include "app/emu/mem.h"
namespace yaze {

View File

@@ -5,7 +5,7 @@
#include <iostream>
#include <vector>
#include "app/emu/log.h"
#include "app/emu/debug/log.h"
// LoROM (Mode 20):
@@ -146,7 +146,7 @@ class Memory {
class MemoryImpl : public Memory, public Loggable {
public:
void Initialize(const std::vector<uint8_t> romData) {
void Initialize(const std::vector<uint8_t>& romData) {
const size_t ROM_CHUNK_SIZE = 0x8000; // 32 KB
const size_t SRAM_SIZE = 0x10000; // 64 KB
const size_t SYSTEM_RAM_SIZE = 0x20000; // 128 KB

View File

@@ -197,7 +197,7 @@ void SNES::Init(ROM& rom) {
apu.Init();
// Initialize SDL_Mixer to play the audio samples
Mix_HookMusic(audio_callback, &apu);
// Mix_HookMusic(audio_callback, &apu);
// Disable interrupts and rendering
memory_.WriteByte(0x4200, 0x00); // NMITIMEN

View File

@@ -128,7 +128,7 @@ class SNES : public DMA {
std::atomic<uint32_t> frame_counter_;
// Other private member variables
bool running_;
bool running_ = false;
int scanline;
};