Merge pull request #467 from death-droid/SeperateRumble

Seperate rumblepak out from pif ram.cpp. Makes it easier to make chan…
This commit is contained in:
zilmar 2015-05-18 15:11:48 +10:00
commit 832330b3af
9 changed files with 107 additions and 32 deletions

View File

@ -28,6 +28,7 @@ class CNotification;
#include "N64 System/Mips/OpCode.h" #include "N64 System/Mips/OpCode.h"
#include "N64 System/Recompiler/X86ops.h" #include "N64 System/Recompiler/X86ops.h"
#include "N64 System/Mips/Mempak.h" #include "N64 System/Mips/Mempak.h"
#include "N64 System/Mips/Rumblepak.h"
#include "N64 System/Mips/FlashRam.h" #include "N64 System/Mips/FlashRam.h"
#include "N64 System/Mips/Sram.h" #include "N64 System/Mips/Sram.h"
#include "N64 System/Mips/Eeprom.h" #include "N64 System/Mips/Eeprom.h"

View File

@ -15,7 +15,7 @@ class Mempak
public: public:
static void Close(); static void Close();
static BYTE CalculateCrc(BYTE * DataToCrc); static BYTE CalculateCrc(BYTE * DataToCrc);
static void ReadFrom(int Control, int Address, BYTE * Buffer); static void ReadFrom(int Control, BYTE * command);
static void WriteTo(int Control, int Address, BYTE * Buffer); static void WriteTo(int Control, BYTE * command);
}; };

View File

@ -106,7 +106,7 @@ BYTE Mempak::CalculateCrc(BYTE * DataToCrc)
{ {
for (Length = 0x80; Length >= 1; Length >>= 1) for (Length = 0x80; Length >= 1; Length >>= 1)
{ {
XorTap = (CRC & 0x80) ? 0x85 : 0; XorTap = (CRC & 0x80) ? 0x85 : 0x00;
CRC <<= 1; CRC <<= 1;
if (Count == 0x20) if (Count == 0x20)
{ {
@ -127,36 +127,37 @@ BYTE Mempak::CalculateCrc(BYTE * DataToCrc)
return CRC; 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) if (hMempakFile[Control] == NULL)
{ {
LoadMempak(Control); LoadMempak(Control);
} }
memcpy(Buffer, &Mempaks[Control][Address], 0x20); memcpy(&command[5], &Mempaks[Control][address], 0x20);
} }
else else
{ {
memset(Buffer, 0, 0x20); memset(&command[5], 0x00, 0x20);
/* Rumble pack area */ /* 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 dwWritten;
DWORD address = (command[3] << 8) | (command[4] & 0xE0);
if (Address < 0x8000) if (address < 0x8000)
{ {
if (hMempakFile[Control] == NULL) if (hMempakFile[Control] == NULL)
{ {
LoadMempak(Control); LoadMempak(Control);
} }
memcpy(&Mempaks[Control][Address], Buffer, 0x20); memcpy(&Mempaks[Control][address], &command[5], 0x20);
SetFilePointer(hMempakFile[Control], 0,NULL,FILE_BEGIN); SetFilePointer(hMempakFile[Control], 0,NULL,FILE_BEGIN);
WriteFile(hMempakFile[Control], &Mempaks[Control][0], 0x8000, &dwWritten, NULL); 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 */ /* Rumble pack area */
} }
Buffer[0x20] = CalculateCrc(Buffer);
} }

View File

@ -523,9 +523,11 @@ void CPifRam::ProcessControllerCommand ( int Control, BYTE * Command)
Command[4] = 0x00; Command[4] = 0x00;
switch ( Controllers[Control].Plugin) switch ( Controllers[Control].Plugin)
{ {
case PLUGIN_RUMBLE_PAK: Command[5] = 1; break; case PLUGIN_TANSFER_PAK:
case PLUGIN_MEMPAK: Command[5] = 1; break; case PLUGIN_RUMBLE_PAK:
case PLUGIN_RAW: Command[5] = 1; break; case PLUGIN_MEMPAK:
case PLUGIN_RAW:
Command[5] = 1; break;
default: Command[5] = 0; break; default: Command[5] = 0; break;
} }
} }
@ -569,19 +571,19 @@ void CPifRam::ProcessControllerCommand ( int Control, BYTE * Command)
} }
if (Controllers[Control].Present == TRUE) if (Controllers[Control].Present == TRUE)
{ {
DWORD address = ((Command[3] << 8) | Command[4] & 0xE0);
switch (Controllers[Control].Plugin) switch (Controllers[Control].Plugin)
{ {
case PLUGIN_RUMBLE_PAK: case PLUGIN_RUMBLE_PAK: Rumblepak::ReadFrom(Command); break;
case PLUGIN_MEMPAK: Mempak::ReadFrom(Control, Command); break;
memset(&Command[5], (address >= 0x8000 && address < 0x9000) ? 0x80 : 0x00, 0x20); case PLUGIN_TANSFER_PAK: /* TODO */; break;
Command[0x25] = Mempak::CalculateCrc(&Command[5]);
break;
case PLUGIN_MEMPAK: Mempak::ReadFrom(Control, address, &Command[5]); 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:
memset(&Command[5], 0, 0x20); memset(&Command[5], 0, 0x20);
Command[0x25] = 0; }
if (Controllers[Control].Plugin != PLUGIN_RAW)
{
Command[0x25] = Mempak::CalculateCrc(&Command[5]);
} }
} }
else else
@ -611,17 +613,16 @@ void CPifRam::ProcessControllerCommand ( int Control, BYTE * Command)
} }
if (Controllers[Control].Present == TRUE) if (Controllers[Control].Present == TRUE)
{ {
DWORD address = ((Command[3] << 8) | Command[4] & 0xE0 );
switch (Controllers[Control].Plugin) 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_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)
{ if (Controllers[Control].Plugin != PLUGIN_RAW)
g_Plugins->Control()->RumbleCommand(Control, *(BOOL *)(&Command[5])); {
}
default:
Command[0x25] = Mempak::CalculateCrc(&Command[5]); Command[0x25] = Mempak::CalculateCrc(&Command[5]);
} }
} }

