DSPCore: Make ExceptionType an enum class

Makes the values strongly typed and avoids polluting the DSP namespace.
This commit is contained in:
Lioncash 2018-06-17 17:42:50 -04:00
parent 8459d2bc5d
commit eb76dc9600
2 changed files with 14 additions and 12 deletions

View File

@ -8,6 +8,7 @@
#include <algorithm> #include <algorithm>
#include <array> #include <array>
#include <memory> #include <memory>
#include <type_traits>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/Event.h" #include "Common/Event.h"
@ -118,7 +119,7 @@ class LLEAccelerator final : public Accelerator
protected: protected:
u8 ReadMemory(u32 address) override { return Host::ReadHostMemory(address); } u8 ReadMemory(u32 address) override { return Host::ReadHostMemory(address); }
void WriteMemory(u32 address, u8 value) override { Host::WriteHostMemory(value, address); } void WriteMemory(u32 address, u8 value) override { Host::WriteHostMemory(value, address); }
void OnEndException() override { DSPCore_SetException(EXP_ACCOV); } void OnEndException() override { DSPCore_SetException(ExceptionType::AcceleratorOverflow); }
}; };
bool DSPCore_Init(const DSPInitOptions& opts) bool DSPCore_Init(const DSPInitOptions& opts)
@ -204,7 +205,7 @@ void DSPCore_Reset()
void DSPCore_SetException(ExceptionType exception) void DSPCore_SetException(ExceptionType exception)
{ {
g_dsp.exceptions |= 1 << exception; g_dsp.exceptions |= 1 << static_cast<std::underlying_type_t<ExceptionType>>(exception);
} }
// Notify that an external interrupt is pending (used by thread mode) // Notify that an external interrupt is pending (used by thread mode)
@ -220,7 +221,7 @@ void DSPCore_CheckExternalInterrupt()
return; return;
// Signal the SPU about new mail // Signal the SPU about new mail
DSPCore_SetException(EXP_INT); DSPCore_SetException(ExceptionType::ExternalInterrupt);
g_dsp.cr &= ~CR_EXTERNAL_INT; g_dsp.cr &= ~CR_EXTERNAL_INT;
} }
@ -236,7 +237,8 @@ void DSPCore_CheckExceptions()
// Seems exp int are not masked by sr_int_enable // Seems exp int are not masked by sr_int_enable
if (g_dsp.exceptions & (1 << i)) if (g_dsp.exceptions & (1 << i))
{ {
if (Interpreter::dsp_SR_is_flag_set(SR_INT_ENABLE) || (i == EXP_INT)) if (Interpreter::dsp_SR_is_flag_set(SR_INT_ENABLE) ||
i == static_cast<int>(ExceptionType::ExternalInterrupt))
{ {
// store pc and sr until RTI // store pc and sr until RTI
dsp_reg_store_stack(StackRegister::Call, g_dsp.pc); dsp_reg_store_stack(StackRegister::Call, g_dsp.pc);

View File

@ -208,15 +208,15 @@ enum : u16
}; };
// Exception vectors // Exception vectors
enum ExceptionType : int enum class ExceptionType
{ {
EXP_STOVF = 1, // 0x0002 stack under/over flow StackOverflow = 1, // 0x0002 stack under/over flow
EXP_2 = 2, // 0x0004 EXP_2 = 2, // 0x0004
EXP_3 = 3, // 0x0006 EXP_3 = 3, // 0x0006
EXP_4 = 4, // 0x0008 EXP_4 = 4, // 0x0008
EXP_ACCOV = 5, // 0x000a accelerator address overflow AcceleratorOverflow = 5, // 0x000a accelerator address overflow
EXP_6 = 6, // 0x000c EXP_6 = 6, // 0x000c
EXP_INT = 7 // 0x000e external int (message from CPU) ExternalInterrupt = 7 // 0x000e external int (message from CPU)
}; };
struct DSP_Regs struct DSP_Regs