Skip to content

Commit

Permalink
Merge pull request #4585 from lioncash/dspnamespace
Browse files Browse the repository at this point in the history
DSP: Namespace remaining un-namespaced DSP code
  • Loading branch information
lioncash committed Jan 1, 2017
2 parents 4c90ad7 + 3eb25ce commit 6c5063c
Show file tree
Hide file tree
Showing 70 changed files with 689 additions and 431 deletions.
21 changes: 12 additions & 9 deletions Source/Core/Core/DSP/DSPAccelerator.cpp
Expand Up @@ -11,14 +11,16 @@
#include "Core/DSP/DSPCore.h"
#include "Core/DSP/DSPHost.h"

namespace DSP
{
// The hardware adpcm decoder :)
static s16 ADPCM_Step(u32& _rSamplePos)
{
const s16* pCoefTable = (const s16*)&g_dsp.ifx_regs[DSP_COEF_A1_0];

if ((_rSamplePos & 15) == 0)
{
g_dsp.ifx_regs[DSP_PRED_SCALE] = DSPHost::ReadHostMemory((_rSamplePos & ~15) >> 1);
g_dsp.ifx_regs[DSP_PRED_SCALE] = Host::ReadHostMemory((_rSamplePos & ~15) >> 1);
_rSamplePos += 2;
}

Expand All @@ -28,8 +30,8 @@ static s16 ADPCM_Step(u32& _rSamplePos)
s32 coef1 = pCoefTable[coef_idx * 2 + 0];
s32 coef2 = pCoefTable[coef_idx * 2 + 1];

int temp = (_rSamplePos & 1) ? (DSPHost::ReadHostMemory(_rSamplePos >> 1) & 0xF) :
(DSPHost::ReadHostMemory(_rSamplePos >> 1) >> 4);
int temp = (_rSamplePos & 1) ? (Host::ReadHostMemory(_rSamplePos >> 1) & 0xF) :
(Host::ReadHostMemory(_rSamplePos >> 1) >> 4);

if (temp >= 8)
temp -= 16;
Expand Down Expand Up @@ -60,11 +62,11 @@ u16 dsp_read_aram_d3()
switch (g_dsp.ifx_regs[DSP_FORMAT])
{
case 0x5: // u8 reads
val = DSPHost::ReadHostMemory(Address);
val = Host::ReadHostMemory(Address);
Address++;
break;
case 0x6: // u16 reads
val = (DSPHost::ReadHostMemory(Address * 2) << 8) | DSPHost::ReadHostMemory(Address * 2 + 1);
val = (Host::ReadHostMemory(Address * 2) << 8) | Host::ReadHostMemory(Address * 2 + 1);
Address++;
break;
default:
Expand Down Expand Up @@ -94,8 +96,8 @@ void dsp_write_aram_d3(u16 value)
switch (g_dsp.ifx_regs[DSP_FORMAT])
{
case 0xA: // u16 writes
DSPHost::WriteHostMemory(value >> 8, Address * 2);
DSPHost::WriteHostMemory(value & 0xFF, Address * 2 + 1);
Host::WriteHostMemory(value >> 8, Address * 2);
Host::WriteHostMemory(value & 0xFF, Address * 2 + 1);
Address++;
break;
default:
Expand Down Expand Up @@ -138,14 +140,14 @@ u16 dsp_read_accelerator()
val = ADPCM_Step(Address);
break;
case 0x0A: // 16-bit PCM audio
val = (DSPHost::ReadHostMemory(Address * 2) << 8) | DSPHost::ReadHostMemory(Address * 2 + 1);
val = (Host::ReadHostMemory(Address * 2) << 8) | Host::ReadHostMemory(Address * 2 + 1);
g_dsp.ifx_regs[DSP_YN2] = g_dsp.ifx_regs[DSP_YN1];
g_dsp.ifx_regs[DSP_YN1] = val;
step_size_bytes = 2;
Address++;
break;
case 0x19: // 8-bit PCM audio
val = DSPHost::ReadHostMemory(Address) << 8;
val = Host::ReadHostMemory(Address) << 8;
g_dsp.ifx_regs[DSP_YN2] = g_dsp.ifx_regs[DSP_YN1];
g_dsp.ifx_regs[DSP_YN1] = val;
step_size_bytes = 2;
Expand Down Expand Up @@ -179,3 +181,4 @@ u16 dsp_read_accelerator()
g_dsp.ifx_regs[DSP_ACCAL] = Address & 0xffff;
return val;
}
} // namespace DSP
3 changes: 3 additions & 0 deletions Source/Core/Core/DSP/DSPAccelerator.h
Expand Up @@ -6,7 +6,10 @@

#include "Common/CommonTypes.h"

namespace DSP
{
u16 dsp_read_accelerator();

u16 dsp_read_aram_d3();
void dsp_write_aram_d3(u16 value);
} // namespace DSP
7 changes: 5 additions & 2 deletions Source/Core/Core/DSP/DSPAnalyzer.cpp
Expand Up @@ -12,7 +12,9 @@
#include "Core/DSP/DSPMemoryMap.h"
#include "Core/DSP/DSPTables.h"

namespace DSPAnalyzer
namespace DSP
{
namespace Analyzer
{
namespace
{
Expand Down Expand Up @@ -165,4 +167,5 @@ u8 GetCodeFlags(u16 address)
return code_flags[address];
}

} // namespace DSPAnalyzer
} // namespace Analyzer
} // namespace DSP
7 changes: 5 additions & 2 deletions Source/Core/Core/DSP/DSPAnalyzer.h
Expand Up @@ -7,7 +7,9 @@
#include "Common/CommonTypes.h"

// Basic code analysis.
namespace DSPAnalyzer
namespace DSP
{
namespace Analyzer
{
// Useful things to detect:
// * Loop endpoints - so that we can avoid checking for loops every cycle.
Expand All @@ -33,4 +35,5 @@ void Analyze();
// Retrieves the flags set during analysis for code in memory.
u8 GetCodeFlags(u16 address);

} // namespace DSPAnalyzer
} // namespace Analyzer
} // namespace DSP
3 changes: 3 additions & 0 deletions Source/Core/Core/DSP/DSPAssembler.cpp
Expand Up @@ -19,6 +19,8 @@
#include "Core/DSP/DSPDisassembler.h"
#include "Core/DSP/DSPTables.h"

