shithub: cstory

Download patch

ref: f9d62f38efc3b00d86151d09431264ea955104e6
parent: 7578abafc5128ecf92c8911e0b15e3f868b7f152
parent: 44094b103e5df0857ef0267c388b972705b60050
author: Gabriel Ravier <[email protected]>
date: Wed Jun 12 15:44:23 EDT 2019

Merge pull request #23 from Clownacy/master

Merge Clownacy/master into master

--- a/.gitignore
+++ b/.gitignore
@@ -16,13 +16,13 @@
 
 # Exclude build output on Linux (exclude normally produced executable files and out files)
 build_en/CSE2
-build_en/CSE2d
+build_en/CSE2_debug
 build_en/DoConfig
-build_en/DoConfigd
+build_en/DoConfig_debug
 build_jp/CSE2
-build_jp/CSE2d
+build_jp/CSE2_debug
 build_jp/DoConfig
-build_jp/DoConfigd
+build_jp/DoConfig_debug
 build_en/*.out
 build_jp/*.out
 
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -263,10 +263,7 @@
 endif()
 
 # Magic to convert resources to header files
-add_executable(bin2h "src/misc/bin2h.c")
-if(MSVC)
-	target_compile_definitions(bin2h PRIVATE _CRT_SECURE_NO_WARNINGS)	# Shut up those stupid warnings
-endif()
+add_subdirectory("bin2h")
 foreach(FILENAME IN LISTS RESOURCES)
 	set(IN_DIR "${CMAKE_CURRENT_SOURCE_DIR}/res")
 	set(OUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/Resource")
@@ -294,10 +291,8 @@
 	CXX_EXTENSIONS OFF
 )
 
-# Name debug builds "CSE2d", to distinguish them
-set_target_properties(CSE2 PROPERTIES
-	DEBUG_OUTPUT_NAME "CSE2d"
-)
+# Name debug builds "CSE2_debug", to distinguish them
+set_target_properties(CSE2 PROPERTIES DEBUG_OUTPUT_NAME "CSE2_debug")
 
 # Send executable to the build_en/build_jp directory
 set_target_properties(CSE2 PROPERTIES
@@ -371,6 +366,9 @@
 ##
 
 add_subdirectory("DoConfig")
+
+# Name debug builds "DoConfig_debug", to distinguish them
+set_target_properties(DoConfig PROPERTIES DEBUG_OUTPUT_NAME "DoConfig_debug")
 
 # Send executable to the build_en/build_jp directory
 set_target_properties(DoConfig PROPERTIES
--- a/DoConfig/CMakeLists.txt
+++ b/DoConfig/CMakeLists.txt
@@ -10,9 +10,6 @@
 
 add_executable(DoConfig "DoConfig.cpp" "icon.rc")
 
-# Name debug builds "DoConfigd", to distinguish them
-set_target_properties(CSE2 PROPERTIES DEBUG_OUTPUT_NAME "DoConfigd")
-
 # Windows tweak
 if(WIN32)
 	set_target_properties(DoConfig PROPERTIES WIN32_EXECUTABLE YES)	# Disable the console window
--- a/DoConfig/DoConfig.cpp
+++ b/DoConfig/DoConfig.cpp
@@ -5,14 +5,17 @@
  * http://sam.zoy.org/wtfpl/COPYING for more details. */
 
 #include <cstdlib>
-#include <iostream>
 #include <fstream>
-#include <cstring>
 #include "FL/Fl.H"
 #include "FL/Fl_Window.H"
 #include "FL/Fl_Radio_Round_Button.H"
 #include "FL/Fl_Choice.H"
 #include "FL/Fl_Check_Button.H"
+#include <FL/Fl_Button.H>
+#include <FL/Fl_Group.H>
+#include <FL/Fl_Menu_Item.H>
+#include <FL/Fl_Round_Button.H>
+#include <FL/Enumerations.H>
 
 #define MAGIC "DOUKUTSU20041206"
 #define FONT "Courier New"
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@
 	FILENAME_DEF = CSE2
 else
 	CXXFLAGS = -Og -g3
-	FILENAME_DEF = CSE2d
+	FILENAME_DEF = CSE2_debug
 endif
 
 ifeq ($(JAPANESE), 1)
@@ -226,10 +226,10 @@
 	@echo Converting $<
 	@obj/bin2h $< $@
 
-obj/bin2h: src/misc/bin2h.c
+obj/bin2h: bin2h/bin2h.c
 	@mkdir -p $(@D)
 	@echo Compiling $^
-	@$(CC) -O3 -s -std=c90 $^ -o $@
+	@$(CC) -O3 -s -std=c90 -Wall -Wextra -pedantic $^ -o $@
 
 include $(wildcard $(DEPENDENCIES))
 
