Skip to content

Commit

Permalink
Merge pull request #3115 from lioncash/ifx
Browse files Browse the repository at this point in the history
DSPCore: Minor changes
  • Loading branch information
shuffle2 committed Oct 4, 2015
2 parents 06379cc + 75907d8 commit 4fb90bf
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 35 deletions.
48 changes: 19 additions & 29 deletions Source/Core/Core/DSP/DSPCore.cpp
Expand Up @@ -3,6 +3,10 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.

#include <algorithm>
#include <array>

#include "Common/CommonFuncs.h"
#include "Common/CommonTypes.h"
#include "Common/Event.h"
#include "Common/FileUtil.h"
Expand Down Expand Up @@ -33,7 +37,9 @@ static bool VerifyRoms()
{
u32 hash_irom; // dsp_rom.bin
u32 hash_drom; // dsp_coef.bin
} KNOWN_ROMS[] = {
};

static const std::array<DspRomHashes, 4> known_roms = {{
// Official Nintendo ROM
{ 0x66f334fe, 0xf3b93527 },

Expand All @@ -46,17 +52,17 @@ static bool VerifyRoms()

// above with improved resampling coefficients
{ 0xd9907f71, 0xdb6880c1 }
};
}};

u32 hash_irom = HashAdler32((u8*)g_dsp.irom, DSP_IROM_BYTE_SIZE);
u32 hash_drom = HashAdler32((u8*)g_dsp.coef, DSP_COEF_BYTE_SIZE);
int rom_idx = -1;

for (u32 i = 0; i < sizeof (KNOWN_ROMS) / sizeof (KNOWN_ROMS[0]); ++i)
for (size_t i = 0; i < known_roms.size(); ++i)
{
DspRomHashes& rom = KNOWN_ROMS[i];
const DspRomHashes& rom = known_roms[i];
if (hash_irom == rom.hash_irom && hash_drom == rom.hash_drom)
rom_idx = i;
rom_idx = static_cast<int>(i);
}

if (rom_idx < 0)
Expand Down Expand Up @@ -115,33 +121,20 @@ bool DSPCore_Init(const DSPInitOptions& opts)

memset(&g_dsp.r,0,sizeof(g_dsp.r));

for (int i = 0; i < 4; i++)
{
g_dsp.reg_stack_ptr[i] = 0;
for (int j = 0; j < DSP_STACK_DEPTH; j++)
{
g_dsp.reg_stack[i][j] = 0;
}
}
std::fill(std::begin(g_dsp.reg_stack_ptr), std::end(g_dsp.reg_stack_ptr), 0);

for (size_t i = 0; i < ArraySize(g_dsp.reg_stack); i++)
std::fill(std::begin(g_dsp.reg_stack[i]), std::end(g_dsp.reg_stack[i]), 0);

// Fill IRAM with HALT opcodes.
for (int i = 0; i < DSP_IRAM_SIZE; i++)
{
g_dsp.iram[i] = 0x0021; // HALT opcode
}
std::fill(g_dsp.iram, g_dsp.iram + DSP_IRAM_SIZE, 0x0021);

// Just zero out DRAM.
for (int i = 0; i < DSP_DRAM_SIZE; i++)
{
g_dsp.dram[i] = 0;
}
std::fill(g_dsp.dram, g_dsp.dram + DSP_DRAM_SIZE, 0);

// Copied from a real console after the custom UCode has been loaded.
// These are the indexing wrapping registers.
g_dsp.r.wr[0] = 0xffff;
g_dsp.r.wr[1] = 0xffff;
g_dsp.r.wr[2] = 0xffff;
g_dsp.r.wr[3] = 0xffff;
std::fill(std::begin(g_dsp.r.wr), std::end(g_dsp.r.wr), 0xffff);

g_dsp.r.sr |= SR_INT_ENABLE;
g_dsp.r.sr |= SR_EXT_INT_ENABLE;
Expand Down Expand Up @@ -184,10 +177,7 @@ void DSPCore_Reset()
{
g_dsp.pc = DSP_RESET_VECTOR;

g_dsp.r.wr[0] = 0xffff;
g_dsp.r.wr[1] = 0xffff;
g_dsp.r.wr[2] = 0xffff;
g_dsp.r.wr[3] = 0xffff;
std::fill(std::begin(g_dsp.r.wr), std::end(g_dsp.r.wr), 0xffff);

DSPAnalyzer::Analyze();
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/DSP/DSPCore.h
Expand Up @@ -242,7 +242,7 @@ struct SDSP
std::atomic<u32> mbox[2];

// Accelerator / DMA / other hardware registers. Not GPRs.
u16 ifx_regs[256];
std::array<u16, 256> ifx_regs;

// When state saving, all of the above can just be memcpy'd into the save state.
// The below needs special handling.
Expand Down
5 changes: 1 addition & 4 deletions Source/Core/Core/DSP/DSPHWInterface.cpp
Expand Up @@ -21,10 +21,7 @@ static void gdsp_do_dma();

void gdsp_ifx_init()
{
for (int i = 0; i < 256; i++)
{
g_dsp.ifx_regs[i] = 0;
}
g_dsp.ifx_regs.fill(0);

g_dsp.mbox[0].store(0);
g_dsp.mbox[1].store(0);
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/HW/DSPLLE/DSPLLE.cpp
Expand Up @@ -74,7 +74,7 @@ void DSPLLE::DoState(PointerWrap &p)
}

p.Do(g_dsp.step_counter);
p.Do(g_dsp.ifx_regs);
p.DoArray(g_dsp.ifx_regs);
p.Do(g_dsp.mbox[0]);
p.Do(g_dsp.mbox[1]);
UnWriteProtectMemory(g_dsp.iram, DSP_IRAM_BYTE_SIZE, false);
Expand Down

0 comments on commit 4fb90bf

Please sign in to comment.