shithub: cstory

Download patch

ref: 68895b15977310e042dc575bed7c2acde0220911
parent: 4be2ef394279c6cd607d235a1f9ecc1b42540ec5
parent: e3549f87038b4880b0c05b25c7129067b542b5c9
author: Cucky <[email protected]>
date: Fri Feb 22 11:16:13 EST 2019

Merge pull request #70 from Clownacy/master

Bugfixes

--- a/Makefile
+++ b/Makefile
@@ -35,14 +35,16 @@
 endif
 
 CXXFLAGS += -std=c++98 `sdl2-config --cflags` `pkg-config freetype2 --cflags` -MMD -MP -MF [email protected]
-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
--- 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 @@
 	// 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);
 
--- a/src/Draw.cpp
+++ b/src/Draw.cpp
@@ -291,7 +291,7 @@
 								}
 
 								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,6 +474,12 @@
 	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
@@ -480,7 +486,10 @@
 	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 @@
 	//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;
 }
--- 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 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);
--- a/src/Ending.cpp
+++ b/src/Ending.cpp
@@ -75,7 +75,7 @@
 			//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 @@
 		{
 			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);
 		}
 	}
 }
--- a/src/Fade.cpp
+++ b/src/Fade.cpp
@@ -2,26 +2,42 @@
 
 #include <string.h>
 
+#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,7 +46,7 @@
 	gFade.mode = 2;
 	gFade.count = 0;
 	gFade.dir = dir;
-	gFade.bMask = false;
+	gFade.bMask = FALSE;
 	
 	for (int y = 0; y < FADE_HEIGHT; y++)
 	{
@@ -37,7 +53,7 @@
 		for (int x = 0; x < FADE_WIDTH; x++)
 		{
 			gFade.ani_no[y][x] = 0;
-			gFade.flag[y][x] = 0;
+			gFade.flag[y][x] = FALSE;
 		}
 	}
 }
@@ -44,225 +60,234 @@
 
 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++)
