shithub: cstory

Download patch

ref: 5ea356a3bd46a96604d5f2dadd00fcf0d418ccdb
parent: 5a9492166d630b97b6888e5969c359f8b35862e3
author: Clownacy <Clownacy@users.noreply.github.com>
date: Tue Sep 3 20:27:36 EDT 2019

Weed out a lot of the Windows dependency

Storytime: Cucky's original SDL2 port work involved using SDL2's
threading API to emulate the original WinAPI threading.

I can't be assed with that stuff, so I used the same trick Cucky did
for the Wii port, and hooked Organya up to the SDL2 audio callback.
This actually opens up the possibility for perfectly-synchronised
Organya playback. By that I mean, instead of needing a super
low-latency audio callback, I can have the callback synchronise its
audio mixing with Organya itself. I haven't done it yet, I plan to
soon.

--- a/Makefile
+++ b/Makefile
@@ -44,7 +44,7 @@
 	CXXFLAGS += -DDEBUG_SAVE
 endif
 
-CXXFLAGS += -std=c++98 -MMD -MP -MF $@.d -DWINDOWS -DNONPORTABLE `pkg-config sdl2 --cflags`
+CXXFLAGS += -std=c++98 -MMD -MP -MF $@.d -DWINDOWS `pkg-config sdl2 --cflags`
 LIBS += -lkernel32 -lgdi32 -lddraw -ldinput -ldsound -lversion -lshlwapi -limm32 -lwinmm -ldxguid
 
 ifeq ($(STATIC), 1)
@@ -72,11 +72,11 @@
 	src/Bullet \
 	src/Caret \
 	src/Config \
-	src/Dialog \
 	src/Draw \
 	src/Ending \
 	src/Escape \
 	src/Fade \
+	src/File \
 	src/Flags \
 	src/Flash \
 	src/Frame \
