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.
This commit is contained in:
Clownacy 2019-09-04 00:27:36 +01:00
parent 5a9492166d
commit 5ea356a3bd
34 changed files with 231 additions and 787 deletions

View file

@ -44,7 +44,7 @@ ifeq ($(DEBUG_SAVE), 1)
CXXFLAGS += -DDEBUG_SAVE CXXFLAGS += -DDEBUG_SAVE
endif 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 LIBS += -lkernel32 -lgdi32 -lddraw -ldinput -ldsound -lversion -lshlwapi -limm32 -lwinmm -ldxguid
ifeq ($(STATIC), 1) ifeq ($(STATIC), 1)
@ -72,11 +72,11 @@ SOURCES = \
src/Bullet \ src/Bullet \
src/Caret \ src/Caret \
src/Config \ src/Config \
src/Dialog \
src/Draw \ src/Draw \
src/Ending \ src/Ending \
src/Escape \ src/Escape \
src/Fade \ src/Fade \
src/File \
src/Flags \ src/Flags \
src/Flash \ src/Flash \
src/Frame \ src/Frame \

View file

@ -394,7 +394,7 @@ int CampLoop()
if (gKeyTrg & KEY_ESCAPE) if (gKeyTrg & KEY_ESCAPE)
{ {
switch (Call_Escape(ghWnd)) switch (Call_Escape())
{ {
case 0: case 0:
return 0; return 0;

View file

@ -7,6 +7,7 @@
#include "CommonDefines.h" #include "CommonDefines.h"
#include "Draw.h" #include "Draw.h"
#include "File.h"
#include "Frame.h" #include "Frame.h"
#include "Game.h" #include "Game.h"
#include "Map.h" #include "Map.h"

View file

@ -6,6 +6,7 @@
#include "SDL.h" #include "SDL.h"
#include "../../Organya.h"
#include "../../WindowsWrapper.h" #include "../../WindowsWrapper.h"
#define MIN(a, b) ((a) < (b) ? (a) : (b)) #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) for (unsigned int i = 0; i < frames_total * 2; ++i)
stream[i] = 0.0f; 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) for (AudioBackend_Sound *sound = sound_list_head; sound != NULL; sound = sound->next)
{ {
if (sound->playing) if (sound->playing)

View file

@ -5,6 +5,7 @@
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
#include "Config.h" #include "Config.h"
#include "File.h"
#include "Tags.h" #include "Tags.h"
static const char* const config_filename = "Config.dat"; // Not the original name static const char* const config_filename = "Config.dat"; // Not the original name

View file

@ -1,157 +0,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;
}

View file

@ -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);

View file

@ -59,12 +59,12 @@ BOOL Flip_SystemTask(void)
return FALSE; return FALSE;
// Framerate limiter // Framerate limiter
timeNow = GetTickCount(); timeNow = SDL_GetTicks();
if (timeNow >= timePrev + FRAMERATE) if (timeNow >= timePrev + FRAMERATE)
break; break;
Sleep(1); SDL_Delay(1);
} }
if (timeNow >= timePrev + 100) 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); 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 // Comes in 00BBGGRR, goes out 00BBGGRR
return col; return col;

View file

@ -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 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 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); 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 CortBox(const RECT *rect, unsigned long col);
void CortBox2(const RECT *rect, unsigned long col, SurfaceID surf_no); void CortBox2(const RECT *rect, unsigned long col, SurfaceID surf_no);
int RestoreSurfaces(void); int RestoreSurfaces(void);

View file