namespace DSP
{
static const char* err_string[] = {"",
"Unknown Error",
"Unknown opcode",
Expand Down Expand Up @@ -1031,3 +1033,4 @@ bool DSPAssembler::AssembleFile(const char* fname, int pass)

return !failed;
}
} // namespace DSP
3 changes: 3 additions & 0 deletions Source/Core/Core/DSP/DSPAssembler.h
Expand Up @@ -14,6 +14,8 @@
#include "Core/DSP/DSPTables.h"
#include "Core/DSP/LabelMap.h"

namespace DSP
{
enum err_t
{
ERR_OK = 0,
Expand Down Expand Up @@ -116,3 +118,4 @@ class DSPAssembler
int m_current_param;
const AssemblerSettings settings_;
};
} // namespace DSP
3 changes: 3 additions & 0 deletions Source/Core/Core/DSP/DSPBreakpoints.h
Expand Up @@ -7,6 +7,8 @@
#include <cstring>
#include "Common/CommonTypes.h"

namespace DSP
{
// super fast breakpoints for a limited range.
// To be used interchangeably with the BreakPoints class.
class DSPBreakpoints
Expand Down Expand Up @@ -44,3 +46,4 @@ class DSPBreakpoints
private:
u8 b[65536];
};
} // namespace DSP
3 changes: 3 additions & 0 deletions Source/Core/Core/DSP/DSPCaptureLogger.cpp
Expand Up @@ -11,6 +11,8 @@

#include "Core/DSP/DSPCaptureLogger.h"

namespace DSP
{
// Definition of the packet structures stored in PCAP capture files.

const u8 IFX_ACCESS_PACKET_MAGIC = 0;
Expand Down Expand Up @@ -77,3 +79,4 @@ void PCAPDSPCaptureLogger::LogDMA(u16 control, u32 gc_address, u16 dsp_address,

m_pcap->AddPacket(buffer, sizeof(DMAPacket) + length);
}
} // namespace DSP
3 changes: 3 additions & 0 deletions Source/Core/Core/DSP/DSPCaptureLogger.h
Expand Up @@ -12,6 +12,8 @@

class PCAP;

namespace DSP
{
// An interface used to capture and log structured data about internal DSP
// data transfers.
//
Expand Down Expand Up @@ -70,3 +72,4 @@ class PCAPDSPCaptureLogger final : public DSPCaptureLogger, NonCopyable

std::unique_ptr<PCAP> m_pcap;
};
} // namespace DSP
3 changes: 3 additions & 0 deletions Source/Core/Core/DSP/DSPCodeUtil.cpp
Expand Up @@ -15,6 +15,8 @@
#include "Core/DSP/DSPCodeUtil.h"
#include "Core/DSP/DSPDisassembler.h"