--- a/src/ArmsItem.cpp
+++ b/src/ArmsItem.cpp
@@ -394,7 +394,7 @@
 
 		if (gKeyTrg & KEY_ESCAPE)
 		{
-			switch (Call_Escape(ghWnd))
+			switch (Call_Escape())
 			{
 				case 0:
 					return 0;
--- a/src/Back.cpp
+++ b/src/Back.cpp
@@ -7,6 +7,7 @@
 
 #include "CommonDefines.h"
 #include "Draw.h"
+#include "File.h"
 #include "Frame.h"
 #include "Game.h"
 #include "Map.h"
--- a/src/Backends/Audio/SDL2.cpp
+++ b/src/Backends/Audio/SDL2.cpp
@@ -6,6 +6,7 @@
 
 #include "SDL.h"
 
+#include "../../Organya.h"
 #include "../../WindowsWrapper.h"
 
 #define MIN(a, b) ((a) < (b) ? (a) : (b))
@@ -77,6 +78,22 @@
 
 	for (unsigned int i = 0; i < frames_total * 2; ++i)
 		stream[i] = 0.0f;
+
+	if (organya_timer != 0)
+	{
+		static int timer_countdown;
+
+		timer_countdown -= frames_total * 1000;
+
+		if (timer_countdown <= 0)
+		{
+			do
+			{
+				timer_countdown += organya_timer * 44100;
+				UpdateOrganya();
+			} while (timer_countdown <= 0);
+		}
+	}
 
 	for (AudioBackend_Sound *sound = sound_list_head; sound != NULL; sound = sound->next)
 	{
--- a/src/Config.cpp
+++ b/src/Config.cpp
@@ -5,6 +5,7 @@
 #include "WindowsWrapper.h"
 
 #include "Config.h"
+#include "File.h"
 #include "Tags.h"
 
 static const char* const config_filename = "Config.dat";	// Not the original name
--- a/src/Dialog.cpp
+++ /dev/null
@@ -1,157 +1,0 @@
-#include "Dialog.h"
-
-#include <stdio.h>
-
-#include "WindowsWrapper.h"
-
-#include "Generic.h"
-#include "Organya.h"
-#include "Profile.h"
-
-// All of the original names for the functions/variables in this file are unknown
-
-static const char *version_string = 
-	"version.%d.%d.%d.%d\r\n"
-	"2004/12/20 - %04d/%02d/%02d\r\n"
-	"Studio Pixel"
-	;
-
-// TODO - Inaccurate stack frame
-BOOL __stdcall VersionDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
-{
-	char string_buffer[104];
-
-	int year;
-	int month;
-	int day;
-
-	int version1;
-	int version2;
-	int version3;
-	int version4;
-
-	switch (Msg)
-	{
-		case WM_INITDIALOG:
-			GetCompileDate(&year, &month, &day);
-			GetCompileVersion(&version1, &version2, &version3, &version4);
-			sprintf(string_buffer, version_string, version1, version2, version3, version4, year, month, day);
-			SetDlgItemTextA(hWnd, 1011, string_buffer);
-
-			CenterWindow(hWnd);
-
-			return TRUE;
-
-		case WM_COMMAND:
-			switch (LOWORD(wParam))
-			{
-				case 1:
-					EndDialog(hWnd, 1);
-					break;
-			}
-
-			break;
-	}
-
-	return FALSE;
-}
-
-BOOL __stdcall DebugMuteDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
-{
-	switch (Msg)
-	{
-		case WM_INITDIALOG:
-			CenterWindow(hWnd);
-			CheckDlgButton(hWnd, 1010, g_mute[0] != 0);
-			CheckDlgButton(hWnd, 1018, g_mute[1] != 0);
-			CheckDlgButton(hWnd, 1019, g_mute[2] != 0);
-			CheckDlgButton(hWnd, 1020, g_mute[3] != 0);
-			CheckDlgButton(hWnd, 1021, g_mute[4] != 0);
-			CheckDlgButton(hWnd, 1022, g_mute[5] != 0);
-			CheckDlgButton(hWnd, 1023, g_mute[6] != 0);
-			CheckDlgButton(hWnd, 1024, g_mute[7] != 0);
-			return TRUE;
-
-		case WM_COMMAND:
-			switch (LOWORD(wParam))
-			{
-				case 2:
-					EndDialog(hWnd, 0);
-					break;
-
-				case 1:
-					g_mute[0] = IsDlgButtonChecked(hWnd, 1010);
-					g_mute[1] = IsDlgButtonChecked(hWnd, 1018);
-					g_mute[2] = IsDlgButtonChecked(hWnd, 1019);
-					g_mute[3] = IsDlgButtonChecked(hWnd, 1020);
-					g_mute[4] = IsDlgButtonChecked(hWnd, 1021);
-					g_mute[5] = IsDlgButtonChecked(hWnd, 1022);
-					g_mute[6] = IsDlgButtonChecked(hWnd, 1023);
-					g_mute[7] = IsDlgButtonChecked(hWnd, 1024);
-					EndDialog(hWnd, 1);
-					break;
-			}
-
-			break;
-	}
-
-	return FALSE;
-}
-
-BOOL __stdcall DebugSaveDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
-{
-	char string[100];
-
-	switch (Msg)
-	{
-		case WM_INITDIALOG:
-			SetDlgItemTextA(hWnd, 1008, "000.dat");
-			CenterWindow(hWnd);
-			return TRUE;
-
-		case WM_COMMAND:
-			switch (LOWORD(wParam))
-			{
-				case 2:
-					EndDialog(hWnd, 0);
-					break;
-
-				case 1:
-					GetDlgItemTextA(hWnd, 1008, string, sizeof(string));
-					SaveProfile(string);
-					EndDialog(hWnd, 1);
-					break;
-			}
-
-			break;
-	}
-
-	return FALSE;
-}
-
-BOOL __stdcall QuitDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
-{
-	switch (Msg)
-	{
-		case WM_INITDIALOG:
-			SetDlgItemTextA(hWnd, 1009, (LPCSTR)lParam);
-			CenterWindow(hWnd);
-			return TRUE;
-
-		case WM_COMMAND:
-			switch (LOWORD(wParam))
-			{
-				case 2:
-					EndDialog(hWnd, 2);
-					break;
-
-				case 1:
-					EndDialog(hWnd, 1);
-					break;
-			}
-
-			break;
-	}
-
-	return FALSE;
-}
--- a/src/Dialog.h
+++ /dev/null
@@ -1,8 +1,0 @@
-#pragma once
-
-#include "WindowsWrapper.h"
-
-BOOL __stdcall VersionDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
-BOOL __stdcall DebugMuteDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
-BOOL __stdcall DebugSaveDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
-BOOL __stdcall QuitDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
--- a/src/Draw.cpp
+++ b/src/Draw.cpp
@@ -59,12 +59,12 @@
 			return FALSE;
 
 		// Framerate limiter
-		timeNow = GetTickCount();
+		timeNow = SDL_GetTicks();
 
 		if (timeNow >= timePrev + FRAMERATE)
 			break;
 
-		Sleep(1);
+		SDL_Delay(1);
 	}
 
 	if (timeNow >= timePrev + 100)
@@ -482,7 +482,7 @@
 	Backend_Blit(surf[from], &src_rect, surf[to], x * magnification, y * magnification, TRUE);
 }
 
-unsigned long GetCortBoxColor(COLORREF col)
+unsigned long GetCortBoxColor(unsigned long col)
 {
 	// Comes in 00BBGGRR, goes out 00BBGGRR
 	return col;
--- a/src/Draw.h
+++ b/src/Draw.h
@@ -64,7 +64,7 @@
 void PutBitmap3(const RECT *rcView, int x, int y, const RECT *rect, SurfaceID surf_no);
 void PutBitmap4(const RECT *rcView, int x, int y, const RECT *rect, SurfaceID surf_no);
 void Surface2Surface(int x, int y, const RECT *rect, int to, int from);
-unsigned long GetCortBoxColor(COLORREF col);
+unsigned long GetCortBoxColor(unsigned long col);
 void CortBox(const RECT *rect, unsigned long col);
 void CortBox2(const RECT *rect, unsigned long col, SurfaceID surf_no);
 int RestoreSurfaces(void);
--- a/src/Ending.cpp
+++ b/src/Ending.cpp
@@ -435,7 +435,7 @@
 }
 
 // Scene of the island falling
-int Scene_DownIsland(HWND hWnd, int mode)
+int Scene_DownIsland(int mode)
 {
 	// Setup background
 	RECT rc_frame = {(WINDOW_WIDTH - 160) / 2, (WINDOW_HEIGHT - 80) / 2, (WINDOW_WIDTH + 160) / 2, (WINDOW_HEIGHT + 80) / 2};
@@ -457,7 +457,7 @@
 		// Escape menu
 		if (gKey & 0x8000)
 		{
-			switch (Call_Escape(hWnd))
+			switch (Call_Escape())
 			{
 				case 0:
 					return 0;
--- a/src/Ending.h
+++ b/src/Ending.h
@@ -52,4 +52,4 @@
 int GetScriptNumber(const char *text);
 void SetCreditIllust(int a);
 void CutCreditIllust();
-int Scene_DownIsland(HWND hWnd, int mode);
+int Scene_DownIsland(int mode);
--- a/src/Escape.cpp
+++ b/src/Escape.cpp
@@ -7,7 +7,7 @@
 #include "KeyControl.h"
 #include "Main.h"
 
-int Call_Escape(HWND hWnd)
+int Call_Escape(void)
 {
 	RECT rc = {0, 128, 208, 144};
 
--- a/src/Escape.h
+++ b/src/Escape.h
@@ -1,5 +1,3 @@
 #pragma once
 
-#include "WindowsWrapper.h"
-
-int Call_Escape(HWND hWnd);
+int Call_Escape(void);
--- /dev/null
+++ b/src/File.cpp
@@ -1,0 +1,96 @@
+#include "File.h"
+
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+long LoadFileToMemory(const char *file_path, unsigned char **file_buffer)
+{
+	long returned_size = -1;
+
+	FILE *file = fopen(file_path, "rb");
+
+	if (file != NULL)
+	{
+		if (!fseek(file, 0, SEEK_END))
+		{
+			const long file_size = ftell(file);
+
+			if (file_size >= 0)
+			{
+				rewind(file);
+				*file_buffer = (unsigned char*)malloc(file_size);
+
+				if (*file_buffer != NULL)
+				{
+					if (fread(*file_buffer, file_size, 1, file) == 1)
+						returned_size = file_size;
+				}
+			}
+		}
+
+		fclose(file);
+	}
+
+	return returned_size;
+}
+
+unsigned short File_ReadBE16(FILE *stream)
+{
+	unsigned char bytes[2];
+
+	fread(bytes, 2, 1, stream);
+
+	return (bytes[0] << 8) | bytes[1];
+}
+
+unsigned long File_ReadBE32(FILE *stream)
+{
+	unsigned char bytes[4];
+
+	fread(bytes, 4, 1, stream);
+
+	return (bytes[0] << 24) | (bytes[1] << 16) | (bytes[2] << 8) | bytes[3];
+}
+
+unsigned short File_ReadLE16(FILE *stream)
+{
+	unsigned char bytes[2];
+
+	fread(bytes, 2, 1, stream);
+
+	return (bytes[1] << 8) | bytes[0];
+}
+
+unsigned long File_ReadLE32(FILE *stream)
+{
+	unsigned char bytes[4];
+
+	fread(bytes, 4, 1, stream);
+
+	return (bytes[3] << 24) | (bytes[2] << 16) | (bytes[1] << 8) | bytes[0];
+}
+
+void File_WriteBE16(unsigned short value, FILE *stream)
+{
+	for (unsigned int i = 2; i-- != 0;)
+		fputc(value >> (8 * i), stream);
+}
+
+void File_WriteBE32(unsigned long value, FILE *stream)
+{
+	for (unsigned int i = 4; i-- != 0;)
+		fputc(value >> (8 * i), stream);
+}
+
+void File_WriteLE16(unsigned short value, FILE *stream)
+{
+	for (unsigned int i = 0; i < 2; ++i)
+		fputc(value >> (8 * i), stream);
+}
+
+void File_WriteLE32(unsigned long value, FILE *stream)
+{
+	for (unsigned int i = 0; i < 4; ++i)
+		fputc(value >> (8 * i), stream);
+}
--- /dev/null
+++ b/src/File.h
@@ -1,0 +1,15 @@
+#pragma once
+
+#include <stdio.h>
+
+long LoadFileToMemory(const char *file_path, unsigned char **file_buffer);
+
+unsigned short File_ReadBE16(FILE *stream);
+unsigned long File_ReadBE32(FILE *stream);
+unsigned short File_ReadLE16(FILE *stream);
+unsigned long File_ReadLE32(FILE *stream);
+
+void File_WriteBE16(unsigned short value, FILE *stream);
+void File_WriteBE32(unsigned long value, FILE *stream);
+void File_WriteLE16(unsigned short value, FILE *stream);
+void File_WriteLE32(unsigned long value, FILE *stream);
--- a/src/Game.cpp
+++ b/src/Game.cpp
@@ -4,6 +4,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#include "SDL.h"
+
 #include "WindowsWrapper.h"
 
 #include "ArmsItem.h"
@@ -108,7 +110,7 @@
 	}
 }
 
-int ModeOpening(HWND hWnd)
+int ModeOpening()
 {
 	int frame_x;
 	int frame_y;
@@ -150,7 +152,7 @@
 		// Escape menu
 		if (gKey & KEY_ESCAPE)
 		{
-			switch (Call_Escape(ghWnd))
+			switch (Call_Escape())
 			{
 				case 0:
 					return 0;
@@ -211,8 +213,8 @@
 		++gCounter;
 	}
 
-	wait = GetTickCount();
-	while (GetTickCount() < wait + 500)
+	wait = SDL_GetTicks();
+	while (SDL_GetTicks() < wait + 500)
 	{
 		CortBox(&grcGame, 0x000000);
 		PutFramePerSecound();
@@ -222,7 +224,7 @@
 	return 2;
 }
 
-int ModeTitle(HWND hWnd)
+int ModeTitle(void)
 {
 	// Set rects
 	RECT rcTitle = {0, 0, 144, 40};
@@ -360,7 +362,7 @@
 
 		if (gKey & KEY_ESCAPE)
 		{
-			switch (Call_Escape(ghWnd))
+			switch (Call_Escape())
 			{
 				case 0:
 					return 0;
@@ -456,8 +458,8 @@
 	ChangeMusic(MUS_SILENCE);
 
 	// Black screen when option is selected
-	wait = GetTickCount();
-	while (GetTickCount() < wait + 1000)
+	wait = SDL_GetTicks();
+	while (SDL_GetTicks() < wait + 1000)
 	{
 		CortBox(&grcGame, 0);
 		PutFramePerSecound();
@@ -468,7 +470,7 @@
 	return 3;
 }
 
-int ModeAction(HWND hWnd)
+int ModeAction(void)
 {
 	int frame_x;
 	int frame_y;
@@ -506,12 +508,12 @@
 
 	if (bContinue)
 	{
-		if (!LoadProfile(NULL) && !InitializeGame(hWnd))	// ...Shouldn't that '&&' be a '||'?
+		if (!LoadProfile(NULL) && !InitializeGame())	// ...Shouldn't that '&&' be a '||'?
 			return 0;
 	}
 	else
 	{
-		if (!InitializeGame(hWnd))
+		if (!InitializeGame())
 			return 0;
 	}
 
@@ -523,7 +525,7 @@
 		// Escape menu
 		if (gKey & KEY_ESCAPE)
 		{
-			switch (Call_Escape(ghWnd))
+			switch (Call_Escape())
 			{
 				case 0:
 					return 0;
@@ -676,25 +678,17 @@
 	return 0;
 }
 
-BOOL Game(HWND hWnd)
+BOOL Game(void)
 {
 	int mode;
 
 	if (!LoadGenericData())
 	{
-		#if defined(NONPORTABLE) && defined(WINDOWS)
-			#ifdef JAPANESE
-			MessageBoxA(hWnd, "\x94\xC4\x97\x70\x83\x74\x83\x40\x83\x43\x83\x8B\x82\xAA\x93\xC7\x82\xDF\x82\xC8\x82\xA2", "\x83\x47\x83\x89\x81\x5B", MB_OK);
-			#else
-			MessageBoxA(hWnd, "Couldn't read general purpose files", "Error", MB_OK);
-			#endif
-		#else
-			#ifdef JAPANESE
-			SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "エラー", "汎用ファイルが読めない", NULL);
-			#else
-			SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "Couldn't read general purpose files", NULL);
-			#endif
-		#endif
+#ifdef JAPANESE
+		SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "エラー", "汎用ファイルが読めない", NULL);
+#else
+		SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "Couldn't read general purpose files", NULL);
+#endif
 
 		return FALSE;
 	}
@@ -706,19 +700,11 @@
 
 	if (!LoadNpcTable(path))
 	{
-		#if defined(NONPORTABLE) && defined(WINDOWS)
-			#ifdef JAPANESE
-			MessageBoxA(hWnd, "\x4E\x50\x43\x83\x65\x81\x5B\x83\x75\x83\x8B\x82\xAA\x93\xC7\x82\xDF\x82\xC8\x82\xA2", "\x83\x47\x83\x89\x81\x5B", MB_OK);
-			#else
-			MessageBoxA(hWnd, "Couldn't read the NPC table", "Error", MB_OK);
-			#endif
-		#else
-			#ifdef JAPANESE
-			SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "エラー", "NPCテーブルが読めない", NULL);
-			#else
-			SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "Couldn't read the NPC table", NULL);
-			#endif
-		#endif
+#ifdef JAPANESE
+		SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "エラー", "NPCテーブルが読めない", NULL);
+#else
+		SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "Couldn't read the NPC table", NULL);
+#endif
 
 		return FALSE;
 	}
@@ -732,11 +718,11 @@
 	while (mode)
 	{
 		if (mode == 1)
-			mode = ModeOpening(hWnd);
+			mode = ModeOpening();
 		if (mode == 2)
-			mode = ModeTitle(hWnd);
+			mode = ModeTitle();
 		if (mode == 3)
-			mode = ModeAction(hWnd);
+			mode = ModeAction();
 	}
 
 	PlaySoundObject(7, 0);
@@ -745,9 +731,6 @@
 	EndTextScript();
 	ReleaseNpcTable();
 	ReleaseCreditScript();
-
-	if (!bFullscreen)
-		SaveWindowRect(hWnd, "window.rect");
 
 	return TRUE;
 }
--- a/src/Game.h
+++ b/src/Game.h
@@ -8,4 +8,4 @@
 int Random(int min, int max);
 void PutNumber4(int x, int y, int value, BOOL bZero);
 
-BOOL Game(HWND hWnd);
+BOOL Game(void);
--- a/src/Generic.cpp
+++ b/src/Generic.cpp
@@ -36,68 +36,8 @@
 	*month = i;
 }
 
-#ifdef WINDOWS
-// TODO - Inaccurate stack frame
 BOOL GetCompileVersion(int *v1, int *v2, int *v3, int *v4)
 {
-	unsigned int puLen;
-	VS_FIXEDFILEINFO *lpBuffer;
-	DWORD dwHandle;
-	DWORD dwLen;
-	char path[MAX_PATH];
-	LPVOID lpData;
-	BOOL bResult;
-
-	lpData = NULL;
-	bResult = FALSE;
-
-	GetModuleFileNameA(NULL, path, sizeof(path));
-	dwLen = GetFileVersionInfoSizeA(path, &dwHandle);
-
-	if (dwLen == 0)
-	{
-		
-	}
-	else
-	{
-		lpData = malloc(dwLen);
-
-		if (lpData == NULL)
-		{
-			
-		}
-		else
-		{
-			if (!GetFileVersionInfoA(path, 0, dwLen, lpData))
-			{
-				
-			}
-			else
-			{
-				if (!VerQueryValueA(lpData, "\\", (LPVOID*)&lpBuffer, &puLen))
-				{
-					
-				}
-				else
-				{
-					*v1 = (unsigned short)(lpBuffer->dwFileVersionMS >> 16);
-					*v2 = (unsigned short)(lpBuffer->dwFileVersionMS & 0xFFFF);
-					*v3 = (unsigned short)(lpBuffer->dwFileVersionLS >> 16);
-					*v4 = (unsigned short)(lpBuffer->dwFileVersionLS & 0xFFFF);
-					bResult = TRUE;
-				}
-			}
-		}
-	}
-
-	if (lpData)
-		free(lpData);
-
-	return bResult;
-}
-#else
-BOOL GetCompileVersion(int *v1, int *v2, int *v3, int *v4)
-{
 	*v1 = 1;
 	*v2 = 0;
 	*v3 = 0;
@@ -104,81 +44,13 @@
 	*v4 = 6;
 	return TRUE;
 }
-#endif
 
-#ifdef WINDOWS
-// This seems to be broken in recent Windows (Sndvol32.exe was renamed 'SndVol.exe')
-// TODO - Inaccurate stack frame
-BOOL OpenVolumeConfiguration(HWND hWnd)
-{
-	char path[MAX_PATH];
-	char path2[MAX_PATH];
-	char path3[MAX_PATH];
-#ifdef FIX_BUGS
-	char path4[MAX_PATH];
-	char path5[MAX_PATH];
-#endif
-	int error1;
-	int error2;
-#ifdef FIX_BUGS
-	int error3;
-	int error4;
-#endif
-	size_t i;
-
-	GetSystemDirectoryA(path, sizeof(path));
-	sprintf(path2, "%s\\Sndvol32.exe", path);
-#ifdef FIX_BUGS
-	sprintf(path4, "%s\\Sndvol.exe", path);
-#endif
-
-	i = strlen(path);
-	while (path[i] != '\\')
-		--i;
-
-	path[i] = '\0';
-	sprintf(path3, "%s\\Sndvol32.exe", path);
-#ifdef FIX_BUGS
-	sprintf(path5, "%s\\Sndvol.exe", path);
-#endif
-
-#ifdef FIX_BUGS
-	error1 = (int)ShellExecuteA(hWnd, "open", path2, NULL, NULL, SW_SHOW);
-	if (error1 > 32)
-		return TRUE;
-
-	error2 = (int)ShellExecuteA(hWnd, "open", path3, NULL, NULL, SW_SHOW);
-	if (error2 > 32)
-		return TRUE;
-
-	error3 = (int)ShellExecuteA(hWnd, "open", path4, NULL, NULL, SW_SHOW);
-	if (error3 > 32)
-		return TRUE;
-
-	error4 = (int)ShellExecuteA(hWnd, "open", path5, NULL, NULL, SW_SHOW);
-	if (error4 > 32)
-		return TRUE;
-
-	return FALSE;
-#else
-	error1 = (int)ShellExecuteA(hWnd, "open", path2, NULL, NULL, SW_SHOW);
-	error2 = (int)ShellExecuteA(hWnd, "open", path3, NULL, NULL, SW_SHOW);
-
-	if (error1 <= 32 && error2 <= 32)
-		return FALSE;
-	else
-		return TRUE;
-#endif
-}
-#endif
-
-#ifdef WINDOWS
 void DeleteDebugLog(void)
 {
 	char path[MAX_PATH];
 
-	sprintf(path, "%s\\debug.txt", gModulePath);
-	DeleteFileA(path);
+	sprintf(path, "%s/debug.txt", gModulePath);
+	remove(path);
 }
 
 BOOL PrintDebugLog(const char *string, int value1, int value2, int value3)
@@ -186,8 +58,8 @@
 	char path[MAX_PATH];
 	FILE *fp;
 
-	sprintf(path, "%s\\debug.txt", gModulePath);
-	fp = fopen(path, "a+t");
+	sprintf(path, "%s/debug.txt", gModulePath);
+	fp = fopen(path, "a+");
 
 	if (fp == NULL)
 		return FALSE;
@@ -196,48 +68,12 @@
 	fclose(fp);
 	return TRUE;
 }