+		case 2:
+			switch (gFade.dir)
+			{
+				case 0:
+					for (y = 0; y < FADE_HEIGHT; y++)
 					{
-						if ((FADE_WIDTH - 1) - gFade.count == x)
-							gFade.flag[y][x] = 1;
+						for (x = 0; x < FADE_WIDTH; x++)
+						{
+							if ((FADE_WIDTH - 1) - gFade.count == x)
+								gFade.flag[y][x] = TRUE;
+						}
 					}
-				}
-				break;
-				
-			case 1:
-				for (int y = 0; y < FADE_HEIGHT; y++)
-				{
-					for (int x = 0; x < FADE_WIDTH; x++)
+					break;
+					
+				case 2:
+					for (y = 0; y < FADE_HEIGHT; y++)
 					{
-						if ((FADE_HEIGHT - 1) - gFade.count == y)
-							gFade.flag[y][x] = 1;
+						for (x = 0; x < FADE_WIDTH; x++)
+						{
+							if (gFade.count == x)
+								gFade.flag[y][x] = TRUE;
+						}
 					}
-				}
-				break;
-				
-			case 2:
-				for (int y = 0; y < FADE_HEIGHT; y++)
-				{
-					for (int x = 0; x < FADE_WIDTH; x++)
+					break;
+					
+				case 1:
+					for (y = 0; y < FADE_HEIGHT; y++)
 					{
-						if (gFade.count == x)
-							gFade.flag[y][x] = 1;
+						for (x = 0; x < FADE_WIDTH; x++)
+						{
+							if ((FADE_HEIGHT - 1) - gFade.count == y)
+								gFade.flag[y][x] = TRUE;
+						}
 					}
-				}
-				break;
-				
-			case 3:
-				for (int y = 0; y < FADE_HEIGHT; y++)
-				{
-					for (int x = 0; x < FADE_WIDTH; x++)
+					break;
+					
+				case 3:
+					for (y = 0; y < FADE_HEIGHT; y++)
 					{
-						if (gFade.count == y)
-							gFade.flag[y][x] = 1;
+						for (x = 0; x < FADE_WIDTH; x++)
+						{
+							if (gFade.count == y)
+								gFade.flag[y][x] = TRUE;
+						}
 					}
-				}
-				break;
-				
-			case 4:
-				for (int y = 0; y < (FADE_HEIGHT / 2); y++)
-				{
-					for (int x = 0; x < (FADE_WIDTH / 2); x++)
+					break;
+					
+				case 4:
+					for (y = 0; y < (FADE_HEIGHT / 2); y++)
 					{
-						if ((FADE_WIDTH - 1) - gFade.count == x + y)
-							gFade.flag[y][x] = 1;
+						for (x = 0; x < (FADE_WIDTH / 2); x++)
+						{
+							if (gFade.count == x + y)
+								gFade.flag[y][x] = TRUE;
+						}
 					}
-				}
-				for (int y = 0; y < (FADE_HEIGHT / 2); y++)
-				{
-					for (int x = (FADE_WIDTH / 2); x < FADE_WIDTH; x++)
+					for (y = 0; y < (FADE_HEIGHT / 2); y++)
 					{
-						if ((FADE_WIDTH - 1) - gFade.count == y + ((FADE_WIDTH - 1) - x))
-							gFade.flag[y][x] = 1;
+						for (x = (FADE_WIDTH / 2); x < FADE_WIDTH; x++)
+						{
+							if (gFade.count == y + ((FADE_WIDTH - 1) - x))
+								gFade.flag[y][x] = TRUE;
+						}
 					}
-				}
-				for (int y = (FADE_HEIGHT / 2); y < FADE_HEIGHT; y++)
-				{
-					for (int x = 0; x < (FADE_WIDTH / 2); x++)
+					for (y = (FADE_HEIGHT / 2); y < FADE_HEIGHT; y++)
 					{
-						if ((FADE_WIDTH - 1) - gFade.count == x + ((FADE_HEIGHT - 1) - y))
-							gFade.flag[y][x] = 1;
+						for (x = 0; x < (FADE_WIDTH / 2); x++)
+						{
+							if (gFade.count == x + ((FADE_HEIGHT - 1) - y))
+								gFade.flag[y][x] = TRUE;
+						}
 					}
-				}
-				for (int y = (FADE_HEIGHT / 2); y < FADE_HEIGHT; y++)
-				{
-					for (int x = (FADE_WIDTH / 2); x < FADE_WIDTH; x++)
+					for (y = (FADE_HEIGHT / 2); y < FADE_HEIGHT; y++)
 					{
-						if ((FADE_WIDTH - 1) - gFade.count == ((FADE_WIDTH - 1) - x) + ((FADE_HEIGHT - 1) - y))
-							gFade.flag[y][x] = 1;
+						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;
+			}
+			
+			for (y = 0; y < FADE_HEIGHT; y++)
+			{
+				for (x = 0; x < FADE_WIDTH; x++)
+				{
+					if (gFade.ani_no[y][x] < 15 && gFade.flag[y][x])
+						++gFade.ani_no[y][x];
 				}
-				break;
-				
-			default:
-				break;
-		}
-		
-		for (int y = 0; y < FADE_HEIGHT; y++)
-		{
-			for (int x = 0; x < FADE_WIDTH; x++)
+			}
+			
+			if (++gFade.count > ((FADE_WIDTH > FADE_HEIGHT) ? FADE_WIDTH : FADE_HEIGHT) + 16)
 			{
-				if (gFade.ani_no[y][x] > 0 && gFade.flag[y][x])
-					--gFade.ani_no[y][x];
+				gFade.bMask = TRUE;
+				gFade.mode = 0;
 			}
-		}
-		
-		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++)
+
+			break;
+
+		case 1:
+			gFade.bMask = FALSE;
+			
+			switch (gFade.dir)
+			{
+				case 0:
+					for (y = 0; y < FADE_HEIGHT; y++)
 					{
-						if ((FADE_WIDTH - 1) - gFade.count == x)
-							gFade.flag[y][x] = 1;
+						for (x = 0; x < FADE_WIDTH; x++)
+						{
+							if ((FADE_WIDTH - 1) - gFade.count == x)
+								gFade.flag[y][x] = TRUE;
+						}
 					}
-				}
-				break;
-				
-			case 1:
-				for (int y = 0; y < FADE_HEIGHT; y++)
-				{
-					for (int x = 0; x < FADE_WIDTH; x++)
+					break;
+					
+				case 2:
+					for (y = 0; y < FADE_HEIGHT; y++)
 					{
-						if ((FADE_HEIGHT - 1) - gFade.count == y)
-							gFade.flag[y][x] = 1;
+						for (x = 0; x < FADE_WIDTH; x++)
+						{
+							if (gFade.count == x)
+								gFade.flag[y][x] = TRUE;
+						}
 					}
-				}
-				break;
-				
-			case 2:
-				for (int y = 0; y < FADE_HEIGHT; y++)
-				{
-					for (int x = 0; x < FADE_WIDTH; x++)
+					break;
+					
+				case 1:
+					for (y = 0; y < FADE_HEIGHT; y++)
 					{
-						if (gFade.count == x)
-							gFade.flag[y][x] = 1;
+						for (x = 0; x < FADE_WIDTH; x++)
+						{
+							if ((FADE_HEIGHT - 1) - gFade.count == y)
+								gFade.flag[y][x] = TRUE;
+						}
 					}
-				}
-				break;
-				
-			case 3:
-				for (int y = 0; y < FADE_HEIGHT; y++)
-				{
-					for (int x = 0; x < FADE_WIDTH; x++)
+					break;
+					
+				case 3:
+					for (y = 0; y < FADE_HEIGHT; y++)
 					{
-						if (gFade.count == y)
-							gFade.flag[y][x] = 1;
+						for (x = 0; x < FADE_WIDTH; x++)
+						{
+							if (gFade.count == y)
+								gFade.flag[y][x] = TRUE;
+						}
 					}
-				}
-				break;
-				
-			case 4:
-				for (int y = 0; y < (FADE_HEIGHT / 2); y++)
-				{
-					for (int x = 0; x < (FADE_WIDTH / 2); x++)
+					break;
+					
+				case 4:
+					for (y = 0; y < (FADE_HEIGHT / 2); y++)
 					{
-						if (gFade.count == x + y)
-							gFade.flag[y][x] = 1;
+						for (x = 0; x < (FADE_WIDTH / 2); x++)
+						{
+							if ((FADE_WIDTH - 1) - gFade.count == x + y)
+								gFade.flag[y][x] = TRUE;
+						}
 					}
-				}
-				for (int y = 0; y < (FADE_HEIGHT / 2); y++)
-				{
-					for (int x = (FADE_WIDTH / 2); x < FADE_WIDTH; x++)
+					for (y = 0; y < (FADE_HEIGHT / 2); y++)
 					{
-						if (gFade.count == y + ((FADE_WIDTH - 1) - x))
-							gFade.flag[y][x] = 1;
+						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 (int y = (FADE_HEIGHT / 2); y < FADE_HEIGHT; y++)
-				{
-					for (int x = 0; x < (FADE_WIDTH / 2); x++)
+					for (y = (FADE_HEIGHT / 2); y < FADE_HEIGHT; y++)
 					{
-						if (gFade.count == x + ((FADE_HEIGHT - 1) - y))
-							gFade.flag[y][x] = 1;
+						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 (int y = (FADE_HEIGHT / 2); y < FADE_HEIGHT; y++)
-				{
-					for (int x = (FADE_WIDTH / 2); x < FADE_WIDTH; x++)
+					for (y = (FADE_HEIGHT / 2); y < FADE_HEIGHT; y++)
 					{
-						if (gFade.count == ((FADE_WIDTH - 1) - x) + ((FADE_HEIGHT - 1) - y))
-							gFade.flag[y][x] = 1;
+						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 (int y = 0; y < FADE_HEIGHT; y++)
-		{
-			for (int x = 0; x < FADE_WIDTH; x++)
+					break;
+					
+				default:
+					break;
+			}
+			
+			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] > 0 && 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.mode = 0;
+
+			break;
 	}
 }
 
@@ -274,23 +299,28 @@
 	
 	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;
 }
--- a/src/Fade.h
+++ b/src/Fade.h
@@ -1,20 +1,7 @@
 #pragma once
 
-#include "CommonDefines.h"
+#include "WindowsWrapper.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;
-};
-
 void InitFade();
 void SetFadeMask();
 void ClearFade();
@@ -22,4 +9,4 @@
 void StartFadeIn(char dir);
 void ProcFade();
 void PutFade();
-bool GetFadeActive();
+BOOL GetFadeActive();
--- a/src/Flags.cpp
+++ b/src/Flags.cpp
@@ -1,11 +1,12 @@
 #include "Flags.h"
 
-#include <stdint.h>
 #include <string.h>
 
-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 @@
 }
 
 //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;
 }
