From a497e9ef38b5ca8670a4fe3b4812a06803d2a4d6 Mon Sep 17 00:00:00 2001 From: zilmar Date: Mon, 12 Oct 2020 11:48:38 +1030 Subject: [PATCH 1/6] Project64: welcome screen was not saving drive --- Source/Project64/UserInterface/WelcomeScreen.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Project64/UserInterface/WelcomeScreen.cpp b/Source/Project64/UserInterface/WelcomeScreen.cpp index 46fd3711d..57bd7a9e8 100644 --- a/Source/Project64/UserInterface/WelcomeScreen.cpp +++ b/Source/Project64/UserInterface/WelcomeScreen.cpp @@ -103,7 +103,7 @@ LRESULT WelcomeScreen::OnOkCmd(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCt CPath GameDir(GetCWindowText(GetDlgItem(IDC_GAME_DIR)).c_str(), ""); if (GameDir.DirectoryExists()) { - g_Settings->SaveString(RomList_GameDir, GameDir.GetDirectory().c_str()); + g_Settings->SaveString(RomList_GameDir, GameDir.GetDriveDirectory().c_str()); Notify().AddRecentDir(GameDir); } EndDialog(0); From 6caa9ea47a0e9ceef90931aff83069f64823da49 Mon Sep 17 00:00:00 2001 From: zilmar Date: Mon, 12 Oct 2020 12:10:21 +1030 Subject: [PATCH 2/6] Project64: Some code clean up of N64RomClass.h --- Source/Project64-core/N64System/N64RomClass.h | 35 ++++++++++--------- Source/Project64-core/RomList/RomList.cpp | 20 +++++------ .../UserInterface/RomInformationClass.cpp | 4 +-- 3 files changed, 30 insertions(+), 29 deletions(-) diff --git a/Source/Project64-core/N64System/N64RomClass.h b/Source/Project64-core/N64System/N64RomClass.h index 221d17b0b..2babcc04f 100644 --- a/Source/Project64-core/N64System/N64RomClass.h +++ b/Source/Project64-core/N64System/N64RomClass.h @@ -21,20 +21,20 @@ public: CN64Rom(); ~CN64Rom(); - bool LoadN64Image(const char * FileLoc, bool LoadBootCodeOnly = false); - bool LoadN64ImageIPL(const char * FileLoc, bool LoadBootCodeOnly = false); + bool LoadN64Image(const char * FileLoc, bool LoadBootCodeOnly = false); + bool LoadN64ImageIPL(const char * FileLoc, bool LoadBootCodeOnly = false); static bool IsValidRomImage(uint8_t Test[4]); - bool IsLoadedRomDDIPL(); - void SaveRomSettingID(bool temp); - void ClearRomSettingID(); + bool IsLoadedRomDDIPL(); + void SaveRomSettingID(bool temp); + void ClearRomSettingID(); CICChip CicChipID(); uint8_t * GetRomAddress() { return m_ROMImage; } - uint32_t GetRomSize() const { return m_RomFileSize; } - stdstr GetRomMD5() const { return m_MD5; } - stdstr GetRomName() const { return m_RomName; } - stdstr GetFileName() const { return m_FileName; } + uint32_t GetRomSize() const { return m_RomFileSize; } + const std::string & GetRomMD5() const { return m_MD5; } + const std::string & GetRomName() const { return m_RomName; } + const std::string & GetFileName() const { return m_FileName; } Country GetCountry() const { return m_Country; } - void UnallocateRomImage(); + void UnallocateRomImage(); //Get a message id for the reason that you failed to load the rom LanguageStringID GetError() const { return m_ErrorMsg; } @@ -42,14 +42,15 @@ public: static void CleanRomName(char * RomName, bool byteswap = true); private: - bool AllocateRomImage(uint32_t RomFileSize); - bool AllocateAndLoadN64Image(const char * FileLoc, bool LoadBootCodeOnly); - bool AllocateAndLoadZipImage(const char * FileLoc, bool LoadBootCodeOnly); - void ByteSwapRom(); - void SetError(LanguageStringID ErrorMsg); + bool AllocateRomImage(uint32_t RomFileSize); + bool AllocateAndLoadN64Image(const char * FileLoc, bool LoadBootCodeOnly); + bool AllocateAndLoadZipImage(const char * FileLoc, bool LoadBootCodeOnly); + void ByteSwapRom(); + void SetError(LanguageStringID ErrorMsg); + void CalculateCicChip(); + void CalculateRomCrc(); + static void NotificationCB(const char * Status, CN64Rom * _this); - void CalculateCicChip(); - void CalculateRomCrc(); //constant values enum { ReadFromRomSection = 0x400000 }; diff --git a/Source/Project64-core/RomList/RomList.cpp b/Source/Project64-core/RomList/RomList.cpp index 2dd65c163..648acde81 100644 --- a/Source/Project64-core/RomList/RomList.cpp +++ b/Source/Project64-core/RomList/RomList.cpp @@ -148,11 +148,11 @@ void CRomList::AddRomToList(const char * RomLocation) void CRomList::FillRomList(strlist & FileList, const char * Directory) { WriteTrace(TraceRomList, TraceDebug, "Start (m_GameDir = %s, Directory: %s)", (const char *)m_GameDir, Directory); - CPath SearchPath((const char *)m_GameDir, "*"); - SearchPath.AppendDirectory(Directory); + CPath SearchDir((const char *)m_GameDir, "*"); + SearchDir.AppendDirectory(Directory); WriteTrace(TraceRomList, TraceVerbose, "SearchPath: %s", (const char *)SearchPath); - if (!SearchPath.FindFirst(CPath::FIND_ATTRIBUTE_ALLFILES)) + if (!SearchDir.FindFirst(CPath::FIND_ATTRIBUTE_ALLFILES)) { WriteTrace(TraceRomList, TraceVerbose, "No files found"); WriteTrace(TraceRomList, TraceDebug, "Done (Directory: %s)", Directory); @@ -168,20 +168,20 @@ void CRomList::FillRomList(strlist & FileList, const char * Directory) break; } - if (SearchPath.IsDirectory()) + if (SearchDir.IsDirectory()) { if (g_Settings->LoadBool(RomList_GameDirRecursive)) { CPath CurrentDir(Directory); - CurrentDir.AppendDirectory(SearchPath.GetLastDirectory().c_str()); + CurrentDir.AppendDirectory(SearchDir.GetLastDirectory().c_str()); FillRomList(FileList, CurrentDir); } continue; } - AddFileNameToList(FileList, Directory, SearchPath); + AddFileNameToList(FileList, Directory, SearchDir); - stdstr Extension = stdstr(SearchPath.GetExtension()).ToLower(); + stdstr Extension = stdstr(SearchDir.GetExtension()).ToLower(); for (uint8_t i = 0; i < sizeof(ROM_extensions) / sizeof(ROM_extensions[0]); i++) { if (Extension != ROM_extensions[i]) @@ -191,7 +191,7 @@ void CRomList::FillRomList(strlist & FileList, const char * Directory) WriteTrace(TraceRomList, TraceVerbose, "File has matching extension: \"%s\"", ROM_extensions[i]); if (Extension != "7z") { - AddRomToList(SearchPath); + AddRomToList(SearchDir); } #ifdef _WIN32 else @@ -199,7 +199,7 @@ void CRomList::FillRomList(strlist & FileList, const char * Directory) WriteTrace(TraceRomList, TraceVerbose, "Looking at contents of 7z file"); try { - C7zip ZipFile(SearchPath); + C7zip ZipFile(SearchDir); if (!ZipFile.OpenSuccess()) { continue; @@ -322,7 +322,7 @@ void CRomList::FillRomList(strlist & FileList, const char * Directory) #endif break; } - } while (SearchPath.FindNext()); + } while (SearchDir.FindNext()); #ifdef _WIN32 m_ZipIniFile->FlushChanges(); #endif diff --git a/Source/Project64/UserInterface/RomInformationClass.cpp b/Source/Project64/UserInterface/RomInformationClass.cpp index 0f6a627ff..6e59a9613 100644 --- a/Source/Project64/UserInterface/RomInformationClass.cpp +++ b/Source/Project64/UserInterface/RomInformationClass.cpp @@ -103,12 +103,12 @@ DWORD CALLBACK RomInfoProc(HWND hDlg, DWORD uMsg, DWORD wParam, DWORD lParam) SetDlgItemTextW(hDlg, IDC_CIC_CHIP, wGS(INFO_CIC_CHIP_TEXT).c_str()); SetDlgItemTextW(hDlg, IDC_CLOSE_BUTTON, wGS(BOTTOM_CLOSE).c_str()); - SetDlgItemTextW(hDlg, IDC_INFO_ROMNAME, _this->m_pRomInfo->GetRomName().ToUTF16(stdstr::CODEPAGE_932).c_str()); + SetDlgItemTextW(hDlg, IDC_INFO_ROMNAME, stdstr(_this->m_pRomInfo->GetRomName()).ToUTF16(stdstr::CODEPAGE_932).c_str()); SetDlgItemTextW(hDlg, IDC_INFO_FILENAME, stdstr(CPath(_this->m_pRomInfo->GetFileName()).GetNameExtension()).ToUTF16(CP_ACP).c_str()); SetDlgItemTextW(hDlg, IDC_INFO_LOCATION, stdstr(CPath(_this->m_pRomInfo->GetFileName()).GetDriveDirectory()).ToUTF16(CP_ACP).c_str()); - SetDlgItemTextW(hDlg, IDC_INFO_MD5, _this->m_pRomInfo->GetRomMD5().ToUTF16().c_str()); + SetDlgItemTextW(hDlg, IDC_INFO_MD5, stdstr(_this->m_pRomInfo->GetRomMD5()).ToUTF16().c_str()); SetDlgItemTextW(hDlg, IDC_INFO_ROMSIZE, stdstr_f("%.1f MBit", (float)_this->m_pRomInfo->GetRomSize() / 0x20000).ToUTF16().c_str()); BYTE * RomHeader = _this->m_pRomInfo->GetRomAddress(); From 0bff53e11cf4720da89796f00d2441cb5c729eef Mon Sep 17 00:00:00 2001 From: zilmar Date: Mon, 12 Oct 2020 14:11:19 +1030 Subject: [PATCH 3/6] Project64: Update language enum --- .../Project64-core/N64System/N64DiskClass.cpp | 37 +++++++++++-------- .../Project64-core/N64System/N64RomClass.cpp | 22 +++++------ Source/Project64-core/N64System/N64RomClass.h | 2 +- Source/Project64-core/N64System/N64Types.h | 24 ++++++++++-- 4 files changed, 54 insertions(+), 31 deletions(-) diff --git a/Source/Project64-core/N64System/N64DiskClass.cpp b/Source/Project64-core/N64System/N64DiskClass.cpp index 662b44d18..6960cb11d 100644 --- a/Source/Project64-core/N64System/N64DiskClass.cpp +++ b/Source/Project64-core/N64System/N64DiskClass.cpp @@ -19,17 +19,17 @@ #include CN64Disk::CN64Disk() : -m_DiskImage(NULL), -m_DiskImageBase(NULL), -m_DiskHeader(NULL), -m_DiskHeaderBase(NULL), -m_ErrorMsg(EMPTY_STRING), -m_DiskBufAddress(0), -m_DiskSysAddress(0), -m_DiskIDAddress(0), -m_DiskRomAddress(0), -m_DiskRamAddress(0), -m_isShadowDisk(false) + m_DiskImage(NULL), + m_DiskImageBase(NULL), + m_DiskHeader(NULL), + m_DiskHeaderBase(NULL), + m_ErrorMsg(EMPTY_STRING), + m_DiskBufAddress(0), + m_DiskSysAddress(0), + m_DiskIDAddress(0), + m_DiskRomAddress(0), + m_DiskRamAddress(0), + m_isShadowDisk(false) { } @@ -221,9 +221,14 @@ void CN64Disk::SaveDiskSettingID(bool temp) switch (GetCountry()) { - case Germany: case french: case Italian: - case Europe: case Spanish: case Australia: - case X_PAL: case Y_PAL: + case Country_Germany: + case Country_French: + case Country_Italian: + case Country_Europe: + case Country_Spanish: + case Country_Australia: + case Country_EuropeanX_PAL: + case Country_EuropeanY_PAL: g_Settings->SaveDword(Game_SystemType, SYSTEM_PAL); break; default: @@ -790,7 +795,7 @@ bool CN64Disk::IsSysSectorGood(uint32_t block, uint32_t sectorsize) //Always 0xFFFFFFFF if (*(uint32_t*)&m_DiskImage[(block * 0x4D08) + 0x18] != 0xFFFFFFFF) return false; - + uint8_t alt = 0xC; //Retail if ((block & 2) != 0) alt = 0xA; //Development @@ -945,7 +950,7 @@ uint16_t CN64Disk::LBAToPhys(uint32_t lba) uint16_t vzone_lba = 0; if (vzone != 0) vzone_lba = VZONE_LBA_TBL[m_DiskType][vzone - 1]; - + //Calculate Physical Track uint16_t track = (lba - vzone_lba) >> 1; diff --git a/Source/Project64-core/N64System/N64RomClass.cpp b/Source/Project64-core/N64System/N64RomClass.cpp index 2bead72cb..f7ff26dc6 100644 --- a/Source/Project64-core/N64System/N64RomClass.cpp +++ b/Source/Project64-core/N64System/N64RomClass.cpp @@ -324,11 +324,11 @@ void CN64Rom::CalculateRomCrc() uint32_t v0, v1; uint32_t length = 0x00100000; - // 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 + // 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 (JPN) at=0x02E90EDD , s6=0xdd // 64DD IPL (USA) at=0x02E90EDD , s6=0xde @@ -445,12 +445,12 @@ bool CN64Rom::IsLoadedRomDDIPL() { switch (CicChipID()) { - case CIC_NUS_8303: - case CIC_NUS_DDUS: - case CIC_NUS_DDTL: - return true; - default: - return false; + case CIC_NUS_8303: + case CIC_NUS_DDUS: + case CIC_NUS_DDTL: + return true; + default: + return false; } } diff --git a/Source/Project64-core/N64System/N64RomClass.h b/Source/Project64-core/N64System/N64RomClass.h index 2babcc04f..2bb8e01e2 100644 --- a/Source/Project64-core/N64System/N64RomClass.h +++ b/Source/Project64-core/N64System/N64RomClass.h @@ -28,7 +28,7 @@ public: void SaveRomSettingID(bool temp); void ClearRomSettingID(); CICChip CicChipID(); - uint8_t * GetRomAddress() { return m_ROMImage; } + uint8_t * GetRomAddress() { return m_ROMImage; } uint32_t GetRomSize() const { return m_RomFileSize; } const std::string & GetRomMD5() const { return m_MD5; } const std::string & GetRomName() const { return m_RomName; } diff --git a/Source/Project64-core/N64System/N64Types.h b/Source/Project64-core/N64System/N64Types.h index 268ad5b15..96e1a30b5 100644 --- a/Source/Project64-core/N64System/N64Types.h +++ b/Source/Project64-core/N64System/N64Types.h @@ -77,9 +77,27 @@ enum CICChip enum Country { - NTSC_BETA = 0x37, X_NTSC = 0x41, Germany = 0x44, USA = 0x45, french = 0x46, Italian = 0x49, - Japan = 0x4A, Europe = 0x50, Spanish = 0x53, Australia = 0x55, X_PAL = 0x58, Y_PAL = 0x59, - UnknownCountry = 0 + Country_NTSC_BETA = 0x37, + Country_Asian_NTSC = 0x41, + Country_Brazilian = 0x42, + Country_Chinese = 0x43, + Country_Germany = 0x44, + Country_NorthAmerica = 0x45, + Country_French = 0x46, + Country_Gateway64_NTSC = 0x47, + Country_Dutch = 0x48, + Country_Italian = 0x49, + Country_Japan = 0x4A, + Country_Korean = 0x4B, + Country_Gateway64_PAL = 0x4C, + Country_Canadian = 0x4E, + Country_Europe = 0x50, + Country_Spanish = 0x53, + Country_Australia = 0x55, + Country_Scandinavian = 0x57, + Country_EuropeanX_PAL = 0x58, + Country_EuropeanY_PAL = 0x59, + Country_Unknown = 0 }; enum PROFILE_TIMERS From f5c2c3314956593f9bb7d3a304d5a7582cb73c90 Mon Sep 17 00:00:00 2001 From: zilmar Date: Mon, 12 Oct 2020 15:01:28 +1030 Subject: [PATCH 4/6] Project64: Add CN64Rom::IsPal --- Source/Project64-core/N64System/Mips/Disk.cpp | 2 +- Source/Project64-core/N64System/N64Class.cpp | 19 +++---- .../Project64-core/N64System/N64DiskClass.cpp | 6 +-- .../Project64-core/N64System/N64RomClass.cpp | 32 +++++++----- Source/Project64-core/N64System/N64RomClass.h | 1 + .../UserInterface/RomInformationClass.cpp | 52 +++++++++---------- 6 files changed, 58 insertions(+), 54 deletions(-) diff --git a/Source/Project64-core/N64System/Mips/Disk.cpp b/Source/Project64-core/N64System/Mips/Disk.cpp index cd3cb17da..bcbe613ab 100644 --- a/Source/Project64-core/N64System/Mips/Disk.cpp +++ b/Source/Project64-core/N64System/Mips/Disk.cpp @@ -300,7 +300,7 @@ void DiskBMUpdate() else { //Read Data - if (((g_Reg->ASIC_CUR_TK >> 16) & 0x1FFF) == 6 && g_Reg->ASIC_CUR_SECTOR == 0 && g_Disk->GetCountry() != Country::UnknownCountry) + if (((g_Reg->ASIC_CUR_TK >> 16) & 0x1FFF) == 6 && g_Reg->ASIC_CUR_SECTOR == 0 && g_Disk->GetCountry() != Country_Unknown) { //Copy Protection if Retail Disk g_Reg->ASIC_STATUS &= ~DD_STATUS_DATA_RQ; diff --git a/Source/Project64-core/N64System/N64Class.cpp b/Source/Project64-core/N64System/N64Class.cpp index 2d5897637..df6ccc5fc 100644 --- a/Source/Project64-core/N64System/N64Class.cpp +++ b/Source/Project64-core/N64System/N64Class.cpp @@ -601,15 +601,15 @@ bool CN64System::SelectAndLoadFileImageIPL(Country country, bool combo) LanguageStringID IPLROMError; switch (country) { - case Country::Japan: + case Country_Japan: IPLROMPathSetting = File_DiskIPLPath; IPLROMError = MSG_IPL_REQUIRED; break; - case Country::USA: + case Country_NorthAmerica: IPLROMPathSetting = File_DiskIPLUSAPath; IPLROMError = MSG_USA_IPL_REQUIRED; break; - case Country::UnknownCountry: + case Country_Unknown: default: IPLROMPathSetting = File_DiskIPLTOOLPath; IPLROMError = MSG_TOOL_IPL_REQUIRED; @@ -990,7 +990,7 @@ void CN64System::InitRegisters(bool bPostPif, CMipsMemoryVM & MMU) //Start 64DD in Reset State and Motor Not Spinning m_Reg.ASIC_STATUS = DD_STATUS_RST_STATE | DD_STATUS_MTR_N_SPIN; m_Reg.ASIC_ID_REG = 0x00030000; - if (g_DDRom && (g_DDRom->CicChipID() == CIC_NUS_DDTL || (g_Disk && g_Disk->GetCountry() == Country::UnknownCountry))) + if (g_DDRom && (g_DDRom->CicChipID() == CIC_NUS_DDTL || (g_Disk && g_Disk->GetCountry() == Country_Unknown))) m_Reg.ASIC_ID_REG = 0x00040000; //m_Reg.REVISION_REGISTER = 0x00000511; @@ -1018,11 +1018,8 @@ void CN64System::InitRegisters(bool bPostPif, CMipsMemoryVM & MMU) m_Reg.m_GPR[29].DW = 0xFFFFFFFFA4001FF0; m_Reg.m_GPR[30].DW = 0x0000000000000000; - switch (g_Rom->GetCountry()) + if (g_Rom->IsPal()) { - case Germany: case french: case Italian: - case Europe: case Spanish: case Australia: - case X_PAL: case Y_PAL: switch (g_Rom->CicChipID()) { case CIC_UNKNOWN: @@ -1051,9 +1048,9 @@ void CN64System::InitRegisters(bool bPostPif, CMipsMemoryVM & MMU) m_Reg.m_GPR[20].DW = 0x0000000000000000; m_Reg.m_GPR[23].DW = 0x0000000000000006; m_Reg.m_GPR[31].DW = 0xFFFFFFFFA4001554; - break; - case NTSC_BETA: case X_NTSC: case USA: case Japan: - default: + } + else + { switch (g_Rom->CicChipID()) { case CIC_UNKNOWN: diff --git a/Source/Project64-core/N64System/N64DiskClass.cpp b/Source/Project64-core/N64System/N64DiskClass.cpp index 6960cb11d..d27844a25 100644 --- a/Source/Project64-core/N64System/N64DiskClass.cpp +++ b/Source/Project64-core/N64System/N64DiskClass.cpp @@ -816,12 +816,12 @@ Country CN64Disk::GetDiskCountryCode() switch (*(uint32_t*)&GetDiskAddressSys()[0]) { case DISK_COUNTRY_JPN: - return Japan; + return Country_Japan; case DISK_COUNTRY_USA: - return USA; + return Country_NorthAmerica; case DISK_COUNTRY_DEV: default: - return UnknownCountry; + return Country_Unknown; } } diff --git a/Source/Project64-core/N64System/N64RomClass.cpp b/Source/Project64-core/N64System/N64RomClass.cpp index f7ff26dc6..4f612886a 100644 --- a/Source/Project64-core/N64System/N64RomClass.cpp +++ b/Source/Project64-core/N64System/N64RomClass.cpp @@ -27,7 +27,7 @@ CN64Rom::CN64Rom() : m_ROMImageBase(NULL), m_RomFileSize(0), m_ErrorMsg(EMPTY_STRING), - m_Country(UnknownCountry), + m_Country(Country_Unknown), m_CicChip(CIC_UNKNOWN) { } @@ -849,18 +849,7 @@ void CN64Rom::SaveRomSettingID(bool temp) g_Settings->SaveString(Game_GameName, m_RomName.c_str()); g_Settings->SaveString(Game_IniKey, m_RomIdent.c_str()); g_Settings->SaveString(Game_UniqueSaveDir, stdstr_f("%s-%s", m_RomName.c_str(), m_MD5.c_str()).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; - } + g_Settings->SaveDword(Game_SystemType, IsPal() ? SYSTEM_PAL : SYSTEM_NTSC); } void CN64Rom::ClearRomSettingID() @@ -874,6 +863,23 @@ void CN64Rom::SetError(LanguageStringID ErrorMsg) m_ErrorMsg = ErrorMsg; } +bool CN64Rom::IsPal() +{ + switch (m_Country) + { + case Country_Germany: + case Country_French: + case Country_Italian: + case Country_Europe: + case Country_Spanish: + case Country_Australia: + case Country_EuropeanX_PAL: + case Country_EuropeanY_PAL: + return true; + } + return false; +} + void CN64Rom::UnallocateRomImage() { m_RomFile.Close(); diff --git a/Source/Project64-core/N64System/N64RomClass.h b/Source/Project64-core/N64System/N64RomClass.h index 2bb8e01e2..3bd3f2bc7 100644 --- a/Source/Project64-core/N64System/N64RomClass.h +++ b/Source/Project64-core/N64System/N64RomClass.h @@ -34,6 +34,7 @@ public: const std::string & GetRomName() const { return m_RomName; } const std::string & GetFileName() const { return m_FileName; } Country GetCountry() const { return m_Country; } + bool IsPal(); void UnallocateRomImage(); //Get a message id for the reason that you failed to load the rom diff --git a/Source/Project64/UserInterface/RomInformationClass.cpp b/Source/Project64/UserInterface/RomInformationClass.cpp index 6e59a9613..f1d98a542 100644 --- a/Source/Project64/UserInterface/RomInformationClass.cpp +++ b/Source/Project64/UserInterface/RomInformationClass.cpp @@ -123,19 +123,19 @@ DWORD CALLBACK RomInfoProc(HWND hDlg, DWORD uMsg, DWORD wParam, DWORD lParam) switch (RomHeader[0x3D]) { - case NTSC_BETA: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"Beta"); break; - case X_NTSC: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"NTSC"); break; - case Germany: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"Germany"); break; - case USA: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"America"); break; - case french: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"France"); break; - case Italian: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"Italy"); break; - case Japan: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"Japan"); break; - case Europe: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"Europe"); break; - case Spanish: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"Spain"); break; - case Australia: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"Australia"); break; - case X_PAL: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"PAL"); break; - case Y_PAL: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"PAL"); break; - case 0: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"None"); break; + case Country_NTSC_BETA: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"Beta"); break; + case Country_Asian_NTSC: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"NTSC"); break; + case Country_Germany: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"Germany"); break; + case Country_NorthAmerica: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"America"); break; + case Country_French: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"France"); break; + case Country_Italian: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"Italy"); break; + case Country_Japan: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"Japan"); break; + case Country_Europe: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"Europe"); break; + case Country_Spanish: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"Spain"); break; + case Country_Australia: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"Australia"); break; + case Country_EuropeanX_PAL: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"PAL"); break; + case Country_EuropeanY_PAL: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"PAL"); break; + case Country_Unknown: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"None"); break; default: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, stdstr_f(" Unknown %c (%02X)", RomHeader[0x3D], RomHeader[0x3D]).ToUTF16().c_str()); } @@ -203,19 +203,19 @@ DWORD CALLBACK RomInfoProc(HWND hDlg, DWORD uMsg, DWORD wParam, DWORD lParam) switch (DiskHeader[0x00]) { - case NTSC_BETA: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"Beta"); break; - case X_NTSC: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"NTSC"); break; - case Germany: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"Germany"); break; - case USA: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"America"); break; - case french: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"France"); break; - case Italian: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"Italy"); break; - case Japan: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"Japan"); break; - case Europe: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"Europe"); break; - case Spanish: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"Spain"); break; - case Australia: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"Australia"); break; - case X_PAL: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"PAL"); break; - case Y_PAL: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"PAL"); break; - case 0: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"None"); break; + case Country_NTSC_BETA: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"Beta"); break; + case Country_Asian_NTSC: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"NTSC"); break; + case Country_Germany: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"Germany"); break; + case Country_NorthAmerica: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"America"); break; + case Country_French: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"France"); break; + case Country_Italian: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"Italy"); break; + case Country_Japan: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"Japan"); break; + case Country_Europe: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"Europe"); break; + case Country_Spanish: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"Spain"); break; + case Country_Australia: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"Australia"); break; + case Country_EuropeanX_PAL: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"PAL"); break; + case Country_EuropeanY_PAL: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"PAL"); break; + case Country_Unknown: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, L"None"); break; default: SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, stdstr_f(" Unknown %c (%02X)", DiskHeader[0x03], DiskHeader[0x03]).ToUTF16().c_str()); } From 7e503dc1923b58586855beac88302017e6ad8dd4 Mon Sep 17 00:00:00 2001 From: zilmar Date: Mon, 12 Oct 2020 16:51:23 +1030 Subject: [PATCH 5/6] Project64: In ini handling change SectionList from vector to set --- Source/Common/IniFileClass.cpp | 10 +++--- Source/Common/IniFileClass.h | 7 ++-- Source/JoinSettings/main.cpp | 32 ++++++++--------- .../SettingType/SettingsType-Application.cpp | 36 +++++++++---------- Source/Project64/Project64.vcxproj | 3 -- Source/Project64/Project64.vcxproj.filters | 9 ----- 6 files changed, 43 insertions(+), 54 deletions(-) diff --git a/Source/Common/IniFileClass.cpp b/Source/Common/IniFileClass.cpp index 724341ed6..2430aa88b 100644 --- a/Source/Common/IniFileClass.cpp +++ b/Source/Common/IniFileClass.cpp @@ -497,7 +497,7 @@ bool CIniFileBase::DeleteSection(const char * lpSectionName) CGuard Guard(m_CS); if (!m_File.IsOpen()) { return false; } - + SaveCurrentSection(); if (!MoveToSectionNameData(lpSectionName, true)) { @@ -517,10 +517,10 @@ bool CIniFileBase::DeleteSection(const char * lpSectionName) if (result <= 1) { continue; } if (strlen(CleanLine(Input)) <= 1) { continue; } - if (Input[0] != '[') - { + if (Input[0] != '[') + { NextLine = (m_File.GetPosition() - DataSize) + ReadPos; - continue; + continue; } NextSectionStart = NextLine != 0 ? NextLine : (m_File.GetPosition() - DataSize) + ReadPos; break; @@ -869,7 +869,7 @@ void CIniFileBase::GetVectorOfSections(SectionList & sections) for (FILELOC::const_iterator iter = m_SectionsPos.begin(); iter != m_SectionsPos.end(); iter++) { - sections.push_back(iter->first); + sections.insert(iter->first); } } diff --git a/Source/Common/IniFileClass.h b/Source/Common/IniFileClass.h index d8c1adc90..5f8e5fd39 100644 --- a/Source/Common/IniFileClass.h +++ b/Source/Common/IniFileClass.h @@ -10,14 +10,15 @@ #include #include #include +#include #include class CIniFileBase { public: typedef std::map KeyValueData; - typedef std::vector SectionList; - typedef std::list strlist; + typedef std::set SectionList; + typedef std::list strlist; typedef std::pair KeyValueItem; typedef std::vector KeyValueVector; typedef void(*SortData)(KeyValueVector &); @@ -68,7 +69,7 @@ private: typedef std::map FILELOC; typedef FILELOC::iterator FILELOC_ITR; typedef std::map KeyValueList; - + std::string m_CurrentSection; bool m_CurrentSectionDirty; int m_CurrentSectionFilePos; // Where in the file is the current Section diff --git a/Source/JoinSettings/main.cpp b/Source/JoinSettings/main.cpp index 1ae778419..9eb1fa7d3 100644 --- a/Source/JoinSettings/main.cpp +++ b/Source/JoinSettings/main.cpp @@ -70,9 +70,9 @@ void SplitFile(const char * FileName, const char * Target) CIniFile CheatIniFile(FileName); CheatIniFile.GetVectorOfSections(Sections); - for (size_t i = 0, n = Sections.size(); i < n; i++) + for (CIniFile::SectionList::const_iterator SectionItr = Sections.begin(); SectionItr != Sections.end(); SectionItr++) { - const char * Section = Sections[i].c_str(); + const char * Section = SectionItr->c_str(); CIniFile::KeyValueData data; CheatIniFile.GetKeyValueData(Section, data); @@ -136,9 +136,9 @@ void RegionSection(CFile &TargetIniFile, Files &files, const char * Region, cons bool found = false; stdstr_f searchStr(":%s", RegionCode); - for (size_t i = 0, n = Sections.size(); i < n; i++) + for (CIniFile::SectionList::const_iterator SectionItr = Sections.begin(); SectionItr != Sections.end(); SectionItr++) { - const char * Section = Sections[i].c_str(); + const char * Section = SectionItr->c_str(); const char * pos = strstr(Section, searchStr.c_str()); if (pos == NULL) { @@ -147,15 +147,15 @@ void RegionSection(CFile &TargetIniFile, Files &files, const char * Region, cons found = true; break; } - + if (!found) { continue; } - for (size_t i = 0, n = Sections.size(); i < n; i++) + for (CIniFile::SectionList::const_iterator SectionItr = Sections.begin(); SectionItr != Sections.end(); SectionItr++) { - const char * Section = Sections[i].c_str(); + const char * Section = SectionItr->c_str(); CIniFile::KeyValueData data; GameIniFile.GetKeyValueData(Section, data); @@ -200,9 +200,9 @@ void JoinFile(const char * Directory, const char * Target) CIniFile::SectionList Sections; GameIniFile.GetVectorOfSections(Sections); - for (size_t i = 0, n = Sections.size(); i < n; i++) + for (CIniFile::SectionList::const_iterator SectionItr = Sections.begin(); SectionItr != Sections.end(); SectionItr++) { - const char * Section = Sections[i].c_str(); + const char * Section = SectionItr->c_str(); stdstr Name = GameIniFile.GetString(Section, "Name", Section); Name.Trim("\t ="); if (Name.size() > 0) @@ -239,7 +239,7 @@ void JoinFile(const char * Directory, const char * Target) { CIniFile::KeyValueData data; MetaIniFile.GetKeyValueData("Meta", data); - + LineData = stdstr_f("[Meta]\r\n"); TargetIniFile.Write(LineData.c_str(), (int)LineData.length()); for (CIniFile::KeyValueData::const_iterator itr = data.begin(); itr != data.end(); itr++) @@ -282,9 +282,9 @@ void UpdateNames(const char* Directory, const char* RdbFile) CIniFile::SectionList Sections; CheatFile.GetVectorOfSections(Sections); CheatFile.SetCustomSort(CustomSortData); - for (size_t i = 0, n = Sections.size(); i < n; i++) + for (CIniFile::SectionList::const_iterator SectionItr = Sections.begin(); SectionItr != Sections.end(); SectionItr++) { - const char * Section = Sections[i].c_str(); + const char * Section = SectionItr->c_str(); std::string Name = RdbIni.GetString(Section, "Good Name", ""); if (Name.empty()) { @@ -616,9 +616,9 @@ void convertGS(const char* Directory) CIniFile::SectionList Sections; CheatFile.GetVectorOfSections(Sections); CheatFile.SetCustomSort(CustomSortData); - for (size_t i = 0, n = Sections.size(); i < n; i++) + for (CIniFile::SectionList::const_iterator SectionItr = Sections.begin(); SectionItr != Sections.end(); SectionItr++) { - const char * Section = Sections[i].c_str(); + const char * Section = SectionItr->c_str(); for (uint32_t cheat = 0; cheat < MaxCheats; cheat++) { std::string CheatEntry = CheatFile.GetString(Section, stdstr_f("Cheat%d", cheat).c_str(), ""); @@ -846,9 +846,9 @@ void ConvertNew(const char * Src, const char * Dest) MaxCheats = 50000, }; - for (size_t i = 0, n = Sections.size(); i < n; i++) + for (CIniFile::SectionList::const_iterator SectionItr = Sections.begin(); SectionItr != Sections.end(); SectionItr++) { - const char * Section = Sections[i].c_str(); + const char * Section = SectionItr->c_str(); std::string GameName = SrcIniFile.GetString(Section, "Name", ""); DstCheatFile.SetName(Section, GameName.c_str()); for (uint32_t cheat = 0; cheat < MaxCheats; cheat++) diff --git a/Source/Project64-core/Settings/SettingType/SettingsType-Application.cpp b/Source/Project64-core/Settings/SettingType/SettingsType-Application.cpp index 0206ffe68..227aa7f06 100644 --- a/Source/Project64-core/Settings/SettingType/SettingsType-Application.cpp +++ b/Source/Project64-core/Settings/SettingType/SettingsType-Application.cpp @@ -121,9 +121,9 @@ void CSettingTypeApplication::ResetAll() } CIniFile::SectionList sections; m_SettingsIniFile->GetVectorOfSections(sections); - for (size_t i = 0; i < sections.size(); i++) + for (CIniFile::SectionList::const_iterator itr = sections.begin(); itr != sections.end(); itr++) { - m_SettingsIniFile->DeleteSection(sections[i].c_str()); + m_SettingsIniFile->DeleteSection(itr->c_str()); } } @@ -156,14 +156,14 @@ bool CSettingTypeApplication::Load(uint32_t Index, bool & Value) const } else { - if (g_Settings->IndexBasedSetting(m_DefaultSetting)) - { - g_Settings->LoadBoolIndex(m_DefaultSetting, Index, Value); - } - else - { - g_Settings->LoadBool(m_DefaultSetting, Value); - } + if (g_Settings->IndexBasedSetting(m_DefaultSetting)) + { + g_Settings->LoadBoolIndex(m_DefaultSetting, Index, Value); + } + else + { + g_Settings->LoadBool(m_DefaultSetting, Value); + } } } return bRes; @@ -203,13 +203,13 @@ void CSettingTypeApplication::LoadDefault(uint32_t Index, bool & Value) const { Value = m_DefaultValue != 0; } - else if (g_Settings->IndexBasedSetting(m_DefaultSetting)) - { - g_Settings->LoadBoolIndex(m_DefaultSetting, Index, Value); - } - else - { - g_Settings->LoadBool(m_DefaultSetting, Value); + else if (g_Settings->IndexBasedSetting(m_DefaultSetting)) + { + g_Settings->LoadBoolIndex(m_DefaultSetting, Index, Value); + } + else + { + g_Settings->LoadBool(m_DefaultSetting, Value); } } } @@ -233,7 +233,7 @@ void CSettingTypeApplication::LoadDefault(uint32_t /*Index*/, std::string & Valu //Update the settings void CSettingTypeApplication::Save(uint32_t Index, bool Value) { - bool indexed = g_Settings->IndexBasedSetting(m_DefaultSetting); + bool indexed = g_Settings->IndexBasedSetting(m_DefaultSetting); if (m_DefaultSetting != Default_None && ((m_DefaultSetting == Default_Constant && m_DefaultValue == (uint32_t)Value) || diff --git a/Source/Project64/Project64.vcxproj b/Source/Project64/Project64.vcxproj index cfaf32fad..1e9afd451 100644 --- a/Source/Project64/Project64.vcxproj +++ b/Source/Project64/Project64.vcxproj @@ -118,10 +118,8 @@ - - @@ -157,7 +155,6 @@ - diff --git a/Source/Project64/Project64.vcxproj.filters b/Source/Project64/Project64.vcxproj.filters index d436f28fe..687fd4bcf 100644 --- a/Source/Project64/Project64.vcxproj.filters +++ b/Source/Project64/Project64.vcxproj.filters @@ -353,9 +353,6 @@ Header Files - - Header Files - Header Files\User Interface Headers\WTL Controls Headers @@ -428,9 +425,6 @@ Header Files\User Interface Headers\Debugger Headers - - Header Files\User Interface Headers\Debugger Headers - Header Files\User Interface Headers\Debugger Headers @@ -461,9 +455,6 @@ Header Files\User Interface Headers\Settings Header - - Header Files - Header Files\User Interface Headers\WTL Controls Headers From 373df2a912adae2edca974c04252bd5454f2e854 Mon Sep 17 00:00:00 2001 From: zilmar Date: Thu, 22 Oct 2020 12:37:09 +1030 Subject: [PATCH 6/6] Project64: Provide ability for alternate identifier game settings --- Config/Project64.rdb | 3 +++ .../Project64-core/N64System/N64RomClass.cpp | 20 +++++++++++++++++++ Source/Project64-core/RomList/RomList.cpp | 14 ++++++++++++- Source/Project64-core/RomList/RomList.h | 1 + 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/Config/Project64.rdb b/Config/Project64.rdb index 8be597483..80aa8377d 100644 --- a/Config/Project64.rdb +++ b/Config/Project64.rdb @@ -5872,6 +5872,9 @@ SMM-TLB=0 Self Texture=1 RDRAM Size=8 +[THE LEGEND OF ZELDA-C:45] +Alt Identifier=EC7011B7-7616D72B-C:45 + [EC7011B7-7616D72B-C:45] Good Name=The Legend of Zelda - Ocarina of Time (U) (V1.0) Internal Name=THE LEGEND OF ZELDA diff --git a/Source/Project64-core/N64System/N64RomClass.cpp b/Source/Project64-core/N64System/N64RomClass.cpp index 4f612886a..e8870255f 100644 --- a/Source/Project64-core/N64System/N64RomClass.cpp +++ b/Source/Project64-core/N64System/N64RomClass.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #ifdef _WIN32 @@ -654,6 +655,25 @@ bool CN64Rom::LoadN64Image(const char * FileLoc, bool LoadBootCodeOnly) } m_RomIdent = stdstr_f("%08X-%08X-C:%X", CRC1, CRC2, m_ROMImage[0x3D]); + { + CIniFileBase::SectionList GameIdentifiers; + CIniFile RomDatabase(g_Settings->LoadStringVal(SupportFile_RomDatabase).c_str()); + RomDatabase.GetVectorOfSections(GameIdentifiers); + + if (GameIdentifiers.find(m_RomIdent.c_str()) == GameIdentifiers.end()) + { + char InternalName[22] = { 0 }; + memcpy(InternalName, (void *)(m_ROMImage + 0x20), 20); + CN64Rom::CleanRomName(InternalName); + + std::string AltIdentifier = stdstr_f("%s-C:%X", stdstr(InternalName).Trim().ToUpper().c_str(), m_Country); + AltIdentifier = RomDatabase.GetString(AltIdentifier.c_str(), "Alt Identifier", ""); + if (!AltIdentifier.empty()) + { + m_RomIdent = AltIdentifier; + } + } + } WriteTrace(TraceN64System, TraceDebug, "Ident: %s", m_RomIdent.c_str()); if (!LoadBootCodeOnly && g_Rom == this) diff --git a/Source/Project64-core/RomList/RomList.cpp b/Source/Project64-core/RomList/RomList.cpp index 648acde81..762b326de 100644 --- a/Source/Project64-core/RomList/RomList.cpp +++ b/Source/Project64-core/RomList/RomList.cpp @@ -59,6 +59,10 @@ CRomList::CRomList() : #endif g_Settings->RegisterChangeCB(RomList_GameDir, this, (CSettings::SettingChangedFunc)RefreshSettings); } + if (m_RomIniFile) + { + m_RomIniFile->GetVectorOfSections(m_GameIdentifiers); + } WriteTrace(TraceRomList, TraceVerbose, "Done"); } @@ -582,9 +586,17 @@ void CRomList::FillRomExtensionInfo(ROM_INFO * pRomInfo) strcpy(pRomInfo->Name, "#321#"); strcpy(pRomInfo->Status, "Unknown"); - //Get File Identifier char Identifier[100]; sprintf(Identifier, "%08X-%08X-C:%X", pRomInfo->CRC1, pRomInfo->CRC2, pRomInfo->Country); + if (m_GameIdentifiers.find(Identifier) == m_GameIdentifiers.end()) + { + std::string AltIdentifier = stdstr_f("%s-C:%X", stdstr(pRomInfo->InternalName).Trim().ToUpper().c_str(), pRomInfo->Country); + AltIdentifier = m_RomIniFile->GetString(AltIdentifier.c_str(), "Alt Identifier", ""); + if (!AltIdentifier.empty()) + { + strcpy(Identifier, AltIdentifier.c_str()); + } + } //Rom Notes strncpy(pRomInfo->UserNotes, m_NotesIniFile->GetString(Identifier, "Note", "").c_str(), sizeof(pRomInfo->UserNotes) / sizeof(char)); diff --git a/Source/Project64-core/RomList/RomList.h b/Source/Project64-core/RomList/RomList.h index a1e2b759f..e79345391 100644 --- a/Source/Project64-core/RomList/RomList.h +++ b/Source/Project64-core/RomList/RomList.h @@ -95,6 +95,7 @@ private: CIniFile * m_ZipIniFile; #endif CThread m_RefreshThread; + CIniFileBase::SectionList m_GameIdentifiers; #define DISKSIZE_MAME 0x0435B0C0 #define DISKSIZE_SDK 0x03DEC800