2010-06-14 21:14:58 +00:00
|
|
|
#include "stdafx.h"
|
2015-12-21 20:35:11 +00:00
|
|
|
#include <stdio.h>
|
2015-12-21 20:34:48 +00:00
|
|
|
|
2016-01-13 11:15:30 +00:00
|
|
|
#include <Project64-core/N64System/Mips/PifRam.h>
|
2015-12-06 09:59:58 +00:00
|
|
|
#include <Project64-core/N64System/SystemGlobals.h>
|
|
|
|
#include <Project64-core/Plugins/ControllerPlugin.h>
|
|
|
|
#include <Project64-core/N64System/Mips/RegisterClass.h>
|
2015-12-21 07:35:22 +00:00
|
|
|
#include <Project64-core/N64System/Mips/MemoryVirtualMem.h>
|
2015-12-06 09:59:58 +00:00
|
|
|
#include <Project64-core/N64System/N64Class.h>
|
2016-01-29 11:17:59 +00:00
|
|
|
#include <Project64-core/N64System/Mips/Transferpak.h>
|
2015-12-06 09:59:58 +00:00
|
|
|
#include <Project64-core/N64System/Mips/Rumblepak.h>
|
2017-07-30 16:32:50 +00:00
|
|
|
#include <Project64-core/N64System/Mips/Mempak.h>
|
2015-12-06 09:59:58 +00:00
|
|
|
#include <Project64-core/Logging.h>
|
2010-06-14 21:14:58 +00:00
|
|
|
|
2015-11-13 06:34:57 +00:00
|
|
|
CPifRam::CPifRam(bool SavesReadOnly) :
|
2018-02-16 05:38:00 +00:00
|
|
|
CEeprom(SavesReadOnly)
|
2010-06-14 21:14:58 +00:00
|
|
|
{
|
2015-11-13 06:34:57 +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-04-28 22:19:02 +00:00
|
|
|
void CPifRam::Reset()
|
2011-01-02 10:40:00 +00:00
|
|
|
{
|
2015-11-13 06:34:57 +00:00
|
|
|
memset(m_PifRam, 0, sizeof(m_PifRam));
|
|
|
|
memset(m_PifRom, 0, sizeof(m_PifRom));
|
2011-01-02 10:40:00 +00:00
|
|
|
}
|
|
|
|
|
2016-01-18 08:54:39 +00:00
|
|
|
void CPifRam::n64_cic_nus_6105(char challenge[], char respone[], int32_t length)
|
2012-09-26 10:36:52 +00:00
|
|
|
{
|
2015-11-13 06:34:57 +00:00
|
|
|
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;
|
2016-01-18 08:54:39 +00:00
|
|
|
int32_t i, sgn, mag, mod;
|
2015-11-13 06:34:57 +00:00
|
|
|
|
|
|
|
for (key = 0xB, lut = lut0, i = 0; i < length; i++)
|
|
|
|
{
|
|
|
|
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))
|
|
|
|
{
|
|
|
|
mod = 1;
|
|
|
|
}
|
|
|
|
if (lut == lut1 && (respone[i] == 0xB || respone[i] == 0xE))
|
|
|
|
{
|
|
|
|
mod = 0;
|
|
|
|
}
|
|
|
|
lut = (mod == 1) ? lut1 : lut0;
|
|
|
|
}
|
2012-09-26 10:36:52 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 22:19:02 +00:00
|
|
|
void CPifRam::PifRamRead()
|
2010-06-14 21:14:58 +00:00
|
|
|
{
|
2015-11-13 06:34:57 +00:00
|
|
|
if (m_PifRam[0x3F] == 0x2)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CONTROL * Controllers = g_Plugins->Control()->PluginControllers();
|
|
|
|
|
2016-01-18 08:54:39 +00:00
|
|
|
int32_t Channel = 0;
|
|
|
|
for (int32_t CurPos = 0; CurPos < 0x40; CurPos++)
|
2015-11-13 06:34:57 +00:00
|
|
|
{
|
|
|
|
switch (m_PifRam[CurPos])
|
|
|
|
{
|
|
|
|
case 0x00:
|
|
|
|
Channel += 1;
|
|
|
|
if (Channel > 6)
|
|
|
|
{
|
|
|
|
CurPos = 0x40;
|
|
|
|
}
|
|
|
|
break;
|
2016-05-22 11:41:21 +00:00
|
|
|
case 0xFD: CurPos = 0x40; break;
|
2015-11-13 06:34:57 +00:00
|
|
|
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 (g_Plugins->Control()->ReadController)
|
|
|
|
{
|
|
|
|
g_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
|
|
|
|
{
|
2016-05-14 01:56:18 +00:00
|
|
|
if (CurPos != 0x27 && bShowPifRamErrors())
|
2015-11-13 06:34:57 +00:00
|
|
|
{
|
2015-12-23 20:04:36 +00:00
|
|
|
g_Notify->DisplayError(stdstr_f("Unknown Command in PifRamRead(%X)", m_PifRam[CurPos]).c_str());
|
2015-11-13 06:34:57 +00:00
|
|
|
}
|
|
|
|
CurPos = 0x40;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (g_Plugins->Control()->ReadController)
|
|
|
|
{
|
2021-04-12 11:35:39 +00:00
|
|
|
g_Plugins->Control()->ReadController(-1, nullptr);
|
2015-11-13 06:34:57 +00:00
|
|
|
}
|
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
|
|
|
{
|
2015-11-13 06:34:57 +00:00
|
|
|
CONTROL * Controllers = g_Plugins->Control()->PluginControllers();
|
2016-01-18 08:54:39 +00:00
|
|
|
int32_t Channel = 0, CurPos;
|
2015-11-13 06:34:57 +00:00
|
|
|
|
|
|
|
if (m_PifRam[0x3F] > 0x1)
|
|
|
|
{
|
|
|
|
switch (m_PifRam[0x3F])
|
|
|
|
{
|
|
|
|
case 0x02:
|
|
|
|
// format the 'challenge' message into 30 nibbles for X-Scale's CIC code
|
2016-07-09 11:03:10 +00:00
|
|
|
{
|
|
|
|
char Challenge[30], Response[30];
|
|
|
|
for (int32_t 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);
|
|
|
|
uint64_t ResponseValue = 0;
|
|
|
|
m_PifRam[46] = m_PifRam[47] = 0x00;
|
|
|
|
for (int32_t z = 8; z > 0; z--)
|
|
|
|
{
|
|
|
|
ResponseValue = (ResponseValue << 8) | ((Response[(z - 1) * 2] << 4) + Response[(z - 1) * 2 + 1]);
|
|
|
|
}
|
|
|
|
memcpy(&m_PifRam[48], &ResponseValue, sizeof(uint64_t));
|
|
|
|
ResponseValue = 0;
|
|
|
|
for (int32_t z = 7; z > 0; z--)
|
|
|
|
{
|
|
|
|
ResponseValue = (ResponseValue << 8) | ((Response[((z + 8) - 1) * 2] << 4) + Response[((z + 8) - 1) * 2 + 1]);
|
|
|
|
}
|
|
|
|
memcpy(&m_PifRam[56], &ResponseValue, sizeof(uint64_t));
|
|
|
|
}
|
2016-01-18 08:54:39 +00:00
|
|
|
break;
|
2015-11-13 06:34:57 +00:00
|
|
|
case 0x08:
|
|
|
|
m_PifRam[0x3F] = 0;
|
|
|
|
g_Reg->MI_INTR_REG |= MI_INTR_SI;
|
|
|
|
g_Reg->SI_STATUS_REG |= SI_STATUS_INTERRUPT;
|
|
|
|
g_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())
|
|
|
|
{
|
2015-12-23 20:04:36 +00:00
|
|
|
g_Notify->DisplayError(stdstr_f("Unkown PifRam control: %d", m_PifRam[0x3F]).c_str());
|
2015-11-13 06:34:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (CurPos = 0; CurPos < 0x40; CurPos++)
|
|
|
|
{
|
|
|
|
switch (m_PifRam[CurPos])
|
|
|
|
{
|
|
|
|
case 0x00:
|
|
|
|
Channel += 1;
|
|
|
|
if (Channel > 6)
|
|
|
|
{
|
|
|
|
CurPos = 0x40;
|
|
|
|
}
|
|
|
|
break;
|
2016-05-22 11:41:21 +00:00
|
|
|
case 0xFD: CurPos = 0x40; break;
|
2015-11-13 06:34:57 +00:00
|
|
|
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 (g_Plugins->Control()->ControllerCommand)
|
|
|
|
{
|
|
|
|
g_Plugins->Control()->ControllerCommand(Channel, &m_PifRam[CurPos]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ProcessControllerCommand(Channel, &m_PifRam[CurPos]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (Channel == 4)
|
|
|
|
{
|
|
|
|
EepromCommand(&m_PifRam[CurPos]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (bShowPifRamErrors())
|
|
|
|
{
|
2015-12-23 20:04:36 +00:00
|
|
|
g_Notify->DisplayError("Command on channel 5?");
|
2015-11-13 06:34:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
CurPos += m_PifRam[CurPos] + (m_PifRam[CurPos + 1] & 0x3F) + 1;
|
|
|
|
Channel += 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-05-14 01:56:18 +00:00
|
|
|
if (CurPos != 0x27 && bShowPifRamErrors())
|
2015-11-13 06:34:57 +00:00
|
|
|
{
|
2015-12-23 20:04:36 +00:00
|
|
|
g_Notify->DisplayError(stdstr_f("Unknown Command in PifRamWrite(%X)", m_PifRam[CurPos]).c_str());
|
2015-11-13 06:34:57 +00:00
|
|
|
}
|
|
|
|
CurPos = 0x40;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_PifRam[0x3F] = 0;
|
|
|
|
if (g_Plugins->Control()->ControllerCommand)
|
|
|
|
{
|
2021-04-12 11:35:39 +00:00
|
|
|
g_Plugins->Control()->ControllerCommand(-1, nullptr);
|
2015-11-13 06:34:57 +00:00
|
|
|
}
|
2010-06-14 21:14:58 +00:00
|
|
|
}
|
|
|
|
|
2015-11-13 06:34:57 +00:00
|
|
|
void CPifRam::SI_DMA_READ()
|
2010-06-14 21:14:58 +00:00
|
|
|
{
|
2015-12-06 09:59:58 +00:00
|
|
|
uint8_t * PifRamPos = m_PifRam;
|
|
|
|
uint8_t * RDRAM = g_MMU->Rdram();
|
2015-11-13 06:34:57 +00:00
|
|
|
|
2015-11-08 20:21:28 +00:00
|
|
|
uint32_t & SI_DRAM_ADDR_REG = (uint32_t &)g_Reg->SI_DRAM_ADDR_REG;
|
|
|
|
if ((int32_t)SI_DRAM_ADDR_REG > (int32_t)g_System->RdramSize())
|
|
|
|
{
|
|
|
|
if (bShowPifRamErrors())
|
|
|
|
{
|
2016-01-14 01:04:31 +00:00
|
|
|
g_Notify->DisplayError(stdstr_f("%s\nSI_DRAM_ADDR_REG not in RDRam space", __FUNCTION__).c_str());
|
2015-11-08 20:21:28 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2010-06-14 21:14:58 +00:00
|
|
|
|
2015-11-08 20:21:28 +00:00
|
|
|
PifRamRead();
|
|
|
|
SI_DRAM_ADDR_REG &= 0xFFFFFFF8;
|
|
|
|
if ((int32_t)SI_DRAM_ADDR_REG < 0)
|
|
|
|
{
|
|
|
|
int32_t count, RdramPos;
|
|
|
|
|
|
|
|
RdramPos = (int32_t)SI_DRAM_ADDR_REG;
|
|
|
|
for (count = 0; count < 0x40; count++, RdramPos++)
|
|
|
|
{
|
|
|
|
if (RdramPos < 0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
RDRAM[RdramPos ^ 3] = m_PifRam[count];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-11-13 06:34:57 +00:00
|
|
|
for (size_t i = 0; i < 64; i++)
|
|
|
|
{
|
|
|
|
RDRAM[(SI_DRAM_ADDR_REG + i) ^ 3] = PifRamPos[i];
|
2015-11-08 20:21:28 +00:00
|
|
|
}
|
|
|
|
}
|
2010-06-14 21:14:58 +00:00
|
|
|
|
2015-11-13 13:23:43 +00:00
|
|
|
if (LogPRDMAMemStores())
|
2015-11-08 20:21:28 +00:00
|
|
|
{
|
|
|
|
int32_t count;
|
|
|
|
char HexData[100], AsciiData[100], Addon[20];
|
|
|
|
LogMessage("\tData DMAed to RDRAM:");
|
|
|
|
LogMessage("\t--------------------");
|
2015-11-13 06:34:57 +00:00
|
|
|
for (count = 0; count < 16; count++)
|
2015-11-08 20:21:28 +00:00
|
|
|
{
|
|
|
|
if ((count % 4) == 0)
|
|
|
|
{
|
2016-07-07 11:51:06 +00:00
|
|
|
HexData[0] = '\0';
|
|
|
|
AsciiData[0] = '\0';
|
2015-11-08 20:21:28 +00:00
|
|
|
}
|
2015-11-13 06:34:57 +00:00
|
|
|
sprintf(Addon, "%02X %02X %02X %02X",
|
2015-11-08 20:21:28 +00:00
|
|
|
m_PifRam[(count << 2) + 0], m_PifRam[(count << 2) + 1],
|
2015-11-13 06:34:57 +00:00
|
|
|
m_PifRam[(count << 2) + 2], m_PifRam[(count << 2) + 3]);
|
|
|
|
strcat(HexData, Addon);
|
2015-11-08 20:21:28 +00:00
|
|
|
if (((count + 1) % 4) != 0)
|
|
|
|
{
|
2015-11-13 06:34:57 +00:00
|
|
|
sprintf(Addon, "-");
|
|
|
|
strcat(HexData, Addon);
|
2015-11-08 20:21:28 +00:00
|
|
|
}
|
|
|
|
|
2015-11-13 06:34:57 +00:00
|
|
|
sprintf(Addon, "%c%c%c%c",
|
2015-11-08 20:21:28 +00:00
|
|
|
m_PifRam[(count << 2) + 0], m_PifRam[(count << 2) + 1],
|
2015-11-13 06:34:57 +00:00
|
|
|
m_PifRam[(count << 2) + 2], m_PifRam[(count << 2) + 3]);
|
|
|
|
strcat(AsciiData, Addon);
|
2015-11-08 20:21:28 +00:00
|
|
|
|
|
|
|
if (((count + 1) % 4) == 0)
|
|
|
|
{
|
2015-11-13 06:34:57 +00:00
|
|
|
LogMessage("\t%s %s", HexData, AsciiData);
|
2015-11-08 20:21:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
LogMessage("");
|
|
|
|
}
|
|
|
|
|
2019-10-02 22:18:19 +00:00
|
|
|
if(g_System->bRandomizeSIPIInterrupts())
|
2015-11-08 20:21:28 +00:00
|
|
|
{
|
2019-10-02 22:18:19 +00:00
|
|
|
if(g_System->bDelaySI())
|
|
|
|
{
|
|
|
|
g_SystemTimer->SetTimer(CSystemTimer::SiTimer, 0x900 + (g_Random->next() % 0x40), false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_SystemTimer->SetTimer(CSystemTimer::SiTimer, g_Random->next() % 0x40, false);
|
|
|
|
}
|
2015-11-08 20:21:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-10-02 22:18:19 +00:00
|
|
|
if(g_System->bDelaySI())
|
|
|
|
{
|
|
|
|
g_SystemTimer->SetTimer(CSystemTimer::SiTimer, 0x900, false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_Reg->MI_INTR_REG |= MI_INTR_SI;
|
|
|
|
g_Reg->SI_STATUS_REG |= SI_STATUS_INTERRUPT;
|
|
|
|
g_Reg->CheckInterrupts();
|
|
|
|
}
|
2015-11-08 20:21:28 +00:00
|
|
|
}
|
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
|
|
|
{
|
2015-11-08 20:21:28 +00:00
|
|
|
uint8_t * PifRamPos = m_PifRam;
|
2010-06-14 21:14:58 +00:00
|
|
|
|
2015-11-08 20:21:28 +00:00
|
|
|
uint32_t & SI_DRAM_ADDR_REG = (uint32_t &)g_Reg->SI_DRAM_ADDR_REG;
|
|
|
|
if ((int32_t)SI_DRAM_ADDR_REG > (int32_t)g_System->RdramSize())
|
|
|
|
{
|
|
|
|
if (bShowPifRamErrors())
|
|
|
|
{
|
2015-12-23 20:04:36 +00:00
|
|
|
g_Notify->DisplayError("SI DMA\nSI_DRAM_ADDR_REG not in RDRam space");
|
2015-11-08 20:21:28 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2010-06-14 21:14:58 +00:00
|
|
|
|
2015-11-08 20:21:28 +00:00
|
|
|
SI_DRAM_ADDR_REG &= 0xFFFFFFF8;
|
|
|
|
uint8_t * RDRAM = g_MMU->Rdram();
|
|
|
|
|
|
|
|
if ((int32_t)SI_DRAM_ADDR_REG < 0)
|
|
|
|
{
|
|
|
|
int32_t RdramPos = (int32_t)SI_DRAM_ADDR_REG;
|
|
|
|
|
|
|
|
for (int32_t count = 0; count < 0x40; count++, RdramPos++)
|
|
|
|
{
|
|
|
|
if (RdramPos < 0)
|
|
|
|
{
|
|
|
|
m_PifRam[count] = 0; continue;
|
|
|
|
}
|
|
|
|
m_PifRam[count] = RDRAM[RdramPos ^ 3];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-11-13 06:34:57 +00:00
|
|
|
for (size_t i = 0; i < 64; i++)
|
2015-11-08 20:21:28 +00:00
|
|
|
{
|
2015-11-13 06:34:57 +00:00
|
|
|
PifRamPos[i] = RDRAM[(SI_DRAM_ADDR_REG + i) ^ 3];
|
2015-11-08 20:21:28 +00:00
|
|
|
}
|
|
|
|
}
|
2010-06-14 21:14:58 +00:00
|
|
|
|
2015-11-13 13:23:43 +00:00
|
|
|
if (LogPRDMAMemLoads())
|
2015-11-08 20:21:28 +00:00
|
|
|
{
|
|
|
|
int32_t count;
|
|
|
|
char HexData[100], AsciiData[100], Addon[20];
|
|
|
|
LogMessage("");
|
|
|
|
LogMessage("\tData DMAed to the Pif Ram:");
|
|
|
|
LogMessage("\t--------------------------");
|
2015-11-13 06:34:57 +00:00
|
|
|
for (count = 0; count < 16; count++)
|
2015-11-08 20:21:28 +00:00
|
|
|
{
|
|
|
|
if ((count % 4) == 0)
|
|
|
|
{
|
2016-07-07 11:51:06 +00:00
|
|
|
HexData[0] = '\0';
|
|
|
|
AsciiData[0] = '\0';
|
2015-11-08 20:21:28 +00:00
|
|
|
}
|
2015-11-13 06:34:57 +00:00
|
|
|
sprintf(Addon, "%02X %02X %02X %02X",
|
2015-11-08 20:21:28 +00:00
|
|
|
m_PifRam[(count << 2) + 0], m_PifRam[(count << 2) + 1],
|
2015-11-13 06:34:57 +00:00
|
|
|
m_PifRam[(count << 2) + 2], m_PifRam[(count << 2) + 3]);
|
|
|
|
strcat(HexData, Addon);
|
2015-11-08 20:21:28 +00:00
|
|
|
if (((count + 1) % 4) != 0)
|
|
|
|
{
|
2015-11-13 06:34:57 +00:00
|
|
|
sprintf(Addon, "-");
|
|
|
|
strcat(HexData, Addon);
|
2015-11-08 20:21:28 +00:00
|
|
|
}
|
|
|
|
|
2015-11-13 06:34:57 +00:00
|
|
|
sprintf(Addon, "%c%c%c%c",
|
2015-11-08 20:21:28 +00:00
|
|
|
m_PifRam[(count << 2) + 0], m_PifRam[(count << 2) + 1],
|
2015-11-13 06:34:57 +00:00
|
|
|
m_PifRam[(count << 2) + 2], m_PifRam[(count << 2) + 3]);
|
|
|
|
strcat(AsciiData, Addon);
|
2015-11-08 20:21:28 +00:00
|
|
|
|
|
|
|
if (((count + 1) % 4) == 0)
|
|
|
|
{
|
2015-11-13 06:34:57 +00:00
|
|
|
LogMessage("\t%s %s", HexData, AsciiData);
|
2015-11-08 20:21:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
LogMessage("");
|
|
|
|
}
|
|
|
|
|
|
|
|
PifRamWrite();
|
|
|
|
|
|
|
|
if (g_System->bDelaySI())
|
|
|
|
{
|
|
|
|
g_SystemTimer->SetTimer(CSystemTimer::SiTimer, 0x900, false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-01-18 08:54:39 +00:00
|
|
|
void CPifRam::ProcessControllerCommand(int32_t Control, uint8_t * Command)
|
2010-06-14 21:14:58 +00:00
|
|
|
{
|
2015-11-13 06:34:57 +00:00
|
|
|
CONTROL * Controllers = g_Plugins->Control()->PluginControllers();
|
|
|
|
|
|
|
|
switch (Command[2])
|
|
|
|
{
|
|
|
|
case 0x00: // check
|
|
|
|
case 0xFF: // reset & check ?
|
|
|
|
if ((Command[1] & 0x80) != 0)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (bShowPifRamErrors())
|
|
|
|
{
|
2016-01-28 10:58:14 +00:00
|
|
|
if (Command[0] != 1 || Command[1] != 3)
|
2015-11-13 06:34:57 +00:00
|
|
|
{
|
2015-12-23 20:04:36 +00:00
|
|
|
g_Notify->DisplayError("What am I meant to do with this Controller Command");
|
2015-11-13 06:34:57 +00:00
|
|
|
}
|
|
|
|
}
|
2016-07-07 11:51:06 +00:00
|
|
|
if (Controllers[Control].Present != 0)
|
2015-11-13 06:34:57 +00:00
|
|
|
{
|
|
|
|
Command[3] = 0x05;
|
|
|
|
Command[4] = 0x00;
|
|
|
|
switch (Controllers[Control].Plugin)
|
|
|
|
{
|
|
|
|
case PLUGIN_TANSFER_PAK:
|
|
|
|
case PLUGIN_RUMBLE_PAK:
|
|
|
|
case PLUGIN_MEMPAK:
|
|
|
|
case PLUGIN_RAW:
|
|
|
|
Command[5] = 1; break;
|
|
|
|
default: Command[5] = 0; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Command[1] |= 0x80;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x01: // read controller
|
|
|
|
if (bShowPifRamErrors())
|
|
|
|
{
|
2016-01-28 10:58:14 +00:00
|
|
|
if (Command[0] != 1 || Command[1] != 4)
|
2015-11-13 06:34:57 +00:00
|
|
|
{
|
2015-12-23 20:04:36 +00:00
|
|
|
g_Notify->DisplayError("What am I meant to do with this Controller Command");
|
2015-11-13 06:34:57 +00:00
|
|
|
}
|
|
|
|
}
|
2015-12-06 09:59:58 +00:00
|
|
|
if (Controllers[Control].Present == false)
|
2015-11-13 06:34:57 +00:00
|
|
|
{
|
|
|
|
Command[1] |= 0x80;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x02: //read from controller pack
|
2015-11-13 13:23:43 +00:00
|
|
|
if (LogControllerPak())
|
2015-11-13 06:34:57 +00:00
|
|
|
{
|
|
|
|
LogControllerPakData("Read: Before Gettting Results");
|
|
|
|
}
|
|
|
|
if (bShowPifRamErrors())
|
|
|
|
{
|
2016-01-28 10:58:14 +00:00
|
|
|
if (Command[0] != 3 || Command[1] != 33)
|
2015-11-13 06:34:57 +00:00
|
|
|
{
|
2015-12-23 20:04:36 +00:00
|
|
|
g_Notify->DisplayError("What am I meant to do with this Controller Command");
|
2015-11-13 06:34:57 +00:00
|
|
|
}
|
|
|
|
}
|
2016-07-07 11:51:06 +00:00
|
|
|
if (Controllers[Control].Present != 0)
|
2015-11-13 06:34:57 +00:00
|
|
|
{
|
2016-01-28 10:58:14 +00:00
|
|
|
uint32_t address = (Command[3] << 8) | (Command[4] & 0xE0);
|
|
|
|
uint8_t* data = &Command[5];
|
|
|
|
|
2015-11-13 06:34:57 +00:00
|
|
|
switch (Controllers[Control].Plugin)
|
|
|
|
{
|
2016-01-28 10:58:14 +00:00
|
|
|
case PLUGIN_RUMBLE_PAK: Rumblepak::ReadFrom(address, data); break;
|
2016-07-07 11:51:06 +00:00
|
|
|
case PLUGIN_MEMPAK: g_Mempak->ReadFrom(Control, address, data); break;
|
2021-01-19 05:58:59 +00:00
|
|
|
case PLUGIN_TANSFER_PAK: Transferpak::ReadFrom((uint16_t)address, data); break;
|
2015-11-13 06:34:57 +00:00
|
|
|
case PLUGIN_RAW: if (g_Plugins->Control()->ControllerCommand) { g_Plugins->Control()->ControllerCommand(Control, Command); } break;
|
|
|
|
default:
|
|
|
|
memset(&Command[5], 0, 0x20);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Controllers[Control].Plugin != PLUGIN_RAW)
|
|
|
|
{
|
2016-07-07 11:51:06 +00:00
|
|
|
Command[0x25] = CMempak::CalculateCrc(data);
|
2015-11-13 06:34:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Command[1] |= 0x80;
|
|
|
|
}
|
2015-11-13 13:23:43 +00:00
|
|
|
if (LogControllerPak())
|
2015-11-13 06:34:57 +00:00
|
|
|
{
|
|
|
|
LogControllerPakData("Read: After Gettting Results");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x03: //write controller pak
|
2015-11-13 13:23:43 +00:00
|
|
|
if (LogControllerPak())
|
2015-11-13 06:34:57 +00:00
|
|
|
{
|
|
|
|
LogControllerPakData("Write: Before Processing");
|
|
|
|
}
|
|
|
|
if (bShowPifRamErrors())
|
|
|
|
{
|
2016-01-28 10:58:14 +00:00
|
|
|
if (Command[0] != 35 || Command[1] != 1)
|
2015-11-13 06:34:57 +00:00
|
|
|
{
|
2015-12-23 20:04:36 +00:00
|
|
|
g_Notify->DisplayError("What am I meant to do with this Controller Command");
|
2015-11-13 06:34:57 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-19 05:58:59 +00:00
|
|
|
if (Controllers[Control].Present != 0)
|
2015-11-13 06:34:57 +00:00
|
|
|
{
|
2016-01-28 10:58:14 +00:00
|
|
|
uint32_t address = (Command[3] << 8) | (Command[4] & 0xE0);
|
|
|
|
uint8_t* data = &Command[5];
|
|
|
|
|
2015-11-13 06:34:57 +00:00
|
|
|
switch (Controllers[Control].Plugin)
|
|
|
|
{
|
2016-07-07 11:51:06 +00:00
|
|
|
case PLUGIN_MEMPAK: g_Mempak->WriteTo(Control, address, data); break;
|
2016-01-28 10:58:14 +00:00
|
|
|
case PLUGIN_RUMBLE_PAK: Rumblepak::WriteTo(Control, address, data); break;
|
2021-01-19 05:58:59 +00:00
|
|
|
case PLUGIN_TANSFER_PAK: Transferpak::WriteTo((uint16_t)address, data); break;
|
2015-11-13 06:34:57 +00:00
|
|
|
case PLUGIN_RAW: if (g_Plugins->Control()->ControllerCommand) { g_Plugins->Control()->ControllerCommand(Control, Command); } break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Controllers[Control].Plugin != PLUGIN_RAW)
|
|
|
|
{
|
2016-07-07 11:51:06 +00:00
|
|
|
Command[0x25] = CMempak::CalculateCrc(data);
|
2015-11-13 06:34:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Command[1] |= 0x80;
|
|
|
|
}
|
2015-11-13 13:23:43 +00:00
|
|
|
if (LogControllerPak())
|
2015-11-13 06:34:57 +00:00
|
|
|
{
|
|
|
|
LogControllerPakData("Write: After Processing");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (bShowPifRamErrors())
|
|
|
|
{
|
2015-12-23 20:04:36 +00:00
|
|
|
g_Notify->DisplayError(stdstr_f("Unknown ControllerCommand %d", Command[2]).c_str());
|
2015-11-13 06:34:57 +00:00
|
|
|
}
|
|
|
|
}
|
2010-06-14 21:14:58 +00:00
|
|
|
}
|
|
|
|
|
2016-01-18 08:54:39 +00:00
|
|
|
void CPifRam::ReadControllerCommand(int32_t Control, uint8_t * Command)
|
|
|
|
{
|
2015-11-13 06:34:57 +00:00
|
|
|
CONTROL * Controllers = g_Plugins->Control()->PluginControllers();
|
|
|
|
|
|
|
|
switch (Command[2])
|
|
|
|
{
|
|
|
|
case 0x01: // read controller
|
2016-07-07 11:51:06 +00:00
|
|
|
if (Controllers[Control].Present != 0)
|
2015-11-13 06:34:57 +00:00
|
|
|
{
|
|
|
|
if (bShowPifRamErrors())
|
|
|
|
{
|
2016-01-28 10:58:14 +00:00
|
|
|
if (Command[0] != 1 || Command[1] != 4) { g_Notify->DisplayError("What am I meant to do with this Controller Command"); }
|
2015-11-13 06:34:57 +00:00
|
|
|
}
|
|
|
|
|
2015-12-06 09:59:58 +00:00
|
|
|
const uint32_t buttons = g_BaseSystem->GetButtons(Control);
|
2016-01-15 00:19:51 +00:00
|
|
|
memcpy(&Command[3], &buttons, sizeof(uint32_t));
|
2015-11-13 06:34:57 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x02: //read from controller pack
|
2016-07-07 11:51:06 +00:00
|
|
|
if (Controllers[Control].Present != 0)
|
2015-11-13 06:34:57 +00:00
|
|
|
{
|
|
|
|
switch (Controllers[Control].Plugin)
|
|
|
|
{
|
|
|
|
case PLUGIN_RAW: if (g_Plugins->Control()->ReadController) { g_Plugins->Control()->ReadController(Control, Command); } break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x03: //write controller pak
|
2016-07-07 11:51:06 +00:00
|
|
|
if (Controllers[Control].Present != 0)
|
2015-11-13 06:34:57 +00:00
|
|
|
{
|
|
|
|
switch (Controllers[Control].Plugin)
|
|
|
|
{
|
|
|
|
case PLUGIN_RAW: if (g_Plugins->Control()->ReadController) { g_Plugins->Control()->ReadController(Control, Command); } break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2010-06-14 21:14:58 +00:00
|
|
|
}
|
|
|
|
|
2016-01-18 08:54:39 +00:00
|
|
|
void CPifRam::LogControllerPakData(const char * Description)
|
2010-06-14 21:14:58 +00:00
|
|
|
{
|
2015-12-06 09:59:58 +00:00
|
|
|
uint8_t * PIF_Ram = g_MMU->PifRam();
|
2015-11-13 06:34:57 +00:00
|
|
|
|
2016-01-18 08:54:39 +00:00
|
|
|
int32_t count, count2;
|
2015-11-13 06:34:57 +00:00
|
|
|
char HexData[100], AsciiData[100], Addon[20];
|
|
|
|
LogMessage("\t%s:", Description);
|
|
|
|
LogMessage("\t------------------------------");
|
|
|
|
for (count = 0; count < 16; count++)
|
|
|
|
{
|
|
|
|
if ((count % 4) == 0)
|
|
|
|
{
|
2016-07-07 11:51:06 +00:00
|
|
|
HexData[0] = '\0';
|
|
|
|
AsciiData[0] = '\0';
|
2015-11-13 06:34:57 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
|
{
|
2019-03-27 09:40:37 +00:00
|
|
|
char tmp[2];
|
|
|
|
sprintf(tmp, "%c", PIF_Ram[(count << 2) + count2]);
|
|
|
|
strcat(Addon, tmp);
|
2015-11-13 06:34:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
strcat(AsciiData, Addon);
|
|
|
|
|
|
|
|
if (((count + 1) % 4) == 0)
|
|
|
|
{
|
|
|
|
LogMessage("\t%s %s", HexData, AsciiData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LogMessage("");
|
2016-07-07 11:51:06 +00:00
|
|
|
}
|