namespace DSP
{
bool Assemble(const std::string& text, std::vector<u16>& code, bool force)
{
AssemblerSettings settings;
Expand Down Expand Up @@ -216,3 +218,4 @@ bool SaveBinary(const std::vector<u16>& code, const std::string& filename)
return false;
return true;
}
} // namespace DSP
3 changes: 3 additions & 0 deletions Source/Core/Core/DSP/DSPCodeUtil.h
Expand Up @@ -9,6 +9,8 @@

#include "Common/CommonTypes.h"

namespace DSP
{
bool Assemble(const std::string& text, std::vector<u16>& code, bool force = false);
bool Disassemble(const std::vector<u16>& code, bool line_numbers, std::string& text);
bool Compare(const std::vector<u16>& code1, const std::vector<u16>& code2);
Expand All @@ -25,3 +27,4 @@ void BinaryStringBEToCode(const std::string& str, std::vector<u16>& code);
// Load code (big endian binary).
bool LoadBinary(const std::string& filename, std::vector<u16>& code);
bool SaveBinary(const std::vector<u16>& code, const std::string& filename);
} // namespace DSP
3 changes: 3 additions & 0 deletions Source/Core/Core/DSP/DSPCommon.h
Expand Up @@ -6,4 +6,7 @@

#include "Common/CommonTypes.h"

namespace DSP
{
typedef u16 UDSPInstruction;
} // namespace DSP
38 changes: 21 additions & 17 deletions Source/Core/Core/DSP/DSPCore.cpp
Expand Up @@ -24,12 +24,14 @@
#include "Core/DSP/Interpreter/DSPInterpreter.h"
#include "Core/DSP/Jit/DSPEmitter.h"

namespace DSP
{
SDSP g_dsp;
DSPBreakpoints g_dsp_breakpoints;
static DSPCoreState core_state = DSPCORE_STOP;
u16 g_cycles_left = 0;
bool g_init_hax = false;
std::unique_ptr<DSP::JIT::x86::DSPEmitter> g_dsp_jit;
std::unique_ptr<JIT::x86::DSPEmitter> g_dsp_jit;
std::unique_ptr<DSPCaptureLogger> g_dsp_cap;
static Common::Event step_event;

Expand Down Expand Up @@ -77,14 +79,14 @@ static bool VerifyRoms()

if (rom_idx == 1)
{
DSPHost::OSD_AddMessage("You are using an old free DSP ROM made by the Dolphin Team.", 6000);
DSPHost::OSD_AddMessage("Only games using the Zelda UCode will work correctly.", 6000);
Host::OSD_AddMessage("You are using an old free DSP ROM made by the Dolphin Team.", 6000);
Host::OSD_AddMessage("Only games using the Zelda UCode will work correctly.", 6000);
}
else if (rom_idx == 2 || rom_idx == 3)
{
DSPHost::OSD_AddMessage("You are using a free DSP ROM made by the Dolphin Team.", 8000);
DSPHost::OSD_AddMessage("All Wii games will work correctly, and most GC games should ", 8000);
DSPHost::OSD_AddMessage("also work fine, but the GBA/IPL/CARD UCodes will not work.", 8000);
Host::OSD_AddMessage("You are using a free DSP ROM made by the Dolphin Team.", 8000);
Host::OSD_AddMessage("All Wii games will work correctly, and most GC games should ", 8000);
Host::OSD_AddMessage("also work fine, but the GBA/IPL/CARD UCodes will not work.", 8000);
}

return true;
Expand Down Expand Up @@ -148,7 +150,7 @@ bool DSPCore_Init(const DSPInitOptions& opts)

// Initialize JIT, if necessary
if (opts.core_type == DSPInitOptions::CORE_JIT)
g_dsp_jit = std::make_unique<DSP::JIT::x86::DSPEmitter>();
g_dsp_jit = std::make_unique<JIT::x86::DSPEmitter>();

g_dsp_cap.reset(opts.capture_logger);

Expand Down Expand Up @@ -176,7 +178,7 @@ void DSPCore_Reset()

std::fill(std::begin(g_dsp.r.wr), std::end(g_dsp.r.wr), 0xffff);

DSPAnalyzer::Analyze();
Analyzer::Analyze();
}