-#endif
 
-#ifdef WINDOWS
-/*
-This function is a mystery. It seems to check if the system time is within
-a certain range, specified by the two parameters. Nothing in the original game
-uses this code.
-
-This is just speculation, but this *might* have been used in those prototypes
-Pixel released to testers, to prevent them from running after a certain date.
-*/
-int CheckTime(SYSTEMTIME *system_time_low, SYSTEMTIME *system_time_high)
-{
-	FILETIME FileTime1;
-	FILETIME FileTime2;
-	SYSTEMTIME SystemTime;
-
-	GetSystemTime(&SystemTime);
-	SystemTimeToFileTime(&SystemTime, &FileTime1);
-	SystemTimeToFileTime(system_time_low, &FileTime2);
-
-	if (CompareFileTime(&FileTime2, &FileTime1) >= 0)
-		return -1;	// Return if actual time is lower than system_time_low
-
-	SystemTimeToFileTime(system_time_high, &FileTime2);
-
-	if (CompareFileTime(&FileTime2, &FileTime1) <= 0)
-		return 1;	// Return if actual time is higher than system_time_high
-	else
-		return 0;
-}
-#endif
-
 BOOL CheckFileExists(const char *name)
 {
 	char path[MAX_PATH];
 
-#ifdef NONPORTABLE
-	sprintf(path, "%s\\%s", gModulePath, name);
-#else
 	sprintf(path, "%s/%s", gModulePath, name);
-#endif
 
 	FILE *file = fopen(path, "rb");
 
@@ -250,20 +86,6 @@
 
 long GetFileSizeLong(const char *path)
 {
-#ifdef NONPORTABLE
-	DWORD len;
-	HANDLE hFile;
-
-	len = 0;
-
-	hFile = CreateFileA(path, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
-	if (hFile == INVALID_HANDLE_VALUE)
-		return -1;
-
-	len = GetFileSize(hFile, NULL);
-	CloseHandle(hFile);
-	return len;
-#else
 	long len;
 	FILE *fp;
 
@@ -277,21 +99,19 @@
 	len = ftell(fp);
 	fclose(fp);
 	return len;
-#endif
 }
 
-#ifdef WINDOWS
 BOOL PrintBitmapError(const char *string, int value)
 {
 	char path[MAX_PATH];
 	FILE *fp;
 
-	sprintf(path, "%s\\%s", gModulePath, "error.log");
+	sprintf(path, "%s/%s", gModulePath, "error.log");
 
 	if (GetFileSizeLong(path) > 0x19000)	// Purge the error log if it gets too big, I guess
-		DeleteFileA(path);
+		remove(path);
 
-	fp = fopen(path, "a+t");
+	fp = fopen(path, "a+");
 	if (fp == NULL)
 		return FALSE;
 
@@ -299,7 +119,6 @@
 	fclose(fp);
 	return TRUE;
 }
-#endif
 
 BOOL IsShiftJIS(unsigned char c)
 {
@@ -310,155 +129,6 @@
 		return TRUE;
 
 	return FALSE;
-}
-
-// TODO - Inaccurate stack frame
-BOOL CenterWindow(HWND hWnd)
-{
-	RECT window_rect;
-	HWND parent_hwnd;
-	RECT parent_rect;
-	int x;
-	int y;
-	RECT child_rect;
-
-	SystemParametersInfoA(SPI_GETWORKAREA, 0, &child_rect, 0);
-
-	GetWindowRect(hWnd, &window_rect);
-
-	parent_hwnd = GetParent(hWnd);
-	if (parent_hwnd)
-		GetWindowRect(parent_hwnd, &parent_rect);
-	else
-		SystemParametersInfoA(SPI_GETWORKAREA, 0, &parent_rect, 0);
-
-	x = parent_rect.left + (parent_rect.right - parent_rect.left - (window_rect.right - window_rect.left)) / 2;
-	y = parent_rect.top + (parent_rect.bottom - parent_rect.top - (window_rect.bottom - window_rect.top)) / 2;
-
-	if (x < child_rect.left)
-		x = child_rect.left;
-
-	if (y < child_rect.top)
-		y = child_rect.top;
-
-	if (window_rect.right - window_rect.left + x > child_rect.right)
-		x = child_rect.right - (window_rect.right - window_rect.left);
-
-	if (window_rect.bottom - window_rect.top + y > child_rect.bottom)
-		y = child_rect.bottom - (window_rect.bottom - window_rect.top);
-
-	return SetWindowPos(hWnd, HWND_TOP, x, y, 0, 0, SWP_NOSIZE);
-}
-
-// TODO - Inaccurate stack frame
-BOOL LoadWindowRect(HWND hWnd, const char *filename, BOOL unknown)
-{
-	char path[MAX_PATH];
-	int min_window_width;
-	int min_window_height;
-	int max_window_width;
-	int max_window_height;
-	FILE *fp;
-	RECT Rect;
-	int showCmd;
-	RECT pvParam;
-
-	showCmd = SW_SHOWNORMAL;
-
-	sprintf(path, "%s\\%s", gModulePath, filename);
-
-	fp = fopen(path, "rb");
-	if (fp)
-	{
-		fread(&Rect, sizeof(RECT), 1, fp);
-		fread(&showCmd, sizeof(int), 1, fp);
-		fclose(fp);
-
-		SystemParametersInfoA(SPI_GETWORKAREA, 0, &pvParam, 0);
-
-		max_window_width = GetSystemMetrics(SM_CXMAXIMIZED);
-		max_window_height = GetSystemMetrics(SM_CYMAXIMIZED);
-		min_window_width = GetSystemMetrics(SM_CXMIN);
-		min_window_height = GetSystemMetrics(SM_CYMIN);
-
-		if (Rect.right - Rect.left < min_window_width)
-			Rect.right = min_window_width + Rect.left;
-		if (Rect.bottom - Rect.top < min_window_height)
-			Rect.bottom = min_window_height + Rect.top;
-		if (Rect.right - Rect.left > max_window_width)
-			Rect.right = max_window_width + Rect.left;
-		if (Rect.bottom - Rect.top > max_window_height)
-			Rect.bottom = max_window_width + Rect.top;
-
-		if (Rect.left < pvParam.left)
-		{
-			Rect.right += pvParam.left - Rect.left;
-			Rect.left = pvParam.left;
-		}
-		if (Rect.top < pvParam.top)
-		{
-			Rect.bottom += pvParam.top - Rect.top;
-			Rect.top = pvParam.top;
-		}
-		if (Rect.right > pvParam.right)
-		{
-			Rect.left -= Rect.right - pvParam.right;
-			Rect.right -= Rect.right - pvParam.right;
-		}
-		if (Rect.bottom > pvParam.bottom)
-		{
-			Rect.top -= Rect.bottom - pvParam.bottom;
-			Rect.bottom -= Rect.bottom - pvParam.bottom;
-		}
-
-		if (unknown)
-			MoveWindow(hWnd, Rect.left, Rect.top, Rect.right - Rect.left, Rect.bottom - Rect.top, 0);
-		else
-			SetWindowPos(hWnd, HWND_TOP, Rect.left, Rect.top, 0, 0, SWP_NOSIZE);
-	}
-
-	if (showCmd == SW_MAXIMIZE)
-	{
-		if (!ShowWindow(hWnd, SW_MAXIMIZE))
-			return FALSE;
-	}
-	else
-	{
-		ShowWindow(hWnd, SW_SHOWNORMAL);
-	}
-
-	return TRUE;
-}
-
-BOOL SaveWindowRect(HWND hWnd, const char *filename)
-{
-	char path[MAX_PATH];
-	WINDOWPLACEMENT wndpl;
-	FILE *fp;
-	RECT rect;
-
-	if (!GetWindowPlacement(hWnd, &wndpl))
-		return FALSE;
-
-	if (wndpl.showCmd == SW_SHOWNORMAL)
-	{
-		if (!GetWindowRect(hWnd, &rect))
-			return FALSE;
-
-		wndpl.rcNormalPosition = rect;
-	}
-
-	sprintf(path, "%s\\%s", gModulePath, filename);
-
-	fp = fopen(path, "wb");
-	if (fp == NULL)
-		return FALSE;
-
-	fwrite(&wndpl.rcNormalPosition, sizeof(RECT), 1, fp);
-	fwrite(&wndpl.showCmd, sizeof(int), 1, fp);
-	fclose(fp);
-
-	return TRUE;
 }
 
 BOOL IsEnableBitmap(const char *path)
--- a/src/Generic.h
+++ b/src/Generic.h
@@ -4,19 +4,10 @@
 
 void GetCompileDate(int *year, int *month, int *day);
 BOOL GetCompileVersion(int *v1, int *v2, int *v3, int *v4);
-#ifdef WINDOWS
-BOOL OpenVolumeConfiguration(HWND hWnd);
 void DeleteDebugLog(void);
 BOOL PrintDebugLog(const char *string, int value1, int value2, int value3);
-int CheckTime(SYSTEMTIME *system_time_low, SYSTEMTIME *system_time_high);
-#endif
 BOOL CheckFileExists(const char *name);
 long GetFileSizeLong(const char *path);
-#ifdef WINDOWS
 BOOL PrintBitmapError(const char *string, int value);
-#endif
 BOOL IsShiftJIS(unsigned char c);
-BOOL CenterWindow(HWND hWnd);
-BOOL LoadWindowRect(HWND hWnd, const char *filename, BOOL unknown);
-BOOL SaveWindowRect(HWND hWnd, const char *filename);
 BOOL IsEnableBitmap(const char *path);
--- a/src/Main.cpp
+++ b/src/Main.cpp
@@ -4,17 +4,14 @@
 #include <stdio.h>
 #include <string.h>
 
-#include <shlwapi.h>
-
 #include "SDL.h"
-#include "SDL_syswm.h"
 
 #include "WindowsWrapper.h"
 
 #include "CommonDefines.h"
 #include "Config.h"
-#include "Dialog.h"
 #include "Draw.h"
+#include "File.h"
 #include "Game.h"
 #include "Generic.h"
 #include "Input.h"
@@ -30,7 +27,6 @@
 
 int gJoystickButtonTable[8];
 
-HWND ghWnd;
 BOOL bFullscreen;
 BOOL gbUseJoystick = FALSE;
 
@@ -37,9 +33,6 @@
 static BOOL bFps = FALSE;
 static BOOL bActive = TRUE;
 
-static HANDLE hObject;
-static HANDLE hMutex;
-
 static int windowWidth;
 static int windowHeight;
 
@@ -71,11 +64,11 @@
 
 	if (need_new_base_tick)
 	{
-		base_tick = GetTickCount();
+		base_tick = SDL_GetTicks();
 		need_new_base_tick = FALSE;
 	}
 
-	current_tick = GetTickCount();
+	current_tick = SDL_GetTicks();
 	++current_frame;
 
 	if (base_tick + 1000 <= current_tick)
@@ -95,22 +88,16 @@
 
 	int i;
 
-	hObject = OpenMutexA(MUTEX_ALL_ACCESS, 0, mutex_name);
-	if (hObject != NULL)
-	{
-		CloseHandle(hObject);
-		return 0;
-	}
-
-	hMutex = CreateMutexA(NULL, FALSE, mutex_name);
-
 	// Get executable's path
-	GetModuleFileNameA(NULL, gModulePath, MAX_PATH);
-	PathRemoveFileSpecA(gModulePath);
+	char *base_path = SDL_GetBasePath();
+	size_t base_path_length = strlen(base_path);
+	base_path[base_path_length - 1] = '\0';
+	strcpy(gModulePath, base_path);
+	SDL_free(base_path);
 
 	// Get path of the data folder
 	strcpy(gDataPath, gModulePath);
-	strcat(gDataPath, "\\data");
+	strcat(gDataPath, "/data");
 
 	CONFIG conf;
 	if (!LoadConfigData(&conf))
@@ -205,9 +192,7 @@
 
 	SDL_Init(SDL_INIT_EVENTS);
 
-	HWND hWnd;
 	SDL_Window *window;
-	SDL_SysWMinfo info;
 
 	switch (conf.display_mode)
 	{
@@ -228,17 +213,8 @@
 			window = CreateWindow(lpWindowName, windowWidth, windowHeight);
 
 			if (window == NULL)
-			{
-				ReleaseMutex(hMutex);
 				return 0;
-			}
 
-			SDL_VERSION(&info.version);
-			SDL_GetWindowWMInfo(window, &info);
-			hWnd = info.info.win.window;
-
-			ghWnd = hWnd;
-
 			if (conf.display_mode == 1)
 				StartDirectDraw(window, 0);
 			else
@@ -256,24 +232,8 @@
 			window = CreateWindow(lpWindowName, windowWidth, windowHeight);
 
 			if (window == NULL)
-			{
-				ReleaseMutex(hMutex);
 				return 0;
-			}
 
-			SDL_VERSION(&info.version);
-			SDL_GetWindowWMInfo(window, &info);
-			hWnd = info.info.win.window;
-
-			ghWnd = hWnd;
-
-			if (hWnd == NULL)
-			{
-				SDL_DestroyWindow(window);
-				ReleaseMutex(hMutex);
-				return 0;
-			}
-
 			// Set colour depth
 			int depth;
 
@@ -303,9 +263,6 @@
 	if (CheckFileExists("fps"))
 		bFps = TRUE;
 
-	if (!bFullscreen)
-		LoadWindowRect(hWnd, "window.rect", FALSE);
-
 	// Set rects
 	RECT rcLoading = {0, 0, 64, 8};
 	RECT rcFull = {0, 0, 0, 0};
@@ -323,7 +280,6 @@
 	if (!Flip_SystemTask())
 	{
 		SDL_DestroyWindow(window);
-		ReleaseMutex(hMutex);
 		return 1;
 	}
 	else
@@ -343,7 +299,7 @@
 		InitTriangleTable();
 
 		// Run game code
-		Game(hWnd);
+		Game();
 
 		// End stuff
 		EndDirectSound();
@@ -351,7 +307,6 @@
 		EndDirectDraw();
 
 		SDL_DestroyWindow(window);
-		ReleaseMutex(hMutex);
 	}
 
 	return 1;
--- a/src/Main.h
+++ b/src/Main.h
@@ -2,7 +2,6 @@
 
 #include "WindowsWrapper.h"
 
-extern HWND ghWnd;
 extern BOOL bFullscreen;
 
 void PutFramePerSecound(void);
--- a/src/Map.cpp
+++ b/src/Map.cpp
@@ -9,6 +9,7 @@
 
 #include "CommonDefines.h"
 #include "Draw.h"
+#include "File.h"
 #include "NpChar.h"
 #include "Tags.h"
 
--- a/src/MiniMap.cpp
+++ b/src/MiniMap.cpp
@@ -94,7 +94,7 @@
 
 		if (gKey & KEY_ESCAPE)
 		{
-			switch (Call_Escape(ghWnd))
+			switch (Call_Escape())
 			{
 				case 0:
 					return 0;
@@ -138,7 +138,7 @@
 
 		if (gKey & KEY_ESCAPE)
 		{
-			switch (Call_Escape(ghWnd))
+			switch (Call_Escape())
 			{
 				case 0:
 					return 0;
@@ -179,7 +179,7 @@
 
 		if (gKey & KEY_ESCAPE)
 		{
-			switch (Call_Escape(ghWnd))
+			switch (Call_Escape())
 			{
 				case 0:
 					return 0;
--- a/src/MycParam.cpp
+++ b/src/MycParam.cpp
@@ -8,6 +8,7 @@
 #include "CommonDefines.h"
 #include "Caret.h"
 #include "Draw.h"
+#include "File.h"
 #include "Game.h"
 #include "MyChar.h"
 #include "NpChar.h"
--- a/src/NpChar.cpp
+++ b/src/NpChar.cpp
@@ -9,6 +9,7 @@
 #include "ArmsItem.h"
 #include "Caret.h"
 #include "Draw.h"
+#include "File.h"
 #include "Flags.h"
 #include "Game.h"
 #include "MyChar.h"
--- a/src/NpcTbl.cpp
+++ b/src/NpcTbl.cpp
@@ -6,6 +6,7 @@
 
 #include "WindowsWrapper.h"
 
+#include "File.h"
 #include "Generic.h"
 #include "NpcAct.h"
 
--- a/src/Organya.cpp
+++ b/src/Organya.cpp
@@ -8,6 +8,7 @@
 
 #include <stddef.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 
 #include "WindowsWrapper.h"
@@ -112,6 +113,8 @@
 	BOOL InitMusicData(const char *path);
 } ORGDATA;
 
+unsigned short organya_timer;
+
 ORGDATA org_data;
 
 AudioBackend_Sound *lpORGANBUFFER[8][8][2] = {NULL};
@@ -678,117 +681,6 @@
 	}
 }
 
-/*■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■*/
-//プロトタイプ宣言 (prototype declaration)
-/*■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■*/
-
-BOOL InitMMTimer();
-BOOL StartTimer(DWORD dwTimer);
-VOID CALLBACK TimerProc(UINT uTID,UINT uMsg,DWORD dwUser,DWORD dwParam1,DWORD dwParam2);
-BOOL QuitMMTimer();
-
-/*■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■*/
-//グローバル変数 (Global variable)
-/*■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■*/
-static UINT ExactTime   = 13;	// 最小精度 (Minimum accuracy)
-static UINT TimerID;
-static BOOL nameless_flag;
-
-/*■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■*/
-// タイマー精度を設定する。 (Set timer accuracy.)
-// この関数はアプリケーション初期化時に一度呼び出す。 (This function is called once when the application is initialized.)
-/*■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■*/
-BOOL InitMMTimer()
-{
-	TIMECAPS tc;
-	MMRESULT ret;
-
-	// タイマーの精度情報を取得する (Get timer accuracy information)
-	ret = timeGetDevCaps(&tc,sizeof(TIMECAPS));
-	if (ret != TIMERR_NOERROR)
-		return FALSE;
-
-	if (ExactTime < tc.wPeriodMin)
-		ExactTime = tc.wPeriodMin;
-
-	// この精度で初期化する (Initialize with this precision)
-	ret = timeBeginPeriod(ExactTime);
-	if (ret != TIMERR_NOERROR)
-		return FALSE;
-
-	return TRUE;
-}
-
-/*■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■*/
-// タイマーを起動する。 (Start the timer.)
-// dwTimer   設定するタイマー間隔 (dwTimer   Timer interval to be set)
-/*■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■*/
-BOOL StartTimer(DWORD dwTimer)
-{
-	MMRESULT ret = MMSYSERR_NOERROR;
-	ExactTime = dwTimer;
-
-	// タイマーを生成する (Generate timer)
-	TimerID = timeSetEvent
-	(
-		dwTimer,                   // タイマー時間 (Timer time)
-		10,                        // 許容できるタイマー精度 (Acceptable timer accuracy)
-		(LPTIMECALLBACK)TimerProc, // コールバックプロシージャ (Callback procedure)
-		0,                         // ユーザーがコールバック関数のdwUserに送る情報値 (Information value sent by user to dwUser in callback function)
-		TIME_PERIODIC              // タイマー時間毎にイベントを発生させる (Generate an event every timer time)
-	);
-
-	if (ret != TIMERR_NOERROR)
-		return FALSE;
-
-	nameless_flag = TRUE;
-
-	return TRUE;
-}
-
-/*■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■*/
-// タイマーのコールバック関数 (Timer callback function)
-/*■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■*/
-VOID CALLBACK TimerProc(UINT uTID,UINT uMsg,DWORD dwUser,DWORD dwParam1,DWORD dwParam2)
-{
-	DWORD dwNowTime;
-	dwNowTime = timeGetTime();
-	//===================================================================================
-	// ここにユーザー定義のソースを書く。 (Write user-defined source here.)
-	// 基本的に関数を呼び出すだけで処理は他の関数でするべきだろう。 (Basically just call a function and the process should be another function.)
-	//===================================================================================
-	org_data.PlayData();
-}
-
-/*■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■*/
-// タイマーリソースを開放する。 (Release timer resources.)
-// アプリケーション終了時に一度呼び出す。 (Call once when the application ends.)
-/*■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■*/
-BOOL QuitMMTimer()
-{
-	MMRESULT ret;
-
-	if (!nameless_flag)
-		return FALSE;
-
-	if(TimerID != TIMERR_NOERROR)
-	{
-		// タイマーを使用中なら終了させる (Terminate timer if in use)
-		ret = timeKillEvent(TimerID);
-		if (ret != TIMERR_NOERROR)
-			return FALSE;
-	}
-
-	// タイマーリソースを開放する (Release timer resources)
-	ret = timeEndPeriod(ExactTime);
-	if (ret != TIMERR_NOERROR)
-		return FALSE;
-
-	nameless_flag = FALSE;
-
-	return TRUE;
-}
-
 // Play data
 long play_p;
 NOTELIST *play_np[MAXTRACK];
@@ -915,9 +807,7 @@
 
 void PlayOrganyaMusic(void)
 {
-	QuitMMTimer();
-	InitMMTimer();
-	StartTimer(org_data.info.wait);
+	organya_timer = org_data.info.wait;
 }
 
 BOOL ChangeOrganyaVolume(signed int volume)
@@ -931,8 +821,7 @@
 
 void StopOrganyaMusic()
 {
-	// Stop timer
-	QuitMMTimer();
+	organya_timer = 0;
 
 	// Stop notes
 	for (int i = 0; i < MAXMELODY; i++)
@@ -942,7 +831,7 @@
 	memset(key_on, 0, sizeof(key_on));
 	memset(key_twin, 0, sizeof(key_twin));
 
-	Sleep(100);
+//	Sleep(100);
 }
 
 void SetOrganyaFadeout()
@@ -952,8 +841,7 @@
 
 void EndOrganya()
 {
-	// End timer
-	QuitMMTimer();
+	organya_timer = 0;
 
 	// Release everything related to org
 	org_data.ReleaseNote();
@@ -963,4 +851,9 @@
 		PlayOrganObject(0, 0, i, 0);
 		ReleaseOrganyaObject(i);
 	}
+}
+
+void UpdateOrganya(void)
+{
+	org_data.PlayData();
 }
--- a/src/Organya.h
+++ b/src/Organya.h
@@ -1,7 +1,5 @@
 #pragma once
 
-#include <dsound.h>
-
 #include "WindowsWrapper.h"
 
 #define MAXTRACK 16
@@ -8,6 +6,8 @@
 #define MAXMELODY 8
 #define MAXDRAM 8
 
+extern unsigned short organya_timer;
+
 extern BOOL g_mute[MAXTRACK];	// Used by the debug Mute menu
 
 BOOL MakeOrganyaWave(signed char track, signed char wave_no, signed char pipi);
@@ -22,3 +22,4 @@
 void SetOrganyaFadeout();
 BOOL StartOrganya(const char *wave_filename);
 void EndOrganya();
+void UpdateOrganya(void);
--- a/src/Profile.cpp
+++ b/src/Profile.cpp
@@ -9,6 +9,7 @@
 #include "ArmsItem.h"
 #include "BossLife.h"
 #include "Fade.h"
+#include "File.h"
 #include "Flags.h"
 #include "Frame.h"
 #include "Game.h"
@@ -237,7 +238,7 @@
 	return TRUE;
 }
 
-BOOL InitializeGame(HWND hWnd)
+BOOL InitializeGame(void)
 {
 	InitMyChar();
 	gSelectedArms = 0;
@@ -250,21 +251,11 @@
 	InitFlags();
 	if (!TransferStage(13, 200, 10, 8))
 	{
-		#if defined(NONPORTABLE) && defined(WINDOWS)
-			#ifdef JAPANESE
-			MessageBoxA(hWnd, "\x83\x58\x83\x65\x81\x5B\x83\x57\x82\xCC\x93\xC7\x82\xDD\x8D\x9E\x82\xDD\x82\xC9\x8E\xB8\x94\x73", "\x83\x47\x83\x89\x81\x5B", MB_OK);
-			#else
-			MessageBoxA(hWnd, "Failed to load stage", "Error", MB_OK);
-			#endif
-		#else
-			(void)hWnd;
-
-			#ifdef JAPANESE
-			SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "エラー", "ステージの読み込みに失敗", NULL);
-			#else
-			SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "Failed to load stage", NULL);
-			#endif
-		#endif
+#ifdef JAPANESE
+		SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "エラー", "ステージの読み込みに失敗", NULL);
+#else
+		SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "Failed to load stage", NULL);
+#endif
 
 		return FALSE;
 	}