View File

@ -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]));
}
}
}

View File

@ -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);
};

View File

@ -467,6 +467,10 @@
RelativePath="N64 System\Mips\Memory Virtual Mem.cpp" RelativePath="N64 System\Mips\Memory Virtual Mem.cpp"
> >
</File> </File>
<File
RelativePath=".\N64 System\Mips\Rumblepak.cpp"
>
</File>
<File <File
RelativePath=".\N64 System\Mips\Mempak.cpp" RelativePath=".\N64 System\Mips\Mempak.cpp"
> >
@ -1115,6 +1119,10 @@
RelativePath="N64 System\Mips\Memory Virtual Mem.h" RelativePath="N64 System\Mips\Memory Virtual Mem.h"
> >
</File> </File>
<File
RelativePath=".\N64 System\Mips\Rumblepak.h"
>
</File>
<File <File
RelativePath=".\N64 System\Mips\Mempak.H" RelativePath=".\N64 System\Mips\Mempak.H"
> >

View File

@ -39,6 +39,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="main.cpp" /> <ClCompile Include="main.cpp" />
<ClCompile Include="N64 System\Mips\Rumblepak.cpp" />
<ClCompile Include="Plugins\Plugin Base.cpp" /> <ClCompile Include="Plugins\Plugin Base.cpp" />
<ClCompile Include="stdafx.cpp"> <ClCompile Include="stdafx.cpp">
<PrecompiledHeader>Create</PrecompiledHeader> <PrecompiledHeader>Create</PrecompiledHeader>
@ -177,6 +178,7 @@
<ItemGroup> <ItemGroup>
<ClInclude Include="Multilanguage.h" /> <ClInclude Include="Multilanguage.h" />
<ClInclude Include="N64 System.h" /> <ClInclude Include="N64 System.h" />
<ClInclude Include="N64 System\Mips\Rumblepak.h" />
<ClInclude Include="Plugin.h" /> <ClInclude Include="Plugin.h" />
<ClInclude Include="Plugins\Plugin Base.h" /> <ClInclude Include="Plugins\Plugin Base.h" />
<ClInclude Include="Settings.h" /> <ClInclude Include="Settings.h" />

View File

@ -411,6 +411,9 @@
<ClCompile Include="Plugins\Plugin Base.cpp"> <ClCompile Include="Plugins\Plugin Base.cpp">
<Filter>Source Files\Plugin Source</Filter> <Filter>Source Files\Plugin Source</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="N64 System\Mips\Rumblepak.cpp">
<Filter>Source Files\N64 System Source\Mips Source</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Image Include="User Interface\Bitmaps\AboutScreenBottom.bmp"> <Image Include="User Interface\Bitmaps\AboutScreenBottom.bmp">
@ -830,5 +833,8 @@
<ClInclude Include="Version.h"> <ClInclude Include="Version.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="N64 System\Mips\Rumblepak.h">
<Filter>Source Files\N64 System Source\Mips Source</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>