DSPCore: Convert DSP stack register enum into an enum class

Makes it more self-documenting which stack is being loaded or stored to,
as C, D, and magic numbers are extremely vague. It also enforces a
strongly-typed API instead of accepting arbitrary integral values.

It also adds the two other missing stack register names -- loop address
and loop counter.
This commit is contained in:
Lioncash committed 2017-01-28 09:17:27 -05:00
1 parent 688262fea0
commit 10d73988e7
9 files changed
+118 -99

No files matched your search

+17 -11
View File
@@ -3,38 +3,44 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "Common/CommonTypes.h"
#include "Core/DSP/DSPCore.h"
#include "Core/DSP/DSPStacks.h"
#include <cstddef>
#include "Common/CommonTypes.h"
#include "Core/DSP/DSPCore.h"
// Stacks. The stacks are outside the DSP RAM, in dedicated hardware.
namespace DSP
{
static void dsp_reg_stack_push(int stack_reg)
static void dsp_reg_stack_push(size_t stack_reg)
{
g_dsp.reg_stack_ptr[stack_reg]++;
g_dsp.reg_stack_ptr[stack_reg] &= DSP_STACK_MASK;
g_dsp.reg_stack[stack_reg][g_dsp.reg_stack_ptr[stack_reg]] = g_dsp.r.st[stack_reg];
}
static void dsp_reg_stack_pop(int stack_reg)
static void dsp_reg_stack_pop(size_t stack_reg)
{
g_dsp.r.st[stack_reg] = g_dsp.reg_stack[stack_reg][g_dsp.reg_stack_ptr[stack_reg]];
g_dsp.reg_stack_ptr[stack_reg]--;
g_dsp.reg_stack_ptr[stack_reg] &= DSP_STACK_MASK;
}
void dsp_reg_store_stack(int stack_reg, u16 val)
void dsp_reg_store_stack(StackRegister stack_reg, u16 val)
{
dsp_reg_stack_push(stack_reg);
g_dsp.r.st[stack_reg] = val;
const auto reg_index = static_cast<size_t>(stack_reg);
dsp_reg_stack_push(reg_index);
g_dsp.r.st[reg_index] = val;
}
u16 dsp_reg_load_stack(int stack_reg)
u16 dsp_reg_load_stack(StackRegister stack_reg)
{
u16 val = g_dsp.r.st[stack_reg];
dsp_reg_stack_pop(stack_reg);
const auto reg_index = static_cast<size_t>(stack_reg);
const u16 val = g_dsp.r.st[reg_index];
dsp_reg_stack_pop(reg_index);
return val;
}
} // namespace DSP