From 767c2972ae09642c63528c2efbe4adf77f9a6e11 Mon Sep 17 00:00:00 2001 From: cuckydev Date: Sat, 9 Feb 2019 22:02:18 -0500 Subject: [PATCH 1/4] tallscreen fix, replicated MSVC rand --- src/Back.cpp | 37 +++++++++++++++++----------------- src/Ending.cpp | 48 ++++++++++++++++++++++++++++---------------- src/Main.cpp | 15 ++++++++++++++ src/PixTone.cpp | 2 ++ src/WindowsWrapper.h | 5 +++++ 5 files changed, 72 insertions(+), 35 deletions(-) diff --git a/src/Back.cpp b/src/Back.cpp index 8c1b93ad..ff5cbb7e 100644 --- a/src/Back.cpp +++ b/src/Back.cpp @@ -52,6 +52,7 @@ void ActBack() void PutBack(int fx, int fy) { RECT rect = {0, 0, gBack.partsW, gBack.partsH}; + RECT rcSkyFiller = {106, 0, 255, 88}; switch (gBack.type) { @@ -90,63 +91,63 @@ void PutBack(int fx, int fy) case 6: case 7: //Sky + for (int y = 0; y < WINDOW_HEIGHT - 240 + 88; y += 88) + { + for (int x = -((y * 54) % 149); x < WINDOW_WIDTH; x += 149) + { + PutBitmap4(&grcGame, x, y, &rcSkyFiller, SURFACE_ID_LEVEL_BACKGROUND); + } + } + rect.top = 0; rect.bottom = 88; rect.left = 0; rect.right = 320; - PutBitmap4(&grcGame, (WINDOW_WIDTH - 320) / 2, 0, &rect, SURFACE_ID_LEVEL_BACKGROUND); - - rect.left = 106; - rect.right = 255; - for (int i = 0; i < ((WINDOW_WIDTH + 329) / 320); i++) - { - PutBitmap4(&grcGame, (WINDOW_WIDTH - 320) / 2 - (149 * (i + 1)), 0, &rect, SURFACE_ID_LEVEL_BACKGROUND); - PutBitmap4(&grcGame, (WINDOW_WIDTH - 320) / 2 + 320 + (149 * i), 0, &rect, SURFACE_ID_LEVEL_BACKGROUND); - } - + PutBitmap4(&grcGame, (WINDOW_WIDTH - 320) / 2, WINDOW_HEIGHT - 240, &rect, SURFACE_ID_LEVEL_BACKGROUND); + //Cloud layer 1 rect.top = 88; rect.bottom = 123; rect.left = gBack.fx / 2; rect.right = 320; - PutBitmap4(&grcGame, 0, 88, &rect, SURFACE_ID_LEVEL_BACKGROUND); + PutBitmap4(&grcGame, 0, 88 + (WINDOW_HEIGHT - 240), &rect, SURFACE_ID_LEVEL_BACKGROUND); rect.left = 0; for (int i = 0; i < ((WINDOW_WIDTH + 329) / 320) + 1; i++) - PutBitmap4(&grcGame, (320 * (i + 1)) - gBack.fx / 2 % 320, 88, &rect, SURFACE_ID_LEVEL_BACKGROUND); + PutBitmap4(&grcGame, (320 * (i + 1)) - gBack.fx / 2 % 320, 88 + (WINDOW_HEIGHT - 240), &rect, SURFACE_ID_LEVEL_BACKGROUND); //Cloud layer 2 rect.top = 123; rect.bottom = 146; rect.left = gBack.fx % 320; rect.right = 320; - PutBitmap4(&grcGame, 0, 123, &rect, SURFACE_ID_LEVEL_BACKGROUND); + PutBitmap4(&grcGame, 0, 123 + (WINDOW_HEIGHT - 240), &rect, SURFACE_ID_LEVEL_BACKGROUND); rect.left = 0; for (int i = 0; i < ((WINDOW_WIDTH + 329) / 320) + 1; i++) - PutBitmap4(&grcGame, (320 * (i + 1)) - gBack.fx % 320, 123, &rect, SURFACE_ID_LEVEL_BACKGROUND); + PutBitmap4(&grcGame, (320 * (i + 1)) - gBack.fx % 320, 123 + (WINDOW_HEIGHT - 240), &rect, SURFACE_ID_LEVEL_BACKGROUND); //Cloud layer 3 rect.top = 146; rect.bottom = 176; rect.left = 2 * gBack.fx % 320; rect.right = 320; - PutBitmap4(&grcGame, 0, 146, &rect, SURFACE_ID_LEVEL_BACKGROUND); + PutBitmap4(&grcGame, 0, 146 + (WINDOW_HEIGHT - 240), &rect, SURFACE_ID_LEVEL_BACKGROUND); rect.left = 0; for (int i = 0; i < ((WINDOW_WIDTH + 329) / 320) + 1; i++) - PutBitmap4(&grcGame, (320 * (i + 1)) - 2 * gBack.fx % 320, 146, &rect, SURFACE_ID_LEVEL_BACKGROUND); + PutBitmap4(&grcGame, (320 * (i + 1)) - 2 * gBack.fx % 320, 146 + (WINDOW_HEIGHT - 240), &rect, SURFACE_ID_LEVEL_BACKGROUND); //Cloud layer 4 rect.top = 176; rect.bottom = 240; rect.left = 4 * gBack.fx % 320; rect.right = 320; - PutBitmap4(&grcGame, 0, 176, &rect, SURFACE_ID_LEVEL_BACKGROUND); + PutBitmap4(&grcGame, 0, 176 + (WINDOW_HEIGHT - 240), &rect, SURFACE_ID_LEVEL_BACKGROUND); rect.left = 0; for (int i = 0; i < ((WINDOW_WIDTH + 329) / 320) + 1; i++) - PutBitmap4(&grcGame, (320 * (i + 1)) - 4 * gBack.fx % 320, 176, &rect, SURFACE_ID_LEVEL_BACKGROUND); + PutBitmap4(&grcGame, (320 * (i + 1)) - 4 * gBack.fx % 320, 176 + (WINDOW_HEIGHT - 240), &rect, SURFACE_ID_LEVEL_BACKGROUND); break; default: diff --git a/src/Ending.cpp b/src/Ending.cpp index 987979bd..ff0feff1 100644 --- a/src/Ending.cpp +++ b/src/Ending.cpp @@ -100,6 +100,10 @@ void ActionIllust() { switch (Illust.act_no) { + case 0: //Off-screen to the left + Illust.x = -0x14000; + break; + case 1: //Move in from the left Illust.x += 0x5000; if (Illust.x > 0) @@ -111,10 +115,6 @@ void ActionIllust() if (Illust.x < -0x14000) Illust.x = -0x14000; break; - - case 0: //Off-screen to the left - Illust.x = -0x14000; - break; } } @@ -137,6 +137,7 @@ void ReloadIllust(int a) //Initialize and release credits void InitCreditScript() { + //Clear script state and casts memset(&Credit, 0, sizeof(CREDIT)); memset(Strip, 0, sizeof(Strip)); } @@ -145,6 +146,7 @@ void ReleaseCreditScript() { if (Credit.pData) { + //Free script data free(Credit.pData); Credit.pData = NULL; } @@ -179,7 +181,8 @@ bool StartCreditScript() return false; //Read data - fp->read(fp, Credit.pData, 1, Credit.size); + SDL_RWread(fp, Credit.pData, 1, Credit.size); + SDL_RWclose(fp); EncryptionBinaryData2((uint8_t*)Credit.pData, Credit.size); //Reset credits @@ -203,14 +206,16 @@ bool StartCreditScript() //Clear casts memset(Strip, 0, sizeof(Strip)); - SDL_RWclose(fp); return true; } //Get number from text (4 digit) int GetScriptNumber(const char *text) { - return 1000 * *text - 48000 + 100 * text[1] - 4800 + 10 * text[2] - 480 + text[3] - 48; + return 1000 * text[0] - 48000 + + 100 * text[1] - 4800 + + 10 * text[2] - 480 + + text[3] - 48; } //Parse credits @@ -218,6 +223,7 @@ void ActionCredit_Read() { while (Credit.offset < Credit.size) { + //Get character uint8_t character = Credit.pData[Credit.offset]; int a, b, len; @@ -352,6 +358,7 @@ void ActionCredit() { if (Credit.offset < Credit.size) { + //Update script, or if waiting, decrement the wait value if (Credit.mode == 1) { ActionCredit_Read(); @@ -379,23 +386,24 @@ void CutCreditIllust() //Scene of the island falling int Scene_DownIsland(int mode) { - RECT rc_sprite; - RECT rc_ground; - RECT rc_sky; - RECT rc_frame; + //Setup background + RECT rc_frame = {(WINDOW_WIDTH - 160) / 2, (WINDOW_HEIGHT - 80) / 2, (WINDOW_WIDTH + 160) / 2, (WINDOW_HEIGHT + 80) / 2}; + RECT rc_sky = {0, 0, 160, 80}; + RECT rc_ground = {160, 48, 320, 80}; + + //Setup island + RECT rc_sprite = {160, 0, 200, 24}; + ISLAND_SPRITE sprite; - - rc_frame = {(WINDOW_WIDTH - 160) / 2, (WINDOW_HEIGHT - 80) / 2, (WINDOW_WIDTH + 160) / 2, (WINDOW_HEIGHT + 80) / 2}; - rc_sky = {0, 0, 160, 80}; - rc_ground = {160, 48, 320, 80}; - rc_sprite = {160, 0, 200, 24}; sprite.x = 0x15000; sprite.y = 0x8000; for (int wait = 0; wait < 900; wait++) { + //Get pressed keys GetTrg(); + //Escape menu if (gKey & 0x8000) { int escRet = Call_Escape(); @@ -408,6 +416,7 @@ int Scene_DownIsland(int mode) switch (mode) { case 0: + //Move down sprite.y += 0x33; break; @@ -418,33 +427,38 @@ int Scene_DownIsland(int mode) { 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 { + //Move down at normal speed sprite.y += 0x33; } break; } - + //Draw scene CortBox(&grcFull, 0); PutBitmap3(&rc_frame, 80 + (WINDOW_WIDTH - 320) / 2, 80 + (WINDOW_HEIGHT - 240) / 2, &rc_sky, 21); PutBitmap3(&rc_frame, sprite.x / 0x200 - 20 + (WINDOW_WIDTH - 320) / 2, sprite.y / 512 - 12 + (WINDOW_HEIGHT - 240) / 2, &rc_sprite, 21); PutBitmap3(&rc_frame, 80 + (WINDOW_WIDTH - 320) / 2, 128 + (WINDOW_HEIGHT - 240) / 2, &rc_ground, 21); PutTimeCounter(16, 8); + //Draw window PutFramePerSecound(); if (!Flip_SystemTask()) return 0; diff --git a/src/Main.cpp b/src/Main.cpp index 3e87a65b..bb2ec523 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -44,6 +44,21 @@ const char *lpWindowName = "洞窟物語エンジン2"; const char *lpWindowName = "Cave Story Engine 2 ~ Doukutsu Monogatari Enjin 2"; #endif +//A replication of MSVC's rand algorithm +static unsigned long int next = 1; + +int _rand() +{ + next = ((next) * 214013 + 2531011); + return ((next) >> 16) & 0x7FFF; +} + +void _srand(unsigned int seed) +{ + next = seed; +} + +//Framerate stuff void PutFramePerSecound() { if (bFps) diff --git a/src/PixTone.cpp b/src/PixTone.cpp index 46377ffc..49e98786 100644 --- a/src/PixTone.cpp +++ b/src/PixTone.cpp @@ -5,6 +5,8 @@ #include #include +#include "WindowsWrapper.h" + #include "CommonDefines.h" #include "Tags.h" #include "PixTone.h" diff --git a/src/WindowsWrapper.h b/src/WindowsWrapper.h index 17918798..18ee4fe3 100644 --- a/src/WindowsWrapper.h +++ b/src/WindowsWrapper.h @@ -1,5 +1,10 @@ #pragma once +#define rand _rand +#define srand _srand +int _rand(); +void _srand(unsigned int seed); + typedef int BOOL; #ifndef FALSE From 1e748f94069d98418eae911b0d003e67e57eecce Mon Sep 17 00:00:00 2001 From: cuckydev Date: Sat, 9 Feb 2019 23:07:23 -0500 Subject: [PATCH 2/4] fix --- src/Game.cpp | 2 +- src/Main.cpp | 4 ++-- src/PixTone.cpp | 4 ++-- src/ValueView.cpp | 35 +++++++++++++++++++++++++++-------- src/WindowsWrapper.h | 7 ++----- 5 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/Game.cpp b/src/Game.cpp index e3ebd343..0402e701 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -50,7 +50,7 @@ bool bContinue; int Random(int min, int max) { - return min + rand() % (max - min + 1); + return min + rep_rand() % (max - min + 1); } void PutNumber4(int x, int y, int value, bool bZero) diff --git a/src/Main.cpp b/src/Main.cpp index bb2ec523..547cb977 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -47,13 +47,13 @@ const char *lpWindowName = "Cave Story Engine 2 ~ Doukutsu Monogatari Enjin 2"; //A replication of MSVC's rand algorithm static unsigned long int next = 1; -int _rand() +int rep_rand() { next = ((next) * 214013 + 2531011); return ((next) >> 16) & 0x7FFF; } -void _srand(unsigned int seed) +void rep_srand(unsigned int seed) { next = seed; } diff --git a/src/PixTone.cpp b/src/PixTone.cpp index 49e98786..bfd55470 100644 --- a/src/PixTone.cpp +++ b/src/PixTone.cpp @@ -46,9 +46,9 @@ void MakeWaveTables() gWaveModelTable[4][i] = -0x40; /* White noise wave */ - srand(0); + rep_srand(0); for (int i = 0; i < 0x100; i++) - gWaveModelTable[5][i] = (int8_t)rand() / 2; + gWaveModelTable[5][i] = (int8_t)rep_rand() / 2; } //Loading .pxt files diff --git a/src/ValueView.cpp b/src/ValueView.cpp index 09c7fb3a..48d85c59 100644 --- a/src/ValueView.cpp +++ b/src/ValueView.cpp @@ -43,7 +43,7 @@ void SetValueView(int *px, int *py, int value) //Get if negative or not bool minus; - if ( value >= 0 ) + if (value >= 0) { minus = false; } @@ -85,6 +85,28 @@ void SetValueView(int *px, int *py, int value) gVV[index].rect.right = 40; gVV[index].rect.bottom = 8 * (index + 1); + RECT rect[20]; + rect[0] = {0, 56, 8, 64}; + rect[1] = {8, 56, 16, 64}; + rect[2] = {16, 56, 24, 64}; + rect[3] = {24, 56, 32, 64}; + rect[4] = {32, 56, 40, 64}; + rect[5] = {40, 56, 48, 64}; + rect[6] = {48, 56, 56, 64}; + rect[7] = {56, 56, 64, 64}; + rect[8] = {64, 56, 72, 64}; + rect[9] = {72, 56, 80, 64}; + rect[10] = {0, 64, 8, 72}; + rect[11] = {8, 64, 16, 72}; + rect[12] = {16, 64, 24, 72}; + rect[13] = {24, 64, 32, 72}; + rect[14] = {32, 64, 40, 72}; + rect[15] = {40, 64, 48, 72}; + rect[16] = {48, 64, 56, 72}; + rect[17] = {56, 64, 64, 72}; + rect[18] = {64, 64, 72, 72}; + rect[19] = {72, 64, 80, 72}; + //Get digits int dig[4]; dig[0] = 1; @@ -103,7 +125,7 @@ void SetValueView(int *px, int *py, int value) } } - int sw = 0; + bool sw = false; RECT rcPlus = {32, 48, 40, 56}; RECT rcMinus = {40, 48, 48, 56}; @@ -120,15 +142,12 @@ void SetValueView(int *px, int *py, int value) { if (sw || !i || fig[i]) { - sw = 1; + sw = true; - RECT rect; if (minus) - rect = {fig[i] << 3, 64, (fig[i] + 1) << 3, 72}; - else - rect = {fig[i] << 3, 56, (fig[i] + 1) << 3, 64}; + fig[i] += 10; - Surface2Surface(8 * (4 - i), gVV[index].rect.top, &rect, 29, 26); + Surface2Surface(8 * (4 - i), gVV[index].rect.top, &rect[fig[i]], 29, 26); } } } diff --git a/src/WindowsWrapper.h b/src/WindowsWrapper.h index 18ee4fe3..fbc9eb22 100644 --- a/src/WindowsWrapper.h +++ b/src/WindowsWrapper.h @@ -1,9 +1,6 @@ #pragma once - -#define rand _rand -#define srand _srand -int _rand(); -void _srand(unsigned int seed); +int rep_rand(); +void rep_srand(unsigned int seed); typedef int BOOL; From 92b798610cf7fb7930f13fc726f165ed4eb31dc2 Mon Sep 17 00:00:00 2001 From: cuckydev Date: Sun, 10 Feb 2019 09:29:51 -0500 Subject: [PATCH 3/4] Added some thingy --- build/fps | 0 src/Back.cpp | 5 ++++- src/Draw.cpp | 3 +++ src/Ending.cpp | 2 -- src/Ending.h | 2 ++ src/Frame.cpp | 10 ++-------- src/GenericLoad.cpp | 3 ++- 7 files changed, 13 insertions(+), 12 deletions(-) create mode 100644 build/fps diff --git a/build/fps b/build/fps new file mode 100644 index 00000000..e69de29b diff --git a/src/Back.cpp b/src/Back.cpp index ff5cbb7e..1cd09b8e 100644 --- a/src/Back.cpp +++ b/src/Back.cpp @@ -91,9 +91,12 @@ void PutBack(int fx, int fy) case 6: case 7: //Sky + static unsigned int fillNext; + fillNext = 0; for (int y = 0; y < WINDOW_HEIGHT - 240 + 88; y += 88) { - for (int x = -((y * 54) % 149); x < WINDOW_WIDTH; x += 149) + fillNext = ((fillNext) * 214013 + 2531011); + for (int x = -(fillNext % 149); x < WINDOW_WIDTH; x += 149) { PutBitmap4(&grcGame, x, y, &rcSkyFiller, SURFACE_ID_LEVEL_BACKGROUND); } diff --git a/src/Draw.cpp b/src/Draw.cpp index 2ba7bf3f..7f424d64 100644 --- a/src/Draw.cpp +++ b/src/Draw.cpp @@ -66,6 +66,8 @@ bool Flip_SystemTask() static bool IsEnableBitmap(SDL_RWops *fp) { + return true; + /* char str[16]; const char *extra_text = "(C)Pixel"; @@ -75,6 +77,7 @@ static bool IsEnableBitmap(SDL_RWops *fp) fp->read(fp, str, 1, len); fp->seek(fp, 0, RW_SEEK_SET); return memcmp(str, extra_text, len) == 0; + */ } void ReleaseSurface(int s) diff --git a/src/Ending.cpp b/src/Ending.cpp index ff0feff1..3846d1cf 100644 --- a/src/Ending.cpp +++ b/src/Ending.cpp @@ -17,8 +17,6 @@ #include "Draw.h" #include "TextScr.h" -#define MAX_STRIP 0x10 - CREDIT Credit; STRIP Strip[MAX_STRIP]; ILLUSTRATION Illust; diff --git a/src/Ending.h b/src/Ending.h index 1a7627af..c32064d4 100644 --- a/src/Ending.h +++ b/src/Ending.h @@ -32,6 +32,8 @@ struct ISLAND_SPRITE int y; }; +#define MAX_STRIP ((WINDOW_HEIGHT + 14) / 15) + void ActionStripper(); void PutStripper(); void SetStripper(int x, int y, char *text, int cast); diff --git a/src/Frame.cpp b/src/Frame.cpp index 6e879a61..c6b5f4de 100644 --- a/src/Frame.cpp +++ b/src/Frame.cpp @@ -22,30 +22,24 @@ void MoveFrame3() const int num_x = ((WINDOW_WIDTH + 0xF) >> 4) + 1; const int num_y = ((WINDOW_HEIGHT + 0xF) >> 4) + 1; - if (map_w >= num_x || g_GameFlags & 8) + if (map_w >= num_x) { if (gFrame.x <= -0x200) gFrame.x = 0; if (gFrame.x > ((((map_w - 1) << 4) - ((g_GameFlags & 8) ? 320 : WINDOW_WIDTH))) << 9) gFrame.x = (((map_w - 1) << 4) - ((g_GameFlags & 8) ? 320 : WINDOW_WIDTH)) << 9; - - if (g_GameFlags & 8) - gFrame.x -= ((WINDOW_WIDTH - 320) / 2) << 9; } else { gFrame.x = (((map_w - 1) << 4) - WINDOW_WIDTH) << 8; } - if (map_l >= num_y || g_GameFlags & 8) + if (map_l >= num_y) { if (gFrame.y <= -0x200) gFrame.y = 0; if (gFrame.y > ((((map_l - 1) << 4) - ((g_GameFlags & 8) ? 240 : WINDOW_HEIGHT))) << 9) gFrame.y = (((map_l - 1) << 4) - ((g_GameFlags & 8) ? 240 : WINDOW_HEIGHT)) << 9; - - if (g_GameFlags & 8) - gFrame.y += ((WINDOW_HEIGHT - 240) / 2) << 9; } else { diff --git a/src/GenericLoad.cpp b/src/GenericLoad.cpp index 0cde4c67..7194cf75 100644 --- a/src/GenericLoad.cpp +++ b/src/GenericLoad.cpp @@ -2,6 +2,7 @@ #include "Draw.h" #include "Sound.h" #include "PixTone.h" +#include "Ending.h" bool LoadGenericData() { @@ -52,7 +53,7 @@ bool LoadGenericData() MakeSurface_Generic(40, 240, 29); //Unknown? MakeSurface_Generic(320, 240, SURFACE_ID_LEVEL_SPRITESET_1); MakeSurface_Generic(320, 240, SURFACE_ID_LEVEL_SPRITESET_2); - MakeSurface_Generic(WINDOW_WIDTH, 240, SURFACE_ID_CREDIT_CAST); + MakeSurface_Generic(WINDOW_WIDTH, 15 * MAX_STRIP, SURFACE_ID_CREDIT_CAST); char path[0x100]; uint8_t *buf = nullptr; From ecc9f758b68d9fc00b150dae0f04248590debe2e Mon Sep 17 00:00:00 2001 From: cuckydev Date: Sun, 10 Feb 2019 09:34:05 -0500 Subject: [PATCH 4/4] what was i thinking --- src/Ending.h | 2 +- src/GenericLoad.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Ending.h b/src/Ending.h index c32064d4..3cc7ec63 100644 --- a/src/Ending.h +++ b/src/Ending.h @@ -32,7 +32,7 @@ struct ISLAND_SPRITE int y; }; -#define MAX_STRIP ((WINDOW_HEIGHT + 14) / 15) +#define MAX_STRIP (WINDOW_HEIGHT / 16) + 1 void ActionStripper(); void PutStripper(); diff --git a/src/GenericLoad.cpp b/src/GenericLoad.cpp index 7194cf75..f16c928e 100644 --- a/src/GenericLoad.cpp +++ b/src/GenericLoad.cpp @@ -53,7 +53,7 @@ bool LoadGenericData() MakeSurface_Generic(40, 240, 29); //Unknown? MakeSurface_Generic(320, 240, SURFACE_ID_LEVEL_SPRITESET_1); MakeSurface_Generic(320, 240, SURFACE_ID_LEVEL_SPRITESET_2); - MakeSurface_Generic(WINDOW_WIDTH, 15 * MAX_STRIP, SURFACE_ID_CREDIT_CAST); + MakeSurface_Generic(WINDOW_WIDTH, 16 * MAX_STRIP, SURFACE_ID_CREDIT_CAST); char path[0x100]; uint8_t *buf = nullptr;