From b8a2db96f4e717416d489727f10a47a997ab6206 Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Thu, 12 Nov 2020 16:22:44 +0000 Subject: [PATCH] Include interrupt information in the disassembler output. Signed-off-by: Adrian Conlon --- LR35902/inc/Disassembler.h | 1 + LR35902/inc/LR35902.h | 6 ++++-- LR35902/src/Disassembler.cpp | 24 ++++++++++++++++++++++++ LR35902/src/LR35902.cpp | 12 +++++++++--- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/LR35902/inc/Disassembler.h b/LR35902/inc/Disassembler.h index 94a22d4..4c950ef 100644 --- a/LR35902/inc/Disassembler.h +++ b/LR35902/inc/Disassembler.h @@ -27,6 +27,7 @@ namespace EightBit { static std::string binary(uint8_t value); static std::string decimal(uint8_t value); static std::string io(uint8_t value); + static std::string interrupt(uint8_t value); static std::string invalid(uint8_t value); diff --git a/LR35902/inc/LR35902.h b/LR35902/inc/LR35902.h index 2ef8b9d..578ed66 100644 --- a/LR35902/inc/LR35902.h +++ b/LR35902/inc/LR35902.h @@ -35,6 +35,10 @@ namespace EightBit { [[nodiscard]] register16_t& DE() final; [[nodiscard]] register16_t& HL() final; + bool& IME() noexcept { return m_ime; } + + [[nodiscard]] uint8_t enabledInterrupts(); + [[nodiscard]] uint8_t flaggedInterrupts(); [[nodiscard]] uint8_t maskedInterrupts(); protected: @@ -89,8 +93,6 @@ namespace EightBit { bool m_prefixCB = false; - bool& IME() noexcept { return m_ime; } - [[nodiscard]] auto R(const int r) { ASSUME(r >= 0); ASSUME(r <= 7); diff --git a/LR35902/src/Disassembler.cpp b/LR35902/src/Disassembler.cpp index eec4d12..c120dc6 100644 --- a/LR35902/src/Disassembler.cpp +++ b/LR35902/src/Disassembler.cpp @@ -31,6 +31,9 @@ std::string EightBit::GameBoy::Disassembler::state(LR35902& cpu) { auto h = cpu.H(); auto l = cpu.L(); + const auto maskedInterrupts = cpu.maskedInterrupts(); + const auto ime = cpu.IME(); + std::ostringstream output; output @@ -42,6 +45,12 @@ std::string EightBit::GameBoy::Disassembler::state(LR35902& cpu) { << " " << "D=" << hex(d) << " " << "E=" << hex(e) << " " << "H=" << hex(h) << " " << "L=" << hex(l); + // Interrupt handling + output << " IME:" << (ime ? "I" : "-"); + output << " IE:" << interrupt(cpu.enabledInterrupts()); + output << " IF:" << interrupt(cpu.flaggedInterrupts()); + output << " (" << interrupt(cpu.maskedInterrupts()) << ")"; + return output.str(); } @@ -683,3 +692,18 @@ std::string EightBit::GameBoy::Disassembler::io(uint8_t value) { return hex(value); } } + +std::string EightBit::GameBoy::Disassembler::interrupt(uint8_t value) { + std::ostringstream output; + const auto ik = value & IoRegisters::KeypadPressed; + output << (ik ? "K" : "-"); + const auto is = value & IoRegisters::SerialTransfer; + output << (is ? "S" : "-"); + const auto it = value & IoRegisters::TimerOverflow; + output << (it ? "T" : "-"); + const auto id = value & IoRegisters::DisplayControlStatus; + output << (id ? "D" : "-"); + const auto iv = value & IoRegisters::VerticalBlank; + output << (iv ? "V" : "-"); + return output.str(); +} \ No newline at end of file diff --git a/LR35902/src/LR35902.cpp b/LR35902/src/LR35902.cpp index 51a3d9f..779febc 100644 --- a/LR35902/src/LR35902.cpp +++ b/LR35902/src/LR35902.cpp @@ -295,10 +295,16 @@ void EightBit::GameBoy::LR35902::ccf(uint8_t& f, const uint8_t operand) { f = clearBit(f, CF, f & CF); } +uint8_t EightBit::GameBoy::LR35902::enabledInterrupts() { + return BUS().peek(IoRegisters::BASE + IoRegisters::IE); +} + +uint8_t EightBit::GameBoy::LR35902::flaggedInterrupts() { + return m_bus.IO().peek(IoRegisters::IF); +} + uint8_t EightBit::GameBoy::LR35902::maskedInterrupts() { - const auto interruptEnable = BUS().peek(IoRegisters::BASE + IoRegisters::IE); - const auto interruptFlags = m_bus.IO().peek(IoRegisters::IF); - return interruptEnable & interruptFlags; + return enabledInterrupts() & flaggedInterrupts(); } int EightBit::GameBoy::LR35902::step() {