--- /dev/null
+++ b/bin2h/CMakeLists.txt
@@ -1,0 +1,31 @@
+cmake_minimum_required(VERSION 3.7.2)
+
+if((${CMAKE_VERSION} VERSION_EQUAL 3.9) OR (${CMAKE_VERSION} VERSION_GREATER 3.9))
+	cmake_policy(SET CMP0069 NEW)
+endif()
+
+project(bin2h LANGUAGES C)
+
+add_executable(bin2h "bin2h.c")
+
+set_target_properties(bin2h PROPERTIES
+	C_STANDARD 90
+	C_STANDARD_REQUIRED ON
+	C_EXTENSIONS OFF
+)
+
+# MSVC tweak
+if(MSVC)
+	target_compile_definitions(bin2h PRIVATE _CRT_SECURE_NO_WARNINGS)	# Shut up those stupid warnings
+endif()
+
+# Enable link-time optimisation if available
+if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
+	if((${CMAKE_VERSION} VERSION_EQUAL 3.9) OR (${CMAKE_VERSION} VERSION_GREATER 3.9))
+		include(CheckIPOSupported)
+		check_ipo_supported(RESULT result)
+		if(result)
+			set_target_properties(bin2h PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
+		endif()
+	endif()
+endif()
--- /dev/null
+++ b/bin2h/bin2h.c
@@ -1,0 +1,92 @@
+/*Bin2h by -C-u-c-k-y- Clownypants*/
+/*Converts files to the .h's expected by Cave Story Engine for resources.*/
+
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int main(int argc, char *argv[])
+{
+	int result = 0;
+
+	if (argc > 2)
+	{
+		char *last_forward_slash;
+		char *last_back_slash;
+		char *last_path_seperator;
+		char *filename_pointer;
+		char *dot;
+		size_t filename_length;
+		char *filename;
+		FILE *in_file;
+		FILE *out_file;
+
+		last_forward_slash = strrchr(argv[1], '/');
+		last_back_slash = strrchr(argv[1], '\\');
+
+		last_path_seperator = last_forward_slash > last_back_slash ? last_forward_slash : last_back_slash;
+
+		filename_pointer = (last_path_seperator == NULL) ? argv[1] : last_path_seperator + 1;
+		dot = strchr(filename_pointer, '.');
+		filename_length = (dot == NULL) ? strlen(filename_pointer) : (size_t)(dot - filename_pointer);
+
+		filename = malloc(filename_length + 1);
+		memcpy(filename, filename_pointer, filename_length);
+		filename[filename_length] = '\0';
+
+		in_file = fopen(argv[1], "rb");
+		out_file = fopen(argv[2], "w");
+
+		if (in_file == NULL)
+		{
+			printf("Couldn't open '%s'\n", argv[1]);
+			result = 1;
+		}
+		else if (out_file == NULL)
+		{
+			printf("Couldn't open '%s'\n", argv[2]);
+			result = 1;
+		}
+		else
+		{
+			long in_file_size;
+			unsigned char *in_file_buffer;
+			unsigned char *in_file_pointer;
+			long i;
+
+			fseek(in_file, 0, SEEK_END);
+			in_file_size = ftell(in_file);
+			rewind(in_file);
+			in_file_buffer = malloc(in_file_size);
+			fread(in_file_buffer, 1, in_file_size, in_file);
+			fclose(in_file);
+			in_file_pointer = in_file_buffer;
+
+			setvbuf(out_file, NULL, _IOFBF, 0x10000);
+
+			fprintf(out_file, "#pragma once\n\nstatic const unsigned char r%s[0x%lX] = {\n\t", filename, in_file_size);
+
+			for (i = 0; i < in_file_size - 1; ++i)
+			{
+				if (i % 32 == 32-1)
+					fprintf(out_file, "%d,\n\t", *in_file_pointer++);
+				else
+					fprintf(out_file, "%d,", *in_file_pointer++);
+			}
+
+			fprintf(out_file, "%d\n};\n", *in_file_pointer++);
+
+			fclose(out_file);
+			free(in_file_buffer);
+		}
+
+		free(filename);
+	}
+	else
+	{
+		result = 1;
+	}
+
+	return result;
+}
--- a/src/Back.cpp
+++ b/src/Back.cpp
@@ -1,9 +1,11 @@
 #include "Back.h"
 
+#include <stddef.h>
 #include <stdio.h>
 
 #include "WindowsWrapper.h"
 
+#include "CommonDefines.h"
 #include "Draw.h"
 #include "File.h"
 #include "Frame.h"
@@ -250,7 +252,7 @@
 	// Draw black bars
 	if (!(g_GameFlags & 8)) // Detect if credits are running
 	{
-		const bool fromFocus = (gStageNo == 31); // Get if we should only draw around a 320x240 area of the focus point
+		const BOOL fromFocus = (gStageNo == 31); // Get if we should only draw around a 320x240 area of the focus point
 
 		// Get focus rect
 		int focusX = gFrame.x + (WINDOW_WIDTH << 8) - (320 << 8);
--- a/src/BossIronH.cpp
+++ b/src/BossIronH.cpp
@@ -6,6 +6,7 @@
 #include "Frame.h"
 #include "Game.h"
 #include "MyChar.h"
+#include "NpChar.h"
 #include "Sound.h"
 
 void ActBossChar_Ironhead(void)
--- a/src/BossPress.cpp
+++ b/src/BossPress.cpp
@@ -5,6 +5,7 @@
 #include "Boss.h"
 #include "Game.h"
 #include "Map.h"
+#include "NpChar.h"
 #include "Sound.h"
 
 void ActBossChar_Press(void)
--- a/src/BulHit.cpp
+++ b/src/BulHit.cpp
@@ -1,13 +1,9 @@
 #include "BulHit.h"
 
-#include <stdio.h>
-#include <string.h>
-
 #include "Bullet.h"
 #include "Caret.h"
 #include "Game.h"
 #include "Map.h"
-#include "MyChar.h"
 #include "NpChar.h"
 #include "Sound.h"
 
--- a/src/Config.cpp
+++ b/src/Config.cpp
@@ -8,7 +8,6 @@
 #include "Config.h"
 #include "File.h"
 #include "Tags.h"
-#include "Types.h"
 
 static const char* const config_filename = "Config.dat";	// Not the original name
 static const char* const config_magic = "DOUKUTSU20041206";	// Not the original name
--- a/src/Draw.cpp
+++ b/src/Draw.cpp
@@ -1,5 +1,8 @@
 #include <stddef.h>
 #include <stdio.h>
+#ifdef WINDOWS
+#include <stdlib.h>
+#endif
 #include <string.h>
 
 #ifdef WINDOWS
@@ -23,12 +26,11 @@
 #include "Font.h"
 #include "Resource.h"
 #include "Tags.h"
-#include "Types.h"
 
 struct SURFACE
 {
-	bool in_use;
-	bool needs_updating;
+	BOOL in_use;
+	BOOL needs_updating;
 	SDL_Surface *surface;
 	SDL_Texture *texture;
 };
@@ -40,7 +42,7 @@
 RECT grcFull = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT};
 
 int magnification;
-bool fullscreen;
+BOOL fullscreen;
 
 SURFACE surf[SURFACE_ID_MAX];
 
@@ -52,7 +54,7 @@
 {
 	(void)hWnd;
 
-	while (true)
+	while (TRUE)
 	{
 		if (!SystemTask())
 			return FALSE;
@@ -99,17 +101,17 @@
 		{
 			case 0:
 				magnification = 1;
-				fullscreen = false;
+				fullscreen = FALSE;
 				break;
 
 			case 1:
 				magnification = 2;
-				fullscreen = false;
+				fullscreen = FALSE;
 				break;
 
 			case 2:
 				magnification = 2;
-				fullscreen = true;
+				fullscreen = TRUE;
 				SDL_SetWindowFullscreen(gWindow, SDL_WINDOW_FULLSCREEN);
 				break;
 		}
@@ -129,7 +131,7 @@
 		ReleaseSurface(i);
 }
 
-static bool IsEnableBitmap(SDL_RWops *fp)
+static BOOL IsEnableBitmap(SDL_RWops *fp)
 {
 	char str[16];
 	const char *extra_text = "(C)Pixel";
@@ -149,7 +151,7 @@
 	{
 		SDL_DestroyTexture(surf[s].texture);
 		SDL_FreeSurface(surf[s].surface);
-		surf[s].in_use = false;
+		surf[s].in_use = FALSE;
 	}
 }
 
@@ -169,7 +171,7 @@
 	}
 	else
 	{
-		if (surf[surf_no].in_use == true)
+		if (surf[surf_no].in_use == TRUE)
 		{
 			printf("Tried to create drawable surface at occupied slot (%d)\n", surf_no);
 		}
@@ -194,7 +196,7 @@
 				}
 				else
 				{
-					surf[surf_no].in_use = true;
+					surf[surf_no].in_use = TRUE;
 					success = TRUE;
 				}
 			}
@@ -231,9 +233,9 @@
 	SDL_UnlockTexture(surf[surf_no].texture);
 }
 
