diff --git a/src/app/emu/audio/apu.cc b/src/app/emu/audio/apu.cc index deb17f9f..71a9ce60 100644 --- a/src/app/emu/audio/apu.cc +++ b/src/app/emu/audio/apu.cc @@ -27,7 +27,7 @@ void APU::Init() { [this](int16_t sample) { this->PushToAudioBuffer(sample); }); // Initialize registers - // ... + SignalReady(); } void APU::Reset() { diff --git a/src/app/emu/audio/apu.h b/src/app/emu/audio/apu.h index d1b91d0d..4e74a7f3 100644 --- a/src/app/emu/audio/apu.h +++ b/src/app/emu/audio/apu.h @@ -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_}; diff --git a/src/app/emu/cpu.cc b/src/app/emu/cpu.cc index 0c86765e..a642339b 100644 --- a/src/app/emu/cpu.cc +++ b/src/app/emu/cpu.cc @@ -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); } diff --git a/src/app/emu/cpu.h b/src/app/emu/cpu.h index 68e624d8..61dc872d 100644 --- a/src/app/emu/cpu.h +++ b/src/app/emu/cpu.h @@ -7,7 +7,7 @@ #include #include "app/emu/clock.h" -#include "app/emu/log.h" +#include "app/emu/debug/log.h" #include "app/emu/mem.h" namespace yaze { diff --git a/src/app/emu/log.h b/src/app/emu/debug/log.h similarity index 100% rename from src/app/emu/log.h rename to src/app/emu/debug/log.h diff --git a/src/app/emu/mem.h b/src/app/emu/mem.h index b1933c81..872ba5f1 100644 --- a/src/app/emu/mem.h +++ b/src/app/emu/mem.h @@ -5,7 +5,7 @@ #include #include -#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 romData) { + void Initialize(const std::vector& 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 diff --git a/src/app/emu/snes.cc b/src/app/emu/snes.cc index e4019de0..aa40cf70 100644 --- a/src/app/emu/snes.cc +++ b/src/app/emu/snes.cc @@ -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 diff --git a/src/app/emu/snes.h b/src/app/emu/snes.h index ca917830..d6e09e00 100644 --- a/src/app/emu/snes.h +++ b/src/app/emu/snes.h @@ -128,7 +128,7 @@ class SNES : public DMA { std::atomic frame_counter_; // Other private member variables - bool running_; + bool running_ = false; int scanline; };