project64/Source/Project64/N64 System/Mips/Pif Ram.cpp

834 lines
39 KiB
C++
Raw Normal View History

#include "stdafx.h"
#include "../C Core/mempak.h"
int CPifRamSettings::m_RefCount = 0;
bool CPifRamSettings::m_bShowPifRamErrors = false;
bool CPifRamSettings::m_DelaySI = false;
DWORD CPifRamSettings::m_RdramSize = 0;
CPifRamSettings::CPifRamSettings()
{
m_RefCount += 1;
if (m_RefCount == 1)
{
_Settings->RegisterChangeCB(Debugger_ShowPifErrors,NULL,RefreshSettings);
_Settings->RegisterChangeCB(Game_RDRamSize,NULL,RefreshSettings);
_Settings->RegisterChangeCB(Game_DelaySI,NULL,RefreshSettings);
RefreshSettings(NULL);
}
}
CPifRamSettings::~CPifRamSettings()
{
m_RefCount -= 1;
if (m_RefCount == 0)
{
_Settings->UnregisterChangeCB(Debugger_ShowPifErrors,NULL,RefreshSettings);
_Settings->UnregisterChangeCB(Game_RDRamSize,NULL,RefreshSettings);
_Settings->UnregisterChangeCB(Game_DelaySI,NULL,RefreshSettings);
}
}
void CPifRamSettings::RefreshSettings(void *)
{
m_bShowPifRamErrors = _Settings->LoadBool(Debugger_ShowPifErrors);
m_RdramSize = _Settings->LoadDword(Game_RDRamSize);
m_DelaySI = _Settings->LoadBool(Game_DelaySI);
}
CPifRam::CPifRam( bool SavesReadOnly ) :
CEeprom(SavesReadOnly)
{
Reset();
}
CPifRam::~CPifRam( void )
{
}
void CPifRam::Reset ( void )
{
memset(m_PifRam,0,sizeof(m_PifRam));
memset(m_PifRom,0,sizeof(m_PifRom));
}
void CPifRam::PifRamRead (void)
{
if (m_PifRam[0x3F] == 0x2)
{
return;
}
CONTROL * Controllers = _Plugins->Control()->PluginControllers();
int Channel = 0;
for (int CurPos = 0; CurPos < 0x40; CurPos ++)
{
switch(m_PifRam[CurPos]) {
case 0x00:
Channel += 1;
if (Channel > 6)
{
CurPos = 0x40;
}
break;
case 0xFE: CurPos = 0x40; break;
case 0xFF: break;
case 0xB4: case 0x56: case 0xB8: break; /* ??? */
default:
if ((m_PifRam[CurPos] & 0xC0) == 0)
{
if (Channel < 4) {
if (Controllers[Channel].Present && Controllers[Channel].RawData) {
if (_Plugins->Control()->ReadController) { _Plugins->Control()->ReadController(Channel,&m_PifRam[CurPos]); }
} else {
ReadControllerCommand(Channel,&m_PifRam[CurPos]);
}
}
CurPos += m_PifRam[CurPos] + (m_PifRam[CurPos + 1] & 0x3F) + 1;
Channel += 1;
} else {
if (bShowPifRamErrors()) { DisplayError("Unknown Command in PifRamRead(%X)",m_PifRam[CurPos]); }
CurPos = 0x40;
}
break;
}
}
if (_Plugins->Control()->ReadController) { _Plugins->Control()->ReadController(-1,NULL); }
}
void CPifRam::PifRamWrite (void) {
CONTROL * Controllers = _Plugins->Control()->PluginControllers();
int Channel, CurPos;
Channel = 0;
if( m_PifRam[0x3F] > 0x1) {
switch (m_PifRam[0x3F]) {
case 0x02: Pif2Write (); break;
case 0x08:
m_PifRam[0x3F] = 0;
_Reg->MI_INTR_REG |= MI_INTR_SI;
_Reg->SI_STATUS_REG |= SI_STATUS_INTERRUPT;
_Reg->CheckInterrupts();
break;
case 0x10:
memset(m_PifRom,0,0x7C0);
break;
case 0x30:
m_PifRam[0x3F] = 0x80;
break;
case 0xC0:
memset(m_PifRam,0,0x40);
break;
default:
if (bShowPifRamErrors()) { DisplayError("Unkown PifRam control: %d",m_PifRam[0x3F]); }
}
return;
}
for (CurPos = 0; CurPos < 0x40; CurPos++){
switch(m_PifRam[CurPos]) {
case 0x00:
Channel += 1;
if (Channel > 6) { CurPos = 0x40; }
break;
case 0xFE: CurPos = 0x40; break;
case 0xFF: break;
case 0xB4: case 0x56: case 0xB8: break; /* ??? */
default:
if ((m_PifRam[CurPos] & 0xC0) == 0) {
if (Channel < 4) {
if (Controllers[Channel].Present && Controllers[Channel].RawData) {
if (_Plugins->Control()->ControllerCommand) { _Plugins->Control()->ControllerCommand(Channel,&m_PifRam[CurPos]); }
} else {
ProcessControllerCommand(Channel,&m_PifRam[CurPos]);
}
} else if (Channel == 4) {
EepromCommand(&m_PifRam[CurPos]);
} else {
if (bShowPifRamErrors())
{
DisplayError("Command on channel 5?");
}
}
CurPos += m_PifRam[CurPos] + (m_PifRam[CurPos + 1] & 0x3F) + 1;
Channel += 1;
} else {
if (bShowPifRamErrors()) { DisplayError("Unknown Command in PifRamWrite(%X)",m_PifRam[CurPos]); }
CurPos = 0x40;
}
break;
}
}
m_PifRam[0x3F] = 0;
if (_Plugins->Control()->ControllerCommand) { _Plugins->Control()->ControllerCommand(-1,NULL); }
}
void CPifRam::SI_DMA_READ (void)
{
BYTE * PifRamPos = m_PifRam;
BYTE * RDRAM = _MMU->Rdram();
DWORD & SI_DRAM_ADDR_REG = _Reg->SI_DRAM_ADDR_REG;
if ((int)SI_DRAM_ADDR_REG > (int)RdramSize())
{
if (bShowPifRamErrors())
{
DisplayError("SI DMA\nSI_DRAM_ADDR_REG not in RDRam space");
}
return;
}
PifRamRead();
SI_DRAM_ADDR_REG &= 0xFFFFFFF8;
if ((int)SI_DRAM_ADDR_REG < 0) {
int count, RdramPos;
RdramPos = (int)SI_DRAM_ADDR_REG;
for (count = 0; count < 0x40; count++, RdramPos++) {
if (RdramPos < 0) { continue; }
RDRAM[RdramPos ^3] = m_PifRam[count];
}
} else {
_asm {
mov edi, dword ptr [SI_DRAM_ADDR_REG]
mov edi, dword ptr [edi]
add edi, RDRAM
mov ecx, PifRamPos
mov edx, 0
memcpyloop:
mov eax, dword ptr [ecx + edx]
bswap eax
mov dword ptr [edi + edx],eax
mov eax, dword ptr [ecx + edx + 4]
bswap eax
mov dword ptr [edi + edx + 4],eax
mov eax, dword ptr [ecx + edx + 8]
bswap eax
mov dword ptr [edi + edx + 8],eax
mov eax, dword ptr [ecx + edx + 12]
bswap eax
mov dword ptr [edi + edx + 12],eax
add edx, 16
cmp edx, 64
jb memcpyloop
}
}
#ifndef EXTERNAL_RELEASE
if (LogOptions.LogPRDMAMemStores) {
int count;
char HexData[100], AsciiData[100], Addon[20];
LogMessage("\tData DMAed to RDRAM:");
LogMessage("\t--------------------");
for (count = 0; count < 16; count ++ ) {
if ((count % 4) == 0) {
sprintf(HexData,"\0");
sprintf(AsciiData,"\0");
}
sprintf(Addon,"%02X %02X %02X %02X",
m_PifRam[(count << 2) + 0], m_PifRam[(count << 2) + 1],
m_PifRam[(count << 2) + 2], m_PifRam[(count << 2) + 3] );
strcat(HexData,Addon);
if (((count + 1) % 4) != 0) {
sprintf(Addon,"-");
strcat(HexData,Addon);
}
sprintf(Addon,"%c%c%c%c",
m_PifRam[(count << 2) + 0], m_PifRam[(count << 2) + 1],
m_PifRam[(count << 2) + 2], m_PifRam[(count << 2) + 3] );
strcat(AsciiData,Addon);
if (((count + 1) % 4) == 0) {
LogMessage("\t%s %s",HexData, AsciiData);
}
}
LogMessage("");
}
#endif
if (bDelaySI()) {
_SystemTimer->SetTimer(CSystemTimer::SiTimer,0x900,false);
} else {
_Reg->MI_INTR_REG |= MI_INTR_SI;
_Reg->SI_STATUS_REG |= SI_STATUS_INTERRUPT;
_Reg->CheckInterrupts();
}
}
void CPifRam::SI_DMA_WRITE (void)
{
BYTE * PifRamPos = m_PifRam;
DWORD & SI_DRAM_ADDR_REG = _Reg->SI_DRAM_ADDR_REG;
if ((int)SI_DRAM_ADDR_REG > (int)RdramSize())
{
if (bShowPifRamErrors())
{
DisplayError("SI DMA\nSI_DRAM_ADDR_REG not in RDRam space");
}
return;
}
SI_DRAM_ADDR_REG &= 0xFFFFFFF8;
BYTE * RDRAM = _MMU->Rdram();
if ((int)SI_DRAM_ADDR_REG < 0) {
int count, RdramPos;
RdramPos = (int)SI_DRAM_ADDR_REG;
for (count = 0; count < 0x40; count++, RdramPos++) {
if (RdramPos < 0) { m_PifRam[count] = 0; continue; }
m_PifRam[count] = RDRAM[RdramPos ^3];
}
} else {
_asm {
mov ecx, dword ptr [SI_DRAM_ADDR_REG]
mov ecx, dword ptr [ecx]
add ecx, RDRAM
mov edi, PifRamPos
mov edx, 0
memcpyloop:
mov eax, dword ptr [ecx + edx]
bswap eax
mov dword ptr [edi + edx],eax
mov eax, dword ptr [ecx + edx + 4]
bswap eax
mov dword ptr [edi + edx + 4],eax
mov eax, dword ptr [ecx + edx + 8]
bswap eax
mov dword ptr [edi + edx + 8],eax
mov eax, dword ptr [ecx + edx + 12]
bswap eax
mov dword ptr [edi + edx + 12],eax
add edx, 16
cmp edx, 64
jb memcpyloop
}
}
#ifndef EXTERNAL_RELEASE
if (LogOptions.LogPRDMAMemLoads) {
int count;
char HexData[100], AsciiData[100], Addon[20];
LogMessage("");
LogMessage("\tData DMAed to the Pif Ram:");
LogMessage("\t--------------------------");
for (count = 0; count < 16; count ++ ) {
if ((count % 4) == 0) {
sprintf(HexData,"\0");
sprintf(AsciiData,"\0");
}
sprintf(Addon,"%02X %02X %02X %02X",
m_PifRam[(count << 2) + 0], m_PifRam[(count << 2) + 1],
m_PifRam[(count << 2) + 2], m_PifRam[(count << 2) + 3] );
strcat(HexData,Addon);
if (((count + 1) % 4) != 0) {
sprintf(Addon,"-");
strcat(HexData,Addon);
}
sprintf(Addon,"%c%c%c%c",
m_PifRam[(count << 2) + 0], m_PifRam[(count << 2) + 1],
m_PifRam[(count << 2) + 2], m_PifRam[(count << 2) + 3] );
strcat(AsciiData,Addon);
if (((count + 1) % 4) == 0) {
LogMessage("\t%s %s",HexData, AsciiData);
}
}
LogMessage("");
}
#endif
PifRamWrite();
if (bDelaySI()) {
_SystemTimer->SetTimer(CSystemTimer::SiTimer,0x900,false);
} else {
_Reg->MI_INTR_REG |= MI_INTR_SI;
_Reg->SI_STATUS_REG |= SI_STATUS_INTERRUPT;
_Reg->CheckInterrupts();
}
}
void CPifRam::Pif2Write (void)
{
static const QWORD Pif2Reply[][4] =
{
//; Jet Force Gemini
{ 0x8FBB1DB876B63CEC, 0x025BEAEDEC803A6B, 0xDEB04FDB4CF76A13, 0x000B73E74AC64045 },
//; Banjo TooiE },
{ 0x0004001000400000, 0x0200000000000001, 0xA862ECC671D39FBF, 0x00F9F9F9F9F9F9CB },
{ 0x0004001000400001, 0x0200001000400001, 0x71939FBF8C2AE6B4, 0x00171737C6A8EC76 },
{ 0x0004001000400002, 0x0200002000800001, 0xA862ECC671D399B9, 0x001717177171F9CB },
{ 0x0004001000400003, 0x0200003000C00001, 0x71939FBF8C2AC6BE, 0x005555558C2AEC76 },
{ 0x0004001000410004, 0x0200004000000001, 0xF91B1737E6B471B3, 0x00ECC6A8ECC66EFE },
{ 0x0004001000410005, 0x0200005000400001, 0xA862ECE69F2FC6B8, 0x00ECC6A81737F9CB },
{ 0x0004001000410006, 0x0200006000800001, 0x71939FBF8C5A37BD, 0x00C66E4EECE6EC76 },
{ 0x0004001000410007, 0x0200007000C00001, 0x8CCA6EEC9909A8B2, 0x00C66E4E17377163 },
{ 0x0004001000420008, 0x0200008000000001, 0xA862ECE69F5F17B7, 0x00717171F9F9F9CB },
{ 0x0004001000420009, 0x0200009000400001, 0xF91B1737C60E6EBC, 0x005555B5E6046EFE },
{ 0x000400100042000A, 0x020000A000800001, 0xA862ECE69F5F11B1, 0x009F9F9F7171F9CB },
{ 0x000400100042000B, 0x020000B000C00001, 0x55151111A8A2ECB6, 0x007171D38C2A8C5A },
{ 0x000400100043000C, 0x020000C000000001, 0xF91B1737C69855BB, 0x006E8C2AECC66EFE },
{ 0x000400100043000D, 0x020000D000400001, 0x4EE0C66E17A74EB0, 0x00ECC6A89FBF7163 },
{ 0x000400100043000E, 0x020000E000800001, 0xF91B1737C69855B5, 0x006E8C2A6E4E6EFE },
{ 0x000400100043000F, 0x020000F000C00001, 0x4EE0C66E17A78CBA, 0x006EECC617377163 },
{ 0x0004001100440010, 0x0200000000000001, 0x8CCA6E3CC62EE604, 0x0071717171717163 },
{ 0x0004001100440011, 0x0200001000400001, 0x5575716317D79909, 0x00171737C6A88C5A },
{ 0x0004001100440012, 0x0200002000800001, 0x8CCA6E3CC62EC60E, 0x009F9F9FF9F97163 },
{ 0x0004001100440013, 0x0200003000C00001, 0x37FDF9CB71B37103, 0x009F9FBF6E8C6E1C },
{ 0x0004001100450014, 0x0200004000000001, 0x37FDF9CB7123C608, 0x00ECC6A8ECC66E1C },
{ 0x0004001100450015, 0x0200005000400001, 0x8CCA6E3CC65E370D, 0x006E8C2A9FBF7163 },
{ 0x0004001100450016, 0x0200006000800001, 0x55757163370DA802, 0x00C66E4EECE68C5A },
{ 0x0004001100450017, 0x0200007000C00001, 0x8CCA6E3CC65E1707, 0x00C66E4E17377163 },
{ 0x0004001100460018, 0x0200008000000001, 0xA862EC16A8026E0C, 0x00717171F9F9F9CB },
{ 0x0004001100460019, 0x0200009000400001, 0x37FDF9CB71531101, 0x005555B5E6046E1C },
{ 0x000400110046001A, 0x020000A000800001, 0x4EE0E6B4ECA6EC06, 0x00171717F9F97163 },
{ 0x000400110046001B, 0x020000B000C00001, 0x557571631797550B, 0x007171D38C2A8C5A },
{ 0x000400110047001C, 0x020000C000000001, 0x55757143F9AB4E00, 0x00ECC6A8C66E8C5A },
{ 0x000400110047001D, 0x020000D000400001, 0x8CCA6E1C6E9C5505, 0x00ECC6A89FBF7163 },
{ 0x000400110047001E, 0x020000E000800001, 0x55757143F9AB8C0A, 0x006EECC6ECE68C5A },
{ 0x000400110047001F, 0x020000F000C00001, 0x4EE0E6B4ECD69F0F, 0x006EECC617377163 },
{ 0x0004001200480020, 0x0200000000000001, 0x4EE0C66811915555, 0x0071717171717163 },
{ 0x0004001200480021, 0x0200001000400001, 0x71939FBF4EA08C5A, 0x00171737C6A8EC76 },
{ 0x0004001200480022, 0x0200002000800001, 0x4EE0C648F9DB9F5F, 0x009F9F9FF9F97163 },
{ 0x0004001200480023, 0x0200003000C00001, 0x9959551BA822E654, 0x007171D3C6A8C69E },
{ 0x0004001200490024, 0x0200004000000001, 0x71939FBF4ED09959, 0x006E8C2AC66EEC76 },
{ 0x0004001200490025, 0x0200005000400001, 0x4EE0C6681727C65E, 0x006E8C2A9FBF7163 },
{ 0x0004001200490026, 0x0200006000800001, 0x557571116EBC7153, 0x00C66E4EECE68C5A },
{ 0x0004001200490027, 0x0200007000C00001, 0x4EE0C6681727C658, 0x00C66E4E17377163 },
{ 0x00040012004A0028, 0x0200008000000001, 0x4EE0C6681757375D, 0x00F9F9F971717163 },
{ 0x00040012004A0029, 0x0200009000400001, 0x379D99B9EC06A852, 0x005555B5E6046E1C },
{ 0x00040012004A002A, 0x020000A000800001, 0x4EE0C66817571757, 0x00171717F9F97163 },
{ 0x00040012004A002B, 0x020000B000C00001, 0x379D99B9EC066E5C, 0x001717376E8C6E1C },
{ 0x00040012004B002C, 0x020000C000000001, 0x557571116E5C1151, 0x00ECC6A8C66E8C5A },
{ 0x00040012004B002D, 0x020000D000400001, 0xA8624EE09FAFEC56, 0x006E8C2A1737F9CB },
{ 0x00040012004B002E, 0x020000E000800001, 0x71939FBF4E90555B, 0x006EECC6ECE6EC76 },
{ 0x00040012004B002F, 0x020000F000C00001, 0xA8624EE09FAF4E50, 0x00C66E4E9FBFF9CB },
{ 0x00040013004C0030, 0x0200000000000001, 0x4EE0C6BEEC26C6A8, 0x0071717171717163 },
{ 0x00040013004C0031, 0x0200001000400001, 0xF91B376D115137AD, 0x00171737E6046EFE },
{ 0x00040013004C0032, 0x0200002000800001, 0x4EE0E6B44E00A8A2, 0x009F9F9FF9F97163 },
{ 0x00040013004C0033, 0x0200003000C00001, 0xF91B376D115117A7, 0x009F9FBF6E8C6EFE },
{ 0x00040013004D0034, 0x0200004000000001, 0xF91B17A755056EAC, 0x00ECC6A8ECC66EFE },
{ 0x00040013004D0035, 0x0200005000400001, 0x4EE0E6B44EB071A1, 0x006E8C2A9FBF7163 },
{ 0x00040013004D0036, 0x0200006000800001, 0xF91B374DF9A9ECA6, 0x00ECC6A86E4E6EFE },
{ 0x00040013004D0037, 0x0200007000C00001, 0xA862EC36C638F9AB, 0x006EECC69FBFF9CB },
{ 0x00040013004E0038, 0x0200008000000001, 0xA862EC166EAE4EA0, 0x00717171F9F9F9CB },
{ 0x00040013004E0039, 0x0200009000400001, 0x995955E59F9F55A5, 0x001717378C2AC69E },
{ 0x00040013004E003A, 0x020000A000800001, 0xA862EC166EAE8CAA, 0x009F9F9F7171F9CB },
{ 0x00040013004E003B, 0x020000B000C00001, 0xF91B374DF9D99FAF, 0x001717376E8C6EFE },
{ 0x00040013004F003C, 0x020000C000000001, 0xF91B17A75525E6A4, 0x006E8C2AECC66EFE },
{ 0x00040013004F003D, 0x020000D000400001, 0xA8624E10A832F9A9, 0x006E8C2A1737F9CB },
{ 0x00040013004F003E, 0x020000E000800001, 0x995955E59F0F6EAE, 0x00C66E4EC66EC69E },
{ 0x00040013004F003F, 0x020000F000C00001, 0x4EE0C6BE8CBA71A3, 0x006EECC617377163 },
{ 0x0005001400500040, 0x0200000000000001, 0xA8F2F91B6E8CF9F9, 0x00F9F9F9F9F9F9CB },
{ 0x0005001400500041, 0x0200001000400001, 0x9FCF6EAC55556EFE, 0x009F9FBF8C2AE694 },
{ 0x0005001400500042, 0x0200002000800001, 0xC65E553BE60471F3, 0x009F9F9FF9F971E1 },
{ 0x0005001400500043, 0x0200003000C00001, 0x17678CCA7171C6F8, 0x009F9FBF6E8C6E1C },
{ 0x0005001400510044, 0x0200004000000001, 0x9FCFA86237AD37FD, 0x00ECE6046EECE694 },
{ 0x0005001400510045, 0x0200005000400001, 0x8C7A71B38C5AA8F2, 0x006E8C2A9FBF7163 },
{ 0x0005001400510046, 0x0200006000800001, 0x9FCFA86237AD17F7, 0x006EECC6C66EE694 },
{ 0x0005001400510047, 0x0200007000C00001, 0x8C7A71B38C5A6EFC, 0x00C66E4E17377163 },
{ 0x0005001400520048, 0x0200008000000001, 0xC65E553BC60E71F1, 0x00F9F9F9717171E1 },
{ 0x0005001400520049, 0x0200009000400001, 0x17678CCA71F3ECF6, 0x005555B5E6046E1C },
{ 0x000500140052004A, 0x020000A000800001, 0x8C7A71B3EC86F9FB, 0x00171717F9F97163 },
{ 0x000500140052004B, 0x020000B000C00001, 0x17678CCA71F34EF0, 0x001717376E8C6E1C },
{ 0x000500140053004C, 0x020000C000000001, 0x9FCFA842F9EB55F5, 0x00C66E8C6EECE694 },
{ 0x000500140053004D, 0x020000D000400001, 0xC65E553BC6F88CFA, 0x00ECC6A89FBF71E1 },
{ 0x000500140053004E, 0x020000E000800001, 0x17674EE099299FFF, 0x006E8C2A6E4E6E1C },
{ 0x000500140053004F, 0x020000F000C00001, 0xA8F2F9B94E70E6F4, 0x00C66E4E9FBFF9CB },
{ 0x0005001500540050, 0x0200000000000001, 0xC65E55E599596E4E, 0x00717171717171E1 },
{ 0x0005001500540051, 0x0200001000400001, 0x17674E30C6087143, 0x00171737E6046E1C },
{ 0x0005001500540052, 0x0200002000800001, 0x8C7A71A15575C648, 0x009F9F9Ff9f97163 },
{ 0x0005001500540053, 0x0200003000C00001, 0x17674E106EAC374D, 0x009F9FBF6E8C6E1C },
{ 0x0005001500550054, 0x0200004000000001, 0x17674E30C65EA842, 0x00ECC6A8ECC66E1C },
{ 0x0005001500550055, 0x0200005000400001, 0xC6989FCF71A11747, 0x006E8C2A9FBF71E1 },
{ 0x0005001500550056, 0x0200006000800001, 0x17674E30C65E6E4C, 0x00ECC6A86E4E6E1C },
{ 0x0005001500550057, 0x0200007000C00001, 0x4E101767370D7141, 0x00C66E4E17377163 },
{ 0x0005001500560058, 0x0200008000000001, 0x4E10176717F7EC46, 0x00F9F9F971717163 },
{ 0x0005001500560059, 0x0200009000400001, 0x55E5C6B88C8AF94B, 0x005555B5C6A88C5A },
{ 0x000500150056005A, 0x020000A000800001, 0x4E10176717F74E40, 0x00171717F9F97163 },
{ 0x000500150056005B, 0x020000B000C00001, 0x55E5C6B88CEA5545, 0x007171D38C2A8C5A },
{ 0x000500150057005C, 0x020000C000000001, 0x17674E106EFC8C4A, 0x006E8C2AECC66E1C },
{ 0x000500150057005D, 0x020000D000400001, 0x4E101767372D9F4F, 0x00ECC6A89FBF7163 },
{ 0x000500150057005E, 0x020000E000800001, 0x17674E30E674E644, 0x006E8C2A6E4E6E1C },
{ 0x000500150057005F, 0x020000F000C00001, 0xC6989FEF9F8FF949, 0x006EECC6173771E1 },
{ 0x0005001600580060, 0x0200000000000001, 0xC6989F1FA8229F9F, 0x00717171717171E1 },
{ 0x0005001600580061, 0x0200001000400001, 0x9FCF6E4CF979E694, 0x009F9FBF8C2AE694 },
{ 0x0005001600580062, 0x0200002000800001, 0xC65E5535E684F999, 0x009F9F9FF9F971E1 },
{ 0x0005001600580063, 0x0200003000C00001, 0x9FCF6E6C375D6E9E, 0x007171D3C6A8E694 },
{ 0x0005001600590064, 0x0200004000000001, 0x9FCF6E6C11017193, 0x00ECE6046EECE694 },
{ 0x0005001600590065, 0x0200005000400001, 0xC65E55156E7EC698, 0x006E8C2A9FBF71E1 },
{ 0x0005001600590066, 0x0200006000800001, 0x1767ECA655A5379D, 0x00ECC6A86E4E6E1C },
{ 0x0005001600590067, 0x0200007000C00001, 0xC6989F1FA852A892, 0x00C66E4E173771E1 },
{ 0x00050016005A0068, 0x0200008000000001, 0x4E1037BD8CAA1797, 0x00F9F9F971717163 },
{ 0x00050016005A0069, 0x0200009000400001, 0x9FCF6E6C17576E9C, 0x001717378C2AE694 },
{ 0x00050016005A006A, 0x020000A000800001, 0x4E1037BDEC067191, 0x00171717F9F97163 },
{ 0x00050016005A006B, 0x020000B000C00001, 0x9FCF6E4CF9FBEC96, 0x00555555C6A8E694 },
{ 0x00050016005B006C, 0x020000C000000001, 0x55E5E6C47183F99B, 0x00ECC6A8C66E8C5A },
{ 0x00050016005B006D, 0x020000D000400001, 0x8C7A71B34EF04E90, 0x00ECC6A89FBF7163 },
{ 0x00050016005B006E, 0x020000E000800001, 0x55E5E6C471E35595, 0x006EECC6ECE68C5A },
{ 0x00050016005B006F, 0x020000F000C00001, 0x8C7A71B34EF08C9A, 0x006EECC617377163 },
{ 0x00050017005C0070, 0x0200000000000001, 0xA8F2F9AB55F5ECE6, 0x00F9F9F9F9F9F9CB },
{ 0x00050017005C0071, 0x0200001000400001, 0x17678C3AC6E855EB, 0x00171737E6046E1C },
{ 0x00050017005C0072, 0x0200002000800001, 0xA8F2F9AB55F54EE0, 0x001717177171F9CB },
{ 0x00050017005C0073, 0x0200003000C00001, 0x17678C3AC6E855E5, 0x009F9FBF6E8C6E1C },
{ 0x00050017005D0074, 0x0200004000000001, 0x9FCFA8B28CFA8CEA, 0x00ECE6046EECE694 },
{ 0x00050017005D0075, 0x0200005000400001, 0xA8F2F9AB552B9FEF, 0x00ECC6A81737F9CB },
{ 0x00050017005D0076, 0x0200006000800001, 0x55E5E614A872E6E4, 0x00C66E4EECE68C5A },
{ 0x00050017005D0077, 0x0200007000C00001, 0xA8F2F9AB552B99E9, 0x006EECC69FBFF9CB },
{ 0x00050017005E0078, 0x0200008000000001, 0x8C1A11611777C6EE, 0x00F9F9F971717163 },
{ 0x00050017005E0079, 0x0200009000400001, 0x9FCFA8B28C0A71E3, 0x001717378C2AE694 },
{ 0x00050017005E007A, 0x020000A000800001, 0x8C1A11611777C6E8, 0x00171717F9F97163 },
{ 0x00050017005E007B, 0x020000B000C00001, 0x17678C1A6EAE37ED, 0x001717376E8C6E1C },
{ 0x00050017005F007C, 0x020000C000000001, 0x55E5C6B84E50A8E2, 0x00ECC6A8C66E8C5A },
{ 0x00050017005F007D, 0x020000D000400001, 0xA8F2F9C971A317E7, 0x006E8C2A1737F9CB },
{ 0x00050017005F007E, 0x020000E000800001, 0x55E5C6B84E506EEC, 0x006EECC6ECE68C5A },
{ 0x00050017005F007F, 0x020000F000C00001, 0xABF2F9C971A311E1, 0x00C66E4E9FBFF9CB },
{ 0x0006001800600080, 0x0200000000000001, 0x6E6CEC46F9F91737, 0x00F9F9F9F9F9F9CB },
{ 0x0006001800600081, 0x0200001000400001, 0x379D9F3FC6A86E3C, 0x00171737E6046E1C },
{ 0x0006001800600082, 0x0200002000800001, 0x6E6CEC46F9F91131, 0x001717177171F9CB },
{ 0x0006001800600083, 0x0200003000C00001, 0x379D9F1F6E4EEC36, 0x009F9FBF6E8C6E1C },
{ 0x0006001800610084, 0x0200004000000001, 0x379D9F1F6E3C553B, 0x00ECC6A8ECC66E1C },
{ 0x0006001800610085, 0x0200005000400001, 0xE6C46ECE71434E30, 0x006E8C2A9FBF71E1 },
{ 0x0006001800610086, 0x0200006000800001, 0x379D9F1F6E3C5535, 0x00ECC6A86E4E6E1C },
{ 0x0006001800610087, 0x0200007000C00001, 0xE6C46ECE71438C3A, 0x00C66E4E173771E1 },
{ 0x0006001800620088, 0x0200008000000001, 0x6E6CEC46F97B9F3F, 0x00717171F9F9F9CB },
{ 0x0006001800620089, 0x0200009000400001, 0x551537BD4EC0E634, 0x005555B5C6A88C5A },
{ 0x000600180062008A, 0x020000A000800001, 0x6E6CEC46F97B9939, 0x009F9F9F7171F9CB },
{ 0x000600180062008B, 0x020000B000C00001, 0x551537BD4EC0C63E, 0x007171D38C2A8C5A },
{ 0x000600180063008C, 0x020000C000000001, 0x379D9F3FE6547133, 0x006E8C2AECC66E1C },
{ 0x000600180063008D, 0x020000D000400001, 0x6E6C4EA055C5C638, 0x006E8C2A1737F9CB },
{ 0x000600180063008E, 0x020000E000800001, 0x379D9F3FC6F8373D, 0x006E8C2A6E4E6E1C },
{ 0x000600180063008F, 0x020000F000C00001, 0x6E6CEC6617A7A832, 0x00C66E4E9FBFF9CB },
{ 0x0006001900640090, 0x0200000000000001, 0x8CEAE6146EAC6E8C, 0x0071717171717163 },
{ 0x0006001900640091, 0x0200001000400001, 0x7153556B37FD1181, 0x00171737C6A8EC76 },
{ 0x0006001900640092, 0x0200002000800001, 0x8CEAC61EA842EC86, 0x009F9F9FF9F97163 },
{ 0x0006001900640093, 0x0200003000C00001, 0x715355A5553B558B, 0x005555558C2AEC76 },
{ 0x0006001900650094, 0x0200004000000001, 0x7153556B17474E80, 0x006E8C2AC66EEC76 },
{ 0x0006001900650095, 0x0200005000400001, 0xE6C4A8B24E305585, 0x006E8C2A9FBF71E1 },
{ 0x0006001900650096, 0x0200006000800001, 0x7153556B17478C8A, 0x00C66E4EECE6EC76 },
{ 0x0006001900650097, 0x0200007000C00001, 0xE6C46EBC8C7A9F8F, 0x00C66E4E173771E1 },
{ 0x0006001900660098, 0x0200008000000001, 0x8CEAE634E6C4E684, 0x00F9F9F971717163 },
{ 0x0006001900660099, 0x0200009000400001, 0x9F7F71E39F7F9989, 0x001717378C2AE694 },
{ 0x000600190066009A, 0x020000A000800001, 0x8CEAE634E6C4C68E, 0x00171717F9F97163 },
{ 0x000600190066009B, 0x020000B000C00001, 0x9F7F71C371537183, 0x00555555C6A8E694 },
{ 0x000600190067009C, 0x020000C000000001, 0x17F7F94BF9C9C688, 0x006E8C2AECC66E1C },
{ 0x000600190067009D, 0x020000D000400001, 0x8CEAE6146EFC378D, 0x00ECC6A89FBF7163 },
{ 0x000600190067009E, 0x020000E000800001, 0x17F7F94BF9ABA882, 0x006E8C2A6E4E6E1C },
{ 0x000600190067009F, 0x020000F000C00001, 0x8CEAE6146EFC1787, 0x006EECC617377163 },
{ 0x0002000A002800A0, 0x0200000000000000, 0xF97B71919F1F71D3, 0x00F9F9F9F9F9F9F9 },
{ 0x0002000A002800A1, 0x0200001000400000, 0x4EC06EEEE684C6D8, 0x009F9FBF8C2AC66E },
{ 0x0002000A002800A2, 0x0200002000800000, 0x71F3F91917B737DD, 0x009F9F9FF9F97171 },
{ 0x0002000A002800A3, 0x0200003000C00000, 0xC6684E60EC66A8D2, 0x009F9FBF6E8C6EEC },
{ 0x0002000A002900A4, 0x0200004000000000, 0xECE6C6C86EBC17D7, 0x00ECE6046EECC66E },
{ 0x0002000A002900A5, 0x0200005000400000, 0x71111757556B6EDC, 0x006E8C2A9FBF7171 },
{ 0x0002000A002900A6, 0x0200006000800000, 0x4EC06EEEE61471D1, 0x006EECC6C66EC66E },
{ 0x0002000A002900A7, 0x0200007000C00000, 0xF97B71131101ECD6, 0x006EECC69FBFF9F9 },
{ 0x0002000A002A00A8, 0x0200008000000000, 0xF97B71737191F9DB, 0x00717171F9F9F9F9 },
{ 0x0002000A002A00A9, 0x0200009000400000, 0xC6684E60EC064ED0, 0x005555B5E6046EEC },
{ 0x0002000A002A00AA, 0x020000A000800000, 0x71F3F9FBF9FB55D5, 0x00171717F9F97171 },
{ 0x0002000A002A00AB, 0x020000B000C00000, 0xC6684E60EC068CDA, 0x001717376E8C6EEC },
{ 0x0002000A002B00AC, 0x020000C000000000, 0x4EC06EEEC63E9FDF, 0x00C66E8C6EECC66E },
{ 0x0002000A002B00AD, 0x020000D000400000, 0xF97B71737183E6D4, 0x006E8C2A1737F9F9 },
{ 0x0002000A002B00AE, 0x020000E000800000, 0xC6684E60EC96F9D9, 0x006E8C2A6E4E6EEC },
{ 0x0002000A002B00AF, 0x020000F000C00000, 0x7111175755656EDE, 0x006EECC617377171 },
{ 0x0002000B002C00B0, 0x0200000000000000, 0x9F5F55654E008C2A, 0x009F9F9F9F9F9F9F },
{ 0x0002000B002C00B1, 0x0200001000400000, 0xECE6C67871339F2F, 0x009F9FBF8C2AC66E },
{ 0x0002000B002C00B2, 0x0200002000800000, 0xF97B71E3C688E624, 0x991717177171F9F9 },
{ 0x0002000B002C00B3, 0x0200003000C00000, 0xECE6C67871339929, 0x007171D3C6A8C66E },
{ 0x0002000B002D00B4, 0x0200004000000000, 0x4EC06E1E378DC62E, 0x00ECE6046EECC66E },
{ 0x0002000B002D00B5, 0x0200005000400000, 0xF97B71E3C6187123, 0x00ECC6A81737F9F9 },
{ 0x0002000B002D00B6, 0x0200006000800000, 0x4EC06E1E378DC628, 0x006EECC6C66EC66E },
{ 0x0002000B002D00B7, 0x0200007000C00000, 0x9F5F55654EB0372D, 0x00C66E8C55559F9F },
{ 0x0002000B002E00B8, 0x0200008000000000, 0xF97B71E3E664A822, 0x00717171F9F9F9F9 },
{ 0x0002000B002E00B9, 0x0200009000400000, 0x4EC06E5C55B51727, 0x001717378C2AC66E },
{ 0x0002000B002E00BA, 0x020000A000800000, 0xF97B71E3E6646E2C, 0x009F9F9F7171F9F9 },
{ 0x0002000B002E00BB, 0x020000B000C00000, 0xC6684EF0F9BB1121, 0x001717376E8C6EEC },
{ 0x0002000B002F00BC, 0x020000C000000000, 0xC668EC969F0FEC26, 0x006E8C2AECC66EEC },
{ 0x0002000B002F00BD, 0x020000D000400000, 0xF97B71E3E6F4552B, 0x006E8C2A1737F9F9 },
{ 0x0002000B002F00BE, 0x020000E000800000, 0xC668EC969F0F4E20, 0x006E8C2A6E4E6EEC },
{ 0x0002000B002F00BF, 0x020000F000C00000, 0xF97B71E3E6F45525, 0x00C66E4E9FBFF9F9 },
{ 0x0003000C003000C0, 0x0200000000000000, 0xF9EBC6E8C66E7171, 0x00F9F9F9F9F9F9F9 },
{ 0x0003000C003000C1, 0x0200001000400000, 0x4E1011515555EC76, 0x009F9FBF8C2AC66E },
{ 0x0003000C003000C2, 0x0200002000800000, 0x376D8C6AECE6F97B, 0x001717379F9F1717 },
{ 0x0003000C003000C3, 0x0200003000C00000, 0x4E10115155554E70, 0x007171D3C6A8C66E },
{ 0x0003000C003100C4, 0x0200004000000000, 0xEC16377D71435575, 0x00ECE6046EECC66E },
{ 0x0003000C003100C5, 0x0200005000400000, 0x376D8C6A8C5A8C7A, 0x00C66EEC55551717 },
{ 0x0003000C003100C6, 0x0200006000800000, 0xEC16371D11819F7F, 0x006EECC6C66EC66E },
{ 0x0003000C003100C7, 0x0200007000C00000, 0xF9EBC6E8C6D8E674, 0x006EECC69FBFF9F9 },
{ 0x0003000C003200C8, 0x0200008000000000, 0x376D8C6A4EE0F979, 0x009F9F9F17171717 },
{ 0x0003000C003200C9, 0x0200009000400000, 0xE654559599B96E7E, 0x005555B5E6046EEC },
{ 0x0003000C003200CA, 0x020000A000800000, 0xF9EBC6E8C6687173, 0x009F9F9F7171F9F9 },
{ 0x0003000C003200CB, 0x020000B000C00000, 0x4E70711337DDC678, 0x00555555C6A8C66E },
{ 0x0003000C003300CC, 0x020000C000000000, 0xEC16377D7103377D, 0x00C66E8C6EECC66E },
{ 0x0003000C003300CD, 0x020000D000400000, 0xF9EBC6E8E6B4A872, 0x006E8C2A1737F9F9 },
{ 0x0003000C003300CE, 0x020000E000800000, 0xEC16377D71031777, 0x00C66E4EC66EC66E },
{ 0x0003000C003300CF, 0x020000F000C00000, 0xF9EBC6E8C6BE6E7C, 0x00C66E4E9FBFF9F9 },
{ 0x0003000D003400D0, 0x0200000000000000, 0x376D8C9A9959ECC6, 0x0017171717171717 },
{ 0x0003000D003400D1, 0x0200001000400000, 0x6E9E9F6F8CEAF9CB, 0x00171737C6A8ECC6 },
{ 0x0003000D003400D2, 0x0200002000800000, 0x376D8C9A99594EC0, 0x001717379F9F1717 },
{ 0x0003000D003400D3, 0x0200003000C00000, 0xEC1617C7A84255C5, 0x007171D3C6A8C66E },
{ 0x0003000D003500D4, 0x0200004000000000, 0xEC1637EDC65E8CCA, 0x00ECE6046EECC66E },
{ 0x0003000D003500D5, 0x0200005000400000, 0x376DEC5655859FCF, 0x00C66EEC55551717 },
{ 0x0003000D003500D6, 0x0200006000800000, 0xEC1617C76EDCE6C4, 0x006EECC6C66EC66E },
{ 0x0003000D003500D7, 0x0200007000C00000, 0x376D4E909FEFF9C9, 0x00ECC6A871D31717 },
{ 0x0003000D003600D8, 0x0200008000000000, 0xF9EBC61837BD6ECE, 0x00717171F9F9F9F9 },
{ 0x0003000D003600D9, 0x0200009000400000, 0xEC1617C76E6C71C3, 0x001717378C2AC66E },
{ 0x0003000D003600DA, 0x020000A000800000, 0x55C5A87271D1C6C8, 0x009F9F9F71D35555 },
{ 0x0003000D003600DB, 0x020000B000C00000, 0xEC1617C7A80237CD, 0x00555555C6A8C66E },
{ 0x0003000D003700DC, 0x020000C000000000, 0xEC1637EDC6B8A8C2, 0x00C66E8C6EECC66E },
{ 0x0003000D003700DD, 0x020000D000400000, 0xF9EBC618170717C7, 0x006E8C2A1737F9F9 },
{ 0x0003000D003700DE, 0x020000E000800000, 0xEC1617C7A8B26ECC, 0x00C66E4EC66EC66E },
{ 0x0003000D003700DF, 0x020000F000C00000, 0x55C5A812116171C1, 0x006EECC611115555 },
{ 0x0003000E003800E0, 0x0200000000000000, 0x55C56ECC6E0C1717, 0x0055555555555555 },
{ 0x0003000E003800E1, 0x0200001000400000, 0xEC16371D17B76E1C, 0x009F9FBF8C2AC66E },
{ 0x0003000E003800E2, 0x0200002000800000, 0xF9EBE664EC667111, 0x001717177171F9F9 },
{ 0x0003000E003800E3, 0x0200003000C00000, 0xEC16371D375DEC16, 0x007171D3C6A8C66E },
{ 0x0003000E003900E4, 0x0200004000000000, 0xEC16177771E3F91B, 0x00ECE6046EECC66E },
{ 0x0003000E003900E5, 0x0200005000400000, 0x55C56ECCA8524E10, 0x006E8C2A99995555 },
{ 0x0003000E003900E6, 0x0200006000800000, 0x6E9E9FFFF94B5515, 0x00C66E4EECE6ECC6 },
{ 0x0003000E003900E7, 0x0200007000C00000, 0x55C56ECCA8528C1A, 0x00C66E4E11115555 },
{ 0x0003000E003A00E8, 0x0200008000000000, 0x55C5A8E2C68E9F1F, 0x007171D355555555 },
{ 0x0003000E003A00E9, 0x0200009000400000, 0xE654555B55D5E614, 0x005555B5E6046EEC },
{ 0x0003000E003A00EA, 0x020000A000800000, 0x55C5A8E2C6E8F919, 0x009F9F9F71D35555 },
{ 0x0003000E003A00EB, 0x020000B000C00000, 0xEC16171711B16E1E, 0x00555555C6A8C66E },
{ 0x0003000E003B00EC, 0x020000C000000000, 0xE654555B55657113, 0x006E8C2AECC66EEC },
{ 0x0003000E003B00ED, 0x020000D000400000, 0xF9EBE6648CDAC618, 0x006E8C2A1737F9F9 },
{ 0x0003000E003B00EE, 0x020000E000800000, 0xE654555B550B371D, 0x006E8C2A6E4E6EEC },
{ 0x0003000E003B00EF, 0x020000F000C00000, 0x55C56ECC6EBCA812, 0x006EECC611115555 },
{ 0x0003000F003C00F0, 0x0200000000000000, 0x376D8C9A9FDFC66E, 0x0017171717171717 },
{ 0x0003000F003C00F1, 0x0200001000400000, 0xC69899698C6A7163, 0x00171737E6046EEC },
{ 0x0003000F003C00F2, 0x0200002000800000, 0x376D8C9A9FDFC668, 0x001717379F9F1717 },
{ 0x0003000F003C00F3, 0x0200003000C00000, 0xC69899694E00376D, 0x009F9FBF6E8C6EEC },
{ 0x0003000F003D00F4, 0x0200004000000000, 0xC6989969ECB6A862, 0x00ECC6A8ECC66EEC },
{ 0x0003000F003D00F5, 0x0200005000400000, 0x376D4E5055051767, 0x00C66EEC55551717 },
{ 0x0003000F003D00F6, 0x0200006000800000, 0xC69899694EB06E6C, 0x00ECC6A86E4E6EEC },
{ 0x0003000F003D00F7, 0x0200007000C00000, 0x376D4E5055051161, 0x00ECC6A871D31717 },
{ 0x0003000F003E00F8, 0x0200008000000000, 0x376D4E50555BEC66, 0x009F9F9F17171717 },
{ 0x0003000F003E00F9, 0x0200009000400000, 0xEC1617E7E644556B, 0x001717378C2AC66E },
{ 0x0003000F003E00FA, 0x020000A000800000, 0x376D4E50555B4E60, 0x009F9FBF9F9F1717 },
{ 0x0003000F003E00FB, 0x020000B000C00000, 0xEC1617E7E6445565, 0x00555555C6A8C66E },
{ 0x0003000F003F00FC, 0x020000C000000000, 0xC69899694E508C6A, 0x006E8C2AECC66EEC },
{ 0x0003000F003F00FD, 0x020000D000400000, 0x55C5A81217879F6F, 0x00ECC6A899995555 },
{ 0x0003000F003F00FE, 0x020000E000800000, 0x4E7071C16EDEE664, 0x00C66E4EC66EC66E },
{ 0x0003000F003F00FF, 0x020000F000C00000, 0x55C5A81217879969, 0x006EECC611115555 },
{ 0x0006001A006800A0, 0x0200000000000001, 0x6E6C4E60375D71D3, 0x00F9F9F9F9F9F9CB },
{ 0x0006001A006800A1, 0x0200001000400001, 0x17F7F9196ECEC6D8, 0x00171737E6046E1C },
{ 0x0006001A006800A2, 0x0200002000800001, 0x8CEAC6C871F137DD, 0x009F9F9FF9F97163 },
{ 0x0006001A006800A3, 0x0200003000C00001, 0x551517B74EA0A8D2, 0x005555558C2A8C5A },
{ 0x0006001A006900A4, 0x0200004000000001, 0x9F1F11B1ECF617D7, 0x00ECE6046EECE694 },
{ 0x0006001A006900A5, 0x0200005000400001, 0x6E6C8CAA55A56EDC, 0x00ECC6A81737F9CB },
{ 0x0006001A006900A6, 0x0200006000800001, 0x9F7F7113A85271D1, 0x006EECC6C66EE694 },
{ 0x0006001A006900A7, 0x0200007000C00001, 0x6E6C4E40F94BECD6, 0x006EECC69FBFF9CB },
{ 0x0006001A006A00A8, 0x0200008000000001, 0x6E6C8CAA55D5F9DB, 0x00717171F9F9F9CB },
{ 0x0006001A006A00A9, 0x0200009000400001, 0x551517B74E404ED0, 0x005555B5C6A88C5A },
{ 0x0006001A006A00AA, 0x020000A000800001, 0xE6C46EEE993955D5, 0x00171717F9F971E1 },
};
bool found = false;
for (int i = 0, n = sizeof(Pif2Reply)/sizeof(Pif2Reply[0]); i < n; i++)
{
if (Pif2Reply[i][0] != *(QWORD *)&m_PifRam[48]) { continue; }
if (Pif2Reply[i][1] != *(QWORD *)&m_PifRam[56]) { continue; }
m_PifRam[46] = m_PifRam[47] = 0x00;
*(QWORD *)&m_PifRam[48] = Pif2Reply[i][2];
*(QWORD *)&m_PifRam[56] = Pif2Reply[i][3];
found = true;
break;
}
if (!found) {
char buff[256];
int count;
sprintf (buff, "%s :(\r\n\r\nInfo:\r\nP1=%08X%08X P2=%08X%08X\r\n", GS(MSG_PIF2_ERROR),
*(DWORD *)&m_PifRam[52],*(DWORD *)&m_PifRam[48],*(DWORD *)&m_PifRam[60],*(DWORD *)&m_PifRam[56]);
for (count = 48; count < 64; count++) {
if (count % 4 == 0) {
strcat(buff,count == 48?"0x":", 0x");
}
char buff2[20];
sprintf(buff2,"%02X",m_PifRam[count]);
strcat(buff,buff2);
_Notify->DisplayError(buff);
}
}
}
void CPifRam::ProcessControllerCommand ( int Control, BYTE * Command)
{
CONTROL * Controllers = _Plugins->Control()->PluginControllers();
switch (Command[2]) {
case 0x00: // check
case 0xFF: // reset & check ?
if ((Command[1] & 0x80) != 0) { break; }
if (bShowPifRamErrors())
{
if (Command[0] != 1) { DisplayError("What am I meant to do with this Controller Command"); }
if (Command[1] != 3) { DisplayError("What am I meant to do with this Controller Command"); }
}
if (Controllers[Control].Present == TRUE) {
Command[3] = 0x05;
Command[4] = 0x00;
switch ( Controllers[Control].Plugin) {
case PLUGIN_RUMBLE_PAK: Command[5] = 1; break;
case PLUGIN_MEMPAK: Command[5] = 1; break;
case PLUGIN_RAW: Command[5] = 1; break;
default: Command[5] = 0; break;
}
} else {
Command[1] |= 0x80;
}
break;
case 0x01: // read controller
if (bShowPifRamErrors())
{
if (Command[0] != 1) { DisplayError("What am I meant to do with this Controller Command"); }
if (Command[1] != 4) { DisplayError("What am I meant to do with this Controller Command"); }
}
if (Controllers[Control].Present == FALSE) {
Command[1] |= 0x80;
}
break;
case 0x02: //read from controller pack
#ifndef EXTERNAL_RELEASE
if (LogOptions.LogControllerPak) { LogControllerPakData("Read: Before Gettting Results"); }
#endif
if (bShowPifRamErrors())
{
if (Command[0] != 3) { DisplayError("What am I meant to do with this Controller Command"); }
if (Command[1] != 33) { DisplayError("What am I meant to do with this Controller Command"); }
}
if (Controllers[Control].Present == TRUE) {
DWORD address = ((Command[3] << 8) | Command[4]);
switch (Controllers[Control].Plugin) {
case PLUGIN_RUMBLE_PAK:
memset(&Command[5], (address >= 0x8000 && address < 0x9000) ? 0x80 : 0x00, 0x20);
Command[0x25] = Mempacks_CalulateCrc(&Command[5]);
break;
case PLUGIN_MEMPAK: ReadFromMempak(Control, address, &Command[5]); break;
case PLUGIN_RAW: if (_Plugins->Control()->ControllerCommand) { _Plugins->Control()->ControllerCommand(Control, Command); } break;
default:
memset(&Command[5], 0, 0x20);
Command[0x25] = 0;
}
} else {
Command[1] |= 0x80;
}
#ifndef EXTERNAL_RELEASE
if (LogOptions.LogControllerPak) { LogControllerPakData("Read: After Gettting Results"); }
#endif
break;
case 0x03: //write controller pak
#ifndef EXTERNAL_RELEASE
if (LogOptions.LogControllerPak) { LogControllerPakData("Write: Before Processing"); }
#endif
if (bShowPifRamErrors())
{
if (Command[0] != 35) { DisplayError("What am I meant to do with this Controller Command"); }
if (Command[1] != 1) { DisplayError("What am I meant to do with this Controller Command"); }
}
if (Controllers[Control].Present == TRUE) {
DWORD address = ((Command[3] << 8) | Command[4]);
switch (Controllers[Control].Plugin) {
case PLUGIN_MEMPAK: WriteToMempak(Control, address, &Command[5]); break;
case PLUGIN_RAW: if (_Plugins->Control()->ControllerCommand) { _Plugins->Control()->ControllerCommand(Control, Command); } break;
case PLUGIN_RUMBLE_PAK:
if ((address & 0xFFE0) == 0xC000 && _Plugins->Control()->RumbleCommand != NULL) {
_Plugins->Control()->RumbleCommand(Control, *(BOOL *)(&Command[5]));
}
default:
Command[0x25] = Mempacks_CalulateCrc(&Command[5]);
}
} else {
Command[1] |= 0x80;
}
#ifndef EXTERNAL_RELEASE
if (LogOptions.LogControllerPak) { LogControllerPakData("Write: After Processing"); }
#endif
break;
default:
if (bShowPifRamErrors()) { DisplayError("Unknown ControllerCommand %d",Command[2]); }
}
}
void CPifRam::ReadControllerCommand (int Control, BYTE * Command) {
CONTROL * Controllers = _Plugins->Control()->PluginControllers();
switch (Command[2]) {
case 0x01: // read controller
if (Controllers[Control].Present == TRUE)
{
if (bShowPifRamErrors())
{
if (Command[0] != 1) { DisplayError("What am I meant to do with this Controller Command"); }
if (Command[1] != 4) { DisplayError("What am I meant to do with this Controller Command"); }
}
*(DWORD *)&Command[3] = _BaseSystem->GetButtons(Control);
}
break;
case 0x02: //read from controller pack
if (Controllers[Control].Present == TRUE) {
switch (Controllers[Control].Plugin) {
case PLUGIN_RAW: if (_Plugins->Control()->ReadController) { _Plugins->Control()->ReadController(Control, Command); } break;
}
}
break;
case 0x03: //write controller pak
if (Controllers[Control].Present == TRUE) {
switch (Controllers[Control].Plugin) {
case PLUGIN_RAW: if (_Plugins->Control()->ReadController) { _Plugins->Control()->ReadController(Control, Command); } break;
}
}
break;
}
}
void CPifRam::LogControllerPakData (char * Description)
{
BYTE * PIF_Ram = _MMU->PifRam();
#if (!defined(EXTERNAL_RELEASE))
int count, count2;
char HexData[100], AsciiData[100], Addon[20];
LogMessage("\t%s:",Description);
LogMessage("\t------------------------------");
for (count = 0; count < 16; count ++ ) {
if ((count % 4) == 0) {
sprintf(HexData,"\0");
sprintf(AsciiData,"\0");
}
sprintf(Addon,"%02X %02X %02X %02X",
PIF_Ram[(count << 2) + 0], PIF_Ram[(count << 2) + 1],
PIF_Ram[(count << 2) + 2], PIF_Ram[(count << 2) + 3] );
strcat(HexData,Addon);
if (((count + 1) % 4) != 0) {
sprintf(Addon,"-");
strcat(HexData,Addon);
}
Addon[0] = 0;
for (count2 = 0; count2 < 4; count2++) {
if (PIF_Ram[(count << 2) + count2] < 30) {
strcat(Addon,".");
} else {
sprintf(Addon,"%s%c",Addon,PIF_Ram[(count << 2) + count2]);
}
}
strcat(AsciiData,Addon);
if (((count + 1) % 4) == 0) {
LogMessage("\t%s %s",HexData, AsciiData);
}
}
LogMessage("");
#endif
}