-static bool LoadBitmap(SDL_RWops *fp, Surface_Ids surf_no, bool create_surface)
+static BOOL LoadBitmap(SDL_RWops *fp, Surface_Ids surf_no, BOOL create_surface)
 {
-	bool success = false;
+	BOOL success = FALSE;
 
 	if (surf_no >= SURFACE_ID_MAX)
 	{
@@ -255,15 +257,15 @@
 			}
 			else
 			{
-				if (create_surface == false || MakeSurface_Generic(surface->w, surface->h, surf_no, FALSE))
+				if (create_surface == FALSE || MakeSurface_Generic(surface->w, surface->h, surf_no, FALSE))
 				{
 					if (magnification == 1)
 					{
 						SDL_Rect dst_rect = {0, 0, surface->w, surface->h};
 						SDL_BlitSurface(surface, NULL, surf[surf_no].surface, &dst_rect);
-						surf[surf_no].needs_updating = true;
+						surf[surf_no].needs_updating = TRUE;
 						printf(" ^ Successfully loaded\n");
-						success = true;
+						success = TRUE;
 					}
 					else
 					{
@@ -301,9 +303,9 @@
 							}
 
 							SDL_FreeSurface(converted_surface);
-							surf[surf_no].needs_updating = true;
+							surf[surf_no].needs_updating = TRUE;
 							printf(" ^ Successfully loaded\n");
-							success = true;
+							success = TRUE;
 						}
 					}
 				}
@@ -318,7 +320,7 @@
 	return success;
 }
 
-static BOOL LoadBitmap_File(const char *name, Surface_Ids surf_no, bool create_surface)
+static BOOL LoadBitmap_File(const char *name, Surface_Ids surf_no, BOOL create_surface)
 {
 	char path[PATH_LENGTH];
 	SDL_RWops *fp;
@@ -355,7 +357,7 @@
 	return FALSE;
 }
 
-static BOOL LoadBitmap_Resource(const char *res, Surface_Ids surf_no, bool create_surface)
+static BOOL LoadBitmap_Resource(const char *res, Surface_Ids surf_no, BOOL create_surface)
 {
 	size_t size;
 	const unsigned char *data = FindResource(res, "BITMAP", &size);
@@ -378,22 +380,22 @@
 
 BOOL MakeSurface_File(const char *name, Surface_Ids surf_no)
 {
-	return LoadBitmap_File(name, surf_no, true);
+	return LoadBitmap_File(name, surf_no, TRUE);
 }
 
 BOOL MakeSurface_Resource(const char *res, Surface_Ids surf_no)
 {
-	return LoadBitmap_Resource(res, surf_no, true);
+	return LoadBitmap_Resource(res, surf_no, TRUE);
 }
 
 BOOL ReloadBitmap_File(const char *name, Surface_Ids surf_no)
 {
-	return LoadBitmap_File(name, surf_no, false);
+	return LoadBitmap_File(name, surf_no, FALSE);
 }
 
 BOOL ReloadBitmap_Resource(const char *res, Surface_Ids surf_no)
 {
-	return LoadBitmap_Resource(res, surf_no, false);
+	return LoadBitmap_Resource(res, surf_no, FALSE);
 }
 
 static SDL_Rect RectToSDLRect(RECT *rect)
@@ -431,18 +433,18 @@
 	SDL_Rect frameRect = RectToSDLRectScaled(rect);
 
 	SDL_BlitSurface(surface, &frameRect, surf[surf_no].surface, &frameRect);
-	surf[surf_no].needs_updating = true;
+	surf[surf_no].needs_updating = TRUE;
 
 	// Free surface
 	SDL_FreeSurface(surface);
 }
 
-static void DrawBitmap(RECT *rcView, int x, int y, RECT *rect, Surface_Ids surf_no, bool transparent)
+static void DrawBitmap(RECT *rcView, int x, int y, RECT *rect, Surface_Ids surf_no, BOOL transparent)
 {
 	if (surf[surf_no].needs_updating)
 	{
 		FlushSurface(surf_no);
-		surf[surf_no].needs_updating = false;
+		surf[surf_no].needs_updating = FALSE;
 	}
 
 	// Get SDL_Rects
@@ -467,12 +469,12 @@
 
 void PutBitmap3(RECT *rcView, int x, int y, RECT *rect, Surface_Ids surf_no) // Transparency
 {
-	DrawBitmap(rcView, x, y, rect, surf_no, true);
+	DrawBitmap(rcView, x, y, rect, surf_no, TRUE);
 }
 
 void PutBitmap4(RECT *rcView, int x, int y, RECT *rect, Surface_Ids surf_no) // No Transparency
 {
-	DrawBitmap(rcView, x, y, rect, surf_no, false);
+	DrawBitmap(rcView, x, y, rect, surf_no, FALSE);
 }
 
 void Surface2Surface(int x, int y, RECT *rect, int to, int from)
@@ -482,7 +484,7 @@
 	SDL_Rect frameRect = RectToSDLRectScaled(rect);
 
 	SDL_BlitSurface(surf[from].surface, &frameRect, surf[to].surface, &rcSet);
-	surf[to].needs_updating = true;
+	surf[to].needs_updating = TRUE;
 }
 
 unsigned long GetCortBoxColor(unsigned long col)
@@ -514,7 +516,7 @@
 	const unsigned char col_green = (unsigned char)((col >> 8) & 0xFF);
 	const unsigned char col_blue = (unsigned char)((col >> 16) & 0xFF);
 	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;
+	surf[surf_no].needs_updating = TRUE;
 }
 
 #ifdef WINDOWS
@@ -635,7 +637,7 @@
 void PutText2(int x, int y, const char *text, unsigned long color, Surface_Ids surf_no)
 {
 	DrawText(gFont, (unsigned char*)surf[surf_no].surface->pixels, surf[surf_no].surface->pitch, surf[surf_no].surface->w, surf[surf_no].surface->h, x * magnification, y * magnification, color, text, strlen(text));
-	surf[surf_no].needs_updating = true;
+	surf[surf_no].needs_updating = TRUE;
 }
 
 void EndTextObject()
--- a/src/Draw.h
+++ b/src/Draw.h
@@ -10,7 +10,7 @@
 extern RECT grcFull;
 
 extern int magnification;