--- a/src/Profile.h
+++ b/src/Profile.h
@@ -34,4 +34,4 @@
 BOOL IsProfile();
 BOOL SaveProfile(const char *name);
 BOOL LoadProfile(const char *name);
-BOOL InitializeGame(HWND hWnd);
+BOOL InitializeGame(void);
--- a/src/SelStage.cpp
+++ b/src/SelStage.cpp
@@ -169,7 +169,7 @@
 
 		if (gKey & KEY_ESCAPE)
 		{
-			switch (Call_Escape(ghWnd))
+			switch (Call_Escape())
 			{
 				case 0:
 					return 0;
--- a/src/Sound.cpp
+++ b/src/Sound.cpp
@@ -233,7 +233,6 @@
 {
 	int i;
 	int j;
-	DSBUFFERDESC dsbd;
 	const PIXTONEPARAMETER *ptp_pointer;
 	int sample_count;
 	unsigned char *pcm_buffer;
--- a/src/TextScr.cpp
+++ b/src/TextScr.cpp
@@ -705,18 +705,10 @@
 						y = GetTextScriptNo(gTS.p_read + 19);
 						if (!TransferStage(z, w, x, y))
 						{
-							#if defined(NONPORTABLE) && defined(WINDOWS)
-								#ifdef JAPANESE
-								MessageBoxA(ghWnd, "\x83\x58\x83\x65\x81\x5B\x83\x57\x82\xCC\x93\xC7\x82\xDD\x8D\x9E\x82\xDD\x82\xC9\x8E\xB8\x94\x73", "\x83\x47\x83\x89\x81\x5B", MB_OK);
-								#else
-								MessageBoxA(ghWnd, "Failed to load stage", "Error", MB_OK);
-								#endif
+							#ifdef JAPANESE
+							SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "エラー", "ステージの読み込みに失敗", NULL);
 							#else
-								#ifdef JAPANESE
-								SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "エラー", "ステージの読み込みに失敗", NULL);
-								#else
-								SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "Failed to load stage", NULL);
-								#endif
+							SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "Failed to load stage", NULL);
 							#endif
 
 							return 0;
