From e879431606535007f35081f54dbe68f76dbdf8df Mon Sep 17 00:00:00 2001 From: Emmet Young Date: Thu, 28 Jan 2016 21:58:14 +1100 Subject: [PATCH 1/2] Prepare the emulator for easier implementation of the transferpak, pass Command[5] directly into the Pak functions, and also generate the address beforehand. --- Source/Project64-core/N64System/Mips/Mempak.H | 4 +- .../Project64-core/N64System/Mips/Mempak.cpp | 14 +++---- .../Project64-core/N64System/Mips/PifRam.cpp | 41 +++++++------------ .../N64System/Mips/Rumblepak.cpp | 14 +++---- .../Project64-core/N64System/Mips/Rumblepak.h | 4 +- 5 files changed, 29 insertions(+), 48 deletions(-) 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..d66928c81 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..9d88576d6 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); }; From c6fa59ac3aa7edffbf6269cfb281bcdefb594e15 Mon Sep 17 00:00:00 2001 From: Emmet Young Date: Thu, 28 Jan 2016 22:51:48 +1100 Subject: [PATCH 2/2] Made a slight mistake when porting over from my old branch. Mempak and Rumblepak will work fine again. --- Source/Project64-core/N64System/Mips/Mempak.cpp | 6 +++--- Source/Project64-core/N64System/Mips/Rumblepak.cpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/Project64-core/N64System/Mips/Mempak.cpp b/Source/Project64-core/N64System/Mips/Mempak.cpp index d66928c81..6a29211f7 100644 --- a/Source/Project64-core/N64System/Mips/Mempak.cpp +++ b/Source/Project64-core/N64System/Mips/Mempak.cpp @@ -113,11 +113,11 @@ void Mempak::ReadFrom(int32_t Control, uint32_t address, uint8_t * data) { if (address < 0x8000) { - memcpy(&data, &Mempaks[Control][address], 0x20); + memcpy(data, &Mempaks[Control][address], 0x20); } else { - memset(&data, 0x00, 0x20); + memset(data, 0x00, 0x20); /* Rumble pack area */ } } @@ -126,7 +126,7 @@ void Mempak::WriteTo(int32_t Control, uint32_t address, uint8_t * data) { if (address < 0x8000) { - memcpy(&Mempaks[Control][address], &data, 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/Rumblepak.cpp b/Source/Project64-core/N64System/Mips/Rumblepak.cpp index 9d88576d6..811dc4747 100644 --- a/Source/Project64-core/N64System/Mips/Rumblepak.cpp +++ b/Source/Project64-core/N64System/Mips/Rumblepak.cpp @@ -19,11 +19,11 @@ void Rumblepak::ReadFrom(uint32_t address, uint8_t * data) { if ((address >= 0x8000) && (address < 0x9000)) { - memset(&data, 0x80, 0x20); + memset(data, 0x80, 0x20); } else { - memset(&data, 0x00, 0x20); + memset(data, 0x00, 0x20); } } @@ -33,7 +33,7 @@ void Rumblepak::WriteTo(int32_t Control, uint32_t address, uint8_t * data) { if (g_Plugins->Control()->RumbleCommand != NULL) { - g_Plugins->Control()->RumbleCommand(Control, *(int *)(&data)); + g_Plugins->Control()->RumbleCommand(Control, *(int *)data); } } } \ No newline at end of file