-extern bool fullscreen;
+extern BOOL fullscreen;
 
 typedef enum Surface_Ids
 {
--- a/src/Ending.h
+++ b/src/Ending.h
@@ -2,6 +2,8 @@
 
 #include "WindowsWrapper.h"
 
+#include "CommonDefines.h"
+
 struct CREDIT
 {
 	int size;
--- a/src/Fade.cpp
+++ b/src/Fade.cpp
@@ -6,7 +6,6 @@
 #include "WindowsWrapper.h"
 
 #include "Draw.h"
-#include "Game.h"
 
 #define FADE_WIDTH	(((WINDOW_WIDTH - 1) / 16) + 1)
 #define FADE_HEIGHT	(((WINDOW_HEIGHT - 1) / 16) + 1)
--- a/src/Font.cpp
+++ b/src/Font.cpp
@@ -2,7 +2,6 @@
 
 #include <math.h>
 #include <stddef.h>
-#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -11,6 +10,8 @@
 #include FT_LCD_FILTER_H
 #include FT_BITMAP_H
 
+#include "WindowsWrapper.h"
+
 #include "File.h"
 
 // Uncomment for that authentic pre-Windows Vista feel
@@ -39,7 +40,7 @@
 	FT_Face face;
 	unsigned char *data;
 #ifndef DISABLE_FONT_ANTIALIASING
-	bool lcd_mode;
+	BOOL lcd_mode;
 #endif
 	CachedGlyph *glyph_list_head;
 } FontObject;
--- a/src/Frame.cpp
+++ b/src/Frame.cpp
@@ -1,7 +1,5 @@
 #include "Frame.h"
 
-#include <string.h>
-
 #include "Boss.h"
 #include "CommonDefines.h"
 #include "Game.h"
@@ -16,7 +14,7 @@
 	short map_w, map_l;
 	GetMapData(0, &map_w, &map_l);
 
-#if WINDOW_WIDTH != 320 || WINDOW_HEIGHT != 240	// TODO - Really need to make this a compiler flag
+#if WINDOW_WIDTH != 320 || WINDOW_HEIGHT != 240	// TODO - Really need to make this a compiler flag (also, should probably move this stuff to the enhanced branch)
 	if (g_GameFlags & 8)
 	{
 		// Use the original camera boundaries during the credits
@@ -41,7 +39,7 @@
 		// Widescreen/tallscreen-safe behaviour
 		if (map_w * 0x10 < WINDOW_WIDTH)
 		{
-			gFrame.x = -((WINDOW_WIDTH - map_w * 0x10) * 0x200 / 2);
+			gFrame.x = -(((WINDOW_WIDTH - (map_w - 1) * 0x10) * 0x200) / 2);
 		}
 		else
 		{
@@ -56,7 +54,7 @@
 
 		if (map_l * 0x10 < WINDOW_HEIGHT)
 		{
-			gFrame.y = -((WINDOW_HEIGHT - map_l * 0x10) * 0x200 / 2);
+			gFrame.y = -(((WINDOW_HEIGHT - (map_l - 1) * 0x10) * 0x200) / 2);
 		}
 		else
 		{
@@ -126,15 +124,64 @@
 	gFrame.y = fy;
 
 	// Keep in bounds
+#if WINDOW_WIDTH != 320 || WINDOW_HEIGHT != 240
+	if (g_GameFlags & 8)
+	{
+		// Use the original camera boundaries during the credits
+		if (gFrame.x / 0x200 < 0)
+			gFrame.x = 0;
+		if (gFrame.y / 0x200 < 0)
+			gFrame.y = 0;
+
+		if (gFrame.x > ((map_w - 1) * 0x10 - 320) * 0x200)
+			gFrame.x = ((map_w - 1) * 0x10 - 320) * 0x200;
+		if (gFrame.y > ((map_l - 1) * 0x10 - 240) * 0x200)
+			gFrame.y = ((map_l - 1) * 0x10 - 240) * 0x200;
+
+		gFrame.x -= ((WINDOW_WIDTH - 320) / 2) * 0x200;
+		gFrame.y -= ((WINDOW_HEIGHT - 240) / 2) * 0x200;
+	}
+	else
+	{
+		// Widescreen/tallscreen-safe behaviour
+		if (map_w * 0x10 < WINDOW_WIDTH)
+		{
+			gFrame.x = -(((WINDOW_WIDTH - (map_w - 1) * 0x10) * 0x200) / 2);
+		}
+		else
+		{
+			if (gFrame.x / 0x200 < 0)
+				gFrame.x = 0;
+
+			if (gFrame.x > ((map_w - 1) * 0x10 - WINDOW_WIDTH) * 0x200)
+				gFrame.x = ((map_w - 1) * 0x10 - WINDOW_WIDTH) * 0x200;
+		}
+
+		if (map_l * 0x10 < WINDOW_HEIGHT)
+		{
+			gFrame.y = -(((WINDOW_HEIGHT - (map_l - 1) * 0x10) * 0x200) / 2);
+		}
+		else
+		{
+			if (gFrame.y / 0x200 < 0)
+				gFrame.y = 0;
+
+			if (gFrame.y > ((map_l - 1) * 0x10 - WINDOW_HEIGHT) * 0x200)
+				gFrame.y = ((map_l - 1) * 0x10 - WINDOW_HEIGHT) * 0x200;
+		}
+	}
+#else
+	// Vanilla behaviour
 	if (gFrame.x / 0x200 < 0)
 		gFrame.x = 0;
 	if (gFrame.y / 0x200 < 0)
 		gFrame.y = 0;
 
-	if (gFrame.x > ((((map_w - 1) * 0x10) - WINDOW_WIDTH)) * 0x200)
+	if (gFrame.x > (((map_w - 1) * 0x10) - WINDOW_WIDTH) * 0x200)
 		gFrame.x = (((map_w - 1) * 0x10) - WINDOW_WIDTH) * 0x200;
-	if (gFrame.y > ((((map_l - 1) * 0x10) - WINDOW_HEIGHT)) * 0x200)
+	if (gFrame.y > (((map_l - 1) * 0x10) - WINDOW_HEIGHT) * 0x200)
 		gFrame.y = (((map_l - 1) * 0x10) - WINDOW_HEIGHT) * 0x200;
+#endif
 }
 
 void SetFrameMyChar()
@@ -150,15 +197,64 @@
 	gFrame.y = mc_y - (WINDOW_HEIGHT << 8);
 
 	// Keep in bounds
+#if WINDOW_WIDTH != 320 || WINDOW_HEIGHT != 240
+	if (g_GameFlags & 8)
+	{
+		// Use the original camera boundaries during the credits
+		if (gFrame.x / 0x200 < 0)
+			gFrame.x = 0;
+		if (gFrame.y / 0x200 < 0)
+			gFrame.y = 0;
+
+		if (gFrame.x > ((map_w - 1) * 0x10 - 320) * 0x200)
+			gFrame.x = ((map_w - 1) * 0x10 - 320) * 0x200;
+		if (gFrame.y > ((map_l - 1) * 0x10 - 240) * 0x200)
+			gFrame.y = ((map_l - 1) * 0x10 - 240) * 0x200;
+
+		gFrame.x -= ((WINDOW_WIDTH - 320) / 2) * 0x200;
+		gFrame.y -= ((WINDOW_HEIGHT - 240) / 2) * 0x200;
+	}
+	else
+	{
+		// Widescreen/tallscreen-safe behaviour
+		if (map_w * 0x10 < WINDOW_WIDTH)
+		{
+			gFrame.x = -(((WINDOW_WIDTH - (map_w - 1) * 0x10) * 0x200) / 2);
+		}
+		else
+		{
+			if (gFrame.x / 0x200 < 0)
+				gFrame.x = 0;
+
+			if (gFrame.x > ((map_w - 1) * 0x10 - WINDOW_WIDTH) * 0x200)
+				gFrame.x = ((map_w - 1) * 0x10 - WINDOW_WIDTH) * 0x200;
+		}
+
+		if (map_l * 0x10 < WINDOW_HEIGHT)
+		{
+			gFrame.y = -(((WINDOW_HEIGHT - (map_l - 1) * 0x10) * 0x200) / 2);
+		}
+		else
+		{
+			if (gFrame.y / 0x200 < 0)
+				gFrame.y = 0;
+
+			if (gFrame.y > ((map_l - 1) * 0x10 - WINDOW_HEIGHT) * 0x200)
+				gFrame.y = ((map_l - 1) * 0x10 - WINDOW_HEIGHT) * 0x200;
+		}
+	}
+#else
+	// Vanilla behaviour
 	if (gFrame.x / 0x200 < 0)
 		gFrame.x = 0;
 	if (gFrame.y / 0x200 < 0)
 		gFrame.y = 0;
 
-	if (gFrame.x > ((((map_w - 1) * 0x10) - WINDOW_WIDTH)) * 0x200)
+	if (gFrame.x > (((map_w - 1) * 0x10) - WINDOW_WIDTH) * 0x200)
 		gFrame.x = (((map_w - 1) * 0x10) - WINDOW_WIDTH) * 0x200;
-	if (gFrame.y > ((((map_l - 1) * 0x10) - WINDOW_HEIGHT)) * 0x200)
+	if (gFrame.y > (((map_l - 1) * 0x10) - WINDOW_HEIGHT) * 0x200)
 		gFrame.y = (((map_l - 1) * 0x10) - WINDOW_HEIGHT) * 0x200;
+#endif
 }
 
 void SetFrameTargetMyChar(int wait)
--- a/src/Game.cpp
+++ b/src/Game.cpp
@@ -1,8 +1,7 @@
 #include "Game.h"
 
-#include <stdlib.h>
+#include <stddef.h>
 #include <stdio.h>
-#include <string.h>
 
 #include <SDL_timer.h>
 
@@ -15,6 +14,7 @@
 #include "BulHit.h"
 #include "Bullet.h"
 #include "Caret.h"
+#include "CommonDefines.h"
 #include "Draw.h"
 #include "Ending.h"
 #include "Escape.h"
@@ -35,7 +35,6 @@
 #include "NpChar.h"
 #include "NpcHit.h"
 #include "NpcTbl.h"
-#include "Organya.h"
 #include "Profile.h"
 #include "SelStage.h"
 #include "Shoot.h"
--- a/src/Input.cpp
+++ b/src/Input.cpp
@@ -3,14 +3,10 @@
 #include <stddef.h>
 #include <string.h>
 
-#include <SDL.h>
+#include "SDL.h"
 
 #include "WindowsWrapper.h"
 
-#include "CommonDefines.h"
-#include "Tags.h"
-#include "Types.h"
-
 #define JOYSTICK_DEADZONE 10000
 
 SDL_Joystick *joystick; // This was probably a name that was given by Simon, but it fits the rest of Pixel's names so it's fine.
@@ -26,7 +22,7 @@
 	}
 }
 
-bool InitDirectInput()
+BOOL InitDirectInput()
 {
 	// Open first available joystick
 	SDL_InitSubSystem(SDL_INIT_JOYSTICK);
@@ -40,10 +36,10 @@
 			break;
 	}
 
-	return true;
+	return TRUE;
 }
 
-bool GetJoystickStatus(JOYSTICK_STATUS *pStatus)
+BOOL GetJoystickStatus(JOYSTICK_STATUS *pStatus)
 {
 	// Clear status
 	memset(pStatus, 0, sizeof(JOYSTICK_STATUS));
@@ -64,13 +60,13 @@
 		for (int button = 0; button < numButtons; button++)
 			pStatus->bButton[button] = SDL_JoystickGetButton(joystick, button) != 0;
 
-		return true;
+		return TRUE;
 	}
 
-	return false;
+	return FALSE;
 }
 
-bool ResetJoystickStatus()
+BOOL ResetJoystickStatus()
 {
-	return true;
+	return TRUE;
 }
--- a/src/Input.h
+++ b/src/Input.h
@@ -1,18 +1,20 @@
 #pragma once
 
-extern bool gbUseJoystick;
+#include "WindowsWrapper.h"
+
+extern BOOL gbUseJoystick;
 extern int gJoystickButtonTable[8];
 
 struct JOYSTICK_STATUS
 {
-	bool bLeft;
-	bool bRight;
-	bool bUp;
-	bool bDown;
-	bool bButton[32];
+	BOOL bLeft;
+	BOOL bRight;
+	BOOL bUp;
+	BOOL bDown;
+	BOOL bButton[32];
 };
 
 void ReleaseDirectInput();
-bool InitDirectInput();
-bool GetJoystickStatus(JOYSTICK_STATUS *pStatus);
-bool ResetJoystickStatus();
+BOOL InitDirectInput();
+BOOL GetJoystickStatus(JOYSTICK_STATUS *pStatus);
+BOOL ResetJoystickStatus();
--- a/src/Main.cpp
+++ b/src/Main.cpp
@@ -4,7 +4,7 @@
 #include <stdio.h>
 #include <string.h>
 
-#include <SDL.h>
+#include "SDL.h"
 
 #include "WindowsWrapper.h"
 
@@ -21,7 +21,6 @@
 #include "Resource.h"
 #include "Sound.h"
 #include "Triangle.h"
-#include "Types.h"
 
 // These two are defined in Draw.cpp. This is a bit of a hack.
 extern SDL_Window *gWindow;
@@ -33,10 +32,10 @@
 int gJoystickButtonTable[8];
 
 int ghWnd;	// Placeholder until we restore the WinAPI code
-bool gbUseJoystick = false;
-bool bFps = false;
+BOOL gbUseJoystick = FALSE;
+BOOL bFps = FALSE;
 
-bool bActive = true;
+BOOL bActive = TRUE;
 
 #ifdef JAPANESE
 const char *lpWindowName = "洞窟物語エンジン2";
@@ -68,7 +67,7 @@
 int GetFramePerSecound()
 {
 	unsigned int current_tick;
-	static bool need_new_base_tick = true;
+	static BOOL need_new_base_tick = TRUE;
 	static int frames_this_second;
 	static int current_frame;
 	static int base_tick;
@@ -76,7 +75,7 @@
 	if (need_new_base_tick)
 	{
 		base_tick = SDL_GetTicks();
-		need_new_base_tick = false;
+		need_new_base_tick = FALSE;
 	}
 
 	current_tick = SDL_GetTicks();
@@ -299,7 +298,7 @@
 
 					StartDirectDraw(2, colourDepth);
 
-					fullscreen = true;
+					fullscreen = TRUE;
 					SDL_ShowCursor(0);
 					break;
 				}
