Merge pull request #232 from delroth/dsphle-cleanups

Random DSPHLE cleanups
This commit is contained in:
Pierre Bourdon 2014-03-30 01:23:09 +01:00
commit b31d1fd313
16 changed files with 271 additions and 262 deletions

View File

@ -12,13 +12,13 @@
#define AX_GC #define AX_GC
#include "Core/HW/DSPHLE/UCodes/AXVoice.h" #include "Core/HW/DSPHLE/UCodes/AXVoice.h"
AXUCode::AXUCode(DSPHLE* dsp_hle, u32 crc) AXUCode::AXUCode(DSPHLE* dsphle, u32 crc)
: UCodeInterface(dsp_hle, crc) : UCodeInterface(dsphle, crc)
, m_work_available(false) , m_work_available(false)
, m_cmdlist_size(0) , m_cmdlist_size(0)
{ {
WARN_LOG(DSPHLE, "Instantiating AXUCode: crc=%08x", crc); WARN_LOG(DSPHLE, "Instantiating AXUCode: crc=%08x", crc);
m_rMailHandler.PushMail(DSP_INIT); m_mail_handler.PushMail(DSP_INIT);
DSP::GenerateDSPInterruptFromDSPEmu(DSP::INT_DSP); DSP::GenerateDSPInterruptFromDSPEmu(DSP::INT_DSP);
LoadResamplingCoefficients(); LoadResamplingCoefficients();
@ -26,7 +26,7 @@ AXUCode::AXUCode(DSPHLE* dsp_hle, u32 crc)
AXUCode::~AXUCode() AXUCode::~AXUCode()
{ {
m_rMailHandler.Clear(); m_mail_handler.Clear();
} }
void AXUCode::LoadResamplingCoefficients() void AXUCode::LoadResamplingCoefficients()
@ -69,7 +69,7 @@ void AXUCode::LoadResamplingCoefficients()
void AXUCode::SignalWorkEnd() void AXUCode::SignalWorkEnd()
{ {
// Signal end of processing // Signal end of processing
m_rMailHandler.PushMail(DSP_YIELD); m_mail_handler.PushMail(DSP_YIELD);
DSP::GenerateDSPInterruptFromDSPEmu(DSP::INT_DSP); DSP::GenerateDSPInterruptFromDSPEmu(DSP::INT_DSP);
} }
@ -270,7 +270,7 @@ AXMixControl AXUCode::ConvertMixerControl(u32 mixer_control)
u32 ret = 0; u32 ret = 0;
// TODO: find other UCode versions with different mixer_control values // TODO: find other UCode versions with different mixer_control values
if (m_CRC == 0x4e8a8b21) if (m_crc == 0x4e8a8b21)
{ {
ret |= MIX_L | MIX_R; ret |= MIX_L | MIX_R;
if (mixer_control & 0x0001) ret |= MIX_AUXA_L | MIX_AUXA_R; if (mixer_control & 0x0001) ret |= MIX_AUXA_L | MIX_AUXA_R;
@ -611,23 +611,23 @@ void AXUCode::HandleMail(u32 mail)
CopyCmdList(mail, cmdlist_size); CopyCmdList(mail, cmdlist_size);
m_work_available = true; m_work_available = true;
} }
else if (m_UploadSetupInProgress) else if (m_upload_setup_in_progress)
{ {
PrepareBootUCode(mail); PrepareBootUCode(mail);
} }
else if (mail == MAIL_RESUME) else if (mail == MAIL_RESUME)
{ {
// Acknowledge the resume request // Acknowledge the resume request
m_rMailHandler.PushMail(DSP_RESUME); m_mail_handler.PushMail(DSP_RESUME);
DSP::GenerateDSPInterruptFromDSPEmu(DSP::INT_DSP); DSP::GenerateDSPInterruptFromDSPEmu(DSP::INT_DSP);
} }
else if (mail == MAIL_NEW_UCODE) else if (mail == MAIL_NEW_UCODE)
{ {
m_UploadSetupInProgress = true; m_upload_setup_in_progress = true;
} }
else if (mail == MAIL_RESET) else if (mail == MAIL_RESET)
{ {
m_DSPHLE->SetUCode(UCODE_ROM); m_dsphle->SetUCode(UCODE_ROM);
} }
else if (mail == MAIL_CONTINUE) else if (mail == MAIL_CONTINUE)
{ {
@ -666,7 +666,7 @@ void AXUCode::Update(int cycles)
// Used for UCode switching. // Used for UCode switching.
if (NeedsResumeMail()) if (NeedsResumeMail())
{ {
m_rMailHandler.PushMail(DSP_RESUME); m_mail_handler.PushMail(DSP_RESUME);
DSP::GenerateDSPInterruptFromDSPEmu(DSP::INT_DSP); DSP::GenerateDSPInterruptFromDSPEmu(DSP::INT_DSP);
} }
else if (m_work_available) else if (m_work_available)

View File

@ -52,7 +52,7 @@ enum AXMixControl
class AXUCode : public UCodeInterface class AXUCode : public UCodeInterface
{ {
public: public:
AXUCode(DSPHLE* dsp_hle, u32 crc); AXUCode(DSPHLE* dsphle, u32 crc);
virtual ~AXUCode(); virtual ~AXUCode();
virtual void HandleMail(u32 mail) override; virtual void HandleMail(u32 mail) override;

View File

@ -15,8 +15,8 @@
#include "Core/HW/DSPHLE/UCodes/UCodes.h" #include "Core/HW/DSPHLE/UCodes/UCodes.h"
AXWiiUCode::AXWiiUCode(DSPHLE *dsp_hle, u32 l_CRC) AXWiiUCode::AXWiiUCode(DSPHLE *dsphle, u32 crc)
: AXUCode(dsp_hle, l_CRC), : AXUCode(dsphle, crc),
m_last_main_volume(0x8000) m_last_main_volume(0x8000)
{ {
for (u16& volume : m_last_aux_volumes) for (u16& volume : m_last_aux_volumes)
@ -24,7 +24,7 @@ AXWiiUCode::AXWiiUCode(DSPHLE *dsp_hle, u32 l_CRC)
WARN_LOG(DSPHLE, "Instantiating AXWiiUCode"); WARN_LOG(DSPHLE, "Instantiating AXWiiUCode");
m_old_axwii = (l_CRC == 0xfa450138); m_old_axwii = (crc == 0xfa450138);
} }
AXWiiUCode::~AXWiiUCode() AXWiiUCode::~AXWiiUCode()

View File

@ -9,7 +9,7 @@
class AXWiiUCode : public AXUCode class AXWiiUCode : public AXUCode
{ {
public: public:
AXWiiUCode(DSPHLE *dsp_hle, u32 _CRC); AXWiiUCode(DSPHLE *dsphle, u32 crc);
virtual ~AXWiiUCode(); virtual ~AXWiiUCode();
u32 GetUpdateMs() override; u32 GetUpdateMs() override;

View File

@ -9,24 +9,24 @@
#include "Core/HW/DSPHLE/UCodes/UCodes.h" #include "Core/HW/DSPHLE/UCodes/UCodes.h"
CARDUCode::CARDUCode(DSPHLE *dsp_hle, u32 crc) CARDUCode::CARDUCode(DSPHLE *dsphle, u32 crc)
: UCodeInterface(dsp_hle, crc) : UCodeInterface(dsphle, crc)
{ {
DEBUG_LOG(DSPHLE, "CARDUCode - initialized"); DEBUG_LOG(DSPHLE, "CARDUCode - initialized");
m_rMailHandler.PushMail(DSP_INIT); m_mail_handler.PushMail(DSP_INIT);
} }
CARDUCode::~CARDUCode() CARDUCode::~CARDUCode()
{ {
m_rMailHandler.Clear(); m_mail_handler.Clear();
} }
void CARDUCode::Update(int cycles) void CARDUCode::Update(int cycles)
{ {
// check if we have to sent something // check if we have to sent something
if (!m_rMailHandler.IsEmpty()) if (!m_mail_handler.IsEmpty())
{ {
DSP::GenerateDSPInterruptFromDSPEmu(DSP::INT_DSP); DSP::GenerateDSPInterruptFromDSPEmu(DSP::INT_DSP);
} }
@ -37,19 +37,19 @@ u32 CARDUCode::GetUpdateMs()
return SConfig::GetInstance().m_LocalCoreStartupParameter.bWii ? 3 : 5; return SConfig::GetInstance().m_LocalCoreStartupParameter.bWii ? 3 : 5;
} }
void CARDUCode::HandleMail(u32 _uMail) void CARDUCode::HandleMail(u32 mail)
{ {
if (_uMail == 0xFF000000) // unlock card if (mail == 0xFF000000) // unlock card
{ {
// m_Mails.push(0x00000001); // ACK (actually anything != 0) // m_Mails.push(0x00000001); // ACK (actually anything != 0)
} }
else else
{ {
DEBUG_LOG(DSPHLE, "CARDUCode - unknown command: %x", _uMail); DEBUG_LOG(DSPHLE, "CARDUCode - unknown command: %x", mail);
} }
m_rMailHandler.PushMail(DSP_DONE); m_mail_handler.PushMail(DSP_DONE);
m_DSPHLE->SetUCode(UCODE_ROM); m_dsphle->SetUCode(UCODE_ROM);
} }

View File

@ -9,11 +9,11 @@
class CARDUCode : public UCodeInterface class CARDUCode : public UCodeInterface
{ {
public: public:
CARDUCode(DSPHLE *dsp_hle, u32 crc); CARDUCode(DSPHLE *dsphle, u32 crc);
virtual ~CARDUCode(); virtual ~CARDUCode();
u32 GetUpdateMs() override; u32 GetUpdateMs() override;
void HandleMail(u32 _uMail) override; void HandleMail(u32 mail) override;
void Update(int cycles) override; void Update(int cycles) override;
}; };

View File

@ -7,21 +7,21 @@
#include "Core/HW/DSPHLE/UCodes/GBA.h" #include "Core/HW/DSPHLE/UCodes/GBA.h"
#include "Core/HW/DSPHLE/UCodes/UCodes.h" #include "Core/HW/DSPHLE/UCodes/UCodes.h"
GBAUCode::GBAUCode(DSPHLE *dsp_hle, u32 crc) GBAUCode::GBAUCode(DSPHLE *dsphle, u32 crc)
: UCodeInterface(dsp_hle, crc) : UCodeInterface(dsphle, crc)
{ {
m_rMailHandler.PushMail(DSP_INIT); m_mail_handler.PushMail(DSP_INIT);
} }
GBAUCode::~GBAUCode() GBAUCode::~GBAUCode()
{ {
m_rMailHandler.Clear(); m_mail_handler.Clear();
} }
void GBAUCode::Update(int cycles) void GBAUCode::Update(int cycles)
{ {
// check if we have to send something // check if we have to send something
if (!m_rMailHandler.IsEmpty()) if (!m_mail_handler.IsEmpty())
{ {
DSP::GenerateDSPInterruptFromDSPEmu(DSP::INT_DSP); DSP::GenerateDSPInterruptFromDSPEmu(DSP::INT_DSP);
} }
@ -32,23 +32,23 @@ u32 GBAUCode::GetUpdateMs()
return SConfig::GetInstance().m_LocalCoreStartupParameter.bWii ? 3 : 5; return SConfig::GetInstance().m_LocalCoreStartupParameter.bWii ? 3 : 5;
} }
void GBAUCode::HandleMail(u32 _uMail) void GBAUCode::HandleMail(u32 mail)
{ {
static bool nextmail_is_mramaddr = false; static bool nextmail_is_mramaddr = false;
static bool calc_done = false; static bool calc_done = false;
if (m_UploadSetupInProgress) if (m_upload_setup_in_progress)
{ {
PrepareBootUCode(_uMail); PrepareBootUCode(mail);
} }
else if ((_uMail >> 16 == 0xabba) && !nextmail_is_mramaddr) else if ((mail >> 16 == 0xabba) && !nextmail_is_mramaddr)
{ {
nextmail_is_mramaddr = true; nextmail_is_mramaddr = true;
} }
else if (nextmail_is_mramaddr) else if (nextmail_is_mramaddr)
{ {
nextmail_is_mramaddr = false; nextmail_is_mramaddr = false;
u32 mramaddr = _uMail; u32 mramaddr = mail;
struct sec_params_t struct sec_params_t
{ {
@ -123,25 +123,25 @@ void GBAUCode::HandleMail(u32 _uMail)
x22, x23); x22, x23);
calc_done = true; calc_done = true;
m_rMailHandler.PushMail(DSP_DONE); m_mail_handler.PushMail(DSP_DONE);
} }
else if ((_uMail >> 16 == 0xcdd1) && calc_done) else if ((mail >> 16 == 0xcdd1) && calc_done)
{ {
switch (_uMail & 0xffff) switch (mail & 0xffff)
{ {
case 1: case 1:
m_UploadSetupInProgress = true; m_upload_setup_in_progress = true;
break; break;
case 2: case 2:
m_DSPHLE->SetUCode(UCODE_ROM); m_dsphle->SetUCode(UCODE_ROM);
break; break;
default: default:
DEBUG_LOG(DSPHLE, "GBAUCode - unknown 0xcdd1 command: %08x", _uMail); DEBUG_LOG(DSPHLE, "GBAUCode - unknown 0xcdd1 command: %08x", mail);
break; break;
} }
} }
else else
{ {
DEBUG_LOG(DSPHLE, "GBAUCode - unknown command: %08x", _uMail); DEBUG_LOG(DSPHLE, "GBAUCode - unknown command: %08x", mail);
} }
} }

View File

@ -8,10 +8,10 @@
struct GBAUCode : public UCodeInterface struct GBAUCode : public UCodeInterface
{ {
GBAUCode(DSPHLE *dsp_hle, u32 crc); GBAUCode(DSPHLE *dsphle, u32 crc);
virtual ~GBAUCode(); virtual ~GBAUCode();
u32 GetUpdateMs() override; u32 GetUpdateMs() override;
void HandleMail(u32 _uMail) override; void HandleMail(u32 mail) override;
void Update(int cycles) override; void Update(int cycles) override;
}; };

View File

@ -6,8 +6,8 @@
#include "Core/HW/DSPHLE/UCodes/INIT.h" #include "Core/HW/DSPHLE/UCodes/INIT.h"
#include "Core/HW/DSPHLE/UCodes/UCodes.h" #include "Core/HW/DSPHLE/UCodes/UCodes.h"
INITUCode::INITUCode(DSPHLE *dsp_hle, u32 crc) INITUCode::INITUCode(DSPHLE *dsphle, u32 crc)
: UCodeInterface(dsp_hle, crc) : UCodeInterface(dsphle, crc)
{ {
DEBUG_LOG(DSPHLE, "INITUCode - initialized"); DEBUG_LOG(DSPHLE, "INITUCode - initialized");
} }
@ -25,9 +25,9 @@ void INITUCode::Init()
void INITUCode::Update(int cycles) void INITUCode::Update(int cycles)
{ {
if (m_rMailHandler.IsEmpty()) if (m_mail_handler.IsEmpty())
{ {
m_rMailHandler.PushMail(0x80544348); m_mail_handler.PushMail(0x80544348);
// HALT // HALT
} }
} }
@ -37,7 +37,7 @@ u32 INITUCode::GetUpdateMs()
return SConfig::GetInstance().m_LocalCoreStartupParameter.bWii ? 3 : 5; return SConfig::GetInstance().m_LocalCoreStartupParameter.bWii ? 3 : 5;
} }
void INITUCode::HandleMail(u32 _uMail) void INITUCode::HandleMail(u32 mail)
{ {
} }

View File

@ -9,11 +9,11 @@
class INITUCode : public UCodeInterface class INITUCode : public UCodeInterface
{ {
public: public:
INITUCode(DSPHLE *dsp_hle, u32 crc); INITUCode(DSPHLE *dsphle, u32 crc);
virtual ~INITUCode(); virtual ~INITUCode();
u32 GetUpdateMs() override; u32 GetUpdateMs() override;
void HandleMail(u32 _uMail) override; void HandleMail(u32 mail) override;
void Update(int cycles) override; void Update(int cycles) override;
void Init(); void Init();
}; };

View File

@ -7,21 +7,22 @@
#endif #endif
#include "Common/Hash.h" #include "Common/Hash.h"
#include "Common/StringUtil.h"
#include "Core/ConfigManager.h" #include "Core/ConfigManager.h"
#include "Core/HW/Memmap.h" #include "Core/HW/Memmap.h"
#include "Core/HW/DSPHLE/UCodes/ROM.h" #include "Core/HW/DSPHLE/UCodes/ROM.h"
#include "Core/HW/DSPHLE/UCodes/UCodes.h" #include "Core/HW/DSPHLE/UCodes/UCodes.h"
ROMUCode::ROMUCode(DSPHLE *dsp_hle, u32 crc) ROMUCode::ROMUCode(DSPHLE *dsphle, u32 crc)
: UCodeInterface(dsp_hle, crc) : UCodeInterface(dsphle, crc)
, m_CurrentUCode() , m_current_ucode()
, m_BootTask_numSteps(0) , m_boot_task_num_steps(0)
, m_NextParameter(0) , m_next_parameter(0)
{ {
DEBUG_LOG(DSPHLE, "UCode_Rom - initialized"); DEBUG_LOG(DSPHLE, "UCode_Rom - initialized");
m_rMailHandler.Clear(); m_mail_handler.Clear();
m_rMailHandler.PushMail(0x8071FEED); m_mail_handler.PushMail(0x8071FEED);
} }
ROMUCode::~ROMUCode() ROMUCode::~ROMUCode()
@ -30,46 +31,46 @@ ROMUCode::~ROMUCode()
void ROMUCode::Update(int cycles) void ROMUCode::Update(int cycles)
{} {}
void ROMUCode::HandleMail(u32 _uMail) void ROMUCode::HandleMail(u32 mail)
{ {
if (m_NextParameter == 0) if (m_next_parameter == 0)
{ {
// wait for beginning of UCode // wait for beginning of UCode
if ((_uMail & 0xFFFF0000) != 0x80F30000) if ((mail & 0xFFFF0000) != 0x80F30000)
{ {
u32 Message = 0xFEEE0000 | (_uMail & 0xFFFF); u32 Message = 0xFEEE0000 | (mail & 0xFFFF);
m_rMailHandler.PushMail(Message); m_mail_handler.PushMail(Message);
} }
else else
{ {
m_NextParameter = _uMail; m_next_parameter = mail;
} }
} }
else else
{ {
switch (m_NextParameter) switch (m_next_parameter)
{ {
case 0x80F3A001: case 0x80F3A001:
m_CurrentUCode.m_RAMAddress = _uMail; m_current_ucode.m_ram_address = mail;
break; break;
case 0x80F3A002: case 0x80F3A002:
m_CurrentUCode.m_Length = _uMail & 0xffff; m_current_ucode.m_length = mail & 0xffff;
break; break;
case 0x80F3B002: case 0x80F3B002:
m_CurrentUCode.m_DMEMLength = _uMail & 0xffff; m_current_ucode.m_dmem_length = mail & 0xffff;
if (m_CurrentUCode.m_DMEMLength) { if (m_current_ucode.m_dmem_length) {
NOTICE_LOG(DSPHLE,"m_CurrentUCode.m_DMEMLength = 0x%04x.", m_CurrentUCode.m_DMEMLength); NOTICE_LOG(DSPHLE,"m_current_ucode.m_dmem_length = 0x%04x.", m_current_ucode.m_dmem_length);
} }
break; break;
case 0x80F3C002: case 0x80F3C002:
m_CurrentUCode.m_IMEMAddress = _uMail & 0xffff; m_current_ucode.m_imem_address = mail & 0xffff;
break; break;
case 0x80F3D001: case 0x80F3D001:
m_CurrentUCode.m_StartPC = _uMail & 0xffff; m_current_ucode.m_start_pc = mail & 0xffff;
BootUCode(); BootUCode();
return; // Important! BootUCode indirectly does "delete this;". Must exit immediately. return; // Important! BootUCode indirectly does "delete this;". Must exit immediately.
@ -78,33 +79,37 @@ void ROMUCode::HandleMail(u32 _uMail)
} }
// THE GODDAMN OVERWRITE WAS HERE. Without the return above, since BootUCode may delete "this", well ... // THE GODDAMN OVERWRITE WAS HERE. Without the return above, since BootUCode may delete "this", well ...
m_NextParameter = 0; m_next_parameter = 0;
} }
} }
void ROMUCode::BootUCode() void ROMUCode::BootUCode()
{ {
u32 ector_crc = HashEctor( u32 ector_crc = HashEctor(
(u8*)HLEMemory_Get_Pointer(m_CurrentUCode.m_RAMAddress), (u8*)HLEMemory_Get_Pointer(m_current_ucode.m_ram_address),
m_CurrentUCode.m_Length); m_current_ucode.m_length);
#if defined(_DEBUG) || defined(DEBUGFAST) #if defined(_DEBUG) || defined(DEBUGFAST)
char binFile[MAX_PATH]; std::string ucode_dump_path = StringFromFormat(
sprintf(binFile, "%sDSP_UC_%08X.bin", File::GetUserPath(D_DUMPDSP_IDX).c_str(), ector_crc); "%sDSP_UC_%08X.bin", File::GetUserPath(D_DUMPDSP_IDX).c_str(), ector_crc);
File::IOFile pFile(binFile, "wb"); File::IOFile fp(ucode_dump_path, "wb");
pFile.WriteArray((u8*)Memory::GetPointer(m_CurrentUCode.m_RAMAddress), m_CurrentUCode.m_Length); if (fp)
{
fp.WriteArray((u8*)HLEMemory_Get_Pointer(m_current_ucode.m_ram_address),
m_current_ucode.m_length);
}
#endif #endif
DEBUG_LOG(DSPHLE, "CurrentUCode SOURCE Addr: 0x%08x", m_CurrentUCode.m_RAMAddress); DEBUG_LOG(DSPHLE, "CurrentUCode SOURCE Addr: 0x%08x", m_current_ucode.m_ram_address);
DEBUG_LOG(DSPHLE, "CurrentUCode Length: 0x%08x", m_CurrentUCode.m_Length); DEBUG_LOG(DSPHLE, "CurrentUCode Length: 0x%08x", m_current_ucode.m_length);
DEBUG_LOG(DSPHLE, "CurrentUCode DEST Addr: 0x%08x", m_CurrentUCode.m_IMEMAddress); DEBUG_LOG(DSPHLE, "CurrentUCode DEST Addr: 0x%08x", m_current_ucode.m_imem_address);
DEBUG_LOG(DSPHLE, "CurrentUCode DMEM Length: 0x%08x", m_CurrentUCode.m_DMEMLength); DEBUG_LOG(DSPHLE, "CurrentUCode DMEM Length: 0x%08x", m_current_ucode.m_dmem_length);
DEBUG_LOG(DSPHLE, "CurrentUCode init_vector: 0x%08x", m_CurrentUCode.m_StartPC); DEBUG_LOG(DSPHLE, "CurrentUCode init_vector: 0x%08x", m_current_ucode.m_start_pc);
DEBUG_LOG(DSPHLE, "CurrentUCode CRC: 0x%08x", ector_crc); DEBUG_LOG(DSPHLE, "CurrentUCode CRC: 0x%08x", ector_crc);
DEBUG_LOG(DSPHLE, "BootTask - done"); DEBUG_LOG(DSPHLE, "BootTask - done");
m_DSPHLE->SetUCode(ector_crc); m_dsphle->SetUCode(ector_crc);
} }
u32 ROMUCode::GetUpdateMs() u32 ROMUCode::GetUpdateMs()
@ -114,9 +119,9 @@ u32 ROMUCode::GetUpdateMs()
void ROMUCode::DoState(PointerWrap &p) void ROMUCode::DoState(PointerWrap &p)
{ {
p.Do(m_CurrentUCode); p.Do(m_current_ucode);
p.Do(m_BootTask_numSteps); p.Do(m_boot_task_num_steps);
p.Do(m_NextParameter); p.Do(m_next_parameter);
DoStateShared(p); DoStateShared(p);
} }

View File

@ -9,28 +9,28 @@
class ROMUCode : public UCodeInterface class ROMUCode : public UCodeInterface
{ {
public: public:
ROMUCode(DSPHLE *dsp_hle, u32 _crc); ROMUCode(DSPHLE *dsphle, u32 crc);
virtual ~ROMUCode(); virtual ~ROMUCode();
u32 GetUpdateMs() override; u32 GetUpdateMs() override;
void HandleMail(u32 _uMail) override; void HandleMail(u32 mail) override;
void Update(int cycles) override; void Update(int cycles) override;
void DoState(PointerWrap &p) override; void DoState(PointerWrap &p) override;
private: private:
struct SUCode struct UCodeBootInfo
{ {
u32 m_RAMAddress; u32 m_ram_address;
u32 m_Length; u32 m_length;
u32 m_IMEMAddress; u32 m_imem_address;
u32 m_DMEMLength; u32 m_dmem_length;
u32 m_StartPC; u32 m_start_pc;
}; };
SUCode m_CurrentUCode; UCodeBootInfo m_current_ucode;
int m_BootTask_numSteps; int m_boot_task_num_steps;
u32 m_NextParameter; u32 m_next_parameter;
void BootUCode(); void BootUCode();
}; };

View File

@ -7,6 +7,7 @@
#endif #endif
#include "Common/Hash.h" #include "Common/Hash.h"
#include "Common/StringUtil.h"
#include "Core/HW/DSPHLE/UCodes/AX.h" #include "Core/HW/DSPHLE/UCodes/AX.h"
#include "Core/HW/DSPHLE/UCodes/AXWii.h" #include "Core/HW/DSPHLE/UCodes/AXWii.h"
@ -17,25 +18,25 @@
#include "Core/HW/DSPHLE/UCodes/UCodes.h" #include "Core/HW/DSPHLE/UCodes/UCodes.h"
#include "Core/HW/DSPHLE/UCodes/Zelda.h" #include "Core/HW/DSPHLE/UCodes/Zelda.h"
UCodeInterface* UCodeFactory(u32 _CRC, DSPHLE *dsp_hle, bool bWii) UCodeInterface* UCodeFactory(u32 crc, DSPHLE *dsphle, bool wii)
{ {
switch (_CRC) switch (crc)
{ {
case UCODE_ROM: case UCODE_ROM:
INFO_LOG(DSPHLE, "Switching to ROM ucode"); INFO_LOG(DSPHLE, "Switching to ROM ucode");
return new ROMUCode(dsp_hle, _CRC); return new ROMUCode(dsphle, crc);
case UCODE_INIT_AUDIO_SYSTEM: case UCODE_INIT_AUDIO_SYSTEM:
INFO_LOG(DSPHLE, "Switching to INIT ucode"); INFO_LOG(DSPHLE, "Switching to INIT ucode");
return new INITUCode(dsp_hle, _CRC); return new INITUCode(dsphle, crc);
case 0x65d6cc6f: // CARD case 0x65d6cc6f: // CARD
INFO_LOG(DSPHLE, "Switching to CARD ucode"); INFO_LOG(DSPHLE, "Switching to CARD ucode");
return new CARDUCode(dsp_hle, _CRC); return new CARDUCode(dsphle, crc);
case 0xdd7e72d5: case 0xdd7e72d5:
INFO_LOG(DSPHLE, "Switching to GBA ucode"); INFO_LOG(DSPHLE, "Switching to GBA ucode");
return new GBAUCode(dsp_hle, _CRC); return new GBAUCode(dsphle, crc);
case 0x3ad3b7ac: // Naruto3, Paper Mario - The Thousand Year Door case 0x3ad3b7ac: // Naruto3, Paper Mario - The Thousand Year Door
case 0x3daf59b9: // Alien Hominid case 0x3daf59b9: // Alien Hominid
@ -47,31 +48,31 @@ UCodeInterface* UCodeFactory(u32 _CRC, DSPHLE *dsp_hle, bool bWii)
// Zelda:OOT, Tony hawk, viewtiful joe // Zelda:OOT, Tony hawk, viewtiful joe
case 0xe2136399: // billy hatcher, dragonballz, mario party 5, TMNT, ava1080 case 0xe2136399: // billy hatcher, dragonballz, mario party 5, TMNT, ava1080
case 0x3389a79e: // MP1/MP2 Wii (Metroid Prime Trilogy) case 0x3389a79e: // MP1/MP2 Wii (Metroid Prime Trilogy)
INFO_LOG(DSPHLE, "CRC %08x: AX ucode chosen", _CRC); INFO_LOG(DSPHLE, "CRC %08x: AX ucode chosen", crc);
return new AXUCode(dsp_hle, _CRC); return new AXUCode(dsphle, crc);
case 0x6ba3b3ea: // IPL - PAL case 0x6ba3b3ea: // IPL - PAL
case 0x24b22038: // IPL - NTSC/NTSC-JAP case 0x24b22038: // IPL - NTSC/NTSC-JAP
case 0x42f64ac4: // Luigi case 0x42f64ac4: // Luigi
case 0x4be6a5cb: // AC, Pikmin case 0x4be6a5cb: // AC, Pikmin
INFO_LOG(DSPHLE, "CRC %08x: JAC (early Zelda) ucode chosen", _CRC); INFO_LOG(DSPHLE, "CRC %08x: JAC (early Zelda) ucode chosen", crc);
return new ZeldaUCode(dsp_hle, _CRC); return new ZeldaUCode(dsphle, crc);
case 0x6CA33A6D: // DK Jungle Beat case 0x6CA33A6D: // DK Jungle Beat
case 0x86840740: // Zelda WW - US case 0x86840740: // Zelda WW - US
case 0x56d36052: // Mario Sunshine case 0x56d36052: // Mario Sunshine
case 0x2fcdf1ec: // Mario Kart, zelda 4 swords case 0x2fcdf1ec: // Mario Kart, zelda 4 swords
case 0x267fd05a: // Pikmin PAL case 0x267fd05a: // Pikmin PAL
INFO_LOG(DSPHLE, "CRC %08x: Zelda ucode chosen", _CRC); INFO_LOG(DSPHLE, "CRC %08x: Zelda ucode chosen", crc);
return new ZeldaUCode(dsp_hle, _CRC); return new ZeldaUCode(dsphle, crc);
// WII CRCs // WII CRCs
case 0xb7eb9a9c: // Wii Pikmin - PAL case 0xb7eb9a9c: // Wii Pikmin - PAL
case 0xeaeb38cc: // Wii Pikmin 2 - PAL case 0xeaeb38cc: // Wii Pikmin 2 - PAL
case 0x6c3f6f94: // Zelda TP - PAL case 0x6c3f6f94: // Zelda TP - PAL
case 0xd643001f: // Mario Galaxy - PAL / WII DK Jungle Beat - PAL case 0xd643001f: // Mario Galaxy - PAL / WII DK Jungle Beat - PAL
INFO_LOG(DSPHLE, "CRC %08x: Zelda Wii ucode chosen\n", _CRC); INFO_LOG(DSPHLE, "CRC %08x: Zelda Wii ucode chosen\n", crc);
return new ZeldaUCode(dsp_hle, _CRC); return new ZeldaUCode(dsphle, crc);
case 0x2ea36ce6: // Some Wii demos case 0x2ea36ce6: // Some Wii demos
case 0x5ef56da3: // AX demo case 0x5ef56da3: // AX demo
@ -80,19 +81,19 @@ UCodeInterface* UCodeFactory(u32 _CRC, DSPHLE *dsp_hle, bool bWii)
case 0xadbc06bd: // Elebits case 0xadbc06bd: // Elebits
case 0x4cc52064: // Bleach: Versus Crusade case 0x4cc52064: // Bleach: Versus Crusade
case 0xd9c4bf34: // WiiMenu case 0xd9c4bf34: // WiiMenu
INFO_LOG(DSPHLE, "CRC %08x: Wii - AXWii chosen", _CRC); INFO_LOG(DSPHLE, "CRC %08x: Wii - AXWii chosen", crc);
return new AXWiiUCode(dsp_hle, _CRC); return new AXWiiUCode(dsphle, crc);
default: default:
if (bWii) if (wii)
{ {
PanicAlert("DSPHLE: Unknown ucode (CRC = %08x) - forcing AXWii.\n\nTry LLE emulator if this is homebrew.", _CRC); PanicAlert("DSPHLE: Unknown ucode (CRC = %08x) - forcing AXWii.\n\nTry LLE emulator if this is homebrew.", crc);
return new AXWiiUCode(dsp_hle, _CRC); return new AXWiiUCode(dsphle, crc);
} }
else else
{ {
PanicAlert("DSPHLE: Unknown ucode (CRC = %08x) - forcing AX.\n\nTry LLE emulator if this is homebrew.", _CRC); PanicAlert("DSPHLE: Unknown ucode (CRC = %08x) - forcing AX.\n\nTry LLE emulator if this is homebrew.", crc);
return new AXUCode(dsp_hle, _CRC); return new AXUCode(dsphle, crc);
} }
case UCODE_NULL: case UCODE_NULL:
@ -104,9 +105,9 @@ UCodeInterface* UCodeFactory(u32 _CRC, DSPHLE *dsp_hle, bool bWii)
bool UCodeInterface::NeedsResumeMail() bool UCodeInterface::NeedsResumeMail()
{ {
if (m_NeedsResumeMail) if (m_needs_resume_mail)
{ {
m_NeedsResumeMail = false; m_needs_resume_mail = false;
return true; return true;
} }
return false; return false;
@ -114,70 +115,73 @@ bool UCodeInterface::NeedsResumeMail()
void UCodeInterface::PrepareBootUCode(u32 mail) void UCodeInterface::PrepareBootUCode(u32 mail)
{ {
switch (m_NextUCode_steps) switch (m_next_ucode_steps)
{ {
case 0: m_NextUCode.mram_dest_addr = mail; break; case 0: m_next_ucode.mram_dest_addr = mail; break;
case 1: m_NextUCode.mram_size = mail & 0xffff; break; case 1: m_next_ucode.mram_size = mail & 0xffff; break;
case 2: m_NextUCode.mram_dram_addr = mail & 0xffff; break; case 2: m_next_ucode.mram_dram_addr = mail & 0xffff; break;
case 3: m_NextUCode.iram_mram_addr = mail; break; case 3: m_next_ucode.iram_mram_addr = mail; break;
case 4: m_NextUCode.iram_size = mail & 0xffff; break; case 4: m_next_ucode.iram_size = mail & 0xffff; break;
case 5: m_NextUCode.iram_dest = mail & 0xffff; break; case 5: m_next_ucode.iram_dest = mail & 0xffff; break;
case 6: m_NextUCode.iram_startpc = mail & 0xffff; break; case 6: m_next_ucode.iram_startpc = mail & 0xffff; break;
case 7: m_NextUCode.dram_mram_addr = mail; break; case 7: m_next_ucode.dram_mram_addr = mail; break;
case 8: m_NextUCode.dram_size = mail & 0xffff; break; case 8: m_next_ucode.dram_size = mail & 0xffff; break;
case 9: m_NextUCode.dram_dest = mail & 0xffff; break; case 9: m_next_ucode.dram_dest = mail & 0xffff; break;
} }
m_NextUCode_steps++; m_next_ucode_steps++;
if (m_NextUCode_steps == 10) if (m_next_ucode_steps == 10)
{ {
m_NextUCode_steps = 0; m_next_ucode_steps = 0;
m_NeedsResumeMail = true; m_needs_resume_mail = true;
m_UploadSetupInProgress = false; m_upload_setup_in_progress = false;
u32 ector_crc = HashEctor( u32 ector_crc = HashEctor(
(u8*)HLEMemory_Get_Pointer(m_NextUCode.iram_mram_addr), (u8*)HLEMemory_Get_Pointer(m_next_ucode.iram_mram_addr),
m_NextUCode.iram_size); m_next_ucode.iram_size);
#if defined(_DEBUG) || defined(DEBUGFAST) #if defined(_DEBUG) || defined(DEBUGFAST)
char binFile[MAX_PATH]; std::string ucode_dump_path = StringFromFormat(
sprintf(binFile, "%sDSP_UC_%08X.bin", File::GetUserPath(D_DUMPDSP_IDX).c_str(), ector_crc); "%sDSP_UC_%08X.bin", File::GetUserPath(D_DUMPDSP_IDX).c_str(), ector_crc);
File::IOFile pFile(binFile, "wb"); File::IOFile fp(ucode_dump_path, "wb");
if (pFile) if (fp)
pFile.WriteArray((u8*)Memory::GetPointer(m_NextUCode.iram_mram_addr), m_NextUCode.iram_size); {
fp.WriteArray((u8*)Memory::GetPointer(m_next_ucode.iram_mram_addr),
m_next_ucode.iram_size);
}
#endif #endif
DEBUG_LOG(DSPHLE, "PrepareBootUCode 0x%08x", ector_crc); DEBUG_LOG(DSPHLE, "PrepareBootUCode 0x%08x", ector_crc);
DEBUG_LOG(DSPHLE, "DRAM -> MRAM: src %04x dst %08x size %04x", DEBUG_LOG(DSPHLE, "DRAM -> MRAM: src %04x dst %08x size %04x",
m_NextUCode.mram_dram_addr, m_NextUCode.mram_dest_addr, m_next_ucode.mram_dram_addr, m_next_ucode.mram_dest_addr,
m_NextUCode.mram_size); m_next_ucode.mram_size);
DEBUG_LOG(DSPHLE, "MRAM -> IRAM: src %08x dst %04x size %04x startpc %04x", DEBUG_LOG(DSPHLE, "MRAM -> IRAM: src %08x dst %04x size %04x startpc %04x",
m_NextUCode.iram_mram_addr, m_NextUCode.iram_dest, m_next_ucode.iram_mram_addr, m_next_ucode.iram_dest,
m_NextUCode.iram_size, m_NextUCode.iram_startpc); m_next_ucode.iram_size, m_next_ucode.iram_startpc);
DEBUG_LOG(DSPHLE, "MRAM -> DRAM: src %08x dst %04x size %04x", DEBUG_LOG(DSPHLE, "MRAM -> DRAM: src %08x dst %04x size %04x",
m_NextUCode.dram_mram_addr, m_NextUCode.dram_dest, m_next_ucode.dram_mram_addr, m_next_ucode.dram_dest,
m_NextUCode.dram_size); m_next_ucode.dram_size);
if (m_NextUCode.mram_size) if (m_next_ucode.mram_size)
{ {
WARN_LOG(DSPHLE, WARN_LOG(DSPHLE,
"Trying to boot new ucode with dram download - not implemented"); "Trying to boot new ucode with dram download - not implemented");
} }
if (m_NextUCode.dram_size) if (m_next_ucode.dram_size)
{ {
WARN_LOG(DSPHLE, WARN_LOG(DSPHLE,
"Trying to boot new ucode with dram upload - not implemented"); "Trying to boot new ucode with dram upload - not implemented");
} }
m_DSPHLE->SwapUCode(ector_crc); m_dsphle->SwapUCode(ector_crc);
} }
} }
void UCodeInterface::DoStateShared(PointerWrap &p) void UCodeInterface::DoStateShared(PointerWrap &p)
{ {
p.Do(m_UploadSetupInProgress); p.Do(m_upload_setup_in_progress);
p.Do(m_NextUCode); p.Do(m_next_ucode);
p.Do(m_NextUCode_steps); p.Do(m_next_ucode_steps);
p.Do(m_NeedsResumeMail); p.Do(m_needs_resume_mail);
} }

View File

@ -17,63 +17,63 @@
class CMailHandler; class CMailHandler;
inline bool ExramRead(u32 _uAddress) inline bool ExramRead(u32 address)
{ {
if (_uAddress & 0x10000000) if (address & 0x10000000)
return true; return true;
else else
return false; return false;
} }
inline u8 HLEMemory_Read_U8(u32 _uAddress) inline u8 HLEMemory_Read_U8(u32 address)
{ {
if (ExramRead(_uAddress)) if (ExramRead(address))
return Memory::m_pEXRAM[_uAddress & Memory::EXRAM_MASK]; return Memory::m_pEXRAM[address & Memory::EXRAM_MASK];
else else
return Memory::m_pRAM[_uAddress & Memory::RAM_MASK]; return Memory::m_pRAM[address & Memory::RAM_MASK];
} }
inline u16 HLEMemory_Read_U16(u32 _uAddress) inline u16 HLEMemory_Read_U16(u32 address)
{ {
if (ExramRead(_uAddress)) if (ExramRead(address))
return Common::swap16(*(u16*)&Memory::m_pEXRAM[_uAddress & Memory::EXRAM_MASK]); return Common::swap16(*(u16*)&Memory::m_pEXRAM[address & Memory::EXRAM_MASK]);
else else
return Common::swap16(*(u16*)&Memory::m_pRAM[_uAddress & Memory::RAM_MASK]); return Common::swap16(*(u16*)&Memory::m_pRAM[address & Memory::RAM_MASK]);
} }
inline u32 HLEMemory_Read_U32(u32 _uAddress) inline u32 HLEMemory_Read_U32(u32 address)
{ {
if (ExramRead(_uAddress)) if (ExramRead(address))
return Common::swap32(*(u32*)&Memory::m_pEXRAM[_uAddress & Memory::EXRAM_MASK]); return Common::swap32(*(u32*)&Memory::m_pEXRAM[address & Memory::EXRAM_MASK]);
else else
return Common::swap32(*(u32*)&Memory::m_pRAM[_uAddress & Memory::RAM_MASK]); return Common::swap32(*(u32*)&Memory::m_pRAM[address & Memory::RAM_MASK]);
} }
inline void* HLEMemory_Get_Pointer(u32 _uAddress) inline void* HLEMemory_Get_Pointer(u32 address)
{ {
if (ExramRead(_uAddress)) if (ExramRead(address))
return &Memory::m_pEXRAM[_uAddress & Memory::EXRAM_MASK]; return &Memory::m_pEXRAM[address & Memory::EXRAM_MASK];
else else
return &Memory::m_pRAM[_uAddress & Memory::RAM_MASK]; return &Memory::m_pRAM[address & Memory::RAM_MASK];
} }
class UCodeInterface class UCodeInterface
{ {
public: public:
UCodeInterface(DSPHLE *dsphle, u32 _crc) UCodeInterface(DSPHLE *dsphle, u32 crc)
: m_rMailHandler(dsphle->AccessMailHandler()) : m_mail_handler(dsphle->AccessMailHandler())
, m_UploadSetupInProgress(false) , m_upload_setup_in_progress(false)
, m_DSPHLE(dsphle) , m_dsphle(dsphle)
, m_CRC(_crc) , m_crc(crc)
, m_NextUCode() , m_next_ucode()
, m_NextUCode_steps(0) , m_next_ucode_steps(0)
, m_NeedsResumeMail(false) , m_needs_resume_mail(false)
{} {}
virtual ~UCodeInterface() virtual ~UCodeInterface()
{} {}
virtual void HandleMail(u32 _uMail) = 0; virtual void HandleMail(u32 mail) = 0;
// Cycles are out of the 81/121mhz the DSP runs at. // Cycles are out of the 81/121mhz the DSP runs at.
virtual void Update(int cycles) = 0; virtual void Update(int cycles) = 0;
@ -81,7 +81,7 @@ public:
virtual void DoState(PointerWrap &p) { DoStateShared(p); } virtual void DoState(PointerWrap &p) { DoStateShared(p); }
static u32 GetCRC(UCodeInterface* pUCode) { return pUCode ? pUCode->m_CRC : UCODE_NULL; } static u32 GetCRC(UCodeInterface* ucode) { return ucode ? ucode->m_crc : UCODE_NULL; }
protected: protected:
void PrepareBootUCode(u32 mail); void PrepareBootUCode(u32 mail);
@ -93,7 +93,7 @@ protected:
void DoStateShared(PointerWrap &p); void DoStateShared(PointerWrap &p);
CMailHandler& m_rMailHandler; CMailHandler& m_mail_handler;
enum EDSP_Codes enum EDSP_Codes
{ {
@ -107,17 +107,17 @@ protected:
// UCode is forwarding mails to PrepareBootUCode // UCode is forwarding mails to PrepareBootUCode
// UCode only needs to set this to true, UCodeInterface will set to false when done! // UCode only needs to set this to true, UCodeInterface will set to false when done!
bool m_UploadSetupInProgress; bool m_upload_setup_in_progress;
// Need a pointer back to DSPHLE to switch ucodes. // Need a pointer back to DSPHLE to switch ucodes.
DSPHLE *m_DSPHLE; DSPHLE *m_dsphle;
// used for reconstruction when loading saves, // used for reconstruction when loading saves,
// and for variations within certain ucodes. // and for variations within certain ucodes.
u32 m_CRC; u32 m_crc;
private: private:
struct SUCode struct NextUCodeInfo
{ {
u32 mram_dest_addr; u32 mram_dest_addr;
u16 mram_size; u16 mram_size;
@ -130,10 +130,10 @@ private:
u16 dram_size; u16 dram_size;
u16 dram_dest; u16 dram_dest;
}; };
SUCode m_NextUCode; NextUCodeInfo m_next_ucode;
int m_NextUCode_steps; int m_next_ucode_steps;
bool m_NeedsResumeMail; bool m_needs_resume_mail;
}; };
extern UCodeInterface* UCodeFactory(u32 _CRC, DSPHLE *dsp_hle, bool bWii); extern UCodeInterface* UCodeFactory(u32 crc, DSPHLE *dsphle, bool wii);

View File

@ -13,9 +13,9 @@
#include "Core/HW/DSPHLE/UCodes/Zelda.h" #include "Core/HW/DSPHLE/UCodes/Zelda.h"
ZeldaUCode::ZeldaUCode(DSPHLE *dsp_hle, u32 _CRC) ZeldaUCode::ZeldaUCode(DSPHLE *dsphle, u32 crc)
: :
UCodeInterface(dsp_hle, _CRC), UCodeInterface(dsphle, crc),
m_bSyncInProgress(false), m_bSyncInProgress(false),
m_MaxVoice(0), m_MaxVoice(0),
@ -56,13 +56,13 @@ ZeldaUCode::ZeldaUCode(DSPHLE *dsp_hle, u32 _CRC)
if (IsLightVersion()) if (IsLightVersion())
{ {
DEBUG_LOG(DSPHLE, "Luigi Stylee!"); DEBUG_LOG(DSPHLE, "Luigi Stylee!");
m_rMailHandler.PushMail(0x88881111); m_mail_handler.PushMail(0x88881111);
} }
else else
{ {
m_rMailHandler.PushMail(DSP_INIT); m_mail_handler.PushMail(DSP_INIT);
DSP::GenerateDSPInterruptFromDSPEmu(DSP::INT_DSP); DSP::GenerateDSPInterruptFromDSPEmu(DSP::INT_DSP);
m_rMailHandler.PushMail(0xF3551111); // handshake m_mail_handler.PushMail(0xF3551111); // handshake
} }
m_VoiceBuffer = new s32[256 * 1024]; m_VoiceBuffer = new s32[256 * 1024];
@ -78,7 +78,7 @@ ZeldaUCode::ZeldaUCode(DSPHLE *dsp_hle, u32 _CRC)
ZeldaUCode::~ZeldaUCode() ZeldaUCode::~ZeldaUCode()
{ {
m_rMailHandler.Clear(); m_mail_handler.Clear();
delete [] m_VoiceBuffer; delete [] m_VoiceBuffer;
delete [] m_ResampleBuffer; delete [] m_ResampleBuffer;
@ -98,31 +98,31 @@ void ZeldaUCode::Update(int cycles)
{ {
if (!IsLightVersion()) if (!IsLightVersion())
{ {
if (m_rMailHandler.GetNextMail() == DSP_FRAME_END) if (m_mail_handler.GetNextMail() == DSP_FRAME_END)
DSP::GenerateDSPInterruptFromDSPEmu(DSP::INT_DSP); DSP::GenerateDSPInterruptFromDSPEmu(DSP::INT_DSP);
} }
if (NeedsResumeMail()) if (NeedsResumeMail())
{ {
m_rMailHandler.PushMail(DSP_RESUME); m_mail_handler.PushMail(DSP_RESUME);
DSP::GenerateDSPInterruptFromDSPEmu(DSP::INT_DSP); DSP::GenerateDSPInterruptFromDSPEmu(DSP::INT_DSP);
} }
} }
void ZeldaUCode::HandleMail(u32 _uMail) void ZeldaUCode::HandleMail(u32 mail)
{ {
if (IsLightVersion()) if (IsLightVersion())
HandleMail_LightVersion(_uMail); HandleMail_LightVersion(mail);
else if (IsSMSVersion()) else if (IsSMSVersion())
HandleMail_SMSVersion(_uMail); HandleMail_SMSVersion(mail);
else else
HandleMail_NormalVersion(_uMail); HandleMail_NormalVersion(mail);
} }
void ZeldaUCode::HandleMail_LightVersion(u32 _uMail) void ZeldaUCode::HandleMail_LightVersion(u32 mail)
{ {
//ERROR_LOG(DSPHLE, "Light version mail %08X, list in progress: %s, step: %i/%i", //ERROR_LOG(DSPHLE, "Light version mail %08X, list in progress: %s, step: %i/%i",
// _uMail, m_bListInProgress ? "yes":"no", m_step, m_numSteps); // mail, m_bListInProgress ? "yes":"no", m_step, m_numSteps);
if (m_bSyncCmdPending) if (m_bSyncCmdPending)
{ {
@ -142,7 +142,7 @@ void ZeldaUCode::HandleMail_LightVersion(u32 _uMail)
if (!m_bListInProgress) if (!m_bListInProgress)
{ {
switch ((_uMail >> 24) & 0x7F) switch ((mail >> 24) & 0x7F)
{ {
case 0x00: m_numSteps = 1; break; // dummy case 0x00: m_numSteps = 1; break; // dummy
case 0x01: m_numSteps = 5; break; // DsetupTable case 0x01: m_numSteps = 5; break; // DsetupTable
@ -151,7 +151,7 @@ void ZeldaUCode::HandleMail_LightVersion(u32 _uMail)
default: default:
{ {
m_numSteps = 0; m_numSteps = 0;
PanicAlert("Zelda uCode (light version): unknown/unsupported command %02X", (_uMail >> 24) & 0x7F); PanicAlert("Zelda uCode (light version): unknown/unsupported command %02X", (mail >> 24) & 0x7F);
} }
return; return;
} }
@ -163,7 +163,7 @@ void ZeldaUCode::HandleMail_LightVersion(u32 _uMail)
if (m_step >= sizeof(m_Buffer) / 4) if (m_step >= sizeof(m_Buffer) / 4)
PanicAlert("m_step out of range"); PanicAlert("m_step out of range");
((u32*)m_Buffer)[m_step] = _uMail; ((u32*)m_Buffer)[m_step] = mail;
m_step++; m_step++;
if (m_step >= m_numSteps) if (m_step >= m_numSteps)
@ -173,14 +173,14 @@ void ZeldaUCode::HandleMail_LightVersion(u32 _uMail)
} }
} }
void ZeldaUCode::HandleMail_SMSVersion(u32 _uMail) void ZeldaUCode::HandleMail_SMSVersion(u32 mail)
{ {
if (m_bSyncInProgress) if (m_bSyncInProgress)
{ {
if (m_bSyncCmdPending) if (m_bSyncCmdPending)
{ {
m_SyncFlags[(m_NumSyncMail << 1) ] = _uMail >> 16; m_SyncFlags[(m_NumSyncMail << 1) ] = mail >> 16;
m_SyncFlags[(m_NumSyncMail << 1) + 1] = _uMail & 0xFFFF; m_SyncFlags[(m_NumSyncMail << 1) + 1] = mail & 0xFFFF;
m_NumSyncMail++; m_NumSyncMail++;
if (m_NumSyncMail == 2) if (m_NumSyncMail == 2)
@ -192,13 +192,13 @@ void ZeldaUCode::HandleMail_SMSVersion(u32 _uMail)
m_CurBuffer++; m_CurBuffer++;
m_rMailHandler.PushMail(DSP_SYNC); m_mail_handler.PushMail(DSP_SYNC);
DSP::GenerateDSPInterruptFromDSPEmu(DSP::INT_DSP); DSP::GenerateDSPInterruptFromDSPEmu(DSP::INT_DSP);
m_rMailHandler.PushMail(0xF355FF00 | m_CurBuffer); m_mail_handler.PushMail(0xF355FF00 | m_CurBuffer);
if (m_CurBuffer == m_NumBuffers) if (m_CurBuffer == m_NumBuffers)
{ {
m_rMailHandler.PushMail(DSP_FRAME_END); m_mail_handler.PushMail(DSP_FRAME_END);
// DSP::GenerateDSPInterruptFromDSPEmu(DSP::INT_DSP); // DSP::GenerateDSPInterruptFromDSPEmu(DSP::INT_DSP);
m_bSyncCmdPending = false; m_bSyncCmdPending = false;
@ -218,7 +218,7 @@ void ZeldaUCode::HandleMail_SMSVersion(u32 _uMail)
if (m_step >= sizeof(m_Buffer) / 4) if (m_step >= sizeof(m_Buffer) / 4)
PanicAlert("m_step out of range"); PanicAlert("m_step out of range");
((u32*)m_Buffer)[m_step] = _uMail; ((u32*)m_Buffer)[m_step] = mail;
m_step++; m_step++;
if (m_step >= m_numSteps) if (m_step >= m_numSteps)
@ -232,23 +232,23 @@ void ZeldaUCode::HandleMail_SMSVersion(u32 _uMail)
// Here holds: m_bSyncInProgress == false && m_bListInProgress == false // Here holds: m_bSyncInProgress == false && m_bListInProgress == false
if (_uMail == 0) if (mail == 0)
{ {
m_bSyncInProgress = true; m_bSyncInProgress = true;
m_NumSyncMail = 0; m_NumSyncMail = 0;
} }
else if ((_uMail >> 16) == 0) else if ((mail >> 16) == 0)
{ {
m_bListInProgress = true; m_bListInProgress = true;
m_numSteps = _uMail; m_numSteps = mail;
m_step = 0; m_step = 0;
} }
else if ((_uMail >> 16) == 0xCDD1) // A 0xCDD1000X mail should come right after we send a DSP_SYNCEND mail else if ((mail >> 16) == 0xCDD1) // A 0xCDD1000X mail should come right after we send a DSP_SYNCEND mail
{ {
// The low part of the mail tells the operation to perform // The low part of the mail tells the operation to perform
// Seeing as every possible operation number halts the uCode, // Seeing as every possible operation number halts the uCode,
// except 3, that thing seems to be intended for debugging // except 3, that thing seems to be intended for debugging
switch (_uMail & 0xFFFF) switch (mail & 0xFFFF)
{ {
case 0x0003: // Do nothing case 0x0003: // Do nothing
return; return;
@ -256,27 +256,27 @@ void ZeldaUCode::HandleMail_SMSVersion(u32 _uMail)
case 0x0000: // Halt case 0x0000: // Halt
case 0x0001: // Dump memory? and halt case 0x0001: // Dump memory? and halt
case 0x0002: // Do something and halt case 0x0002: // Do something and halt
WARN_LOG(DSPHLE, "Zelda uCode(SMS version): received halting operation %04X", _uMail & 0xFFFF); WARN_LOG(DSPHLE, "Zelda uCode(SMS version): received halting operation %04X", mail & 0xFFFF);
return; return;
default: // Invalid (the real ucode would likely crash) default: // Invalid (the real ucode would likely crash)
WARN_LOG(DSPHLE, "Zelda uCode(SMS version): received invalid operation %04X", _uMail & 0xFFFF); WARN_LOG(DSPHLE, "Zelda uCode(SMS version): received invalid operation %04X", mail & 0xFFFF);
return; return;
} }
} }
else else
{ {
WARN_LOG(DSPHLE, "Zelda uCode (SMS version): unknown mail %08X", _uMail); WARN_LOG(DSPHLE, "Zelda uCode (SMS version): unknown mail %08X", mail);
} }
} }
void ZeldaUCode::HandleMail_NormalVersion(u32 _uMail) void ZeldaUCode::HandleMail_NormalVersion(u32 mail)
{ {
// WARN_LOG(DSPHLE, "Zelda uCode: Handle mail %08X", _uMail); // WARN_LOG(DSPHLE, "Zelda uCode: Handle mail %08X", mail);
if (m_UploadSetupInProgress) // evaluated first! if (m_upload_setup_in_progress) // evaluated first!
{ {
PrepareBootUCode(_uMail); PrepareBootUCode(mail);
return; return;
} }
@ -284,9 +284,9 @@ void ZeldaUCode::HandleMail_NormalVersion(u32 _uMail)
{ {
if (m_bSyncCmdPending) if (m_bSyncCmdPending)
{ {
u32 n = (_uMail >> 16) & 0xF; u32 n = (mail >> 16) & 0xF;
m_MaxVoice = (n + 1) << 4; m_MaxVoice = (n + 1) << 4;
m_SyncFlags[n] = _uMail & 0xFFFF; m_SyncFlags[n] = mail & 0xFFFF;
m_bSyncInProgress = false; m_bSyncInProgress = false;
m_CurVoice = m_MaxVoice; m_CurVoice = m_MaxVoice;
@ -297,16 +297,16 @@ void ZeldaUCode::HandleMail_NormalVersion(u32 _uMail)
m_CurBuffer++; m_CurBuffer++;
m_rMailHandler.PushMail(DSP_SYNC); m_mail_handler.PushMail(DSP_SYNC);
DSP::GenerateDSPInterruptFromDSPEmu(DSP::INT_DSP); DSP::GenerateDSPInterruptFromDSPEmu(DSP::INT_DSP);
m_rMailHandler.PushMail(0xF355FF00 | m_CurBuffer); m_mail_handler.PushMail(0xF355FF00 | m_CurBuffer);
m_CurVoice = 0; m_CurVoice = 0;
if (m_CurBuffer == m_NumBuffers) if (m_CurBuffer == m_NumBuffers)
{ {
if (!IsDMAVersion()) // this is a hack... without it Pikmin 1 Wii/ Zelda TP Wii mail-s stopped if (!IsDMAVersion()) // this is a hack... without it Pikmin 1 Wii/ Zelda TP Wii mail-s stopped
m_rMailHandler.PushMail(DSP_FRAME_END); m_mail_handler.PushMail(DSP_FRAME_END);
//g_dspInitialize.pGenerateDSPInterrupt(); //g_dspInitialize.pGenerateDSPInterrupt();
m_bSyncCmdPending = false; m_bSyncCmdPending = false;
@ -326,7 +326,7 @@ void ZeldaUCode::HandleMail_NormalVersion(u32 _uMail)
if (m_step >= sizeof(m_Buffer) / 4) if (m_step >= sizeof(m_Buffer) / 4)
PanicAlert("m_step out of range"); PanicAlert("m_step out of range");
((u32*)m_Buffer)[m_step] = _uMail; ((u32*)m_Buffer)[m_step] = mail;
m_step++; m_step++;
if (m_step >= m_numSteps) if (m_step >= m_numSteps)
@ -345,47 +345,47 @@ void ZeldaUCode::HandleMail_NormalVersion(u32 _uMail)
// - 00000000, 000X0000 - Sync mails // - 00000000, 000X0000 - Sync mails
// - CDD1XXXX - comes after DsyncFrame completed, seems to be debugging stuff // - CDD1XXXX - comes after DsyncFrame completed, seems to be debugging stuff
if (_uMail == 0) if (mail == 0)
{ {
m_bSyncInProgress = true; m_bSyncInProgress = true;
} }
else if ((_uMail >> 16) == 0) else if ((mail >> 16) == 0)
{ {
m_bListInProgress = true; m_bListInProgress = true;
m_numSteps = _uMail; m_numSteps = mail;
m_step = 0; m_step = 0;
} }
else if ((_uMail >> 16) == 0xCDD1) // A 0xCDD1000X mail should come right after we send a DSP_FRAME_END mail else if ((mail >> 16) == 0xCDD1) // A 0xCDD1000X mail should come right after we send a DSP_FRAME_END mail
{ {
// The low part of the mail tells the operation to perform // The low part of the mail tells the operation to perform
// Seeing as every possible operation number halts the uCode, // Seeing as every possible operation number halts the uCode,
// except 3, that thing seems to be intended for debugging // except 3, that thing seems to be intended for debugging
switch (_uMail & 0xFFFF) switch (mail & 0xFFFF)
{ {
case 0x0003: // Do nothing - continue normally case 0x0003: // Do nothing - continue normally
return; return;
case 0x0001: // accepts params to either dma to iram and/or dram (used for hotbooting a new ucode) case 0x0001: // accepts params to either dma to iram and/or dram (used for hotbooting a new ucode)
// TODO find a better way to protect from HLEMixer? // TODO find a better way to protect from HLEMixer?
m_UploadSetupInProgress = true; m_upload_setup_in_progress = true;
return; return;
case 0x0002: // Let IROM play us off case 0x0002: // Let IROM play us off
m_DSPHLE->SetUCode(UCODE_ROM); m_dsphle->SetUCode(UCODE_ROM);
return; return;
case 0x0000: // Halt case 0x0000: // Halt
WARN_LOG(DSPHLE, "Zelda uCode: received halting operation %04X", _uMail & 0xFFFF); WARN_LOG(DSPHLE, "Zelda uCode: received halting operation %04X", mail & 0xFFFF);
return; return;
default: // Invalid (the real ucode would likely crash) default: // Invalid (the real ucode would likely crash)
WARN_LOG(DSPHLE, "Zelda uCode: received invalid operation %04X", _uMail & 0xFFFF); WARN_LOG(DSPHLE, "Zelda uCode: received invalid operation %04X", mail & 0xFFFF);
return; return;
} }
} }
else else
{ {
WARN_LOG(DSPHLE, "Zelda uCode: unknown mail %08X", _uMail); WARN_LOG(DSPHLE, "Zelda uCode: unknown mail %08X", mail);
} }
} }
@ -514,15 +514,15 @@ void ZeldaUCode::ExecuteList()
if (IsLightVersion()) if (IsLightVersion())
{ {
if (m_bSyncCmdPending) if (m_bSyncCmdPending)
m_rMailHandler.PushMail(0x80000000 | m_NumBuffers); // after CMD_2 m_mail_handler.PushMail(0x80000000 | m_NumBuffers); // after CMD_2
else else
m_rMailHandler.PushMail(0x80000000 | Sync); // after CMD_0, CMD_1 m_mail_handler.PushMail(0x80000000 | Sync); // after CMD_0, CMD_1
} }
else else
{ {
m_rMailHandler.PushMail(DSP_SYNC); m_mail_handler.PushMail(DSP_SYNC);
DSP::GenerateDSPInterruptFromDSPEmu(DSP::INT_DSP); DSP::GenerateDSPInterruptFromDSPEmu(DSP::INT_DSP);
m_rMailHandler.PushMail(0xF3550000 | Sync); m_mail_handler.PushMail(0xF3550000 | Sync);
} }
} }

View File

@ -117,14 +117,14 @@ union ZeldaUnkPB
class ZeldaUCode : public UCodeInterface class ZeldaUCode : public UCodeInterface
{ {
public: public:
ZeldaUCode(DSPHLE *dsp_hle, u32 _CRC); ZeldaUCode(DSPHLE *dsphle, u32 crc);
virtual ~ZeldaUCode(); virtual ~ZeldaUCode();
u32 GetUpdateMs() override; u32 GetUpdateMs() override;
void HandleMail(u32 _uMail) override; void HandleMail(u32 mail) override;
void HandleMail_LightVersion(u32 _uMail); void HandleMail_LightVersion(u32 mail);
void HandleMail_SMSVersion(u32 _uMail); void HandleMail_SMSVersion(u32 mail);
void HandleMail_NormalVersion(u32 _uMail); void HandleMail_NormalVersion(u32 mail);
void Update(int cycles) override; void Update(int cycles) override;
void CopyPBsFromRAM(); void CopyPBsFromRAM();
@ -152,7 +152,7 @@ private:
// - sound data transferred using DMA instead of accelerator // - sound data transferred using DMA instead of accelerator
bool IsDMAVersion() const bool IsDMAVersion() const
{ {
switch (m_CRC) switch (m_crc)
{ {
case 0xb7eb9a9c: // Wii Pikmin - PAL case 0xb7eb9a9c: // Wii Pikmin - PAL
case 0xeaeb38cc: // Wii Pikmin 2 - PAL case 0xeaeb38cc: // Wii Pikmin 2 - PAL
@ -169,7 +169,7 @@ private:
// - exceptions and interrupts not used // - exceptions and interrupts not used
bool IsLightVersion() const bool IsLightVersion() const
{ {
switch (m_CRC) switch (m_crc)
{ {
case 0x6ba3b3ea: // IPL - PAL case 0x6ba3b3ea: // IPL - PAL
case 0x24b22038: // IPL - NTSC/NTSC-JAP case 0x24b22038: // IPL - NTSC/NTSC-JAP
@ -187,7 +187,7 @@ private:
// and I couldn't find a better name) // and I couldn't find a better name)
bool IsSMSVersion() const bool IsSMSVersion() const
{ {
switch (m_CRC) switch (m_crc)
{ {
case 0x56d36052: // Super Mario Sunshine case 0x56d36052: // Super Mario Sunshine
case 0x267fd05a: // Pikmin PAL case 0x267fd05a: // Pikmin PAL