From 5e129967d8979e84f9adb9f983cfb6ed40a5ab1c Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Tue, 7 May 2019 08:34:37 +0200 Subject: [PATCH 1/8] Changed debug flags from -O0 -g to -Og -g3 -Og is because "It is a better choice than -O0 for producing debuggable code because some compiler passes that collect debug information are disabled at -O0." and for making the code at least optimized a little bit -g3 is for adding maximum debug information (such as macro information) Signed-off-by: Gabriel Ravier --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index e727670e..6d86c2d4 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ ifeq ($(RELEASE), 1) LDFLAGS = -s FILENAME_DEF = CSE2 else - CXXFLAGS = -O0 -g + CXXFLAGS = -Og -g3 FILENAME_DEF = CSE2d endif From 9b82baeb021dfa6b49225d7410586922c1b4f532 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Mon, 13 May 2019 17:50:09 +0100 Subject: [PATCH 2/8] Made MiniMap.cpp actually ASM-accurate --- src/ArmsItem.cpp | 8 ++++---- src/Draw.cpp | 4 +++- src/Draw.h | 2 +- src/Ending.cpp | 4 ++-- src/Escape.cpp | 4 ++-- src/Escape.h | 2 +- src/Game.cpp | 16 ++++++++-------- src/Main.cpp | 3 ++- src/Main.h | 2 ++ src/MiniMap.cpp | 23 +++++++++++++---------- src/SelStage.cpp | 4 ++-- 11 files changed, 40 insertions(+), 32 deletions(-) diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index aba1bbea..61e57f67 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -129,10 +129,10 @@ BOOL AddItemData(long code) } if (i == ITEM_MAX) - return false; + return FALSE; gItemData[i].code = code; - return true; + return TRUE; } BOOL SubItemData(long code) @@ -388,7 +388,7 @@ int CampLoop() if (gKeyTrg & KEY_ESCAPE) { - switch (Call_Escape()) + switch (Call_Escape(hWnd)) { case 0: return 0; @@ -430,7 +430,7 @@ int CampLoop() } } - if (!Flip_SystemTask()) + if (!Flip_SystemTask(hWnd)) return 0; } diff --git a/src/Draw.cpp b/src/Draw.cpp index 1e1dea2f..18744f41 100644 --- a/src/Draw.cpp +++ b/src/Draw.cpp @@ -48,8 +48,10 @@ FontObject *gFont; #define FRAMERATE 20 -BOOL Flip_SystemTask() +BOOL Flip_SystemTask(int hWnd) { + (void)hWnd; + while (true) { if (!SystemTask()) diff --git a/src/Draw.h b/src/Draw.h index 9ba82618..abe3269f 100644 --- a/src/Draw.h +++ b/src/Draw.h @@ -52,7 +52,7 @@ struct SURFACE; extern SURFACE surf[SURFACE_ID_MAX]; -BOOL Flip_SystemTask(); +BOOL Flip_SystemTask(int hWnd); BOOL StartDirectDraw(int lMagnification, int lColourDepth); void EndDirectDraw(); void ReleaseSurface(int s); diff --git a/src/Ending.cpp b/src/Ending.cpp index 55949d9d..5dda8473 100644 --- a/src/Ending.cpp +++ b/src/Ending.cpp @@ -410,7 +410,7 @@ int Scene_DownIsland(int mode) // Escape menu if (gKey & 0x8000) { - int escRet = Call_Escape(); + int escRet = Call_Escape(hWnd); if (escRet == 0) return 0; if (escRet == 2) @@ -464,7 +464,7 @@ int Scene_DownIsland(int mode) // Draw window PutFramePerSecound(); - if (!Flip_SystemTask()) + if (!Flip_SystemTask(hWnd)) return 0; } diff --git a/src/Escape.cpp b/src/Escape.cpp index 99a8bdd4..bd7c80d3 100644 --- a/src/Escape.cpp +++ b/src/Escape.cpp @@ -7,7 +7,7 @@ #include "KeyControl.h" #include "Main.h" -int Call_Escape() +int Call_Escape(int hWnd) { RECT rc = {0, 128, 208, 144}; @@ -37,7 +37,7 @@ int Call_Escape() PutBitmap3(&grcFull, (WINDOW_WIDTH - 208) / 2, (WINDOW_HEIGHT - 16) / 2, &rc, SURFACE_ID_TEXT_BOX); PutFramePerSecound(); - if (!Flip_SystemTask()) + if (!Flip_SystemTask(hWnd)) { // Quit if window is closed gKeyTrg = 0; diff --git a/src/Escape.h b/src/Escape.h index b2be505f..d63213c1 100644 --- a/src/Escape.h +++ b/src/Escape.h @@ -1,3 +1,3 @@ #pragma once -int Call_Escape(); +int Call_Escape(int hWnd); diff --git a/src/Game.cpp b/src/Game.cpp index b0af8034..0a5f761c 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -141,7 +141,7 @@ int ModeOpening() // Escape menu if (gKey & KEY_ESCAPE) { - int escRet = Call_Escape(); + int escRet = Call_Escape(hWnd); if (escRet == 0) return 0; if (escRet == 2) @@ -193,7 +193,7 @@ int ModeOpening() PutTextScript(); PutFramePerSecound(); - if (!Flip_SystemTask()) + if (!Flip_SystemTask(hWnd)) return 0; ++gCounter; @@ -204,7 +204,7 @@ int ModeOpening() { CortBox(&grcGame, 0x000000); PutFramePerSecound(); - if (!Flip_SystemTask()) + if (!Flip_SystemTask(hWnd)) return 0; } return 2; @@ -335,7 +335,7 @@ int ModeTitle() if (gKey & KEY_ESCAPE) { - int escRet = Call_Escape(); + int escRet = Call_Escape(hWnd); if (escRet == 0) return 0; if (escRet == 2) @@ -420,7 +420,7 @@ int ModeTitle() PutFramePerSecound(); - if (!Flip_SystemTask()) + if (!Flip_SystemTask(hWnd)) return 0; } @@ -433,7 +433,7 @@ int ModeTitle() { CortBox(&grcGame, 0); PutFramePerSecound(); - if (!Flip_SystemTask()) + if (!Flip_SystemTask(hWnd)) return 0; } @@ -479,7 +479,7 @@ int ModeAction() // Escape menu if (gKey & KEY_ESCAPE) { - int escRet = Call_Escape(); + int escRet = Call_Escape(hWnd); if (escRet == 0) return 0; if (escRet == 2) @@ -614,7 +614,7 @@ int ModeAction() PutTextScript(); PutFramePerSecound(); - if (!Flip_SystemTask()) + if (!Flip_SystemTask(hWnd)) break; ++gCounter; } diff --git a/src/Main.cpp b/src/Main.cpp index bc136be2..d6590f6a 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -32,6 +32,7 @@ char gDataPath[PATH_LENGTH]; int gJoystickButtonTable[8]; +int hWnd; // Placeholder until we restore the WinAPI code bool gbUseJoystick = false; bool bFps = false; @@ -349,7 +350,7 @@ int main(int argc, char *argv[]) PutBitmap3(&clip_rect, (WINDOW_WIDTH - 64) / 2, (WINDOW_HEIGHT - 8) / 2, &loading_rect, SURFACE_ID_LOADING); // Draw to screen - if (Flip_SystemTask()) + if (Flip_SystemTask(hWnd)) { // Initialize sound InitDirectSound(); diff --git a/src/Main.h b/src/Main.h index 8d059ff1..793c36e6 100644 --- a/src/Main.h +++ b/src/Main.h @@ -1,4 +1,6 @@ #pragma once +extern int hWnd; + void PutFramePerSecound(); int GetFramePerSecound(); diff --git a/src/MiniMap.cpp b/src/MiniMap.cpp index 9d3800f6..d0cf5ab7 100644 --- a/src/MiniMap.cpp +++ b/src/MiniMap.cpp @@ -79,19 +79,23 @@ void WriteMiniMapLine(int line) int MiniMapLoop() { int f; + int line; + unsigned char my_wait; + + RECT rcMiniMap; + RECT rcView; RECT my_rect = {0, 57, 1, 58}; int my_x = (gMC.x / 0x200 + 8) / 16; int my_y = (gMC.y / 0x200 + 8) / 16; - RECT rcView; for (f = 0; f <= 8; f++) { GetTrg(); if (gKey & KEY_ESCAPE) { - switch (Call_Escape()) + switch (Call_Escape(hWnd)) { case 0: return 0; @@ -111,11 +115,10 @@ int MiniMapLoop() CortBox(&rcView, 0); PutFramePerSecound(); - if (!Flip_SystemTask()) + if (!Flip_SystemTask(hWnd)) return 0; } - RECT rcMiniMap; rcMiniMap.left = 0; rcMiniMap.right = gMap.width; rcMiniMap.top = 0; @@ -125,8 +128,8 @@ int MiniMapLoop() rcView.bottom = --rcView.top + gMap.length + 2; CortBox2(&rcMiniMap, 0, SURFACE_ID_MAP); - int line = 0; - unsigned char my_wait = 0; + line = 0; + my_wait = 0; while (true) { GetTrg(); @@ -136,7 +139,7 @@ int MiniMapLoop() if (gKey & KEY_ESCAPE) { - switch (Call_Escape()) + switch (Call_Escape(hWnd)) { case 0: return 0; @@ -167,7 +170,7 @@ int MiniMapLoop() PutBitmap3(&grcGame, my_x + rcView.left + 1, my_y + rcView.top + 1, &my_rect, SURFACE_ID_TEXT_BOX); PutFramePerSecound(); - if (!Flip_SystemTask()) + if (!Flip_SystemTask(hWnd)) return 0; } @@ -177,7 +180,7 @@ int MiniMapLoop() if (gKey & KEY_ESCAPE) { - switch (Call_Escape()) + switch (Call_Escape(hWnd)) { case 0: return 0; @@ -197,7 +200,7 @@ int MiniMapLoop() CortBox(&rcView, 0); PutFramePerSecound(); - if (!Flip_SystemTask()) + if (!Flip_SystemTask(hWnd)) return 0; } diff --git a/src/SelStage.cpp b/src/SelStage.cpp index 6fe62be0..25cbff45 100644 --- a/src/SelStage.cpp +++ b/src/SelStage.cpp @@ -151,7 +151,7 @@ int StageSelectLoop(int *p_event) if (gKey & KEY_ESCAPE) { - int escRet = Call_Escape(); + int escRet = Call_Escape(hWnd); if (escRet == 0) return 0; if (escRet == 2) @@ -193,7 +193,7 @@ int StageSelectLoop(int *p_event) PutFramePerSecound(); } - while (Flip_SystemTask()); + while (Flip_SystemTask(hWnd)); return 0; } From d3af5e372ff9b2d0861f700b3e5af683f8ca758a Mon Sep 17 00:00:00 2001 From: Clownacy Date: Mon, 13 May 2019 19:00:48 +0100 Subject: [PATCH 3/8] Made ArmsItem.cpp ASM-accurate --- msvc2003/devilution/comparer-config.toml | 68 ++++++++++++++++++++++++ src/ArmsItem.cpp | 23 ++++---- 2 files changed, 81 insertions(+), 10 deletions(-) diff --git a/msvc2003/devilution/comparer-config.toml b/msvc2003/devilution/comparer-config.toml index 2209efd7..e7f532c5 100644 --- a/msvc2003/devilution/comparer-config.toml +++ b/msvc2003/devilution/comparer-config.toml @@ -2,10 +2,78 @@ # = (0x401000 - PE header offset) (0x400 for VC5 linker) address_offset = 0x400000 +[[func]] +name = "ClearArmsData" +addr = 0x401000 + +[[func]] +name = "ClearItemData" +addr = 0x401030 + [[func]] name = "AddArmsData" addr = 0x401050 +[[func]] +name = "SubArmsData" +addr = 0x401160 + +[[func]] +name = "TradeArms" +addr = 0x401220 + +[[func]] +name = "AddItemData" +addr = 0x4012D0 + +[[func]] +name = "SubItemData" +addr = 0x401330 + +[[func]] +name = "MoveCampCursor" +addr = 0x4013C0 + +[[func]] +name = "PutCampObject" +addr = 0x4016F0 + +[[func]] +name = "CampLoop" +addr = 0x401D10 + +[[func]] +name = "CheckItem" +addr = 0x401F20 + +[[func]] +name = "CheckArms" +addr = 0x401F60 + +[[func]] +name = "UseArmsEnergy" +addr = 0x401FA0 + +[[func]] +name = "ChargeArmsEnergy" +addr = 0x402020 + +[[func]] +name = "FullArmsEnergy" +addr = 0x402090 + +[[func]] +name = "RotationArms" +addr = 0x4020E0 + +[[func]] +name = "RotationArmsRev" +addr = 0x402190 + +[[func]] +name = "ChangeToFirstArms" +addr = 0x402240 + [[func]] name = "InitBack" addr = 0x402270 diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index 61e57f67..e947a133 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -270,6 +270,10 @@ void MoveCampCursor() void PutCampObject() { + int i; + RECT rcArms; + RECT rcItem; + // Get rects RECT rcPer = {72, 48, 80, 56}; RECT rcNone = {80, 48, 96, 56}; @@ -284,11 +288,10 @@ void PutCampObject() RECT rcBoxBottom = {0, 16, 244, 24}; // Draw box - int y; PutBitmap3(&rcView, (WINDOW_WIDTH - 244) / 2, (WINDOW_HEIGHT - 224) / 2, &rcBoxTop, SURFACE_ID_TEXT_BOX); - for (y = 1; y < 18; y++) - PutBitmap3(&rcView, (WINDOW_WIDTH - 244) / 2, ((WINDOW_HEIGHT - 240) / 2) + (8 * (y + 1)), &rcBoxBody, SURFACE_ID_TEXT_BOX); - PutBitmap3(&rcView, (WINDOW_WIDTH - 244) / 2, ((WINDOW_HEIGHT - 240) / 2) + (8 * (y + 1)), &rcBoxBottom, SURFACE_ID_TEXT_BOX); + for (i = 1; i < 18; ++i) + PutBitmap3(&rcView, (WINDOW_WIDTH - 244) / 2, ((WINDOW_HEIGHT - 240) / 2) + (8 * (i + 1)), &rcBoxBody, SURFACE_ID_TEXT_BOX); + PutBitmap3(&rcView, (WINDOW_WIDTH - 244) / 2, ((WINDOW_HEIGHT - 240) / 2) + (8 * (i + 1)), &rcBoxBottom, SURFACE_ID_TEXT_BOX); // Move titles if (gCampTitleY > (WINDOW_HEIGHT - 208) / 2) @@ -308,12 +311,11 @@ void PutCampObject() PutBitmap3(&rcView, 40 * gSelectedArms + (WINDOW_WIDTH - 224) / 2, (WINDOW_HEIGHT / 2) - 96, &rcCur1[1], SURFACE_ID_TEXT_BOX); // Draw arms - for (int i = 0; i < ARMS_MAX; i++) + for (i = 0; i < ARMS_MAX; i++) { if (gArmsData[i].code == 0) break; - RECT rcArms; rcArms.left = 16 * (gArmsData[i].code % 16); rcArms.right = rcArms.left + 16; rcArms.top = 16 * (gArmsData[i].code / 16); @@ -343,12 +345,11 @@ void PutCampObject() else PutBitmap3(&rcView, 32 * (gSelectedItem % 6) + (WINDOW_WIDTH - 224) / 2, 16 * (gSelectedItem / 6) + (WINDOW_HEIGHT - 88) / 2, &rcCur2[1], SURFACE_ID_TEXT_BOX); - for (int i = 0; i < ITEM_MAX; i++) + for (i = 0; i < ITEM_MAX; i++) { if (gItemData[i].code == 0) break; - RECT rcItem; rcItem.left = 32 * (gItemData[i].code % 8); rcItem.right = rcItem.left + 32; rcItem.top = 16 * (gItemData[i].code / 8); @@ -360,10 +361,12 @@ void PutCampObject() int CampLoop() { + int arms_num; + char old_script_path[PATH_LENGTH]; + RECT rcView = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT}; // Load the inventory script - char old_script_path[PATH_LENGTH]; GetTextScriptPath(old_script_path); LoadTextScript2("ArmsItem.tsc"); @@ -373,7 +376,7 @@ int CampLoop() gSelectedItem = 0; // Run script - int arms_num = 0; + arms_num = 0; for (; gArmsData[arms_num].code != 0;) ++arms_num; From c9d5b3d03afbdf613f8c84f390b3646bafdaaec0 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Mon, 13 May 2019 20:43:43 +0100 Subject: [PATCH 4/8] Made Ending.cpp ASM-accurate --- msvc2003/devilution/comparer-config.toml | 64 +++++ src/ArmsItem.cpp | 4 +- src/Ending.cpp | 310 +++++++++++++---------- src/Ending.h | 6 +- src/Game.cpp | 16 +- src/Generic.cpp | 20 +- src/Generic.h | 8 +- src/Main.cpp | 4 +- src/Main.h | 2 +- src/MiniMap.cpp | 12 +- src/Profile.cpp | 6 +- src/SelStage.cpp | 4 +- src/TextScr.cpp | 5 +- 13 files changed, 287 insertions(+), 174 deletions(-) diff --git a/msvc2003/devilution/comparer-config.toml b/msvc2003/devilution/comparer-config.toml index e7f532c5..82146f47 100644 --- a/msvc2003/devilution/comparer-config.toml +++ b/msvc2003/devilution/comparer-config.toml @@ -355,6 +355,70 @@ addr = 0x40AD60 name = "DefaultConfigData" addr = 0x40AE30 +[[func]] +name = "ActionStripper" +addr = 0x40CF90 + +[[func]] +name = "PutStripper" +addr = 0x40D010 + +[[func]] +name = "SetStripper" +addr = 0x40D150 + +[[func]] +name = "RestoreStripper" +addr = 0x40D240 + +[[func]] +name = "ActionIllust" +addr = 0x40D2D0 + +[[func]] +name = "PutIllust" +addr = 0x40D350 + +[[func]] +name = "ReloadIllust" +addr = 0x40D3A0 + +[[func]] +name = "InitCreditScript" +addr = 0x40D3E0 + +[[func]] +name = "ReleaseCreditScript" +addr = 0x40D410 + +[[func]] +name = "StartCreditScript" +addr = 0x40D440 + +[[func]] +name = "ActionCredit" +addr = 0x40D5C0 + +[[func]] +name = "ActionCredit_Read" +addr = 0x40D620 + +[[func]] +name = "GetScriptNumber" +addr = 0x40DB00 + +[[func]] +name = "SetCreditIllust" +addr = 0x40DB40 + +[[func]] +name = "CutCreditIllust" +addr = 0x40DB60 + +[[func]] +name = "Scene_DownIsland" +addr = 0x40DB70 + [[func]] name = "Call_Escape" addr = 0x40DD70 diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index e947a133..2791ad00 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -391,7 +391,7 @@ int CampLoop() if (gKeyTrg & KEY_ESCAPE) { - switch (Call_Escape(hWnd)) + switch (Call_Escape(ghWnd)) { case 0: return 0; @@ -433,7 +433,7 @@ int CampLoop() } } - if (!Flip_SystemTask(hWnd)) + if (!Flip_SystemTask(ghWnd)) return 0; } diff --git a/src/Ending.cpp b/src/Ending.cpp index 5dda8473..3ab2cefd 100644 --- a/src/Ending.cpp +++ b/src/Ending.cpp @@ -39,20 +39,27 @@ void ActionStripper() // Draw casts void PutStripper() { + RECT rc; + for (int s = 0; s < MAX_STRIP; s++) { if (Strip[s].flag & 0x80) { // Draw text - RECT rc = {0, 16 * s, 320, 16 * s + 16}; - PutBitmap3(&grcFull, (Strip[s].x + ((WINDOW_WIDTH - 320) << 8)) / 0x200, Strip[s].y / 0x200, &rc, SURFACE_ID_CREDIT_CAST); + rc.left = 0; + rc.right = 320; + rc.top = s * 0x10; + rc.bottom = rc.top + 0x10; + + PutBitmap3(&grcFull, (Strip[s].x / 0x200) + ((WINDOW_WIDTH - 320) / 2), (Strip[s].y / 0x200), &rc, SURFACE_ID_CREDIT_CAST); // Draw character rc.left = 24 * (Strip[s].cast % 13); rc.right = rc.left + 24; rc.top = 24 * (Strip[s].cast / 13); rc.bottom = rc.top + 24; - PutBitmap3(&grcFull, (Strip[s].x + ((WINDOW_WIDTH - 320) << 8)) / 0x200 - 24, Strip[s].y / 0x200 - 8, &rc, SURFACE_ID_CASTS); + + PutBitmap3(&grcFull, (Strip[s].x / 0x200) + ((WINDOW_WIDTH - 320) / 2) - 24, (Strip[s].y / 0x200) - 8, &rc, SURFACE_ID_CASTS); } } } @@ -60,34 +67,47 @@ void PutStripper() // Create a cast object void SetStripper(int x, int y, const char *text, int cast) { - for (int s = 0; s < MAX_STRIP; s++) - { - if (!(Strip[s].flag & 0x80)) - { - // Initialize cast property - Strip[s].flag = 0x80; - Strip[s].x = x; - Strip[s].y = y; - Strip[s].cast = cast; - strcpy(Strip[s].str, text); + RECT rc; + int s; - // Draw text - RECT rc = {0, 16 * s, 320, 16 * s + 16}; - CortBox2(&rc, 0, SURFACE_ID_CREDIT_CAST); - PutText2(0, 16 * s, text, RGB(0xFF, 0xFF, 0xFE), SURFACE_ID_CREDIT_CAST); + for (s = 0; s < MAX_STRIP; s++) + if (!(Strip[s].flag & 0x80)) break; - } - } + + if (s == MAX_STRIP) + return; + + // Initialize cast property + Strip[s].flag = 0x80; + Strip[s].x = x; + Strip[s].y = y; + Strip[s].cast = cast; + strcpy(Strip[s].str, text); + + // Draw text + rc.left = 0; + rc.right = 320; + rc.top = s * 0x10; + rc.bottom = rc.top + 0x10; + + CortBox2(&rc, 0, SURFACE_ID_CREDIT_CAST); + PutText2(0, rc.top, text, RGB(0xFF, 0xFF, 0xFE), SURFACE_ID_CREDIT_CAST); } // Regenerate cast text void RestoreStripper() { + RECT rc; + for (int s = 0; s < MAX_STRIP; s++) { if (Strip[s].flag & 0x80) { - RECT rc = {0, 16 * s, 320, 16 * s + 16}; + rc.left = 0; + rc.right = 320; + rc.top = s * 0x10; + rc.bottom = rc.top + 0x10; + CortBox2(&rc, 0, SURFACE_ID_CREDIT_CAST); PutText2(0, rc.top, Strip[s].str, RGB(0xFF, 0xFF, 0xFE), SURFACE_ID_CREDIT_CAST); } @@ -121,8 +141,13 @@ void ActionIllust() void PutIllust() { RECT rcIllust = {0, 0, 160, 240}; +#if WINDOW_WIDTH != 320 || WINDOW_HEIGHT != 240 + // Widescreen edit RECT rcClip = {(WINDOW_WIDTH - 320) / 2, 0, WINDOW_WIDTH, WINDOW_HEIGHT}; - PutBitmap3(&rcClip, (Illust.x + ((WINDOW_WIDTH - 320) << 8)) / 0x200, (WINDOW_HEIGHT - 240) / 2, &rcIllust, SURFACE_ID_CREDITS_IMAGE); + PutBitmap3(&rcClip, (Illust.x / 0x200) + ((WINDOW_WIDTH - 320) / 2), (WINDOW_HEIGHT - 240) / 2, &rcIllust, SURFACE_ID_CREDITS_IMAGE); +#else + PutBitmap3(&grcFull, (Illust.x / 0x200) + ((WINDOW_WIDTH - 320) / 2), (WINDOW_HEIGHT - 240) / 2, &rcIllust, SURFACE_ID_CREDITS_IMAGE); +#endif } // Load illustration @@ -151,8 +176,10 @@ void ReleaseCreditScript() } } +const char *credit_script = "Credit.tsc"; + // Start playing credits -bool StartCreditScript() +BOOL StartCreditScript() { // Clear previously existing credits data if (Credit.pData) @@ -163,22 +190,22 @@ bool StartCreditScript() // Open file char path[PATH_LENGTH]; - sprintf(path, "%s/%s", gDataPath, "Credit.tsc"); + sprintf(path, "%s/%s", gDataPath, credit_script); Credit.size = GetFileSizeLong(path); if (Credit.size == -1) - return false; + return FALSE; // Allocate buffer data Credit.pData = (char*)malloc(Credit.size); if (Credit.pData == NULL) - return false; + return FALSE; FILE *fp = fopen(path, "rb"); if (fp == NULL) { - printf("Couldn't open %s", path); - return false; + free(Credit.pData); + return FALSE; } // Read data @@ -199,98 +226,97 @@ bool StartCreditScript() // Modify cliprect grcGame.left = WINDOW_WIDTH / 2; +#if WINDOW_WIDTH != 320 || WINDOW_HEIGHT != 240 // These three are non-vanilla: for wide/tallscreen support grcGame.right = ((WINDOW_WIDTH - 320) / 2) + 320; grcGame.top = (WINDOW_HEIGHT - 240) / 2; grcGame.bottom = ((WINDOW_HEIGHT - 240) / 2) + 240; +#endif // Reload casts if (!ReloadBitmap_File("casts", SURFACE_ID_CASTS)) - return false; + return FALSE; // Clear casts memset(Strip, 0, sizeof(Strip)); - return true; + return TRUE; } // Get number from text (4 digit) int GetScriptNumber(const char *text) { - return 1000 * text[0] - 48000 + - 100 * text[1] - 4800 + - 10 * text[2] - 480 + - text[3] - 48; + return (text[0] - '0') * 1000 + + (text[1] - '0') * 100 + + (text[2] - '0') * 10 + + text[3] - '0'; } // Parse credits void ActionCredit_Read() { - while (Credit.offset < Credit.size) - { - // Get character - unsigned char character = Credit.pData[Credit.offset]; + int a, b, len; + char text[40]; - int a, b, len; - switch (character) + while (1) + { + if (Credit.offset >= Credit.size) + break; + + switch (Credit.pData[Credit.offset]) { case '[': // Create cast // Get the range for the cast text - a = ++Credit.offset; + ++Credit.offset; + + a = Credit.offset; while (Credit.pData[a] != ']') { if (IsShiftJIS(Credit.pData[a])) a += 2; else - a++; + a += 1; } len = a - Credit.offset; // Copy the text to the cast text - char text[40]; - memcpy(text, &Credit.pData[Credit.offset], a - Credit.offset); + memcpy(text, &Credit.pData[Credit.offset], len); text[len] = 0; // Get cast id - Credit.offset = a + 1; - len = GetScriptNumber(&Credit.pData[a + 1]); + Credit.offset = a; + len = GetScriptNumber(&Credit.pData[++Credit.offset]); // Create cast object - SetStripper(Credit.start_x, (WINDOW_HEIGHT << 9) + 0x1000, text, len); + SetStripper(Credit.start_x, (WINDOW_HEIGHT * 0x200) + (8 * 0x200), text, len); // Change offset Credit.offset += 4; return; - case 'j': // Jump to label - // Get number - b = GetScriptNumber(&Credit.pData[++Credit.offset]); - - // Change offset + case '-': // Wait for X amount of frames + ++Credit.offset; + Credit.wait = GetScriptNumber(&Credit.pData[Credit.offset]); Credit.offset += 4; + Credit.mode = 2; + return; - // Jump to specific label - while (Credit.offset < Credit.size) - { - if (Credit.pData[Credit.offset] == 'l') - { - // What is this - a = GetScriptNumber(&Credit.pData[++Credit.offset]); - Credit.offset += 4; - if (b == a) - return; - } - else if (IsShiftJIS(Credit.pData[Credit.offset])) - { - Credit.offset += 2; - } - else - { - ++Credit.offset; - } - } + case '+': // Change casts x-position + ++Credit.offset; + Credit.start_x = GetScriptNumber(&Credit.pData[Credit.offset]) * 0x200; + Credit.offset += 4; + return; + case '/': // Stop credits + Credit.mode = 0; + return; + + case '!': // Change music + ++Credit.offset; + a = GetScriptNumber(&Credit.pData[Credit.offset]); + Credit.offset += 4; + ChangeMusic(a); return; case '~': // Start fading out music @@ -298,9 +324,46 @@ void ActionCredit_Read() SetOrganyaFadeout(); return; + case 'j': // Jump to label + ++Credit.offset; + + // Get number + b = GetScriptNumber(&Credit.pData[Credit.offset]); + + // Change offset + Credit.offset += 4; + + // Jump to specific label + if (1) + { + while (Credit.offset < Credit.size) + { + if (Credit.pData[Credit.offset] == 'l') + { + // What is this + a = GetScriptNumber(&Credit.pData[++Credit.offset]); + Credit.offset += 4; + if (b == a) + break; + } + else if (IsShiftJIS(Credit.pData[Credit.offset])) + { + Credit.offset += 2; + } + else + { + ++Credit.offset; + } + } + } + + return; + case 'f': // Flag jump + ++Credit.offset; + // Read numbers XXXX:YYYY - a = GetScriptNumber(&Credit.pData[++Credit.offset]); + a = GetScriptNumber(&Credit.pData[Credit.offset]); Credit.offset += 5; b = GetScriptNumber(&Credit.pData[Credit.offset]); Credit.offset += 4; @@ -316,7 +379,7 @@ void ActionCredit_Read() a = GetScriptNumber(&Credit.pData[++Credit.offset]); Credit.offset += 4; if (b == a) - return; + break; } else if (IsShiftJIS(Credit.pData[Credit.offset])) { @@ -330,47 +393,30 @@ void ActionCredit_Read() } return; - case '+': // Change casts x-position - Credit.start_x = GetScriptNumber(&Credit.pData[++Credit.offset]) << 9; - Credit.offset += 4; - return; - - case '-': // Wait for X amount of frames - Credit.wait = GetScriptNumber(&Credit.pData[++Credit.offset]); - Credit.offset += 4; - Credit.mode = 2; - return; - - case '/': // Stop credits - Credit.mode = 0; - return; - - case '!': // Change music - a = GetScriptNumber(&Credit.pData[++Credit.offset]); - Credit.offset += 4; - ChangeMusic(a); - return; + default: + // Progress through file + ++Credit.offset; + break; } - - // Progress through file - ++Credit.offset; } } // Update credits void ActionCredit() { - if (Credit.offset < Credit.size) + if (Credit.offset >= Credit.size) + return; + + // Update script, or if waiting, decrement the wait value + switch (Credit.mode) { - // Update script, or if waiting, decrement the wait value - if (Credit.mode == 1) - { + case 1: ActionCredit_Read(); - } - else if (Credit.mode == 2 && --Credit.wait <= 0) - { - Credit.mode = 1; - } + break; + + case 2: + if (--Credit.wait <= 0) + Credit.mode = 1; } } @@ -388,7 +434,7 @@ void CutCreditIllust() } // Scene of the island falling -int Scene_DownIsland(int mode) +int Scene_DownIsland(int hWnd, int mode) { // Setup background RECT rc_frame = {(WINDOW_WIDTH - 160) / 2, (WINDOW_HEIGHT - 80) / 2, (WINDOW_WIDTH + 160) / 2, (WINDOW_HEIGHT + 80) / 2}; @@ -410,11 +456,13 @@ int Scene_DownIsland(int mode) // Escape menu if (gKey & 0x8000) { - int escRet = Call_Escape(hWnd); - if (escRet == 0) - return 0; - if (escRet == 2) - return 2; + switch (Call_Escape(hWnd)) + { + case 0: + return 0; + case 2: + return 2; + } } switch (mode) @@ -425,33 +473,27 @@ int Scene_DownIsland(int mode) break; case 1: - if (wait >= 350) - { - if (wait >= 500) - { - if (wait >= 600) - { - // End scene - if (wait == 750) - wait = 900; - } - else - { - // Move down slow - sprite.y += 0xC; - } - } - else - { - // Move down slower - sprite.y += 0x19; - } - } - else + if (wait < 350) { // Move down at normal speed sprite.y += 0x33; } + else if (wait < 500) + { + // Move down slower + sprite.y += 0x19; + } + else if (wait < 600) + { + // Move down slow + sprite.y += 0xC; + } + else if (wait == 750) + { + // End scene + wait = 900; + } + break; } diff --git a/src/Ending.h b/src/Ending.h index 3c38ae2b..4a745ce4 100644 --- a/src/Ending.h +++ b/src/Ending.h @@ -1,5 +1,7 @@ #pragma once +#include "WindowsWrapper.h" + struct CREDIT { int size; @@ -42,8 +44,8 @@ void PutIllust(); void ReloadIllust(int a); void InitCreditScript(); void ReleaseCreditScript(); -bool StartCreditScript(); +BOOL StartCreditScript(); void ActionCredit(); void SetCreditIllust(int a); void CutCreditIllust(); -int Scene_DownIsland(int mode); +int Scene_DownIsland(int hWnd, int mode); diff --git a/src/Game.cpp b/src/Game.cpp index 0a5f761c..82b5aa36 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -141,7 +141,7 @@ int ModeOpening() // Escape menu if (gKey & KEY_ESCAPE) { - int escRet = Call_Escape(hWnd); + int escRet = Call_Escape(ghWnd); if (escRet == 0) return 0; if (escRet == 2) @@ -193,7 +193,7 @@ int ModeOpening() PutTextScript(); PutFramePerSecound(); - if (!Flip_SystemTask(hWnd)) + if (!Flip_SystemTask(ghWnd)) return 0; ++gCounter; @@ -204,7 +204,7 @@ int ModeOpening() { CortBox(&grcGame, 0x000000); PutFramePerSecound(); - if (!Flip_SystemTask(hWnd)) + if (!Flip_SystemTask(ghWnd)) return 0; } return 2; @@ -335,7 +335,7 @@ int ModeTitle() if (gKey & KEY_ESCAPE) { - int escRet = Call_Escape(hWnd); + int escRet = Call_Escape(ghWnd); if (escRet == 0) return 0; if (escRet == 2) @@ -420,7 +420,7 @@ int ModeTitle() PutFramePerSecound(); - if (!Flip_SystemTask(hWnd)) + if (!Flip_SystemTask(ghWnd)) return 0; } @@ -433,7 +433,7 @@ int ModeTitle() { CortBox(&grcGame, 0); PutFramePerSecound(); - if (!Flip_SystemTask(hWnd)) + if (!Flip_SystemTask(ghWnd)) return 0; } @@ -479,7 +479,7 @@ int ModeAction() // Escape menu if (gKey & KEY_ESCAPE) { - int escRet = Call_Escape(hWnd); + int escRet = Call_Escape(ghWnd); if (escRet == 0) return 0; if (escRet == 2) @@ -614,7 +614,7 @@ int ModeAction() PutTextScript(); PutFramePerSecound(); - if (!Flip_SystemTask(hWnd)) + if (!Flip_SystemTask(ghWnd)) break; ++gCounter; } diff --git a/src/Generic.cpp b/src/Generic.cpp index b996ade8..72873bd4 100644 --- a/src/Generic.cpp +++ b/src/Generic.cpp @@ -2,16 +2,18 @@ #include +#include "WindowsWrapper.h" + #include "CommonDefines.h" #include "Tags.h" -bool GetCompileVersion(int *v1, int *v2, int *v3, int *v4) +BOOL GetCompileVersion(int *v1, int *v2, int *v3, int *v4) { *v1 = 1; *v2 = 0; *v3 = 0; *v4 = 6; - return true; + return TRUE; } long GetFileSizeLong(const char *path) @@ -29,7 +31,7 @@ long GetFileSizeLong(const char *path) return len; } -bool CheckFileExists(const char *name) +BOOL CheckFileExists(const char *name) { char path[PATH_LENGTH]; sprintf(path, "%s/%s", gModulePath, name); @@ -38,17 +40,17 @@ bool CheckFileExists(const char *name) if (file) { fclose(file); - return true; + return TRUE; } - return false; + return FALSE; } -bool IsShiftJIS(unsigned char c) +BOOL IsShiftJIS(unsigned char c) { if (c > 0x80 && c < 0xA0) - return true; + return TRUE; if (c < 0xE0 || c >= 0xF0) - return false; - return true; + return FALSE; + return TRUE; } diff --git a/src/Generic.h b/src/Generic.h index 175df9a4..191b38d7 100644 --- a/src/Generic.h +++ b/src/Generic.h @@ -1,6 +1,8 @@ #pragma once -bool GetCompileVersion(int *v1, int *v2, int *v3, int *v4); +#include "WindowsWrapper.h" + +BOOL GetCompileVersion(int *v1, int *v2, int *v3, int *v4); long GetFileSizeLong(const char *path); -bool CheckFileExists(const char *name); -bool IsShiftJIS(unsigned char c); +BOOL CheckFileExists(const char *name); +BOOL IsShiftJIS(unsigned char c); diff --git a/src/Main.cpp b/src/Main.cpp index d6590f6a..02c28b53 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -32,7 +32,7 @@ char gDataPath[PATH_LENGTH]; int gJoystickButtonTable[8]; -int hWnd; // Placeholder until we restore the WinAPI code +int ghWnd; // Placeholder until we restore the WinAPI code bool gbUseJoystick = false; bool bFps = false; @@ -350,7 +350,7 @@ int main(int argc, char *argv[]) PutBitmap3(&clip_rect, (WINDOW_WIDTH - 64) / 2, (WINDOW_HEIGHT - 8) / 2, &loading_rect, SURFACE_ID_LOADING); // Draw to screen - if (Flip_SystemTask(hWnd)) + if (Flip_SystemTask(ghWnd)) { // Initialize sound InitDirectSound(); diff --git a/src/Main.h b/src/Main.h index 793c36e6..4213ccfe 100644 --- a/src/Main.h +++ b/src/Main.h @@ -1,6 +1,6 @@ #pragma once -extern int hWnd; +extern int ghWnd; void PutFramePerSecound(); int GetFramePerSecound(); diff --git a/src/MiniMap.cpp b/src/MiniMap.cpp index d0cf5ab7..6759886f 100644 --- a/src/MiniMap.cpp +++ b/src/MiniMap.cpp @@ -95,7 +95,7 @@ int MiniMapLoop() if (gKey & KEY_ESCAPE) { - switch (Call_Escape(hWnd)) + switch (Call_Escape(ghWnd)) { case 0: return 0; @@ -115,7 +115,7 @@ int MiniMapLoop() CortBox(&rcView, 0); PutFramePerSecound(); - if (!Flip_SystemTask(hWnd)) + if (!Flip_SystemTask(ghWnd)) return 0; } @@ -139,7 +139,7 @@ int MiniMapLoop() if (gKey & KEY_ESCAPE) { - switch (Call_Escape(hWnd)) + switch (Call_Escape(ghWnd)) { case 0: return 0; @@ -170,7 +170,7 @@ int MiniMapLoop() PutBitmap3(&grcGame, my_x + rcView.left + 1, my_y + rcView.top + 1, &my_rect, SURFACE_ID_TEXT_BOX); PutFramePerSecound(); - if (!Flip_SystemTask(hWnd)) + if (!Flip_SystemTask(ghWnd)) return 0; } @@ -180,7 +180,7 @@ int MiniMapLoop() if (gKey & KEY_ESCAPE) { - switch (Call_Escape(hWnd)) + switch (Call_Escape(ghWnd)) { case 0: return 0; @@ -200,7 +200,7 @@ int MiniMapLoop() CortBox(&rcView, 0); PutFramePerSecound(); - if (!Flip_SystemTask(hWnd)) + if (!Flip_SystemTask(ghWnd)) return 0; } diff --git a/src/Profile.cpp b/src/Profile.cpp index 56d63925..07d8e4ae 100644 --- a/src/Profile.cpp +++ b/src/Profile.cpp @@ -254,12 +254,12 @@ BOOL InitializeGame() InitFlags(); if (!TransferStage(13, 200, 10, 8)) { - // TODO - restore this when hWnd is available + // TODO - restore this when ghWnd is available /*#if defined(NONPORTABLE) && defined(WINDOWS) #ifdef JAPANESE - MessageBoxA(hWnd, "ステージの読み込みに失敗", "エラー", MB_OK); + MessageBoxA(ghWnd, "ステージの読み込みに失敗", "エラー", MB_OK); #else - MessageBoxA(hWnd, "Failed to load stage", "Error", MB_OK); + MessageBoxA(ghWnd, "Failed to load stage", "Error", MB_OK); #endif #else*/ #ifdef JAPANESE diff --git a/src/SelStage.cpp b/src/SelStage.cpp index 25cbff45..35d5c2d4 100644 --- a/src/SelStage.cpp +++ b/src/SelStage.cpp @@ -151,7 +151,7 @@ int StageSelectLoop(int *p_event) if (gKey & KEY_ESCAPE) { - int escRet = Call_Escape(hWnd); + int escRet = Call_Escape(ghWnd); if (escRet == 0) return 0; if (escRet == 2) @@ -193,7 +193,7 @@ int StageSelectLoop(int *p_event) PutFramePerSecound(); } - while (Flip_SystemTask(hWnd)); + while (Flip_SystemTask(ghWnd)); return 0; } diff --git a/src/TextScr.cpp b/src/TextScr.cpp index ab8dc9a8..b5a7bad7 100644 --- a/src/TextScr.cpp +++ b/src/TextScr.cpp @@ -21,6 +21,7 @@ #include "Game.h" #include "Generic.h" #include "KeyControl.h" +#include "Main.h" #include "Map.h" #include "MapName.h" #include "MiniMap.h" @@ -682,7 +683,7 @@ int TextScriptProc() SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "Failed to load stage", NULL); #endif - //MessageBoxA(hWnd, "ステージの読み込みに失敗", "エラー", 0); + //MessageBoxA(ghWnd, "ステージの読み込みに失敗", "エラー", 0); return 0; } } @@ -1207,7 +1208,7 @@ int TextScriptProc() bExit = TRUE; z = GetTextScriptNo(gTS.p_read + 4); - switch (Scene_DownIsland(z)) + switch (Scene_DownIsland(ghWnd, z)) { case 0: return 0; From e1d3898d59b4759efb4a04395d0f00c0786c910f Mon Sep 17 00:00:00 2001 From: Clownacy Date: Mon, 13 May 2019 21:31:14 +0100 Subject: [PATCH 5/8] Made SelStage.cpp ASM-accurate --- msvc2003/devilution/comparer-config.toml | 24 ++++ src/SelStage.cpp | 154 +++++++++++++---------- src/SelStage.h | 6 +- 3 files changed, 116 insertions(+), 68 deletions(-) diff --git a/msvc2003/devilution/comparer-config.toml b/msvc2003/devilution/comparer-config.toml index 82146f47..6225ee1b 100644 --- a/msvc2003/devilution/comparer-config.toml +++ b/msvc2003/devilution/comparer-config.toml @@ -962,6 +962,30 @@ addr = 0x41D260 name = "InitializeGame" addr = 0x41D550 +[[func]] +name = "ClearPermitStage" +addr = 0x41D610 + +[[func]] +name = "AddPermitStage" +addr = 0x41D630 + +[[func]] +name = "SubPermitStage" +addr = 0x41D6A0 + +[[func]] +name = "MoveStageSelectCursor" +addr = 0x41D740 + +[[func]] +name = "PutStageSelectObject" +addr = 0x41D840 + +[[func]] +name = "StageSelectLoop" +addr = 0x41DA00 + [[func]] name = "ShootBullet_Frontia1" addr = 0x41DBD0 diff --git a/src/SelStage.cpp b/src/SelStage.cpp index 35d5c2d4..1664e6eb 100644 --- a/src/SelStage.cpp +++ b/src/SelStage.cpp @@ -21,73 +21,82 @@ void ClearPermitStage(void) memset(gPermitStage, 0, 0x40); } -bool AddPermitStage(int index, int event) +BOOL AddPermitStage(int index, int event) { - for (int i = 0; i < 8; ++i) + int i = 0; + while (i < 8) { - if (gPermitStage[i].index == 0 || gPermitStage[i].index == index) - { - gPermitStage[i].index = index; - gPermitStage[i].event = event; - return true; - } + if (gPermitStage[i].index == index) + break; + + if (gPermitStage[i].index == 0) + break; + + ++i; } - return false; + if (i == 8) + return FALSE; + + gPermitStage[i].index = index; + gPermitStage[i].event = event; + + return TRUE; } -bool SubPermitStage(int index) +BOOL SubPermitStage(int index) { int i; - for (i = 0; i < 8 && gPermitStage[i].index != index; ++i); + for (i = 0; i < 8; ++i) + if (gPermitStage[i].index == index) + break; #ifdef FIX_BUGS - if (i != 8) + if (i == 8) #else - if (i != 32) + if (i == 32) #endif + return FALSE; + + for (i += 1; i < 8; ++i) { - int ia; - for (ia = i + 1; ia < 8; ++ia) - { - gPermitStage[ia - 1].index = gPermitStage[ia].index; - gPermitStage[ia - 1].event = gPermitStage[ia].event; - } - - gPermitStage[ia - 1].index = 0; - gPermitStage[ia - 1].event = 0; - - return true; + gPermitStage[i - 1] = gPermitStage[i]; } - return false; + gPermitStage[i - 1].index = 0; + gPermitStage[i - 1].event = 0; + + return TRUE; } void MoveStageSelectCursor(void) { - int stage_num; - for (stage_num = 0; gPermitStage[stage_num].index != 0; ++stage_num); + int stage_num = 0; + while (gPermitStage[stage_num].index != 0) + ++stage_num; - if (stage_num) - { - if (gKeyTrg & gKeyLeft) - --gSelectedStage; + int stage_x = (WINDOW_WIDTH - 40 * stage_num) / 2; // Unused - if (gKeyTrg & gKeyRight) - ++gSelectedStage; + if (stage_num == 0) + return; - if (gSelectedStage < 0) - gSelectedStage = stage_num - 1; + if (gKeyTrg & gKeyLeft) + --gSelectedStage; - if (stage_num - 1 < gSelectedStage) - gSelectedStage = 0; + if (gKeyTrg & gKeyRight) + ++gSelectedStage; - if ((gKeyRight | gKeyLeft) & gKeyTrg) - StartTextScript(gPermitStage[gSelectedStage].index + 1000); + if (gSelectedStage < 0) + gSelectedStage = stage_num - 1; - if ((gKeyRight | gKeyLeft) & gKeyTrg) - PlaySoundObject(1, 1); - } + if (gSelectedStage > stage_num - 1) + gSelectedStage = 0; + + if ((gKeyLeft | gKeyRight) & gKeyTrg) + StartTextScript(gPermitStage[gSelectedStage].index + 1000); + + if ((gKeyLeft | gKeyRight) & gKeyTrg) + PlaySoundObject(1, 1); } void PutStageSelectObject(void) @@ -103,25 +112,33 @@ void PutStageSelectObject(void) RECT rcTitle1 = {80, 64, 144, 72}; + int i; + int stage_num; + int stage_x; + RECT rcStage; + if (gStageSelectTitleY > (WINDOW_HEIGHT / 2) - 74) --gStageSelectTitleY; PutBitmap3(&rcView, (WINDOW_WIDTH / 2) - 32, gStageSelectTitleY, &rcTitle1, SURFACE_ID_TEXT_BOX); - int stage_num; - for (stage_num = 0; gPermitStage[stage_num].index; ++stage_num); + stage_num = 0; + while (gPermitStage[stage_num].index) + ++stage_num; ++flash; if (stage_num) { - int stage_x = (WINDOW_WIDTH - 40 * stage_num) / 2; + stage_x = (WINDOW_WIDTH - 40 * stage_num) / 2; PutBitmap3(&rcView, stage_x + 40 * gSelectedStage, (WINDOW_HEIGHT / 2) - 56, &rcCur[(flash >> 1) % 2], SURFACE_ID_TEXT_BOX); - for (int i = 0; i < 8 && gPermitStage[i].index; ++i) + for (i = 0; i < 8; ++i) { - RECT rcStage; + if (gPermitStage[i].index == 0) + break; + rcStage.left = 32 * (gPermitStage[i].index % 8); rcStage.right = rcStage.left + 32; rcStage.top = 16 * (gPermitStage[i].index / 8); @@ -145,26 +162,30 @@ int StageSelectLoop(int *p_event) gStageSelectTitleY = (WINDOW_HEIGHT / 2) - 66; StartTextScript(gPermitStage[gSelectedStage].index + 1000); - do + for (;;) { GetTrg(); if (gKey & KEY_ESCAPE) { - int escRet = Call_Escape(ghWnd); - if (escRet == 0) - return 0; - if (escRet == 2) - return 2; + switch (Call_Escape(ghWnd)) + { + case 0: + return 0; + case 2: + return 2; + } } MoveStageSelectCursor(); - int tscRet = TextScriptProc(); - if (tscRet == 0) - return 0; - if (tscRet == 2) - return 2; + switch (TextScriptProc()) + { + case 0: + return 0; + case 2: + return 2; + } #ifdef FIX_BUGS PutBitmap4(&rcView, 0, 0, &rcView, SURFACE_ID_SCREEN_GRAB); @@ -178,12 +199,9 @@ int StageSelectLoop(int *p_event) if (gKeyTrg & gKeyOk) { StopTextScript(); - LoadTextScript_Stage(old_script_path); - *p_event = gPermitStage[gSelectedStage].event; - return 1; + break; } - - if (gKeyTrg & gKeyCancel) + else if (gKeyTrg & gKeyCancel) { StopTextScript(); LoadTextScript_Stage(old_script_path); @@ -192,8 +210,12 @@ int StageSelectLoop(int *p_event) } PutFramePerSecound(); - } - while (Flip_SystemTask(ghWnd)); - return 0; + if (!Flip_SystemTask(ghWnd)) + return 0; + } + + LoadTextScript_Stage(old_script_path); + *p_event = gPermitStage[gSelectedStage].event; + return 1; } diff --git a/src/SelStage.h b/src/SelStage.h index 7a2000bd..419b94b7 100644 --- a/src/SelStage.h +++ b/src/SelStage.h @@ -1,5 +1,7 @@ #pragma once +#include "WindowsWrapper.h" + struct PERMIT_STAGE { int index; @@ -9,8 +11,8 @@ struct PERMIT_STAGE extern PERMIT_STAGE gPermitStage[8]; void ClearPermitStage(void); -bool AddPermitStage(int index, int event); -bool SubPermitStage(int index); +BOOL AddPermitStage(int index, int event); +BOOL SubPermitStage(int index); void MoveStageSelectCursor(void); void PutStageSelectObject(void); int StageSelectLoop(int *p_event); From d5dd2c9575fdf08192b78a0f6a55931bb7d02339 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Mon, 13 May 2019 23:51:11 +0100 Subject: [PATCH 6/8] Made TextScr.cpp almost ASM-accurate TextScriptProc is all that's left, but it's being a pain, so I'm commiting this now, and dealing with the straggler later. --- msvc2003/devilution/comparer-config.toml | 56 ++++++++++++++ src/Draw.cpp | 6 +- src/Draw.h | 2 +- src/GenericLoad.cpp | 20 ++--- src/TextScr.cpp | 93 ++++++++++++++---------- src/TextScr.h | 2 +- 6 files changed, 126 insertions(+), 53 deletions(-) diff --git a/msvc2003/devilution/comparer-config.toml b/msvc2003/devilution/comparer-config.toml index 6225ee1b..e5ca6738 100644 --- a/msvc2003/devilution/comparer-config.toml +++ b/msvc2003/devilution/comparer-config.toml @@ -1062,6 +1062,62 @@ addr = 0x421040 name = "PutStar" addr = 0x4213B0 +[[func]] +name = "InitTextScript2" +addr = 0x4214E0 + +[[func]] +name = "EndTextScript" +addr = 0x421570 + +[[func]] +name = "EncryptionBinaryData2" +addr = 0x4215C0 + +[[func]] +name = "LoadTextScript2" +addr = 0x421660 + +[[func]] +name = "LoadTextScript_Stage" +addr = 0x421750 + +[[func]] +name = "GetTextScriptPath" +addr = 0x4218E0 + +[[func]] +name = "GetTextScriptNo" +addr = 0x421900 + +[[func]] +name = "StartTextScript" +addr = 0x421990 + +[[func]] +name = "JumpTextScript" +addr = 0x421AF0 + +[[func]] +name = "StopTextScript" +addr = 0x421C50 + +[[func]] +name = "CheckNewLine" +addr = 0x421C80 + +[[func]] +name = "SetNumberTextScript" +addr = 0x421D10 + +[[func]] +name = "ClearTextLine" +addr = 0x421E90 + +[[func]] +name = "PutTextScript" +addr = 0x421F10 + [[func]] name = "TextScriptProc" addr = 0x422510 diff --git a/src/Draw.cpp b/src/Draw.cpp index 18744f41..44c28157 100644 --- a/src/Draw.cpp +++ b/src/Draw.cpp @@ -153,8 +153,10 @@ void ReleaseSurface(int s) } } -BOOL MakeSurface_Generic(int bxsize, int bysize, Surface_Ids surf_no) +BOOL MakeSurface_Generic(int bxsize, int bysize, Surface_Ids surf_no, BOOL bSystem) { + (void)bSystem; + BOOL success = FALSE; #ifdef FIX_BUGS @@ -253,7 +255,7 @@ static bool LoadBitmap(SDL_RWops *fp, Surface_Ids surf_no, bool create_surface) } else { - if (create_surface == false || MakeSurface_Generic(surface->w, surface->h, surf_no)) + if (create_surface == false || MakeSurface_Generic(surface->w, surface->h, surf_no, FALSE)) { if (magnification == 1) { diff --git a/src/Draw.h b/src/Draw.h index abe3269f..4542f4b9 100644 --- a/src/Draw.h +++ b/src/Draw.h @@ -60,7 +60,7 @@ BOOL MakeSurface_File(const char *name, Surface_Ids surf_no); BOOL MakeSurface_Resource(const char *res, Surface_Ids surf_no); BOOL ReloadBitmap_File(const char *name, Surface_Ids surf_no); BOOL ReloadBitmap_Resource(const char *res, Surface_Ids surf_no); -BOOL MakeSurface_Generic(int bxsize, int bysize, Surface_Ids surf_no); +BOOL MakeSurface_Generic(int bxsize, int bysize, Surface_Ids surf_no, BOOL bSystem); void BackupSurface(Surface_Ids surf_no, RECT *rect); void PutBitmap3(RECT *rcView, int x, int y, RECT *rect, Surface_Ids surf_no); void PutBitmap4(RECT *rcView, int x, int y, RECT *rect, Surface_Ids surf_no); diff --git a/src/GenericLoad.cpp b/src/GenericLoad.cpp index d9d4eb58..eb22e3e6 100644 --- a/src/GenericLoad.cpp +++ b/src/GenericLoad.cpp @@ -197,16 +197,16 @@ BOOL LoadGenericData() } else { - MakeSurface_Generic(WINDOW_WIDTH, WINDOW_HEIGHT, SURFACE_ID_SCREEN_GRAB); - MakeSurface_Generic(WINDOW_WIDTH, WINDOW_HEIGHT, SURFACE_ID_LEVEL_BACKGROUND); - MakeSurface_Generic(WINDOW_WIDTH, WINDOW_HEIGHT, SURFACE_ID_MAP); - MakeSurface_Generic(WINDOW_WIDTH, WINDOW_HEIGHT, SURFACE_ID_CASTS); - MakeSurface_Generic(256, 256, SURFACE_ID_LEVEL_TILESET); - MakeSurface_Generic(160, 16, SURFACE_ID_ROOM_NAME); - MakeSurface_Generic(40, 240, SURFACE_ID_VALUE_VIEW); - MakeSurface_Generic(320, 240, SURFACE_ID_LEVEL_SPRITESET_1); - MakeSurface_Generic(320, 240, SURFACE_ID_LEVEL_SPRITESET_2); - MakeSurface_Generic(WINDOW_WIDTH, 16 * MAX_STRIP, SURFACE_ID_CREDIT_CAST); + MakeSurface_Generic(WINDOW_WIDTH, WINDOW_HEIGHT, SURFACE_ID_SCREEN_GRAB, TRUE); + MakeSurface_Generic(WINDOW_WIDTH, WINDOW_HEIGHT, SURFACE_ID_LEVEL_BACKGROUND, FALSE); + MakeSurface_Generic(WINDOW_WIDTH, WINDOW_HEIGHT, SURFACE_ID_MAP, TRUE); + MakeSurface_Generic(WINDOW_WIDTH, WINDOW_HEIGHT, SURFACE_ID_CASTS, FALSE); + MakeSurface_Generic(256, 256, SURFACE_ID_LEVEL_TILESET, FALSE); + MakeSurface_Generic(160, 16, SURFACE_ID_ROOM_NAME, FALSE); + MakeSurface_Generic(40, 240, SURFACE_ID_VALUE_VIEW, FALSE); + MakeSurface_Generic(320, 240, SURFACE_ID_LEVEL_SPRITESET_1, FALSE); + MakeSurface_Generic(320, 240, SURFACE_ID_LEVEL_SPRITESET_2, FALSE); + MakeSurface_Generic(WINDOW_WIDTH, 16 * MAX_STRIP, SURFACE_ID_CREDIT_CAST, FALSE); pt_size = 0; pt_size += MakePixToneObject(&gPtpTable[0], 2, 32); diff --git a/src/TextScr.cpp b/src/TextScr.cpp index b5a7bad7..e4f2f112 100644 --- a/src/TextScr.cpp +++ b/src/TextScr.cpp @@ -65,7 +65,7 @@ BOOL InitTextScript2() //Create line surfaces for (int i = 0; i < 4; i++) - MakeSurface_Generic(gRect_line.right, gRect_line.bottom, (Surface_Ids)(i + SURFACE_ID_TEXT_LINE1)); + MakeSurface_Generic(gRect_line.right, gRect_line.bottom, (Surface_Ids)(i + SURFACE_ID_TEXT_LINE1), FALSE); //Clear text memset(text, 0, sizeof(text)); @@ -94,6 +94,8 @@ void EndTextScript() void EncryptionBinaryData2(unsigned char *pData, int size) { int val1; + int work; + int i; int half = size / 2; if (pData[half] == 0) @@ -101,9 +103,9 @@ void EncryptionBinaryData2(unsigned char *pData, int size) else val1 = (pData[half] % 256) * -1; - for (int i = 0; i < size; i++) + for (i = 0; i < size; i++) { - int work = pData[i]; + work = pData[i]; work += val1; if (i != half) @@ -220,7 +222,7 @@ BOOL StartTextScript(int no) gTS.rcText.left = TEXT_LEFT; gTS.rcText.top = WINDOW_HEIGHT - 56; - gTS.rcText.right = WINDOW_WIDTH + 108; + gTS.rcText.right = WINDOW_WIDTH - TEXT_LEFT; gTS.rcText.bottom = gTS.rcText.top + 48; /* This is present in the Linux port, but not the Windows version (1.0.0.6, at least) @@ -337,6 +339,13 @@ void CheckNewLine() //Type a number into the text buffer void SetNumberTextScript(int index) { + int a; + int b; + int i; + BOOL bZero; + int offset; + char str[5]; + //Get digit table int table[3]; table[0] = 1000; @@ -344,15 +353,13 @@ void SetNumberTextScript(int index) table[2] = 10; //Get number to print - int a = gNumberTextScript[index]; - int b; + a = gNumberTextScript[index]; - char str[5]; - BOOL bZero = false; - int offset = 0; + bZero = FALSE; + offset = 0; //Trim leading zeroes - for (int i = 0; i < 3; i++) + for (i = 0; i < 3; i++) { if (a / table[i] || bZero != FALSE) { @@ -365,7 +372,7 @@ void SetNumberTextScript(int index) } //Set last digit of string, and add null terminator - str[offset] = a + '0'; + str[offset] = (char)a + '0'; str[offset + 1] = 0; //Append number to line @@ -405,6 +412,18 @@ void ClearTextLine() //Draw textbox and whatever else void PutTextScript() { + RECT rcFace; + RECT rcItemBox1; + RECT rcItemBox2; + RECT rcItemBox3; + RECT rcItemBox4; + RECT rcItemBox5; + int i; + RECT rect_yesno; + RECT rect_cur; + RECT rect; + int text_offset; + if (gTS.mode == 0) return; @@ -431,14 +450,12 @@ void PutTextScript() RECT rcFrame3 = {0, 16, 244, 24}; PutBitmap3(&grcFull, WINDOW_WIDTH / 2 - 122, gTS.rcText.top - 10, &rcFrame1, SURFACE_ID_TEXT_BOX); - int i; for (i = 1; i < 7; i++) PutBitmap3(&grcFull, WINDOW_WIDTH / 2 - 122, 8 * i + gTS.rcText.top - 10, &rcFrame2, SURFACE_ID_TEXT_BOX); PutBitmap3(&grcFull, WINDOW_WIDTH / 2 - 122, 8 * i + gTS.rcText.top - 10, &rcFrame3, SURFACE_ID_TEXT_BOX); } //Draw face picture - RECT rcFace; rcFace.left = 48 * (gTS.face % 6); rcFace.top = 48 * (gTS.face / 6); rcFace.right = rcFace.left + 48; @@ -446,23 +463,22 @@ void PutTextScript() if (gTS.face_x < (TEXT_LEFT * 0x200)) gTS.face_x += 0x1000; + PutBitmap3(&gTS.rcText, gTS.face_x / 0x200, gTS.rcText.top - 3, &rcFace, SURFACE_ID_FACE); //Draw text - int text_offset; if (gTS.face) text_offset = 56; else text_offset = 0; - for (int i = 0; i < 4; i++) + for (i = 0; i < 4; i++) PutBitmap3(&gTS.rcText, text_offset + TEXT_LEFT, gTS.offsetY + gTS.ypos_line[i] + gTS.rcText.top, &gRect_line, (Surface_Ids)(i + SURFACE_ID_TEXT_LINE1)); //Draw NOD cursor if ((gTS.wait_beam++ % 20 > 12) && gTS.mode == 2) { - RECT rect; - rect.left = TEXT_LEFT + text_offset + 6 * gTS.p_write; + rect.left = TEXT_LEFT + 6 * gTS.p_write + text_offset; rect.top = gTS.ypos_line[gTS.line % 4] + gTS.rcText.top + gTS.offsetY; rect.right = rect.left + 5; rect.bottom = rect.top + 11; @@ -482,11 +498,11 @@ void PutTextScript() } //Draw GIT - RECT rcItemBox1 = {0, 0, 72, 16}; - RECT rcItemBox2 = {0, 8, 72, 24}; - RECT rcItemBox3 = {240, 0, 244, 8}; - RECT rcItemBox4 = {240, 8, 244, 16}; - RECT rcItemBox5 = {240, 16, 244, 24}; + SET_RECT(rcItemBox1, 0, 0, 72, 16) + SET_RECT(rcItemBox2, 0, 8, 72, 24) + SET_RECT(rcItemBox3, 240, 0, 244, 8) + SET_RECT(rcItemBox4, 240, 8, 244, 16) + SET_RECT(rcItemBox5, 240, 16, 244, 24) if (gTS.item) { @@ -500,7 +516,6 @@ void PutTextScript() if (gTS.item_y < WINDOW_HEIGHT - 104) ++gTS.item_y; - RECT rect; if (gTS.item < 1000) { rect.left = 16 * (gTS.item % 16); @@ -520,12 +535,11 @@ void PutTextScript() } //Draw Yes / No selection - RECT rect_yesno = {152, 48, 244, 80}; - RECT rect_cur = {112, 88, 128, 104}; + SET_RECT(rect_yesno, 152, 48, 244, 80) + SET_RECT(rect_cur, 112, 88, 128, 104) if (gTS.mode == 6) { - int i; if (gTS.wait < 2) i = (WINDOW_HEIGHT - 96) + (2 - gTS.wait) * 4; else @@ -540,9 +554,13 @@ void PutTextScript() //Parse TSC int TextScriptProc() { - RECT rcSymbol = {64, 48, 72, 56}; - BOOL bExit; + char c[3]; + int w, x, y, z; + int i; + int length; + + RECT rcSymbol = {64, 48, 72, 56}; switch (gTS.mode) { @@ -559,7 +577,6 @@ int TextScriptProc() gTS.wait = 0; //Parsing time - int w, x, y, z; bExit = FALSE; while (bExit == FALSE) @@ -607,13 +624,13 @@ int TextScriptProc() else if (IS_COMMAND('E','Q','+')) { z = GetTextScriptNo(gTS.p_read + 4); - EquipItem(z, true); + EquipItem(z, TRUE); gTS.p_read += 8; } else if (IS_COMMAND('E','Q','-')) { z = GetTextScriptNo(gTS.p_read + 4); - EquipItem(z, false); + EquipItem(z, FALSE); gTS.p_read += 8; } else if (IS_COMMAND('A','M','+')) @@ -696,12 +713,12 @@ int TextScriptProc() } else if (IS_COMMAND('H','M','C')) { - ShowMyChar(false); + ShowMyChar(FALSE); gTS.p_read += 4; } else if (IS_COMMAND('S','M','C')) { - ShowMyChar(true); + ShowMyChar(TRUE); gTS.p_read += 4; } else if (IS_COMMAND('F','L','+')) @@ -732,7 +749,7 @@ int TextScriptProc() { g_GameFlags &= ~2; g_GameFlags |= 1; - gMC.up = false; + gMC.up = FALSE; gMC.shock = 0; gTS.p_read += 4; } @@ -1225,7 +1242,6 @@ int TextScriptProc() else { char str_0[0x40]; - #ifdef JAPANESE sprintf(str_0, "不明のコード:<%c%c%c", gTS.data[gTS.p_read + 1], gTS.data[gTS.p_read + 2], gTS.data[gTS.p_read + 3]); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "エラー", str_0, NULL); @@ -1256,6 +1272,7 @@ int TextScriptProc() else if (gTS.flags & 0x10) { //SAT/CAT/TUR printing + char str[72]; x = gTS.p_read; //Break if reaches command, or new-line while (gTS.data[x] != '<' && gTS.data[x] != '\r') @@ -1268,8 +1285,7 @@ int TextScriptProc() } //Get text to copy - char str[72]; - int length = x - gTS.p_read; + length = x - gTS.p_read; memcpy(str, &gTS.data[gTS.p_read], length); str[length] = 0; @@ -1290,7 +1306,6 @@ int TextScriptProc() else { //Get text to print - char c[3]; c[0] = gTS.data[gTS.p_read]; if (c[0] & 0x80) @@ -1349,7 +1364,7 @@ int TextScriptProc() break; case 3: //NEW LINE - for (int i = 0; i < 4; i++) + for (i = 0; i < 4; i++) { gTS.ypos_line[i] -= 4; diff --git a/src/TextScr.h b/src/TextScr.h index 1c87e1df..f2dfdac8 100644 --- a/src/TextScr.h +++ b/src/TextScr.h @@ -21,7 +21,7 @@ struct TEXT_SCRIPT //Current positions (read position in buffer, x position in line) unsigned int p_read; - unsigned int p_write; + int p_write; //Current line to write to int line; From 00ca00f5dd3dfb38ec5eaa54a6e312969c749b21 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 14 May 2019 01:35:04 +0100 Subject: [PATCH 7/8] Weed out some usage of C++ bools Pixel used BOOL, the C89-friendly Windows-specific equivalent --- src/ArmsItem.cpp | 6 +++--- src/Game.cpp | 42 +++++++++++++++++++++--------------------- src/Game.h | 6 ++++-- src/Main.cpp | 2 +- src/MiniMap.cpp | 8 ++++---- src/MycParam.cpp | 16 ++++++++-------- 6 files changed, 41 insertions(+), 39 deletions(-) diff --git a/src/ArmsItem.cpp b/src/ArmsItem.cpp index 2791ad00..5d7789b9 100644 --- a/src/ArmsItem.cpp +++ b/src/ArmsItem.cpp @@ -324,13 +324,13 @@ void PutCampObject() PutBitmap3(&rcView, 40 * i + (WINDOW_WIDTH - 224) / 2, (WINDOW_HEIGHT - 192) / 2, &rcArms, SURFACE_ID_ARMS_IMAGE); PutBitmap3(&rcView, 40 * i + (WINDOW_WIDTH - 224) / 2, (WINDOW_HEIGHT - 128) / 2, &rcPer, SURFACE_ID_TEXT_BOX); PutBitmap3(&rcView, 40 * i + (WINDOW_WIDTH - 224) / 2, (WINDOW_HEIGHT - 160) / 2, &rcLv, SURFACE_ID_TEXT_BOX); - PutNumber4(40 * i + (WINDOW_WIDTH - 224) / 2, (WINDOW_HEIGHT - 160) / 2, gArmsData[i].level, 0); + PutNumber4(40 * i + (WINDOW_WIDTH - 224) / 2, (WINDOW_HEIGHT - 160) / 2, gArmsData[i].level, FALSE); // Draw ammo if (gArmsData[i].max_num) { - PutNumber4(40 * i + (WINDOW_WIDTH - 224) / 2, (WINDOW_HEIGHT - 144) / 2, gArmsData[i].num, 0); - PutNumber4(40 * i + (WINDOW_WIDTH - 224) / 2, (WINDOW_HEIGHT - 128) / 2, gArmsData[i].max_num, 0); + PutNumber4(40 * i + (WINDOW_WIDTH - 224) / 2, (WINDOW_HEIGHT - 144) / 2, gArmsData[i].num, FALSE); + PutNumber4(40 * i + (WINDOW_WIDTH - 224) / 2, (WINDOW_HEIGHT - 128) / 2, gArmsData[i].max_num, FALSE); } else { diff --git a/src/Game.cpp b/src/Game.cpp index 82b5aa36..cca03ae1 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -56,7 +56,7 @@ int Random(int min, int max) return min + rep_rand() % (max - min + 1); } -void PutNumber4(int x, int y, int value, bool bZero) +void PutNumber4(int x, int y, int value, BOOL bZero) { // Define rects RECT rcClient = grcFull; @@ -189,7 +189,7 @@ int ModeOpening() if (tscRet == 2) return 1; - PutMapName(false); + PutMapName(FALSE); PutTextScript(); PutFramePerSecound(); @@ -317,7 +317,7 @@ int ModeTitle() // Start loop unsigned int wait = 0; - while (true) + while (1) { // Don't accept selection for 10 frames if (wait < 10) @@ -365,10 +365,10 @@ int ModeTitle() int v1, v2, v3, v4; GetCompileVersion(&v1, &v2, &v3, &v4); - PutNumber4((WINDOW_WIDTH - 40) / 2, WINDOW_HEIGHT - 24, v1, 0); - PutNumber4((WINDOW_WIDTH - 8) / 2, WINDOW_HEIGHT - 24, v2, 0); - PutNumber4((WINDOW_WIDTH + 24) / 2, WINDOW_HEIGHT - 24, v3, 0); - PutNumber4((WINDOW_WIDTH + 56) / 2, WINDOW_HEIGHT - 24, v4, 0); + PutNumber4((WINDOW_WIDTH - 40) / 2, WINDOW_HEIGHT - 24, v1, FALSE); + PutNumber4((WINDOW_WIDTH - 8) / 2, WINDOW_HEIGHT - 24, v2, FALSE); + PutNumber4((WINDOW_WIDTH + 24) / 2, WINDOW_HEIGHT - 24, v3, FALSE); + PutNumber4((WINDOW_WIDTH + 56) / 2, WINDOW_HEIGHT - 24, v4, FALSE); // Draw main title PutBitmap3(&grcGame, (WINDOW_WIDTH - 144) / 2, 40, &rcTitle, SURFACE_ID_TITLE); @@ -447,7 +447,7 @@ int ModeAction() unsigned long color = GetCortBoxColor(RGB(0, 0, 0x20)); - bool swPlay = true; + unsigned int swPlay = 1; // Reset stuff gCounter = 0; @@ -471,7 +471,7 @@ int ModeAction() if ((bContinue && LoadProfile(NULL)) || InitializeGame()) { - while (true) + while (1) { // Get pressed keys GetTrg(); @@ -486,12 +486,12 @@ int ModeAction() return 1; } - if (swPlay & 1 && g_GameFlags & 1) + if (swPlay % 2 && g_GameFlags & 1) { if (g_GameFlags & 2) - ActMyChar(true); + ActMyChar(TRUE); else - ActMyChar(false); + ActMyChar(FALSE); ActStar(); ActNpChar(); @@ -515,9 +515,9 @@ int ModeAction() ActFlash(frame_x, frame_y); if (g_GameFlags & 2) - AnimationMyChar(true); + AnimationMyChar(TRUE); else - AnimationMyChar(false); + AnimationMyChar(FALSE); } if (g_GameFlags & 8) @@ -585,7 +585,7 @@ int ModeAction() RotationArmsRev(); } - if (swPlay & 1) + if (swPlay % 2) { int tscRet = TextScriptProc(); if (tscRet == 0) @@ -594,13 +594,13 @@ int ModeAction() return 1; } - PutMapName(false); + PutMapName(FALSE); PutTimeCounter(16, 8); if (g_GameFlags & 2) { - PutMyLife(true); - PutArmsEnergy(true); + PutMyLife(TRUE); + PutArmsEnergy(TRUE); PutMyAir((WINDOW_WIDTH - 80) / 2, (WINDOW_HEIGHT - 32) / 2); PutActiveArmsList(); } @@ -623,7 +623,7 @@ int ModeAction() return 0; } -bool Game() +BOOL Game() { if (LoadGenericData()) { @@ -655,9 +655,9 @@ bool Game() } else { - return false; + return FALSE; } } - return true; + return TRUE; } diff --git a/src/Game.h b/src/Game.h index 19be7142..c90a00be 100644 --- a/src/Game.h +++ b/src/Game.h @@ -1,9 +1,11 @@ #pragma once +#include "WindowsWrapper.h" + extern int g_GameFlags; extern int gCounter; 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(); +BOOL Game(); diff --git a/src/Main.cpp b/src/Main.cpp index 02c28b53..df5d9921 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -62,7 +62,7 @@ void rep_srand(unsigned int seed) void PutFramePerSecound() { if (bFps) - PutNumber4(WINDOW_WIDTH - 40, 8, GetFramePerSecound(), false); + PutNumber4(WINDOW_WIDTH - 40, 8, GetFramePerSecound(), FALSE); } int GetFramePerSecound() diff --git a/src/MiniMap.cpp b/src/MiniMap.cpp index 6759886f..f444580b 100644 --- a/src/MiniMap.cpp +++ b/src/MiniMap.cpp @@ -111,7 +111,7 @@ int MiniMapLoop() rcView.top = (WINDOW_HEIGHT / 2) - gMap.length * f / 8 / 2; rcView.bottom = (WINDOW_HEIGHT / 2) + gMap.length * f / 8 / 2; - PutMapName(true); + PutMapName(TRUE); CortBox(&rcView, 0); PutFramePerSecound(); @@ -130,7 +130,7 @@ int MiniMapLoop() line = 0; my_wait = 0; - while (true) + while (1) { GetTrg(); @@ -164,7 +164,7 @@ int MiniMapLoop() PutBitmap3(&grcGame, rcView.left + 1, rcView.top + 1, &rcMiniMap, SURFACE_ID_MAP); - PutMapName(true); + PutMapName(TRUE); if (++my_wait / 8 % 2) PutBitmap3(&grcGame, my_x + rcView.left + 1, my_y + rcView.top + 1, &my_rect, SURFACE_ID_TEXT_BOX); @@ -196,7 +196,7 @@ int MiniMapLoop() rcView.top = (WINDOW_HEIGHT / 2) - gMap.length * f / 8 / 2; rcView.bottom = (WINDOW_HEIGHT / 2) + gMap.length * f / 8 / 2; - PutMapName(true); + PutMapName(TRUE); CortBox(&rcView, 0); PutFramePerSecound(); diff --git a/src/MycParam.cpp b/src/MycParam.cpp index b5a31019..62527be8 100644 --- a/src/MycParam.cpp +++ b/src/MycParam.cpp @@ -252,8 +252,8 @@ void PutArmsEnergy(BOOL flash) // Draw max ammo if (gArmsData[gSelectedArms].max_num) { - PutNumber4(gArmsEnergyX + 32, 16, gArmsData[gSelectedArms].num, 0); - PutNumber4(gArmsEnergyX + 32, 24, gArmsData[gSelectedArms].max_num, 0); + PutNumber4(gArmsEnergyX + 32, 16, gArmsData[gSelectedArms].num, FALSE); + PutNumber4(gArmsEnergyX + 32, 24, gArmsData[gSelectedArms].max_num, FALSE); } else { @@ -267,7 +267,7 @@ void PutArmsEnergy(BOOL flash) PutBitmap3(&rcView, gArmsEnergyX + 32, 24, &rcPer, SURFACE_ID_TEXT_BOX); PutBitmap3(&rcView, gArmsEnergyX, 32, &rcLv, SURFACE_ID_TEXT_BOX); - PutNumber4(gArmsEnergyX - 8, 32, gArmsData[gSelectedArms].level, 0); + PutNumber4(gArmsEnergyX - 8, 32, gArmsData[gSelectedArms].level, FALSE); SET_RECT(rcExpBox, 0, 72, 40, 80) SET_RECT(rcExpVal, 0, 80, 0, 88) @@ -366,7 +366,7 @@ void PutMyLife(BOOL flash) PutBitmap3(&grcGame, 16, 40, &rcCase, SURFACE_ID_TEXT_BOX); PutBitmap3(&grcGame, 40, 40, &rcBr, SURFACE_ID_TEXT_BOX); PutBitmap3(&grcGame, 40, 40, &rcLife, SURFACE_ID_TEXT_BOX); - PutNumber4(8, 40, gMC.lifeBr, 0); + PutNumber4(8, 40, gMC.lifeBr, FALSE); } void PutMyAir(int x, int y) @@ -383,7 +383,7 @@ void PutMyAir(int x, int y) { // Draw how much air is left if (gMC.air_get % 6 < 4) - PutNumber4(x + 32, y, gMC.air / 10, 0); + PutNumber4(x + 32, y, gMC.air / 10, FALSE); // Draw "AIR" text if (gMC.air % 30 > 10) @@ -420,9 +420,9 @@ void PutTimeCounter(int x, int y) } // Draw time - PutNumber4(x, y, time_count / (60 * 50), false); - PutNumber4(x + 20, y, time_count / 50 % 60, true); - PutNumber4(x + 32, y, time_count / 5 % 10, false); + PutNumber4(x, y, time_count / (60 * 50), FALSE); + PutNumber4(x + 20, y, time_count / 50 % 60, TRUE); + PutNumber4(x + 32, y, time_count / 5 % 10, FALSE); PutBitmap3(&grcGame, x + 30, y, &rcTime[2], SURFACE_ID_TEXT_BOX); } else From b2812053b7b255928f2547529c762c9135d2b174 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 14 May 2019 01:47:30 +0100 Subject: [PATCH 8/8] Shut up a warning GCC was giving me --- src/Profile.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Profile.cpp b/src/Profile.cpp index 07d8e4ae..68ce7255 100644 --- a/src/Profile.cpp +++ b/src/Profile.cpp @@ -45,7 +45,7 @@ BOOL SaveProfile(const char *name) { PROFILE profile; FILE *fp; - char *FLAG = "FLAG"; + const char *FLAG = "FLAG"; char path[PATH_LENGTH]; //Get path