mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-31 00:32:53 +00:00
DSP: Make Mailbox enum strongly typed
Avoids implicit conversions and also prevents dumping identifiers into the current namespace.
This commit is contained in:
parent
ee048ad83c
commit
024e983c3a
@ -228,10 +228,10 @@ enum class ExceptionType
|
||||
ExternalInterrupt = 7 // 0x000e external int (message from CPU)
|
||||
};
|
||||
|
||||
enum Mailbox : int
|
||||
enum class Mailbox
|
||||
{
|
||||
MAILBOX_CPU,
|
||||
MAILBOX_DSP
|
||||
CPU,
|
||||
DSP
|
||||
};
|
||||
|
||||
struct DSP_Regs
|
||||
@ -445,6 +445,9 @@ struct SDSP
|
||||
u16* coef = nullptr;
|
||||
|
||||
private:
|
||||
auto& GetMailbox(Mailbox mailbox) { return mbox[static_cast<u32>(mailbox)]; }
|
||||
const auto& GetMailbox(Mailbox mailbox) const { return mbox[static_cast<u32>(mailbox)]; }
|
||||
|
||||
void FreeMemoryPages();
|
||||
|
||||
void DoDMA();
|
||||
|
@ -25,21 +25,21 @@ void SDSP::InitializeIFX()
|
||||
{
|
||||
ifx_regs.fill(0);
|
||||
|
||||
mbox[MAILBOX_CPU].store(0);
|
||||
mbox[MAILBOX_DSP].store(0);
|
||||
GetMailbox(Mailbox::CPU).store(0);
|
||||
GetMailbox(Mailbox::DSP).store(0);
|
||||
}
|
||||
|
||||
u32 SDSP::PeekMailbox(Mailbox mailbox) const
|
||||
{
|
||||
return mbox[mailbox].load();
|
||||
return GetMailbox(mailbox).load();
|
||||
}
|
||||
|
||||
u16 SDSP::ReadMailboxLow(Mailbox mailbox)
|
||||
{
|
||||
const u32 value = mbox[mailbox].load(std::memory_order_acquire);
|
||||
mbox[mailbox].store(value & ~0x80000000, std::memory_order_release);
|
||||
const u32 value = GetMailbox(mailbox).load(std::memory_order_acquire);
|
||||
GetMailbox(mailbox).store(value & ~0x80000000, std::memory_order_release);
|
||||
|
||||
if (m_dsp_core.GetInitHax() && mailbox == MAILBOX_DSP)
|
||||
if (m_dsp_core.GetInitHax() && mailbox == Mailbox::DSP)
|
||||
{
|
||||
m_dsp_core.SetInitHax(false);
|
||||
m_dsp_core.Reset();
|
||||
@ -47,7 +47,7 @@ u16 SDSP::ReadMailboxLow(Mailbox mailbox)
|
||||
}
|
||||
|
||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||
const char* const type = mailbox == MAILBOX_DSP ? "DSP" : "CPU";
|
||||
const char* const type = mailbox == Mailbox::DSP ? "DSP" : "CPU";
|
||||
DEBUG_LOG_FMT(DSP_MAIL, "{}(RM) B:{} M:0x{:#010x} (pc={:#06x})", type, mailbox,
|
||||
PeekMailbox(mailbox), pc);
|
||||
#endif
|
||||
@ -57,7 +57,7 @@ u16 SDSP::ReadMailboxLow(Mailbox mailbox)
|
||||
|
||||
u16 SDSP::ReadMailboxHigh(Mailbox mailbox)
|
||||
{
|
||||
if (m_dsp_core.GetInitHax() && mailbox == MAILBOX_DSP)
|
||||
if (m_dsp_core.GetInitHax() && mailbox == Mailbox::DSP)
|
||||
{
|
||||
return 0x8054;
|
||||
}
|
||||
@ -68,13 +68,13 @@ u16 SDSP::ReadMailboxHigh(Mailbox mailbox)
|
||||
|
||||
void SDSP::WriteMailboxLow(Mailbox mailbox, u16 value)
|
||||
{
|
||||
const u32 old_value = mbox[mailbox].load(std::memory_order_acquire);
|
||||
const u32 old_value = GetMailbox(mailbox).load(std::memory_order_acquire);
|
||||
const u32 new_value = (old_value & ~0xffff) | value;
|
||||
|
||||
mbox[mailbox].store(new_value | 0x80000000, std::memory_order_release);
|
||||
GetMailbox(mailbox).store(new_value | 0x80000000, std::memory_order_release);
|
||||
|
||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||
const char* const type = mailbox == MAILBOX_DSP ? "DSP" : "CPU";
|
||||
const char* const type = mailbox == Mailbox::DSP ? "DSP" : "CPU";
|
||||
DEBUG_LOG_FMT(DSP_MAIL, "{}(WM) B:{} M:{:#010x} (pc={:#06x})", type, mailbox,
|
||||
PeekMailbox(mailbox), pc);
|
||||
#endif
|
||||
@ -82,10 +82,10 @@ void SDSP::WriteMailboxLow(Mailbox mailbox, u16 value)
|
||||
|
||||
void SDSP::WriteMailboxHigh(Mailbox mailbox, u16 value)
|
||||
{
|
||||
const u32 old_value = mbox[mailbox].load(std::memory_order_acquire);
|
||||
const u32 old_value = GetMailbox(mailbox).load(std::memory_order_acquire);
|
||||
const u32 new_value = (old_value & 0xffff) | (value << 16);
|
||||
|
||||
mbox[mailbox].store(new_value & ~0x80000000, std::memory_order_release);
|
||||
GetMailbox(mailbox).store(new_value & ~0x80000000, std::memory_order_release);
|
||||
}
|
||||
|
||||
void SDSP::WriteIFX(u32 address, u16 value)
|
||||
@ -102,19 +102,19 @@ void SDSP::WriteIFX(u32 address, u16 value)
|
||||
break;
|
||||
|
||||
case DSP_DMBH:
|
||||
WriteMailboxHigh(MAILBOX_DSP, value);
|
||||
WriteMailboxHigh(Mailbox::DSP, value);
|
||||
break;
|
||||
|
||||
case DSP_DMBL:
|
||||
WriteMailboxLow(MAILBOX_DSP, value);
|
||||
WriteMailboxLow(Mailbox::DSP, value);
|
||||
break;
|
||||
|
||||
case DSP_CMBH:
|
||||
WriteMailboxHigh(MAILBOX_CPU, value);
|
||||
WriteMailboxHigh(Mailbox::CPU, value);
|
||||
break;
|
||||
|
||||
case DSP_CMBL:
|
||||
WriteMailboxLow(MAILBOX_CPU, value);
|
||||
WriteMailboxLow(Mailbox::CPU, value);
|
||||
break;
|
||||
|
||||
case DSP_DSBL:
|
||||
@ -207,16 +207,16 @@ u16 SDSP::ReadIFXImpl(u16 address)
|
||||
switch (address & 0xff)
|
||||
{
|
||||
case DSP_DMBH:
|
||||
return ReadMailboxHigh(MAILBOX_DSP);
|
||||
return ReadMailboxHigh(Mailbox::DSP);
|
||||
|
||||
case DSP_DMBL:
|
||||
return ReadMailboxLow(MAILBOX_DSP);
|
||||
return ReadMailboxLow(Mailbox::DSP);
|
||||
|
||||
case DSP_CMBH:
|
||||
return ReadMailboxHigh(MAILBOX_CPU);
|
||||
return ReadMailboxHigh(Mailbox::CPU);
|
||||
|
||||
case DSP_CMBL:
|
||||
return ReadMailboxLow(MAILBOX_CPU);
|
||||
return ReadMailboxLow(Mailbox::CPU);
|
||||
|
||||
case DSP_DSCR:
|
||||
return ifx_regs[address & 0xFF];
|
||||
|
@ -213,25 +213,25 @@ u16 DSPLLE::DSP_ReadControlRegister()
|
||||
|
||||
u16 DSPLLE::DSP_ReadMailBoxHigh(bool cpu_mailbox)
|
||||
{
|
||||
return m_dsp_core.ReadMailboxHigh(cpu_mailbox ? MAILBOX_CPU : MAILBOX_DSP);
|
||||
return m_dsp_core.ReadMailboxHigh(cpu_mailbox ? Mailbox::CPU : Mailbox::DSP);
|
||||
}
|
||||
|
||||
u16 DSPLLE::DSP_ReadMailBoxLow(bool cpu_mailbox)
|
||||
{
|
||||
return m_dsp_core.ReadMailboxLow(cpu_mailbox ? MAILBOX_CPU : MAILBOX_DSP);
|
||||
return m_dsp_core.ReadMailboxLow(cpu_mailbox ? Mailbox::CPU : Mailbox::DSP);
|
||||
}
|
||||
|
||||
void DSPLLE::DSP_WriteMailBoxHigh(bool cpu_mailbox, u16 value)
|
||||
{
|
||||
if (cpu_mailbox)
|
||||
{
|
||||
if ((m_dsp_core.PeekMailbox(MAILBOX_CPU) & 0x80000000) != 0)
|
||||
if ((m_dsp_core.PeekMailbox(Mailbox::CPU) & 0x80000000) != 0)
|
||||
{
|
||||
// the DSP didn't read the previous value
|
||||
WARN_LOG_FMT(DSPLLE, "Mailbox isn't empty ... strange");
|
||||
}
|
||||
|
||||
m_dsp_core.WriteMailboxHigh(MAILBOX_CPU, value);
|
||||
m_dsp_core.WriteMailboxHigh(Mailbox::CPU, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -243,7 +243,7 @@ void DSPLLE::DSP_WriteMailBoxLow(bool cpu_mailbox, u16 value)
|
||||
{
|
||||
if (cpu_mailbox)
|
||||
{
|
||||
m_dsp_core.WriteMailboxLow(MAILBOX_CPU, value);
|
||||
m_dsp_core.WriteMailboxLow(Mailbox::CPU, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user