--- a/src/Flags.h
+++ b/src/Flags.h
@@ -1,15 +1,15 @@
 #pragma once
 
-#include <stdint.h>
+#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);
--- a/src/Flash.cpp
+++ b/src/Flash.cpp
@@ -21,7 +21,7 @@
 
 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(int flx, int fly)
 {
 	if (flash.flag == FALSE)
+		return;
+
+	switch (flash.mode)
 	{
-		// Do nothing
+		case 1:
+			ActFlash_Explosion(flx, fly);
+			break;
+		case 2:
+			ActFlash_Flash();
+			break;
 	}
-	else
-	{
-		switch (flash.mode)
-		{
-			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)
--- a/src/Font.cpp
+++ b/src/Font.cpp
@@ -1,6 +1,5 @@
 #include "Font.h"
 
-#include <stdbool.h>
 #include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
--- a/src/Game.cpp
+++ b/src/Game.cpp
@@ -1,6 +1,7 @@
 #include "Game.h"
 
 #include <stdlib.h>
+#include <stdio.h>
 #include <string.h>
 
 #include <SDL_timer.h>
@@ -266,6 +267,7 @@
 	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 @@
 			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 frame_x = 0;
 	int frame_y = 0;
-	
+
+	unsigned long color = GetCortBoxColor(RGB(0, 0, 0x20));
+
 	bool swPlay = true;
 	
 	//Reset stuff
@@ -524,7 +528,7 @@
 			}
 			
 			ProcFade();
-			CortBox(&grcFull, 0x000020);
+			CortBox(&grcFull, color);
 			GetFramePosition(&frame_x, &frame_y);
 			PutBack(frame_x, frame_y);
 			PutStage_Back(frame_x, frame_y);
--- a/src/Input.cpp
+++ b/src/Input.cpp
@@ -2,6 +2,7 @@
 
 #include <stddef.h>
 #include <stdint.h>
+#include <string.h>
 
 #include <SDL.h>
 
--- a/src/MapName.cpp
+++ b/src/MapName.cpp
@@ -36,8 +36,8 @@
 	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 @@
 	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);
 }
