From 7153b0e9b6347d8e90afe1c35c78a2b9f593651d Mon Sep 17 00:00:00 2001 From: Riyyi Date: Fri, 2 Sep 2022 23:15:06 +0200 Subject: [PATCH] Emulator: Optimize interrupt request checking --- src/cpu.cpp | 20 ++++++-------------- src/cpu.h | 13 ------------- 2 files changed, 6 insertions(+), 27 deletions(-) diff --git a/src/cpu.cpp b/src/cpu.cpp index 5fc2fc4..d4f3fbf 100644 --- a/src/cpu.cpp +++ b/src/cpu.cpp @@ -12,6 +12,7 @@ #include "ruc/format/color.h" #include "ruc/format/print.h" #include "ruc/meta/assert.h" +#include "ruc/meta/core.h" CPU::CPU(uint32_t frequency) : ProcessingUnit(frequency) @@ -95,20 +96,11 @@ void CPU::update() uint32_t interrupt_flag = Emu::the().readMemory(0xff0f) & 0x1f; uint32_t interrupt = interrupt_enabled & interrupt_flag; - if (interrupt & InterruptRequest::VBlank) { - handleInterrupt(interrupt_flag, InterruptRequest::VBlank, 0x40); - } - else if (interrupt & InterruptRequest::STAT) { - handleInterrupt(interrupt_flag, InterruptRequest::STAT, 0x48); - } - else if (interrupt & InterruptRequest::Timer) { - handleInterrupt(interrupt_flag, InterruptRequest::Timer, 0x50); - } - else if (interrupt & InterruptRequest::Serial) { - handleInterrupt(interrupt_flag, InterruptRequest::Serial, 0x58); - } - else if (interrupt & InterruptRequest::Joypad) { - handleInterrupt(interrupt_flag, InterruptRequest::Joypad, 0x60); + for (uint8_t i = 0; i < 5; ++i) { + if (interrupt & BIT(i)) { + handleInterrupt(interrupt_flag, BIT(i), i * 8 + 0x40); + break; + } } } diff --git a/src/cpu.h b/src/cpu.h index 146d586..4963821 100644 --- a/src/cpu.h +++ b/src/cpu.h @@ -13,19 +13,6 @@ #include "processing-unit.h" #include "ruc/format/formatter.h" -#include "ruc/meta/core.h" - -namespace InterruptRequest { - -enum Enum : uint8_t { - VBlank = BIT(0), - STAT = BIT(1), - Timer = BIT(2), - Serial = BIT(3), - Joypad = BIT(4), -}; - -} // namespace InterruptRequest class CPU final : public ProcessingUnit { private: