Page 1 of 1

Small patches for win32 by gocha

Posted: Sat Jul 21, 2012 4:37 am
by gocha
win32: improve DBCS processing in S9xBasename. This one should process S9xBasename("C:\roms\ソウルブレイダー.smc") correctly.

Code: Select all

612369f106bdc4d79c4f8727e68484bf046f5c11
 win32/win32.cpp |   26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/win32/win32.cpp b/win32/win32.cpp
index 7d4a52f..3492280 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)
win32: fix Cheat Search not to add the same cheat twice.

Code: Select all

a1a3cfc986062cacc72ac158f13e1d01bf64a6e5
 win32/wsnes9x.cpp |   18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/win32/wsnes9x.cpp b/win32/wsnes9x.cpp
index 694338f..66c794b 100644
--- a/win32/wsnes9x.cpp
+++ b/win32/wsnes9x.cpp
@@ -9613,16 +9613,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<cht.size; p++)
-						{
-							S9xAddCheat(TRUE, cht.saved, cht.address +p, ((cht.new_val>>(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:
@@ -10132,8 +10123,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;
 					}
 				}

Re: Small patches for win32 by gocha

Posted: Sat Jul 21, 2012 5:48 pm
by adventure_of_link
just curious, does the first patch allow all Japanese character named ROMs to process correctly or just that specific one?

Re: Small patches for win32 by gocha

Posted: Sat Jul 21, 2012 11:09 pm
by gocha
adventure_of_link wrote:just curious, does the first patch allow all Japanese character named ROMs to process correctly or just that specific one?
All characters. ソ is a character whose trailer byte is 0x5c (\). I just wanted to show an example of problematic input. It should process all characters as well.

Re: Small patches for win32 by gocha

Posted: Sun Jul 22, 2012 12:14 am
by gocha
The DBCS patch above probably can be wrong when it processes a string which has both slash and backslash. I've made a fix.

Code: Select all

const char *S9xBasename (const char *f)
{
	const char *p = f;
	const char *last = p;
	const char *slash;
	const char *backslash;

	// search rightmost separator
	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
		// 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 last;
}

Re: Small patches for win32 by gocha

Posted: Sun Jul 22, 2012 4:01 am
by Camo_Yoshi
gocha wrote:
adventure_of_link wrote:just curious, does the first patch allow all Japanese character named ROMs to process correctly or just that specific one?
All characters. ソ is a character whose trailer byte is 0x5c (\). I just wanted to show an example of problematic input. It should process all characters as well.

Isn't this because certain characters, regardless of region settings, are not allowed by Windows?

Re: Small patches for win32 by gocha

Posted: Sun Jul 22, 2012 4:44 am
by gocha
Camo_Yoshi wrote:
gocha wrote:
adventure_of_link wrote:just curious, does the first patch allow all Japanese character named ROMs to process correctly or just that specific one?
All characters. ソ is a character whose trailer byte is 0x5c (\). I just wanted to show an example of problematic input. It should process all characters as well.

Isn't this because certain characters, regardless of region settings, are not allowed by Windows?
What do you mean by "not allowed by Windows?" Windows allows using all katakana for filename.
The problem is simply caused by a poor filename processing. Uh, is there any English website which describes about the SJIS (MS932) trailer byte problem? I think they'll explain the things better...

Re: Small patches for win32 by gocha

Posted: Sun Jul 22, 2012 4:56 am
by gocha
win32: Unicode - fix Custom ROM dialog to show half-width katakana

Code: Select all

83594657052359eb030726dff32ade38588f7cda
 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 537b3c7..8f0d82e 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 5cb88e1..8429b99 100644
--- a/win32/_tfwopen.h
+++ b/win32/_tfwopen.h
@@ -227,6 +227,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 a2319b3..8dfc254 100644
--- a/win32/wsnes9x.cpp
+++ b/win32/wsnes9x.cpp
@@ -5322,7 +5322,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);
 				}
 			}
 
@@ -5340,7 +5340,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)
 					{
@@ -5350,7 +5350,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);
 						}
 					}
 				}
@@ -5359,7 +5359,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 0e0e6e5..415c9c3 100644
--- a/win32/wsnes9x.h
+++ b/win32/wsnes9x.h
@@ -217,9 +217,11 @@
 #ifdef UNICODE
 #define _tToChar WideToUtf8
 #define _tFromChar Utf8ToWide
+#define _tFromMS932 MS932ToWide
 #else
 #define _tToChar
 #define _tFromChar
