diff --git a/Source/Project64/N64 System.h b/Source/Project64/N64 System.h
index 03c51cbf7..2b37e1ca3 100644
--- a/Source/Project64/N64 System.h
+++ b/Source/Project64/N64 System.h
@@ -28,6 +28,7 @@ class CNotification;
#include "N64 System/Mips/OpCode.h"
#include "N64 System/Recompiler/X86ops.h"
#include "N64 System/Mips/Mempak.h"
+#include "N64 System/Mips/Rumblepak.h"
#include "N64 System/Mips/FlashRam.h"
#include "N64 System/Mips/Sram.h"
#include "N64 System/Mips/Eeprom.h"
diff --git a/Source/Project64/N64 System/Mips/Mempak.H b/Source/Project64/N64 System/Mips/Mempak.H
index b8c473b4f..650b466c3 100644
--- a/Source/Project64/N64 System/Mips/Mempak.H
+++ b/Source/Project64/N64 System/Mips/Mempak.H
@@ -15,7 +15,7 @@ class Mempak
public:
static void Close();
static BYTE CalculateCrc(BYTE * DataToCrc);
- static void ReadFrom(int Control, int Address, BYTE * Buffer);
- static void WriteTo(int Control, int Address, BYTE * Buffer);
+ static void ReadFrom(int Control, BYTE * command);
+ static void WriteTo(int Control, BYTE * command);
};
diff --git a/Source/Project64/N64 System/Mips/Mempak.cpp b/Source/Project64/N64 System/Mips/Mempak.cpp
index 22ab0c22a..1a8fece98 100644
--- a/Source/Project64/N64 System/Mips/Mempak.cpp
+++ b/Source/Project64/N64 System/Mips/Mempak.cpp
@@ -106,7 +106,7 @@ BYTE Mempak::CalculateCrc(BYTE * DataToCrc)
{
for (Length = 0x80; Length >= 1; Length >>= 1)
{
- XorTap = (CRC & 0x80) ? 0x85 : 0;
+ XorTap = (CRC & 0x80) ? 0x85 : 0x00;
CRC <<= 1;
if (Count == 0x20)
{
@@ -127,36 +127,37 @@ BYTE Mempak::CalculateCrc(BYTE * DataToCrc)
return CRC;
}
-void Mempak::ReadFrom(int Control, int Address, BYTE * Buffer)
+void Mempak::ReadFrom(int Control, BYTE * command)
{
- if (Address < 0x8000)
+ DWORD address = (command[3] << 8) | (command[4] & 0xE0);
+
+ if (address < 0x8000)
{
if (hMempakFile[Control] == NULL)
{
LoadMempak(Control);
}
- memcpy(Buffer, &Mempaks[Control][Address], 0x20);
+ memcpy(&command[5], &Mempaks[Control][address], 0x20);
}
else
{
- memset(Buffer, 0, 0x20);
+ memset(&command[5], 0x00, 0x20);
/* Rumble pack area */
}
-
- Buffer[0x20] = CalculateCrc(Buffer);
}
-void Mempak::WriteTo(int Control, int Address, BYTE * Buffer)
+void Mempak::WriteTo(int Control, BYTE * command)
{
DWORD dwWritten;
+ DWORD address = (command[3] << 8) | (command[4] & 0xE0);
- if (Address < 0x8000)
+ if (address < 0x8000)
{
if (hMempakFile[Control] == NULL)
{
LoadMempak(Control);
}
- memcpy(&Mempaks[Control][Address], Buffer, 0x20);
+ memcpy(&Mempaks[Control][address], &command[5], 0x20);
SetFilePointer(hMempakFile[Control], 0,NULL,FILE_BEGIN);
WriteFile(hMempakFile[Control], &Mempaks[Control][0], 0x8000, &dwWritten, NULL);
@@ -165,5 +166,4 @@ void Mempak::WriteTo(int Control, int Address, BYTE * Buffer)
{
/* Rumble pack area */
}
- Buffer[0x20] = CalculateCrc(Buffer);
}
diff --git a/Source/Project64/N64 System/Mips/Pif Ram.cpp b/Source/Project64/N64 System/Mips/Pif Ram.cpp
index 436e269d7..3dacf5796 100644
--- a/Source/Project64/N64 System/Mips/Pif Ram.cpp
+++ b/Source/Project64/N64 System/Mips/Pif Ram.cpp
@@ -523,9 +523,11 @@ void CPifRam::ProcessControllerCommand ( int Control, BYTE * Command)
Command[4] = 0x00;
switch ( Controllers[Control].Plugin)
{
- case PLUGIN_RUMBLE_PAK: Command[5] = 1; break;
- case PLUGIN_MEMPAK: Command[5] = 1; break;
- case PLUGIN_RAW: Command[5] = 1; break;
+ case PLUGIN_TANSFER_PAK:
+ case PLUGIN_RUMBLE_PAK:
+ case PLUGIN_MEMPAK:
+ case PLUGIN_RAW:
+ Command[5] = 1; break;
default: Command[5] = 0; break;
}
}
@@ -569,19 +571,19 @@ void CPifRam::ProcessControllerCommand ( int Control, BYTE * Command)
}
if (Controllers[Control].Present == TRUE)
{
- DWORD address = ((Command[3] << 8) | Command[4] & 0xE0);
switch (Controllers[Control].Plugin)
{
- case PLUGIN_RUMBLE_PAK:
-
- memset(&Command[5], (address >= 0x8000 && address < 0x9000) ? 0x80 : 0x00, 0x20);
- Command[0x25] = Mempak::CalculateCrc(&Command[5]);
- break;
- case PLUGIN_MEMPAK: Mempak::ReadFrom(Control, address, &Command[5]); break;
+ case PLUGIN_RUMBLE_PAK: Rumblepak::ReadFrom(Command); break;
+ case PLUGIN_MEMPAK: Mempak::ReadFrom(Control, Command); break;
+ case PLUGIN_TANSFER_PAK: /* TODO */; break;
case PLUGIN_RAW: if (g_Plugins->Control()->ControllerCommand) { g_Plugins->Control()->ControllerCommand(Control, Command); } break;
default:
memset(&Command[5], 0, 0x20);
- Command[0x25] = 0;
+ }
+
+ if (Controllers[Control].Plugin != PLUGIN_RAW)
+ {
+ Command[0x25] = Mempak::CalculateCrc(&Command[5]);
}
}
else
@@ -611,17 +613,16 @@ void CPifRam::ProcessControllerCommand ( int Control, BYTE * Command)
}
if (Controllers[Control].Present == TRUE)
{
- DWORD address = ((Command[3] << 8) | Command[4] & 0xE0 );
switch (Controllers[Control].Plugin)
{
- case PLUGIN_MEMPAK: Mempak::WriteTo(Control, address, &Command[5]); break;
+ case PLUGIN_MEMPAK: Mempak::WriteTo(Control, Command); break;
+ case PLUGIN_RUMBLE_PAK: Rumblepak::WriteTo(Control, Command); break;
+ case PLUGIN_TANSFER_PAK: /* TODO */; break;
case PLUGIN_RAW: if (g_Plugins->Control()->ControllerCommand) { g_Plugins->Control()->ControllerCommand(Control, Command); } break;
- case PLUGIN_RUMBLE_PAK:
- if ((address & 0xFFE0) == 0xC000 && g_Plugins->Control()->RumbleCommand != NULL)
- {
- g_Plugins->Control()->RumbleCommand(Control, *(BOOL *)(&Command[5]));
- }
- default:
+ }
+
+ if (Controllers[Control].Plugin != PLUGIN_RAW)
+ {
Command[0x25] = Mempak::CalculateCrc(&Command[5]);
}
}
diff --git a/Source/Project64/N64 System/Mips/Rumblepak.cpp b/Source/Project64/N64 System/Mips/Rumblepak.cpp
new file mode 100644
index 000000000..51051cc6d
--- /dev/null
+++ b/Source/Project64/N64 System/Mips/Rumblepak.cpp
@@ -0,0 +1,38 @@
+/****************************************************************************
+* *
+* Project 64 - A Nintendo 64 emulator. *
+* http://www.pj64-emu.com/ *
+* Copyright (C) 2012 Project64. All rights reserved. *
+* *
+* License: *
+* GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html *
+* *
+****************************************************************************/
+#include "stdafx.h"
+
+void Rumblepak::ReadFrom(BYTE * command)
+{
+ DWORD address = (command[3] << 8) | (command[4] & 0xE0);
+
+ if ((address >= 0x8000) && (address < 0x9000))
+ {
+ memset(&command[5], 0x80, 0x20);
+ }
+ else
+ {
+ memset(&command[5], 0x00, 0x20);
+ }
+}
+
+void Rumblepak::WriteTo(int Control, BYTE * command)
+{
+ DWORD address = (command[3] << 8) | (command[4] & 0xE0);
+
+ if ((address) == 0xC000)
+ {
+ if (g_Plugins->Control()->RumbleCommand != NULL)
+ {
+ g_Plugins->Control()->RumbleCommand(Control, *(BOOL *)(&command[5]));
+ }
+ }
+}
\ No newline at end of file
diff --git a/Source/Project64/N64 System/Mips/Rumblepak.h b/Source/Project64/N64 System/Mips/Rumblepak.h
new file mode 100644
index 000000000..73b476c15
--- /dev/null
+++ b/Source/Project64/N64 System/Mips/Rumblepak.h
@@ -0,0 +1,19 @@
+/****************************************************************************
+* *
+* Project 64 - A Nintendo 64 emulator. *
+* http://www.pj64-emu.com/ *
+* Copyright (C) 2012 Project64. All rights reserved. *
+* *
+* License: *
+* GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html *
+* *
+****************************************************************************/
+#pragma once
+
+class Rumblepak
+{
+public:
+ static void ReadFrom(BYTE * command);
+ static void WriteTo(int Control, BYTE * command);
+
+};
diff --git a/Source/Project64/Project64.vcproj b/Source/Project64/Project64.vcproj
index 2d6ee3a02..5e7b84e54 100644
--- a/Source/Project64/Project64.vcproj
+++ b/Source/Project64/Project64.vcproj
@@ -467,6 +467,10 @@
RelativePath="N64 System\Mips\Memory Virtual Mem.cpp"
>
+
+
@@ -1115,6 +1119,10 @@
RelativePath="N64 System\Mips\Memory Virtual Mem.h"
>
+
+
diff --git a/Source/Project64/Project64.vcxproj b/Source/Project64/Project64.vcxproj
index a032f0e8d..c6df20064 100644
--- a/Source/Project64/Project64.vcxproj
+++ b/Source/Project64/Project64.vcxproj
@@ -39,6 +39,7 @@
+
Create
@@ -177,6 +178,7 @@
+
diff --git a/Source/Project64/Project64.vcxproj.filters b/Source/Project64/Project64.vcxproj.filters
index fe8ed54c1..2d16682fc 100644
--- a/Source/Project64/Project64.vcxproj.filters
+++ b/Source/Project64/Project64.vcxproj.filters
@@ -411,6 +411,9 @@
Source Files\Plugin Source
+
+ Source Files\N64 System Source\Mips Source
+
@@ -830,5 +833,8 @@
Header Files
+
+ Source Files\N64 System Source\Mips Source
+
\ No newline at end of file