From ca9cc42d6b22d95268516e3c57b5cff1ed2cac78 Mon Sep 17 00:00:00 2001 From: scawful Date: Sun, 3 Dec 2023 05:37:42 -0500 Subject: [PATCH] Apu callback, CPU instruction lengths --- src/app/emu/audio/apu.cc | 7 +++++-- src/app/emu/audio/apu.h | 6 ++++++ src/app/emu/cpu.cc | 28 ++++++++++++++++++++++++++-- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/app/emu/audio/apu.cc b/src/app/emu/audio/apu.cc index 62f6d0b2..d5fef0f6 100644 --- a/src/app/emu/audio/apu.cc +++ b/src/app/emu/audio/apu.cc @@ -43,11 +43,14 @@ void APU::Update() { for (auto i = 0; i < cycles_to_run; ++i) { // Update the APU - // ... + UpdateChannelSettings(); // Update the SPC700 - // ... + uint8_t opcode = spc700_.read(spc700_.PC); + spc700_.ExecuteInstructions(opcode); } + + ProcessSamples(); } void APU::ProcessSamples() { diff --git a/src/app/emu/audio/apu.h b/src/app/emu/audio/apu.h index 3f1edf6b..8f033b6d 100644 --- a/src/app/emu/audio/apu.h +++ b/src/app/emu/audio/apu.h @@ -157,6 +157,10 @@ class APU : public Observer { } } + void SetReadyCallback(std::function callback) { + ready_callback_ = callback; + } + private: // Constants for communication static const uint8_t READY_SIGNAL_0 = 0xAA; @@ -187,6 +191,8 @@ class APU : public Observer { DigitalSignalProcessor dsp_; SPC700 spc700_{aram_}; std::vector audioSamples_; + + std::function ready_callback_; }; } // namespace emu diff --git a/src/app/emu/cpu.cc b/src/app/emu/cpu.cc index d412854b..06517162 100644 --- a/src/app/emu/cpu.cc +++ b/src/app/emu/cpu.cc @@ -368,14 +368,14 @@ void CPU::ExecuteInstruction(uint8_t opcode) { case 0xD0: // BNE Branch if not equal (zero clear) { - operand = FetchByte(); + operand = FetchSignedByte(); BNE(operand); break; } case 0x10: // BPL Branch if plus (negative clear) { - operand = FetchByte(); + operand = FetchSignedByte(); BPL(operand); break; } @@ -390,6 +390,18 @@ void CPU::ExecuteInstruction(uint8_t opcode) { case 0x00: // BRK Break { BRK(); + std::cout << "BRK" << std::endl; + // Print all the registers + std::cout << "A: " << std::hex << std::setw(2) << std::setfill('0') << (int)A << std::endl; + std::cout << "X: " << std::hex << std::setw(2) << std::setfill('0') << (int)X << std::endl; + std::cout << "Y: " << std::hex << std::setw(2) << std::setfill('0') << (int)Y << std::endl; + std::cout << "S: " << std::hex << std::setw(2) << std::setfill('0') << (int)SP() << std::endl; + std::cout << "PC: " << std::hex << std::setw(4) << std::setfill('0') << (int)PC << std::endl; + std::cout << "PB: " << std::hex << std::setw(2) << std::setfill('0') << (int)PB << std::endl; + std::cout << "D: " << std::hex << std::setw(4) << std::setfill('0') << (int)D << std::endl; + std::cout << "DB: " << std::hex << std::setw(2) << std::setfill('0') << (int)DB << std::endl; + std::cout << "E: " << std::hex << std::setw(2) << std::setfill('0') << (int)E << std::endl; + break; } @@ -1730,6 +1742,13 @@ uint8_t CPU::GetInstructionLength(uint8_t opcode) { case 0x93: // STA SR Indirect Indexed, Y case 0x95: // STA Direct Page Indexed, X case 0x96: // STX Direct Page Indexed, Y + case 0xC7: // CMP Direct Page Indirect Long + case 0xD7: // CMP DP Indirect Long Indexed, Y + case 0xD2: // CMP DP Indirect + case 0xD1: // CMP DP Indirect Indexed, Y + case 0x03: // ORA Stack Relative + case 0x13: // ORA SR Indirect Indexed, Y + case 0x07: // ORA Direct Page Indirect Long return 2; case 0x69: // ADC Immediate @@ -1772,6 +1791,11 @@ uint8_t CPU::GetInstructionLength(uint8_t opcode) { case 0x5D: // EOR Absolute Indexed, X case 0x59: // EOR Absolute Indexed, Y case 0x83: // STA Stack Relative Indirect Indexed, Y + case 0xCE: // DEC Absolute + case 0xD5: // CMP DP Indexed, X + case 0xD9: // CMP Absolute Indexed, Y + case 0xDD: // CMP Absolute Indexed, X + case 0x0C: // TSB Absolute return 3; case 0x2F: // AND Absolute Long