feat: Implement audio backend and APU debugging features

- Introduced a new audio backend system with SDL2 support, allowing for flexible audio management and improved performance.
- Added APU handshake tracking capabilities to monitor CPU-APU communication during audio program uploads, enhancing debugging and transfer diagnostics.
- Updated the Emulator class to integrate the new audio backend, ensuring compatibility with existing audio handling.
- Implemented an APU Debugger UI for real-time monitoring of handshake status, port activity, and transfer progress, improving user experience for debugging audio issues.
- Refactored audio-related code to streamline audio sample queuing and management, enhancing overall emulator performance.
This commit is contained in:
scawful
2025-10-08 20:57:43 -04:00
parent 7f4a0f546c
commit 3125ff4b76
14 changed files with 1057 additions and 122 deletions

View File

@@ -36,6 +36,9 @@ void Snes::Init(std::vector<uint8_t>& rom_data) {
// Initialize the CPU, PPU, and APU
ppu_.Init();
apu_.Init();
// Connect handshake tracker to APU for debugging
apu_.set_handshake_tracker(&apu_handshake_tracker_);
// Load the ROM into memory and set up the memory mapping
memory_.Initialize(rom_data);
@@ -419,6 +422,11 @@ void Snes::WriteBBus(uint8_t adr, uint8_t val) {
if (adr < 0x80) {
CatchUpApu(); // catch up the apu before writing
apu_.in_ports_[adr & 0x3] = val;
// Track CPU port writes for handshake debugging
uint32_t full_pc = (static_cast<uint32_t>(cpu_.PB) << 16) | cpu_.PC;
apu_handshake_tracker_.OnCpuPortWrite(adr & 0x3, val, full_pc);
static int cpu_port_write_count = 0;
if (cpu_port_write_count++ < 10) { // Reduced to prevent crash
LOG_DEBUG("SNES", "CPU wrote APU port $21%02X (F%d) = $%02X at PC=$%02X:%04X",