diff --git a/Source/Project64-core/N64System/Mips/Mempak.H b/Source/Project64-core/N64System/Mips/Mempak.H index e394a217c..d344dc6f2 100644 --- a/Source/Project64-core/N64System/Mips/Mempak.H +++ b/Source/Project64-core/N64System/Mips/Mempak.H @@ -16,6 +16,6 @@ public: static uint8_t CalculateCrc(uint8_t * DataToCrc); static void Load(); static void Format(int32_t Control); - static void ReadFrom(int32_t Control, uint8_t * command); - static void WriteTo(int32_t Control, uint8_t * command); + static void ReadFrom(int32_t Control, uint32_t address, uint8_t * data); + static void WriteTo(int32_t Control, uint32_t address, uint8_t * data); }; \ No newline at end of file diff --git a/Source/Project64-core/N64System/Mips/Mempak.cpp b/Source/Project64-core/N64System/Mips/Mempak.cpp index 6e6df87b4..6a29211f7 100644 --- a/Source/Project64-core/N64System/Mips/Mempak.cpp +++ b/Source/Project64-core/N64System/Mips/Mempak.cpp @@ -109,28 +109,24 @@ uint8_t Mempak::CalculateCrc(uint8_t * DataToCrc) 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) { - memcpy(&command[5], &Mempaks[Control][address], 0x20); + memcpy(data, &Mempaks[Control][address], 0x20); } else { - memset(&command[5], 0x00, 0x20); + memset(data, 0x00, 0x20); /* 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) { - memcpy(&Mempaks[Control][address], &command[5], 0x20); + memcpy(&Mempaks[Control][address], data, 0x20); FILE* mempak = fopen(MempakNames[Control], "wb"); fwrite(Mempaks[Control], 1, 0x8000, mempak); diff --git a/Source/Project64-core/N64System/Mips/PifRam.cpp b/Source/Project64-core/N64System/Mips/PifRam.cpp index bb0f493c2..4257f0935 100644 --- a/Source/Project64-core/N64System/Mips/PifRam.cpp +++ b/Source/Project64-core/N64System/Mips/PifRam.cpp @@ -468,11 +468,7 @@ void CPifRam::ProcessControllerCommand(int32_t Control, uint8_t * Command) } if (bShowPifRamErrors()) { - if (Command[0] != 1) - { - g_Notify->DisplayError("What am I meant to do with this Controller Command"); - } - if (Command[1] != 3) + if (Command[0] != 1 || Command[1] != 3) { 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 if (bShowPifRamErrors()) { - if (Command[0] != 1) - { - g_Notify->DisplayError("What am I meant to do with this Controller Command"); - } - if (Command[1] != 4) + if (Command[0] != 1 || Command[1] != 4) { 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 (Command[0] != 3) - { - g_Notify->DisplayError("What am I meant to do with this Controller Command"); - } - if (Command[1] != 33) + if (Command[0] != 3 || Command[1] != 33) { g_Notify->DisplayError("What am I meant to do with this Controller Command"); } } if (Controllers[Control].Present == true) { + uint32_t address = (Command[3] << 8) | (Command[4] & 0xE0); + uint8_t* data = &Command[5]; + switch (Controllers[Control].Plugin) { - case PLUGIN_RUMBLE_PAK: Rumblepak::ReadFrom(Command); break; - case PLUGIN_MEMPAK: Mempak::ReadFrom(Control, Command); break; + case PLUGIN_RUMBLE_PAK: Rumblepak::ReadFrom(address, data); break; + case PLUGIN_MEMPAK: Mempak::ReadFrom(Control, address, data); break; case PLUGIN_TANSFER_PAK: /* TODO */; break; case PLUGIN_RAW: if (g_Plugins->Control()->ControllerCommand) { g_Plugins->Control()->ControllerCommand(Control, Command); } break; default: @@ -562,21 +553,20 @@ void CPifRam::ProcessControllerCommand(int32_t Control, uint8_t * Command) } if (bShowPifRamErrors()) { - if (Command[0] != 35) - { - g_Notify->DisplayError("What am I meant to do with this Controller Command"); - } - if (Command[1] != 1) + if (Command[0] != 35 || Command[1] != 1) { g_Notify->DisplayError("What am I meant to do with this Controller Command"); } } if (Controllers[Control].Present == true) { + uint32_t address = (Command[3] << 8) | (Command[4] & 0xE0); + uint8_t* data = &Command[5]; + switch (Controllers[Control].Plugin) { - case PLUGIN_MEMPAK: Mempak::WriteTo(Control, Command); break; - case PLUGIN_RUMBLE_PAK: Rumblepak::WriteTo(Control, Command); break; + case PLUGIN_MEMPAK: Mempak::WriteTo(Control, address, data); break; + case PLUGIN_RUMBLE_PAK: Rumblepak::WriteTo(Control, address, data); break; case PLUGIN_TANSFER_PAK: /* TODO */; 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 (Command[0] != 1) { 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"); } + if (Command[0] != 1 || Command[1] != 4) { g_Notify->DisplayError("What am I meant to do with this Controller Command"); } } const uint32_t buttons = g_BaseSystem->GetButtons(Control); diff --git a/Source/Project64-core/N64System/Mips/Rumblepak.cpp b/Source/Project64-core/N64System/Mips/Rumblepak.cpp index fd1607613..811dc4747 100644 --- a/Source/Project64-core/N64System/Mips/Rumblepak.cpp +++ b/Source/Project64-core/N64System/Mips/Rumblepak.cpp @@ -15,29 +15,25 @@ #include #include -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)) { - memset(&command[5], 0x80, 0x20); + memset(data, 0x80, 0x20); } 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 (g_Plugins->Control()->RumbleCommand != NULL) { - g_Plugins->Control()->RumbleCommand(Control, *(int *)(&command[5])); + g_Plugins->Control()->RumbleCommand(Control, *(int *)data); } } } \ No newline at end of file diff --git a/Source/Project64-core/N64System/Mips/Rumblepak.h b/Source/Project64-core/N64System/Mips/Rumblepak.h index 3e76eacce..7a16af175 100644 --- a/Source/Project64-core/N64System/Mips/Rumblepak.h +++ b/Source/Project64-core/N64System/Mips/Rumblepak.h @@ -13,6 +13,6 @@ class Rumblepak { public: - static void ReadFrom(uint8_t * command); - static void WriteTo(int32_t Control, uint8_t * command); + static void ReadFrom(uint32_t address, uint8_t * data); + static void WriteTo(int32_t Control, uint32_t address, uint8_t * data); };