@@ -313,7 +312,7 @@
 		{
 			// Check debug things
 			if (CheckFileExists("fps"))
-				bFps = true;
+				bFps = TRUE;
 
 #ifndef WINDOWS
 			// Load icon
@@ -359,7 +358,7 @@
 				if (config.bJoystick && InitDirectInput())
 				{
 					ResetJoystickStatus();
-					gbUseJoystick = true;
+					gbUseJoystick = TRUE;
 				}
 
 				// Initialize stuff
@@ -390,7 +389,7 @@
 {
 	if (bActive)
 	{
-		bActive = false;
+		bActive = FALSE;
 		StopOrganyaMusic();
 		SleepNoise();
 	}
@@ -402,7 +401,7 @@
 {
 	if (!bActive)
 	{
-		bActive = true;
+		bActive = TRUE;
 		StopOrganyaMusic();
 		PlayOrganyaMusic();
 		ResetNoise();
@@ -446,10 +445,10 @@
 		gKey &= ~key; \
 	break;
 
-bool SystemTask()
+BOOL SystemTask()
 {
 	// Handle window events
-	bool focusGained = true;
+	BOOL focusGained = TRUE;
 
 	while (SDL_PollEvent(NULL) || !focusGained)
 	{
@@ -459,7 +458,7 @@
 		switch (event.type)
 		{
 			case SDL_QUIT:
-				return false;
+				return FALSE;
 				break;
 
 			case SDL_WINDOWEVENT:
@@ -466,12 +465,12 @@
 				switch (event.window.event)
 				{
 					case SDL_WINDOWEVENT_FOCUS_GAINED:
-						focusGained = true;
+						focusGained = TRUE;
 						ActiveWindow();
 						break;
 
 					case SDL_WINDOWEVENT_FOCUS_LOST:
-						focusGained = false;
+						focusGained = FALSE;
 						InactiveWindow();
 						break;
 
@@ -552,7 +551,7 @@
 						DO_KEY_PRESS(KEY_PLUS)
 
 					case SDL_SCANCODE_F5:
-						gbUseJoystick = false;
+						gbUseJoystick = FALSE;
 						break;
 
 					default:
@@ -621,7 +620,7 @@
 						DO_KEY_PRESS(KEY_PLUS)
 
 					case SDLK_F5:
-						gbUseJoystick = false;
+						gbUseJoystick = FALSE;
 						break;
 				}
 				break;
@@ -633,5 +632,5 @@
 	if (gbUseJoystick)
 		JoystickProc();
 
-	return true;
+	return TRUE;
 }
--- a/src/Map.cpp
+++ b/src/Map.cpp
@@ -1,6 +1,7 @@
 #include "Map.h"
 
 #include <stddef.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
--- a/src/MiniMap.cpp
+++ b/src/MiniMap.cpp
@@ -7,7 +7,6 @@
 #include "CommonDefines.h"
 #include "Draw.h"
 #include "Escape.h"
-#include "Game.h"
 #include "KeyControl.h"
 #include "Main.h"
 #include "Map.h"
--- a/src/MycParam.cpp
+++ b/src/MycParam.cpp
@@ -1,5 +1,7 @@
 #include "MycParam.h"
 
+#include <stdio.h>
+
 #include "SDL.h"
 
 #include "WindowsWrapper.h"
--- a/src/NpcAct020.cpp
+++ b/src/NpcAct020.cpp
@@ -2,7 +2,6 @@
 
 #include "WindowsWrapper.h"
 
-#include "Back.h"
 #include "Caret.h"
 #include "Game.h"
 #include "Frame.h"
--- a/src/NpcAct040.cpp
+++ b/src/NpcAct040.cpp
@@ -2,7 +2,6 @@
 
 #include "WindowsWrapper.h"
 
-#include "Back.h"
 #include "Caret.h"
 #include "CommonDefines.h"
 #include "Game.h"
--- a/src/NpcAct060.cpp
+++ b/src/NpcAct060.cpp
@@ -2,8 +2,8 @@
 
 #include "WindowsWrapper.h"
 
-#include "Back.h"
 #include "CommonDefines.h"
+#include "Draw.h"
 #include "Flash.h"
 #include "Frame.h"
 #include "Game.h"
--- a/src/NpcAct100.cpp
+++ b/src/NpcAct100.cpp
@@ -2,7 +2,6 @@
 
 #include "WindowsWrapper.h"
 
-#include "Back.h"
 #include "Bullet.h"
 #include "Caret.h"
 #include "Frame.h"
@@ -10,7 +9,6 @@
 #include "MyChar.h"
 #include "NpChar.h"
 #include "Sound.h"
-#include "Triangle.h"
 
 // Grate
 void ActNpc100(NPCHAR *npc)
--- a/src/NpcAct120.cpp
+++ b/src/NpcAct120.cpp
@@ -2,7 +2,6 @@
 
 #include "WindowsWrapper.h"
 
-#include "Back.h"
 #include "Bullet.h"
 #include "Caret.h"
 #include "Frame.h"
--- a/src/NpcAct140.cpp
+++ b/src/NpcAct140.cpp
@@ -2,7 +2,6 @@
 
 #include "WindowsWrapper.h"
 
-#include "Back.h"
 #include "Bullet.h"
 #include "Caret.h"
 #include "CommonDefines.h"
--- a/src/NpcAct160.cpp
+++ b/src/NpcAct160.cpp
@@ -2,7 +2,6 @@
 
 #include "WindowsWrapper.h"
 
-#include "Back.h"
 #include "Caret.h"
 #include "CommonDefines.h"
 #include "Frame.h"
--- a/src/NpcAct200.cpp
+++ b/src/NpcAct200.cpp
@@ -2,7 +2,6 @@
 
 #include "WindowsWrapper.h"
 
-#include "Back.h"
 #include "Bullet.h"
 #include "Caret.h"
 #include "Frame.h"
--- a/src/NpcAct220.cpp
+++ b/src/NpcAct220.cpp
@@ -2,10 +2,7 @@
 
 #include "WindowsWrapper.h"
 
-#include "Back.h"
-#include "Bullet.h"
 #include "Caret.h"
-#include "Frame.h"
 #include "Game.h"
 #include "MyChar.h"
 #include "NpChar.h"
--- a/src/NpcAct240.cpp
+++ b/src/NpcAct240.cpp
@@ -2,7 +2,6 @@
 
 #include "WindowsWrapper.h"
 
-#include "Back.h"
 #include "Caret.h"
 #include "Frame.h"
 #include "Game.h"
--- a/src/NpcAct260.cpp
+++ b/src/NpcAct260.cpp
@@ -2,7 +2,6 @@
 
 #include "WindowsWrapper.h"
 
-#include "Back.h"
 #include "Caret.h"
 #include "Frame.h"
 #include "Game.h"
--- a/src/NpcAct280.cpp
+++ b/src/NpcAct280.cpp
@@ -2,7 +2,6 @@
 
 #include "WindowsWrapper.h"
 
-#include "Back.h"
 #include "Boss.h"
 #include "Frame.h"
 #include "Game.h"
--- a/src/NpcAct300.cpp
+++ b/src/NpcAct300.cpp
@@ -4,7 +4,6 @@
 
 #include "WindowsWrapper.h"
 
-#include "Back.h"
 #include "Boss.h"
 #include "Bullet.h"
 #include "Caret.h"
--- a/src/NpcAct320.cpp
+++ b/src/NpcAct320.cpp
@@ -1,8 +1,9 @@
 #include "NpcAct.h"
 
+#include <stddef.h>
+
 #include "WindowsWrapper.h"
 
-#include "Back.h"
 #include "Bullet.h"
 #include "Caret.h"
 #include "Frame.h"
@@ -12,7 +13,6 @@
 #include "MyChar.h"
 #include "NpChar.h"
 #include "Sound.h"
-#include "Triangle.h"
 
 // Curly (carried, shooting)
 void ActNpc320(NPCHAR *npc)
--- a/src/NpcAct340.cpp
+++ b/src/NpcAct340.cpp
@@ -2,9 +2,9 @@
 
 #include "WindowsWrapper.h"
 
-#include "Back.h"
 #include "Caret.h"
 #include "CommonDefines.h"
+#include "Draw.h"
 #include "Flash.h"
 #include "Flags.h"
 #include "Frame.h"
--- a/src/NpcTbl.cpp
+++ b/src/NpcTbl.cpp
@@ -3,7 +3,6 @@
 #include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
 
 #include "WindowsWrapper.h"
 
--- a/src/NpcTbl.h
+++ b/src/NpcTbl.h
@@ -2,7 +2,6 @@
 
 #include "WindowsWrapper.h"
 
-#include "Draw.h"
 #include "NpChar.h"
 
 struct NPC_TBL_RECT
--- a/src/Organya.cpp
+++ b/src/Organya.cpp
@@ -4,16 +4,12 @@
 #include <stdio.h>
 #include <string.h>
 
-#include <SDL_thread.h>
-#include <SDL_timer.h>
-#include <SDL_events.h>
+#include "SDL.h"
 
 #include "WindowsWrapper.h"
 
-#include "CommonDefines.h"
 #include "Resource.h"
 #include "Sound.h"
-#include "Tags.h"
 
 #define PANDUMMY 0xFF
 #define VOLDUMMY 0xFF
@@ -30,9 +26,9 @@
 
 int gTrackVol[MAXTRACK];
 int gOrgVolume = 100;
-bool bFadeout = false;
+BOOL bFadeout = FALSE;
 
-bool OrganyaNoteAlloc(unsigned short alloc)
+BOOL OrganyaNoteAlloc(unsigned short alloc)
 {
 	for(int j = 0; j < MAXTRACK; j++)
 	{
@@ -51,7 +47,7 @@
 				}
 			}
 
-			return false;
+			return FALSE;
 		}
 
 		for(int i = 0; i < alloc; i++)
@@ -72,7 +68,7 @@
 
 	//this->track = 0;
 
-	return true;
+	return FALSE;
 }
 
 void OrganyaReleaseNote()
@@ -109,7 +105,7 @@
 	{   8,128, 32 }, //7 Oct
 };
 
-bool MakeSoundObject8(signed char *wavep, signed char track, signed char pipi)
+BOOL MakeSoundObject8(signed char *wavep, signed char track, signed char pipi)
 {
 	for (int j = 0; j < 8; j++)
 	{
@@ -150,7 +146,7 @@
 		}
 	}
 
-	return true;
+	return TRUE;
 }
 
 //Playing melody tracks
@@ -272,17 +268,17 @@
 }
 
 //Create org wave
-bool MakeOrganyaWave(signed char track, signed char wave_no, signed char pipi)
+BOOL MakeOrganyaWave(signed char track, signed char wave_no, signed char pipi)
 {
 	if(wave_no > 99)
 	{
 		printf("WARNING: track %d has out-of-range wave_no %d\n", track, wave_no);
-		return false;
+		return FALSE;
 	}
 
 	ReleaseOrganyaObject(track);
 	MakeSoundObject8(wave_data[wave_no], track, pipi);
-	return true;
+	return TRUE;
 }
 
 //Dram
@@ -525,7 +521,7 @@
 	SetPlayPointer(0);
 
 	//Set as loaded
-	info.loaded = true;
+	info.loaded = TRUE;
 }
 
 void SetOrganyaPosition(unsigned int x)
