2012-12-19 09:30:18 +00:00
|
|
|
/****************************************************************************
|
|
|
|
* *
|
2015-11-10 05:21:49 +00:00
|
|
|
* Project64 - A Nintendo 64 emulator. *
|
2012-12-19 09:30:18 +00:00
|
|
|
* http://www.pj64-emu.com/ *
|
|
|
|
* Copyright (C) 2012 Project64. All rights reserved. *
|
|
|
|
* *
|
|
|
|
* License: *
|
|
|
|
* GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
2010-05-23 10:05:41 +00:00
|
|
|
#include "stdafx.h"
|
2015-12-06 09:59:58 +00:00
|
|
|
#include "N64RomClass.h"
|
|
|
|
#include "SystemGlobals.h"
|
|
|
|
#include <Project64-core/3rdParty/zip.h>
|
|
|
|
#include <Common/md5.h>
|
2016-01-14 21:06:33 +00:00
|
|
|
#include <Common/Platform.h>
|
|
|
|
#include <Common/MemoryManagement.h>
|
|
|
|
#include <memory>
|
|
|
|
|
2016-02-01 06:04:05 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include <Project64-core/3rdParty/7zip.h>
|
|
|
|
#endif
|
|
|
|
|
2016-01-14 21:06:33 +00:00
|
|
|
CN64Rom::CN64Rom() :
|
|
|
|
m_ROMImage(NULL),
|
|
|
|
m_ROMImageBase(NULL),
|
|
|
|
m_ErrorMsg(EMPTY_STRING),
|
|
|
|
m_Country(UnknownCountry),
|
|
|
|
m_CicChip(CIC_UNKNOWN)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-04-28 22:19:02 +00:00
|
|
|
CN64Rom::~CN64Rom()
|
|
|
|
{
|
2015-11-15 09:56:34 +00:00
|
|
|
UnallocateRomImage();
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2016-01-14 21:06:33 +00:00
|
|
|
bool CN64Rom::AllocateRomImage(uint32_t RomFileSize)
|
|
|
|
{
|
|
|
|
WriteTrace(TraceN64System, TraceDebug, "Allocating memory for rom");
|
|
|
|
std::auto_ptr<uint8_t> ImageBase(new uint8_t[RomFileSize + 0x1000]);
|
|
|
|
if (ImageBase.get() == NULL)
|
|
|
|
{
|
|
|
|
SetError(MSG_MEM_ALLOC_ERROR);
|
|
|
|
WriteTrace(TraceN64System, TraceError, "Failed to allocate memory for rom (size: 0x%X)", RomFileSize);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
uint8_t * Image = (uint8_t *)(((uint64_t)ImageBase.get() + 0xFFF) & ~0xFFF); // start at begining of memory page
|
|
|
|
WriteTrace(TraceN64System, TraceDebug, "Allocated rom memory (%p)", Image);
|
|
|
|
|
|
|
|
//save information about the rom loaded
|
|
|
|
m_ROMImageBase = ImageBase.release();
|
|
|
|
m_ROMImage = Image;
|
|
|
|
m_RomFileSize = RomFileSize;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-11-15 20:05:55 +00:00
|
|
|
bool CN64Rom::AllocateAndLoadN64Image(const char * FileLoc, bool LoadBootCodeOnly)
|
|
|
|
{
|
2016-01-14 21:06:33 +00:00
|
|
|
WriteTrace(TraceN64System, TraceDebug, "Trying to open %s", FileLoc);
|
|
|
|
if (!m_RomFile.Open(FileLoc, CFileBase::modeRead))
|
|
|
|
{
|
|
|
|
WriteTrace(TraceN64System, TraceError, "Failed to open %s", FileLoc);
|
|
|
|
return false;
|
|
|
|
}
|
2015-11-15 09:56:34 +00:00
|
|
|
|
|
|
|
//Read the first 4 bytes and make sure it is a valid n64 image
|
2016-01-14 21:06:33 +00:00
|
|
|
uint8_t Test[4];
|
|
|
|
m_RomFile.SeekToBegin();
|
|
|
|
if (m_RomFile.Read(Test, sizeof(Test)) != sizeof(Test))
|
|
|
|
{
|
|
|
|
m_RomFile.Close();
|
|
|
|
WriteTrace(TraceN64System, TraceError, "Failed to read ident bytes");
|
|
|
|
return false;
|
|
|
|
}
|
2015-11-15 20:05:55 +00:00
|
|
|
if (!IsValidRomImage(Test))
|
|
|
|
{
|
2016-01-14 21:06:33 +00:00
|
|
|
m_RomFile.Close();
|
|
|
|
WriteTrace(TraceN64System, TraceError, "invalid image file %X %X %X %X", Test[0], Test[1], Test[2], Test[3]);
|
2015-11-15 09:56:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-01-14 21:06:33 +00:00
|
|
|
uint32_t RomFileSize = m_RomFile.GetLength();
|
|
|
|
WriteTrace(TraceN64System, TraceDebug, "Successfully Opened, size: 0x%X", RomFileSize);
|
2015-11-15 09:56:34 +00:00
|
|
|
|
|
|
|
//if loading boot code then just load the first 0x1000 bytes
|
2016-01-14 21:06:33 +00:00
|
|
|
if (LoadBootCodeOnly)
|
|
|
|
{
|
|
|
|
WriteTrace(TraceN64System, TraceDebug, "loading boot code, so loading the first 0x1000 bytes", RomFileSize);
|
|
|
|
RomFileSize = 0x1000;
|
|
|
|
}
|
2015-11-15 09:56:34 +00:00
|
|
|
|
2016-01-14 21:06:33 +00:00
|
|
|
if (!AllocateRomImage(RomFileSize))
|
2015-11-15 20:05:55 +00:00
|
|
|
{
|
2016-01-14 21:06:33 +00:00
|
|
|
m_RomFile.Close();
|
2015-11-15 09:56:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Load the n64 rom to the allocated memory
|
|
|
|
g_Notify->DisplayMessage(5, MSG_LOADING);
|
2016-01-14 21:06:33 +00:00
|
|
|
m_RomFile.SeekToBegin();
|
2015-11-15 09:56:34 +00:00
|
|
|
|
2016-01-14 21:06:33 +00:00
|
|
|
uint32_t count, TotalRead = 0;
|
2015-11-15 20:05:55 +00:00
|
|
|
for (count = 0; count < (int)RomFileSize; count += ReadFromRomSection)
|
|
|
|
{
|
2016-01-14 21:06:33 +00:00
|
|
|
uint32_t dwToRead = RomFileSize - count;
|
2015-11-15 09:56:34 +00:00
|
|
|
if (dwToRead > ReadFromRomSection) { dwToRead = ReadFromRomSection; }
|
|
|
|
|
2016-01-14 21:06:33 +00:00
|
|
|
if (m_RomFile.Read(&m_ROMImage[count], dwToRead) != dwToRead)
|
2015-11-15 20:05:55 +00:00
|
|
|
{
|
2016-01-14 21:06:33 +00:00
|
|
|
m_RomFile.Close();
|
2015-11-15 09:56:34 +00:00
|
|
|
SetError(MSG_FAIL_IMAGE);
|
2016-01-14 21:06:33 +00:00
|
|
|
WriteTrace(TraceN64System, TraceError, "Failed to read file (TotalRead: 0x%X)", TotalRead);
|
2015-11-15 09:56:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-01-14 21:06:33 +00:00
|
|
|
TotalRead += dwToRead;
|
2015-11-15 09:56:34 +00:00
|
|
|
|
|
|
|
//Show Message of how much % wise of the rom has been loaded
|
2015-12-23 20:04:36 +00:00
|
|
|
g_Notify->DisplayMessage(0, stdstr_f("%s: %.2f%c", GS(MSG_LOADED), ((float)TotalRead / (float)RomFileSize) * 100.0f, '%').c_str());
|
2015-11-15 09:56:34 +00:00
|
|
|
}
|
|
|
|
|
2016-01-14 21:06:33 +00:00
|
|
|
if (RomFileSize != TotalRead)
|
2015-11-15 20:05:55 +00:00
|
|
|
{
|
2016-01-14 21:06:33 +00:00
|
|
|
m_RomFile.Close();
|
2015-11-15 09:56:34 +00:00
|
|
|
SetError(MSG_FAIL_IMAGE);
|
2016-01-14 21:06:33 +00:00
|
|
|
WriteTrace(TraceN64System, TraceError, "Expected to read: 0x%X, read: 0x%X", TotalRead, RomFileSize);
|
2015-11-15 09:56:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_Notify->DisplayMessage(5, MSG_BYTESWAP);
|
|
|
|
ByteSwapRom();
|
|
|
|
|
|
|
|
//Protect the memory so that it can not be written to.
|
2016-01-14 21:06:33 +00:00
|
|
|
ProtectMemory(m_ROMImage, m_RomFileSize, MEM_READONLY);
|
2015-11-15 09:56:34 +00:00
|
|
|
return true;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2015-11-15 20:05:55 +00:00
|
|
|
bool CN64Rom::AllocateAndLoadZipImage(const char * FileLoc, bool LoadBootCodeOnly)
|
|
|
|
{
|
2015-11-15 09:56:34 +00:00
|
|
|
unzFile file = unzOpen(FileLoc);
|
|
|
|
if (file == NULL)
|
2015-11-15 20:05:55 +00:00
|
|
|
{
|
2015-11-15 09:56:34 +00:00
|
|
|
return false;
|
2015-11-15 20:05:55 +00:00
|
|
|
}
|
2015-11-15 09:56:34 +00:00
|
|
|
|
|
|
|
int port = unzGoToFirstFile(file);
|
|
|
|
bool FoundRom = false;
|
|
|
|
|
|
|
|
//scan through all files in zip to a suitable file is found
|
2015-11-15 20:05:55 +00:00
|
|
|
while (port == UNZ_OK && !FoundRom)
|
|
|
|
{
|
2015-11-15 09:56:34 +00:00
|
|
|
unz_file_info info;
|
2016-04-14 22:38:02 +00:00
|
|
|
char zname[260];
|
2015-11-15 09:56:34 +00:00
|
|
|
|
|
|
|
unzGetCurrentFileInfo(file, &info, zname, sizeof(zname), NULL, 0, NULL, 0);
|
2015-11-15 20:05:55 +00:00
|
|
|
if (unzLocateFile(file, zname, 1) != UNZ_OK)
|
|
|
|
{
|
2015-11-15 09:56:34 +00:00
|
|
|
SetError(MSG_FAIL_ZIP);
|
|
|
|
break;
|
|
|
|
}
|
2015-11-15 20:05:55 +00:00
|
|
|
if (unzOpenCurrentFile(file) != UNZ_OK)
|
|
|
|
{
|
2015-11-15 09:56:34 +00:00
|
|
|
SetError(MSG_FAIL_ZIP);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Read the first 4 bytes to check magic number
|
2015-11-15 20:05:55 +00:00
|
|
|
uint8_t Test[4];
|
2015-11-15 09:56:34 +00:00
|
|
|
unzReadCurrentFile(file, Test, sizeof(Test));
|
2015-11-15 20:05:55 +00:00
|
|
|
if (IsValidRomImage(Test))
|
|
|
|
{
|
2015-11-15 09:56:34 +00:00
|
|
|
//Get the size of the rom and try to allocate the memory needed.
|
2016-01-14 21:06:33 +00:00
|
|
|
uint32_t RomFileSize = info.uncompressed_size;
|
2015-11-15 20:05:55 +00:00
|
|
|
if (LoadBootCodeOnly)
|
|
|
|
{
|
2015-11-15 09:56:34 +00:00
|
|
|
RomFileSize = 0x1000;
|
|
|
|
}
|
2016-01-14 21:06:33 +00:00
|
|
|
|
|
|
|
if (!AllocateRomImage(RomFileSize))
|
2015-11-15 20:05:55 +00:00
|
|
|
{
|
2016-01-14 21:06:33 +00:00
|
|
|
m_RomFile.Close();
|
|
|
|
return false;
|
2015-11-15 09:56:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Load the n64 rom to the allocated memory
|
|
|
|
g_Notify->DisplayMessage(5, MSG_LOADING);
|
2016-01-14 21:06:33 +00:00
|
|
|
memcpy(m_ROMImage, Test, 4);
|
2015-11-15 09:56:34 +00:00
|
|
|
|
2016-01-14 21:06:33 +00:00
|
|
|
uint32_t dwRead, count, TotalRead = 0;
|
2015-11-15 20:05:55 +00:00
|
|
|
for (count = 4; count < (int)RomFileSize; count += ReadFromRomSection)
|
|
|
|
{
|
2016-01-14 21:06:33 +00:00
|
|
|
uint32_t dwToRead = RomFileSize - count;
|
2015-11-15 09:56:34 +00:00
|
|
|
if (dwToRead > ReadFromRomSection) { dwToRead = ReadFromRomSection; }
|
|
|
|
|
2016-01-14 21:06:33 +00:00
|
|
|
dwRead = unzReadCurrentFile(file, &m_ROMImage[count], dwToRead);
|
2015-11-15 20:05:55 +00:00
|
|
|
if (dwRead == 0)
|
|
|
|
{
|
2015-11-15 09:56:34 +00:00
|
|
|
SetError(MSG_FAIL_ZIP);
|
|
|
|
unzCloseCurrentFile(file);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
TotalRead += dwRead;
|
|
|
|
|
|
|
|
//Show Message of how much % wise of the rom has been loaded
|
2015-12-23 20:04:36 +00:00
|
|
|
g_Notify->DisplayMessage(5, stdstr_f("%s: %.2f%c", GS(MSG_LOADED), ((float)TotalRead / (float)RomFileSize) * 100.0f, '%').c_str());
|
2015-11-15 09:56:34 +00:00
|
|
|
}
|
|
|
|
dwRead = TotalRead + 4;
|
|
|
|
|
2015-11-15 20:05:55 +00:00
|
|
|
if (RomFileSize != dwRead)
|
|
|
|
{
|
2015-11-15 09:56:34 +00:00
|
|
|
unzCloseCurrentFile(file);
|
|
|
|
SetError(MSG_FAIL_ZIP);
|
2015-12-23 20:04:36 +00:00
|
|
|
g_Notify->DisplayMessage(1, "");
|
2015-11-15 09:56:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
FoundRom = true;
|
|
|
|
|
|
|
|
g_Notify->DisplayMessage(5, MSG_BYTESWAP);
|
|
|
|
ByteSwapRom();
|
|
|
|
|
|
|
|
//Protect the memory so that it can not be written to.
|
2016-01-14 21:06:33 +00:00
|
|
|
ProtectMemory(m_ROMImage, m_RomFileSize, MEM_READONLY);
|
2015-11-15 09:56:34 +00:00
|
|
|
}
|
|
|
|
unzCloseCurrentFile(file);
|
|
|
|
|
|
|
|
if (!FoundRom)
|
2015-11-15 20:05:55 +00:00
|
|
|
{
|
2015-11-15 09:56:34 +00:00
|
|
|
port = unzGoToNextFile(file);
|
2015-11-15 20:05:55 +00:00
|
|
|
}
|
2015-11-15 09:56:34 +00:00
|
|
|
}
|
|
|
|
unzClose(file);
|
|
|
|
|
|
|
|
return FoundRom;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2015-11-15 20:05:55 +00:00
|
|
|
void CN64Rom::ByteSwapRom()
|
|
|
|
{
|
2016-01-14 21:06:33 +00:00
|
|
|
uint32_t count;
|
2015-11-15 09:56:34 +00:00
|
|
|
|
2016-01-14 21:06:33 +00:00
|
|
|
switch (*((uint32_t *)&m_ROMImage[0]))
|
2015-11-15 20:05:55 +00:00
|
|
|
{
|
2015-11-15 09:56:34 +00:00
|
|
|
case 0x12408037:
|
2015-11-15 20:05:55 +00:00
|
|
|
for (count = 0; count < m_RomFileSize; count += 4)
|
|
|
|
{
|
2015-11-15 09:56:34 +00:00
|
|
|
m_ROMImage[count] ^= m_ROMImage[count + 2];
|
|
|
|
m_ROMImage[count + 2] ^= m_ROMImage[count];
|
|
|
|
m_ROMImage[count] ^= m_ROMImage[count + 2];
|
|
|
|
m_ROMImage[count + 1] ^= m_ROMImage[count + 3];
|
|
|
|
m_ROMImage[count + 3] ^= m_ROMImage[count + 1];
|
|
|
|
m_ROMImage[count + 1] ^= m_ROMImage[count + 3];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x40072780: //64DD IPL
|
|
|
|
case 0x40123780:
|
2015-11-15 20:05:55 +00:00
|
|
|
for (count = 0; count < m_RomFileSize; count += 4)
|
|
|
|
{
|
2015-11-15 09:56:34 +00:00
|
|
|
m_ROMImage[count] ^= m_ROMImage[count + 3];
|
|
|
|
m_ROMImage[count + 3] ^= m_ROMImage[count];
|
|
|
|
m_ROMImage[count] ^= m_ROMImage[count + 3];
|
|
|
|
m_ROMImage[count + 1] ^= m_ROMImage[count + 2];
|
|
|
|
m_ROMImage[count + 2] ^= m_ROMImage[count + 1];
|
|
|
|
m_ROMImage[count + 1] ^= m_ROMImage[count + 2];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x80371240: break;
|
|
|
|
default:
|
2015-12-23 20:04:36 +00:00
|
|
|
g_Notify->DisplayError(stdstr_f("ByteSwapRom: %X", m_ROMImage[0]).c_str());
|
2015-11-15 09:56:34 +00:00
|
|
|
}
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2016-04-14 22:38:02 +00:00
|
|
|
CICChip CN64Rom::GetCicChipID(uint8_t * RomData, uint64_t * CRC)
|
|
|
|
{
|
|
|
|
uint64_t crc = 0;
|
|
|
|
int32_t count;
|
|
|
|
|
|
|
|
for (count = 0x40; count < 0x1000; count += 4)
|
|
|
|
{
|
|
|
|
crc += *(uint32_t *)(RomData + count);
|
|
|
|
}
|
|
|
|
if (CRC != NULL) { *CRC = crc; }
|
|
|
|
|
|
|
|
switch (crc)
|
|
|
|
{
|
|
|
|
case 0x000000D0027FDF31: return CIC_NUS_6101;
|
|
|
|
case 0x000000CFFB631223: return CIC_NUS_6101;
|
|
|
|
case 0x000000D057C85244: return CIC_NUS_6102;
|
|
|
|
case 0x000000D6497E414B: return CIC_NUS_6103;
|
|
|
|
case 0x0000011A49F60E96: return CIC_NUS_6105;
|
|
|
|
case 0x000000D6D5BE5580: return CIC_NUS_6106;
|
|
|
|
case 0x000001053BC19870: return CIC_NUS_5167; //64DD CONVERSION CIC
|
|
|
|
case 0x000000D2E53EF008: return CIC_NUS_8303; //64DD IPL
|
|
|
|
default:
|
|
|
|
return CIC_UNKNOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-28 22:19:02 +00:00
|
|
|
void CN64Rom::CalculateCicChip()
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2016-04-14 22:38:02 +00:00
|
|
|
uint64_t CRC = 0;
|
2015-11-15 09:56:34 +00:00
|
|
|
|
|
|
|
if (m_ROMImage == NULL)
|
|
|
|
{
|
|
|
|
m_CicChip = CIC_UNKNOWN;
|
|
|
|
return;
|
|
|
|
}
|
2016-04-14 22:38:02 +00:00
|
|
|
m_CicChip = GetCicChipID(m_ROMImage, &CRC);
|
|
|
|
if (m_CicChip == CIC_UNKNOWN)
|
2015-11-15 20:05:55 +00:00
|
|
|
{
|
2015-11-15 09:56:34 +00:00
|
|
|
if (bHaveDebugger())
|
|
|
|
{
|
2015-12-23 20:04:36 +00:00
|
|
|
g_Notify->DisplayError(stdstr_f("Unknown CIC checksum:\n%I64X.", CRC).c_str());
|
2015-11-15 09:56:34 +00:00
|
|
|
}
|
|
|
|
}
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2015-06-15 13:08:07 +00:00
|
|
|
void CN64Rom::CalculateRomCrc()
|
|
|
|
{
|
2016-01-14 21:06:33 +00:00
|
|
|
uint32_t t0, t2, t3, t4, t5;
|
|
|
|
uint32_t a0, a1, a2, a3;
|
|
|
|
uint32_t s0;
|
|
|
|
uint32_t v0, v1;
|
2015-11-15 09:56:34 +00:00
|
|
|
|
|
|
|
// CIC_NUS_6101 at=0x5D588B65 , s6=0x3F
|
|
|
|
// CIC_NUS_6102 at=0x5D588B65 , s6=0x3F
|
|
|
|
// CIC_NUS_6103 at=0x6C078965 , s6=0x78
|
|
|
|
// CIC_NUS_6105 at=0x5d588b65 , s6=0x91
|
|
|
|
// CIC_NUS_6106 at=0x6C078965 , s6=0x85
|
|
|
|
|
|
|
|
// 64DD IPL at=0x02E90EDD , s6=0xdd
|
|
|
|
|
|
|
|
//v0 = 0xFFFFFFFF & (0x3F * at) + 1;
|
2015-11-15 20:05:55 +00:00
|
|
|
switch (m_CicChip)
|
|
|
|
{
|
2015-11-15 09:56:34 +00:00
|
|
|
case CIC_NUS_6101:
|
|
|
|
case CIC_NUS_6102: v0 = 0xF8CA4DDC; break;
|
|
|
|
case CIC_NUS_6103: v0 = 0xA3886759; break;
|
|
|
|
case CIC_NUS_6105: v0 = 0xDF26F436; break;
|
|
|
|
case CIC_NUS_6106: v0 = 0x1FEA617A; break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-14 21:06:33 +00:00
|
|
|
ProtectMemory(m_ROMImage, m_RomFileSize, MEM_READWRITE);
|
2015-11-15 09:56:34 +00:00
|
|
|
|
|
|
|
v1 = 0;
|
|
|
|
t0 = 0;
|
|
|
|
t5 = 0x20;
|
|
|
|
|
|
|
|
a3 = v0;
|
|
|
|
t2 = v0;
|
|
|
|
t3 = v0;
|
|
|
|
s0 = v0;
|
|
|
|
a2 = v0;
|
|
|
|
t4 = v0;
|
|
|
|
|
2015-11-15 20:05:55 +00:00
|
|
|
for (t0 = 0; t0 < 0x00100000; t0 += 4)
|
|
|
|
{
|
2016-01-14 21:06:33 +00:00
|
|
|
v0 = *(uint32_t *)(m_ROMImage + t0 + 0x1000);
|
2015-11-15 09:56:34 +00:00
|
|
|
|
|
|
|
v1 = a3 + v0;
|
|
|
|
a1 = v1;
|
|
|
|
|
|
|
|
if (v1 < a3) t2 += 0x1;
|
|
|
|
v1 = v0 & 0x001F;
|
|
|
|
|
|
|
|
a0 = (v0 << v1) | (v0 >> (t5 - v1));
|
|
|
|
|
|
|
|
a3 = a1;
|
|
|
|
t3 = t3 ^ v0;
|
|
|
|
|
|
|
|
s0 = s0 + a0;
|
|
|
|
if (a2 < v0) a2 = a3 ^ v0 ^ a2;
|
|
|
|
else a2 = a2 ^ a0;
|
|
|
|
|
2015-11-15 20:05:55 +00:00
|
|
|
if (m_CicChip == CIC_NUS_6105)
|
|
|
|
{
|
2016-01-14 21:06:33 +00:00
|
|
|
t4 = (v0 ^ (*(uint32_t *)(m_ROMImage + (0xFF & t0) + 0x750))) + t4;
|
2015-11-15 09:56:34 +00:00
|
|
|
}
|
|
|
|
else t4 = (v0 ^ s0) + t4;
|
|
|
|
}
|
2015-11-15 20:05:55 +00:00
|
|
|
if (m_CicChip == CIC_NUS_6103)
|
|
|
|
{
|
2015-11-15 09:56:34 +00:00
|
|
|
a3 = (a3 ^ t2) + t3;
|
|
|
|
s0 = (s0 ^ a2) + t4;
|
|
|
|
}
|
2015-11-15 20:05:55 +00:00
|
|
|
else if (m_CicChip == CIC_NUS_6106)
|
|
|
|
{
|
2015-11-15 09:56:34 +00:00
|
|
|
a3 = 0xFFFFFFFF & (a3 * t2) + t3;
|
|
|
|
s0 = 0xFFFFFFFF & (s0 * a2) + t4;
|
|
|
|
}
|
2015-11-15 20:05:55 +00:00
|
|
|
else
|
|
|
|
{
|
2015-11-15 09:56:34 +00:00
|
|
|
a3 = a3 ^ t2 ^ t3;
|
|
|
|
s0 = s0 ^ a2 ^ t4;
|
|
|
|
}
|
|
|
|
|
2016-01-14 21:06:33 +00:00
|
|
|
*(uint32_t *)(m_ROMImage + 0x10) = a3;
|
|
|
|
*(uint32_t *)(m_ROMImage + 0x14) = s0;
|
2015-11-15 09:56:34 +00:00
|
|
|
|
2016-01-14 21:06:33 +00:00
|
|
|
ProtectMemory(m_ROMImage, m_RomFileSize, MEM_READONLY);
|
2015-06-15 13:08:07 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 22:19:02 +00:00
|
|
|
CICChip CN64Rom::CicChipID()
|
|
|
|
{
|
2015-11-15 09:56:34 +00:00
|
|
|
return m_CicChip;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2015-11-15 20:05:55 +00:00
|
|
|
bool CN64Rom::IsValidRomImage(uint8_t Test[4])
|
|
|
|
{
|
2016-01-14 21:06:33 +00:00
|
|
|
if (*((uint32_t *)&Test[0]) == 0x40123780) { return true; }
|
|
|
|
if (*((uint32_t *)&Test[0]) == 0x12408037) { return true; }
|
|
|
|
if (*((uint32_t *)&Test[0]) == 0x80371240) { return true; }
|
|
|
|
if (*((uint32_t *)&Test[0]) == 0x40072780) { return true; } //64DD IPL
|
2015-11-15 09:56:34 +00:00
|
|
|
return false;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2016-04-15 23:17:37 +00:00
|
|
|
void CN64Rom::CleanRomName(char * RomName, bool byteswap)
|
|
|
|
{
|
|
|
|
if (byteswap)
|
|
|
|
{
|
|
|
|
for (int count = 0; count < 20; count += 4)
|
|
|
|
{
|
|
|
|
RomName[count] ^= RomName[count + 3];
|
|
|
|
RomName[count + 3] ^= RomName[count];
|
|
|
|
RomName[count] ^= RomName[count + 3];
|
|
|
|
RomName[count + 1] ^= RomName[count + 2];
|
|
|
|
RomName[count + 2] ^= RomName[count + 1];
|
|
|
|
RomName[count + 1] ^= RomName[count + 2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//truncate all the spaces at the end of the string
|
|
|
|
for (int count = 19; count >= 0; count--)
|
|
|
|
{
|
|
|
|
if (RomName[count] == ' ')
|
|
|
|
{
|
|
|
|
RomName[count] = '\0';
|
|
|
|
}
|
|
|
|
else if (RomName[count] == '\0')
|
|
|
|
{
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
count = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RomName[20] = '\0';
|
|
|
|
|
|
|
|
//remove all /,\,: from the string
|
|
|
|
for (int count = 0; count < (int)strlen(RomName); count++)
|
|
|
|
{
|
|
|
|
switch (RomName[count])
|
|
|
|
{
|
|
|
|
case '/': case '\\': RomName[count] = '-'; break;
|
|
|
|
case ':': RomName[count] = ';'; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-23 20:04:36 +00:00
|
|
|
void CN64Rom::NotificationCB(const char * Status, CN64Rom * /*_this*/)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2015-12-23 20:04:36 +00:00
|
|
|
g_Notify->DisplayMessage(5, stdstr_f("%s", Status).c_str());
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2015-11-15 20:05:55 +00:00
|
|
|
bool CN64Rom::LoadN64Image(const char * FileLoc, bool LoadBootCodeOnly)
|
|
|
|
{
|
2015-11-15 09:56:34 +00:00
|
|
|
UnallocateRomImage();
|
|
|
|
m_ErrorMsg = EMPTY_STRING;
|
|
|
|
|
2016-01-14 21:06:33 +00:00
|
|
|
stdstr ext = CPath(FileLoc).GetExtension();
|
2015-11-15 09:56:34 +00:00
|
|
|
bool Loaded7zFile = false;
|
|
|
|
|
2016-02-01 06:04:05 +00:00
|
|
|
#ifdef _WIN32
|
2016-01-14 21:06:33 +00:00
|
|
|
if (strstr(FileLoc, "?") != NULL || _stricmp(ext.c_str(), "7z") == 0)
|
2015-11-15 09:56:34 +00:00
|
|
|
{
|
2016-01-14 21:06:33 +00:00
|
|
|
stdstr FullPath = FileLoc;
|
2015-11-15 09:56:34 +00:00
|
|
|
|
|
|
|
//this should be a 7zip file
|
2016-01-14 21:06:33 +00:00
|
|
|
char * SubFile = strstr(const_cast<char*>(FullPath.c_str()), "?");
|
2015-11-15 09:56:34 +00:00
|
|
|
if (SubFile == NULL)
|
|
|
|
{
|
|
|
|
//Pop up a dialog and select file
|
|
|
|
//allocate memory for sub name and copy selected file name to var
|
2016-01-14 21:06:33 +00:00
|
|
|
return false; //remove once dialog is done
|
2015-11-15 09:56:34 +00:00
|
|
|
}
|
2015-11-15 20:05:55 +00:00
|
|
|
else
|
|
|
|
{
|
2015-11-15 09:56:34 +00:00
|
|
|
*SubFile = '\0';
|
|
|
|
SubFile += 1;
|
|
|
|
}
|
|
|
|
|
2016-01-14 21:06:33 +00:00
|
|
|
C7zip ZipFile(FullPath.c_str());
|
2015-11-15 09:56:34 +00:00
|
|
|
ZipFile.SetNotificationCallback((C7zip::LP7ZNOTIFICATION)NotificationCB, this);
|
|
|
|
for (int i = 0; i < ZipFile.NumFiles(); i++)
|
|
|
|
{
|
|
|
|
CSzFileItem * f = ZipFile.FileItem(i);
|
|
|
|
if (f->IsDir)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
stdstr ZipFileName;
|
|
|
|
ZipFileName.FromUTF16(ZipFile.FileNameIndex(i).c_str());
|
|
|
|
if (SubFile != NULL)
|
|
|
|
{
|
|
|
|
if (_stricmp(ZipFileName.c_str(), SubFile) != 0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Get the size of the rom and try to allocate the memory needed.
|
2016-01-14 21:06:33 +00:00
|
|
|
uint32_t RomFileSize = (uint32_t)f->Size;
|
2015-11-15 09:56:34 +00:00
|
|
|
//if loading boot code then just load the first 0x1000 bytes
|
|
|
|
if (LoadBootCodeOnly) { RomFileSize = 0x1000; }
|
|
|
|
|
2016-01-14 21:06:33 +00:00
|
|
|
if (!AllocateRomImage(RomFileSize))
|
2015-11-15 20:05:55 +00:00
|
|
|
{
|
2015-11-15 09:56:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Load the n64 rom to the allocated memory
|
|
|
|
g_Notify->DisplayMessage(5, MSG_LOADING);
|
2016-01-14 21:06:33 +00:00
|
|
|
if (!ZipFile.GetFile(i, m_ROMImage, RomFileSize))
|
2015-11-15 09:56:34 +00:00
|
|
|
{
|
|
|
|
SetError(MSG_FAIL_IMAGE);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-14 21:06:33 +00:00
|
|
|
if (!IsValidRomImage(m_ROMImage))
|
2015-11-15 09:56:34 +00:00
|
|
|
{
|
|
|
|
SetError(MSG_FAIL_IMAGE);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
g_Notify->DisplayMessage(5, MSG_BYTESWAP);
|
|
|
|
ByteSwapRom();
|
|
|
|
|
|
|
|
//Protect the memory so that it can not be written to.
|
2016-01-14 21:06:33 +00:00
|
|
|
ProtectMemory(m_ROMImage, m_RomFileSize, MEM_READONLY);
|
2015-11-15 09:56:34 +00:00
|
|
|
Loaded7zFile = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!Loaded7zFile)
|
|
|
|
{
|
|
|
|
SetError(MSG_7Z_FILE_NOT_FOUND);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2016-02-01 06:04:05 +00:00
|
|
|
#endif
|
2015-11-15 09:56:34 +00:00
|
|
|
|
|
|
|
//Try to open the file as a zip file
|
|
|
|
if (!Loaded7zFile)
|
|
|
|
{
|
2015-11-15 20:05:55 +00:00
|
|
|
if (!AllocateAndLoadZipImage(FileLoc, LoadBootCodeOnly))
|
|
|
|
{
|
|
|
|
if (m_ErrorMsg != EMPTY_STRING)
|
|
|
|
{
|
2015-11-15 09:56:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-01-14 21:06:33 +00:00
|
|
|
if (!AllocateAndLoadN64Image(FileLoc, LoadBootCodeOnly))
|
2015-11-15 20:05:55 +00:00
|
|
|
{
|
2015-11-15 09:56:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
char RomName[260];
|
|
|
|
//Get the header from the rom image
|
|
|
|
memcpy(&RomName[0], (void *)(m_ROMImage + 0x20), 20);
|
2016-04-15 23:17:37 +00:00
|
|
|
CN64Rom::CleanRomName(RomName);
|
2015-11-15 09:56:34 +00:00
|
|
|
|
2015-11-15 20:05:55 +00:00
|
|
|
if (strlen(RomName) == 0)
|
|
|
|
{
|
2016-01-14 21:06:33 +00:00
|
|
|
strcpy(RomName, CPath(FileLoc).GetName().c_str());
|
2016-04-15 23:17:37 +00:00
|
|
|
CN64Rom::CleanRomName(RomName, false);
|
2015-11-15 09:56:34 +00:00
|
|
|
}
|
|
|
|
|
2016-01-14 21:06:33 +00:00
|
|
|
WriteTrace(TraceN64System, TraceDebug, "RomName %s", RomName);
|
2015-11-15 09:56:34 +00:00
|
|
|
|
|
|
|
m_RomName = RomName;
|
|
|
|
m_FileName = FileLoc;
|
|
|
|
m_MD5 = "";
|
|
|
|
|
2015-11-15 20:05:55 +00:00
|
|
|
if (!LoadBootCodeOnly)
|
|
|
|
{
|
2015-11-15 09:56:34 +00:00
|
|
|
//Calculate files MD5
|
|
|
|
m_MD5 = MD5((const unsigned char *)m_ROMImage, m_RomFileSize).hex_digest();
|
2016-01-14 21:06:33 +00:00
|
|
|
WriteTrace(TraceN64System, TraceDebug, "MD5: %s", m_MD5.c_str());
|
2015-11-15 09:56:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_Country = (Country)m_ROMImage[0x3D];
|
2016-01-14 21:06:33 +00:00
|
|
|
m_RomIdent.Format("%08X-%08X-C:%X", *(uint32_t *)(&m_ROMImage[0x10]), *(uint32_t *)(&m_ROMImage[0x14]), m_ROMImage[0x3D]);
|
|
|
|
WriteTrace(TraceN64System, TraceDebug, "Ident: %s", m_RomIdent.c_str());
|
2015-11-15 09:56:34 +00:00
|
|
|
CalculateCicChip();
|
|
|
|
|
|
|
|
if (!LoadBootCodeOnly && g_Rom == this)
|
|
|
|
{
|
2015-11-15 20:05:55 +00:00
|
|
|
g_Settings->SaveBool(GameRunning_LoadingInProgress, false);
|
2015-11-15 09:56:34 +00:00
|
|
|
SaveRomSettingID(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_Settings->LoadBool(Game_CRC_Recalc))
|
|
|
|
{
|
|
|
|
//Calculate ROM Header CRC
|
|
|
|
CalculateRomCrc();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2016-01-25 19:58:57 +00:00
|
|
|
bool CN64Rom::LoadN64ImageIPL(const char * FileLoc, bool LoadBootCodeOnly)
|
|
|
|
{
|
|
|
|
UnallocateRomImage();
|
|
|
|
m_ErrorMsg = EMPTY_STRING;
|
|
|
|
|
|
|
|
stdstr ext = CPath(FileLoc).GetExtension();
|
|
|
|
bool Loaded7zFile = false;
|
2016-02-01 06:04:05 +00:00
|
|
|
#ifdef _WIN32
|
2016-01-25 19:58:57 +00:00
|
|
|
if (strstr(FileLoc, "?") != NULL || _stricmp(ext.c_str(), "7z") == 0)
|
|
|
|
{
|
|
|
|
stdstr FullPath = FileLoc;
|
|
|
|
|
|
|
|
//this should be a 7zip file
|
|
|
|
char * SubFile = strstr(const_cast<char*>(FullPath.c_str()), "?");
|
|
|
|
if (SubFile == NULL)
|
|
|
|
{
|
|
|
|
//Pop up a dialog and select file
|
|
|
|
//allocate memory for sub name and copy selected file name to var
|
|
|
|
return false; //remove once dialog is done
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*SubFile = '\0';
|
|
|
|
SubFile += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
C7zip ZipFile(FullPath.c_str());
|
|
|
|
ZipFile.SetNotificationCallback((C7zip::LP7ZNOTIFICATION)NotificationCB, this);
|
|
|
|
for (int i = 0; i < ZipFile.NumFiles(); i++)
|
|
|
|
{
|
|
|
|
CSzFileItem * f = ZipFile.FileItem(i);
|
|
|
|
if (f->IsDir)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
stdstr ZipFileName;
|
|
|
|
ZipFileName.FromUTF16(ZipFile.FileNameIndex(i).c_str());
|
|
|
|
if (SubFile != NULL)
|
|
|
|
{
|
|
|
|
if (_stricmp(ZipFileName.c_str(), SubFile) != 0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Get the size of the rom and try to allocate the memory needed.
|
|
|
|
uint32_t RomFileSize = (uint32_t)f->Size;
|
|
|
|
//if loading boot code then just load the first 0x1000 bytes
|
|
|
|
if (LoadBootCodeOnly) { RomFileSize = 0x1000; }
|
|
|
|
|
|
|
|
if (!AllocateRomImage(RomFileSize))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Load the n64 rom to the allocated memory
|
|
|
|
g_Notify->DisplayMessage(5, MSG_LOADING);
|
|
|
|
if (!ZipFile.GetFile(i, m_ROMImage, RomFileSize))
|
|
|
|
{
|
|
|
|
SetError(MSG_FAIL_IMAGE);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!IsValidRomImage(m_ROMImage))
|
|
|
|
{
|
|
|
|
SetError(MSG_FAIL_IMAGE);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
g_Notify->DisplayMessage(5, MSG_BYTESWAP);
|
|
|
|
ByteSwapRom();
|
|
|
|
|
|
|
|
//Protect the memory so that it can not be written to.
|
|
|
|
ProtectMemory(m_ROMImage, m_RomFileSize, MEM_READONLY);
|
|
|
|
Loaded7zFile = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!Loaded7zFile)
|
|
|
|
{
|
|
|
|
SetError(MSG_7Z_FILE_NOT_FOUND);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2016-02-01 06:04:05 +00:00
|
|
|
#endif
|
2016-01-25 19:58:57 +00:00
|
|
|
|
|
|
|
//Try to open the file as a zip file
|
|
|
|
if (!Loaded7zFile)
|
|
|
|
{
|
|
|
|
if (!AllocateAndLoadZipImage(FileLoc, LoadBootCodeOnly))
|
|
|
|
{
|
|
|
|
if (m_ErrorMsg != EMPTY_STRING)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!AllocateAndLoadN64Image(FileLoc, LoadBootCodeOnly))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
char RomName[260];
|
|
|
|
//Get the header from the rom image
|
|
|
|
memcpy(&RomName[0], (void *)(m_ROMImage + 0x20), 20);
|
2016-04-15 23:17:37 +00:00
|
|
|
CN64Rom::CleanRomName(RomName);
|
2016-01-25 19:58:57 +00:00
|
|
|
if (strlen(RomName) == 0)
|
|
|
|
{
|
|
|
|
strcpy(RomName, CPath(FileLoc).GetName().c_str());
|
2016-04-15 23:17:37 +00:00
|
|
|
CN64Rom::CleanRomName(RomName,false);
|
2016-01-25 19:58:57 +00:00
|
|
|
}
|
|
|
|
WriteTrace(TraceN64System, TraceDebug, "RomName %s", RomName);
|
|
|
|
|
|
|
|
m_RomName = RomName;
|
|
|
|
m_FileName = FileLoc;
|
|
|
|
m_MD5 = "";
|
|
|
|
|
|
|
|
if (!LoadBootCodeOnly)
|
|
|
|
{
|
|
|
|
//Calculate files MD5
|
|
|
|
m_MD5 = MD5((const unsigned char *)m_ROMImage, m_RomFileSize).hex_digest();
|
|
|
|
WriteTrace(TraceN64System, TraceDebug, "MD5: %s", m_MD5.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Country = (Country)m_ROMImage[0x3D];
|
|
|
|
m_RomIdent.Format("%08X-%08X-C:%X", *(uint32_t *)(&m_ROMImage[0x10]), *(uint32_t *)(&m_ROMImage[0x14]), m_ROMImage[0x3D]);
|
|
|
|
WriteTrace(TraceN64System, TraceDebug, "Ident: %s", m_RomIdent.c_str());
|
|
|
|
CalculateCicChip();
|
|
|
|
|
|
|
|
if (!LoadBootCodeOnly && g_DDRom == this)
|
|
|
|
{
|
|
|
|
g_Settings->SaveBool(GameRunning_LoadingInProgress, false);
|
|
|
|
SaveRomSettingID(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_Settings->LoadBool(Game_CRC_Recalc))
|
|
|
|
{
|
|
|
|
//Calculate ROM Header CRC
|
|
|
|
CalculateRomCrc();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-09-18 03:15:49 +00:00
|
|
|
//Save the settings of the loaded rom, so all loaded settings about rom will be identified with
|
|
|
|
//this rom
|
2015-11-15 09:56:34 +00:00
|
|
|
void CN64Rom::SaveRomSettingID(bool temp)
|
2008-11-14 20:51:06 +00:00
|
|
|
{
|
2015-11-15 09:56:34 +00:00
|
|
|
g_Settings->SaveBool(Game_TempLoaded, temp);
|
|
|
|
g_Settings->SaveString(Game_GameName, m_RomName.c_str());
|
|
|
|
g_Settings->SaveString(Game_IniKey, m_RomIdent.c_str());
|
|
|
|
|
|
|
|
switch (GetCountry())
|
|
|
|
{
|
|
|
|
case Germany: case french: case Italian:
|
|
|
|
case Europe: case Spanish: case Australia:
|
|
|
|
case X_PAL: case Y_PAL:
|
|
|
|
g_Settings->SaveDword(Game_SystemType, SYSTEM_PAL);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_Settings->SaveDword(Game_SystemType, SYSTEM_NTSC);
|
|
|
|
break;
|
|
|
|
}
|
2008-11-14 20:51:06 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 22:19:02 +00:00
|
|
|
void CN64Rom::ClearRomSettingID()
|
2008-11-14 20:51:06 +00:00
|
|
|
{
|
2015-11-15 09:56:34 +00:00
|
|
|
g_Settings->SaveString(Game_GameName, "");
|
|
|
|
g_Settings->SaveString(Game_IniKey, "");
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 22:19:02 +00:00
|
|
|
void CN64Rom::SetError(LanguageStringID ErrorMsg)
|
|
|
|
{
|
2015-11-15 09:56:34 +00:00
|
|
|
m_ErrorMsg = ErrorMsg;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 22:19:02 +00:00
|
|
|
void CN64Rom::UnallocateRomImage()
|
|
|
|
{
|
2016-01-14 21:06:33 +00:00
|
|
|
m_RomFile.Close();
|
2015-11-15 09:56:34 +00:00
|
|
|
|
2016-01-14 21:06:33 +00:00
|
|
|
if (m_ROMImageBase)
|
2015-11-15 20:05:55 +00:00
|
|
|
{
|
2016-01-14 21:11:12 +00:00
|
|
|
ProtectMemory(m_ROMImage, m_RomFileSize, MEM_READWRITE);
|
2016-01-14 21:06:33 +00:00
|
|
|
delete[] m_ROMImageBase;
|
|
|
|
m_ROMImageBase = NULL;
|
2015-11-15 09:56:34 +00:00
|
|
|
}
|
2016-01-14 21:06:33 +00:00
|
|
|
m_ROMImage = NULL;
|
2015-11-15 09:56:34 +00:00
|
|
|
}
|