@ -435,7 +435,7 @@ void CutCreditIllust()
} }
// Scene of the island falling // Scene of the island falling
int Scene_DownIsland(HWND hWnd, int mode) int Scene_DownIsland(int mode)
{ {
// Setup background // Setup background
RECT rc_frame = {(WINDOW_WIDTH - 160) / 2, (WINDOW_HEIGHT - 80) / 2, (WINDOW_WIDTH + 160) / 2, (WINDOW_HEIGHT + 80) / 2}; 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 // Escape menu
if (gKey & 0x8000) if (gKey & 0x8000)
{ {
switch (Call_Escape(hWnd)) switch (Call_Escape())
{ {
case 0: case 0:
return 0; return 0;

View file

@ -52,4 +52,4 @@ void ActionCredit_Read();
int GetScriptNumber(const char *text); int GetScriptNumber(const char *text);
void SetCreditIllust(int a); void SetCreditIllust(int a);
void CutCreditIllust(); void CutCreditIllust();
int Scene_DownIsland(HWND hWnd, int mode); int Scene_DownIsland(int mode);

View file

@ -7,7 +7,7 @@
#include "KeyControl.h" #include "KeyControl.h"
#include "Main.h" #include "Main.h"
int Call_Escape(HWND hWnd) int Call_Escape(void)
{ {
RECT rc = {0, 128, 208, 144}; RECT rc = {0, 128, 208, 144};

View file

@ -1,5 +1,3 @@
#pragma once #pragma once
#include "WindowsWrapper.h" int Call_Escape(void);
int Call_Escape(HWND hWnd);

96
src/File.cpp Normal file
View file

@ -0,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);
}

15
src/File.h Normal file
View file

@ -0,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);

View file

@ -4,6 +4,8 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "SDL.h"
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
#include "ArmsItem.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_x;
int frame_y; int frame_y;
@ -150,7 +152,7 @@ int ModeOpening(HWND hWnd)
// Escape menu // Escape menu
if (gKey & KEY_ESCAPE) if (gKey & KEY_ESCAPE)
{ {
switch (Call_Escape(ghWnd)) switch (Call_Escape())
{ {
case 0: case 0:
return 0; return 0;
@ -211,8 +213,8 @@ int ModeOpening(HWND hWnd)
++gCounter; ++gCounter;
} }
wait = GetTickCount(); wait = SDL_GetTicks();
while (GetTickCount() < wait + 500) while (SDL_GetTicks() < wait + 500)
{ {
CortBox(&grcGame, 0x000000); CortBox(&grcGame, 0x000000);
PutFramePerSecound(); PutFramePerSecound();
@ -222,7 +224,7 @@ int ModeOpening(HWND hWnd)
return 2; return 2;
} }
int ModeTitle(HWND hWnd) int ModeTitle(void)
{ {
// Set rects // Set rects
RECT rcTitle = {0, 0, 144, 40}; RECT rcTitle = {0, 0, 144, 40};
@ -360,7 +362,7 @@ int ModeTitle(HWND hWnd)
if (gKey & KEY_ESCAPE) if (gKey & KEY_ESCAPE)
{ {
switch (Call_Escape(ghWnd)) switch (Call_Escape())
{ {
case 0: case 0:
return 0; return 0;
@ -456,8 +458,8 @@ int ModeTitle(HWND hWnd)
ChangeMusic(MUS_SILENCE); ChangeMusic(MUS_SILENCE);
// Black screen when option is selected // Black screen when option is selected
wait = GetTickCount(); wait = SDL_GetTicks();
while (GetTickCount() < wait + 1000) while (SDL_GetTicks() < wait + 1000)
{ {
CortBox(&grcGame, 0); CortBox(&grcGame, 0);
PutFramePerSecound(); PutFramePerSecound();
@ -468,7 +470,7 @@ int ModeTitle(HWND hWnd)
return 3; return 3;
} }
int ModeAction(HWND hWnd) int ModeAction(void)
{ {
int frame_x; int frame_x;
int frame_y; int frame_y;
@ -506,12 +508,12 @@ int ModeAction(HWND hWnd)
if (bContinue) if (bContinue)
{ {
if (!LoadProfile(NULL) && !InitializeGame(hWnd)) // ...Shouldn't that '&&' be a '||'? if (!LoadProfile(NULL) && !InitializeGame()) // ...Shouldn't that '&&' be a '||'?
return 0; return 0;
} }
else else
{ {
if (!InitializeGame(hWnd)) if (!InitializeGame())
return 0; return 0;
} }
@ -523,7 +525,7 @@ int ModeAction(HWND hWnd)
// Escape menu // Escape menu
if (gKey & KEY_ESCAPE) if (gKey & KEY_ESCAPE)
{ {
switch (Call_Escape(ghWnd)) switch (Call_Escape())
{ {
case 0: case 0:
return 0; return 0;
@ -676,25 +678,17 @@ int ModeAction(HWND hWnd)
return 0; return 0;
} }
BOOL Game(HWND hWnd) BOOL Game(void)
{ {
int mode; int mode;
if (!LoadGenericData()) if (!LoadGenericData())
{ {
#if defined(NONPORTABLE) && defined(WINDOWS) #ifdef JAPANESE
#ifdef JAPANESE SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "エラー", "汎用ファイルが読めない", NULL);
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
#else SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "Couldn't read general purpose files", NULL);
MessageBoxA(hWnd, "Couldn't read general purpose files", "Error", MB_OK); #endif
#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
return FALSE; return FALSE;
} }
@ -706,19 +700,11 @@ BOOL Game(HWND hWnd)
if (!LoadNpcTable(path)) if (!LoadNpcTable(path))
{ {
#if defined(NONPORTABLE) && defined(WINDOWS) #ifdef JAPANESE
#ifdef JAPANESE SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "エラー", "NPCテーブルが読めない", NULL);
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
#else SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "Couldn't read the NPC table", NULL);
MessageBoxA(hWnd, "Couldn't read the NPC table", "Error", MB_OK); #endif
#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
return FALSE; return FALSE;
} }
@ -732,11 +718,11 @@ BOOL Game(HWND hWnd)
while (mode) while (mode)
{ {
if (mode == 1) if (mode == 1)
mode = ModeOpening(hWnd); mode = ModeOpening();
if (mode == 2) if (mode == 2)
mode = ModeTitle(hWnd); mode = ModeTitle();
if (mode == 3) if (mode == 3)
mode = ModeAction(hWnd); mode = ModeAction();
} }
PlaySoundObject(7, 0); PlaySoundObject(7, 0);
@ -746,8 +732,5 @@ BOOL Game(HWND hWnd)
ReleaseNpcTable(); ReleaseNpcTable();
ReleaseCreditScript(); ReleaseCreditScript();
if (!bFullscreen)
SaveWindowRect(hWnd, "window.rect");
return TRUE; return TRUE;
} }

View file

@ -8,4 +8,4 @@ extern int gCounter;
int Random(int min, int max); int Random(int min, int max);
void PutNumber4(int x, int y, int value, BOOL bZero); void PutNumber4(int x, int y, int value, BOOL bZero);
BOOL Game(HWND hWnd); BOOL Game(void);

View file

@ -36,66 +36,6 @@ void GetCompileDate(int *year, int *month, int *day)
*month = i; *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) BOOL GetCompileVersion(int *v1, int *v2, int *v3, int *v4)
{ {
*v1 = 1; *v1 = 1;
@ -104,81 +44,13 @@ BOOL GetCompileVersion(int *v1, int *v2, int *v3, int *v4)
*v4 = 6; *v4 = 6;
return TRUE; 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) void DeleteDebugLog(void)
{ {
char path[MAX_PATH]; char path[MAX_PATH];
sprintf(path, "%s\\debug.txt", gModulePath); sprintf(path, "%s/debug.txt", gModulePath);
DeleteFileA(path); remove(path);
} }
BOOL PrintDebugLog(const char *string, int value1, int value2, int value3) 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]; char path[MAX_PATH];
FILE *fp; FILE *fp;
sprintf(path, "%s\\debug.txt", gModulePath); sprintf(path, "%s/debug.txt", gModulePath);
fp = fopen(path, "a+t"); fp = fopen(path, "a+");
if (fp == NULL) if (fp == NULL)
return FALSE; return FALSE;
@ -196,48 +68,12 @@ BOOL PrintDebugLog(const char *string, int value1, int value2, int value3)
fclose(fp); fclose(fp);
return TRUE; 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) BOOL CheckFileExists(const char *name)
{ {
char path[MAX_PATH]; char path[MAX_PATH];
#ifdef NONPORTABLE
sprintf(path, "%s\\%s", gModulePath, name);
#else
sprintf(path, "%s/%s", gModulePath, name); sprintf(path, "%s/%s", gModulePath, name);
#endif
FILE *file = fopen(path, "rb"); FILE *file = fopen(path, "rb");
@ -250,20 +86,6 @@ BOOL CheckFileExists(const char *name)
long GetFileSizeLong(const char *path) 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; long len;
FILE *fp; FILE *fp;
@ -277,21 +99,19 @@ long GetFileSizeLong(const char *path)
len = ftell(fp); len = ftell(fp);
fclose(fp); fclose(fp);
return len; return len;
#endif
} }
#ifdef WINDOWS
BOOL PrintBitmapError(const char *string, int value) BOOL PrintBitmapError(const char *string, int value)
{ {
char path[MAX_PATH]; char path[MAX_PATH];
FILE *fp; 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 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) if (fp == NULL)
return FALSE; return FALSE;
@ -299,7 +119,6 @@ BOOL PrintBitmapError(const char *string, int value)
fclose(fp); fclose(fp);
return TRUE; return TRUE;
} }
#endif
BOOL IsShiftJIS(unsigned char c) BOOL IsShiftJIS(unsigned char c)
{ {
@ -312,155 +131,6 @@ BOOL IsShiftJIS(unsigned char c)
return FALSE; 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) BOOL IsEnableBitmap(const char *path)
{ {
char str[16]; char str[16];

View file

@ -4,19 +4,10 @@
void GetCompileDate(int *year, int *month, int *day); void GetCompileDate(int *year, int *month, int *day);
BOOL GetCompileVersion(int *v1, int *v2, int *v3, int *v4); BOOL GetCompileVersion(int *v1, int *v2, int *v3, int *v4);
#ifdef WINDOWS
BOOL OpenVolumeConfiguration(HWND hWnd);
void DeleteDebugLog(void); void DeleteDebugLog(void);
BOOL PrintDebugLog(const char *string, int value1, int value2, int value3); 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); BOOL CheckFileExists(const char *name);
long GetFileSizeLong(const char *path); long GetFileSizeLong(const char *path);
#ifdef WINDOWS
BOOL PrintBitmapError(const char *string, int value); BOOL PrintBitmapError(const char *string, int value);
#endif
BOOL IsShiftJIS(unsigned char c); 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); BOOL IsEnableBitmap(const char *path);

View file

@ -4,17 +4,14 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <shlwapi.h>
#include "SDL.h" #include "SDL.h"
#include "SDL_syswm.h"
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
#include "CommonDefines.h" #include "CommonDefines.h"
#include "Config.h" #include "Config.h"
#include "Dialog.h"
#include "Draw.h" #include "Draw.h"
#include "File.h"
#include "Game.h" #include "Game.h"
#include "Generic.h" #include "Generic.h"
#include "Input.h" #include "Input.h"
@ -30,16 +27,12 @@ char gDataPath[MAX_PATH];
int gJoystickButtonTable[8]; int gJoystickButtonTable[8];
HWND ghWnd;
BOOL bFullscreen; BOOL bFullscreen;
BOOL gbUseJoystick = FALSE; BOOL gbUseJoystick = FALSE;
static BOOL bFps = FALSE; static BOOL bFps = FALSE;
static BOOL bActive = TRUE; static BOOL bActive = TRUE;
static HANDLE hObject;
static HANDLE hMutex;
static int windowWidth; static int windowWidth;
static int windowHeight; static int windowHeight;
@ -71,11 +64,11 @@ unsigned long GetFramePerSecound(void)
if (need_new_base_tick) if (need_new_base_tick)
{ {
base_tick = GetTickCount(); base_tick = SDL_GetTicks();
need_new_base_tick = FALSE; need_new_base_tick = FALSE;
} }
current_tick = GetTickCount(); current_tick = SDL_GetTicks();
++current_frame; ++current_frame;
if (base_tick + 1000 <= current_tick) if (base_tick + 1000 <= current_tick)
@ -95,22 +88,16 @@ int main(int argc, char *argv[])
int i; 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 // Get executable's path
GetModuleFileNameA(NULL, gModulePath, MAX_PATH); char *base_path = SDL_GetBasePath();
PathRemoveFileSpecA(gModulePath); 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 // Get path of the data folder
strcpy(gDataPath, gModulePath); strcpy(gDataPath, gModulePath);
strcat(gDataPath, "\\data"); strcat(gDataPath, "/data");
CONFIG conf; CONFIG conf;
if (!LoadConfigData(&conf)) if (!LoadConfigData(&conf))
@ -205,9 +192,7 @@ int main(int argc, char *argv[])
SDL_Init(SDL_INIT_EVENTS); SDL_Init(SDL_INIT_EVENTS);
HWND hWnd;
SDL_Window *window; SDL_Window *window;
SDL_SysWMinfo info;
switch (conf.display_mode) switch (conf.display_mode)
{ {
@ -228,16 +213,7 @@ int main(int argc, char *argv[])
window = CreateWindow(lpWindowName, windowWidth, windowHeight); window = CreateWindow(lpWindowName, windowWidth, windowHeight);
if (window == NULL) if (window == NULL)
{
ReleaseMutex(hMutex);
return 0; return 0;
}
SDL_VERSION(&info.version);
SDL_GetWindowWMInfo(window, &info);
hWnd = info.info.win.window;
ghWnd = hWnd;
if (conf.display_mode == 1) if (conf.display_mode == 1)
StartDirectDraw(window, 0); StartDirectDraw(window, 0);
@ -256,23 +232,7 @@ int main(int argc, char *argv[])
window = CreateWindow(lpWindowName, windowWidth, windowHeight); window = CreateWindow(lpWindowName, windowWidth, windowHeight);
if (window == NULL) if (window == NULL)
{
ReleaseMutex(hMutex);
return 0; 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 // Set colour depth
int depth; int depth;
@ -303,9 +263,6 @@ int main(int argc, char *argv[])
if (CheckFileExists("fps")) if (CheckFileExists("fps"))
bFps = TRUE; bFps = TRUE;
if (!bFullscreen)
LoadWindowRect(hWnd, "window.rect", FALSE);
// Set rects // Set rects
RECT rcLoading = {0, 0, 64, 8}; RECT rcLoading = {0, 0, 64, 8};
RECT rcFull = {0, 0, 0, 0}; RECT rcFull = {0, 0, 0, 0};
@ -323,7 +280,6 @@ int main(int argc, char *argv[])
if (!Flip_SystemTask()) if (!Flip_SystemTask())
{ {
SDL_DestroyWindow(window); SDL_DestroyWindow(window);
ReleaseMutex(hMutex);
return 1; return 1;
} }
else else
@ -343,7 +299,7 @@ int main(int argc, char *argv[])
InitTriangleTable(); InitTriangleTable();
// Run game code // Run game code
Game(hWnd); Game();
// End stuff // End stuff
EndDirectSound(); EndDirectSound();
@ -351,7 +307,6 @@ int main(int argc, char *argv[])
EndDirectDraw(); EndDirectDraw();
SDL_DestroyWindow(window); SDL_DestroyWindow(window);
ReleaseMutex(hMutex);
} }
return 1; return 1;

View file

@ -2,7 +2,6 @@
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
extern HWND ghWnd;
extern BOOL bFullscreen; extern BOOL bFullscreen;
void PutFramePerSecound(void); void PutFramePerSecound(void);

View file

@ -9,6 +9,7 @@
#include "CommonDefines.h" #include "CommonDefines.h"
#include "Draw.h" #include "Draw.h"
#include "File.h"
#include "NpChar.h" #include "NpChar.h"
#include "Tags.h" #include "Tags.h"

View file

@ -94,7 +94,7 @@ int MiniMapLoop()
if (gKey & KEY_ESCAPE) if (gKey & KEY_ESCAPE)
{ {
switch (Call_Escape(ghWnd)) switch (Call_Escape())
{ {
case 0: case 0:
return 0; return 0;
@ -138,7 +138,7 @@ int MiniMapLoop()
if (gKey & KEY_ESCAPE) if (gKey & KEY_ESCAPE)
{ {
switch (Call_Escape(ghWnd)) switch (Call_Escape())
{ {
case 0: case 0:
return 0; return 0;
@ -179,7 +179,7 @@ int MiniMapLoop()
if (gKey & KEY_ESCAPE) if (gKey & KEY_ESCAPE)
{ {
switch (Call_Escape(ghWnd)) switch (Call_Escape())
{ {
case 0: case 0:
return 0; return 0;

View file

@ -8,6 +8,7 @@
#include "CommonDefines.h" #include "CommonDefines.h"
#include "Caret.h" #include "Caret.h"
#include "Draw.h" #include "Draw.h"
#include "File.h"
#include "Game.h" #include "Game.h"
#include "MyChar.h" #include "MyChar.h"
#include "NpChar.h" #include "NpChar.h"

View file

@ -9,6 +9,7 @@
#include "ArmsItem.h" #include "ArmsItem.h"
#include "Caret.h" #include "Caret.h"
#include "Draw.h" #include "Draw.h"
#include "File.h"
#include "Flags.h" #include "Flags.h"
#include "Game.h" #include "Game.h"
#include "MyChar.h" #include "MyChar.h"

View file

@ -6,6 +6,7 @@
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
#include "File.h"
#include "Generic.h" #include "Generic.h"
#include "NpcAct.h" #include "NpcAct.h"

View file

@ -8,6 +8,7 @@
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
@ -112,6 +113,8 @@ typedef struct OrgData
BOOL InitMusicData(const char *path); BOOL InitMusicData(const char *path);
} ORGDATA; } ORGDATA;
unsigned short organya_timer;
ORGDATA org_data; ORGDATA org_data;
AudioBackend_Sound *lpORGANBUFFER[8][8][2] = {NULL}; 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 // Play data
long play_p; long play_p;
NOTELIST *play_np[MAXTRACK]; NOTELIST *play_np[MAXTRACK];
@ -915,9 +807,7 @@ unsigned int GetOrganyaPosition(void)
void PlayOrganyaMusic(void) void PlayOrganyaMusic(void)
{ {
QuitMMTimer(); organya_timer = org_data.info.wait;
InitMMTimer();
StartTimer(org_data.info.wait);
} }
BOOL ChangeOrganyaVolume(signed int volume) BOOL ChangeOrganyaVolume(signed int volume)
@ -931,8 +821,7 @@ BOOL ChangeOrganyaVolume(signed int volume)
void StopOrganyaMusic() void StopOrganyaMusic()
{ {
// Stop timer organya_timer = 0;
QuitMMTimer();
// Stop notes // Stop notes
for (int i = 0; i < MAXMELODY; i++) for (int i = 0; i < MAXMELODY; i++)
@ -942,7 +831,7 @@ void StopOrganyaMusic()
memset(key_on, 0, sizeof(key_on)); memset(key_on, 0, sizeof(key_on));
memset(key_twin, 0, sizeof(key_twin)); memset(key_twin, 0, sizeof(key_twin));
Sleep(100); // Sleep(100);
} }
void SetOrganyaFadeout() void SetOrganyaFadeout()
@ -952,8 +841,7 @@ void SetOrganyaFadeout()
void EndOrganya() void EndOrganya()
{ {
// End timer organya_timer = 0;
QuitMMTimer();
// Release everything related to org // Release everything related to org
org_data.ReleaseNote(); org_data.ReleaseNote();
@ -964,3 +852,8 @@ void EndOrganya()
ReleaseOrganyaObject(i); ReleaseOrganyaObject(i);
} }
} }
void UpdateOrganya(void)
{
org_data.PlayData();
}

View file

@ -1,13 +1,13 @@
#pragma once #pragma once
#include <dsound.h>
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
#define MAXTRACK 16 #define MAXTRACK 16
#define MAXMELODY 8 #define MAXMELODY 8
#define MAXDRAM 8 #define MAXDRAM 8
extern unsigned short organya_timer;
extern BOOL g_mute[MAXTRACK]; // Used by the debug Mute menu extern BOOL g_mute[MAXTRACK]; // Used by the debug Mute menu
BOOL MakeOrganyaWave(signed char track, signed char wave_no, signed char pipi); BOOL MakeOrganyaWave(signed char track, signed char wave_no, signed char pipi);
@ -22,3 +22,4 @@ void StopOrganyaMusic();
void SetOrganyaFadeout(); void SetOrganyaFadeout();
BOOL StartOrganya(const char *wave_filename); BOOL StartOrganya(const char *wave_filename);
void EndOrganya(); void EndOrganya();
void UpdateOrganya(void);

View file

@ -9,6 +9,7 @@
#include "ArmsItem.h" #include "ArmsItem.h"
#include "BossLife.h" #include "BossLife.h"
#include "Fade.h" #include "Fade.h"
#include "File.h"
#include "Flags.h" #include "Flags.h"
#include "Frame.h" #include "Frame.h"
#include "Game.h" #include "Game.h"
@ -237,7 +238,7 @@ BOOL LoadProfile(const char *name)
return TRUE; return TRUE;
} }
BOOL InitializeGame(HWND hWnd) BOOL InitializeGame(void)
{ {
InitMyChar(); InitMyChar();
gSelectedArms = 0; gSelectedArms = 0;
@ -250,21 +251,11 @@ BOOL InitializeGame(HWND hWnd)
InitFlags(); InitFlags();
if (!TransferStage(13, 200, 10, 8)) if (!TransferStage(13, 200, 10, 8))
{ {
#if defined(NONPORTABLE) && defined(WINDOWS) #ifdef JAPANESE
#ifdef JAPANESE SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "エラー", "ステージの読み込みに失敗", NULL);
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
#else SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "Failed to load stage", NULL);
MessageBoxA(hWnd, "Failed to load stage", "Error", MB_OK); #endif
#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
return FALSE; return FALSE;
} }

View file

@ -34,4 +34,4 @@ struct PROFILE
BOOL IsProfile(); BOOL IsProfile();
BOOL SaveProfile(const char *name); BOOL SaveProfile(const char *name);
BOOL LoadProfile(const char *name); BOOL LoadProfile(const char *name);
BOOL InitializeGame(HWND hWnd); BOOL InitializeGame(void);

View file

@ -169,7 +169,7 @@ int StageSelectLoop(int *p_event)
if (gKey & KEY_ESCAPE) if (gKey & KEY_ESCAPE)
{ {
switch (Call_Escape(ghWnd)) switch (Call_Escape())
{ {
case 0: case 0:
return 0; return 0;

View file

@ -233,7 +233,6 @@ int MakePixToneObject(const PIXTONEPARAMETER *ptp, int ptp_num, int no)
{ {
int i; int i;
int j; int j;
DSBUFFERDESC dsbd;
const PIXTONEPARAMETER *ptp_pointer; const PIXTONEPARAMETER *ptp_pointer;
int sample_count; int sample_count;
unsigned char *pcm_buffer; unsigned char *pcm_buffer;

View file

@ -705,18 +705,10 @@ int TextScriptProc()
y = GetTextScriptNo(gTS.p_read + 19); y = GetTextScriptNo(gTS.p_read + 19);
if (!TransferStage(z, w, x, y)) if (!TransferStage(z, w, x, y))
{ {
#if defined(NONPORTABLE) && defined(WINDOWS) #ifdef JAPANESE
#ifdef JAPANESE SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "エラー", "ステージの読み込みに失敗", NULL);
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
#else #else
#ifdef JAPANESE SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "Failed to load stage", NULL);
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "エラー", "ステージの読み込みに失敗", NULL);
#else
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "Failed to load stage", NULL);
#endif
#endif #endif
return 0; return 0;
@ -1180,7 +1172,7 @@ int TextScriptProc()
} }
else if (IS_COMMAND('I','N','I')) else if (IS_COMMAND('I','N','I'))
{ {
InitializeGame(ghWnd); InitializeGame();
gTS.p_read += 4; gTS.p_read += 4;
} }
else if (IS_COMMAND('S','V','P')) else if (IS_COMMAND('S','V','P'))
@ -1191,7 +1183,7 @@ int TextScriptProc()
else if (IS_COMMAND('L','D','P')) else if (IS_COMMAND('L','D','P'))
{ {
if (!LoadProfile(NULL)) if (!LoadProfile(NULL))
InitializeGame(ghWnd); InitializeGame();
} }
else if (IS_COMMAND('F','A','C')) else if (IS_COMMAND('F','A','C'))
{ {
@ -1253,7 +1245,7 @@ int TextScriptProc()
bExit = TRUE; bExit = TRUE;
z = GetTextScriptNo(gTS.p_read + 4); z = GetTextScriptNo(gTS.p_read + 4);
switch (Scene_DownIsland(ghWnd, z)) switch (Scene_DownIsland(z))
{ {
case 0: case 0:
return 0; return 0;

View file

@ -1,5 +1,5 @@
#pragma once #pragma once
/*
#ifdef WINDOWS #ifdef WINDOWS
#include <windows.h> #include <windows.h>
// Avoid name collisions // Avoid name collisions
@ -7,13 +7,16 @@
#undef FindResource #undef FindResource
#undef CreateWindow #undef CreateWindow
#else #else
*/
#include <stdio.h> #include <stdio.h>
typedef int HWND; typedef int HWND;
typedef int BOOL; typedef int BOOL;
typedef unsigned char BYTE;
typedef unsigned long DWORD;
#ifndef FALSE #ifndef FALSE
#define FALSE 0 #define FALSE 0
#endif #endif
@ -29,7 +32,7 @@ struct RECT
long right; long right;
long bottom; long bottom;
}; };
#endif //#endif
#define SET_RECT(rect, l, t, r, b) \ #define SET_RECT(rect, l, t, r, b) \
rect.left = l; \ rect.left = l; \