Seperate rumblepak out from pif ram.cpp. Makes it easier to make changes to and cleans up Pif Ram.cpp

Also prepare for implementing the transfer pak.
This commit is contained in:
Emmet Young 2015-05-18 12:20:15 +10:00
parent 0c8d500328
commit a89f1d29f5
9 changed files with 110 additions and 32 deletions

View File

@ -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"

View File

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

View File

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

View File

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

View File

@ -0,0 +1,41 @@
/****************************************************************************
* *
* 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)
{
unsigned char data;
int address = (command[3] << 8) | (command[4] & 0xE0);
if ((address >= 0x8000) && (address < 0x9000))
{
data = 0x80;
}
else
{
data = 0x00;
}
memset(&command[5], data, 0x20);
}
void Rumblepak::WriteTo(int Control, BYTE * command)
{
int 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"
>
</File>
<File
RelativePath=".\N64 System\Mips\Rumblepak.cpp"
>
</File>
<File
RelativePath=".\N64 System\Mips\Mempak.cpp"
>
@ -1115,6 +1119,10 @@
RelativePath="N64 System\Mips\Memory Virtual Mem.h"
>
</File>
<File
RelativePath=".\N64 System\Mips\Rumblepak.h"
>
</File>
<File
RelativePath=".\N64 System\Mips\Mempak.H"
>

View File

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

View File

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