feat: Refactor Emulator to Accept ROM Parameter and Enhance Logging
- Updated Emulator::Run method to accept a Rom* parameter, improving flexibility in ROM handling. - Refactored texture creation and ROM data initialization to utilize the new parameter. - Enhanced logging in Snes class to provide detailed information during initialization, reset, and frame processing, aiding in debugging and performance monitoring. - Introduced cycle tracking in Apu and Spc700 classes for accurate synchronization and debugging. - Added unit tests for APU DSP functionality and IPL ROM handshake to ensure reliability and correctness of audio processing.
This commit is contained in:
74
test/unit/emu/apu_dsp_test.cc
Normal file
74
test/unit/emu/apu_dsp_test.cc
Normal file
@@ -0,0 +1,74 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "app/emu/audio/apu.h"
|
||||
#include "app/emu/memory/memory.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace emu {
|
||||
|
||||
class ApuDspTest : public ::testing::Test {
|
||||
protected:
|
||||
MemoryImpl mem;
|
||||
Apu* apu;
|
||||
|
||||
void SetUp() override {
|
||||
std::vector<uint8_t> dummy_rom(0x200000, 0);
|
||||
mem.Initialize(dummy_rom);
|
||||
apu = new Apu(mem);
|
||||
apu->Init();
|
||||
apu->Reset();
|
||||
}
|
||||
|
||||
void TearDown() override { delete apu; }
|
||||
};
|
||||
|
||||
TEST_F(ApuDspTest, DspRegistersReadWriteMirror) {
|
||||
// Select register 0x0C (MVOLL)
|
||||
apu->Write(0xF2, 0x0C);
|
||||
apu->Write(0xF3, 0x7F);
|
||||
// Read back
|
||||
apu->Write(0xF2, 0x0C);
|
||||
uint8_t mvoll = apu->Read(0xF3);
|
||||
EXPECT_EQ(mvoll, 0x7F);
|
||||
|
||||
// Select register 0x1C (MVOLR)
|
||||
apu->Write(0xF2, 0x1C);
|
||||
apu->Write(0xF3, 0x40);
|
||||
apu->Write(0xF2, 0x1C);
|
||||
uint8_t mvolr = apu->Read(0xF3);
|
||||
EXPECT_EQ(mvolr, 0x40);
|
||||
}
|
||||
|
||||
TEST_F(ApuDspTest, TimersEnableAndReadback) {
|
||||
// Enable timers 0 and 1, clear in-ports, map IPL off for RAM access
|
||||
apu->Write(0xF1, 0x03);
|
||||
|
||||
// Set timer targets
|
||||
apu->Write(0xFA, 0x04); // timer0 target
|
||||
apu->Write(0xFB, 0x02); // timer1 target
|
||||
|
||||
// Run enough SPC cycles via APU cycle stepping
|
||||
for (int i = 0; i < 10000; ++i) {
|
||||
apu->Cycle();
|
||||
}
|
||||
|
||||
// Read counters (auto-clears)
|
||||
uint8_t t0 = apu->Read(0xFD);
|
||||
uint8_t t1 = apu->Read(0xFE);
|
||||
// Should be within 0..15 and non-zero under these cycles
|
||||
EXPECT_LE(t0, 0x0F);
|
||||
EXPECT_LE(t1, 0x0F);
|
||||
}
|
||||
|
||||
TEST_F(ApuDspTest, GetSamplesReturnsSilenceAfterReset) {
|
||||
int16_t buffer[2 * 256]{};
|
||||
apu->dsp().GetSamples(buffer, 256, /*pal=*/false);
|
||||
for (int i = 0; i < 256; ++i) {
|
||||
EXPECT_EQ(buffer[i * 2 + 0], 0);
|
||||
EXPECT_EQ(buffer[i * 2 + 1], 0);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace emu
|
||||
} // namespace yaze
|
||||
|
||||
Reference in New Issue
Block a user