Fixed a bug caused by static usage of Core::System::GetInstance()

Removed unused headers
Removed unneeded code
Optimised code
Added sanity checks
Added SafeCopyFromEmu/SafeCopyToEmu
Set Triforce buttons to be translatable
This commit is contained in:
crediar 2025-11-12 19:11:21 +01:00
parent 1ac4c03457
commit 5a87533e42
9 changed files with 347 additions and 401 deletions

View File

@ -53,7 +53,6 @@
#include "Core/HLE/HLE.h" #include "Core/HLE/HLE.h"
#include "Core/HW/CPU.h" #include "Core/HW/CPU.h"
#include "Core/HW/DSP.h" #include "Core/HW/DSP.h"
#include "Core/HW/DVD/AMMediaboard.h"
#include "Core/HW/EXI/EXI.h" #include "Core/HW/EXI/EXI.h"
#include "Core/HW/GBAPad.h" #include "Core/HW/GBAPad.h"
#include "Core/HW/GCKeyboard.h" #include "Core/HW/GCKeyboard.h"

File diff suppressed because it is too large Load Diff

View File

@ -58,6 +58,15 @@ class CPUThreadGuard;
class System; class System;
} // namespace Core } // namespace Core
struct MediaBoardRanges
{
u32 start;
u32 end;
u8* buffer;
size_t buffer_size;
u32 base_offset;
};
namespace AMMediaboard namespace AMMediaboard
{ {
@ -154,9 +163,7 @@ enum MediaBoardAddress : u32
DIMMCommandVersion1 = 0x1F900000, DIMMCommandVersion1 = 0x1F900000,
DIMMCommandVersion2 = 0x84000000, DIMMCommandVersion2 = 0x84000000,
DIMMCommandVersion2_1 = 0x84000020,
DIMMCommandVersion2_2 = 0x89000000, DIMMCommandVersion2_2 = 0x89000000,
DIMMCommandVersion2_2_1 = 0x89000200,
DIMMCommandExecute1 = 0x84000040, DIMMCommandExecute1 = 0x84000040,
DIMMCommandExecute2 = 0x88000000, DIMMCommandExecute2 = 0x88000000,

View File

@ -24,9 +24,6 @@
#include "Core/HW/EXI/EXI_Device.h" #include "Core/HW/EXI/EXI_Device.h"
#include "Core/HW/MMIO.h" #include "Core/HW/MMIO.h"
#include "Core/HW/Memmap.h" #include "Core/HW/Memmap.h"
#include "Core/HW/SI/SI.h"
#include "Core/HW/SI/SI_Device.h"
#include "Core/HW/WiimoteReal/WiimoteReal.h"
#include "Core/Movie.h" #include "Core/Movie.h"
#include "Core/PowerPC/PowerPC.h" #include "Core/PowerPC/PowerPC.h"
#include "Core/System.h" #include "Core/System.h"
@ -140,9 +137,7 @@ void CEXIBaseboard::DMAWrite(u32 addr, u32 size)
NOTICE_LOG_FMT(SP1, "AM-BB: COMMAND: Backup DMA Write: {:08x} {:x}", addr, size); NOTICE_LOG_FMT(SP1, "AM-BB: COMMAND: Backup DMA Write: {:08x} {:x}", addr, size);
m_backup.Seek(m_backup_offset, File::SeekOrigin::Begin); m_backup.Seek(m_backup_offset, File::SeekOrigin::Begin);
m_backup.WriteBytes(memory.GetSpanForAddress(addr).data(), size); m_backup.WriteBytes(memory.GetSpanForAddress(addr).data(), size);
m_backup.Flush(); m_backup.Flush();
} }
@ -154,9 +149,6 @@ void CEXIBaseboard::DMARead(u32 addr, u32 size)
NOTICE_LOG_FMT(SP1, "AM-BB: COMMAND: Backup DMA Read: {:08x} {:x}", addr, size); NOTICE_LOG_FMT(SP1, "AM-BB: COMMAND: Backup DMA Read: {:08x} {:x}", addr, size);
m_backup.Seek(m_backup_offset, File::SeekOrigin::Begin); m_backup.Seek(m_backup_offset, File::SeekOrigin::Begin);
m_backup.Flush();
m_backup.ReadBytes(memory.GetSpanForAddress(addr).data(), size); m_backup.ReadBytes(memory.GetSpanForAddress(addr).data(), size);
} }
@ -264,7 +256,6 @@ void CEXIBaseboard::TransferByte(u8& byte)
{ {
// 1 byte out // 1 byte out
case BackupRead: case BackupRead:
m_backup.Flush();
m_backup.ReadBytes(&byte, 1); m_backup.ReadBytes(&byte, 1);
break; break;
case DMAOffsetLengthSet: case DMAOffsetLengthSet:

View File

@ -73,7 +73,7 @@ GCPad::GCPad(const unsigned int index) : m_index(index)
groups.emplace_back(m_triforce = new ControllerEmu::Buttons(TRIFORCE_GROUP)); groups.emplace_back(m_triforce = new ControllerEmu::Buttons(TRIFORCE_GROUP));
for (const char* named_button : {TEST_BUTTON, SERVICE_BUTTON, COIN_BUTTON}) for (const char* named_button : {TEST_BUTTON, SERVICE_BUTTON, COIN_BUTTON})
{ {
m_triforce->AddInput(Translatability::DoNotTranslate, named_button); m_triforce->AddInput(Translatability::Translate, named_button);
} }
// Microphone // Microphone

View File

@ -56,7 +56,7 @@ public:
void RemoveEvent(int device_number); void RemoveEvent(int device_number);
void UpdateDevices(); void UpdateDevices();
u32 GetInLength(void) const { return m_com_csr.INLNGTH; } u32 GetInLength() const { return m_com_csr.INLNGTH; }
void RemoveDevice(int device_number); void RemoveDevice(int device_number);
void AddDevice(SIDevices device, int device_number); void AddDevice(SIDevices device, int device_number);

View File

@ -44,15 +44,15 @@ namespace SerialInterface
void JVSIOMessage::Start(int node) void JVSIOMessage::Start(int node)
{ {
m_last_start = m_ptr; m_last_start = m_pointer;
const u8 hdr[3] = {0xE0, (u8)node, 0}; const u8 header[3] = {0xE0, (u8)node, 0};
m_csum = 0; m_checksum = 0;
AddData(hdr, 3, 1); AddData(header, 3, 1);
} }
void JVSIOMessage::AddData(const u8* dst, size_t len, int sync = 0) void JVSIOMessage::AddData(const u8* dst, size_t len, int sync = 0)
{ {
if (m_ptr + len >= 0x80) if (m_pointer + len >= sizeof(m_message))
{ {
PanicAlertFmt("JVSIOMessage overrun!"); PanicAlertFmt("JVSIOMessage overrun!");
return; return;
@ -63,16 +63,26 @@ void JVSIOMessage::AddData(const u8* dst, size_t len, int sync = 0)
const u8 c = *dst++; const u8 c = *dst++;
if (!sync && ((c == 0xE0) || (c == 0xD0))) if (!sync && ((c == 0xE0) || (c == 0xD0)))
{ {
m_msg[m_ptr++] = 0xD0; if (m_pointer + 2 > sizeof(m_message))
m_msg[m_ptr++] = c - 1; {
PanicAlertFmt("JVSIOMessage overrun!");
break;
}
m_message[m_pointer++] = 0xD0;
m_message[m_pointer++] = c - 1;
} }
else else
{ {
m_msg[m_ptr++] = c; if (m_pointer >= sizeof(m_message))
{
PanicAlertFmt("JVSIOMessage overrun!");
break;
}
m_message[m_pointer++] = c;
} }
if (!sync) if (!sync)
m_csum += c; m_checksum += c;
sync = 0; sync = 0;
} }
} }
@ -95,9 +105,16 @@ void JVSIOMessage::AddData(u32 n)
void JVSIOMessage::End() void JVSIOMessage::End()
{ {
const u32 len = m_ptr - m_last_start; const u32 len = m_pointer - m_last_start;
m_msg[m_last_start + 2] = len - 2; // assuming len <0xD0 if (m_last_start + 2 < sizeof(m_message) && len >= 3)
AddData(m_csum + len - 2); {
m_message[m_last_start + 2] = len - 2; // assuming len <0xD0
AddData(m_checksum + len - 2);
}
else
{
PanicAlertFmt("JVSIOMessage: Not enough space for checksum!");
}
} }
static u8 CheckSumXOR(u8* data, u32 length) static u8 CheckSumXOR(u8* data, u32 length)
@ -2095,8 +2112,8 @@ int CSIDevice_AMBaseboard::RunBuffer(u8* buffer, int request_length)
data_out[data_offset++] = gcam_command; data_out[data_offset++] = gcam_command;
const u8* buf = message.m_msg.data(); const u8* buf = message.m_message.data();
const u32 len = message.m_ptr; const u32 len = message.m_pointer;
data_out[data_offset++] = len; data_out[data_offset++] = len;
for (u32 i = 0; i < len; ++i) for (u32 i = 0; i < len; ++i)

View File

@ -26,12 +26,12 @@ public:
void AddData(u32 n); void AddData(u32 n);
void End(); void End();
u32 m_ptr = 0; u32 m_pointer = 0;
std::array<u8, 0x80> m_msg; std::array<u8, 0x80> m_message;
private: private:
u32 m_last_start = 0; u32 m_last_start = 0;
u32 m_csum = 0; u32 m_checksum = 0;
}; };
// Triforce (GC-AM) baseboard // Triforce (GC-AM) baseboard