@@ -532,7 +528,7 @@
 {
 	SetPlayPointer(x);
 	gOrgVolume = 100;
-	bFadeout = false;
+	bFadeout = FALSE;
 }
 
 unsigned int GetOrganyaPosition()
@@ -546,15 +542,15 @@
 	OrganyaStartTimer(info.wait);
 }
 
-bool ChangeOrganyaVolume(signed int volume)
+BOOL ChangeOrganyaVolume(signed int volume)
 {
 	if (volume >= 0 && volume <= 100)
 	{
 		gOrgVolume = volume;
-		return true;
+		return TRUE;
 	}
 
-	return false;
+	return FALSE;
 }
 
 void StopOrganyaMusic()
@@ -573,12 +569,12 @@
 
 void SetOrganyaFadeout()
 {
-	bFadeout = true;
+	bFadeout = TRUE;
 }
 
 //Org timer
 SDL_Thread *OrganyaTimer = NULL;
-bool bEndTimer = false;
+BOOL bEndTimer = FALSE;
 
 int OrganyaPlayTimer(void *ptr)
 {
@@ -587,7 +583,7 @@
 	//Set time for next step to play
 	Uint32 NextTick = SDL_GetTicks() + info.wait;
 
-	while (bEndTimer == false)
+	while (bEndTimer == FALSE)
 	{
 		if (info.loaded)
 		{
@@ -615,13 +611,13 @@
 void OrganyaStartTimer(unsigned int wait)
 {
 	OrganyaEndTimer();
-	bEndTimer = false;
+	bEndTimer = FALSE;
 	OrganyaTimer = SDL_CreateThread(OrganyaPlayTimer, "OrganyaPlayTimer", (void*)NULL);
 }
 
 void OrganyaEndTimer()
 {
-	bEndTimer = true; //Tell thread to end
+	bEndTimer = TRUE; //Tell thread to end
 	SDL_WaitThread(OrganyaTimer, NULL); //Wait for thread to end
 	OrganyaTimer = NULL;
 }
--- a/src/Organya.h
+++ b/src/Organya.h
@@ -1,5 +1,7 @@
 #pragma once
 
+#include "WindowsWrapper.h"
+
 //Below are Organya song data structures
 struct NOTELIST {
 	NOTELIST *from; //Previous address
@@ -26,8 +28,8 @@
 //Unique information held in songs
 struct MUSICINFO {
 	unsigned short wait;
-	bool loaded;
-	bool playing;
+	BOOL loaded;
+	BOOL playing;
 	unsigned char line; //Number of lines in one measure
 	unsigned char dot; //Number of dots per line
 	unsigned short alloc_note; //Number of allocated notes
@@ -36,7 +38,7 @@
 	TRACKDATA tdata[16];
 };
 
-bool MakeOrganyaWave(signed char track, signed char wave_no, signed char pipi);
+BOOL MakeOrganyaWave(signed char track, signed char wave_no, signed char pipi);
 void OrganyaPlayData();
 void SetPlayPointer(long x);
 void LoadOrganya(const char *name);
@@ -43,7 +45,7 @@
 void SetOrganyaPosition(unsigned int x);
 unsigned int GetOrganyaPosition();
 void PlayOrganyaMusic();
-bool ChangeOrganyaVolume(signed int volume);
+BOOL ChangeOrganyaVolume(signed int volume);
 void StopOrganyaMusic();
 void SetOrganyaFadeout();
 void OrganyaStartTimer(unsigned int wait);
--- a/src/PixTone.cpp
+++ b/src/PixTone.cpp
@@ -1,7 +1,6 @@
 #include "PixTone.h"
 
 #include <math.h>
-#include <stdlib.h>
 #include <string.h>
 
 #include "WindowsWrapper.h"
--- a/src/SelStage.cpp
+++ b/src/SelStage.cpp
@@ -4,6 +4,7 @@
 
 #include "WindowsWrapper.h"
 
+#include "CommonDefines.h"
 #include "Draw.h"
 #include "Escape.h"
 #include "KeyControl.h"
--- a/src/Shoot.cpp
+++ b/src/Shoot.cpp
@@ -1,5 +1,7 @@
 #include "Shoot.h"
 
+#include "WindowsWrapper.h"
+
 #include "ArmsItem.h"
 #include "Bullet.h"
 #include "Caret.h"
--- a/src/Sound.cpp
+++ b/src/Sound.cpp
@@ -1,13 +1,14 @@
 #include "Sound.h"
 
-#include <algorithm>
-#include <cmath>
+#include <math.h>
 #include <stdio.h>
-#include <string>
-#include <cstring>
+#include <stdlib.h>
+#include <string.h>
 
-#include <SDL.h>
+#include "SDL.h"
 
+#include "WindowsWrapper.h"
+
 #include "Organya.h"
 #include "PixTone.h"
 
@@ -14,9 +15,9 @@
 #define FREQUENCY 44100
 
 #ifdef RASPBERRY_PI
-#define STREAM_SIZE 0x400
+#define STREAM_SIZE 0x400	// Larger buffer to prevent stutter
 #else
-#define STREAM_SIZE (FREQUENCY / 200)
+#define STREAM_SIZE 0x100	// FREQUENCY/200 rounded to the nearest power of 2 (SDL2 *needs* a power-of-2 buffer size)
 #endif
 
 #define clamp(x, y, z) (((x) > (z)) ? (z) : ((x) < (y)) ? (y) : (x))
@@ -219,7 +220,7 @@
 //Sound things
 SOUNDBUFFER* lpSECONDARYBUFFER[SOUND_NO];
 
-bool InitDirectSound()
+BOOL InitDirectSound()
 {
 	//Init sound
 	SDL_InitSubSystem(SDL_INIT_AUDIO);
@@ -240,7 +241,7 @@
 	if (audioDevice == 0)
 	{
 		printf("Failed to open audio device\nSDL Error: %s\n", SDL_GetError());
-		return false;
+		return FALSE;
 	}
 
 	//Unpause audio device
@@ -248,7 +249,7 @@
 
 	//Start organya
 	StartOrganya();
-	return true;
+	return TRUE;
 }
 
 void EndDirectSound()
--- a/src/Sound.h
+++ b/src/Sound.h
@@ -2,6 +2,8 @@
 
 #include <stddef.h>
 
+#include "WindowsWrapper.h"
+
 #include "PixTone.h"
 
 class SOUNDBUFFER
@@ -91,7 +93,7 @@
 #define SOUND_NO 0x100
 extern SOUNDBUFFER* lpSECONDARYBUFFER[SOUND_NO];
 
-bool InitDirectSound();
+BOOL InitDirectSound();
 void EndDirectSound();
 void PlaySoundObject(int no, int mode);
 void ChangeSoundFrequency(int no, unsigned long rate);
--- a/src/Stage.cpp
+++ b/src/Stage.cpp
@@ -18,7 +18,6 @@
 #include "MyChar.h"
 #include "NpChar.h"
 #include "Organya.h"
-#include "Tags.h"
 #include "TextScr.h"
 #include "ValueView.h"
 
--- a/src/ValueView.cpp
+++ b/src/ValueView.cpp
@@ -3,7 +3,6 @@
 #include "WindowsWrapper.h"
 
 #include "Draw.h"
-#include "Game.h"
 #include "ValueView.h"
 
 #define VALUEVIEW_MAX 0x10
--- a/src/WindowsWrapper.h
+++ b/src/WindowsWrapper.h
@@ -35,4 +35,4 @@
 	int bottom;
 };
 
-bool SystemTask();
+BOOL SystemTask();
--- a/src/misc/bin2h.c
+++ /dev/null
@@ -1,92 +1,0 @@
-/*Bin2h by -C-u-c-k-y- Clownypants*/
-/*Converts files to the .h's expected by Cave Story Engine for resources.*/
-
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-int main(int argc, char *argv[])
-{
-	int result = 0;
-
-	if (argc > 2)
-	{
-		char *last_forward_slash;
-		char *last_back_slash;
-		char *last_path_seperator;
-		char *filename_pointer;
-		char *dot;
-		size_t filename_length;
-		char *filename;
-		FILE *in_file;
-		FILE *out_file;
-
-		last_forward_slash = strrchr(argv[1], '/');
-		last_back_slash = strrchr(argv[1], '\\');
-
-		last_path_seperator = last_forward_slash > last_back_slash ? last_forward_slash : last_back_slash;
-
-		filename_pointer = (last_path_seperator == NULL) ? argv[1] : last_path_seperator + 1;
-		dot = strchr(filename_pointer, '.');
-		filename_length = (dot == NULL) ? strlen(filename_pointer) : dot - filename_pointer;
-
-		filename = malloc(filename_length + 1);
-		memcpy(filename, filename_pointer, filename_length);
-		filename[filename_length] = '\0';
-
-		in_file = fopen(argv[1], "rb");
-		out_file = fopen(argv[2], "w");
-
-		if (in_file == NULL)
-		{
-			printf("Couldn't open '%s'\n", argv[1]);
-			result = 1;
-		}
-		else if (out_file == NULL)
-		{
-			printf("Couldn't open '%s'\n", argv[2]);
-			result = 1;
-		}
-		else
-		{
-			long in_file_size;
-			unsigned char *in_file_buffer;
-			unsigned char *in_file_pointer;
-			long i;
-
-			fseek(in_file, 0, SEEK_END);
-			in_file_size = ftell(in_file);
-			rewind(in_file);
-			in_file_buffer = malloc(in_file_size);
-			fread(in_file_buffer, 1, in_file_size, in_file);
-			fclose(in_file);
-			in_file_pointer = in_file_buffer;
-
-			setvbuf(out_file, NULL, _IOFBF, 0x10000);
-
-			fprintf(out_file, "#pragma once\n\nconst unsigned char r%s[0x%lX] = {\n\t", filename, in_file_size);
-
-			for (i = 0; i < in_file_size - 1; ++i)
-			{
-				if (i % 16 == 15)
-					fprintf(out_file, "0x%02X,\n\t", *in_file_pointer++);
-				else
-					fprintf(out_file, "0x%02X, ", *in_file_pointer++);
-			}
-
-			fprintf(out_file, "0x%02X\n};\n", *in_file_pointer++);
-
-			fclose(out_file);
-			free(in_file_buffer);
-		}
-
-		free(filename);
-	}
-	else
-	{
-		result = 1;
-	}
-
-	return result;
-}