[Project64] Add CN64Rom::CleanRomName

This commit is contained in:
zilmar 2016-04-16 09:17:37 +10:00
parent c73d91de92
commit 58bd4c2adf
3 changed files with 50 additions and 93 deletions

View File

@ -413,6 +413,49 @@ bool CN64Rom::IsValidRomImage(uint8_t Test[4])
return false;
}
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;
}
}
}
void CN64Rom::NotificationCB(const char * Status, CN64Rom * /*_this*/)
{
g_Notify->DisplayMessage(5, stdstr_f("%s", Status).c_str());
@ -521,49 +564,16 @@ bool CN64Rom::LoadN64Image(const char * FileLoc, bool LoadBootCodeOnly)
}
char RomName[260];
int count;
//Get the header from the rom image
memcpy(&RomName[0], (void *)(m_ROMImage + 0x20), 20);
for (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];
}
CN64Rom::CleanRomName(RomName);
//truncate all the spaces at the end of the string
for (count = 19; count >= 0; count--)
{
if (RomName[count] == ' ')
{
RomName[count] = '\0';
}
else if (RomName[count] == '\0')
{
}
else
{
count = -1;
}
}
RomName[20] = '\0';
if (strlen(RomName) == 0)
{
strcpy(RomName, CPath(FileLoc).GetName().c_str());
CN64Rom::CleanRomName(RomName, false);
}
//remove all /,\,: from the string
for (count = 0; count < (int)strlen(RomName); count++)
{
switch (RomName[count])
{
case '/': case '\\': RomName[count] = '-'; break;
case ':': RomName[count] = ';'; break;
}
}
WriteTrace(TraceN64System, TraceDebug, "RomName %s", RomName);
m_RomName = RomName;
@ -699,48 +709,13 @@ bool CN64Rom::LoadN64ImageIPL(const char * FileLoc, bool LoadBootCodeOnly)
}
char RomName[260];
int count;
//Get the header from the rom image
memcpy(&RomName[0], (void *)(m_ROMImage + 0x20), 20);
for (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 (count = 19; count >= 0; count--)
{
if (RomName[count] == ' ')
{
RomName[count] = '\0';
}
else if (RomName[count] == '\0')
{
}
else
{
count = -1;
}
}
RomName[20] = '\0';
CN64Rom::CleanRomName(RomName);
if (strlen(RomName) == 0)
{
strcpy(RomName, CPath(FileLoc).GetName().c_str());
}
//remove all /,\,: from the string
for (count = 0; count < (int)strlen(RomName); count++)
{
switch (RomName[count])
{
case '/': case '\\': RomName[count] = '-'; break;
case ':': RomName[count] = ';'; break;
}
CN64Rom::CleanRomName(RomName,false);
}
WriteTrace(TraceN64System, TraceDebug, "RomName %s", RomName);

View File

@ -37,6 +37,7 @@ public:
//Get a message id for the reason that you failed to load the rom
LanguageStringID GetError() const { return m_ErrorMsg; }
static CICChip GetCicChipID(uint8_t * RomData, uint64_t * CRC = NULL);
static void CleanRomName(char * RomName, bool byteswap = true);
private:
bool AllocateRomImage(uint32_t RomFileSize);

View File

@ -284,16 +284,7 @@ void CRomList::FillRomList(strlist & FileList, const char * Directory)
{
char InternalName[22];
memcpy(InternalName, (void *)(RomData + 0x20), 20);
for (int32_t count = 0; count < 20; count += 4)
{
InternalName[count] ^= InternalName[count + 3];
InternalName[count + 3] ^= InternalName[count];
InternalName[count] ^= InternalName[count + 3];
InternalName[count + 1] ^= InternalName[count + 2];
InternalName[count + 2] ^= InternalName[count + 1];
InternalName[count + 1] ^= InternalName[count + 2];
}
InternalName[20] = '\0';
CN64Rom::CleanRomName(InternalName);
wcscpy(RomInfo.InternalName, stdstr(InternalName).ToUTF16(stdstr::CODEPAGE_932).c_str());
}
RomInfo.RomSize = (int32_t)f->Size;
@ -432,7 +423,6 @@ bool CRomList::LoadDataFromRomFile(const char * FileName, uint8_t * Data, int32_
bool CRomList::FillRomInfo(ROM_INFO * pRomInfo)
{
int32_t count;
uint8_t RomData[0x1000];
if (LoadDataFromRomFile(pRomInfo->szFullFileName, RomData, sizeof(RomData), &pRomInfo->RomSize, pRomInfo->FileFormat))
@ -447,16 +437,7 @@ bool CRomList::FillRomInfo(ROM_INFO * pRomInfo)
}
char InternalName[22];
memcpy(InternalName, (void *)(RomData + 0x20), 20);
for (count = 0; count < 20; count += 4)
{
InternalName[count] ^= InternalName[count + 3];
InternalName[count + 3] ^= InternalName[count];
InternalName[count] ^= InternalName[count + 3];
InternalName[count + 1] ^= InternalName[count + 2];
InternalName[count + 2] ^= InternalName[count + 1];
InternalName[count + 1] ^= InternalName[count + 2];
}
InternalName[20] = '\0';
CN64Rom::CleanRomName(InternalName);
wcscpy(pRomInfo->InternalName, stdstr(InternalName).ToUTF16(stdstr::CODEPAGE_932).c_str());
pRomInfo->CartID[0] = *(RomData + 0x3F);
pRomInfo->CartID[1] = *(RomData + 0x3E);