From b4e78e3d2cf86d0a55a071215354a40eb351a4cd Mon Sep 17 00:00:00 2001 From: gocha Date: Mon, 16 Jul 2012 20:03:47 +0900 Subject: [PATCH 1/6] win32: fix Cheat Search not to add the same cheat twice. win32: RAM Search can add multi-byte cheat from now. --- win32/wsnes9x.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/win32/wsnes9x.cpp b/win32/wsnes9x.cpp index 510c5914..cbcf7cc3 100644 --- a/win32/wsnes9x.cpp +++ b/win32/wsnes9x.cpp @@ -9583,16 +9583,7 @@ INT_PTR CALLBACK DlgCheatSearch(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lPara } cht.format=val_type; //invoke dialog - if(!DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_CHEAT_FROM_SEARCH), hDlg, DlgCheatSearchAdd, (LPARAM)&cht)) - { - int p; - for(p=0; p>(8*p))&0xFF)); - //add cheat - strcpy(Cheat.c[Cheat.num_cheats-1].name, cht.name); - } - } + DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_CHEAT_FROM_SEARCH), hDlg, DlgCheatSearchAdd, (LPARAM)&cht); } break; case IDC_C_RESET: @@ -10102,8 +10093,11 @@ INT_PTR CALLBACK DlgCheatSearchAdd(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lP strncpy(new_cheat->name,_tToChar(tempBuf),22); new_cheat->enabled=TRUE; - S9xAddCheat(new_cheat->enabled,new_cheat->saved_val,new_cheat->address,new_cheat->new_val); - strcpy(Cheat.c[Cheat.num_cheats-1].name,new_cheat->name); + for(int byteIndex = 0; byteIndex < new_cheat->size; byteIndex++) + { + S9xAddCheat(new_cheat->enabled,new_cheat->saved_val,new_cheat->address+byteIndex,(new_cheat->new_val>>(8*byteIndex))&0xFF); + strcpy(Cheat.c[Cheat.num_cheats-1].name,new_cheat->name); + } ret=0; } } From a91dfcb39b41a71a6efd9e8e12bfe16ad991f9c1 Mon Sep 17 00:00:00 2001 From: gocha Date: Mon, 16 Jul 2012 19:03:49 +0900 Subject: [PATCH 2/6] =?UTF-8?q?win32:=20improve=20DBCS=20processing=20in?= =?UTF-8?q?=20S9xBasename.=20This=20one=20should=20process=20S9xBasename("?= =?UTF-8?q?C:\roms\=E3=82=BD=E3=82=A6=E3=83=AB=E3=83=96=E3=83=AC=E3=82=A4?= =?UTF-8?q?=E3=83=80=E3=83=BC.smc")=20correctly.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- win32/win32.cpp | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/win32/win32.cpp b/win32/win32.cpp index 7d4a52fb..34922807 100644 --- a/win32/win32.cpp +++ b/win32/win32.cpp @@ -611,16 +611,28 @@ void S9xSyncSpeed( void) const char *S9xBasename (const char *f) { - const char *p; - if ((p = strrchr (f, '/')) != NULL || (p = strrchr (f, '\\')) != NULL) - return (p + 1); + const char *p = f; + const char *last = p; + const char *slash; -#ifdef __DJGPP - if (p = _tcsrchr (f, SLASH_CHAR)) - return (p + 1); + // search rightmost separator + while ((slash = strchr (p, '/')) != NULL || (slash = strchr (p, '\\')) != NULL) + { + p = slash + 1; + +#ifdef UNICODE + // update always; UTF-8 doesn't have a problem between ASCII character and multi-byte character. + last = p; +#else + // update if it's not a trailer byte of a double-byte character. + if (CharPrev(f, p) == slash) + { + last = p; + } #endif + } - return (f); + return last; } bool8 S9xReadMousePosition (int which, int &x, int &y, uint32 &buttons) From e4bf711227db798eaef7900f43fee1092dd8747e Mon Sep 17 00:00:00 2001 From: gocha Date: Sun, 22 Jul 2012 09:21:12 +0900 Subject: [PATCH 3/6] win32: fix newly introduced bug of S9xBasename. I guess it could provide a wrong result when it processes a string which has both slash and backslash. --- win32/win32.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/win32/win32.cpp b/win32/win32.cpp index 34922807..db4eedfb 100644 --- a/win32/win32.cpp +++ b/win32/win32.cpp @@ -614,10 +614,25 @@ const char *S9xBasename (const char *f) const char *p = f; const char *last = p; const char *slash; + const char *backslash; // search rightmost separator - while ((slash = strchr (p, '/')) != NULL || (slash = strchr (p, '\\')) != NULL) + while (true) { + slash = strchr (p, '/'); + backslash = strchr (p, '\\'); + if (backslash != NULL) + { + if (slash == NULL || slash > backslash) + { + slash = backslash; + } + } + if (slash == NULL) + { + break; + } + p = slash + 1; #ifdef UNICODE From 5d6d3af4a94c8818307623f3a60c5edf74d40a85 Mon Sep 17 00:00:00 2001 From: gocha Date: Sun, 22 Jul 2012 14:57:35 +0200 Subject: [PATCH 4/6] win32: Unicode - fix Custom ROM dialog to show half-width katakana --- win32/_tfwopen.cpp | 6 ++++++ win32/_tfwopen.h | 9 +++++++++ win32/wsnes9x.cpp | 8 ++++---- win32/wsnes9x.h | 2 ++ 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/win32/_tfwopen.cpp b/win32/_tfwopen.cpp index f13c301b..3ec11451 100644 --- a/win32/_tfwopen.cpp +++ b/win32/_tfwopen.cpp @@ -192,6 +192,12 @@ WideToUtf8::WideToUtf8(const wchar_t *wideChars) { WideCharToMultiByte(CP_UTF8,0,wideChars,-1,utf8Chars,requiredChars,NULL,NULL); } +MS932ToWide::MS932ToWide(const char *ms932Chars) { + int requiredChars = MultiByteToWideChar(932,0,ms932Chars,-1,wideChars,0); + wideChars = new wchar_t[requiredChars]; + MultiByteToWideChar(932,0,ms932Chars,-1,wideChars,requiredChars); +} + extern "C" FILE *_tfwopen(const char *filename, const char *mode ) { wchar_t mode_w[30]; lstrcpyn(mode_w,Utf8ToWide(mode),29); diff --git a/win32/_tfwopen.h b/win32/_tfwopen.h index 52749dae..18471012 100644 --- a/win32/_tfwopen.h +++ b/win32/_tfwopen.h @@ -215,6 +215,15 @@ public: operator char *() { return utf8Chars; } }; +class MS932ToWide { +private: + wchar_t *wideChars; +public: + MS932ToWide(const char *ms932Chars); + ~MS932ToWide() { delete [] wideChars; } + operator wchar_t *() { return wideChars; } +}; + namespace std { class u8nifstream: public std::ifstream { diff --git a/win32/wsnes9x.cpp b/win32/wsnes9x.cpp index cbcf7cc3..81571934 100644 --- a/win32/wsnes9x.cpp +++ b/win32/wsnes9x.cpp @@ -5245,7 +5245,7 @@ void rominfo(const TCHAR *filename, TCHAR *namebuffer, TCHAR *sizebuffer) if (InfoScore((char *)HeaderBuffer) > 1) { EHi = true; - _tcsncpy(namebuffer, _tFromChar((char *)HeaderBuffer), 21); + _tcsncpy(namebuffer, _tFromMS932((char *)HeaderBuffer), 21); } } @@ -5263,7 +5263,7 @@ void rominfo(const TCHAR *filename, TCHAR *namebuffer, TCHAR *sizebuffer) ROMFile.read(HiHead, INFO_LEN); int HiScore = InfoScore(HiHead); - _tcsncpy(namebuffer, _tFromChar(LoScore > HiScore ? LoHead : HiHead), 21); + _tcsncpy(namebuffer, _tFromMS932(LoScore > HiScore ? LoHead : HiHead), 21); if (filestats.st_size - HeaderSize >= 0x20000) { @@ -5273,7 +5273,7 @@ void rominfo(const TCHAR *filename, TCHAR *namebuffer, TCHAR *sizebuffer) if (IntLScore > LoScore && IntLScore > HiScore) { - _tcsncpy(namebuffer, _tFromChar(LoHead), 21); + _tcsncpy(namebuffer, _tFromMS932(LoHead), 21); } } } @@ -5282,7 +5282,7 @@ void rominfo(const TCHAR *filename, TCHAR *namebuffer, TCHAR *sizebuffer) char buf[21]; ROMFile.seekg(0x7FC0 + HeaderSize, ios::beg); ROMFile.read(buf, 21); - _tcsncpy(namebuffer,_tFromChar(buf),21); + _tcsncpy(namebuffer,_tFromMS932(buf),21); } } ROMFile.close(); diff --git a/win32/wsnes9x.h b/win32/wsnes9x.h index fb7c81c6..0f618be0 100644 --- a/win32/wsnes9x.h +++ b/win32/wsnes9x.h @@ -216,9 +216,11 @@ #ifdef UNICODE #define _tToChar WideToUtf8 #define _tFromChar Utf8ToWide +#define _tFromMS932 MS932ToWide #else #define _tToChar #define _tFromChar +#define _tFromMS932 #endif /****************************************************************************/ From cf57ad3d5d4b0f1eca0d7a4025d0e7ac10a285c6 Mon Sep 17 00:00:00 2001 From: OV2 Date: Sun, 22 Jul 2012 15:10:58 +0200 Subject: [PATCH 5/6] win32: also show half-width katakana in rom info dialog --- win32/wsnes9x.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/win32/wsnes9x.cpp b/win32/wsnes9x.cpp index 81571934..f115525d 100644 --- a/win32/wsnes9x.cpp +++ b/win32/wsnes9x.cpp @@ -4490,7 +4490,7 @@ INT_PTR CALLBACK DlgInfoProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { char temp[100]; char romtext[4096]; - sprintf(romtext, "File: %s\r\nName: %s\r\n", Memory.ROMFilename, Memory.ROMName); + sprintf(romtext, "File: %s\r\nName: %s\r\n", Memory.ROMFilename, Memory.RawROMName); sprintf(temp, "Speed: %02X/%s\r\nROM Map: %s\r\nType: %02x\r\n", Memory.ROMSpeed, ((Memory.ROMSpeed&0x10)!=0)?"FastROM":"SlowROM",(Memory.HiROM)?"HiROM":"LoROM",Memory.ROMType); strcat(romtext, temp); strcat(romtext, "Kart contents: "); @@ -4841,7 +4841,7 @@ INT_PTR CALLBACK DlgInfoProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) case 14:strcat(romtext, "Unknown region 14");break; default:strcat(romtext, "Unknown region 15");break; } - SendDlgItemMessage(hDlg, IDC_ROM_DATA, WM_SETTEXT, 0, (LPARAM)((TCHAR *)_tFromChar(romtext))); + SendDlgItemMessage(hDlg, IDC_ROM_DATA, WM_SETTEXT, 0, (LPARAM)((TCHAR *)_tFromMS932(romtext))); break; } case WM_CTLCOLORSTATIC: From e180b02948e3ef09534eef87e233a224499d7430 Mon Sep 17 00:00:00 2001 From: gocha Date: Sun, 22 Jul 2012 19:28:25 +0900 Subject: [PATCH 6/6] fix "not a movie snapshot" everytime bug --- stream.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stream.cpp b/stream.cpp index 0d4082c4..9bc0fb1b 100644 --- a/stream.cpp +++ b/stream.cpp @@ -283,7 +283,7 @@ size_t fStream::size (void) int fStream::revert (size_t from, size_t offset) { - return (REVERT_FSTREAM(fp, from, offset)); + return (REVERT_FSTREAM(fp, offset, from)); } void fStream::closeStream()