--- a/src/NpChar.cpp
+++ b/src/NpChar.cpp
@@ -239,9 +239,10 @@
 {
 	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 @@
 	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++)
 	{
--- a/src/Organya.cpp
+++ b/src/Organya.cpp
@@ -2,6 +2,7 @@
 
 #include <stddef.h>
 #include <stdint.h>
+#include <string.h>
 
 #include <SDL_rwops.h>
 #include <SDL_thread.h>
--- a/src/Sound.cpp
+++ b/src/Sound.cpp
@@ -1,7 +1,7 @@
 #include "Sound.h"
 
 #include <algorithm>
-#include <math.h>
+#include <cmath>
 #include <stdint.h>
 #include <string>
 
--- a/src/TextScr.cpp
+++ b/src/TextScr.cpp
@@ -46,9 +46,17 @@
 
 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 @@
 	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 @@
 		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 @@
 						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 @@
 						}
 						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);
--- a/src/Triangle.cpp
+++ b/src/Triangle.cpp
@@ -8,19 +8,19 @@
 
 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 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)
+	else
 	{
-		if (-ya >= xa)
+		if (y > 0)
 		{
-			while (gTan[a] < (int16_t)((xa << 13) / -ya))
-				++a;
-			a -= 0x40;
+			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
 		{
-			while (gTan[a] < (int16_t)(-0x2000 * ya / xa))
-				++a;
-			a = -a;
+			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;
+			}
 		}
-	}
-	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;
 	}
 	
 	return a;
--- 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);
--- a/src/WindowsWrapper.h
+++ b/src/WindowsWrapper.h
@@ -4,6 +4,7 @@
 void rep_srand(unsigned int seed);
 
 typedef int BOOL;
+typedef unsigned char BOOLEAN;
 
 #ifndef FALSE
 #define FALSE 0