From bc8d8b8fa10203892be339b1e173ead29936df62 Mon Sep 17 00:00:00 2001 From: zilmar Date: Mon, 30 Nov 2015 06:21:47 +1100 Subject: [PATCH 1/8] [Projct64] Clean up std string.cpp --- Source/Common/std string.cpp | 338 ++++++++++++++++++----------------- Source/Common/std string.h | 77 ++++---- 2 files changed, 208 insertions(+), 207 deletions(-) diff --git a/Source/Common/std string.cpp b/Source/Common/std string.cpp index 9deb6067c..2f7c2feec 100644 --- a/Source/Common/std string.cpp +++ b/Source/Common/std string.cpp @@ -6,49 +6,49 @@ stdstr::stdstr() { } -stdstr::stdstr( const std::string & str ) : - std::string(str) +stdstr::stdstr(const std::string & str) : +std::string(str) { } -stdstr::stdstr( const stdstr & str ) : - std::string((const std::string &)str) +stdstr::stdstr(const stdstr & str) : +std::string((const std::string &)str) { } -stdstr::stdstr( const char * str ) : +stdstr::stdstr(const char * str) : std::string(str ? str : "") { } strvector stdstr::Tokenize(const char * delimiter) const { - strvector tokens; + strvector tokens; - stdstr::size_type lastPos = find_first_not_of(delimiter, 0); - stdstr::size_type pos = find_first_of(delimiter, lastPos); - while (stdstr::npos != pos || stdstr::npos != lastPos) - { - tokens.push_back(substr(lastPos, pos - lastPos)); - lastPos = find_first_not_of(delimiter, pos); - pos = find_first_of(delimiter, lastPos); - } - return tokens; + stdstr::size_type lastPos = find_first_not_of(delimiter, 0); + stdstr::size_type pos = find_first_of(delimiter, lastPos); + while (stdstr::npos != pos || stdstr::npos != lastPos) + { + tokens.push_back(substr(lastPos, pos - lastPos)); + lastPos = find_first_not_of(delimiter, pos); + pos = find_first_of(delimiter, lastPos); + } + return tokens; } strvector stdstr::Tokenize(char delimiter) const { - strvector tokens; + strvector tokens; - stdstr::size_type lastPos = find_first_not_of(delimiter, 0); - stdstr::size_type pos = find_first_of(delimiter, lastPos); - while (stdstr::npos != pos || stdstr::npos != lastPos) - { - tokens.push_back(substr(lastPos, pos - lastPos)); - lastPos = find_first_not_of(delimiter, pos); - pos = find_first_of(delimiter, lastPos); - } - return tokens; + stdstr::size_type lastPos = find_first_not_of(delimiter, 0); + stdstr::size_type pos = find_first_of(delimiter, lastPos); + while (stdstr::npos != pos || stdstr::npos != lastPos) + { + tokens.push_back(substr(lastPos, pos - lastPos)); + lastPos = find_first_not_of(delimiter, pos); + pos = find_first_of(delimiter, lastPos); + } + return tokens; } void stdstr::ArgFormat(const char * strFormat, va_list & args) @@ -56,188 +56,190 @@ void stdstr::ArgFormat(const char * strFormat, va_list & args) #pragma warning(push) #pragma warning(disable:4996) - size_t nlen = _vscprintf( strFormat, args ) + 1; - char * buffer = (char *)alloca(nlen * sizeof(char)); - buffer[nlen - 1] = 0; - if(buffer != NULL) - { - vsprintf( buffer, strFormat , args ); - *this = buffer; - } + size_t nlen = _vscprintf(strFormat, args) + 1; + char * buffer = (char *)alloca(nlen * sizeof(char)); + buffer[nlen - 1] = 0; + if (buffer != NULL) + { + vsprintf(buffer, strFormat, args); + *this = buffer; + } #pragma warning(pop) } void stdstr::Format(const char * strFormat, ...) { - va_list args; - va_start(args, strFormat); - ArgFormat(strFormat,args); - va_end(args); + va_list args; + va_start(args, strFormat); + ArgFormat(strFormat, args); + va_end(args); } stdstr& stdstr::ToLower(void) { - std::transform(begin(), end(), begin(), (int(*)(int)) tolower); - return *this; + std::transform(begin(), end(), begin(), (int(*)(int)) tolower); + return *this; } stdstr& stdstr::ToUpper(void) { - std::transform(begin(), end(), begin(), (int(*)(int)) toupper); - return *this; + std::transform(begin(), end(), begin(), (int(*)(int)) toupper); + return *this; } -void stdstr::Replace(const char search, const char replace ) +void stdstr::Replace(const char search, const char replace) { - std::string& str = *this; - std::string::size_type pos = str.find( search ); - while ( pos != std::string::npos ) - { - str.replace( pos, 1, &replace ); - pos = str.find( search, pos + 1 ); - } + std::string& str = *this; + std::string::size_type pos = str.find(search); + while (pos != std::string::npos) + { + str.replace(pos, 1, &replace); + pos = str.find(search, pos + 1); + } } -void stdstr::Replace(const char * search, const char replace ) +void stdstr::Replace(const char * search, const char replace) { - std::string& str = *this; - std::string::size_type pos = str.find( search ); - size_t SearchSize = strlen(search); - while ( pos != std::string::npos ) - { - str.replace( pos, SearchSize, &replace ); - pos = str.find( search, pos + 1 ); - } + std::string& str = *this; + std::string::size_type pos = str.find(search); + size_t SearchSize = strlen(search); + while (pos != std::string::npos) + { + str.replace(pos, SearchSize, &replace); + pos = str.find(search, pos + 1); + } } -void stdstr::Replace(const std::string& search, const std::string& replace ) +void stdstr::Replace(const std::string& search, const std::string& replace) { - std::string& str = *this; - std::string::size_type pos = str.find( search ); - size_t SearchSize = search.size(); - while ( pos != std::string::npos ) - { - str.replace( pos, SearchSize, replace ); - pos = str.find( search, pos + replace.length() ); - } + std::string& str = *this; + std::string::size_type pos = str.find(search); + size_t SearchSize = search.size(); + while (pos != std::string::npos) + { + str.replace(pos, SearchSize, replace); + pos = str.find(search, pos + replace.length()); + } } -stdstr & stdstr::TrimLeft (const char * chars2remove) +stdstr & stdstr::TrimLeft(const char * chars2remove) { - if (!empty()) - { - std::string::size_type pos = find_first_not_of(chars2remove); - if (pos != std::string::npos) - { - erase(0,pos); - } else { - erase(begin(), end()); // make empty - } - } - return *this; + if (!empty()) + { + std::string::size_type pos = find_first_not_of(chars2remove); + if (pos != std::string::npos) + { + erase(0, pos); + } + else { + erase(begin(), end()); // make empty + } + } + return *this; } -stdstr & stdstr::TrimRight (const char * chars2remove) +stdstr & stdstr::TrimRight(const char * chars2remove) { - if (!empty()) - { - std::string::size_type pos = find_last_not_of(chars2remove); - if (pos != std::string::npos) - { - erase(pos+1); - } else { - erase(begin(), end()); // make empty - } - } - return *this; + if (!empty()) + { + std::string::size_type pos = find_last_not_of(chars2remove); + if (pos != std::string::npos) + { + erase(pos + 1); + } + else { + erase(begin(), end()); // make empty + } + } + return *this; } -stdstr & stdstr::Trim (const char * chars2remove) +stdstr & stdstr::Trim(const char * chars2remove) { - if (!empty()) - { - std::string::size_type pos = find_first_not_of(chars2remove); - if (pos != std::string::npos) - { - erase(0,pos); - } - else - { - erase(begin(), end()); // make empty - } + if (!empty()) + { + std::string::size_type pos = find_first_not_of(chars2remove); + if (pos != std::string::npos) + { + erase(0, pos); + } + else + { + erase(begin(), end()); // make empty + } - pos = find_last_not_of(chars2remove); - if (pos != std::string::npos) - { - erase(pos+1); - } - else - { - erase(begin(), end()); // make empty - } - } - return *this; + pos = find_last_not_of(chars2remove); + if (pos != std::string::npos) + { + erase(pos + 1); + } + else + { + erase(begin(), end()); // make empty + } + } + return *this; } -stdstr & stdstr::FromUTF16 ( const wchar_t * UTF16Source, bool * bSuccess ) +stdstr & stdstr::FromUTF16(const wchar_t * UTF16Source, bool * bSuccess) { - bool bConverted = false; + bool bConverted = false; - if (UTF16Source == NULL) - { - *this = ""; - bConverted = true; - } - else if(wcslen(UTF16Source) > 0) - { - DWORD nNeeded = WideCharToMultiByte(CP_UTF8, 0, UTF16Source, -1, NULL, 0, NULL, NULL); - if(nNeeded > 0) - { - char * buf = (char *)alloca(nNeeded + 1); - if( buf != NULL ) - { - memset(buf, 0, nNeeded + 1); + if (UTF16Source == NULL) + { + *this = ""; + bConverted = true; + } + else if (wcslen(UTF16Source) > 0) + { + DWORD nNeeded = WideCharToMultiByte(CP_UTF8, 0, UTF16Source, -1, NULL, 0, NULL, NULL); + if (nNeeded > 0) + { + char * buf = (char *)alloca(nNeeded + 1); + if (buf != NULL) + { + memset(buf, 0, nNeeded + 1); - nNeeded = WideCharToMultiByte(CP_UTF8, 0, UTF16Source, -1, buf, nNeeded, NULL, NULL); - if (nNeeded) - { - *this = buf; - bConverted = true; - } - } - } - } - if (bSuccess) - { - *bSuccess = bConverted; - } - return *this; + nNeeded = WideCharToMultiByte(CP_UTF8, 0, UTF16Source, -1, buf, nNeeded, NULL, NULL); + if (nNeeded) + { + *this = buf; + bConverted = true; + } + } + } + } + if (bSuccess) + { + *bSuccess = bConverted; + } + return *this; } -std::wstring stdstr::ToUTF16 ( bool * bSuccess) +std::wstring stdstr::ToUTF16(bool * bSuccess) { - bool bConverted = false; - std::wstring res; + bool bConverted = false; + std::wstring res; - DWORD nNeeded = MultiByteToWideChar(CP_UTF8, 0, this->c_str(), (int)this->length(), NULL, 0); - if(nNeeded > 0) - { - wchar_t * buf = (wchar_t *)alloca((nNeeded + 1) * sizeof(wchar_t)); - if( buf != NULL ) - { - memset(buf, 0, (nNeeded + 1) * sizeof(wchar_t)); + DWORD nNeeded = MultiByteToWideChar(CP_UTF8, 0, this->c_str(), (int)this->length(), NULL, 0); + if (nNeeded > 0) + { + wchar_t * buf = (wchar_t *)alloca((nNeeded + 1) * sizeof(wchar_t)); + if (buf != NULL) + { + memset(buf, 0, (nNeeded + 1) * sizeof(wchar_t)); - nNeeded = MultiByteToWideChar(CP_UTF8, 0, this->c_str(), (int)this->length(), buf, nNeeded); - if (nNeeded) - { - res = buf; - bConverted = true; - } - } - } - if (bSuccess) - { - *bSuccess = bConverted; - } - return res; -} + nNeeded = MultiByteToWideChar(CP_UTF8, 0, this->c_str(), (int)this->length(), buf, nNeeded); + if (nNeeded) + { + res = buf; + bConverted = true; + } + } + } + if (bSuccess) + { + *bSuccess = bConverted; + } + return res; +} \ No newline at end of file diff --git a/Source/Common/std string.h b/Source/Common/std string.h index c7ebd007e..53931831b 100644 --- a/Source/Common/std string.h +++ b/Source/Common/std string.h @@ -9,63 +9,62 @@ class stdstr; typedef std::vector strvector; -class stdstr : - public std::string +class stdstr : + public std::string { public: - stdstr(); - stdstr( const std::string & str ); - stdstr( const stdstr & str ); - stdstr( const char * str ); + stdstr(); + stdstr(const std::string & str); + stdstr(const stdstr & str); + stdstr(const char * str); - strvector Tokenize ( char delimiter ) const; - strvector Tokenize ( const char * delimiter ) const; - void Format ( const char * strFormat, ... ); - stdstr& ToLower ( void ); - stdstr& ToUpper ( void ); + strvector Tokenize(char delimiter) const; + strvector Tokenize(const char * delimiter) const; + void Format(const char * strFormat, ...); + stdstr& ToLower(void); + stdstr& ToUpper(void); - void Replace ( const char search, const char replace ); - void Replace ( const char * search, const char replace ); - void Replace ( const std::string & search, const std::string & replace ); + void Replace(const char search, const char replace); + void Replace(const char * search, const char replace); + void Replace(const std::string & search, const std::string & replace); - stdstr & Trim ( const char * chars2remove = "\t " ); - stdstr & TrimLeft ( const char * chars2remove = "\t " ); - stdstr & TrimRight ( const char * chars2remove = "\t " ); + stdstr & Trim(const char * chars2remove = "\t "); + stdstr & TrimLeft(const char * chars2remove = "\t "); + stdstr & TrimRight(const char * chars2remove = "\t "); - stdstr & FromUTF16 ( const wchar_t * UTF16Source, bool * bSuccess = NULL); - std::wstring ToUTF16 ( bool * bSuccess = NULL); + stdstr & FromUTF16(const wchar_t * UTF16Source, bool * bSuccess = NULL); + std::wstring ToUTF16(bool * bSuccess = NULL); - void ArgFormat( const char * strFormat, va_list & args); + void ArgFormat(const char * strFormat, va_list & args); +}; -}; - -class stdstr_f: public stdstr +class stdstr_f : public stdstr { public: - stdstr_f(const char * strFormat, ...) - { - va_list args; - va_start(args, strFormat); - ArgFormat(strFormat,args); - va_end(args); - } + stdstr_f(const char * strFormat, ...) + { + va_list args; + va_start(args, strFormat); + ArgFormat(strFormat, args); + va_end(args); + } }; class stdwstr_f : public std::wstring { public: - stdwstr_f(const wchar_t * strFormat, ...) - { - va_list args; - va_start(args, strFormat); + stdwstr_f(const wchar_t * strFormat, ...) + { + va_list args; + va_start(args, strFormat); - wchar_t Msg[1000]; - _vsnwprintf(Msg, sizeof(Msg) - 1, strFormat, args); + wchar_t Msg[1000]; + _vsnwprintf(Msg, sizeof(Msg) - 1, strFormat, args); - va_end(args); + va_end(args); - this->assign(Msg); - } + this->assign(Msg); + } }; typedef std::list strlist; From 942e07569afb4416028405d141a97e387add52c5 Mon Sep 17 00:00:00 2001 From: zilmar Date: Mon, 30 Nov 2015 06:25:09 +1100 Subject: [PATCH 2/8] [Project64] Add codepage stdstr::ToUTF16 --- Source/Common/std string.cpp | 6 +++--- Source/Common/std string.h | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Source/Common/std string.cpp b/Source/Common/std string.cpp index 2f7c2feec..a868d2ada 100644 --- a/Source/Common/std string.cpp +++ b/Source/Common/std string.cpp @@ -216,12 +216,12 @@ stdstr & stdstr::FromUTF16(const wchar_t * UTF16Source, bool * bSuccess) return *this; } -std::wstring stdstr::ToUTF16(bool * bSuccess) +std::wstring stdstr::ToUTF16(UINT CodePage, bool * bSuccess) { bool bConverted = false; std::wstring res; - DWORD nNeeded = MultiByteToWideChar(CP_UTF8, 0, this->c_str(), (int)this->length(), NULL, 0); + DWORD nNeeded = MultiByteToWideChar(CodePage, 0, this->c_str(), (int)this->length(), NULL, 0); if (nNeeded > 0) { wchar_t * buf = (wchar_t *)alloca((nNeeded + 1) * sizeof(wchar_t)); @@ -229,7 +229,7 @@ std::wstring stdstr::ToUTF16(bool * bSuccess) { memset(buf, 0, (nNeeded + 1) * sizeof(wchar_t)); - nNeeded = MultiByteToWideChar(CP_UTF8, 0, this->c_str(), (int)this->length(), buf, nNeeded); + nNeeded = MultiByteToWideChar(CodePage, 0, this->c_str(), (int)this->length(), buf, nNeeded); if (nNeeded) { res = buf; diff --git a/Source/Common/std string.h b/Source/Common/std string.h index 53931831b..9fd743068 100644 --- a/Source/Common/std string.h +++ b/Source/Common/std string.h @@ -13,6 +13,12 @@ class stdstr : public std::string { public: + enum + { + CODEPAGE_UTF8 = 65001, + CODEPAGE_932 = 932, + }; + stdstr(); stdstr(const std::string & str); stdstr(const stdstr & str); @@ -33,7 +39,7 @@ public: stdstr & TrimRight(const char * chars2remove = "\t "); stdstr & FromUTF16(const wchar_t * UTF16Source, bool * bSuccess = NULL); - std::wstring ToUTF16(bool * bSuccess = NULL); + std::wstring ToUTF16(unsigned int CodePage = CODEPAGE_UTF8, bool * bSuccess = NULL); void ArgFormat(const char * strFormat, va_list & args); }; From 655a73e1face690986901a1f9f9dd279e3f308f7 Mon Sep 17 00:00:00 2001 From: zilmar Date: Mon, 30 Nov 2015 06:26:41 +1100 Subject: [PATCH 3/8] [Project64] Use CODEPAGE_932 for internal name in Rom Browser --- Source/Project64/User Interface/Rom Browser Class.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Project64/User Interface/Rom Browser Class.cpp b/Source/Project64/User Interface/Rom Browser Class.cpp index 7fc323cfd..628231e1f 100644 --- a/Source/Project64/User Interface/Rom Browser Class.cpp +++ b/Source/Project64/User Interface/Rom Browser Class.cpp @@ -474,7 +474,7 @@ bool CRomBrowser::FillRomInfo(ROM_INFO * pRomInfo) InternalName[count + 1] ^= InternalName[count + 2]; } InternalName[20] = '\0'; - wcscpy(pRomInfo->InternalName, stdstr(InternalName).ToUTF16().c_str()); + wcscpy(pRomInfo->InternalName, stdstr(InternalName).ToUTF16(stdstr::CODEPAGE_932).c_str()); } pRomInfo->CartID[0] = *(RomData + 0x3F); pRomInfo->CartID[1] = *(RomData + 0x3E); @@ -728,7 +728,7 @@ void CRomBrowser::FillRomList(strlist & FileList, const CPath & BaseDirectory, c InternalName[count + 1] ^= InternalName[count + 2]; } InternalName[20] = '\0'; - wcscpy(RomInfo.InternalName, stdstr(InternalName).ToUTF16().c_str()); + wcscpy(RomInfo.InternalName, stdstr(InternalName).ToUTF16(stdstr::CODEPAGE_932).c_str()); } RomInfo.RomSize = (int32_t)f->Size; From 1b19da61158b8bf5663cc6e00ddefaea47eb2a6e Mon Sep 17 00:00:00 2001 From: zilmar Date: Mon, 30 Nov 2015 06:27:46 +1100 Subject: [PATCH 4/8] [Project64] Do not strcpy on empty item --- Source/Project64/User Interface/Rom Browser Class.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Project64/User Interface/Rom Browser Class.cpp b/Source/Project64/User Interface/Rom Browser Class.cpp index 628231e1f..1e0762cdc 100644 --- a/Source/Project64/User Interface/Rom Browser Class.cpp +++ b/Source/Project64/User Interface/Rom Browser Class.cpp @@ -1431,7 +1431,7 @@ void CRomBrowser::RomList_GetDispInfo(uint32_t pnmh) break; default: wcsncpy(lpdi->item.pszText, L" ", lpdi->item.cchTextMax); } - if (lpdi->item.pszText == NULL || wcslen(lpdi->item.pszText) == 0) { wcscpy(lpdi->item.pszText, L" "); } + if (lpdi->item.pszText == NULL || wcslen(lpdi->item.pszText) == 0) { lpdi->item.pszText = L" "; } } void CRomBrowser::RomList_OpenRom(uint32_t /*pnmh*/) From 4770198dae14df12b40a73cf90d8a5d770f05282 Mon Sep 17 00:00:00 2001 From: zilmar Date: Tue, 1 Dec 2015 04:06:51 +1100 Subject: [PATCH 5/8] [Project64] Rom Browser to use ansi file names --- Source/Project64/User Interface/Gui Class.cpp | 10 ++-- .../User Interface/Rom Browser Class.cpp | 54 +++++++++---------- Source/Project64/User Interface/Rom Browser.h | 14 ++--- 3 files changed, 38 insertions(+), 40 deletions(-) diff --git a/Source/Project64/User Interface/Gui Class.cpp b/Source/Project64/User Interface/Gui Class.cpp index 9773df571..2d5beab52 100644 --- a/Source/Project64/User Interface/Gui Class.cpp +++ b/Source/Project64/User Interface/Gui Class.cpp @@ -450,7 +450,7 @@ void CMainGui::Caption(LPCWSTR Caption) void CMainGui::Create(const char * WindowTitle) { stdstr_f VersionDisplay("Project64 %s", VER_FILE_VERSION_STR); - m_hMainWindow = CreateWindowExW(WS_EX_ACCEPTFILES, VersionDisplay.ToUTF16().c_str(), stdstr(WindowTitle).ToUTF16().c_str(), WS_OVERLAPPED | WS_CLIPCHILDREN | + m_hMainWindow = CreateWindowExW(WS_EX_ACCEPTFILES, VersionDisplay.ToUTF16().c_str(), stdstr(WindowTitle).ToUTF16().c_str(), WS_OVERLAPPED | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_SYSMENU | WS_MINIMIZEBOX, 5, 5, 640, 480, NULL, NULL, GetModuleHandle(NULL), this); m_Created = m_hMainWindow != NULL; @@ -972,12 +972,12 @@ LRESULT CALLBACK CMainGui::MainGui_Proc(HWND hWnd, DWORD uMsg, DWORD wParam, DWO if (_this == NULL) { break; } switch (LOWORD(wParam)) { - case ID_POPUPMENU_PLAYGAME: g_BaseSystem->RunFileImage(stdstr().FromUTF16(_this->CurrentedSelectedRom()).c_str()); break; + case ID_POPUPMENU_PLAYGAME: g_BaseSystem->RunFileImage(_this->CurrentedSelectedRom()); break; case ID_POPUPMENU_ROMDIRECTORY: _this->SelectRomDir(); break; case ID_POPUPMENU_REFRESHROMLIST: _this->RefreshRomBrowser(); break; case ID_POPUPMENU_ROMINFORMATION: { - RomInformation Info(stdstr().FromUTF16(_this->CurrentedSelectedRom()).c_str()); + RomInformation Info(_this->CurrentedSelectedRom()); Info.DisplayInformation(hWnd); } break; @@ -985,7 +985,7 @@ LRESULT CALLBACK CMainGui::MainGui_Proc(HWND hWnd, DWORD uMsg, DWORD wParam, DWO case ID_POPUPMENU_EDITCHEATS: { CN64Rom Rom; - Rom.LoadN64Image(stdstr().FromUTF16(_this->CurrentedSelectedRom()).c_str(), true); + Rom.LoadN64Image(_this->CurrentedSelectedRom(), true); Rom.SaveRomSettingID(true); if (LOWORD(wParam) == ID_POPUPMENU_EDITSETTINGS) @@ -1039,7 +1039,7 @@ LRESULT CALLBACK CMainGui::MainGui_Proc(HWND hWnd, DWORD uMsg, DWORD wParam, DWO if (g_Plugins->Gfx() && g_Plugins->Gfx()->OnRomBrowserMenuItem != NULL) { CN64Rom Rom; - if (!Rom.LoadN64Image(stdstr().FromUTF16(_this->CurrentedSelectedRom()).c_str(), true)) + if (!Rom.LoadN64Image(_this->CurrentedSelectedRom(), true)) { break; } diff --git a/Source/Project64/User Interface/Rom Browser Class.cpp b/Source/Project64/User Interface/Rom Browser Class.cpp index 1e0762cdc..cff591219 100644 --- a/Source/Project64/User Interface/Rom Browser Class.cpp +++ b/Source/Project64/User Interface/Rom Browser Class.cpp @@ -277,17 +277,17 @@ int32_t CRomBrowser::CalcSortPosition(uint32_t lParam) return End + 1; } -void CRomBrowser::AddRomToList(const wchar_t * RomLocation, const wchar_t * lpLastRom) +void CRomBrowser::AddRomToList(const char * RomLocation, const char * lpLastRom) { ROM_INFO RomInfo; memset(&RomInfo, 0, sizeof(ROM_INFO)); - wcsncpy(RomInfo.szFullFileName, RomLocation, (sizeof(RomInfo.szFullFileName) / sizeof(RomInfo.szFullFileName[0])) - 1); + strncpy(RomInfo.szFullFileName, RomLocation, (sizeof(RomInfo.szFullFileName) / sizeof(RomInfo.szFullFileName[0])) - 1); if (!FillRomInfo(&RomInfo)) { return; } AddRomInfoToList(RomInfo, lpLastRom); } -void CRomBrowser::AddRomInfoToList(ROM_INFO &RomInfo, const wchar_t * lpLastRom) +void CRomBrowser::AddRomInfoToList(ROM_INFO &RomInfo, const char * lpLastRom) { int32_t ListPos = m_RomInfo.size(); m_RomInfo.push_back(RomInfo); @@ -305,7 +305,7 @@ void CRomBrowser::AddRomInfoToList(ROM_INFO &RomInfo, const wchar_t * lpLastRom) //if (iItem == -1) { return; } //if the last rom then highlight the item - if (iItem < 0 && _wcsicmp(RomInfo.szFullFileName, lpLastRom) == 0) + if (iItem < 0 && _stricmp(RomInfo.szFullFileName, lpLastRom) == 0) { ListView_SetItemState(m_hRomList, index, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); } @@ -451,14 +451,14 @@ bool CRomBrowser::FillRomInfo(ROM_INFO * pRomInfo) } else { - if (wcsstr(pRomInfo->szFullFileName, L"?") != NULL) + if (strstr(pRomInfo->szFullFileName, "?") != NULL) { - wcscpy(pRomInfo->FileName, wcsstr(pRomInfo->szFullFileName, L"?") + 1); + strcpy(pRomInfo->FileName, strstr(pRomInfo->szFullFileName, "?") + 1); } else { - wchar_t drive[_MAX_DRIVE], dir[_MAX_DIR], ext[_MAX_EXT]; - _wsplitpath(pRomInfo->szFullFileName, drive, dir, pRomInfo->FileName, ext); + char drive[_MAX_DRIVE], dir[_MAX_DIR], ext[_MAX_EXT]; + _splitpath(pRomInfo->szFullFileName, drive, dir, pRomInfo->FileName, ext); } if (m_Fields[RB_InternalName].Pos() >= 0) { @@ -576,8 +576,7 @@ void CRomBrowser::FillRomList(strlist & FileList, const CPath & BaseDirectory, c CPath SearchPath(BaseDirectory, "*.*"); SearchPath.AppendDirectory(Directory.c_str()); - //TODO: Fix exception on Windows XP (Visual Studio 2010+) - //WriteTraceF(TraceDebug,__FUNCTION__ ": 1 %s",(LPCSTR)SearchPath); + WriteTraceF(TraceDebug, __FUNCTION__ ": 1 %s", (const char *)SearchPath); if (!SearchPath.FindFirst(CPath::_A_ALLFILES)) { return; @@ -589,8 +588,7 @@ void CRomBrowser::FillRomList(strlist & FileList, const CPath & BaseDirectory, c int8_t new_list_entry = 0; const uint8_t exts = sizeof(ROM_extensions) / sizeof(ROM_extensions[0]); - //TODO: Fix exception on Windows XP (Visual Studio 2010+) - //WriteTraceF(TraceDebug,__FUNCTION__ ": 2 %s m_StopRefresh = %d",(LPCSTR)SearchPath,m_StopRefresh); + WriteTraceF(TraceDebug, __FUNCTION__ ": 2 %s m_StopRefresh = %d", (const char *)SearchPath, m_StopRefresh); if (m_StopRefresh) { break; } if (SearchPath.IsDirectory()) @@ -618,7 +616,7 @@ void CRomBrowser::FillRomList(strlist & FileList, const CPath & BaseDirectory, c } if (new_list_entry) { - AddRomToList(stdstr((std::string &)SearchPath).ToUTF16().c_str(), stdstr(lpLastRom).ToUTF16().c_str()); + AddRomToList(SearchPath, lpLastRom); continue; } @@ -667,9 +665,9 @@ void CRomBrowser::FillRomList(strlist & FileList, const CPath & BaseDirectory, c stdstr_f zipFileName("%s?%s", (LPCSTR)SearchPath, FileName.c_str()); ZipFile.SetNotificationCallback((C7zip::LP7ZNOTIFICATION)NotificationCB, this); - wcsncpy(RomInfo.szFullFileName, zipFileName.ToUTF16().c_str(), sizeof(RomInfo.szFullFileName) - 1); + strncpy(RomInfo.szFullFileName, zipFileName.c_str(), sizeof(RomInfo.szFullFileName) - 1); RomInfo.szFullFileName[sizeof(RomInfo.szFullFileName) - 1] = 0; - wcscpy(RomInfo.FileName, wcsstr(RomInfo.szFullFileName, L"?") + 1); + strcpy(RomInfo.FileName, strstr(RomInfo.szFullFileName, "?") + 1); RomInfo.FileFormat = Format_7zip; WriteTrace(TraceDebug, __FUNCTION__ ": 8"); @@ -753,7 +751,7 @@ void CRomBrowser::FillRomList(strlist & FileList, const CPath & BaseDirectory, c RomInfo.SelColorBrush = (uint32_t)CreateSolidBrush(RomInfo.SelColor); } WriteTrace(TraceDebug, __FUNCTION__ ": 17"); - AddRomInfoToList(RomInfo, stdstr(lpLastRom).ToUTF16().c_str()); + AddRomInfoToList(RomInfo, lpLastRom); } } catch (...) @@ -799,7 +797,7 @@ void CRomBrowser::HighLightLastRom(void) //Get the string to the last rom stdstr LastRom = g_Settings->LoadStringIndex(File_RecentGameFileIndex, 0); - std::wstring lpLastRom = LastRom.ToUTF16(); + LPCSTR lpLastRom = LastRom.c_str(); LVITEMW lvItem; lvItem.mask = LVIF_PARAM; @@ -824,7 +822,7 @@ void CRomBrowser::HighLightLastRom(void) } //if the last rom then highlight the item - if (_wcsicmp(pRomInfo->szFullFileName, lpLastRom.c_str()) == 0) + if (_stricmp(pRomInfo->szFullFileName, lpLastRom) == 0) { ListView_SetItemState(m_hRomList, index, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); ListView_EnsureVisible(m_hRomList, index, FALSE); @@ -833,17 +831,17 @@ void CRomBrowser::HighLightLastRom(void) } } -bool CRomBrowser::LoadDataFromRomFile(const wchar_t * FileName, uint8_t * Data, int32_t DataLen, int32_t * RomSize, FILE_FORMAT & FileFormat) +bool CRomBrowser::LoadDataFromRomFile(const char * FileName, uint8_t * Data, int32_t DataLen, int32_t * RomSize, FILE_FORMAT & FileFormat) { uint8_t Test[4]; - if (_wcsnicmp(&FileName[wcslen(FileName) - 4], L".ZIP", 4) == 0) + if (_strnicmp(&FileName[strlen(FileName) - 4], ".ZIP", 4) == 0) { int32_t len, port = 0, FoundRom; unz_file_info info; char zname[132]; unzFile file; - file = unzOpen(stdstr().FromUTF16(FileName).c_str()); + file = unzOpen(FileName); if (file == NULL) { return false; } port = unzGoToFirstFile(file); @@ -896,7 +894,7 @@ bool CRomBrowser::LoadDataFromRomFile(const wchar_t * FileName, uint8_t * Data, } else { - HANDLE hFile = CreateFileW(FileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL); + HANDLE hFile = CreateFile(FileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL); if (hFile == INVALID_HANDLE_VALUE) { return false; } SetFilePointer(hFile, 0, 0, FILE_BEGIN); @@ -1213,7 +1211,7 @@ bool CRomBrowser::RomListDrawItem(int32_t idCtrl, uint32_t lParam) //Draw ListView_GetItemRect(m_hRomList, ditem->itemID, &rcItem, LVIR_LABEL); lvItem.iSubItem = 0; - lvItem.cchTextMax = sizeof(String); + lvItem.cchTextMax = sizeof(String) / sizeof(String[0]); lvItem.pszText = String; SendMessageW(m_hRomList, LVM_GETITEMTEXTW, (WPARAM)ditem->itemID, (LPARAM)&lvItem); @@ -1235,7 +1233,7 @@ bool CRomBrowser::RomListDrawItem(int32_t idCtrl, uint32_t lParam) rcItem.right += lvc.cx; lvItem.iSubItem = nColumn; - lvItem.cchTextMax = sizeof(String); + lvItem.cchTextMax = sizeof(String) / sizeof(String[0]); lvItem.pszText = String; SendMessageW(m_hRomList, LVM_GETITEMTEXTW, ditem->itemID, (LPARAM)&lvItem); memcpy(&rcDraw, &rcItem, sizeof(RECT)); @@ -1324,7 +1322,7 @@ int32_t CALLBACK CRomBrowser::RomList_CompareItems(uint32_t lParam1, uint32_t lP switch (SortFieldInfo->Key) { - case RB_FileName: result = (int32_t)lstrcmpiW(pRomInfo1->FileName, pRomInfo2->FileName); break; + case RB_FileName: result = (int32_t)lstrcmpi(pRomInfo1->FileName, pRomInfo2->FileName); break; case RB_InternalName: result = (int32_t)lstrcmpiW(pRomInfo1->InternalName, pRomInfo2->InternalName); break; case RB_GoodName: result = (int32_t)lstrcmpiW(pRomInfo1->GoodName, pRomInfo2->GoodName); break; case RB_Status: result = (int32_t)lstrcmpiW(pRomInfo1->Status, pRomInfo2->Status); break; @@ -1367,7 +1365,7 @@ void CRomBrowser::RomList_GetDispInfo(uint32_t pnmh) switch (m_FieldType[lpdi->item.iSubItem]) { - case RB_FileName: wcsncpy(lpdi->item.pszText, pRomInfo->FileName, lpdi->item.cchTextMax / sizeof(wchar_t)); break; + case RB_FileName: wcsncpy(lpdi->item.pszText, stdstr(pRomInfo->FileName).ToUTF16().c_str(), lpdi->item.cchTextMax); break; case RB_InternalName: wcsncpy(lpdi->item.pszText, pRomInfo->InternalName, lpdi->item.cchTextMax / sizeof(wchar_t)); break; case RB_GoodName: wcsncpy(lpdi->item.pszText, pRomInfo->GoodName, lpdi->item.cchTextMax / sizeof(wchar_t)); break; case RB_CoreNotes: wcsncpy(lpdi->item.pszText, pRomInfo->CoreNotes, lpdi->item.cchTextMax / sizeof(wchar_t)); break; @@ -1455,13 +1453,13 @@ void CRomBrowser::RomList_OpenRom(uint32_t /*pnmh*/) if (!pRomInfo) { return; } m_StopRefresh = true; - CN64System::RunFileImage(stdstr().FromUTF16(pRomInfo->szFullFileName).c_str()); + CN64System::RunFileImage(pRomInfo->szFullFileName); } void CRomBrowser::RomList_PopupMenu(uint32_t /*pnmh*/) { LONG iItem = ListView_GetNextItem(m_hRomList, -1, LVNI_SELECTED); - m_SelectedRom = L""; + m_SelectedRom = ""; if (iItem != -1) { LV_ITEM lvItem; diff --git a/Source/Project64/User Interface/Rom Browser.h b/Source/Project64/User Interface/Rom Browser.h index 0fe87b86e..4bf1cfcdc 100644 --- a/Source/Project64/User Interface/Rom Browser.h +++ b/Source/Project64/User Interface/Rom Browser.h @@ -107,10 +107,10 @@ class CRomBrowser struct ROM_INFO { - wchar_t szFullFileName[300]; + char szFullFileName[300]; FILE_FORMAT FileFormat; wchar_t Status[60]; - wchar_t FileName[200]; + char FileName[200]; wchar_t InternalName[22]; wchar_t GoodName[200]; wchar_t CartID[3]; @@ -142,7 +142,7 @@ class CRomBrowser ROMBROWSER_FIELDS_LIST m_Fields; FIELD_TYPE_LIST m_FieldType; ROMINFO_LIST m_RomInfo; - std::wstring m_SelectedRom; + std::string m_SelectedRom; bool m_Visible; bool m_ShowingRomBrowser; HANDLE m_RefreshThread; @@ -154,8 +154,8 @@ class CRomBrowser bool m_AllowSelectionLastRom; void AddFileNameToList(strlist & FileList, const stdstr & Directory, CPath & File); - void AddRomToList(const wchar_t * RomLocation, const wchar_t * lpLastRom); - void AddRomInfoToList(ROM_INFO &RomInfo, const wchar_t * lpLastRom); + void AddRomToList(const char * RomLocation, const char * lpLastRom); + void AddRomInfoToList(ROM_INFO &RomInfo, const char * lpLastRom); void AllocateBrushs(void); static void ByteSwapRomData(uint8_t * Data, int DataLen); int CalcSortPosition(uint32_t lParam); @@ -166,7 +166,7 @@ class CRomBrowser void FillRomList(strlist & FileList, const CPath & BaseDirectory, const stdstr & Directory, const char * lpLastRom); void FixRomListWindow(void); static int32_t GetCicChipID(uint8_t * RomData); - bool LoadDataFromRomFile(const wchar_t * FileName, uint8_t * Data, int32_t DataLen, int32_t * RomSize, FILE_FORMAT & FileFormat); + bool LoadDataFromRomFile(const char * FileName, uint8_t * Data, int32_t DataLen, int32_t * RomSize, FILE_FORMAT & FileFormat); void LoadRomList(void); void MenuSetText(HMENU hMenu, int32_t MenuPos, const wchar_t * Title, char * ShortCut); void SaveRomList(strlist & FileList); @@ -212,7 +212,7 @@ public: void SelectRomDir(void); void ShowRomList(void); bool ShowingRomBrowser(void) { return m_ShowingRomBrowser; } - const wchar_t * CurrentedSelectedRom(void) { return m_SelectedRom.c_str(); } + const char * CurrentedSelectedRom(void) { return m_SelectedRom.c_str(); } static void GetFieldInfo(ROMBROWSER_FIELDS_LIST & Fields, bool UseDefault = false); }; From b2f73ecb933c8c7cae5d33fb6f7be06b1aad1b80 Mon Sep 17 00:00:00 2001 From: LegendOfDragoon Date: Mon, 30 Nov 2015 19:45:43 -0800 Subject: [PATCH 6/8] Optimize Vector Dest Analysis in RSP Recompiler LPV, LUV, and LHV always write to an entire vector register, so it's beneficial to account for that in Vector Destination Analysis. --- Source/RSP/Recompiler Analysis.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Source/RSP/Recompiler Analysis.c b/Source/RSP/Recompiler Analysis.c index 612692e94..20d2b4337 100644 --- a/Source/RSP/Recompiler Analysis.c +++ b/Source/RSP/Recompiler Analysis.c @@ -648,14 +648,17 @@ BOOL WriteToVectorDest2 (DWORD DestReg, int PC, BOOL RecursiveCall) { case RSP_LSC2_RV: break; - case RSP_LSC2_HV: case RSP_LSC2_QV: case RSP_LSC2_BV: case RSP_LSC2_LV: - case RSP_LSC2_UV: - case RSP_LSC2_PV: case RSP_LSC2_TV: break; + + case RSP_LSC2_PV: + case RSP_LSC2_UV: + case RSP_LSC2_HV: + if (DestReg == RspOp.rt) { return FALSE; } + break; default: CompilerWarning("Unkown opcode in WriteToVectorDest\n%s",RSPOpcodeName(RspOp.Hex,PC)); From 36d491c989cabe70b67608c6b75a50c38999ca90 Mon Sep 17 00:00:00 2001 From: LegendOfDragoon Date: Mon, 30 Nov 2015 20:40:01 -0800 Subject: [PATCH 7/8] Fix issue with STV in Vector Dest Analysis STV can write to multiple registers, so it needs to do extra checking to determine whether or not the destination register is used. --- Source/RSP/Recompiler Analysis.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Source/RSP/Recompiler Analysis.c b/Source/RSP/Recompiler Analysis.c index 20d2b4337..1247d4d35 100644 --- a/Source/RSP/Recompiler Analysis.c +++ b/Source/RSP/Recompiler Analysis.c @@ -678,9 +678,25 @@ BOOL WriteToVectorDest2 (DWORD DestReg, int PC, BOOL RecursiveCall) { case RSP_LSC2_HV: case RSP_LSC2_FV: case RSP_LSC2_WV: - case RSP_LSC2_TV: if (DestReg == RspOp.rt) { return TRUE; } break; + + case RSP_LSC2_TV: + if (8 <= 32 - RspOp.rt) { + if (DestReg >= RspOp.rt && DestReg <= RspOp.rt + 7) { + return TRUE; + } + } else { + int length = 32 - RspOp.rt, count, del = RspOp.del >> 1, vect = RspOp.rt; + for (count = 0; count < length; count++) { + if (DestReg == vect + del) { + return TRUE; + } + del = (del + 1) & 7; + } + } + break; + default: CompilerWarning("Unkown opcode in WriteToVectorDest\n%s",RSPOpcodeName(RspOp.Hex,PC)); return TRUE; From 92b65a4e8ad9b5ef01eeac062b06c9a0f9532bc2 Mon Sep 17 00:00:00 2001 From: Nekokabu Date: Wed, 2 Dec 2015 01:05:24 +0900 Subject: [PATCH 8/8] Fix rom info dialog --- Source/Project64/User Interface/UI Resources.rc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Project64/User Interface/UI Resources.rc b/Source/Project64/User Interface/UI Resources.rc index 71ccfc63e..ec9d23e1a 100644 --- a/Source/Project64/User Interface/UI Resources.rc +++ b/Source/Project64/User Interface/UI Resources.rc @@ -187,7 +187,7 @@ BEGIN LTEXT "CIC Chip:",IDC_CIC_CHIP,11,167,64,9 EDITTEXT IDC_INFO_CIC,77,164,153,13,ES_AUTOHSCROLL | ES_READONLY,WS_EX_CLIENTEDGE | WS_EX_STATICEDGE LTEXT "Location:",IDC_LOCATION,11,45,64,10 - EDITTEXT IDC_INFO_LOCATION,77,45,153,13,ES_AUTOHSCROLL | ES_READONLY + EDITTEXT IDC_INFO_LOCATION,77,45,153,13,ES_AUTOHSCROLL | ES_READONLY,WS_EX_CLIENTEDGE | WS_EX_STATICEDGE LTEXT "MD5:",IDC_ROM_MD5,11,60,64,9 EDITTEXT IDC_INFO_MD5,77,59,153,13,ES_AUTOHSCROLL | ES_READONLY,WS_EX_CLIENTEDGE | WS_EX_STATICEDGE END