diff --git a/Makefile b/Makefile index bc694929..fd8d7d21 100644 --- a/Makefile +++ b/Makefile @@ -35,14 +35,16 @@ ifeq ($(WINDOWS), 1) endif CXXFLAGS += -std=c++98 `sdl2-config --cflags` `pkg-config freetype2 --cflags` -MMD -MP -MF $@.d -LIBS += `sdl2-config --static-libs` `pkg-config freetype2 --libs` +LIBS += `pkg-config freetype2 --libs` ifeq ($(STATIC), 1) - CXXFLAGS += -static + CXXFLAGS += `sdl2-config --static-libs` -static LIBS += -lharfbuzz -lfreetype -lbz2 -lpng -lz -lgraphite2 ifeq ($(WINDOWS), 1) LIBS += -lRpcrt4 -lDwrite -lusp10 endif +else + CXXFLAGS += `sdl2-config --libs` endif # For an accurate result to the original's code, compile in alphabetical order diff --git a/src/Back.cpp b/src/Back.cpp index c6df1c6b..8cfe234d 100644 --- a/src/Back.cpp +++ b/src/Back.cpp @@ -14,9 +14,13 @@ BACK gBack; int gWaterY; +static unsigned long color_black; BOOL InitBack(const char *fName, int type) { + // Unused, hilariously + color_black = GetCortBoxColor(RGB(0, 0, 0x10)); + //Get width and height char path[PATH_LENGTH]; sprintf(path, "%s/%s.pbm", gDataPath, fName); @@ -46,8 +50,10 @@ BOOL InitBack(const char *fName, int type) // This is ridiculously platform-dependant: // It should break on big-endian CPUs, and platforms // where short isn't 16-bit and long isn't 32-bit. - short bmp_header_buffer[7]; - long bmp_header_buffer2[10]; +// short bmp_header_buffer[7]; +// long bmp_header_buffer2[10]; + int16_t bmp_header_buffer[7]; + int32_t bmp_header_buffer2[10]; // We'll need a better solution when we stop using stdint.h fread(bmp_header_buffer, 14, 1, fp); diff --git a/src/Draw.cpp b/src/Draw.cpp index 6b1ea686..d3f9d193 100644 --- a/src/Draw.cpp +++ b/src/Draw.cpp @@ -291,7 +291,7 @@ static bool LoadBitmap(SDL_RWops *fp, Surface_Ids surf_no, bool create_surface) } for (int i = 1; i < magnification; ++i) - memcpy(dst_row + i * surf[surf_no].surface->pitch, dst_row, surf[surf_no].surface->w * sizeof(unsigned long)); + memcpy(dst_row + i * surf[surf_no].surface->pitch, dst_row, surf[surf_no].surface->w * 4); } SDL_FreeSurface(converted_surface); @@ -474,13 +474,22 @@ void Surface2Surface(int x, int y, RECT *rect, int to, int from) surf[to].needs_updating = true; } +unsigned long GetCortBoxColor(unsigned long col) +{ + // This comes in BGR, and goes out BGR + return col; +} + void CortBox(RECT *rect, uint32_t col) { //Get rect SDL_Rect destRect = RectToSDLRectScaled(rect); //Set colour and draw - SDL_SetRenderDrawColor(gRenderer, (col & 0xFF0000) >> 16, (col & 0x00FF00) >> 8, col & 0x0000FF, 0xFF); + const unsigned char col_red = col & 0x0000FF; + const unsigned char col_green = (col & 0x00FF00) >> 8; + const unsigned char col_blue = (col & 0xFF0000) >> 16; + SDL_SetRenderDrawColor(gRenderer, col_red, col_green, col_blue, 0xFF); SDL_RenderFillRect(gRenderer, &destRect); } @@ -489,9 +498,10 @@ void CortBox2(RECT *rect, uint32_t col, Surface_Ids surf_no) //Get rect SDL_Rect destRect = RectToSDLRectScaled(rect); - const unsigned char col_red = (col & 0xFF0000) >> 16; + //Set colour and draw + const unsigned char col_red = col & 0x0000FF; const unsigned char col_green = (col & 0x00FF00) >> 8; - const unsigned char col_blue = col & 0x0000FF; + const unsigned char col_blue = (col & 0xFF0000) >> 16; SDL_FillRect(surf[surf_no].surface, &destRect, SDL_MapRGB(surf[surf_no].surface->format, col_red, col_green, col_blue)); surf[surf_no].needs_updating = true; } diff --git a/src/Draw.h b/src/Draw.h index d5ce2bd8..628fa023 100644 --- a/src/Draw.h +++ b/src/Draw.h @@ -4,6 +4,10 @@ #include "WindowsWrapper.h" +#ifndef RGB +#define RGB(r,g,b) ((r) | ((g) << 8) | ((b) << 16)) +#endif + extern RECT grcGame; extern RECT grcFull; @@ -63,6 +67,7 @@ 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); void Surface2Surface(int x, int y, RECT *rect, int to, int from); +unsigned long GetCortBoxColor(unsigned long col); void CortBox(RECT *rect, uint32_t col); void CortBox2(RECT *rect, uint32_t col, Surface_Ids surf_no); void InitTextObject(const char *font_name); diff --git a/src/Ending.cpp b/src/Ending.cpp index 046b3dca..f9a13118 100644 --- a/src/Ending.cpp +++ b/src/Ending.cpp @@ -75,7 +75,7 @@ void SetStripper(int x, int y, char *text, int cast) //Draw text RECT rc = {0, 16 * s, 320, 16 * s + 16}; CortBox2(&rc, 0, SURFACE_ID_CREDIT_CAST); - PutText2(0, 16 * s, text, 0xFFFFFE, SURFACE_ID_CREDIT_CAST); + PutText2(0, 16 * s, text, RGB(0xFF, 0xFF, 0xFE), SURFACE_ID_CREDIT_CAST); break; } } @@ -90,7 +90,7 @@ void RestoreStripper() { RECT rc = {0, 16 * s, 320, 16 * s + 16}; CortBox2(&rc, 0, SURFACE_ID_CREDIT_CAST); - PutText2(0, rc.top, Strip[s].str, 0xFFFFFE, SURFACE_ID_CREDIT_CAST); + PutText2(0, rc.top, Strip[s].str, RGB(0xFF, 0xFF, 0xFE), SURFACE_ID_CREDIT_CAST); } } } diff --git a/src/Fade.cpp b/src/Fade.cpp index cd305abc..15f6a874 100644 --- a/src/Fade.cpp +++ b/src/Fade.cpp @@ -2,26 +2,42 @@ #include +#include "CommonDefines.h" #include "WindowsWrapper.h" #include "Draw.h" #include "Game.h" -FADE gFade; +#define FADE_WIDTH (((WINDOW_WIDTH - 1) / 16) + 1) +#define FADE_HEIGHT (((WINDOW_HEIGHT - 1) / 16) + 1) + +struct FADE +{ + int mode; + BOOL bMask; + int count; + char ani_no[FADE_HEIGHT][FADE_WIDTH]; + BOOLEAN flag[FADE_HEIGHT][FADE_WIDTH]; + char dir; +}; + +static FADE gFade; +static unsigned long mask_color; void InitFade() { memset(&gFade, 0, sizeof(FADE)); + mask_color = GetCortBoxColor(RGB(0, 0, 0x20)); } void SetFadeMask() { - gFade.bMask = true; + gFade.bMask = TRUE; } void ClearFade() { - gFade.bMask = false; + gFade.bMask = FALSE; gFade.mode = 0; } @@ -30,239 +46,248 @@ void StartFadeOut(char dir) gFade.mode = 2; gFade.count = 0; gFade.dir = dir; - gFade.bMask = false; + gFade.bMask = FALSE; for (int y = 0; y < FADE_HEIGHT; y++) { for (int x = 0; x < FADE_WIDTH; x++) { gFade.ani_no[y][x] = 0; - gFade.flag[y][x] = 0; + gFade.flag[y][x] = FALSE; } } } void StartFadeIn(char dir) { + int x; + int y; + gFade.mode = 1; gFade.count = 0; gFade.dir = dir; - gFade.bMask = true; + gFade.bMask = TRUE; - for (int y = 0; y < FADE_HEIGHT; y++) + for (y = 0; y < FADE_HEIGHT; y++) { - for (int x = 0; x < FADE_WIDTH; x++) + for (x = 0; x < FADE_WIDTH; x++) { gFade.ani_no[y][x] = 15; - gFade.flag[y][x] = 0; + gFade.flag[y][x] = FALSE; } } + + x = x; // What } void ProcFade() { - if (gFade.mode == 1) + int x; + int y; + + switch (gFade.mode) { - gFade.bMask = false; - - switch (gFade.dir) - { - case 0: - for (int y = 0; y < FADE_HEIGHT; y++) - { - for (int x = 0; x <= FADE_WIDTH; x++) - { - if ((FADE_WIDTH - 1) - gFade.count == x) - gFade.flag[y][x] = 1; - } - } - break; - - case 1: - for (int y = 0; y < FADE_HEIGHT; y++) - { - for (int x = 0; x < FADE_WIDTH; x++) - { - if ((FADE_HEIGHT - 1) - gFade.count == y) - gFade.flag[y][x] = 1; - } - } - break; - - case 2: - for (int y = 0; y < FADE_HEIGHT; y++) - { - for (int x = 0; x < FADE_WIDTH; x++) - { - if (gFade.count == x) - gFade.flag[y][x] = 1; - } - } - break; - - case 3: - for (int y = 0; y < FADE_HEIGHT; y++) - { - for (int x = 0; x < FADE_WIDTH; x++) - { - if (gFade.count == y) - gFade.flag[y][x] = 1; - } - } - break; - - case 4: - for (int y = 0; y < (FADE_HEIGHT / 2); y++) - { - for (int x = 0; x < (FADE_WIDTH / 2); x++) - { - if ((FADE_WIDTH - 1) - gFade.count == x + y) - gFade.flag[y][x] = 1; - } - } - for (int y = 0; y < (FADE_HEIGHT / 2); y++) - { - for (int x = (FADE_WIDTH / 2); x < FADE_WIDTH; x++) - { - if ((FADE_WIDTH - 1) - gFade.count == y + ((FADE_WIDTH - 1) - x)) - gFade.flag[y][x] = 1; - } - } - for (int y = (FADE_HEIGHT / 2); y < FADE_HEIGHT; y++) - { - for (int x = 0; x < (FADE_WIDTH / 2); x++) - { - if ((FADE_WIDTH - 1) - gFade.count == x + ((FADE_HEIGHT - 1) - y)) - gFade.flag[y][x] = 1; - } - } - for (int y = (FADE_HEIGHT / 2); y < FADE_HEIGHT; y++) - { - for (int x = (FADE_WIDTH / 2); x < FADE_WIDTH; x++) - { - if ((FADE_WIDTH - 1) - gFade.count == ((FADE_WIDTH - 1) - x) + ((FADE_HEIGHT - 1) - y)) - gFade.flag[y][x] = 1; - } - } - break; - - default: - break; - } - - for (int y = 0; y < FADE_HEIGHT; y++) - { - for (int x = 0; x < FADE_WIDTH; x++) + case 2: + switch (gFade.dir) { - if (gFade.ani_no[y][x] > 0 && gFade.flag[y][x]) - --gFade.ani_no[y][x]; + case 0: + for (y = 0; y < FADE_HEIGHT; y++) + { + for (x = 0; x < FADE_WIDTH; x++) + { + if ((FADE_WIDTH - 1) - gFade.count == x) + gFade.flag[y][x] = TRUE; + } + } + break; + + case 2: + for (y = 0; y < FADE_HEIGHT; y++) + { + for (x = 0; x < FADE_WIDTH; x++) + { + if (gFade.count == x) + gFade.flag[y][x] = TRUE; + } + } + break; + + case 1: + for (y = 0; y < FADE_HEIGHT; y++) + { + for (x = 0; x < FADE_WIDTH; x++) + { + if ((FADE_HEIGHT - 1) - gFade.count == y) + gFade.flag[y][x] = TRUE; + } + } + break; + + case 3: + for (y = 0; y < FADE_HEIGHT; y++) + { + for (x = 0; x < FADE_WIDTH; x++) + { + if (gFade.count == y) + gFade.flag[y][x] = TRUE; + } + } + break; + + case 4: + for (y = 0; y < (FADE_HEIGHT / 2); y++) + { + for (x = 0; x < (FADE_WIDTH / 2); x++) + { + if (gFade.count == x + y) + gFade.flag[y][x] = TRUE; + } + } + for (y = 0; y < (FADE_HEIGHT / 2); y++) + { + for (x = (FADE_WIDTH / 2); x < FADE_WIDTH; x++) + { + if (gFade.count == y + ((FADE_WIDTH - 1) - x)) + gFade.flag[y][x] = TRUE; + } + } + for (y = (FADE_HEIGHT / 2); y < FADE_HEIGHT; y++) + { + for (x = 0; x < (FADE_WIDTH / 2); x++) + { + if (gFade.count == x + ((FADE_HEIGHT - 1) - y)) + gFade.flag[y][x] = TRUE; + } + } + for (y = (FADE_HEIGHT / 2); y < FADE_HEIGHT; y++) + { + for (x = (FADE_WIDTH / 2); x < FADE_WIDTH; x++) + { + if (gFade.count == ((FADE_WIDTH - 1) - x) + ((FADE_HEIGHT - 1) - y)) + gFade.flag[y][x] = TRUE; + } + } + break; } - } - - if (++gFade.count > ((FADE_WIDTH > FADE_HEIGHT) ? FADE_WIDTH : FADE_HEIGHT) + 16) - gFade.mode = 0; - } - else if (gFade.mode == 2) - { - switch (gFade.dir) - { - case 0: - for (int y = 0; y < FADE_HEIGHT; y++) - { - for (int x = 0; x <= FADE_WIDTH; x++) - { - if ((FADE_WIDTH - 1) - gFade.count == x) - gFade.flag[y][x] = 1; - } - } - break; - - case 1: - for (int y = 0; y < FADE_HEIGHT; y++) - { - for (int x = 0; x < FADE_WIDTH; x++) - { - if ((FADE_HEIGHT - 1) - gFade.count == y) - gFade.flag[y][x] = 1; - } - } - break; - - case 2: - for (int y = 0; y < FADE_HEIGHT; y++) - { - for (int x = 0; x < FADE_WIDTH; x++) - { - if (gFade.count == x) - gFade.flag[y][x] = 1; - } - } - break; - - case 3: - for (int y = 0; y < FADE_HEIGHT; y++) - { - for (int x = 0; x < FADE_WIDTH; x++) - { - if (gFade.count == y) - gFade.flag[y][x] = 1; - } - } - break; - - case 4: - for (int y = 0; y < (FADE_HEIGHT / 2); y++) - { - for (int x = 0; x < (FADE_WIDTH / 2); x++) - { - if (gFade.count == x + y) - gFade.flag[y][x] = 1; - } - } - for (int y = 0; y < (FADE_HEIGHT / 2); y++) - { - for (int x = (FADE_WIDTH / 2); x < FADE_WIDTH; x++) - { - if (gFade.count == y + ((FADE_WIDTH - 1) - x)) - gFade.flag[y][x] = 1; - } - } - for (int y = (FADE_HEIGHT / 2); y < FADE_HEIGHT; y++) - { - for (int x = 0; x < (FADE_WIDTH / 2); x++) - { - if (gFade.count == x + ((FADE_HEIGHT - 1) - y)) - gFade.flag[y][x] = 1; - } - } - for (int y = (FADE_HEIGHT / 2); y < FADE_HEIGHT; y++) - { - for (int x = (FADE_WIDTH / 2); x < FADE_WIDTH; x++) - { - if (gFade.count == ((FADE_WIDTH - 1) - x) + ((FADE_HEIGHT - 1) - y)) - gFade.flag[y][x] = 1; - } - } - break; - - default: - break; - } - - for (int y = 0; y < FADE_HEIGHT; y++) - { - for (int x = 0; x < FADE_WIDTH; x++) + + for (y = 0; y < FADE_HEIGHT; y++) { - if (gFade.ani_no[y][x] < 15 && gFade.flag[y][x]) - ++gFade.ani_no[y][x]; + for (x = 0; x < FADE_WIDTH; x++) + { + if (gFade.ani_no[y][x] < 15 && gFade.flag[y][x]) + ++gFade.ani_no[y][x]; + } } - } - - if (++gFade.count > ((FADE_WIDTH > FADE_HEIGHT) ? FADE_WIDTH : FADE_HEIGHT) + 16) - { - gFade.bMask = true; - gFade.mode = 0; - } + + if (++gFade.count > ((FADE_WIDTH > FADE_HEIGHT) ? FADE_WIDTH : FADE_HEIGHT) + 16) + { + gFade.bMask = TRUE; + gFade.mode = 0; + } + + break; + + case 1: + gFade.bMask = FALSE; + + switch (gFade.dir) + { + case 0: + for (y = 0; y < FADE_HEIGHT; y++) + { + for (x = 0; x < FADE_WIDTH; x++) + { + if ((FADE_WIDTH - 1) - gFade.count == x) + gFade.flag[y][x] = TRUE; + } + } + break; + + case 2: + for (y = 0; y < FADE_HEIGHT; y++) + { + for (x = 0; x < FADE_WIDTH; x++) + { + if (gFade.count == x) + gFade.flag[y][x] = TRUE; + } + } + break; + + case 1: + for (y = 0; y < FADE_HEIGHT; y++) + { + for (x = 0; x < FADE_WIDTH; x++) + { + if ((FADE_HEIGHT - 1) - gFade.count == y) + gFade.flag[y][x] = TRUE; + } + } + break; + + case 3: + for (y = 0; y < FADE_HEIGHT; y++) + { + for (x = 0; x < FADE_WIDTH; x++) + { + if (gFade.count == y) + gFade.flag[y][x] = TRUE; + } + } + break; + + case 4: + for (y = 0; y < (FADE_HEIGHT / 2); y++) + { + for (x = 0; x < (FADE_WIDTH / 2); x++) + { + if ((FADE_WIDTH - 1) - gFade.count == x + y) + gFade.flag[y][x] = TRUE; + } + } + for (y = 0; y < (FADE_HEIGHT / 2); y++) + { + for (x = (FADE_WIDTH / 2); x < FADE_WIDTH; x++) + { + if ((FADE_WIDTH - 1) - gFade.count == y + ((FADE_WIDTH - 1) - x)) + gFade.flag[y][x] = TRUE; + } + } + for (y = (FADE_HEIGHT / 2); y < FADE_HEIGHT; y++) + { + for (x = 0; x < (FADE_WIDTH / 2); x++) + { + if ((FADE_WIDTH - 1) - gFade.count == x + ((FADE_HEIGHT - 1) - y)) + gFade.flag[y][x] = TRUE; + } + } + for (y = (FADE_HEIGHT / 2); y < FADE_HEIGHT; y++) + { + for (x = (FADE_WIDTH / 2); x < FADE_WIDTH; x++) + { + if ((FADE_WIDTH - 1) - gFade.count == ((FADE_WIDTH - 1) - x) + ((FADE_HEIGHT - 1) - y)) + gFade.flag[y][x] = TRUE; + } + } + break; + + default: + break; + } + + for (y = 0; y < FADE_HEIGHT; y++) + { + for (x = 0; x < FADE_WIDTH; x++) + { + if (gFade.ani_no[y][x] > 0 && gFade.flag[y][x]) + --gFade.ani_no[y][x]; + } + } + + if (++gFade.count > ((FADE_WIDTH > FADE_HEIGHT) ? FADE_WIDTH : FADE_HEIGHT) + 16) + gFade.mode = 0; + + break; } } @@ -274,23 +299,28 @@ void PutFade() if (gFade.bMask) { - CortBox(&grcGame, 0x000020); + CortBox(&grcGame, mask_color); + return; } - else if (gFade.mode) + + if (gFade.mode == 0) + return; + + for (int y = 0; y < FADE_HEIGHT; y++) { - for (int y = 0; y < FADE_HEIGHT; y++) + for (int x = 0; x < FADE_WIDTH; x++) { - for (int x = 0; x < FADE_WIDTH; x++) - { - rect.left = 16 * gFade.ani_no[y][x]; - rect.right = rect.left + 16; - PutBitmap3(&grcGame, 16 * x, 16 * y, &rect, SURFACE_ID_FADE); - } + rect.left = 16 * gFade.ani_no[y][x]; + rect.right = rect.left + 16; + PutBitmap3(&grcGame, 16 * x, 16 * y, &rect, SURFACE_ID_FADE); } } } -bool GetFadeActive() +BOOL GetFadeActive() { - return gFade.mode != 0; + if (gFade.mode == 0) + return FALSE; + else + return TRUE; } diff --git a/src/Fade.h b/src/Fade.h index 06c3da0e..793372e7 100644 --- a/src/Fade.h +++ b/src/Fade.h @@ -1,19 +1,6 @@ #pragma once -#include "CommonDefines.h" - -#define FADE_WIDTH (((WINDOW_WIDTH - 1) >> 4) + 1) -#define FADE_HEIGHT (((WINDOW_HEIGHT - 1) >> 4) + 1) - -struct FADE -{ - int mode; - bool bMask; - int count; - char ani_no[FADE_HEIGHT][FADE_WIDTH]; - char flag[FADE_HEIGHT][FADE_WIDTH]; - char dir; -}; +#include "WindowsWrapper.h" void InitFade(); void SetFadeMask(); @@ -22,4 +9,4 @@ void StartFadeOut(char dir); void StartFadeIn(char dir); void ProcFade(); void PutFade(); -bool GetFadeActive(); +BOOL GetFadeActive(); diff --git a/src/Flags.cpp b/src/Flags.cpp index 7da02b15..82dbb1fd 100644 --- a/src/Flags.cpp +++ b/src/Flags.cpp @@ -1,10 +1,11 @@ #include "Flags.h" -#include #include -uint8_t gFlagNPC[1000]; -uint8_t gSkipFlag[0x40]; +#include "WindowsWrapper.h" + +unsigned char gFlagNPC[1000]; +unsigned char gSkipFlag[0x40]; //Flag inits void InitFlags() @@ -18,33 +19,39 @@ void InitSkipFlags() } //NPC flags -void SetNPCFlag(int a) +void SetNPCFlag(long a) { gFlagNPC[a / 8] |= 1 << a % 8; } -void CutNPCFlag(int a) +void CutNPCFlag(long a) { gFlagNPC[a / 8] &= ~(1 << a % 8); } -bool GetNPCFlag(int a) +BOOL GetNPCFlag(long a) { - return ((gFlagNPC[a / 8] >> a % 8) & 1) != 0; + if (gFlagNPC[a / 8] & (1 << a % 8)) + return TRUE; + else + return FALSE; } //Skip flags -void SetSkipFlag(int a) +void SetSkipFlag(long a) { gSkipFlag[a / 8] |= 1 << a % 8; } -void CutSkipFlag(int a) +void CutSkipFlag(long a) { gSkipFlag[a / 8] &= ~(1 << a % 8); } -bool GetSkipFlag(int a) +BOOL GetSkipFlag(long a) { - return ((gSkipFlag[a / 8] >> a % 8) & 1) != 0; + if (gSkipFlag[a / 8] & (1 << a % 8)) + return TRUE; + else + return FALSE; } diff --git a/src/Flags.h b/src/Flags.h index 4fb6daea..716ab8e6 100644 --- a/src/Flags.h +++ b/src/Flags.h @@ -1,15 +1,15 @@ #pragma once -#include +#include "WindowsWrapper.h" -extern uint8_t gFlagNPC[1000]; -extern uint8_t gSkipFlag[0x40]; +extern unsigned char gFlagNPC[1000]; +extern unsigned char gSkipFlag[0x40]; void InitFlags(); void InitSkipFlags(); -void SetNPCFlag(int a); -void CutNPCFlag(int a); -bool GetNPCFlag(int a); -void SetSkipFlag(int a); -void CutSkipFlag(int a); -bool GetSkipFlag(int a); +void SetNPCFlag(long a); +void CutNPCFlag(long a); +BOOL GetNPCFlag(long a); +void SetSkipFlag(long a); +void CutSkipFlag(long a); +BOOL GetSkipFlag(long a); diff --git a/src/Flash.cpp b/src/Flash.cpp index c6a04389..28d4e5f7 100644 --- a/src/Flash.cpp +++ b/src/Flash.cpp @@ -21,7 +21,7 @@ static unsigned long gFlashColor; void InitFlash(void) { - gFlashColor = 0xFEFFFF; + gFlashColor = GetCortBoxColor(RGB(0xFF, 0xFF, 0xFE)); } void SetFlash(int x, int y, int mode) @@ -137,34 +137,26 @@ void ActFlash_Flash(void) void ActFlash(int flx, int fly) { if (flash.flag == FALSE) + return; + + switch (flash.mode) { - // Do nothing - } - else - { - switch (flash.mode) - { - case 1: - ActFlash_Explosion(flx, fly); - break; - case 2: - ActFlash_Flash(); - break; - } + case 1: + ActFlash_Explosion(flx, fly); + break; + case 2: + ActFlash_Flash(); + break; } } void PutFlash(void) { if (flash.flag == FALSE) - { - // Do nothing - } - else - { - CortBox(&flash.rect1, gFlashColor); - CortBox(&flash.rect2, gFlashColor); - } + return; + + CortBox(&flash.rect1, gFlashColor); + CortBox(&flash.rect2, gFlashColor); } void ResetFlash(void) diff --git a/src/Font.cpp b/src/Font.cpp index a7ee1c2a..442c3446 100644 --- a/src/Font.cpp +++ b/src/Font.cpp @@ -1,6 +1,5 @@ #include "Font.h" -#include #include #include #include diff --git a/src/Game.cpp b/src/Game.cpp index f0490ee4..4022fe3f 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -1,6 +1,7 @@ #include "Game.h" #include +#include #include #include @@ -266,6 +267,7 @@ int ModeTitle() int anime = 0; int char_type = 0; int time_counter = 0; + unsigned long back_color = GetCortBoxColor(RGB(0x20, 0x20, 0x20)); //Set state bContinue = IsProfile(); @@ -355,7 +357,7 @@ int ModeTitle() anime = 0; //Draw title - CortBox(&grcGame, 0x202020); + CortBox(&grcGame, back_color); //Draw version PutBitmap3(&grcGame, (WINDOW_WIDTH - 120) / 2, WINDOW_HEIGHT - 24, &rcVersion, SURFACE_ID_TEXT_BOX); @@ -442,7 +444,9 @@ int ModeAction() { int frame_x = 0; int frame_y = 0; - + + unsigned long color = GetCortBoxColor(RGB(0, 0, 0x20)); + bool swPlay = true; //Reset stuff @@ -524,7 +528,7 @@ int ModeAction() } ProcFade(); - CortBox(&grcFull, 0x000020); + CortBox(&grcFull, color); GetFramePosition(&frame_x, &frame_y); PutBack(frame_x, frame_y); PutStage_Back(frame_x, frame_y); diff --git a/src/Input.cpp b/src/Input.cpp index ab861da6..405756e3 100644 --- a/src/Input.cpp +++ b/src/Input.cpp @@ -2,6 +2,7 @@ #include #include +#include #include diff --git a/src/MapName.cpp b/src/MapName.cpp index 4cfe28d5..d739e7d3 100644 --- a/src/MapName.cpp +++ b/src/MapName.cpp @@ -36,8 +36,8 @@ void ReadyMapName(const char *str) int len = strlen(gMapName.name); CortBox2(&rc, 0, SURFACE_ID_ROOM_NAME); - PutText2((-6 * len + 160) / 2 + 6, 1, gMapName.name, 0x110022, SURFACE_ID_ROOM_NAME); - PutText2((-6 * len + 160) / 2 + 6, 0, gMapName.name, 0xFFFFFE, SURFACE_ID_ROOM_NAME); + PutText2((-6 * len + 160) / 2 + 6, 1, gMapName.name, RGB(0x11, 0x00, 0x22), SURFACE_ID_ROOM_NAME); + PutText2((-6 * len + 160) / 2 + 6, 0, gMapName.name, RGB(0xFF, 0xFF, 0xFE), SURFACE_ID_ROOM_NAME); } void PutMapName(bool bMini) @@ -69,6 +69,6 @@ void RestoreMapName() int len = strlen(gMapName.name); CortBox2(&rc, 0, SURFACE_ID_ROOM_NAME); - PutText2((-6 * len + 160) / 2 + 6, 1, gMapName.name, 0x110022, SURFACE_ID_ROOM_NAME); - PutText2((-6 * len + 160) / 2 + 6, 0, gMapName.name, 0xFFFFFE, SURFACE_ID_ROOM_NAME); + PutText2((-6 * len + 160) / 2 + 6, 1, gMapName.name, RGB(0x11, 0x00, 0x22), SURFACE_ID_ROOM_NAME); + PutText2((-6 * len + 160) / 2 + 6, 0, gMapName.name, RGB(0xFF, 0xFF, 0xFE), SURFACE_ID_ROOM_NAME); } diff --git a/src/NpChar.cpp b/src/NpChar.cpp index 269802aa..3e204386 100644 --- a/src/NpChar.cpp +++ b/src/NpChar.cpp @@ -239,9 +239,10 @@ bool SetBulletObject(int x, int y, int val) { int tamakazu_ari[10]; + int n; int t = 0; memset(tamakazu_ari, 0, sizeof(tamakazu_ari)); - for (int n = 0; n < 8; n++) + for (n = 0; n < 8; n++) { int code = gArmsData[n].code; if (code == 5) @@ -255,7 +256,7 @@ bool SetBulletObject(int x, int y, int val) if (!t) return false; - int n = Random(1, 10 * t); + n = Random(1, 10 * t); int bullet_no = tamakazu_ari[n % t]; for (n = 0x100; n < NPC_MAX; n++) { diff --git a/src/Organya.cpp b/src/Organya.cpp index b959a5b4..14e9bba7 100644 --- a/src/Organya.cpp +++ b/src/Organya.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include diff --git a/src/Sound.cpp b/src/Sound.cpp index 001ad8ac..4ad1610f 100644 --- a/src/Sound.cpp +++ b/src/Sound.cpp @@ -1,7 +1,7 @@ #include "Sound.h" #include -#include +#include #include #include diff --git a/src/TextScr.cpp b/src/TextScr.cpp index 98c67b3d..21f12dd6 100644 --- a/src/TextScr.cpp +++ b/src/TextScr.cpp @@ -46,9 +46,17 @@ char text[0x100]; RECT gRect_line = {0, 0, 216, 16}; +#ifdef FIX_BUGS +static unsigned long nod_color; +#endif + //Initialize and end tsc BOOL InitTextScript2() { +#ifdef FIX_BUGS + nod_color = GetCortBoxColor(RGB(0xFF, 0xFF, 0xFE)); +#endif + //Clear flags gTS.mode = 0; g_GameFlags &= ~0x04; @@ -359,7 +367,7 @@ void SetNumberTextScript(int index) str[offset + 1] = 0; //Append number to line - PutText2(6 * gTS.p_write, 0, str, 0xFFFFFE, (Surface_Ids)(gTS.line % 4 + SURFACE_ID_TEXT_LINE1)); + PutText2(6 * gTS.p_write, 0, str, RGB(0xFF, 0xFF, 0xFE), (Surface_Ids)(gTS.line % 4 + SURFACE_ID_TEXT_LINE1)); strcat(&text[gTS.line % 4 * 0x40], str); //Play sound and reset blinking cursor @@ -456,7 +464,17 @@ void PutTextScript() rect.top = gTS.ypos_line[gTS.line % 4] + gTS.rcText.top + gTS.offsetY; rect.right = rect.left + 5; rect.bottom = rect.top + 11; - CortBox(&rect, 0xFFFFFE); +#ifdef FIX_BUGS + CortBox(&rect, nod_color); + + // This is how the Linux port fixed this, but it isn't done + // the way Pixel would do it (he only calls GetCortBoxColor + // once, during init functions, so our fix does it that way + // instead). + //CortBox(&rect, GetCortBoxColor(RGB(0xFF, 0xFF, 0xFE)); +#else + CortBox(&rect, RGB(0xFF, 0xFF, 0xFE)); +#endif } //Draw GIT @@ -1235,7 +1253,7 @@ int TextScriptProc() gTS.p_write = x; //Print text - PutText2(0, 0, str, 0xFFFFFE, (Surface_Ids)(gTS.line % 4 + SURFACE_ID_TEXT_LINE1)); + PutText2(0, 0, str, RGB(0xFF, 0xFF, 0xFE), (Surface_Ids)(gTS.line % 4 + SURFACE_ID_TEXT_LINE1)); sprintf(&text[gTS.line % 4 * 0x40], str); //Check if should move to next line (prevent a memory overflow, come on guys, this isn't a leftover of pixel trying to make text wrapping) @@ -1269,7 +1287,7 @@ int TextScriptProc() } else { - PutText2(6 * gTS.p_write, 0, c, 0xFFFFFE, (Surface_Ids)(gTS.line % 4 + SURFACE_ID_TEXT_LINE1)); + PutText2(6 * gTS.p_write, 0, c, RGB(0xFF, 0xFF, 0xFE), (Surface_Ids)(gTS.line % 4 + SURFACE_ID_TEXT_LINE1)); } strcat(&text[gTS.line % 4 * 0x40], c); diff --git a/src/Triangle.cpp b/src/Triangle.cpp index a850b586..d2363163 100644 --- a/src/Triangle.cpp +++ b/src/Triangle.cpp @@ -8,19 +8,19 @@ int16_t gTan[0x21]; void InitTriangleTable() { + int i; + //Sine - for (int i = 0; i < 0x100; ++i ) + for (i = 0; i < 0x100; ++i) { - float v0 = i * 6.2831998 / 256.0; - gSin[i] = (int)(sinf(v0) * 512.0); + gSin[i] = (int)(sin(i * 6.2831998 / 256.0) * 512.0); } //Tangent - for (int i = 0; i < 0x21; ++i ) + for (i = 0; i < 0x21; ++i) { float a = i * 6.2831855 / 256.0; - float v2 = sinf(a); - float b = v2 / cosf(a); + float b = sinf(a) / cosf(a); gTan[i] = (int16_t)(b * 8192.0); } } @@ -32,70 +32,89 @@ int GetSin(uint8_t deg) int GetCos(uint8_t deg) { - return gSin[(uint8_t)(deg + 0x40)]; + deg += 0x40; + return gSin[deg]; } -int GetArktan(int x, int y) +uint8_t GetArktan(int x, int y) { - int xa = -x; - int ya = -y; + x *= -1; + y *= -1; uint8_t a = 0; - - if (xa <= 0) + int16_t k; + + if (x > 0) { - if (ya <= 0) + if (y > 0) { - if (-xa <= -ya) + if (x > y) { - while (gTan[a] < (int16_t)(-0x2000 * xa / -ya)) + k = (y * 0x2000) / x; + while (k > gTan[a]) ++a; - a = -0x40 - a; } else { - while (gTan[a] < (int16_t)(-0x2000 * ya / -xa)) + k = (x * 0x2000) / y; + while (k > gTan[a]) ++a; - a += -0x80; + a = 0x40 - a; } } - else if (-xa <= ya) - { - while (gTan[a] < (int16_t)(-0x2000 * xa / ya)) - ++a; - a += 0x40; - } else { - while (gTan[a] < (int16_t)((ya << 13) / -xa)) - ++a; - a = -0x80 - a; + if (-y < x) + { + k = (-y * 0x2000) / x; + while (k > gTan[a]) + ++a; + a = 0x100 - a; + } + else + { + k = (x * 0x2000) / -y; + while (k > gTan[a]) + ++a; + a = 0x100 - 0x40 + a; + } } } - else if (ya <= 0) - { - if (-ya >= xa) - { - while (gTan[a] < (int16_t)((xa << 13) / -ya)) - ++a; - a -= 0x40; - } - else - { - while (gTan[a] < (int16_t)(-0x2000 * ya / xa)) - ++a; - a = -a; - } - } - else if (xa <= ya) - { - while (gTan[a] < (int16_t)((xa << 13) / ya)) - ++a; - a = 0x40 - a; - } else { - while (gTan[a] < (int16_t)((ya << 13) / xa)) - ++a; + if (y > 0) + { + if (-x > y) + { + k = (y * 0x2000) / -x; + while (k > gTan[a]) + ++a; + a = 0x80 - a; + } + else + { + k = (-x * 0x2000) / y; + while (k > gTan[a]) + ++a; + a = 0x40 + a; + } + } + else + { + if (-x > -y) + { + k = (-y * 0x2000) / -x; + while (k > gTan[a]) + ++a; + a = 0x80 + a; + } + else + { + k = (-x * 0x2000) / -y; + while (k > gTan[a]) + ++a; + a = 0x100 - 0x40 - a; + } + } } return a; diff --git a/src/Triangle.h b/src/Triangle.h index 8d2ab68a..400761a5 100644 --- a/src/Triangle.h +++ b/src/Triangle.h @@ -5,4 +5,4 @@ void InitTriangleTable(); int GetSin(uint8_t deg); int GetCos(uint8_t deg); -int GetArktan(int x, int y); +uint8_t GetArktan(int x, int y); diff --git a/src/WindowsWrapper.h b/src/WindowsWrapper.h index 87b43c13..5c3bfc32 100644 --- a/src/WindowsWrapper.h +++ b/src/WindowsWrapper.h @@ -4,6 +4,7 @@ int rep_rand(); void rep_srand(unsigned int seed); typedef int BOOL; +typedef unsigned char BOOLEAN; #ifndef FALSE #define FALSE 0