From 8a06219353de4a41963f436d0346283987c6efa7 Mon Sep 17 00:00:00 2001 From: scawful Date: Wed, 24 Apr 2024 15:42:07 -0400 Subject: [PATCH] update apu ram management --- src/app/emu/audio/apu.cc | 27 +++++++++++++++------------ src/app/emu/audio/apu.h | 3 +-- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/app/emu/audio/apu.cc b/src/app/emu/audio/apu.cc index 1be425aa..68508387 100644 --- a/src/app/emu/audio/apu.cc +++ b/src/app/emu/audio/apu.cc @@ -31,12 +31,26 @@ static const uint8_t bootRom[0x40] = { void Apu::Init() { // Set the clock frequency clock_.SetFrequency(kApuClockSpeed); + ram.resize(0x10000); + for (int i = 0; i < 0x10000; i++) { + ram[i] = 0; + } + // Copy the boot rom into the ram at ffc0 + for (int i = 0; i < 0x40; i++) { + ram[0xffc0 + i] = bootRom[i]; + } } void Apu::Reset() { spc700_.Reset(true); dsp_.Reset(); - ram.clear(); + for (int i = 0; i < 0x10000; i++) { + ram[i] = 0; + } + // Copy the boot rom into the ram at ffc0 + for (int i = 0; i < 0x40; i++) { + ram[0xffc0 + i] = bootRom[i]; + } rom_readable_ = true; dsp_adr_ = 0; cycles_ = 0; @@ -51,17 +65,6 @@ void Apu::Reset() { } } -void Apu::Update() { - auto cycles_to_run = clock_.GetCycleCount(); - - for (auto i = 0; i < cycles_to_run; ++i) { - // Update the SPC700 - uint8_t opcode = spc700_.read(spc700_.PC); - spc700_.ExecuteInstructions(opcode); - spc700_.PC++; - } -} - void Apu::RunCycles(uint64_t cycles) { uint64_t sync_to = (uint64_t)cycles * diff --git a/src/app/emu/audio/apu.h b/src/app/emu/audio/apu.h index d3bb7857..5520551e 100644 --- a/src/app/emu/audio/apu.h +++ b/src/app/emu/audio/apu.h @@ -60,7 +60,6 @@ class Apu { void Init(); void Reset(); - void Update(); void RunCycles(uint64_t cycles); uint8_t SpcRead(uint16_t address); @@ -80,13 +79,13 @@ class Apu { // Port buffers (equivalent to $2140 to $2143 for the main CPU) uint8_t in_ports_[6]; // includes 2 bytes of ram uint8_t out_ports_[4]; + std::vector ram = std::vector(0x10000, 0); private: Timer timer_[3]; uint32_t cycles_; uint8_t dsp_adr_; bool rom_readable_ = false; - std::vector ram = std::vector(0x10000, 0); // Member variables to store internal APU state and resources Clock &clock_;