+#define _tFromMS932
 #endif
 
 /****************************************************************************/

Re: Small patches for win32 by gocha

Posted: Sun Jul 22, 2012 1:12 pm
by OV2
Thanks, I've commited them.

I've also added the half-width katakana display to the regular rom info dialog.

Re: Small patches for win32 by gocha

Posted: Sun Jul 22, 2012 3:18 pm
by Camo_Yoshi
gocha wrote:
What do you mean by "not allowed by Windows?" Windows allows using all katakana for filename.
The problem is simply caused by a poor filename processing. Uh, is there any English website which describes about the SJIS (MS932) trailer byte problem? I think they'll explain the things better...

Actually, I was referring to the fact that the following characters in filenames are not allowed: \ / : * ? " < > |

Now that I realize the issue at hand, I mistook it for reserved characters in the filesystem. Don't mind me! :P

Re: Small patches for win32 by gocha

Posted: Tue Jul 24, 2012 10:56 am
by gocha
gfx.cpp : adjust input display position since it covers frame counter display - http://git.io/gs_zYw

Re: Small patches for win32 by gocha

Posted: Tue Jul 24, 2012 1:56 pm
by gocha
Also, I suggest to put "static" to all "__forceinline" functions in _twfopen.h. Without it, the source code cannot be compiled when the compiler doesn't inline the function for some reasons.
MSDN wrote:Even with __forceinline, the compiler cannot inline code in all circumstances. The compiler cannot inline a function if:
http://msdn.microsoft.com/en-us/library/z8y1yy88.aspx

Re: Small patches for win32 by gocha

Posted: Tue Jul 31, 2012 11:17 am
by OV2
I've changed the offset and made the __forceinline functions static. Didn't have the time to look into the movie reset desync yet, but will definitely get to it.

Re: Small patches for win32 by gocha

Posted: Thu Aug 02, 2012 11:12 pm
by gocha
OV2 wrote:Didn't have the time to look into the movie reset desync yet, but will definitely get to it.
Thank you very much.

win32: remove "Toggled fast forward mode" checkbox, and give "fast forward toggle" hotkey
https://github.com/snes9x-rr/snes9x/com ... 3dc0743421
I want to use both keys. I hope the change doesn't affect to the existing users.
I think most users didn't change the checkbox frequently. (because it needs to open the settings dialog)

Re: Small patches for win32 by gocha

Posted: Thu Aug 02, 2012 11:40 pm
by odditude
awesome, this satisfies half of my previous feature request!

Re: Small patches for win32 by gocha

Posted: Sat Aug 04, 2012 9:45 pm
by gocha
small fix for the previous post
https://github.com/snes9x-rr/snes9x/com ... 6fe667f7cb

win32: drag and drop support for snes9x movie (*.smv)
https://github.com/snes9x-rr/snes9x/com ... acc9aa47a1

Re: Small patches for win32 by gocha

Posted: Sat Aug 04, 2012 9:52 pm
by gocha
Also, I removed MovieNotifyIgnored from my branch for some reasons.
https://github.com/snes9x-rr/snes9x/com ... a8adcbabaa
If you want, you can merge those (movie-free frame count display, lag frame count display, etc.) changes as well, although I think you don't want them.

Re: Small patches for win32 by gocha

Posted: Wed Aug 15, 2012 1:58 am
by gocha
Fix small mistake of previous contribution.
https://github.com/snes9x-rr/snes9x/com ... ae111b3d27

win32: update mouse coordinates calculation, it fixes the case of non-stretched 3x filters, hi-res games (I know no hi-res games that uses mouse or superscope, though)
https://github.com/snes9x-rr/snes9x/com ... 9aaa9ee9a6

Re: Small patches for win32 by gocha

Posted: Tue Aug 21, 2012 1:40 pm
by gocha
Remove the most of compiler warnings. (VS2008)
http://git.io/dQEQ6Q

Re: Small patches for win32 by gocha

Posted: Fri Aug 24, 2012 12:39 pm
by gocha
Add movie "finished" state. For details, see http://tasvideos.org/LawsOfTAS/OnSavestates.html - http://git.io/Gkg0dg

Re: Small patches for win32 by gocha

Posted: Thu Mar 14, 2013 1:00 pm
by gocha
win32: fix multibyte filename display in ROM Information dialog. · 8f1d176 · snes9x-rr/snes9x · GitHub https://github.com/snes9x-rr/snes9x/com ... 6b3aef6548