Finishing up on refactoring of the "C Core Interface.cpp" file
Added a 'header guard' to 7zip.h to stop multiple definitions TODO: Refactor/clean up Mempak.cpp more
This commit is contained in:
parent
15894a0e6c
commit
730655dda2
|
@ -1,3 +1,6 @@
|
|||
#ifndef _7ZIP_H_
|
||||
#define _7ZIP_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -57,4 +60,6 @@ public:
|
|||
inline int FileSize ( void ) const { return m_FileSize; }
|
||||
|
||||
void SetNotificationCallback (LP7ZNOTIFICATION NotfyFnc, void * CBInfo);
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
|
@ -19,6 +19,7 @@ class CNotification;
|
|||
#include "N64 System/Mips/OpCode.h"
|
||||
#include "N64 System/Mips/OpCode Analysis Class.h"
|
||||
#include "N64 System/Recompiler/X86ops.h"
|
||||
#include "N64 System/Mips/Mempak.h"
|
||||
#include "N64 System/Mips/FlashRam.h"
|
||||
#include "N64 System/Mips/Sram.h"
|
||||
#include "N64 System/Mips/Eeprom.h"
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
#include "stdafx.h"
|
||||
#include "mempak.h"
|
||||
#include "Logging.h"
|
||||
|
||||
//settings
|
||||
enum SAVE_CHIP_TYPE g_SaveUsing;
|
||||
|
||||
void CC_Core::SetSettings ( )
|
||||
{
|
||||
if (_Settings)
|
||||
{
|
||||
g_SaveUsing = (SAVE_CHIP_TYPE)_Settings->LoadDword(Game_SaveChip);
|
||||
}
|
||||
}
|
||||
|
||||
void CloseSaveChips ( void )
|
||||
{
|
||||
CloseMempak();
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
class CC_Core
|
||||
{
|
||||
public:
|
||||
static void SetSettings ( );
|
||||
};
|
||||
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "..\\Types.h"
|
||||
|
||||
void CloseSaveChips ( void );
|
||||
|
||||
//settings
|
||||
extern enum SAVE_CHIP_TYPE g_SaveUsing;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -1,29 +0,0 @@
|
|||
/*
|
||||
* Project 64 - A Nintendo 64 emulator.
|
||||
*
|
||||
* (c) Copyright 2001 zilmar (zilmar@emulation64.com) and
|
||||
* Jabo (jabo@emulation64.com).
|
||||
*
|
||||
* pj64 homepage: www.pj64.net
|
||||
*
|
||||
* Permission to use, copy, modify and distribute Project64 in both binary and
|
||||
* source form, for non-commercial purposes, is hereby granted without fee,
|
||||
* providing that this license information and copyright notice appear with
|
||||
* all copies and any derived work.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event shall the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Project64 is freeware for PERSONAL USE only. Commercial users should
|
||||
* seek permission of the copyright holders first. Commercial use includes
|
||||
* charging money for Project64 or software derived from Project64.
|
||||
*
|
||||
* The copyright holders request that bug fixes and improvements to the code
|
||||
* should be forwarded to them so if they want them.
|
||||
*
|
||||
*/
|
||||
void CloseMempak ( void );
|
||||
BYTE Mempacks_CalulateCrc ( BYTE * DataToCrc );
|
||||
void ReadFromMempak ( int Control, int Address, BYTE * Buffer );
|
||||
void WriteToMempak ( int Control, int Address, BYTE * Buffer );
|
|
@ -31,8 +31,8 @@ void CDMA::PI_DMA_READ (void) {
|
|||
}
|
||||
|
||||
if ( _Reg->PI_CART_ADDR_REG >= 0x08000000 && _Reg->PI_CART_ADDR_REG <= 0x08010000) {
|
||||
if (g_SaveUsing == SaveChip_Auto) { g_SaveUsing = SaveChip_Sram; }
|
||||
if (g_SaveUsing == SaveChip_Sram) {
|
||||
if (_System->m_SaveUsing == SaveChip_Auto) { _System->m_SaveUsing = SaveChip_Sram; }
|
||||
if (_System->m_SaveUsing == SaveChip_Sram) {
|
||||
m_Sram.DmaToSram(
|
||||
_MMU->Rdram() + _Reg->PI_DRAM_ADDR_REG,
|
||||
_Reg->PI_CART_ADDR_REG - 0x08000000,
|
||||
|
@ -43,7 +43,7 @@ void CDMA::PI_DMA_READ (void) {
|
|||
_Reg->CheckInterrupts();
|
||||
return;
|
||||
}
|
||||
if (g_SaveUsing == SaveChip_FlashRam) {
|
||||
if (_System->m_SaveUsing == SaveChip_FlashRam) {
|
||||
m_FlashRam.DmaToFlashram(
|
||||
_MMU->Rdram()+_Reg->PI_DRAM_ADDR_REG,
|
||||
_Reg->PI_CART_ADDR_REG - 0x08000000,
|
||||
|
@ -55,7 +55,7 @@ void CDMA::PI_DMA_READ (void) {
|
|||
return;
|
||||
}
|
||||
}
|
||||
if (g_SaveUsing == SaveChip_FlashRam)
|
||||
if (_System->m_SaveUsing == SaveChip_FlashRam)
|
||||
{
|
||||
_Notify->DisplayError("**** FLashRam DMA Read address %X *****",_Reg->PI_CART_ADDR_REG);
|
||||
_Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY;
|
||||
|
@ -85,8 +85,8 @@ void CDMA::PI_DMA_WRITE (void) {
|
|||
}
|
||||
|
||||
if ( _Reg->PI_CART_ADDR_REG >= 0x08000000 && _Reg->PI_CART_ADDR_REG <= 0x08010000) {
|
||||
if (g_SaveUsing == SaveChip_Auto) { g_SaveUsing = SaveChip_Sram; }
|
||||
if (g_SaveUsing == SaveChip_Sram) {
|
||||
if (_System->m_SaveUsing == SaveChip_Auto) { _System->m_SaveUsing = SaveChip_Sram; }
|
||||
if (_System->m_SaveUsing == SaveChip_Sram) {
|
||||
m_Sram.DmaFromSram(
|
||||
_MMU->Rdram()+_Reg->PI_DRAM_ADDR_REG,
|
||||
_Reg->PI_CART_ADDR_REG - 0x08000000,
|
||||
|
@ -97,7 +97,7 @@ void CDMA::PI_DMA_WRITE (void) {
|
|||
_Reg->CheckInterrupts();
|
||||
return;
|
||||
}
|
||||
if (g_SaveUsing == SaveChip_FlashRam) {
|
||||
if (_System->m_SaveUsing == SaveChip_FlashRam) {
|
||||
m_FlashRam.DmaFromFlashram(
|
||||
_MMU->Rdram()+_Reg->PI_DRAM_ADDR_REG,
|
||||
_Reg->PI_CART_ADDR_REG - 0x08000000,
|
||||
|
|
|
@ -26,11 +26,11 @@ void CEeprom::EepromCommand ( BYTE * Command) {
|
|||
time_t curtime_time;
|
||||
struct tm curtime;
|
||||
|
||||
if (g_SaveUsing == SaveChip_Auto) { g_SaveUsing = SaveChip_Eeprom_4K; }
|
||||
if (_System->m_SaveUsing == SaveChip_Auto) { _System->m_SaveUsing = SaveChip_Eeprom_4K; }
|
||||
|
||||
switch (Command[2]) {
|
||||
case 0: // check
|
||||
if (g_SaveUsing != SaveChip_Eeprom_4K && g_SaveUsing != SaveChip_Eeprom_16K) {
|
||||
if (_System->m_SaveUsing != SaveChip_Eeprom_4K && _System->m_SaveUsing != SaveChip_Eeprom_16K) {
|
||||
Command[1] |= 0x80;
|
||||
break;
|
||||
}
|
||||
|
@ -40,12 +40,12 @@ void CEeprom::EepromCommand ( BYTE * Command) {
|
|||
if ((Command[1] & 3) > 0)
|
||||
Command[3] = 0x00;
|
||||
if ((Command[1] & 3) > 1)
|
||||
Command[4] = (g_SaveUsing == SaveChip_Eeprom_4K) ? 0x80 : 0xC0;
|
||||
Command[4] = (_System->m_SaveUsing == SaveChip_Eeprom_4K) ? 0x80 : 0xC0;
|
||||
if ((Command[1] & 3) > 2)
|
||||
Command[5] = 0x00;
|
||||
} else {
|
||||
Command[3] = 0x00;
|
||||
Command[4] = g_SaveUsing == SaveChip_Eeprom_4K?0x80:0xC0;
|
||||
Command[4] = _System->m_SaveUsing == SaveChip_Eeprom_4K?0x80:0xC0;
|
||||
Command[5] = 0x00;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -1806,8 +1806,8 @@ int CMipsMemoryVM::LW_NonMemory ( DWORD PAddr, DWORD * Value ) {
|
|||
*Value = (*Value << 16) | *Value;
|
||||
return FALSE;
|
||||
case 0x08000000:
|
||||
if (g_SaveUsing == SaveChip_Auto) { g_SaveUsing = SaveChip_FlashRam; }
|
||||
if (g_SaveUsing != SaveChip_FlashRam) {
|
||||
if (_System->m_SaveUsing == SaveChip_Auto) { _System->m_SaveUsing = SaveChip_FlashRam; }
|
||||
if (_System->m_SaveUsing != SaveChip_FlashRam) {
|
||||
*Value = PAddr & 0xFFFF;
|
||||
*Value = (*Value << 16) | *Value;
|
||||
return FALSE;
|
||||
|
@ -2284,8 +2284,9 @@ int CMipsMemoryVM::SW_NonMemory ( DWORD PAddr, DWORD Value ) {
|
|||
break;
|
||||
case 0x08000000:
|
||||
if (PAddr != 0x08010000) { return FALSE; }
|
||||
if (g_SaveUsing == SaveChip_Auto) { g_SaveUsing = SaveChip_FlashRam; }
|
||||
if (g_SaveUsing != SaveChip_FlashRam) { return TRUE; }
|
||||
if (_System->m_SaveUsing == SaveChip_Auto) { _System->m_SaveUsing = SaveChip_FlashRam; }
|
||||
if (_System->m_SaveUsing != SaveChip_FlashRam) { return TRUE; }
|
||||
|
||||
WriteToFlashCommand(Value);
|
||||
return TRUE;
|
||||
break;
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
#ifndef _MEMPAK_H_
|
||||
#define _MEMPAK_H_
|
||||
|
||||
class Mempak
|
||||
{
|
||||
public:
|
||||
static void Close ( void );
|
||||
static BYTE CalculateCrc ( BYTE * DataToCrc );
|
||||
static void ReadFrom ( int Control, int Address, BYTE * Buffer );
|
||||
static void WriteTo ( int Control, int Address, BYTE * Buffer );
|
||||
|
||||
};
|
||||
#endif //_MEMPAK_H_
|
|
@ -1,135 +1,134 @@
|
|||
#include "stdafx.h"
|
||||
|
||||
static BYTE Mempak[4][0x8000];
|
||||
static HANDLE hMempakFile = NULL;
|
||||
|
||||
void CloseMempak (void) {
|
||||
if (hMempakFile) {
|
||||
CloseHandle(hMempakFile);
|
||||
hMempakFile = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void LoadMempak (void) {
|
||||
char File[256], Directory[256];
|
||||
DWORD dwRead, count, count2;
|
||||
|
||||
BYTE Initilize[] = {
|
||||
0x81,0x01,0x02,0x03, 0x04,0x05,0x06,0x07, 0x08,0x09,0x0a,0x0b, 0x0C,0x0D,0x0E,0x0F,
|
||||
0x10,0x11,0x12,0x13, 0x14,0x15,0x16,0x17, 0x18,0x19,0x1A,0x1B, 0x1C,0x1D,0x1E,0x1F,
|
||||
0xFF,0xFF,0xFF,0xFF, 0x05,0x1A,0x5F,0x13, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
|
||||
0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0x01,0xFF, 0x66,0x25,0x99,0xCD,
|
||||
0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
|
||||
0xFF,0xFF,0xFF,0xFF, 0x05,0x1A,0x5F,0x13, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
|
||||
0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0x01,0xFF, 0x66,0x25,0x99,0xCD,
|
||||
0xFF,0xFF,0xFF,0xFF, 0x05,0x1A,0x5F,0x13, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
|
||||
0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0x01,0xFF, 0x66,0x25,0x99,0xCD,
|
||||
0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
|
||||
0xFF,0xFF,0xFF,0xFF, 0x05,0x1A,0x5F,0x13, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
|
||||
0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0x01,0xFF, 0x66,0x25,0x99,0xCD,
|
||||
0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
|
||||
0x00,0x71,0x00,0x03, 0x00,0x03,0x00,0x03, 0x00,0x03,0x00,0x03, 0x00,0x03,0x00,0x03,
|
||||
};
|
||||
for (count = 0; count < 4; count ++) {
|
||||
for (count2 = 0; count2 < 0x8000; count2 += 2) {
|
||||
Mempak[count][count2] = 0x00;
|
||||
Mempak[count][count2 + 1] = 0x03;
|
||||
}
|
||||
memcpy(&Mempak[count][0],Initilize,sizeof(Initilize));
|
||||
}
|
||||
|
||||
strcpy(Directory,_Settings->LoadString(Directory_NativeSave).c_str());
|
||||
sprintf(File,"%s%s.mpk",Directory,_Settings->LoadString(Game_GameName).c_str());
|
||||
|
||||
hMempakFile = CreateFile(File,GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ,NULL,OPEN_ALWAYS,
|
||||
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL);
|
||||
if (hMempakFile == INVALID_HANDLE_VALUE) {
|
||||
switch (GetLastError()) {
|
||||
case ERROR_PATH_NOT_FOUND:
|
||||
CreateDirectory(Directory,NULL);
|
||||
hMempakFile = CreateFile(File,GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ,
|
||||
NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL);
|
||||
if (hMempakFile == INVALID_HANDLE_VALUE) {
|
||||
_Notify->DisplayError(GS(MSG_FAIL_OPEN_MEMPAK));
|
||||
}
|
||||
return;
|
||||
break;
|
||||
default:
|
||||
_Notify->DisplayError(GS(MSG_FAIL_OPEN_MEMPAK));
|
||||
return;
|
||||
}
|
||||
}
|
||||
SetFilePointer(hMempakFile,0,NULL,FILE_BEGIN);
|
||||
ReadFile(hMempakFile,Mempak,sizeof(Mempak),&dwRead,NULL);
|
||||
WriteFile(hMempakFile,Mempak,sizeof(Mempak),&dwRead,NULL);
|
||||
}
|
||||
|
||||
BYTE Mempacks_CalulateCrc(BYTE * DataToCrc) {
|
||||
DWORD Count;
|
||||
DWORD XorTap;
|
||||
|
||||
int Length;
|
||||
BYTE CRC = 0;
|
||||
|
||||
for (Count = 0; Count < 0x21; Count++) {
|
||||
for (Length = 0x80; Length >= 1; Length >>= 1) {
|
||||
XorTap = (CRC & 0x80) ? 0x85 : 0;
|
||||
CRC <<= 1;
|
||||
if (Count == 0x20) {
|
||||
CRC &= 0xFF;
|
||||
} else {
|
||||
if ((*DataToCrc & Length) != 0) {
|
||||
CRC |= 1;
|
||||
}
|
||||
}
|
||||
CRC ^= XorTap;
|
||||
}
|
||||
DataToCrc++;
|
||||
}
|
||||
|
||||
return CRC;
|
||||
}
|
||||
|
||||
void ReadFromMempak(int Control, int Address, BYTE * Buffer) {
|
||||
if (Address == 0x8001) {
|
||||
memset(Buffer, 0, 0x20);
|
||||
Buffer[0x20] = Mempacks_CalulateCrc(Buffer);
|
||||
return;
|
||||
}
|
||||
Address &= 0xFFE0;
|
||||
|
||||
if (Address <= 0x7FE0) {
|
||||
if (hMempakFile == NULL) {
|
||||
LoadMempak();
|
||||
}
|
||||
memcpy(Buffer, &Mempak[Control][Address], 0x20);
|
||||
} else {
|
||||
memset(Buffer, 0, 0x20);
|
||||
/* Rumble pack area */
|
||||
}
|
||||
|
||||
Buffer[0x20] = Mempacks_CalulateCrc(Buffer);
|
||||
}
|
||||
|
||||
void WriteToMempak(int Control, int Address, BYTE * Buffer) {
|
||||
DWORD dwWritten;
|
||||
|
||||
if (Address == 0x8001) { Buffer[0x20] = Mempacks_CalulateCrc(Buffer); return; }
|
||||
|
||||
Address &= 0xFFE0;
|
||||
if (Address <= 0x7FE0) {
|
||||
if (hMempakFile == NULL) {
|
||||
LoadMempak();
|
||||
}
|
||||
memcpy(&Mempak[Control][Address], Buffer, 0x20);
|
||||
|
||||
SetFilePointer(hMempakFile,Control*0x8000,NULL,FILE_BEGIN);
|
||||
WriteFile(hMempakFile,&Mempak[Control][0],0x8000,&dwWritten,NULL);
|
||||
} else {
|
||||
/* Rumble pack area */
|
||||
}
|
||||
Buffer[0x20] = Mempacks_CalulateCrc(Buffer);
|
||||
#include "stdafx.h"
|
||||
static BYTE Mempaks[4][0x8000];
|
||||
HANDLE hMempakFile = NULL;
|
||||
|
||||
void Mempak::Close(void) {
|
||||
if (hMempakFile) {
|
||||
CloseHandle(hMempakFile);
|
||||
hMempakFile = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void LoadMempak (void) {
|
||||
char File[256], Directory[256];
|
||||
DWORD dwRead, count, count2;
|
||||
|
||||
BYTE Initilize[] = {
|
||||
0x81,0x01,0x02,0x03, 0x04,0x05,0x06,0x07, 0x08,0x09,0x0a,0x0b, 0x0C,0x0D,0x0E,0x0F,
|
||||
0x10,0x11,0x12,0x13, 0x14,0x15,0x16,0x17, 0x18,0x19,0x1A,0x1B, 0x1C,0x1D,0x1E,0x1F,
|
||||
0xFF,0xFF,0xFF,0xFF, 0x05,0x1A,0x5F,0x13, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
|
||||
0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0x01,0xFF, 0x66,0x25,0x99,0xCD,
|
||||
0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
|
||||
0xFF,0xFF,0xFF,0xFF, 0x05,0x1A,0x5F,0x13, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
|
||||
0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0x01,0xFF, 0x66,0x25,0x99,0xCD,
|
||||
0xFF,0xFF,0xFF,0xFF, 0x05,0x1A,0x5F,0x13, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
|
||||
0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0x01,0xFF, 0x66,0x25,0x99,0xCD,
|
||||
0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
|
||||
0xFF,0xFF,0xFF,0xFF, 0x05,0x1A,0x5F,0x13, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
|
||||
0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0x01,0xFF, 0x66,0x25,0x99,0xCD,
|
||||
0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
|
||||
0x00,0x71,0x00,0x03, 0x00,0x03,0x00,0x03, 0x00,0x03,0x00,0x03, 0x00,0x03,0x00,0x03,
|
||||
};
|
||||
for (count = 0; count < 4; count ++) {
|
||||
for (count2 = 0; count2 < 0x8000; count2 += 2) {
|
||||
Mempaks[count][count2] = 0x00;
|
||||
Mempaks[count][count2 + 1] = 0x03;
|
||||
}
|
||||
memcpy(&Mempaks[count][0],Initilize,sizeof(Initilize));
|
||||
}
|
||||
|
||||
strcpy(Directory,_Settings->LoadString(Directory_NativeSave).c_str());
|
||||
sprintf(File,"%s%s.mpk",Directory,_Settings->LoadString(Game_GameName).c_str());
|
||||
|
||||
hMempakFile = CreateFile(File,GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ,NULL,OPEN_ALWAYS,
|
||||
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL);
|
||||
if (hMempakFile == INVALID_HANDLE_VALUE) {
|
||||
switch (GetLastError()) {
|
||||
case ERROR_PATH_NOT_FOUND:
|
||||
CreateDirectory(Directory,NULL);
|
||||
hMempakFile = CreateFile(File,GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ,
|
||||
NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL);
|
||||
if (hMempakFile == INVALID_HANDLE_VALUE) {
|
||||
_Notify->DisplayError(GS(MSG_FAIL_OPEN_MEMPAK));
|
||||
}
|
||||
return;
|
||||
break;
|
||||
default:
|
||||
_Notify->DisplayError(GS(MSG_FAIL_OPEN_MEMPAK));
|
||||
return;
|
||||
}
|
||||
}
|
||||
SetFilePointer(hMempakFile,0,NULL,FILE_BEGIN);
|
||||
ReadFile(hMempakFile,Mempaks,sizeof(Mempaks),&dwRead,NULL);
|
||||
WriteFile(hMempakFile,Mempaks,sizeof(Mempaks),&dwRead,NULL);
|
||||
}
|
||||
|
||||
BYTE Mempak::CalculateCrc(BYTE * DataToCrc) {
|
||||
DWORD Count;
|
||||
DWORD XorTap;
|
||||
|
||||
int Length;
|
||||
BYTE CRC = 0;
|
||||
|
||||
for (Count = 0; Count < 0x21; Count++) {
|
||||
for (Length = 0x80; Length >= 1; Length >>= 1) {
|
||||
XorTap = (CRC & 0x80) ? 0x85 : 0;
|
||||
CRC <<= 1;
|
||||
if (Count == 0x20) {
|
||||
CRC &= 0xFF;
|
||||
} else {
|
||||
if ((*DataToCrc & Length) != 0) {
|
||||
CRC |= 1;
|
||||
}
|
||||
}
|
||||
CRC ^= XorTap;
|
||||
}
|
||||
DataToCrc++;
|
||||
}
|
||||
|
||||
return CRC;
|
||||
}
|
||||
|
||||
void Mempak::ReadFrom(int Control, int Address, BYTE * Buffer) {
|
||||
if (Address == 0x8001) {
|
||||
memset(Buffer, 0, 0x20);
|
||||
Buffer[0x20] = CalculateCrc(Buffer);
|
||||
return;
|
||||
}
|
||||
Address &= 0xFFE0;
|
||||
|
||||
if (Address <= 0x7FE0) {
|
||||
if (hMempakFile == NULL) {
|
||||
LoadMempak();
|
||||
}
|
||||
memcpy(Buffer, &Mempaks[Control][Address], 0x20);
|
||||
} else {
|
||||
memset(Buffer, 0, 0x20);
|
||||
/* Rumble pack area */
|
||||
}
|
||||
|
||||
Buffer[0x20] = CalculateCrc(Buffer);
|
||||
}
|
||||
|
||||
void Mempak::WriteTo(int Control, int Address, BYTE * Buffer) {
|
||||
DWORD dwWritten;
|
||||
|
||||
if (Address == 0x8001) { Buffer[0x20] = CalculateCrc(Buffer); return; }
|
||||
|
||||
Address &= 0xFFE0;
|
||||
if (Address <= 0x7FE0) {
|
||||
if (hMempakFile == NULL) {
|
||||
LoadMempak();
|
||||
}
|
||||
memcpy(&Mempaks[Control][Address], Buffer, 0x20);
|
||||
|
||||
SetFilePointer(hMempakFile,Control*0x8000,NULL,FILE_BEGIN);
|
||||
WriteFile(hMempakFile,&Mempaks[Control][0],0x8000,&dwWritten,NULL);
|
||||
} else {
|
||||
/* Rumble pack area */
|
||||
}
|
||||
Buffer[0x20] = CalculateCrc(Buffer);
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
#include "stdafx.h"
|
||||
#include "../C Core/mempak.h"
|
||||
|
||||
int CPifRamSettings::m_RefCount = 0;
|
||||
bool CPifRamSettings::m_bShowPifRamErrors = false;
|
||||
|
@ -448,10 +447,11 @@ void CPifRam::ProcessControllerCommand ( int Control, BYTE * Command)
|
|||
DWORD address = ((Command[3] << 8) | Command[4]);
|
||||
switch (Controllers[Control].Plugin) {
|
||||
case PLUGIN_RUMBLE_PAK:
|
||||
|
||||
memset(&Command[5], (address >= 0x8000 && address < 0x9000) ? 0x80 : 0x00, 0x20);
|
||||
Command[0x25] = Mempacks_CalulateCrc(&Command[5]);
|
||||
Command[0x25] = Mempak::CalculateCrc(&Command[5]);
|
||||
break;
|
||||
case PLUGIN_MEMPAK: ReadFromMempak(Control, address, &Command[5]); break;
|
||||
case PLUGIN_MEMPAK: Mempak::ReadFrom(Control, address, &Command[5]); break;
|
||||
case PLUGIN_RAW: if (_Plugins->Control()->ControllerCommand) { _Plugins->Control()->ControllerCommand(Control, Command); } break;
|
||||
default:
|
||||
memset(&Command[5], 0, 0x20);
|
||||
|
@ -476,14 +476,14 @@ void CPifRam::ProcessControllerCommand ( int Control, BYTE * Command)
|
|||
if (Controllers[Control].Present == TRUE) {
|
||||
DWORD address = ((Command[3] << 8) | Command[4]);
|
||||
switch (Controllers[Control].Plugin) {
|
||||
case PLUGIN_MEMPAK: WriteToMempak(Control, address, &Command[5]); break;
|
||||
case PLUGIN_MEMPAK: Mempak::WriteTo(Control, address, &Command[5]); break;
|
||||
case PLUGIN_RAW: if (_Plugins->Control()->ControllerCommand) { _Plugins->Control()->ControllerCommand(Control, Command); } break;
|
||||
case PLUGIN_RUMBLE_PAK:
|
||||
if ((address & 0xFFE0) == 0xC000 && _Plugins->Control()->RumbleCommand != NULL) {
|
||||
_Plugins->Control()->RumbleCommand(Control, *(BOOL *)(&Command[5]));
|
||||
}
|
||||
default:
|
||||
Command[0x25] = Mempacks_CalulateCrc(&Command[5]);
|
||||
Command[0x25] = Mempak::CalculateCrc(&Command[5]);
|
||||
}
|
||||
} else {
|
||||
Command[1] |= 0x80;
|
||||
|
|
|
@ -478,7 +478,7 @@ void CN64System::Reset (bool bInitReg, bool ClearMenory)
|
|||
m_Audio.Reset();
|
||||
m_MMU_VM.Reset(ClearMenory);
|
||||
Debug_Reset();
|
||||
CloseSaveChips();
|
||||
Mempak::Close();
|
||||
|
||||
m_CyclesToSkip = 0;
|
||||
m_AlistCount = 0;
|
||||
|
@ -781,27 +781,26 @@ void CN64System::ExecuteCPU ( void )
|
|||
//Check me
|
||||
// _Rom->m_RomFileSize = _Rom->GetRomSize();
|
||||
|
||||
CC_Core C_Core;
|
||||
C_Core.SetSettings();
|
||||
m_SaveUsing = (SAVE_CHIP_TYPE)_Settings->LoadDword(Game_SaveChip);
|
||||
|
||||
CInterpreterCPU::BuildCPU();
|
||||
|
||||
switch ((CPU_TYPE)_Settings->LoadDword(Game_CpuType)) {
|
||||
case CPU_Recompiler: ExecuteRecompiler(C_Core); break;
|
||||
case CPU_SyncCores: ExecuteSyncCPU(C_Core); break;
|
||||
default: ExecuteInterpret(C_Core); break;
|
||||
case CPU_Recompiler: ExecuteRecompiler(); break;
|
||||
case CPU_SyncCores: ExecuteSyncCPU(); break;
|
||||
default: ExecuteInterpret(); break;
|
||||
}
|
||||
CpuStopped();
|
||||
SetActiveSystem(false);
|
||||
}
|
||||
|
||||
void CN64System::ExecuteInterpret (CC_Core & C_Core) {
|
||||
void CN64System::ExecuteInterpret () {
|
||||
InitializeCPUCore();
|
||||
SetActiveSystem();
|
||||
CInterpreterCPU::ExecuteCPU();
|
||||
}
|
||||
|
||||
void CN64System::ExecuteRecompiler (CC_Core & C_Core)
|
||||
void CN64System::ExecuteRecompiler ()
|
||||
{
|
||||
//execute opcodes while no errors
|
||||
InitializeCPUCore();
|
||||
|
@ -810,7 +809,7 @@ void CN64System::ExecuteRecompiler (CC_Core & C_Core)
|
|||
m_Recomp->Run();
|
||||
}
|
||||
|
||||
void CN64System::ExecuteSyncCPU (CC_Core & C_Core)
|
||||
void CN64System::ExecuteSyncCPU ()
|
||||
{
|
||||
_Notify->DisplayMessage(5,"Copy Plugins");
|
||||
_Plugins->CopyPlugins(_Settings->LoadString(Directory_PluginSync));
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#pragma once
|
||||
#ifndef _N64CLASS_H_
|
||||
#define _N64CLASS_H_
|
||||
|
||||
typedef std::list<SystemEvent> EVENT_LIST;
|
||||
|
||||
|
@ -32,6 +33,7 @@ public:
|
|||
CProfiling m_Profile;
|
||||
CCheats m_Cheats;
|
||||
bool m_EndEmulation;
|
||||
enum SAVE_CHIP_TYPE m_SaveUsing;
|
||||
enum SystemType m_SystemType;;
|
||||
|
||||
//Methods
|
||||
|
@ -93,9 +95,9 @@ private:
|
|||
void InitRegisters ( bool bPostPif, CMipsMemory & MMU );
|
||||
|
||||
//CPU Methods
|
||||
void ExecuteRecompiler ( CC_Core & C_Core );
|
||||
void ExecuteInterpret ( CC_Core & C_Core );
|
||||
void ExecuteSyncCPU ( CC_Core & C_Core );
|
||||
void ExecuteRecompiler ( );
|
||||
void ExecuteInterpret ( );
|
||||
void ExecuteSyncCPU ();
|
||||
|
||||
void AddEvent ( SystemEvent Event);
|
||||
|
||||
|
@ -154,3 +156,5 @@ private:
|
|||
//list of function that have been called .. used in profiling
|
||||
FUNC_CALLS m_FunctionCalls;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -530,6 +530,10 @@
|
|||
RelativePath="N64 System\Mips\Memory.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\N64 System\Mips\Mempak.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="N64 System\Mips\OpCode Analysis Class.cpp"
|
||||
>
|
||||
|
@ -570,10 +574,6 @@
|
|||
RelativePath="N64 System\C Core\BreakPoints.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="N64 System\C Core\C Core Interface.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="N64 System\C Core\C main.cpp"
|
||||
>
|
||||
|
@ -582,10 +582,6 @@
|
|||
RelativePath="N64 System\C Core\Logging.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="N64 System\C Core\Mempak.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="N64 System\C Core\r4300i Commands.cpp"
|
||||
>
|
||||
|
@ -1255,6 +1251,10 @@
|
|||
RelativePath="N64 System\Mips\Memory Virtual Mem.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\N64 System\Mips\Mempak.H"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="N64 System\Mips\OpCode Analysis Class.h"
|
||||
>
|
||||
|
@ -1303,18 +1303,10 @@
|
|||
RelativePath="N64 System\C Core\BreakPoints.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="N64 System\C Core\C Core Interface.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="N64 System\C Core\Logging.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="N64 System\C Core\MEMPAK.H"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="N64 System\C Core\r4300i Commands.h"
|
||||
>
|
||||
|
|
|
@ -13,7 +13,5 @@
|
|||
#include "Validate Binary.h"
|
||||
#include <Aclapi.h>
|
||||
|
||||
#include "N64 System/C Core/C Core Interface.h"
|
||||
|
||||
#include "3rd Party/Zip.h"
|
||||
#include "3rd Party/7zip.h"
|
||||
|
|
Loading…
Reference in New Issue