void DSPCore_SetException(u8 level)
Expand All @@ -193,7 +195,7 @@ void DSPCore_SetExternalInterrupt(bool val)
// Coming from the CPU
void DSPCore_CheckExternalInterrupt()
{
if (!DSP::Interpreter::dsp_SR_is_flag_set(SR_EXT_INT_ENABLE))
if (!Interpreter::dsp_SR_is_flag_set(SR_EXT_INT_ENABLE))
return;

// Signal the SPU about new mail
Expand All @@ -213,7 +215,7 @@ void DSPCore_CheckExceptions()
// Seems exp int are not masked by sr_int_enable
if (g_dsp.exceptions & (1 << i))
{
if (DSP::Interpreter::dsp_SR_is_flag_set(SR_INT_ENABLE) || (i == EXP_INT))
if (Interpreter::dsp_SR_is_flag_set(SR_INT_ENABLE) || (i == EXP_INT))
{
// store pc and sr until RTI
dsp_reg_store_stack(DSP_STACK_C, g_dsp.pc);
Expand Down Expand Up @@ -251,7 +253,7 @@ int DSPCore_RunCycles(int cycles)
}

g_cycles_left = cycles;
auto exec_addr = (DSP::JIT::x86::DSPEmitter::DSPCompiledCode)g_dsp_jit->enterDispatcher;
auto exec_addr = (JIT::x86::DSPEmitter::DSPCompiledCode)g_dsp_jit->enterDispatcher;
exec_addr();

if (g_dsp.reset_dspjit_codespace)
Expand All @@ -267,9 +269,9 @@ int DSPCore_RunCycles(int cycles)
case DSPCORE_RUNNING:
// Seems to slow things down
#if defined(_DEBUG) || defined(DEBUGFAST)
cycles = DSP::Interpreter::RunCyclesDebug(cycles);
cycles = Interpreter::RunCyclesDebug(cycles);
#else
cycles = DSP::Interpreter::RunCycles(cycles);
cycles = Interpreter::RunCycles(cycles);
#endif
break;

Expand All @@ -278,10 +280,10 @@ int DSPCore_RunCycles(int cycles)
if (core_state != DSPCORE_STEPPING)
continue;

DSP::Interpreter::Step();
Interpreter::Step();
cycles--;

DSPHost::UpdateDebugger();
Host::UpdateDebugger();
break;
case DSPCORE_STOP:
break;
Expand All @@ -293,11 +295,12 @@ int DSPCore_RunCycles(int cycles)
void DSPCore_SetState(DSPCoreState new_state)
{
core_state = new_state;

// kick the event, in case we are waiting
if (new_state == DSPCORE_RUNNING)
step_event.Set();
// Sleep(10);
DSPHost::UpdateDebugger();

Host::UpdateDebugger();
}

DSPCoreState DSPCore_GetState()
Expand Down Expand Up @@ -458,3 +461,4 @@ void DSPCore_WriteRegister(size_t reg, u16 val)
break;
}
}
} // namespace DSP
4 changes: 2 additions & 2 deletions Source/Core/Core/DSP/DSPCore.h
Expand Up @@ -23,7 +23,6 @@ namespace x86
class DSPEmitter;
}
}
}

enum : u32
{
Expand Down Expand Up @@ -311,7 +310,7 @@ extern SDSP g_dsp;
extern DSPBreakpoints g_dsp_breakpoints;
extern u16 g_cycles_left;
extern bool g_init_hax;
extern std::unique_ptr<DSP::JIT::x86::DSPEmitter> g_dsp_jit;
extern std::unique_ptr<JIT::x86::DSPEmitter> g_dsp_jit;
extern std::unique_ptr<DSPCaptureLogger> g_dsp_cap;

struct DSPInitOptions
Expand Down Expand Up @@ -371,3 +370,4 @@ void DSPCore_Step();

u16 DSPCore_ReadRegister(size_t reg);
void DSPCore_WriteRegister(size_t reg, u16 val);
} // namespace DSP
3 changes: 3 additions & 0 deletions Source/Core/Core/DSP/DSPDisassembler.cpp
Expand Up @@ -17,6 +17,8 @@
#include "Core/DSP/DSPTables.h"
#include "Core/DSP/Interpreter/DSPInterpreter.h"

namespace DSP
{
DSPDisassembler::DSPDisassembler(const AssemblerSettings& settings) : settings_(settings)
{
}
Expand Down Expand Up @@ -335,3 +337,4 @@ bool DSPDisassembler::DisassembleFile(const std::string& name, int base_addr, in

return true;
}
} // namespace DSP

0 comments on commit 6c5063c

Please sign in to comment.