@@ -1180,7 +1172,7 @@
 					}
 					else if (IS_COMMAND('I','N','I'))
 					{
-						InitializeGame(ghWnd);
+						InitializeGame();
 						gTS.p_read += 4;
 					}
 					else if (IS_COMMAND('S','V','P'))
@@ -1191,7 +1183,7 @@
 					else if (IS_COMMAND('L','D','P'))
 					{
 						if (!LoadProfile(NULL))
-							InitializeGame(ghWnd);
+							InitializeGame();
 					}
 					else if (IS_COMMAND('F','A','C'))
 					{
@@ -1253,7 +1245,7 @@
 						bExit = TRUE;
 						z = GetTextScriptNo(gTS.p_read + 4);
 
-						switch (Scene_DownIsland(ghWnd, z))
+						switch (Scene_DownIsland(z))
 						{
 							case 0:
 								return 0;
--- a/src/WindowsWrapper.h
+++ b/src/WindowsWrapper.h
@@ -1,5 +1,5 @@
 #pragma once
-
+/*
 #ifdef WINDOWS
 #include <windows.h>
 // Avoid name collisions
@@ -7,7 +7,7 @@
 #undef FindResource
 #undef CreateWindow
 #else
-
+*/
 #include <stdio.h>
 
 typedef int HWND;
@@ -14,6 +14,9 @@
 
 typedef int BOOL;
 
+typedef unsigned char BYTE;
+typedef unsigned long DWORD;
+
 #ifndef FALSE
 #define FALSE 0
 #endif
@@ -29,7 +32,7 @@
 	long right;
 	long bottom;
 };
-#endif
+//#endif
 
 #define SET_RECT(rect, l, t, r, b) \
 	rect.left = l; \
--