From 5ea356a3bd46a96604d5f2dadd00fcf0d418ccdb Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 4 Sep 2019 00:27:36 +0100 Subject: [PATCH] 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. --- Makefile | 4 +- src/ArmsItem.cpp | 2 +- src/Back.cpp | 1 + src/Backends/Audio/SDL2.cpp | 17 ++ src/Config.cpp | 1 + src/Dialog.cpp | 157 ---------------- src/Dialog.h | 8 - src/Draw.cpp | 6 +- src/Draw.h | 2 +- src/Ending.cpp | 4 +- src/Ending.h | 2 +- src/Escape.cpp | 2 +- src/Escape.h | 4 +- src/File.cpp | 96 ++++++++++ src/File.h | 15 ++ src/Game.cpp | 73 +++----- src/Game.h | 2 +- src/Generic.cpp | 344 +----------------------------------- src/Generic.h | 9 - src/Main.cpp | 65 ++----- src/Main.h | 1 - src/Map.cpp | 1 + src/MiniMap.cpp | 6 +- src/MycParam.cpp | 1 + src/NpChar.cpp | 1 + src/NpcTbl.cpp | 1 + src/Organya.cpp | 131 ++------------ src/Organya.h | 5 +- src/Profile.cpp | 23 +-- src/Profile.h | 2 +- src/SelStage.cpp | 2 +- src/Sound.cpp | 1 - src/TextScr.cpp | 20 +-- src/WindowsWrapper.h | 9 +- 34 files changed, 231 insertions(+), 787 deletions(-) delete mode 100644 src/Dialog.cpp delete mode 100644 src/Dialog.h create mode 100644 src/File.cpp create mode 100644 src/File.h diff --git a/Makefile b/Makefile index de23a0fa..71a31948 100644 --- a/Makefile +++ b/Makefile @@ -44,7 +44,7 @@ ifeq ($(DEBUG_SAVE), 1) 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 @@ SOURCES = \ src/Bullet \ src/Caret \ src/Config \ - src/Dialog \ src/Draw \ src/Ending \ src/Escape \ src/Fade \ + src/File \ src/Flags \ src/Flash \ src/Frame \ diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index 18e7123e..62d84c86 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -394,7 +394,7 @@ int CampLoop() if (gKeyTrg & KEY_ESCAPE) { - switch (Call_Escape(ghWnd)) + switch (Call_Escape()) { case 0: return 0; diff --git a/src/Back.cpp b/src/Back.cpp index 0a2f2e97..443503a2 100644 --- 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" diff --git a/src/Backends/Audio/SDL2.cpp b/src/Backends/Audio/SDL2.cpp index 9a8d0ee2..183e24d6 100644 --- 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)) @@ -78,6 +79,22 @@ static void Callback(void *user_data, Uint8 *stream_uint8, int len) 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) { if (sound->playing) diff --git a/src/Config.cpp b/src/Config.cpp index f9b19e5d..d66d1fd6 100644 --- 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 diff --git a/src/Dialog.cpp b/src/Dialog.cpp deleted file mode 100644 index 7cb211a9..00000000 --- a/src/Dialog.cpp +++ /dev/null @@ -1,157 +0,0 @@ -#include "Dialog.h" - -#include - -#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; -} diff --git a/src/Dialog.h b/src/Dialog.h deleted file mode 100644 index 08fa948b..00000000 --- a/src/Dialog.h +++ /dev/null @@ -1,8 +0,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); diff --git a/src/Draw.cpp b/src/Draw.cpp index dd0562b8..756399fd 100644 --- a/src/Draw.cpp +++ b/src/Draw.cpp @@ -59,12 +59,12 @@ BOOL Flip_SystemTask(void) 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 @@ void Surface2Surface(int x, int y, const RECT *rect, int to, int from) 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; diff --git a/src/Draw.h b/src/Draw.h index 99e707ee..4ead4d1a 100644 --- a/src/Draw.h +++ b/src/Draw.h @@ -64,7 +64,7 @@ void BackupSurface(SurfaceID surf_no, const RECT *rect); 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); diff --git a/src/Ending.cpp b/src/Ending.cpp index 3ce6b38c..15494286 100644 --- a/src/Ending.cpp +++ b/src/Ending.cpp @@ -435,7 +435,7 @@ void CutCreditIllust() } // 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 @@ int Scene_DownIsland(HWND hWnd, int mode) // Escape menu if (gKey & 0x8000) { - switch (Call_Escape(hWnd)) + switch (Call_Escape()) { case 0: return 0; diff --git a/src/Ending.h b/src/Ending.h index 54d2b73a..a4e3f9a2 100644 --- a/src/Ending.h +++ b/src/Ending.h @@ -52,4 +52,4 @@ void ActionCredit_Read(); int GetScriptNumber(const char *text); void SetCreditIllust(int a); void CutCreditIllust(); -int Scene_DownIsland(HWND hWnd, int mode); +int Scene_DownIsland(int mode); diff --git a/src/Escape.cpp b/src/Escape.cpp index 11ed3d1e..af9be3e5 100644 --- 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}; diff --git a/src/Escape.h b/src/Escape.h index 508da8c9..391fd2ba 100644 --- 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); diff --git a/src/File.cpp b/src/File.cpp new file mode 100644 index 00000000..257e5e7c --- /dev/null +++ b/src/File.cpp @@ -0,0 +1,96 @@ +#include "File.h" + +#include +#include +#include + +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); +} diff --git a/src/File.h b/src/File.h new file mode 100644 index 00000000..d84dc370 --- /dev/null +++ b/src/File.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +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); diff --git a/src/Game.cpp b/src/Game.cpp index 1bb2e170..a9231fdc 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -4,6 +4,8 @@ #include #include +#include "SDL.h" + #include "WindowsWrapper.h" #include "ArmsItem.h" @@ -108,7 +110,7 @@ void PutNumber4(int x, int y, int value, BOOL bZero) } } -int ModeOpening(HWND hWnd) +int ModeOpening() { int frame_x; int frame_y; @@ -150,7 +152,7 @@ int ModeOpening(HWND hWnd) // Escape menu if (gKey & KEY_ESCAPE) { - switch (Call_Escape(ghWnd)) + switch (Call_Escape()) { case 0: return 0; @@ -211,8 +213,8 @@ int ModeOpening(HWND hWnd) ++gCounter; } - wait = GetTickCount(); - while (GetTickCount() < wait + 500) + wait = SDL_GetTicks(); + while (SDL_GetTicks() < wait + 500) { CortBox(&grcGame, 0x000000); PutFramePerSecound(); @@ -222,7 +224,7 @@ int ModeOpening(HWND hWnd) return 2; } -int ModeTitle(HWND hWnd) +int ModeTitle(void) { // Set rects RECT rcTitle = {0, 0, 144, 40}; @@ -360,7 +362,7 @@ int ModeTitle(HWND hWnd) if (gKey & KEY_ESCAPE) { - switch (Call_Escape(ghWnd)) + switch (Call_Escape()) { case 0: return 0; @@ -456,8 +458,8 @@ int ModeTitle(HWND hWnd) 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 @@ int ModeTitle(HWND hWnd) return 3; } -int ModeAction(HWND hWnd) +int ModeAction(void) { int frame_x; int frame_y; @@ -506,12 +508,12 @@ int ModeAction(HWND hWnd) 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 @@ int ModeAction(HWND hWnd) // Escape menu if (gKey & KEY_ESCAPE) { - switch (Call_Escape(ghWnd)) + switch (Call_Escape()) { case 0: return 0; @@ -676,25 +678,17 @@ int ModeAction(HWND hWnd) 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 @@ BOOL Game(HWND hWnd) 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 @@ BOOL Game(HWND hWnd) 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); @@ -746,8 +732,5 @@ BOOL Game(HWND hWnd) ReleaseNpcTable(); ReleaseCreditScript(); - if (!bFullscreen) - SaveWindowRect(hWnd, "window.rect"); - return TRUE; } diff --git a/src/Game.h b/src/Game.h index e821ed8c..0341de0b 100644 --- a/src/Game.h +++ b/src/Game.h @@ -8,4 +8,4 @@ extern int gCounter; int Random(int min, int max); void PutNumber4(int x, int y, int value, BOOL bZero); -BOOL Game(HWND hWnd); +BOOL Game(void); diff --git a/src/Generic.cpp b/src/Generic.cpp index cee26700..815408fd 100644 --- a/src/Generic.cpp +++ b/src/Generic.cpp @@ -36,66 +36,6 @@ void GetCompileDate(int *year, int *month, int *day) *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; @@ -104,81 +44,13 @@ BOOL GetCompileVersion(int *v1, int *v2, int *v3, int *v4) *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 @@ BOOL PrintDebugLog(const char *string, int value1, int value2, int value3) 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 @@ BOOL PrintDebugLog(const char *string, int value1, int value2, int value3) 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 @@ BOOL CheckFileExists(const char *name) 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 @@ long GetFileSizeLong(const char *path) 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 @@ BOOL PrintBitmapError(const char *string, int value) fclose(fp); return TRUE; } -#endif BOOL IsShiftJIS(unsigned char c) { @@ -312,155 +131,6 @@ BOOL IsShiftJIS(unsigned char c) 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) { char str[16]; diff --git a/src/Generic.h b/src/Generic.h index 1743b0ea..d6ea38bb 100644 --- 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); diff --git a/src/Main.cpp b/src/Main.cpp index 58a43204..2cf9ae66 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -4,17 +4,14 @@ #include #include -#include - #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,16 +27,12 @@ char gDataPath[MAX_PATH]; int gJoystickButtonTable[8]; -HWND ghWnd; BOOL bFullscreen; BOOL gbUseJoystick = FALSE; static BOOL bFps = FALSE; static BOOL bActive = TRUE; -static HANDLE hObject; -static HANDLE hMutex; - static int windowWidth; static int windowHeight; @@ -71,11 +64,11 @@ unsigned long GetFramePerSecound(void) 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 main(int argc, char *argv[]) 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 @@ int main(int argc, char *argv[]) SDL_Init(SDL_INIT_EVENTS); - HWND hWnd; SDL_Window *window; - SDL_SysWMinfo info; switch (conf.display_mode) { @@ -228,16 +213,7 @@ int main(int argc, char *argv[]) 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); @@ -256,23 +232,7 @@ int main(int argc, char *argv[]) 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 @@ int main(int argc, char *argv[]) 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 @@ int main(int argc, char *argv[]) if (!Flip_SystemTask()) { SDL_DestroyWindow(window); - ReleaseMutex(hMutex); return 1; } else @@ -343,7 +299,7 @@ int main(int argc, char *argv[]) InitTriangleTable(); // Run game code - Game(hWnd); + Game(); // End stuff EndDirectSound(); @@ -351,7 +307,6 @@ int main(int argc, char *argv[]) EndDirectDraw(); SDL_DestroyWindow(window); - ReleaseMutex(hMutex); } return 1; diff --git a/src/Main.h b/src/Main.h index 745bde86..cc49639c 100644 --- a/src/Main.h +++ b/src/Main.h @@ -2,7 +2,6 @@ #include "WindowsWrapper.h" -extern HWND ghWnd; extern BOOL bFullscreen; void PutFramePerSecound(void); diff --git a/src/Map.cpp b/src/Map.cpp index 6a96ce06..f0cd6b9e 100644 --- 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" diff --git a/src/MiniMap.cpp b/src/MiniMap.cpp index 168b29d8..bf7e761d 100644 --- a/src/MiniMap.cpp +++ b/src/MiniMap.cpp @@ -94,7 +94,7 @@ int MiniMapLoop() if (gKey & KEY_ESCAPE) { - switch (Call_Escape(ghWnd)) + switch (Call_Escape()) { case 0: return 0; @@ -138,7 +138,7 @@ int MiniMapLoop() if (gKey & KEY_ESCAPE) { - switch (Call_Escape(ghWnd)) + switch (Call_Escape()) { case 0: return 0; @@ -179,7 +179,7 @@ int MiniMapLoop() if (gKey & KEY_ESCAPE) { - switch (Call_Escape(ghWnd)) + switch (Call_Escape()) { case 0: return 0; diff --git a/src/MycParam.cpp b/src/MycParam.cpp index 21965ff1..e18eb37c 100644 --- 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" diff --git a/src/NpChar.cpp b/src/NpChar.cpp index 79854404..bef60e69 100644 --- 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" diff --git a/src/NpcTbl.cpp b/src/NpcTbl.cpp index 25784433..56a46349 100644 --- a/src/NpcTbl.cpp +++ b/src/NpcTbl.cpp @@ -6,6 +6,7 @@ #include "WindowsWrapper.h" +#include "File.h" #include "Generic.h" #include "NpcAct.h" diff --git a/src/Organya.cpp b/src/Organya.cpp index 7fed7147..8e6e229f 100644 --- a/src/Organya.cpp +++ b/src/Organya.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include "WindowsWrapper.h" @@ -112,6 +113,8 @@ typedef struct OrgData BOOL InitMusicData(const char *path); } ORGDATA; +unsigned short organya_timer; + ORGDATA org_data; AudioBackend_Sound *lpORGANBUFFER[8][8][2] = {NULL}; @@ -678,117 +681,6 @@ void OrgData::GetMusicInfo(MUSICINFO *mi) } } -/*■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■*/ -//プロトタイプ宣言 (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 @@ unsigned int GetOrganyaPosition(void) 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 @@ BOOL ChangeOrganyaVolume(signed int volume) void StopOrganyaMusic() { - // Stop timer - QuitMMTimer(); + organya_timer = 0; // Stop notes for (int i = 0; i < MAXMELODY; i++) @@ -942,7 +831,7 @@ void StopOrganyaMusic() 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 SetOrganyaFadeout() void EndOrganya() { - // End timer - QuitMMTimer(); + organya_timer = 0; // Release everything related to org org_data.ReleaseNote(); @@ -964,3 +852,8 @@ void EndOrganya() ReleaseOrganyaObject(i); } } + +void UpdateOrganya(void) +{ + org_data.PlayData(); +} diff --git a/src/Organya.h b/src/Organya.h index a234e260..4b1d8148 100644 --- a/src/Organya.h +++ b/src/Organya.h @@ -1,13 +1,13 @@ #pragma once -#include - #include "WindowsWrapper.h" #define MAXTRACK 16 #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 StopOrganyaMusic(); void SetOrganyaFadeout(); BOOL StartOrganya(const char *wave_filename); void EndOrganya(); +void UpdateOrganya(void); diff --git a/src/Profile.cpp b/src/Profile.cpp index c8f09ac8..0ea76be6 100644 --- 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 @@ BOOL LoadProfile(const char *name) return TRUE; } -BOOL InitializeGame(HWND hWnd) +BOOL InitializeGame(void) { InitMyChar(); gSelectedArms = 0; @@ -250,21 +251,11 @@ BOOL InitializeGame(HWND hWnd) 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; } diff --git a/src/Profile.h b/src/Profile.h index 3bbe37bd..ed95b338 100644 --- a/src/Profile.h +++ b/src/Profile.h @@ -34,4 +34,4 @@ struct PROFILE BOOL IsProfile(); BOOL SaveProfile(const char *name); BOOL LoadProfile(const char *name); -BOOL InitializeGame(HWND hWnd); +BOOL InitializeGame(void); diff --git a/src/SelStage.cpp b/src/SelStage.cpp index 34cbb721..6fd6339c 100644 --- a/src/SelStage.cpp +++ b/src/SelStage.cpp @@ -169,7 +169,7 @@ int StageSelectLoop(int *p_event) if (gKey & KEY_ESCAPE) { - switch (Call_Escape(ghWnd)) + switch (Call_Escape()) { case 0: return 0; diff --git a/src/Sound.cpp b/src/Sound.cpp index 11e96857..352438df 100644 --- a/src/Sound.cpp +++ b/src/Sound.cpp @@ -233,7 +233,6 @@ int MakePixToneObject(const PIXTONEPARAMETER *ptp, int ptp_num, int no) { int i; int j; - DSBUFFERDESC dsbd; const PIXTONEPARAMETER *ptp_pointer; int sample_count; unsigned char *pcm_buffer; diff --git a/src/TextScr.cpp b/src/TextScr.cpp index c8d12781..57832186 100644 --- a/src/TextScr.cpp +++ b/src/TextScr.cpp @@ -705,18 +705,10 @@ int TextScriptProc() 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 @@ int TextScriptProc() } 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 @@ int TextScriptProc() else if (IS_COMMAND('L','D','P')) { if (!LoadProfile(NULL)) - InitializeGame(ghWnd); + InitializeGame(); } else if (IS_COMMAND('F','A','C')) { @@ -1253,7 +1245,7 @@ int TextScriptProc() bExit = TRUE; z = GetTextScriptNo(gTS.p_read + 4); - switch (Scene_DownIsland(ghWnd, z)) + switch (Scene_DownIsland(z)) { case 0: return 0; diff --git a/src/WindowsWrapper.h b/src/WindowsWrapper.h index 42ea3f46..53a7af55 100644 --- a/src/WindowsWrapper.h +++ b/src/WindowsWrapper.h @@ -1,5 +1,5 @@ #pragma once - +/* #ifdef WINDOWS #include // Avoid name collisions @@ -7,13 +7,16 @@ #undef FindResource #undef CreateWindow #else - +*/ #include typedef int HWND; typedef int BOOL; +typedef unsigned char BYTE; +typedef unsigned long DWORD; + #ifndef FALSE #define FALSE 0 #endif @@ -29,7 +32,7 @@ struct RECT long right; long bottom; }; -#endif +//#endif #define SET_RECT(rect, l, t, r, b) \ rect.left = l; \