2012-12-19 09:30:18 +00:00
|
|
|
/****************************************************************************
|
|
|
|
* *
|
|
|
|
* Project 64 - A Nintendo 64 emulator. *
|
|
|
|
* http://www.pj64-emu.com/ *
|
|
|
|
* Copyright (C) 2012 Project64. All rights reserved. *
|
|
|
|
* *
|
|
|
|
* License: *
|
|
|
|
* GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
2010-06-14 21:14:58 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
|
|
|
int CPifRamSettings::m_RefCount = 0;
|
|
|
|
bool CPifRamSettings::m_bShowPifRamErrors = false;
|
|
|
|
|
|
|
|
CPifRamSettings::CPifRamSettings()
|
|
|
|
{
|
|
|
|
m_RefCount += 1;
|
|
|
|
if (m_RefCount == 1)
|
|
|
|
{
|
2012-11-17 01:02:04 +00:00
|
|
|
g_Settings->RegisterChangeCB(Debugger_ShowPifErrors,NULL,RefreshSettings);
|
2010-06-14 21:14:58 +00:00
|
|
|
RefreshSettings(NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CPifRamSettings::~CPifRamSettings()
|
|
|
|
{
|
|
|
|
m_RefCount -= 1;
|
|
|
|
if (m_RefCount == 0)
|
|
|
|
{
|
2012-11-17 01:02:04 +00:00
|
|
|
g_Settings->UnregisterChangeCB(Debugger_ShowPifErrors,NULL,RefreshSettings);
|
2010-06-14 21:14:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPifRamSettings::RefreshSettings(void *)
|
|
|
|
{
|
2012-11-17 01:02:04 +00:00
|
|
|
m_bShowPifRamErrors = g_Settings->LoadBool(Debugger_ShowPifErrors);
|
2010-06-14 21:14:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CPifRam::CPifRam( bool SavesReadOnly ) :
|
|
|
|
CEeprom(SavesReadOnly)
|
|
|
|
{
|
2011-01-02 10:40:00 +00:00
|
|
|
Reset();
|
2010-06-14 21:14:58 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 22:19:02 +00:00
|
|
|
CPifRam::~CPifRam()
|
2010-06-14 21:14:58 +00:00
|
|
|
{
|
2015-03-29 17:19:28 +00:00
|
|
|
|
2010-06-14 21:14:58 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 22:19:02 +00:00
|
|
|
void CPifRam::Reset()
|
2011-01-02 10:40:00 +00:00
|
|
|
{
|
|
|
|
memset(m_PifRam,0,sizeof(m_PifRam));
|
|
|
|
memset(m_PifRom,0,sizeof(m_PifRom));
|
|
|
|
}
|
|
|
|
|
2012-09-26 10:36:52 +00:00
|
|
|
void CPifRam::n64_cic_nus_6105(char challenge[], char respone[], int length)
|
|
|
|
{
|
|
|
|
static char lut0[0x10] = {
|
|
|
|
0x4, 0x7, 0xA, 0x7, 0xE, 0x5, 0xE, 0x1,
|
|
|
|
0xC, 0xF, 0x8, 0xF, 0x6, 0x3, 0x6, 0x9
|
|
|
|
};
|
|
|
|
static char lut1[0x10] = {
|
|
|
|
0x4, 0x1, 0xA, 0x7, 0xE, 0x5, 0xE, 0x1,
|
|
|
|
0xC, 0x9, 0x8, 0x5, 0x6, 0x3, 0xC, 0x9
|
|
|
|
};
|
|
|
|
char key, *lut;
|
|
|
|
int i, sgn, mag, mod;
|
|
|
|
|
2015-03-29 17:19:28 +00:00
|
|
|
for (key = 0xB, lut = lut0, i = 0; i < length; i++)
|
|
|
|
{
|
2012-09-26 10:36:52 +00:00
|
|
|
respone[i] = (key + 5 * challenge[i]) & 0xF;
|
|
|
|
key = lut[respone[i]];
|
|
|
|
sgn = (respone[i] >> 3) & 0x1;
|
|
|
|
mag = ((sgn == 1) ? ~respone[i] : respone[i]) & 0x7;
|
|
|
|
mod = (mag % 3 == 1) ? sgn : 1 - sgn;
|
|
|
|
if (lut == lut1 && (respone[i] == 0x1 || respone[i] == 0x9))
|
2015-03-29 17:19:28 +00:00
|
|
|
{
|
2012-09-26 10:36:52 +00:00
|
|
|
mod = 1;
|
2015-03-29 17:19:28 +00:00
|
|
|
}
|
2012-09-26 10:36:52 +00:00
|
|
|
if (lut == lut1 && (respone[i] == 0xB || respone[i] == 0xE))
|
2015-03-29 17:19:28 +00:00
|
|
|
{
|
2012-09-26 10:36:52 +00:00
|
|
|
mod = 0;
|
2015-03-29 17:19:28 +00:00
|
|
|
}
|
2012-09-26 10:36:52 +00:00
|
|
|
lut = (mod == 1) ? lut1 : lut0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-28 22:19:02 +00:00
|
|
|
void CPifRam::PifRamRead()
|
2010-06-14 21:14:58 +00:00
|
|
|
{
|
|
|
|
if (m_PifRam[0x3F] == 0x2)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-17 02:20:21 +00:00
|
|
|
CONTROL * Controllers = g_Plugins->Control()->PluginControllers();
|
2010-06-14 21:14:58 +00:00
|
|
|
|
|
|
|
int Channel = 0;
|
|
|
|
for (int CurPos = 0; CurPos < 0x40; CurPos ++)
|
|
|
|
{
|
2015-03-29 17:19:28 +00:00
|
|
|
switch (m_PifRam[CurPos])
|
|
|
|
{
|
2010-06-14 21:14:58 +00:00
|
|
|
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)
|
|
|
|
{
|
2015-03-29 17:19:28 +00:00
|
|
|
if (Channel < 4)
|
|
|
|
{
|
|
|
|
if (Controllers[Channel].Present && Controllers[Channel].RawData)
|
|
|
|
{
|
|
|
|
if (g_Plugins->Control()->ReadController)
|
|
|
|
{
|
|
|
|
g_Plugins->Control()->ReadController(Channel,&m_PifRam[CurPos]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-06-14 21:14:58 +00:00
|
|
|
ReadControllerCommand(Channel,&m_PifRam[CurPos]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CurPos += m_PifRam[CurPos] + (m_PifRam[CurPos + 1] & 0x3F) + 1;
|
|
|
|
Channel += 1;
|
2015-03-29 17:19:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (bShowPifRamErrors())
|
|
|
|
{
|
2015-10-25 11:40:21 +00:00
|
|
|
g_Notify->DisplayError(stdstr_f("Unknown Command in PifRamRead(%X)",m_PifRam[CurPos]).ToUTF16().c_str());
|
2015-03-29 17:19:28 +00:00
|
|
|
}
|
2010-06-14 21:14:58 +00:00
|
|
|
CurPos = 0x40;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2010-09-22 21:43:42 +00:00
|
|
|
}
|
2015-03-29 17:19:28 +00:00
|
|
|
if (g_Plugins->Control()->ReadController)
|
|
|
|
{
|
|
|
|
g_Plugins->Control()->ReadController(-1,NULL);
|
|
|
|
}
|
2010-06-14 21:14:58 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 22:19:02 +00:00
|
|
|
void CPifRam::PifRamWrite()
|
2015-03-29 17:19:28 +00:00
|
|
|
{
|
2012-11-17 02:20:21 +00:00
|
|
|
CONTROL * Controllers = g_Plugins->Control()->PluginControllers();
|
2013-01-06 04:17:23 +00:00
|
|
|
int Channel = 0, CurPos;
|
2010-06-14 21:14:58 +00:00
|
|
|
|
2015-03-29 17:19:28 +00:00
|
|
|
if ( m_PifRam[0x3F] > 0x1)
|
|
|
|
{
|
|
|
|
switch (m_PifRam[0x3F])
|
|
|
|
{
|
2012-09-26 10:26:17 +00:00
|
|
|
case 0x02:
|
|
|
|
// format the 'challenge' message into 30 nibbles for X-Scale's CIC code
|
|
|
|
{
|
2013-01-06 04:17:23 +00:00
|
|
|
char Challenge[30], Response[30];
|
|
|
|
for (int i = 0; i < 15; i++)
|
|
|
|
{
|
|
|
|
Challenge[i*2] = (m_PifRam[48+i] >> 4) & 0x0f;
|
|
|
|
Challenge[i*2+1] = m_PifRam[48+i] & 0x0f;
|
|
|
|
}
|
|
|
|
n64_cic_nus_6105(Challenge, Response, CHALLENGE_LENGTH - 2);
|
|
|
|
QWORD ResponseValue = 0;
|
|
|
|
m_PifRam[46] = m_PifRam[47] = 0x00;
|
|
|
|
for (int z = 8; z > 0; z--)
|
|
|
|
{
|
|
|
|
ResponseValue = (ResponseValue << 8) | ((Response[(z - 1)*2] << 4) + Response[(z - 1)*2+1]);
|
|
|
|
}
|
2015-09-23 06:57:33 +00:00
|
|
|
std::memcpy(&m_PifRam[48], &ResponseValue, sizeof(QWORD));
|
2013-01-06 04:17:23 +00:00
|
|
|
ResponseValue = 0;
|
|
|
|
for (int z = 7; z > 0; z--)
|
|
|
|
{
|
|
|
|
ResponseValue = (ResponseValue << 8) | ((Response[((z + 8) - 1)*2] << 4) + Response[((z + 8) - 1)*2+1]);
|
|
|
|
}
|
2015-09-23 06:57:33 +00:00
|
|
|
std::memcpy(&m_PifRam[56], &ResponseValue, sizeof(QWORD));
|
2012-09-26 10:26:17 +00:00
|
|
|
}
|
|
|
|
break;
|
2010-06-14 21:14:58 +00:00
|
|
|
case 0x08:
|
|
|
|
m_PifRam[0x3F] = 0;
|
2012-11-17 02:18:14 +00:00
|
|
|
g_Reg->MI_INTR_REG |= MI_INTR_SI;
|
|
|
|
g_Reg->SI_STATUS_REG |= SI_STATUS_INTERRUPT;
|
|
|
|
g_Reg->CheckInterrupts();
|
2010-06-14 21:14:58 +00:00
|
|
|
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:
|
2015-03-29 17:19:28 +00:00
|
|
|
if (bShowPifRamErrors())
|
|
|
|
{
|
2015-10-25 11:40:21 +00:00
|
|
|
g_Notify->DisplayError(stdstr_f("Unkown PifRam control: %d",m_PifRam[0x3F]).ToUTF16().c_str());
|
2015-03-29 17:19:28 +00:00
|
|
|
}
|
2010-06-14 21:14:58 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-29 17:19:28 +00:00
|
|
|
for (CurPos = 0; CurPos < 0x40; CurPos++)
|
|
|
|
{
|
2015-03-29 21:58:51 +00:00
|
|
|
switch (m_PifRam[CurPos])
|
2015-03-29 17:19:28 +00:00
|
|
|
{
|
2010-06-14 21:14:58 +00:00
|
|
|
case 0x00:
|
|
|
|
Channel += 1;
|
2015-03-29 17:19:28 +00:00
|
|
|
if (Channel > 6)
|
|
|
|
{
|
|
|
|
CurPos = 0x40;
|
|
|
|
}
|
2010-06-14 21:14:58 +00:00
|
|
|
break;
|
|
|
|
case 0xFE: CurPos = 0x40; break;
|
|
|
|
case 0xFF: break;
|
|
|
|
case 0xB4: case 0x56: case 0xB8: break; /* ??? */
|
|
|
|
default:
|
2015-03-29 17:19:28 +00:00
|
|
|
if ((m_PifRam[CurPos] & 0xC0) == 0)
|
|
|
|
{
|
|
|
|
if (Channel < 4)
|
|
|
|
{
|
|
|
|
if (Controllers[Channel].Present && Controllers[Channel].RawData)
|
|
|
|
{
|
|
|
|
if (g_Plugins->Control()->ControllerCommand)
|
|
|
|
{
|
|
|
|
g_Plugins->Control()->ControllerCommand(Channel,&m_PifRam[CurPos]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-06-14 21:14:58 +00:00
|
|
|
ProcessControllerCommand(Channel,&m_PifRam[CurPos]);
|
|
|
|
}
|
2015-03-29 17:19:28 +00:00
|
|
|
}
|
|
|
|
else if (Channel == 4)
|
|
|
|
{
|
2010-06-14 21:14:58 +00:00
|
|
|
EepromCommand(&m_PifRam[CurPos]);
|
2015-03-29 17:19:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-06-14 21:14:58 +00:00
|
|
|
if (bShowPifRamErrors())
|
|
|
|
{
|
2015-03-04 09:36:08 +00:00
|
|
|
g_Notify->DisplayError(L"Command on channel 5?");
|
2010-06-14 21:14:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
CurPos += m_PifRam[CurPos] + (m_PifRam[CurPos + 1] & 0x3F) + 1;
|
|
|
|
Channel += 1;
|
2015-03-29 17:19:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (bShowPifRamErrors())
|
|
|
|
{
|
2015-10-25 11:40:21 +00:00
|
|
|
g_Notify->DisplayError(stdstr_f("Unknown Command in PifRamWrite(%X)",m_PifRam[CurPos]).ToUTF16().c_str());
|
2015-03-29 17:19:28 +00:00
|
|
|
}
|
2010-06-14 21:14:58 +00:00
|
|
|
CurPos = 0x40;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_PifRam[0x3F] = 0;
|
2015-03-29 17:19:28 +00:00
|
|
|
if (g_Plugins->Control()->ControllerCommand)
|
|
|
|
{
|
|
|
|
g_Plugins->Control()->ControllerCommand(-1,NULL);
|
|
|
|
}
|
2010-06-14 21:14:58 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 22:19:02 +00:00
|
|
|
void CPifRam::SI_DMA_READ()
|
2010-06-14 21:14:58 +00:00
|
|
|
{
|
|
|
|
BYTE * PifRamPos = m_PifRam;
|
2012-11-17 01:18:00 +00:00
|
|
|
BYTE * RDRAM = g_MMU->Rdram();
|
2010-06-14 21:14:58 +00:00
|
|
|
|
2012-11-17 02:18:14 +00:00
|
|
|
DWORD & SI_DRAM_ADDR_REG = g_Reg->SI_DRAM_ADDR_REG;
|
2012-11-29 11:23:35 +00:00
|
|
|
if ((int)SI_DRAM_ADDR_REG > (int)g_System->RdramSize())
|
2010-06-14 21:14:58 +00:00
|
|
|
{
|
|
|
|
if (bShowPifRamErrors())
|
|
|
|
{
|
2015-03-04 09:36:08 +00:00
|
|
|
g_Notify->DisplayError(L"SI DMA\nSI_DRAM_ADDR_REG not in RDRam space");
|
2010-06-14 21:14:58 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PifRamRead();
|
|
|
|
SI_DRAM_ADDR_REG &= 0xFFFFFFF8;
|
2015-03-29 17:19:28 +00:00
|
|
|
if ((int)SI_DRAM_ADDR_REG < 0)
|
|
|
|
{
|
2010-06-14 21:14:58 +00:00
|
|
|
int count, RdramPos;
|
|
|
|
|
|
|
|
RdramPos = (int)SI_DRAM_ADDR_REG;
|
2015-03-29 17:19:28 +00:00
|
|
|
for (count = 0; count < 0x40; count++, RdramPos++)
|
|
|
|
{
|
|
|
|
if (RdramPos < 0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2015-10-26 17:09:38 +00:00
|
|
|
RDRAM[RdramPos ^ 3] = m_PifRam[count];
|
2010-06-14 21:14:58 +00:00
|
|
|
}
|
2015-03-29 17:19:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-10-26 17:09:38 +00:00
|
|
|
for (size_t i = 0; i < 64; i++)
|
2015-03-29 17:19:28 +00:00
|
|
|
{
|
2015-10-26 17:09:38 +00:00
|
|
|
RDRAM[(SI_DRAM_ADDR_REG + i) ^ 3] = PifRamPos[i];
|
2010-06-14 21:14:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-08 09:17:13 +00:00
|
|
|
if (g_LogOptions.LogPRDMAMemStores)
|
2015-03-29 17:19:28 +00:00
|
|
|
{
|
2010-06-14 21:14:58 +00:00
|
|
|
int count;
|
|
|
|
char HexData[100], AsciiData[100], Addon[20];
|
|
|
|
LogMessage("\tData DMAed to RDRAM:");
|
|
|
|
LogMessage("\t--------------------");
|
2015-03-29 17:19:28 +00:00
|
|
|
for (count = 0; count < 16; count ++ )
|
|
|
|
{
|
|
|
|
if ((count % 4) == 0)
|
|
|
|
{
|
2010-06-14 21:14:58 +00:00
|
|
|
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);
|
2015-03-29 17:19:28 +00:00
|
|
|
if (((count + 1) % 4) != 0)
|
|
|
|
{
|
2010-06-14 21:14:58 +00:00
|
|
|
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);
|
|
|
|
|
2015-03-29 17:19:28 +00:00
|
|
|
if (((count + 1) % 4) == 0)
|
|
|
|
{
|
2010-06-14 21:14:58 +00:00
|
|
|
LogMessage("\t%s %s",HexData, AsciiData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LogMessage("");
|
|
|
|
}
|
|
|
|
|
2015-03-29 17:19:28 +00:00
|
|
|
if (g_System->bDelaySI())
|
|
|
|
{
|
2012-11-17 02:31:46 +00:00
|
|
|
g_SystemTimer->SetTimer(CSystemTimer::SiTimer,0x900,false);
|
2015-03-29 17:19:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-17 02:18:14 +00:00
|
|
|
g_Reg->MI_INTR_REG |= MI_INTR_SI;
|
|
|
|
g_Reg->SI_STATUS_REG |= SI_STATUS_INTERRUPT;
|
|
|
|
g_Reg->CheckInterrupts();
|
2010-06-14 21:14:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-28 22:19:02 +00:00
|
|
|
void CPifRam::SI_DMA_WRITE()
|
2010-06-14 21:14:58 +00:00
|
|
|
{
|
|
|
|
BYTE * PifRamPos = m_PifRam;
|
|
|
|
|
2012-11-17 02:18:14 +00:00
|
|
|
DWORD & SI_DRAM_ADDR_REG = g_Reg->SI_DRAM_ADDR_REG;
|
2012-11-29 11:23:35 +00:00
|
|
|
if ((int)SI_DRAM_ADDR_REG > (int)g_System->RdramSize())
|
2010-06-14 21:14:58 +00:00
|
|
|
{
|
|
|
|
if (bShowPifRamErrors())
|
|
|
|
{
|
2015-03-04 09:36:08 +00:00
|
|
|
g_Notify->DisplayError(L"SI DMA\nSI_DRAM_ADDR_REG not in RDRam space");
|
2010-06-14 21:14:58 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SI_DRAM_ADDR_REG &= 0xFFFFFFF8;
|
2012-11-17 01:18:00 +00:00
|
|
|
BYTE * RDRAM = g_MMU->Rdram();
|
2010-06-14 21:14:58 +00:00
|
|
|
|
2015-03-29 17:19:28 +00:00
|
|
|
if ((int)SI_DRAM_ADDR_REG < 0)
|
|
|
|
{
|
2015-09-23 06:57:33 +00:00
|
|
|
int RdramPos = (int)SI_DRAM_ADDR_REG;
|
2010-06-14 21:14:58 +00:00
|
|
|
|
2015-09-23 06:57:33 +00:00
|
|
|
for (int count = 0; count < 0x40; count++, RdramPos++)
|
2015-03-29 17:19:28 +00:00
|
|
|
{
|
|
|
|
if (RdramPos < 0)
|
|
|
|
{
|
|
|
|
m_PifRam[count] = 0; continue;
|
|
|
|
}
|
2010-06-14 21:14:58 +00:00
|
|
|
m_PifRam[count] = RDRAM[RdramPos ^3];
|
|
|
|
}
|
2015-03-29 17:19:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-10-26 17:09:38 +00:00
|
|
|
for (size_t i = 0; i < 64; i++)
|
2015-03-29 17:19:28 +00:00
|
|
|
{
|
2015-10-26 17:09:38 +00:00
|
|
|
PifRamPos[i] = RDRAM[(SI_DRAM_ADDR_REG + i) ^ 3];
|
2010-06-14 21:14:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-08 09:17:13 +00:00
|
|
|
if (g_LogOptions.LogPRDMAMemLoads)
|
2015-03-29 17:19:28 +00:00
|
|
|
{
|
2010-06-14 21:14:58 +00:00
|
|
|
int count;
|
|
|
|
char HexData[100], AsciiData[100], Addon[20];
|
|
|
|
LogMessage("");
|
|
|
|
LogMessage("\tData DMAed to the Pif Ram:");
|
|
|
|
LogMessage("\t--------------------------");
|
2015-03-29 17:19:28 +00:00
|
|
|
for (count = 0; count < 16; count ++ )
|
|
|
|
{
|
|
|
|
if ((count % 4) == 0)
|
|
|
|
{
|
2010-06-14 21:14:58 +00:00
|
|
|
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);
|
2015-03-29 17:19:28 +00:00
|
|
|
if (((count + 1) % 4) != 0)
|
|
|
|
{
|
2010-06-14 21:14:58 +00:00
|
|
|
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);
|
|
|
|
|
2015-03-29 17:19:28 +00:00
|
|
|
if (((count + 1) % 4) == 0)
|
|
|
|
{
|
2010-06-14 21:14:58 +00:00
|
|
|
LogMessage("\t%s %s",HexData, AsciiData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LogMessage("");
|
|
|
|
}
|
|
|
|
|
|
|
|
PifRamWrite();
|
|
|
|
|
2015-03-29 17:19:28 +00:00
|
|
|
if (g_System->bDelaySI())
|
|
|
|
{
|
2012-11-17 02:31:46 +00:00
|
|
|
g_SystemTimer->SetTimer(CSystemTimer::SiTimer,0x900,false);
|
2015-03-29 17:19:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-17 02:18:14 +00:00
|
|
|
g_Reg->MI_INTR_REG |= MI_INTR_SI;
|
|
|
|
g_Reg->SI_STATUS_REG |= SI_STATUS_INTERRUPT;
|
|
|
|
g_Reg->CheckInterrupts();
|
2010-06-14 21:14:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPifRam::ProcessControllerCommand ( int Control, BYTE * Command)
|
|
|
|
{
|
2012-11-17 02:20:21 +00:00
|
|
|
CONTROL * Controllers = g_Plugins->Control()->PluginControllers();
|
2010-06-14 21:14:58 +00:00
|
|
|
|
2015-03-29 17:19:28 +00:00
|
|
|
switch (Command[2])
|
|
|
|
{
|
2010-06-14 21:14:58 +00:00
|
|
|
case 0x00: // check
|
|
|
|
case 0xFF: // reset & check ?
|
2015-03-29 17:19:28 +00:00
|
|
|
if ((Command[1] & 0x80) != 0)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2010-06-14 21:14:58 +00:00
|
|
|
if (bShowPifRamErrors())
|
|
|
|
{
|
2015-03-29 17:19:28 +00:00
|
|
|
if (Command[0] != 1)
|
|
|
|
{
|
|
|
|
g_Notify->DisplayError(L"What am I meant to do with this Controller Command");
|
|
|
|
}
|
|
|
|
if (Command[1] != 3)
|
|
|
|
{
|
|
|
|
g_Notify->DisplayError(L"What am I meant to do with this Controller Command");
|
|
|
|
}
|
2010-06-14 21:14:58 +00:00
|
|
|
}
|
2015-03-29 17:19:28 +00:00
|
|
|
if (Controllers[Control].Present == TRUE)
|
|
|
|
{
|
2010-06-14 21:14:58 +00:00
|
|
|
Command[3] = 0x05;
|
|
|
|
Command[4] = 0x00;
|
2015-03-29 17:19:28 +00:00
|
|
|
switch ( Controllers[Control].Plugin)
|
|
|
|
{
|
2015-05-18 02:20:15 +00:00
|
|
|
case PLUGIN_TANSFER_PAK:
|
|
|
|
case PLUGIN_RUMBLE_PAK:
|
|
|
|
case PLUGIN_MEMPAK:
|
|
|
|
case PLUGIN_RAW:
|
|
|
|
Command[5] = 1; break;
|
2010-06-14 21:14:58 +00:00
|
|
|
default: Command[5] = 0; break;
|
|
|
|
}
|
2015-03-29 17:19:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-06-14 21:14:58 +00:00
|
|
|
Command[1] |= 0x80;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x01: // read controller
|
|
|
|
if (bShowPifRamErrors())
|
|
|
|
{
|
2015-03-29 17:19:28 +00:00
|
|
|
if (Command[0] != 1)
|
|
|
|
{
|
|
|
|
g_Notify->DisplayError(L"What am I meant to do with this Controller Command");
|
|
|
|
}
|
|
|
|
if (Command[1] != 4)
|
|
|
|
{
|
|
|
|
g_Notify->DisplayError(L"What am I meant to do with this Controller Command");
|
|
|
|
}
|
2010-06-14 21:14:58 +00:00
|
|
|
}
|
2015-03-29 17:19:28 +00:00
|
|
|
if (Controllers[Control].Present == FALSE)
|
|
|
|
{
|
2010-06-14 21:14:58 +00:00
|
|
|
Command[1] |= 0x80;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x02: //read from controller pack
|
2015-11-08 09:17:13 +00:00
|
|
|
if (g_LogOptions.LogControllerPak)
|
2015-03-29 17:19:28 +00:00
|
|
|
{
|
|
|
|
LogControllerPakData("Read: Before Gettting Results");
|
|
|
|
}
|
2010-06-14 21:14:58 +00:00
|
|
|
if (bShowPifRamErrors())
|
|
|
|
{
|
2015-03-29 17:19:28 +00:00
|
|
|
if (Command[0] != 3)
|
|
|
|
{
|
|
|
|
g_Notify->DisplayError(L"What am I meant to do with this Controller Command");
|
|
|
|
}
|
|
|
|
if (Command[1] != 33)
|
|
|
|
{
|
|
|
|
g_Notify->DisplayError(L"What am I meant to do with this Controller Command");
|
|
|
|
}
|
2010-06-14 21:14:58 +00:00
|
|
|
}
|
2015-03-29 17:19:28 +00:00
|
|
|
if (Controllers[Control].Present == TRUE)
|
|
|
|
{
|
|
|
|
switch (Controllers[Control].Plugin)
|
|
|
|
{
|
2015-05-18 02:20:15 +00:00
|
|
|
case PLUGIN_RUMBLE_PAK: Rumblepak::ReadFrom(Command); break;
|
|
|
|
case PLUGIN_MEMPAK: Mempak::ReadFrom(Control, Command); break;
|
|
|
|
case PLUGIN_TANSFER_PAK: /* TODO */; break;
|
2012-11-17 02:20:21 +00:00
|
|
|
case PLUGIN_RAW: if (g_Plugins->Control()->ControllerCommand) { g_Plugins->Control()->ControllerCommand(Control, Command); } break;
|
2010-06-14 21:14:58 +00:00
|
|
|
default:
|
|
|
|
memset(&Command[5], 0, 0x20);
|
2015-05-18 02:20:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Controllers[Control].Plugin != PLUGIN_RAW)
|
|
|
|
{
|
|
|
|
Command[0x25] = Mempak::CalculateCrc(&Command[5]);
|
2010-06-14 21:14:58 +00:00
|
|
|
}
|
2015-03-29 17:19:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-06-14 21:14:58 +00:00
|
|
|
Command[1] |= 0x80;
|
|
|
|
}
|
2015-11-08 09:17:13 +00:00
|
|
|
if (g_LogOptions.LogControllerPak)
|
2015-03-29 17:19:28 +00:00
|
|
|
{
|
|
|
|
LogControllerPakData("Read: After Gettting Results");
|
|
|
|
}
|
2010-06-14 21:14:58 +00:00
|
|
|
break;
|
|
|
|
case 0x03: //write controller pak
|
2015-11-08 09:17:13 +00:00
|
|
|
if (g_LogOptions.LogControllerPak)
|
2015-03-29 17:19:28 +00:00
|
|
|
{
|
|
|
|
LogControllerPakData("Write: Before Processing");
|
|
|
|
}
|
2010-06-14 21:14:58 +00:00
|
|
|
if (bShowPifRamErrors())
|
|
|
|
{
|
2015-03-29 17:19:28 +00:00
|
|
|
if (Command[0] != 35)
|
|
|
|
{
|
|
|
|
g_Notify->DisplayError(L"What am I meant to do with this Controller Command");
|
|
|
|
}
|
|
|
|
if (Command[1] != 1)
|
|
|
|
{
|
|
|
|
g_Notify->DisplayError(L"What am I meant to do with this Controller Command");
|
|
|
|
}
|
2010-06-14 21:14:58 +00:00
|
|
|
}
|
2015-03-29 17:19:28 +00:00
|
|
|
if (Controllers[Control].Present == TRUE)
|
|
|
|
{
|
|
|
|
switch (Controllers[Control].Plugin)
|
|
|
|
{
|
2015-05-18 02:20:15 +00:00
|
|
|
case PLUGIN_MEMPAK: Mempak::WriteTo(Control, Command); break;
|
|
|
|
case PLUGIN_RUMBLE_PAK: Rumblepak::WriteTo(Control, Command); break;
|
|
|
|
case PLUGIN_TANSFER_PAK: /* TODO */; break;
|
2012-11-17 02:20:21 +00:00
|
|
|
case PLUGIN_RAW: if (g_Plugins->Control()->ControllerCommand) { g_Plugins->Control()->ControllerCommand(Control, Command); } break;
|
2015-05-18 02:20:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Controllers[Control].Plugin != PLUGIN_RAW)
|
|
|
|
{
|
2012-10-01 15:32:32 +00:00
|
|
|
Command[0x25] = Mempak::CalculateCrc(&Command[5]);
|
2010-06-14 21:14:58 +00:00
|
|
|
}
|
2015-03-29 17:19:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-06-14 21:14:58 +00:00
|
|
|
Command[1] |= 0x80;
|
|
|
|
}
|
2015-11-08 09:17:13 +00:00
|
|
|
if (g_LogOptions.LogControllerPak)
|
2015-03-29 17:19:28 +00:00
|
|
|
{
|
|
|
|
LogControllerPakData("Write: After Processing");
|
|
|
|
}
|
2010-06-14 21:14:58 +00:00
|
|
|
break;
|
|
|
|
default:
|
2015-03-29 17:19:28 +00:00
|
|
|
if (bShowPifRamErrors())
|
|
|
|
{
|
2015-10-25 11:40:21 +00:00
|
|
|
g_Notify->DisplayError(stdstr_f("Unknown ControllerCommand %d",Command[2]).ToUTF16().c_str());
|
2015-03-29 17:19:28 +00:00
|
|
|
}
|
2010-06-14 21:14:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPifRam::ReadControllerCommand (int Control, BYTE * Command) {
|
2012-11-17 02:20:21 +00:00
|
|
|
CONTROL * Controllers = g_Plugins->Control()->PluginControllers();
|
2010-06-14 21:14:58 +00:00
|
|
|
|
2015-03-29 17:19:28 +00:00
|
|
|
switch (Command[2])
|
|
|
|
{
|
2010-06-14 21:14:58 +00:00
|
|
|
case 0x01: // read controller
|
|
|
|
if (Controllers[Control].Present == TRUE)
|
|
|
|
{
|
|
|
|
if (bShowPifRamErrors())
|
|
|
|
{
|
2015-03-04 09:36:08 +00:00
|
|
|
if (Command[0] != 1) { g_Notify->DisplayError(L"What am I meant to do with this Controller Command"); }
|
|
|
|
if (Command[1] != 4) { g_Notify->DisplayError(L"What am I meant to do with this Controller Command"); }
|
2010-06-14 21:14:58 +00:00
|
|
|
}
|
2015-09-23 06:57:33 +00:00
|
|
|
|
|
|
|
const DWORD buttons = g_BaseSystem->GetButtons(Control);
|
|
|
|
std::memcpy(&Command[3], &buttons, sizeof(DWORD));
|
2010-06-14 21:14:58 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x02: //read from controller pack
|
2015-03-29 17:19:28 +00:00
|
|
|
if (Controllers[Control].Present == TRUE)
|
|
|
|
{
|
|
|
|
switch (Controllers[Control].Plugin)
|
|
|
|
{
|
2012-11-17 02:20:21 +00:00
|
|
|
case PLUGIN_RAW: if (g_Plugins->Control()->ReadController) { g_Plugins->Control()->ReadController(Control, Command); } break;
|
2010-06-14 21:14:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x03: //write controller pak
|
2015-03-29 17:19:28 +00:00
|
|
|
if (Controllers[Control].Present == TRUE)
|
|
|
|
{
|
|
|
|
switch (Controllers[Control].Plugin)
|
|
|
|
{
|
2012-11-17 02:20:21 +00:00
|
|
|
case PLUGIN_RAW: if (g_Plugins->Control()->ReadController) { g_Plugins->Control()->ReadController(Control, Command); } break;
|
2010-06-14 21:14:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPifRam::LogControllerPakData (char * Description)
|
|
|
|
{
|
2012-11-17 01:18:00 +00:00
|
|
|
BYTE * PIF_Ram = g_MMU->PifRam();
|
2010-06-14 21:14:58 +00:00
|
|
|
|
|
|
|
int count, count2;
|
|
|
|
char HexData[100], AsciiData[100], Addon[20];
|
|
|
|
LogMessage("\t%s:",Description);
|
|
|
|
LogMessage("\t------------------------------");
|
2015-03-29 17:19:28 +00:00
|
|
|
for (count = 0; count < 16; count ++ )
|
|
|
|
{
|
|
|
|
if ((count % 4) == 0)
|
|
|
|
{
|
2010-06-14 21:14:58 +00:00
|
|
|
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);
|
2015-03-29 17:19:28 +00:00
|
|
|
if (((count + 1) % 4) != 0)
|
|
|
|
{
|
2010-06-14 21:14:58 +00:00
|
|
|
sprintf(Addon,"-");
|
|
|
|
strcat(HexData,Addon);
|
|
|
|
}
|
|
|
|
|
|
|
|
Addon[0] = 0;
|
2015-03-29 17:19:28 +00:00
|
|
|
for (count2 = 0; count2 < 4; count2++)
|
|
|
|
{
|
|
|
|
if (PIF_Ram[(count << 2) + count2] < 30)
|
|
|
|
{
|
2010-06-14 21:14:58 +00:00
|
|
|
strcat(Addon,".");
|
2015-03-29 17:19:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-06-14 21:14:58 +00:00
|
|
|
sprintf(Addon,"%s%c",Addon,PIF_Ram[(count << 2) + count2]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
strcat(AsciiData,Addon);
|
|
|
|
|
2015-03-29 17:19:28 +00:00
|
|
|
if (((count + 1) % 4) == 0)
|
|
|
|
{
|
2010-06-14 21:14:58 +00:00
|
|
|
LogMessage("\t%s %s",HexData, AsciiData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LogMessage("");
|
2015-01-31 19:27:27 +00:00
|
|
|
}
|