Merge pull request #950 from death-droid/PifRAMCleanupChanges
Prepare the emulator for easier implementation of the transferpak, pa…
This commit is contained in:
commit
6b50bc4ff4
|
@ -16,6 +16,6 @@ public:
|
||||||
static uint8_t CalculateCrc(uint8_t * DataToCrc);
|
static uint8_t CalculateCrc(uint8_t * DataToCrc);
|
||||||
static void Load();
|
static void Load();
|
||||||
static void Format(int32_t Control);
|
static void Format(int32_t Control);
|
||||||
static void ReadFrom(int32_t Control, uint8_t * command);
|
static void ReadFrom(int32_t Control, uint32_t address, uint8_t * data);
|
||||||
static void WriteTo(int32_t Control, uint8_t * command);
|
static void WriteTo(int32_t Control, uint32_t address, uint8_t * data);
|
||||||
};
|
};
|
|
@ -109,28 +109,24 @@ uint8_t Mempak::CalculateCrc(uint8_t * DataToCrc)
|
||||||
return CRC;
|
return CRC;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mempak::ReadFrom(int32_t Control, uint8_t * command)
|
void Mempak::ReadFrom(int32_t Control, uint32_t address, uint8_t * data)
|
||||||
{
|
{
|
||||||
uint32_t address = (command[3] << 8) | (command[4] & 0xE0);
|
|
||||||
|
|
||||||
if (address < 0x8000)
|
if (address < 0x8000)
|
||||||
{
|
{
|
||||||
memcpy(&command[5], &Mempaks[Control][address], 0x20);
|
memcpy(data, &Mempaks[Control][address], 0x20);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
memset(&command[5], 0x00, 0x20);
|
memset(data, 0x00, 0x20);
|
||||||
/* Rumble pack area */
|
/* Rumble pack area */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mempak::WriteTo(int32_t Control, uint8_t * command)
|
void Mempak::WriteTo(int32_t Control, uint32_t address, uint8_t * data)
|
||||||
{
|
{
|
||||||
uint32_t address = (command[3] << 8) | (command[4] & 0xE0);
|
|
||||||
|
|
||||||
if (address < 0x8000)
|
if (address < 0x8000)
|
||||||
{
|
{
|
||||||
memcpy(&Mempaks[Control][address], &command[5], 0x20);
|
memcpy(&Mempaks[Control][address], data, 0x20);
|
||||||
|
|
||||||
FILE* mempak = fopen(MempakNames[Control], "wb");
|
FILE* mempak = fopen(MempakNames[Control], "wb");
|
||||||
fwrite(Mempaks[Control], 1, 0x8000, mempak);
|
fwrite(Mempaks[Control], 1, 0x8000, mempak);
|
||||||
|
|
|
@ -468,11 +468,7 @@ void CPifRam::ProcessControllerCommand(int32_t Control, uint8_t * Command)
|
||||||
}
|
}
|
||||||
if (bShowPifRamErrors())
|
if (bShowPifRamErrors())
|
||||||
{
|
{
|
||||||
if (Command[0] != 1)
|
if (Command[0] != 1 || Command[1] != 3)
|
||||||
{
|
|
||||||
g_Notify->DisplayError("What am I meant to do with this Controller Command");
|
|
||||||
}
|
|
||||||
if (Command[1] != 3)
|
|
||||||
{
|
{
|
||||||
g_Notify->DisplayError("What am I meant to do with this Controller Command");
|
g_Notify->DisplayError("What am I meant to do with this Controller Command");
|
||||||
}
|
}
|
||||||
|
@ -499,11 +495,7 @@ void CPifRam::ProcessControllerCommand(int32_t Control, uint8_t * Command)
|
||||||
case 0x01: // read controller
|
case 0x01: // read controller
|
||||||
if (bShowPifRamErrors())
|
if (bShowPifRamErrors())
|
||||||
{
|
{
|
||||||
if (Command[0] != 1)
|
if (Command[0] != 1 || Command[1] != 4)
|
||||||
{
|
|
||||||
g_Notify->DisplayError("What am I meant to do with this Controller Command");
|
|
||||||
}
|
|
||||||
if (Command[1] != 4)
|
|
||||||
{
|
{
|
||||||
g_Notify->DisplayError("What am I meant to do with this Controller Command");
|
g_Notify->DisplayError("What am I meant to do with this Controller Command");
|
||||||
}
|
}
|
||||||
|
@ -520,21 +512,20 @@ void CPifRam::ProcessControllerCommand(int32_t Control, uint8_t * Command)
|
||||||
}
|
}
|
||||||
if (bShowPifRamErrors())
|
if (bShowPifRamErrors())
|
||||||
{
|
{
|
||||||
if (Command[0] != 3)
|
if (Command[0] != 3 || Command[1] != 33)
|
||||||
{
|
|
||||||
g_Notify->DisplayError("What am I meant to do with this Controller Command");
|
|
||||||
}
|
|
||||||
if (Command[1] != 33)
|
|
||||||
{
|
{
|
||||||
g_Notify->DisplayError("What am I meant to do with this Controller Command");
|
g_Notify->DisplayError("What am I meant to do with this Controller Command");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Controllers[Control].Present == true)
|
if (Controllers[Control].Present == true)
|
||||||
{
|
{
|
||||||
|
uint32_t address = (Command[3] << 8) | (Command[4] & 0xE0);
|
||||||
|
uint8_t* data = &Command[5];
|
||||||
|
|
||||||
switch (Controllers[Control].Plugin)
|
switch (Controllers[Control].Plugin)
|
||||||
{
|
{
|
||||||
case PLUGIN_RUMBLE_PAK: Rumblepak::ReadFrom(Command); break;
|
case PLUGIN_RUMBLE_PAK: Rumblepak::ReadFrom(address, data); break;
|
||||||
case PLUGIN_MEMPAK: Mempak::ReadFrom(Control, Command); break;
|
case PLUGIN_MEMPAK: Mempak::ReadFrom(Control, address, data); break;
|
||||||
case PLUGIN_TANSFER_PAK: /* TODO */; break;
|
case PLUGIN_TANSFER_PAK: /* TODO */; break;
|
||||||
case PLUGIN_RAW: if (g_Plugins->Control()->ControllerCommand) { g_Plugins->Control()->ControllerCommand(Control, Command); } break;
|
case PLUGIN_RAW: if (g_Plugins->Control()->ControllerCommand) { g_Plugins->Control()->ControllerCommand(Control, Command); } break;
|
||||||
default:
|
default:
|
||||||
|
@ -562,21 +553,20 @@ void CPifRam::ProcessControllerCommand(int32_t Control, uint8_t * Command)
|
||||||
}
|
}
|
||||||
if (bShowPifRamErrors())
|
if (bShowPifRamErrors())
|
||||||
{
|
{
|
||||||
if (Command[0] != 35)
|
if (Command[0] != 35 || Command[1] != 1)
|
||||||
{
|
|
||||||
g_Notify->DisplayError("What am I meant to do with this Controller Command");
|
|
||||||
}
|
|
||||||
if (Command[1] != 1)
|
|
||||||
{
|
{
|
||||||
g_Notify->DisplayError("What am I meant to do with this Controller Command");
|
g_Notify->DisplayError("What am I meant to do with this Controller Command");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Controllers[Control].Present == true)
|
if (Controllers[Control].Present == true)
|
||||||
{
|
{
|
||||||
|
uint32_t address = (Command[3] << 8) | (Command[4] & 0xE0);
|
||||||
|
uint8_t* data = &Command[5];
|
||||||
|
|
||||||
switch (Controllers[Control].Plugin)
|
switch (Controllers[Control].Plugin)
|
||||||
{
|
{
|
||||||
case PLUGIN_MEMPAK: Mempak::WriteTo(Control, Command); break;
|
case PLUGIN_MEMPAK: Mempak::WriteTo(Control, address, data); break;
|
||||||
case PLUGIN_RUMBLE_PAK: Rumblepak::WriteTo(Control, Command); break;
|
case PLUGIN_RUMBLE_PAK: Rumblepak::WriteTo(Control, address, data); break;
|
||||||
case PLUGIN_TANSFER_PAK: /* TODO */; break;
|
case PLUGIN_TANSFER_PAK: /* TODO */; break;
|
||||||
case PLUGIN_RAW: if (g_Plugins->Control()->ControllerCommand) { g_Plugins->Control()->ControllerCommand(Control, Command); } break;
|
case PLUGIN_RAW: if (g_Plugins->Control()->ControllerCommand) { g_Plugins->Control()->ControllerCommand(Control, Command); } break;
|
||||||
}
|
}
|
||||||
|
@ -614,8 +604,7 @@ void CPifRam::ReadControllerCommand(int32_t Control, uint8_t * Command)
|
||||||
{
|
{
|
||||||
if (bShowPifRamErrors())
|
if (bShowPifRamErrors())
|
||||||
{
|
{
|
||||||
if (Command[0] != 1) { g_Notify->DisplayError("What am I meant to do with this Controller Command"); }
|
if (Command[0] != 1 || Command[1] != 4) { g_Notify->DisplayError("What am I meant to do with this Controller Command"); }
|
||||||
if (Command[1] != 4) { g_Notify->DisplayError("What am I meant to do with this Controller Command"); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint32_t buttons = g_BaseSystem->GetButtons(Control);
|
const uint32_t buttons = g_BaseSystem->GetButtons(Control);
|
||||||
|
|
|
@ -15,29 +15,25 @@
|
||||||
#include <Project64-core/Plugins/PluginClass.h>
|
#include <Project64-core/Plugins/PluginClass.h>
|
||||||
#include <Project64-core/Plugins/ControllerPlugin.h>
|
#include <Project64-core/Plugins/ControllerPlugin.h>
|
||||||
|
|
||||||
void Rumblepak::ReadFrom(uint8_t * command)
|
void Rumblepak::ReadFrom(uint32_t address, uint8_t * data)
|
||||||
{
|
{
|
||||||
uint32_t address = (command[3] << 8) | (command[4] & 0xE0);
|
|
||||||
|
|
||||||
if ((address >= 0x8000) && (address < 0x9000))
|
if ((address >= 0x8000) && (address < 0x9000))
|
||||||
{
|
{
|
||||||
memset(&command[5], 0x80, 0x20);
|
memset(data, 0x80, 0x20);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
memset(&command[5], 0x00, 0x20);
|
memset(data, 0x00, 0x20);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Rumblepak::WriteTo(int32_t Control, uint8_t * command)
|
void Rumblepak::WriteTo(int32_t Control, uint32_t address, uint8_t * data)
|
||||||
{
|
{
|
||||||
uint32_t address = (command[3] << 8) | (command[4] & 0xE0);
|
|
||||||
|
|
||||||
if ((address) == 0xC000)
|
if ((address) == 0xC000)
|
||||||
{
|
{
|
||||||
if (g_Plugins->Control()->RumbleCommand != NULL)
|
if (g_Plugins->Control()->RumbleCommand != NULL)
|
||||||
{
|
{
|
||||||
g_Plugins->Control()->RumbleCommand(Control, *(int *)(&command[5]));
|
g_Plugins->Control()->RumbleCommand(Control, *(int *)data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -13,6 +13,6 @@
|
||||||
class Rumblepak
|
class Rumblepak
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void ReadFrom(uint8_t * command);
|
static void ReadFrom(uint32_t address, uint8_t * data);
|
||||||
static void WriteTo(int32_t Control, uint8_t * command);
|
static void WriteTo(int32_t Control, uint32_t address, uint8_t * data);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue