Small patches for win32 by gocha

This is for people involved in the developement of Snes9x, or SNES emulators in general.
BUG REPORTS BELONG IN TECH SUPPORT/BUG TRACKING!
Post Reply
User avatar
gocha
Snes9x Yellow Belt
Posts: 64
Joined: Sun Dec 30, 2007 12:14 am
Location: Japan, Nagoya

Small patches for win32 by gocha

Post 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;
 					}
 				}
adventure_of_link
Hero of Hyrule | Official Port Recruiter
Posts: 2588
Joined: Mon May 24, 2004 5:06 pm
Location: 255.255.255.255

Re: Small patches for win32 by gocha

Post by adventure_of_link »

just curious, does the first patch allow all Japanese character named ROMs to process correctly or just that specific one?
Image

Unofficial Test Monkey For:
* Snes9X GX (Wii)
* Snes9X EX (Android)
* Snes9X 64-bits (PC/Mac)

ZSNES|Ben Heck|NSRT|Bob Smiley
User avatar
gocha
Snes9x Yellow Belt
Posts: 64
Joined: Sun Dec 30, 2007 12:14 am
Location: Japan, Nagoya

Re: Small patches for win32 by gocha

Post 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.
User avatar
gocha
Snes9x Yellow Belt
Posts: 64
Joined: Sun Dec 30, 2007 12:14 am
Location: Japan, Nagoya

Re: Small patches for win32 by gocha

Post 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;
}
User avatar
Camo_Yoshi
Snes9x Purple belt
Posts: 922
Joined: Thu Nov 08, 2007 7:59 pm

Re: Small patches for win32 by gocha

Post 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?
Snes9x FAQs | Forum Rules
What operating system are you using? 32 or 64bit? Version of Snes9x? Is the text at the bottom of the window white when you load the game?
These suggestions are usually the solution to your issue!
User avatar
gocha
Snes9x Yellow Belt
Posts: 64
Joined: Sun Dec 30, 2007 12:14 am
Location: Japan, Nagoya

Re: Small patches for win32 by gocha

Post 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...
User avatar
gocha
Snes9x Yellow Belt
Posts: 64
Joined: Sun Dec 30, 2007 12:14 am
Location: Japan, Nagoya

Re: Small patches for win32 by gocha

Post 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
 
 /****************************************************************************/
User avatar
OV2
Official Win32 Porter/Dev
Posts: 679
Joined: Thu Aug 30, 2007 10:15 pm

Re: Small patches for win32 by gocha

Post by OV2 »

Thanks, I've commited them.

I've also added the half-width katakana display to the regular rom info dialog.
User avatar
Camo_Yoshi
Snes9x Purple belt
Posts: 922
Joined: Thu Nov 08, 2007 7:59 pm

Re: Small patches for win32 by gocha

Post 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
Snes9x FAQs | Forum Rules
What operating system are you using? 32 or 64bit? Version of Snes9x? Is the text at the bottom of the window white when you load the game?
These suggestions are usually the solution to your issue!
User avatar
gocha
Snes9x Yellow Belt
Posts: 64
Joined: Sun Dec 30, 2007 12:14 am
Location: Japan, Nagoya

Re: Small patches for win32 by gocha

Post by gocha »

gfx.cpp : adjust input display position since it covers frame counter display - http://git.io/gs_zYw
User avatar
gocha
Snes9x Yellow Belt
Posts: 64
Joined: Sun Dec 30, 2007 12:14 am
Location: Japan, Nagoya

Re: Small patches for win32 by gocha

Post 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
User avatar
OV2
Official Win32 Porter/Dev
Posts: 679
Joined: Thu Aug 30, 2007 10:15 pm

Re: Small patches for win32 by gocha

Post 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.
User avatar
gocha
Snes9x Yellow Belt
Posts: 64
Joined: Sun Dec 30, 2007 12:14 am
Location: Japan, Nagoya

Re: Small patches for win32 by gocha

Post 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)
odditude
Snes9x Green Belt
Posts: 445
Joined: Tue May 03, 2011 2:35 pm

Re: Small patches for win32 by gocha

Post by odditude »

awesome, this satisfies half of my previous feature request!
User avatar
gocha
Snes9x Yellow Belt
Posts: 64
Joined: Sun Dec 30, 2007 12:14 am
Location: Japan, Nagoya

Re: Small patches for win32 by gocha

Post 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
User avatar
gocha
Snes9x Yellow Belt
Posts: 64
Joined: Sun Dec 30, 2007 12:14 am
Location: Japan, Nagoya

Re: Small patches for win32 by gocha

Post 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.
User avatar
gocha
Snes9x Yellow Belt
Posts: 64
Joined: Sun Dec 30, 2007 12:14 am
Location: Japan, Nagoya

Re: Small patches for win32 by gocha

Post 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
User avatar
gocha
Snes9x Yellow Belt
Posts: 64
Joined: Sun Dec 30, 2007 12:14 am
Location: Japan, Nagoya

Re: Small patches for win32 by gocha

Post by gocha »

Remove the most of compiler warnings. (VS2008)
http://git.io/dQEQ6Q
User avatar
gocha
Snes9x Yellow Belt
Posts: 64
Joined: Sun Dec 30, 2007 12:14 am
Location: Japan, Nagoya

Re: Small patches for win32 by gocha

Post by gocha »

Add movie "finished" state. For details, see http://tasvideos.org/LawsOfTAS/OnSavestates.html - http://git.io/Gkg0dg
User avatar
gocha
Snes9x Yellow Belt
Posts: 64
Joined: Sun Dec 30, 2007 12:14 am
Location: Japan, Nagoya

Re: Small patches for win32 by gocha

Post by gocha »

win32: fix multibyte filename display in ROM Information dialog. · 8f1d176 · snes9x-rr/snes9x · GitHub https://github.com/snes9x-rr/snes9x/com ... 6b3aef6548
Post Reply