View File

@ -31,41 +31,24 @@ std::string VolumeDisc::GetGameID(const Partition& partition) const
memcpy(id + 1, boot_id->game_id.data() + 2, 2); memcpy(id + 1, boot_id->game_id.data() + 2, 2);
switch (boot_id->region_flags) switch (GetCountry())
{ {
default: default:
case 0x02: // JAPAN case Country::Japan:
id[3] = 'J'; id[3] = 'J';
break; break;
case 0x08: // ASIA case Country::Taiwan:
id[3] = 'W'; id[3] = 'W';
break; break;
case 0x0E: // USA case Country::USA:
id[3] = 'E'; id[3] = 'E';
break; break;
case 0x0C: // EXPORT case Country::Europe:
id[3] = 'P'; id[3] = 'P';
break; break;
} }
// There only seem to be three different makers here, memcpy(id + 4, GetMakerID().c_str(), 2);
// so we can just check the first char to difference between them.
//
// NAMCO CORPORATION, SEGA CORPORATION and Hitmaker co,ltd.
switch (boot_id->manufacturer[0])
{
case 'N': // NAMCO CORPORATION
id[4] = '8';
id[5] = '2';
break;
default:
case 'H': // Hitmaker co,ltd.
case 'S': // SEGA CORPORATION
id[4] = '6';
id[5] = 'E';
break;
}
return DecodeString(id); return DecodeString(id);
} }
@ -134,6 +117,11 @@ std::string VolumeDisc::GetMakerID(const Partition& partition) const
{ {
const BootID* boot_id = static_cast<const VolumeGC*>(this)->GetTriforceBootID(); const BootID* boot_id = static_cast<const VolumeGC*>(this)->GetTriforceBootID();
// There only seem to be three different makers here,
// so we can just check the first char to difference between them.
//
// NAMCO CORPORATION, SEGA CORPORATION and Hitmaker co,ltd.
switch (boot_id->manufacturer[0]) switch (boot_id->manufacturer[0])
{ {
case 'S': // SEGA CORPORATION case 'S': // SEGA CORPORATION