Pif: Changed how pif2 challenge response is written to pif

This commit is contained in:
zilmar 2013-01-06 15:17:23 +11:00
parent c9027d9956
commit 80aaed3107
1 changed files with 21 additions and 16 deletions

View File

@ -128,29 +128,34 @@ void CPifRam::PifRamRead (void)
void CPifRam::PifRamWrite (void) {
CONTROL * Controllers = g_Plugins->Control()->PluginControllers();
int Channel, CurPos;
char Challenge[30], Response[30];
Channel = 0;
int Channel = 0, CurPos;
if( m_PifRam[0x3F] > 0x1) {
switch (m_PifRam[0x3F]) {
case 0x02:
// format the 'challenge' message into 30 nibbles for X-Scale's CIC code
{
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;
}
//Calcuate the proper respone for the give challange(X-Scales algorithm)
n64_cic_nus_6105(Challenge, Response, CHALLENGE_LENGTH - 2);
// re-format the 'response' into a byte stream
for (int i = 0; i < 15; i++)
QWORD ResponseValue = 0;
m_PifRam[46] = m_PifRam[47] = 0x00;
for (int z = 8; z > 0; z--)
{
m_PifRam[48+i] = (Response[i*2] << 4) + Response[i*2+1];
ResponseValue = (ResponseValue << 8) | ((Response[(z - 1)*2] << 4) + Response[(z - 1)*2+1]);
}
*(QWORD *)&m_PifRam[48] = ResponseValue;
ResponseValue = 0;
for (int z = 7; z > 0; z--)
{
ResponseValue = (ResponseValue << 8) | ((Response[((z + 8) - 1)*2] << 4) + Response[((z + 8) - 1)*2+1]);
}
*(QWORD *)&m_PifRam[56] = ResponseValue;
}
// the last byte (2 nibbles) is always 0
m_PifRam[63] = 0;
break;
case 0x08:
m_PifRam[0x3F] = 0;