shithub: cstory

Download patch

ref: d85400446343724f0a2a3f59ced73c86b57d7989
parent: 94ed000bebd10c0ca9601c611dbd52ccb58ddc09
author: Gabriel Ravier <gabravier@gmail.com>
date: Fri May 3 08:27:11 EDT 2019

Added .gitattributes for normalisation and normalized a few sources files to LF (from CRLF)

Signed-off-by: Gabriel Ravier <gabravier@gmail.com>

--- /dev/null
+++ b/.gitattributes
@@ -1,0 +1,10 @@
+# Automatically normalize line endings.
+*	text=auto
+
+# MSVC files have to be CRLF
+*.vcproj	text eol=crlf
+*.sln	text eol=crlf
+
+# Do not change external files
+external/**	-text
+DoConfig/fltk/**	-text
\ No newline at end of file
--- a/Makefile
+++ b/Makefile
@@ -1,243 +1,243 @@
-ifeq ($(RELEASE), 1)
-	CXXFLAGS = -O3 -flto
-	LDFLAGS = -s
-	FILENAME_DEF = release
-else
-	CXXFLAGS = -O0 -g
-	FILENAME_DEF = debug
-endif
-
-ifeq ($(JAPANESE), 1)
-	BUILD_DIR = build_jp
-
-	CXXFLAGS += -DJAPANESE
-
-	ifeq ($(RELEASE), 1)
-		FILENAME_DEF = releasejp
-	else
-		FILENAME_DEF = debugjp
-	endif
-else
-	BUILD_DIR = build_en
-endif
-
-FILENAME ?= $(FILENAME_DEF)
-
-ifeq ($(FIX_BUGS), 1)
-	CXXFLAGS += -DFIX_BUGS
-endif
-
-ifeq ($(WINDOWS), 1)
-	ifeq ($(CONSOLE), 1)
-		CXXFLAGS += -mconsole
-	endif
-
-	CXXFLAGS += -DWINDOWS
-	LIBS += -lkernel32
-endif
-
-ifeq ($(RASPBERRY_PI), 1)
-	CXXFLAGS += -DRASPBERRY_PI
-endif
-
-CXXFLAGS += -std=c++98 `pkg-config sdl2 --cflags` `pkg-config freetype2 --cflags` -MMD -MP -MF $@.d
-
-ifeq ($(STATIC), 1)
-	LDFLAGS += -static
-	LIBS += `pkg-config sdl2 --libs --static` `pkg-config freetype2 --libs --static` -lfreetype
-else
-	LIBS += `pkg-config sdl2 --libs` `pkg-config freetype2 --libs`
-endif
-
-# For an accurate result to the original's code, compile in alphabetical order
-SOURCES = \
-	ArmsItem \
-	Back \
-	Boss \
-	BossAlmo1 \
-	BossAlmo2 \
-	BossBallos \
-	BossFrog \
-	BossIronH \
-	BossLife \
-	BossOhm \
-	BossPress \
-	BossTwinD \
-	BossX \
-	BulHit \
-	Bullet \
-	Caret \
-	Config \
-	Draw \
-	Ending \
-	Escape \
-	Fade \
-	File \
-	Flags \
-	Flash \
-	Font \
-	Frame \
-	Game \
-	Generic \
-	GenericLoad \
-	Input \
-	KeyControl \
-	Main \
-	Map \
-	MapName \
-	MiniMap \
-	MyChar \
-	MycHit \
-	MycParam \
-	NpcAct000 \
-	NpcAct020 \
-	NpcAct040 \
-	NpcAct060 \
-	NpcAct080 \
-	NpcAct100 \
-	NpcAct120 \
-	NpcAct140 \
-	NpcAct160 \
-	NpcAct180 \
-	NpcAct200 \
-	NpcAct220 \
-	NpcAct240 \
-	NpcAct260 \
-	NpcAct280 \
-	NpcAct300 \
-	NpcAct320 \
-	NpcAct340 \
-	NpChar \
-	NpcHit \
-	NpcTbl \
-	Organya \
-	PixTone \
-	Profile \
-	Resource \
-	SelStage \
-	Shoot \
-	Sound \
-	Stage \
-	Star \
-	TextScr \
-	Triangle \
-	ValueView
-
-RESOURCES = \
-	BITMAP/CREDIT01.bmp \
-	BITMAP/CREDIT02.bmp \
-	BITMAP/CREDIT03.bmp \
-	BITMAP/CREDIT04.bmp \
-	BITMAP/CREDIT05.bmp \
-	BITMAP/CREDIT06.bmp \
-	BITMAP/CREDIT07.bmp \
-	BITMAP/CREDIT08.bmp \
-	BITMAP/CREDIT09.bmp \
-	BITMAP/CREDIT10.bmp \
-	BITMAP/CREDIT11.bmp \
-	BITMAP/CREDIT12.bmp \
-	BITMAP/CREDIT14.bmp \
-	BITMAP/CREDIT15.bmp \
-	BITMAP/CREDIT16.bmp \
-	BITMAP/CREDIT17.bmp \
-	BITMAP/CREDIT18.bmp \
-	CURSOR/CURSOR_IKA.bmp \
-	CURSOR/CURSOR_NORMAL.bmp \
-	ORG/ACCESS.org \
-	ORG/ANZEN.org \
-	ORG/BALCONY.org \
-	ORG/BALLOS.org \
-	ORG/BDOWN.org \
-	ORG/CEMETERY.org \
-	ORG/CURLY.org \
-	ORG/DR.org \
-	ORG/ENDING.org \
-	ORG/ESCAPE.org \
-	ORG/FANFALE1.org \
-	ORG/FANFALE2.org \
-	ORG/FANFALE3.org \
-	ORG/FIREEYE.org \
-	ORG/GAMEOVER.org \
-	ORG/GINSUKE.org \
-	ORG/GRAND.org \
-	ORG/GRAVITY.org \
-	ORG/HELL.org \
-	ORG/IRONH.org \
-	ORG/JENKA.org \
-	ORG/JENKA2.org \
-	ORG/KODOU.org \
-	ORG/LASTBT3.org \
-	ORG/LASTBTL.org \
-	ORG/LASTCAVE.org \
-	ORG/MARINE.org \
-	ORG/MAZE.org \
-	ORG/MDOWN2.org \
-	ORG/MURA.org \
-	ORG/OSIDE.org \
-	ORG/PLANT.org \
-	ORG/QUIET.org \
-	ORG/REQUIEM.org \
-	ORG/TOROKO.org \
-	ORG/VIVI.org \
-	ORG/WANPAK2.org \
-	ORG/WANPAKU.org \
-	ORG/WEED.org \
-	ORG/WHITE.org \
-	ORG/XXXX.org \
-	ORG/ZONBIE.org \
-	WAVE/WAVE100
-
-ifeq ($(JAPANESE), 1)
-	RESOURCES += BITMAP/PIXEL_JP.bmp
-else
-	RESOURCES += BITMAP/PIXEL.bmp
-endif
-
-ifneq ($(WINDOWS), 1)
-	RESOURCES += ICON/ICON_MINI.bmp
-endif
-
-OBJECTS = $(addprefix obj/$(FILENAME)/, $(addsuffix .o, $(SOURCES)))
-DEPENDENCIES = $(addprefix obj/$(FILENAME)/, $(addsuffix .o.d, $(SOURCES)))
-
-ifeq ($(WINDOWS), 1)
-	OBJECTS += obj/$(FILENAME)/win_icon.o
-endif
-
-all: $(BUILD_DIR)/$(FILENAME)
-
-$(BUILD_DIR)/$(FILENAME): $(OBJECTS)
-	@mkdir -p $(@D)
-	@echo Linking
-	@$(CXX) $(CXXFLAGS) $(LDFLAGS) $^ -o $@ $(LIBS)
-	@echo Finished compiling: $@
-
-obj/$(FILENAME)/%.o: src/%.cpp
-	@mkdir -p $(@D)
-	@echo Compiling $<
-	@$(CXX) $(CXXFLAGS) $< -o $@ -c
-
-obj/$(FILENAME)/Resource.o: src/Resource.cpp $(addprefix src/Resource/, $(addsuffix .h, $(RESOURCES)))
-	@mkdir -p $(@D)
-	@echo Compiling $<
-	@$(CXX) $(CXXFLAGS) $< -o $@ -c
-
-src/Resource/%.h: res/% obj/bin2h
-	@mkdir -p $(@D)
-	@echo Converting $<
-	@obj/bin2h $< $@
-
-obj/bin2h: src/misc/bin2h.c
-	@mkdir -p $(@D)
-	@echo Compiling $^
-	@$(CC) -O3 -s -std=c90 $^ -o $@
-
-include $(wildcard $(DEPENDENCIES))
-
-obj/$(FILENAME)/win_icon.o: res/ICON/ICON.rc res/ICON/0.ico res/ICON/ICON_MINI.ico
-	@mkdir -p $(@D)
-	@windres $< $@
-
-# TODO
-clean:
-	@rm -rf obj
+ifeq ($(RELEASE), 1)
+	CXXFLAGS = -O3 -flto
+	LDFLAGS = -s
+	FILENAME_DEF = release
+else
+	CXXFLAGS = -O0 -g
+	FILENAME_DEF = debug
+endif
+
+ifeq ($(JAPANESE), 1)
+	BUILD_DIR = build_jp
+
+	CXXFLAGS += -DJAPANESE
+
+	ifeq ($(RELEASE), 1)
+		FILENAME_DEF = releasejp
+	else
+		FILENAME_DEF = debugjp
+	endif
+else
+	BUILD_DIR = build_en
+endif
+
+FILENAME ?= $(FILENAME_DEF)
+
+ifeq ($(FIX_BUGS), 1)
+	CXXFLAGS += -DFIX_BUGS
+endif
+
+ifeq ($(WINDOWS), 1)
+	ifeq ($(CONSOLE), 1)
+		CXXFLAGS += -mconsole
+	endif
+
+	CXXFLAGS += -DWINDOWS
+	LIBS += -lkernel32
+endif
+
+ifeq ($(RASPBERRY_PI), 1)
+	CXXFLAGS += -DRASPBERRY_PI
+endif
+
+CXXFLAGS += -std=c++98 `pkg-config sdl2 --cflags` `pkg-config freetype2 --cflags` -MMD -MP -MF $@.d
+
+ifeq ($(STATIC), 1)
+	LDFLAGS += -static
+	LIBS += `pkg-config sdl2 --libs --static` `pkg-config freetype2 --libs --static` -lfreetype
+else
+	LIBS += `pkg-config sdl2 --libs` `pkg-config freetype2 --libs`
+endif
+
+# For an accurate result to the original's code, compile in alphabetical order
+SOURCES = \
+	ArmsItem \
+	Back \
+	Boss \
+	BossAlmo1 \
+	BossAlmo2 \
+	BossBallos \
+	BossFrog \
+	BossIronH \
+	BossLife \
+	BossOhm \
+	BossPress \
+	BossTwinD \
+	BossX \
+	BulHit \
+	Bullet \
+	Caret \
+	Config \
+	Draw \
+	Ending \
+	Escape \
+	Fade \
+	File \
+	Flags \
+	Flash \
+	Font \
+	Frame \
+	Game \
+	Generic \
+	GenericLoad \
+	Input \
+	KeyControl \
+	Main \
+	Map \
+	MapName \
+	MiniMap \
+	MyChar \
+	MycHit \
+	MycParam \
+	NpcAct000 \
+	NpcAct020 \
+	NpcAct040 \
+	NpcAct060 \
+	NpcAct080 \
+	NpcAct100 \
+	NpcAct120 \
+	NpcAct140 \
+	NpcAct160 \
+	NpcAct180 \
+	NpcAct200 \
+	NpcAct220 \
+	NpcAct240 \
+	NpcAct260 \
+	NpcAct280 \
+	NpcAct300 \
+	NpcAct320 \
+	NpcAct340 \
+	NpChar \
+	NpcHit \
+	NpcTbl \
+	Organya \
+	PixTone \
+	Profile \
+	Resource \
+	SelStage \
+	Shoot \
+	Sound \
+	Stage \
+	Star \
+	TextScr \
+	Triangle \
+	ValueView
+
+RESOURCES = \
+	BITMAP/CREDIT01.bmp \
+	BITMAP/CREDIT02.bmp \
+	BITMAP/CREDIT03.bmp \
+	BITMAP/CREDIT04.bmp \
+	BITMAP/CREDIT05.bmp \
+	BITMAP/CREDIT06.bmp \
+	BITMAP/CREDIT07.bmp \
+	BITMAP/CREDIT08.bmp \
+	BITMAP/CREDIT09.bmp \
+	BITMAP/CREDIT10.bmp \
+	BITMAP/CREDIT11.bmp \
+	BITMAP/CREDIT12.bmp \
+	BITMAP/CREDIT14.bmp \
+	BITMAP/CREDIT15.bmp \
+	BITMAP/CREDIT16.bmp \
+	BITMAP/CREDIT17.bmp \
+	BITMAP/CREDIT18.bmp \
+	CURSOR/CURSOR_IKA.bmp \
+	CURSOR/CURSOR_NORMAL.bmp \
+	ORG/ACCESS.org \
+	ORG/ANZEN.org \
+	ORG/BALCONY.org \
+	ORG/BALLOS.org \
+	ORG/BDOWN.org \
+	ORG/CEMETERY.org \
+	ORG/CURLY.org \
+	ORG/DR.org \
+	ORG/ENDING.org \
+	ORG/ESCAPE.org \
+	ORG/FANFALE1.org \
+	ORG/FANFALE2.org \
+	ORG/FANFALE3.org \
+	ORG/FIREEYE.org \
+	ORG/GAMEOVER.org \
+	ORG/GINSUKE.org \
+	ORG/GRAND.org \
+	ORG/GRAVITY.org \
+	ORG/HELL.org \
+	ORG/IRONH.org \
+	ORG/JENKA.org \
+	ORG/JENKA2.org \
+	ORG/KODOU.org \
+	ORG/LASTBT3.org \
+	ORG/LASTBTL.org \
+	ORG/LASTCAVE.org \
+	ORG/MARINE.org \
+	ORG/MAZE.org \
+	ORG/MDOWN2.org \
+	ORG/MURA.org \
+	ORG/OSIDE.org \
+	ORG/PLANT.org \
+	ORG/QUIET.org \
+	ORG/REQUIEM.org \
+	ORG/TOROKO.org \
+	ORG/VIVI.org \
+	ORG/WANPAK2.org \
+	ORG/WANPAKU.org \
+	ORG/WEED.org \
+	ORG/WHITE.org \
+	ORG/XXXX.org \
+	ORG/ZONBIE.org \
+	WAVE/WAVE100
+
+ifeq ($(JAPANESE), 1)
+	RESOURCES += BITMAP/PIXEL_JP.bmp
+else
+	RESOURCES += BITMAP/PIXEL.bmp
+endif
+
+ifneq ($(WINDOWS), 1)
+	RESOURCES += ICON/ICON_MINI.bmp
+endif
+
+OBJECTS = $(addprefix obj/$(FILENAME)/, $(addsuffix .o, $(SOURCES)))
+DEPENDENCIES = $(addprefix obj/$(FILENAME)/, $(addsuffix .o.d, $(SOURCES)))
+
+ifeq ($(WINDOWS), 1)
+	OBJECTS += obj/$(FILENAME)/win_icon.o
+endif
+
+all: $(BUILD_DIR)/$(FILENAME)
+
+$(BUILD_DIR)/$(FILENAME): $(OBJECTS)
+	@mkdir -p $(@D)
+	@echo Linking
+	@$(CXX) $(CXXFLAGS) $(LDFLAGS) $^ -o $@ $(LIBS)
+	@echo Finished compiling: $@
+
+obj/$(FILENAME)/%.o: src/%.cpp
+	@mkdir -p $(@D)
+	@echo Compiling $<
+	@$(CXX) $(CXXFLAGS) $< -o $@ -c
+
+obj/$(FILENAME)/Resource.o: src/Resource.cpp $(addprefix src/Resource/, $(addsuffix .h, $(RESOURCES)))
+	@mkdir -p $(@D)
+	@echo Compiling $<
+	@$(CXX) $(CXXFLAGS) $< -o $@ -c
+
+src/Resource/%.h: res/% obj/bin2h
+	@mkdir -p $(@D)
+	@echo Converting $<
+	@obj/bin2h $< $@
+
+obj/bin2h: src/misc/bin2h.c
+	@mkdir -p $(@D)
+	@echo Compiling $^
+	@$(CC) -O3 -s -std=c90 $^ -o $@
+
+include $(wildcard $(DEPENDENCIES))
+
+obj/$(FILENAME)/win_icon.o: res/ICON/ICON.rc res/ICON/0.ico res/ICON/ICON_MINI.ico
+	@mkdir -p $(@D)
+	@windres $< $@
+
+# TODO
+clean:
+	@rm -rf obj
--- a/src/CommonDefines.h
+++ b/src/CommonDefines.h
@@ -1,6 +1,6 @@
-#pragma once
-
-#define PATH_LENGTH 260 //Pixel had the path size locked to 260 (dangerously low), if you tried to open the executable in a path with more than around 220 characters, it'd crash.
-
-#define WINDOW_WIDTH 320
-#define WINDOW_HEIGHT 240
+#pragma once
+
+#define PATH_LENGTH 260 //Pixel had the path size locked to 260 (dangerously low), if you tried to open the executable in a path with more than around 220 characters, it'd crash.
+
+#define WINDOW_WIDTH 320
+#define WINDOW_HEIGHT 240
--- a/src/Config.cpp
+++ b/src/Config.cpp
@@ -1,72 +1,72 @@
-#include <stddef.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "WindowsWrapper.h"
-
-#include "CommonDefines.h"
-#include "Config.h"
-#include "File.h"
-#include "Tags.h"
-#include "Types.h"
-
-bool LoadConfigData(CONFIG *conf)
-{
-	//Clear old config data
-	memset(conf, 0, sizeof(CONFIG));
-	
-	//Get path
-	char path[PATH_LENGTH];
-	sprintf(path, "%s/%s", gModulePath, "Config.dat");
-	
-	//Open file
-	FILE *fp = fopen(path, "rb");
-	if (fp == NULL)
-		return false;
-	
-	//Read data
-	//Read the version id and font name
-	fread(conf->proof, sizeof(conf->proof), 1, fp);
-	fread(conf->font_name, sizeof(conf->font_name), 1, fp);
-	
-	//Read control settings
-	conf->move_button_mode = File_ReadLE32(fp);
-	conf->attack_button_mode = File_ReadLE32(fp);
-	conf->ok_button_mode = File_ReadLE32(fp);
-	
-	//Read display mode (320x240, 640x480, 24-bit fullscreen, 32-bit fullscreen) TODO: add more things?
-	conf->display_mode = File_ReadLE32(fp);
-	
-	//Read joystick configuration (if enabled, and mappings)
-	conf->bJoystick = File_ReadLE32(fp);
-	for (int button = 0; button < 8; button++)
-		conf->joystick_button[button] = File_ReadLE32(fp);
-	
-	//Close file
-	fclose(fp);
-	
-	//Check if version is correct, return that it succeeded
-	if (!strcmp(conf->proof, "DOUKUTSU20041206"))
-		return true;
-	
-	//If not, return that it failed
-	return false;
-}
-
-void DefaultConfigData(CONFIG *conf)
-{
-	//Claer old config data
-	memset(conf, 0, sizeof(CONFIG));
-	
-	//Reset joystick settings (as these can't simply be set to 0)
-	conf->bJoystick = 1;
-	conf->joystick_button[0] = 2;
-	conf->joystick_button[1] = 1;
-	conf->joystick_button[2] = 5;
-	conf->joystick_button[3] = 6;
-	conf->joystick_button[4] = 3;
-	conf->joystick_button[5] = 4;
-	conf->joystick_button[6] = 6;
-	conf->joystick_button[7] = 3;
-}
+#include <stddef.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "WindowsWrapper.h"
+
+#include "CommonDefines.h"
+#include "Config.h"
+#include "File.h"
+#include "Tags.h"
+#include "Types.h"
+
+bool LoadConfigData(CONFIG *conf)
+{
+	//Clear old config data
+	memset(conf, 0, sizeof(CONFIG));
+	
+	//Get path
+	char path[PATH_LENGTH];
+	sprintf(path, "%s/%s", gModulePath, "Config.dat");
+	
+	//Open file
+	FILE *fp = fopen(path, "rb");
+	if (fp == NULL)
+		return false;
+	
+	//Read data
+	//Read the version id and font name
+	fread(conf->proof, sizeof(conf->proof), 1, fp);
+	fread(conf->font_name, sizeof(conf->font_name), 1, fp);
+	
+	//Read control settings
+	conf->move_button_mode = File_ReadLE32(fp);
+	conf->attack_button_mode = File_ReadLE32(fp);
+	conf->ok_button_mode = File_ReadLE32(fp);
+	
+	//Read display mode (320x240, 640x480, 24-bit fullscreen, 32-bit fullscreen) TODO: add more things?
+	conf->display_mode = File_ReadLE32(fp);
+	
+	//Read joystick configuration (if enabled, and mappings)
+	conf->bJoystick = File_ReadLE32(fp);
+	for (int button = 0; button < 8; button++)
+		conf->joystick_button[button] = File_ReadLE32(fp);
+	
+	//Close file
+	fclose(fp);
+	
+	//Check if version is correct, return that it succeeded
+	if (!strcmp(conf->proof, "DOUKUTSU20041206"))
+		return true;
+	
+	//If not, return that it failed
+	return false;
+}
+
+void DefaultConfigData(CONFIG *conf)
+{
+	//Claer old config data
+	memset(conf, 0, sizeof(CONFIG));
+	
+	//Reset joystick settings (as these can't simply be set to 0)
+	conf->bJoystick = 1;
+	conf->joystick_button[0] = 2;
+	conf->joystick_button[1] = 1;
+	conf->joystick_button[2] = 5;
+	conf->joystick_button[3] = 6;
+	conf->joystick_button[4] = 3;
+	conf->joystick_button[5] = 4;
+	conf->joystick_button[6] = 6;
+	conf->joystick_button[7] = 3;
+}
--- a/src/Config.h
+++ b/src/Config.h
@@ -1,18 +1,18 @@
-#pragma once
-
-#include <stdint.h>
-
-struct CONFIG
-{
-	char proof[0x20];
-	char font_name[0x40];
-	int32_t move_button_mode;
-	int32_t attack_button_mode;
-	int32_t ok_button_mode;
-	int32_t display_mode;
-	int32_t bJoystick;
-	int32_t joystick_button[8];
-};
-
-bool LoadConfigData(CONFIG *conf);
-void DefaultConfigData(CONFIG *conf);
+#pragma once
+
+#include <stdint.h>
+
+struct CONFIG
+{
+	char proof[0x20];
+	char font_name[0x40];
+	int32_t move_button_mode;
+	int32_t attack_button_mode;
+	int32_t ok_button_mode;
+	int32_t display_mode;
+	int32_t bJoystick;
+	int32_t joystick_button[8];
+};
+
+bool LoadConfigData(CONFIG *conf);
+void DefaultConfigData(CONFIG *conf);
--- a/src/KeyControl.cpp
+++ b/src/KeyControl.cpp
@@ -1,24 +1,24 @@
-#include "KeyControl.h"
-
-int gKey;
-int gKeyTrg;
-
-int gKeyJump = KEY_Z;
-int gKeyShot = KEY_X;
-int gKeyArms = KEY_ARMS;
-int gKeyArmsRev = KEY_ARMSREV;
-int gKeyItem = KEY_ITEM;
-int gKeyMap = KEY_MAP;
-int gKeyOk = KEY_Z;
-int gKeyCancel = KEY_X;
-int gKeyLeft = KEY_LEFT;
-int gKeyUp = KEY_UP;
-int gKeyRight = KEY_RIGHT;
-int gKeyDown = KEY_DOWN;
-
-void GetTrg()
-{
-	static int key_old;
-	gKeyTrg = gKey & (gKey ^ key_old);
-	key_old = gKey;
-}
+#include "KeyControl.h"
+
+int gKey;
+int gKeyTrg;
+
+int gKeyJump = KEY_Z;
+int gKeyShot = KEY_X;
+int gKeyArms = KEY_ARMS;
+int gKeyArmsRev = KEY_ARMSREV;
+int gKeyItem = KEY_ITEM;
+int gKeyMap = KEY_MAP;
+int gKeyOk = KEY_Z;
+int gKeyCancel = KEY_X;
+int gKeyLeft = KEY_LEFT;
+int gKeyUp = KEY_UP;
+int gKeyRight = KEY_RIGHT;
+int gKeyDown = KEY_DOWN;
+
+void GetTrg()
+{
+	static int key_old;
+	gKeyTrg = gKey & (gKey ^ key_old);
+	key_old = gKey;
+}
--- a/src/KeyControl.h
+++ b/src/KeyControl.h
@@ -1,53 +1,53 @@
-#pragma once
-
-enum KEYBIND
-{
-	//The movement keys go in the order of left, right, up and down
-	KEY_LEFT =		0x00000001,
-	KEY_RIGHT =		0x00000002,
-	KEY_UP =		0x00000004,
-	KEY_DOWN =		0x00000008,
-	//Map key
-	KEY_MAP =		0x00000010,
-	//Okay and cancel / Jump and Shoot keys
-	KEY_X =			0x00000020,
-	KEY_Z =			0x00000040,
-	//Left and right weapon switch keys
-	KEY_ARMS =		0x00000080,
-	KEY_ARMSREV =	0x00000100,
-	//Unused?
-	KEY_SHIFT =		0x00000200,
-	//Function keys
-	KEY_F1 =		0x00000400,
-	KEY_F2 =		0x00000800,
-	//Inventory
-	KEY_ITEM =		0x00001000,
-	//Escape key
-	KEY_ESCAPE =	0x00008000,
-	//The alt movement keys go in the order of left, up, right and down
-	KEY_ALT_LEFT =	0x00010000,
-	KEY_ALT_DOWN =	0x00020000,
-	KEY_ALT_RIGHT =	0x00040000,
-	KEY_ALT_UP =	0x00180000,
-	//Alt up actually has 2 seperate keys, but they're kind of merged together (and also for some reason the second one is +/=)
-	KEY_L =			0x00080000,
-	KEY_PLUS =		0x00100000
-};
-
-extern int gKey;
-extern int gKeyTrg;
-
-extern int gKeyJump;
-extern int gKeyShot;
-extern int gKeyArms;
-extern int gKeyArmsRev;
-extern int gKeyItem;
-extern int gKeyMap;
-extern int gKeyOk;
-extern int gKeyCancel;
-extern int gKeyLeft;
-extern int gKeyUp;
-extern int gKeyRight;
-extern int gKeyDown;
-
-void GetTrg();
+#pragma once
+
+enum KEYBIND
+{
+	//The movement keys go in the order of left, right, up and down
+	KEY_LEFT =		0x00000001,
+	KEY_RIGHT =		0x00000002,
+	KEY_UP =		0x00000004,
+	KEY_DOWN =		0x00000008,
+	//Map key
+	KEY_MAP =		0x00000010,
+	//Okay and cancel / Jump and Shoot keys
+	KEY_X =			0x00000020,
+	KEY_Z =			0x00000040,
+	//Left and right weapon switch keys
+	KEY_ARMS =		0x00000080,
+	KEY_ARMSREV =	0x00000100,
+	//Unused?
+	KEY_SHIFT =		0x00000200,
+	//Function keys
+	KEY_F1 =		0x00000400,
+	KEY_F2 =		0x00000800,
+	//Inventory
+	KEY_ITEM =		0x00001000,
+	//Escape key
+	KEY_ESCAPE =	0x00008000,
+	//The alt movement keys go in the order of left, up, right and down
+	KEY_ALT_LEFT =	0x00010000,
+	KEY_ALT_DOWN =	0x00020000,
+	KEY_ALT_RIGHT =	0x00040000,
+	KEY_ALT_UP =	0x00180000,
+	//Alt up actually has 2 seperate keys, but they're kind of merged together (and also for some reason the second one is +/=)
+	KEY_L =			0x00080000,
+	KEY_PLUS =		0x00100000
+};
+
+extern int gKey;
+extern int gKeyTrg;
+
+extern int gKeyJump;
+extern int gKeyShot;
+extern int gKeyArms;
+extern int gKeyArmsRev;
+extern int gKeyItem;
+extern int gKeyMap;
+extern int gKeyOk;
+extern int gKeyCancel;
+extern int gKeyLeft;
+extern int gKeyUp;
+extern int gKeyRight;
+extern int gKeyDown;
+
+void GetTrg();
--- a/src/Main.cpp
+++ b/src/Main.cpp
@@ -1,634 +1,634 @@
-#include "Main.h"
-
-#include <stddef.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <string.h>
-
-#include <SDL.h>
-
-#include "WindowsWrapper.h"
-
-#include "CommonDefines.h"
-#include "Config.h"
-#include "Draw.h"
-#include "Game.h"
-#include "Generic.h"
-#include "Input.h"
-#include "KeyControl.h"
-#include "MyChar.h"
-#include "Organya.h"
-#include "Profile.h"
-#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;
-extern SDL_Renderer *gRenderer;
-
-char gModulePath[PATH_LENGTH];
-char gDataPath[PATH_LENGTH];
-
-int gJoystickButtonTable[8];
-
-bool gbUseJoystick = false;
-bool bFps = false;
-
-bool bActive = true;
-
-#ifdef JAPANESE
-const char *lpWindowName = "洞窟物語エンジン2";
-#else
-const char *lpWindowName = "Cave Story Engine 2 ~ Doukutsu Monogatari Enjin 2";
-#endif
-
-//A replication of MSVC's rand algorithm
-static unsigned long int next = 1;
-
-int rep_rand()
-{
-	next = ((next) * 214013 + 2531011);
-    return ((next) >> 16) & 0x7FFF;
-}
-
-void rep_srand(unsigned int seed)
-{
-    next = seed;
-}
-
-//Framerate stuff
-void PutFramePerSecound()
-{
-	if (bFps)
-		PutNumber4(WINDOW_WIDTH - 40, 8, GetFramePerSecound(), false);
-}
-
-int GetFramePerSecound()
-{
-	unsigned int current_tick;
-	static bool need_new_base_tick = true;
-	static int frames_this_second;
-	static int current_frame;
-	static int base_tick;
-
-	if (need_new_base_tick)
-	{
-		base_tick = SDL_GetTicks();
-		need_new_base_tick = false;
-	}
-	
-	current_tick = SDL_GetTicks();
-	++current_frame;
-	
-	if ( base_tick + 1000 <= current_tick )
-	{
-		base_tick += 1000;
-		frames_this_second = current_frame;
-		current_frame = 0;
-	}
-	
-	return frames_this_second;
-}
-
-int main(int argc, char *argv[])
-{
-	//Get executable's path
-	strcpy(gModulePath, SDL_GetBasePath());
-	if (gModulePath[strlen(gModulePath) - 1] == '/' || gModulePath[strlen(gModulePath) - 1] == '\\')
-		gModulePath[strlen(gModulePath) - 1] = '\0'; //String cannot end in slash or stuff will probably break (original does this through a windows.h provided function)
-	
-	//Get path of the data folder
-	strcpy(gDataPath, gModulePath);
-	strcat(gDataPath, "/data");
-
-#ifdef WINDOWS
-	// Set the window icons. See res/ICON/ICON.rc.
-	SDL_SetHint(SDL_HINT_WINDOWS_INTRESOURCE_ICON, "101");
-	SDL_SetHint(SDL_HINT_WINDOWS_INTRESOURCE_ICON_SMALL, "102");
-#endif
-
-	//Initialize SDL
-	if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_TIMER) >= 0)
-	{
-		//Load configuration
-		CONFIG config;
-		
-		if (!LoadConfigData(&config))
-			DefaultConfigData(&config);
-		
-		//Apply keybinds
-		//Swap X and Z buttons
-		if (config.attack_button_mode)
-		{
-			if (config.attack_button_mode == 1)
-			{
-				gKeyJump = KEY_X;
-				gKeyShot = KEY_Z;
-			}
-		}
-		else
-		{
-			gKeyJump = KEY_Z;
-			gKeyShot = KEY_X;
-		}
-		
-		//Swap Okay and Cancel buttons
-		if (config.ok_button_mode)
-		{
-			if (config.ok_button_mode == 1)
-			{
-				gKeyOk = gKeyShot;
-				gKeyCancel = gKeyJump;
-			}
-		}
-		else
-		{
-			gKeyOk = gKeyJump;
-			gKeyCancel = gKeyShot;
-		}
-		
-		//Swap left and right weapon switch keys
-		if (CheckFileExists("s_reverse"))
-		{
-			gKeyArms = KEY_ARMSREV;
-			gKeyArmsRev = KEY_ARMS;
-		}
-		
-		//Alternate movement keys
-		if (config.move_button_mode)
-		{
-			if (config.move_button_mode == 1)
-			{
-				gKeyLeft = KEY_ALT_LEFT;
-				gKeyUp = KEY_ALT_UP;
-				gKeyRight = KEY_ALT_RIGHT;
-				gKeyDown = KEY_ALT_DOWN;
-			}
-		}
-		else
-		{
-			gKeyLeft = KEY_LEFT;
-			gKeyUp = KEY_UP;
-			gKeyRight = KEY_RIGHT;
-			gKeyDown = KEY_DOWN;
-		}
-		
-		//Set gamepad inputs
-		for (int i = 0; i < 8; i++)
-		{
-			switch (config.joystick_button[i])
-			{
-				case 1:
-					gJoystickButtonTable[i] = gKeyJump;
-					break;
-					
-				case 2:
-					gJoystickButtonTable[i] = gKeyShot;
-					break;
-					
-				case 3:
-					gJoystickButtonTable[i] = gKeyArms;
-					break;
-					
-				case 6:
-					gJoystickButtonTable[i] = gKeyArmsRev;
-					break;
-					
-				case 4:
-					gJoystickButtonTable[i] = gKeyItem;
-					break;
-					
-				case 5:
-					gJoystickButtonTable[i] = gKeyMap;
-					break;
-					
-				default:
-					continue;
-			}
-		}
-		
-		RECT unused_rect = {0, 0, 320, 240};
-
-		//Load cursor
-		SDL_RWops *fp = FindResource("CURSOR_NORMAL");
-		
-		if (fp)
-		{
-			SDL_Surface *cursor_surface = SDL_LoadBMP_RW(fp, 1);
-			SDL_SetColorKey(cursor_surface, SDL_TRUE, SDL_MapRGB(cursor_surface->format, 0xFF, 0, 0xFF));	// Pink regions are transparent
-
-			SDL_Cursor *cursor = SDL_CreateColorCursor(cursor_surface, 0, 0);	// Don't worry, the hotspots are accurate to the original files
-
-			if (cursor)
-				SDL_SetCursor(cursor);
-			else
-				printf("Failed to load cursor\n");
-
-			SDL_FreeSurface(cursor_surface);
-		}
-		else
-		{
-			printf("Failed to load cursor\n");
-		}
-
-		//Get window dimensions and colour depth
-		int windowWidth;
-		int windowHeight;
-		int colourDepth;
-		
-		switch (config.display_mode)
-		{
-			case 1:
-			case 2:
-				//Set window dimensions
-				if (config.display_mode == 1)
-				{
-					windowWidth = WINDOW_WIDTH;
-					windowHeight = WINDOW_HEIGHT;
-				}
-				else
-				{
-					windowWidth = WINDOW_WIDTH * 2;
-					windowHeight = WINDOW_HEIGHT * 2;
-				}
-				
-				//Create window
-				gWindow = SDL_CreateWindow(lpWindowName, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, windowWidth, windowHeight, 0);
-				
-				if (gWindow)
-				{
-					if (config.display_mode == 1)
-						StartDirectDraw(0, 0);
-					else
-						StartDirectDraw(1, 0);
-					break;
-				}
-				
-				break;
-			
-			case 0:
-			case 3:
-			case 4:
-				//Set window dimensions
-				windowWidth = WINDOW_WIDTH * 2;
-				windowHeight = WINDOW_HEIGHT * 2;
-				
-				//Create window
-				gWindow = SDL_CreateWindow(lpWindowName, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, windowWidth, windowHeight, 0);
-				
-				if (gWindow)
-				{
-					//Set colour depth
-					switch (config.display_mode)
-					{
-						case 0:
-							colourDepth = 16;
-							break;
-						case 3:
-							colourDepth = 24;
-							break;
-						case 4:
-							colourDepth = 32;
-							break;
-					}
-					
-					StartDirectDraw(2, colourDepth);
-					
-					fullscreen = true;
-					SDL_ShowCursor(0);
-					break;
-				}
-				break;
-		}
-		
-		//Create window
-		
-		
-		if (gWindow)
-		{
-			//Check debug things
-			if (CheckFileExists("fps"))
-				bFps = true;
-			
-#ifndef WINDOWS
-			//Load icon
-			SDL_RWops *fp = FindResource("ICON_MINI");
-			
-			if (fp)
-			{
-				SDL_Surface *iconSurf = SDL_LoadBMP_RW(fp, 1);
-				SDL_Surface *iconConverted = SDL_ConvertSurfaceFormat(iconSurf, SDL_PIXELFORMAT_RGB888, 0);
-				SDL_FreeSurface(iconSurf);
-				SDL_Surface *iconSurfUpscaled = SDL_CreateRGBSurfaceWithFormat(0, 256, 256, 0, SDL_PIXELFORMAT_RGB888);
-				SDL_LowerBlitScaled(iconConverted, NULL, iconSurfUpscaled, NULL);
-				SDL_FreeSurface(iconConverted);
-				SDL_SetWindowIcon(gWindow, iconSurfUpscaled);
-				SDL_FreeSurface(iconSurfUpscaled);
-			}
-			else
-			{
-				printf("Failed to load icon\n");
-			}
-#endif
-
-			//Set rects
-			RECT loading_rect = {0, 0, 64, 8};
-			RECT clip_rect = {0, 0, windowWidth, windowHeight};
-			
-			//Load the "LOADING" text
-			MakeSurface_File("Loading", SURFACE_ID_LOADING);
-			
-			//Draw loading screen
-			CortBox(&clip_rect, 0x000000);
-			PutBitmap3(&clip_rect, (WINDOW_WIDTH - 64) / 2, (WINDOW_HEIGHT - 8) / 2, &loading_rect, SURFACE_ID_LOADING);
-			
-			//Draw to screen
-			if (Flip_SystemTask())
-			{
-				//Initialize sound
-				InitDirectSound();
-				
-				//Initialize joystick
-				if (config.bJoystick && InitDirectInput())
-				{
-					ResetJoystickStatus();
-					gbUseJoystick = true;
-				}
-				
-				//Initialize stuff
-				InitTextObject(config.font_name);
-				InitTriangleTable();
-				
-				//Run game code
-				Game();
-				
-				//End stuff
-				EndDirectSound();
-				EndTextObject();
-				EndDirectDraw();
-			}
-		}
-	}
-	else
-	{
-		SDL_Quit();
-		return -1;
-	}
-	
-	SDL_Quit();
-	return 0;
-}
-
-void InactiveWindow()
-{
-	if (bActive)
-	{
-		bActive = false;
-		StopOrganyaMusic();
-		SleepNoise();
-	}
-	
-	PlaySoundObject(7, 0);
-}
-
-void ActiveWindow()
-{
-	if (!bActive)
-	{
-		bActive = true;
-		StopOrganyaMusic();
-		PlayOrganyaMusic();
-		ResetNoise();
-	}
-
-	PlaySoundObject(7, -1);
-}
-
-void JoystickProc()
-{
-	JOYSTICK_STATUS status;
-	
-	if (GetJoystickStatus(&status))
-	{
-		//Clear held buttons
-		gKey &= (KEY_ESCAPE | KEY_F2 | KEY_F1);
-		
-		//Set movement buttons
-		if (status.bLeft)
-			gKey |= gKeyLeft;
-		if (status.bRight)
-			gKey |= gKeyRight;
-		if (status.bUp)
-			gKey |= gKeyUp;
-		if (status.bDown)
-			gKey |= gKeyDown;
-		
-		//Set held buttons
-		for (int i = 0; i < 8; i++)
-		{
-			if (status.bButton[i])
-				gKey |= gJoystickButtonTable[i];
-		}
-	}
-}
-
-#define DO_KEY_PRESS(key) \
-	if (event.type == SDL_KEYDOWN) \
-		gKey |= key; \
-	else \
-		gKey &= ~key; \
-	break;
-
-bool SystemTask()
-{
-	//Handle window events
-	bool focusGained = true;
-	
-	while (SDL_PollEvent(NULL) || !focusGained)
-	{
-		SDL_Event event;
-		SDL_WaitEvent(&event);
-		
-		switch (event.type)
-		{
-			case SDL_QUIT:
-				return false;
-				break;
-				
-			case SDL_WINDOWEVENT:
-				switch (event.window.event)
-				{
-					case SDL_WINDOWEVENT_FOCUS_GAINED:
-						focusGained = true;
-						ActiveWindow();
-						break;
-						
-					case SDL_WINDOWEVENT_FOCUS_LOST:
-						focusGained = false;
-						InactiveWindow();
-						break;
-					
-					default:
-						break;
-				}
-				break;
-				
-			case SDL_DROPFILE:
-				LoadProfile(event.drop.file);
-				SDL_free(event.drop.file);
-				break;
-			
-			case SDL_KEYDOWN:
-			case SDL_KEYUP:
-			#ifdef FIX_BUGS
-				//BUG FIX: Pixel relied on key codes for input, but these differ based on keyboard layout.
-				//This would break the alternate movement keys on typical English keyboards, since the '=' key
-				//is in a completely different place to where it is on a Japanese keyboard.
-				//To solve this, we use scancodes instead, which are based on the physical location of keys,
-				//rather than their meaning.
-				switch (event.key.keysym.scancode)
-				{
-					case SDL_SCANCODE_ESCAPE:
-						DO_KEY_PRESS(KEY_ESCAPE)
-
-					case SDL_SCANCODE_W:
-						DO_KEY_PRESS(KEY_MAP)
-
-					case SDL_SCANCODE_LEFT:
-						DO_KEY_PRESS(KEY_LEFT)
-
-					case SDL_SCANCODE_RIGHT:
-						DO_KEY_PRESS(KEY_RIGHT)
-
-					case SDL_SCANCODE_UP:
-						DO_KEY_PRESS(KEY_UP)
-
-					case SDL_SCANCODE_DOWN:
-						DO_KEY_PRESS(KEY_DOWN)
-
-					case SDL_SCANCODE_X:
-						DO_KEY_PRESS(KEY_X)
-
-					case SDL_SCANCODE_Z:
-						DO_KEY_PRESS(KEY_Z)
-
-					case SDL_SCANCODE_S:
-						DO_KEY_PRESS(KEY_ARMS)
-
-					case SDL_SCANCODE_A:
-						DO_KEY_PRESS(KEY_ARMSREV)
-
-					case SDL_SCANCODE_RSHIFT:
-					case SDL_SCANCODE_LSHIFT:
-						DO_KEY_PRESS(KEY_SHIFT)
-
-					case SDL_SCANCODE_F1:
-						DO_KEY_PRESS(KEY_F1)
-
-					case SDL_SCANCODE_F2:
-						DO_KEY_PRESS(KEY_F2)
-
-					case SDL_SCANCODE_Q:
-						DO_KEY_PRESS(KEY_ITEM)
-
-					case SDL_SCANCODE_COMMA:
-						DO_KEY_PRESS(KEY_ALT_LEFT)
-
-					case SDL_SCANCODE_PERIOD:
-						DO_KEY_PRESS(KEY_ALT_DOWN)
-
-					case SDL_SCANCODE_SLASH:
-						DO_KEY_PRESS(KEY_ALT_RIGHT)
-
-					case SDL_SCANCODE_L:
-						DO_KEY_PRESS(KEY_ALT_UP)
-
-					case SDL_SCANCODE_SEMICOLON:
-						DO_KEY_PRESS(KEY_PLUS)
-						
-					case SDL_SCANCODE_F5:
-						gbUseJoystick = false;
-						break;
-
-					default:
-						break;
-				}
-				break;
-			#else
-				switch (event.key.keysym.sym)
-				{
-					case SDLK_ESCAPE:
-						DO_KEY_PRESS(KEY_ESCAPE)
-
-					case SDLK_w:
-						DO_KEY_PRESS(KEY_MAP)
-
-					case SDLK_LEFT:
-						DO_KEY_PRESS(KEY_LEFT)
-
-					case SDLK_RIGHT:
-						DO_KEY_PRESS(KEY_RIGHT)
-
-					case SDLK_UP:
-						DO_KEY_PRESS(KEY_UP)
-
-					case SDLK_DOWN:
-						DO_KEY_PRESS(KEY_DOWN)
-
-					case SDLK_x:
-						DO_KEY_PRESS(KEY_X)
-
-					case SDLK_z:
-						DO_KEY_PRESS(KEY_Z)
-
-					case SDLK_s:
-						DO_KEY_PRESS(KEY_ARMS)
-
-					case SDLK_a:
-						DO_KEY_PRESS(KEY_ARMSREV)
-
-					case SDLK_RSHIFT:
-					case SDLK_LSHIFT:
-						DO_KEY_PRESS(KEY_SHIFT)
-
-					case SDLK_F1:
-						DO_KEY_PRESS(KEY_F1)
-
-					case SDLK_F2:
-						DO_KEY_PRESS(KEY_F2)
-
-					case SDLK_q:
-						DO_KEY_PRESS(KEY_ITEM)
-
-					case SDLK_COMMA:
-						DO_KEY_PRESS(KEY_ALT_LEFT)
-
-					case SDLK_PERIOD:
-						DO_KEY_PRESS(KEY_ALT_DOWN)
-
-					case SDLK_SLASH:
-						DO_KEY_PRESS(KEY_ALT_RIGHT)
-
-					case SDLK_l:
-						DO_KEY_PRESS(KEY_ALT_UP)
-
-					case SDLK_SEMICOLON:
-						DO_KEY_PRESS(KEY_PLUS)
-						
-					case SDLK_F5:
-						gbUseJoystick = false;
-						break;
-				}
-				break;
-			#endif
-		}
-	}
-	
-	//Run joystick code
-	if (gbUseJoystick)
-		JoystickProc();
-	
-	return true;
-}
+#include "Main.h"
+
+#include <stddef.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <SDL.h>
+
+#include "WindowsWrapper.h"
+
+#include "CommonDefines.h"
+#include "Config.h"
+#include "Draw.h"
+#include "Game.h"
+#include "Generic.h"
+#include "Input.h"
+#include "KeyControl.h"
+#include "MyChar.h"
+#include "Organya.h"
+#include "Profile.h"
+#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;
+extern SDL_Renderer *gRenderer;
+
+char gModulePath[PATH_LENGTH];
+char gDataPath[PATH_LENGTH];
+
+int gJoystickButtonTable[8];
+
+bool gbUseJoystick = false;
+bool bFps = false;
+
+bool bActive = true;
+
+#ifdef JAPANESE
+const char *lpWindowName = "洞窟物語エンジン2";
+#else
+const char *lpWindowName = "Cave Story Engine 2 ~ Doukutsu Monogatari Enjin 2";
+#endif
+
+//A replication of MSVC's rand algorithm
+static unsigned long int next = 1;
+
+int rep_rand()
+{
+	next = ((next) * 214013 + 2531011);
+    return ((next) >> 16) & 0x7FFF;
+}
+
+void rep_srand(unsigned int seed)
+{
+    next = seed;
+}
+
+//Framerate stuff
+void PutFramePerSecound()
+{
+	if (bFps)
+		PutNumber4(WINDOW_WIDTH - 40, 8, GetFramePerSecound(), false);
+}
+
+int GetFramePerSecound()
+{
+	unsigned int current_tick;
+	static bool need_new_base_tick = true;
+	static int frames_this_second;
+	static int current_frame;
+	static int base_tick;
+
+	if (need_new_base_tick)
+	{
+		base_tick = SDL_GetTicks();
+		need_new_base_tick = false;
+	}
+	
+	current_tick = SDL_GetTicks();
+	++current_frame;
+	
+	if ( base_tick + 1000 <= current_tick )
+	{
+		base_tick += 1000;
+		frames_this_second = current_frame;
+		current_frame = 0;
+	}
+	
+	return frames_this_second;
+}
+
+int main(int argc, char *argv[])
+{
+	//Get executable's path
+	strcpy(gModulePath, SDL_GetBasePath());
+	if (gModulePath[strlen(gModulePath) - 1] == '/' || gModulePath[strlen(gModulePath) - 1] == '\\')
+		gModulePath[strlen(gModulePath) - 1] = '\0'; //String cannot end in slash or stuff will probably break (original does this through a windows.h provided function)
+	
+	//Get path of the data folder
+	strcpy(gDataPath, gModulePath);
+	strcat(gDataPath, "/data");
+
+#ifdef WINDOWS
+	// Set the window icons. See res/ICON/ICON.rc.
+	SDL_SetHint(SDL_HINT_WINDOWS_INTRESOURCE_ICON, "101");
+	SDL_SetHint(SDL_HINT_WINDOWS_INTRESOURCE_ICON_SMALL, "102");
+#endif
+
+	//Initialize SDL
+	if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_TIMER) >= 0)
+	{
+		//Load configuration
+		CONFIG config;
+		
+		if (!LoadConfigData(&config))
+			DefaultConfigData(&config);
+		
+		//Apply keybinds
+		//Swap X and Z buttons
+		if (config.attack_button_mode)
+		{
+			if (config.attack_button_mode == 1)
+			{
+				gKeyJump = KEY_X;
+				gKeyShot = KEY_Z;
+			}
+		}
+		else
+		{
+			gKeyJump = KEY_Z;
+			gKeyShot = KEY_X;
+		}
+		
+		//Swap Okay and Cancel buttons
+		if (config.ok_button_mode)
+		{
+			if (config.ok_button_mode == 1)
+			{
+				gKeyOk = gKeyShot;
+				gKeyCancel = gKeyJump;
+			}
+		}
+		else
+		{
+			gKeyOk = gKeyJump;
+			gKeyCancel = gKeyShot;
+		}
+		
+		//Swap left and right weapon switch keys
+		if (CheckFileExists("s_reverse"))
+		{
+			gKeyArms = KEY_ARMSREV;
+			gKeyArmsRev = KEY_ARMS;
+		}
+		
+		//Alternate movement keys
+		if (config.move_button_mode)
+		{
+			if (config.move_button_mode == 1)
+			{
+				gKeyLeft = KEY_ALT_LEFT;
+				gKeyUp = KEY_ALT_UP;
+				gKeyRight = KEY_ALT_RIGHT;
+				gKeyDown = KEY_ALT_DOWN;
+			}
+		}
+		else
+		{
+			gKeyLeft = KEY_LEFT;
+			gKeyUp = KEY_UP;
+			gKeyRight = KEY_RIGHT;
+			gKeyDown = KEY_DOWN;
+		}
+		
+		//Set gamepad inputs
+		for (int i = 0; i < 8; i++)
+		{
+			switch (config.joystick_button[i])
+			{
+				case 1:
+					gJoystickButtonTable[i] = gKeyJump;
+					break;
+					
+				case 2:
+					gJoystickButtonTable[i] = gKeyShot;
+					break;
+					
+				case 3:
+					gJoystickButtonTable[i] = gKeyArms;
+					break;
+					
+				case 6:
+					gJoystickButtonTable[i] = gKeyArmsRev;
+					break;
+					
+				case 4:
+					gJoystickButtonTable[i] = gKeyItem;
+					break;
+					
+				case 5:
+					gJoystickButtonTable[i] = gKeyMap;
+					break;
+					
+				default:
+					continue;
+			}
+		}
+		
+		RECT unused_rect = {0, 0, 320, 240};
+
+		//Load cursor
+		SDL_RWops *fp = FindResource("CURSOR_NORMAL");
+		
+		if (fp)
+		{
+			SDL_Surface *cursor_surface = SDL_LoadBMP_RW(fp, 1);
+			SDL_SetColorKey(cursor_surface, SDL_TRUE, SDL_MapRGB(cursor_surface->format, 0xFF, 0, 0xFF));	// Pink regions are transparent
+
+			SDL_Cursor *cursor = SDL_CreateColorCursor(cursor_surface, 0, 0);	// Don't worry, the hotspots are accurate to the original files
+
+			if (cursor)
+				SDL_SetCursor(cursor);
+			else
+				printf("Failed to load cursor\n");
+
+			SDL_FreeSurface(cursor_surface);
+		}
+		else
+		{
+			printf("Failed to load cursor\n");
+		}
+
+		//Get window dimensions and colour depth
+		int windowWidth;
+		int windowHeight;
+		int colourDepth;
+		
+		switch (config.display_mode)
+		{
+			case 1:
+			case 2:
+				//Set window dimensions
+				if (config.display_mode == 1)
+				{
+					windowWidth = WINDOW_WIDTH;
+					windowHeight = WINDOW_HEIGHT;
+				}
+				else
+				{
+					windowWidth = WINDOW_WIDTH * 2;
+					windowHeight = WINDOW_HEIGHT * 2;
+				}
+				
+				//Create window
+				gWindow = SDL_CreateWindow(lpWindowName, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, windowWidth, windowHeight, 0);
+				
+				if (gWindow)
+				{
+					if (config.display_mode == 1)
+						StartDirectDraw(0, 0);
+					else
+						StartDirectDraw(1, 0);
+					break;
+				}
+				
+				break;
+			
+			case 0:
+			case 3:
+			case 4:
+				//Set window dimensions
+				windowWidth = WINDOW_WIDTH * 2;
+				windowHeight = WINDOW_HEIGHT * 2;
+				
+				//Create window
+				gWindow = SDL_CreateWindow(lpWindowName, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, windowWidth, windowHeight, 0);
+				
+				if (gWindow)
+				{
+					//Set colour depth
+					switch (config.display_mode)
+					{
+						case 0:
+							colourDepth = 16;
+							break;
+						case 3:
+							colourDepth = 24;
+							break;
+						case 4:
+							colourDepth = 32;
+							break;
+					}
+					
+					StartDirectDraw(2, colourDepth);
+					
+					fullscreen = true;
+					SDL_ShowCursor(0);
+					break;
+				}
+				break;
+		}
+		
+		//Create window
+		
+		
+		if (gWindow)
+		{
+			//Check debug things
+			if (CheckFileExists("fps"))
+				bFps = true;
+			
+#ifndef WINDOWS
+			//Load icon
+			SDL_RWops *fp = FindResource("ICON_MINI");
+			
+			if (fp)
+			{
+				SDL_Surface *iconSurf = SDL_LoadBMP_RW(fp, 1);
+				SDL_Surface *iconConverted = SDL_ConvertSurfaceFormat(iconSurf, SDL_PIXELFORMAT_RGB888, 0);
+				SDL_FreeSurface(iconSurf);
+				SDL_Surface *iconSurfUpscaled = SDL_CreateRGBSurfaceWithFormat(0, 256, 256, 0, SDL_PIXELFORMAT_RGB888);
+				SDL_LowerBlitScaled(iconConverted, NULL, iconSurfUpscaled, NULL);
+				SDL_FreeSurface(iconConverted);
+				SDL_SetWindowIcon(gWindow, iconSurfUpscaled);
+				SDL_FreeSurface(iconSurfUpscaled);
+			}
+			else
+			{
+				printf("Failed to load icon\n");
+			}
+#endif
+
+			//Set rects
+			RECT loading_rect = {0, 0, 64, 8};
+			RECT clip_rect = {0, 0, windowWidth, windowHeight};
+			
+			//Load the "LOADING" text
+			MakeSurface_File("Loading", SURFACE_ID_LOADING);
+			
+			//Draw loading screen
+			CortBox(&clip_rect, 0x000000);
+			PutBitmap3(&clip_rect, (WINDOW_WIDTH - 64) / 2, (WINDOW_HEIGHT - 8) / 2, &loading_rect, SURFACE_ID_LOADING);
+			
+			//Draw to screen
+			if (Flip_SystemTask())
+			{
+				//Initialize sound
+				InitDirectSound();
+				
+				//Initialize joystick
+				if (config.bJoystick && InitDirectInput())
+				{
+					ResetJoystickStatus();
+					gbUseJoystick = true;
+				}
+				
+				//Initialize stuff
+				InitTextObject(config.font_name);
+				InitTriangleTable();
+				
+				//Run game code
+				Game();
+				
+				//End stuff
+				EndDirectSound();
+				EndTextObject();
+				EndDirectDraw();
+			}
+		}
+	}
+	else
+	{
+		SDL_Quit();
+		return -1;
+	}
+	
+	SDL_Quit();
+	return 0;
+}
+
+void InactiveWindow()
+{
+	if (bActive)
+	{
+		bActive = false;
+		StopOrganyaMusic();
+		SleepNoise();
+	}
+	
+	PlaySoundObject(7, 0);
+}
+
+void ActiveWindow()
+{
+	if (!bActive)
+	{
+		bActive = true;
+		StopOrganyaMusic();
+		PlayOrganyaMusic();
+		ResetNoise();
+	}
+
+	PlaySoundObject(7, -1);
+}
+
+void JoystickProc()
+{
+	JOYSTICK_STATUS status;
+	
+	if (GetJoystickStatus(&status))
+	{
+		//Clear held buttons
+		gKey &= (KEY_ESCAPE | KEY_F2 | KEY_F1);
+		
+		//Set movement buttons
+		if (status.bLeft)
+			gKey |= gKeyLeft;
+		if (status.bRight)
+			gKey |= gKeyRight;
+		if (status.bUp)
+			gKey |= gKeyUp;
+		if (status.bDown)
+			gKey |= gKeyDown;
+		
+		//Set held buttons
+		for (int i = 0; i < 8; i++)
+		{
+			if (status.bButton[i])
+				gKey |= gJoystickButtonTable[i];
+		}
+	}
+}
+
+#define DO_KEY_PRESS(key) \
+	if (event.type == SDL_KEYDOWN) \
+		gKey |= key; \
+	else \
+		gKey &= ~key; \
+	break;
+
+bool SystemTask()
+{
+	//Handle window events
+	bool focusGained = true;
+	
+	while (SDL_PollEvent(NULL) || !focusGained)
+	{
+		SDL_Event event;
+		SDL_WaitEvent(&event);
+		
+		switch (event.type)
+		{
+			case SDL_QUIT:
+				return false;
+				break;
+				
+			case SDL_WINDOWEVENT:
+				switch (event.window.event)
+				{
+					case SDL_WINDOWEVENT_FOCUS_GAINED:
+						focusGained = true;
+						ActiveWindow();
+						break;
+						
+					case SDL_WINDOWEVENT_FOCUS_LOST:
+						focusGained = false;
+						InactiveWindow();
+						break;
+					
+					default:
+						break;
+				}
+				break;
+				
+			case SDL_DROPFILE:
+				LoadProfile(event.drop.file);
+				SDL_free(event.drop.file);
+				break;
+			
+			case SDL_KEYDOWN:
+			case SDL_KEYUP:
+			#ifdef FIX_BUGS
+				//BUG FIX: Pixel relied on key codes for input, but these differ based on keyboard layout.
+				//This would break the alternate movement keys on typical English keyboards, since the '=' key
+				//is in a completely different place to where it is on a Japanese keyboard.
+				//To solve this, we use scancodes instead, which are based on the physical location of keys,
+				//rather than their meaning.
+				switch (event.key.keysym.scancode)
+				{
+					case SDL_SCANCODE_ESCAPE:
+						DO_KEY_PRESS(KEY_ESCAPE)
+
+					case SDL_SCANCODE_W:
+						DO_KEY_PRESS(KEY_MAP)
+
+					case SDL_SCANCODE_LEFT:
+						DO_KEY_PRESS(KEY_LEFT)
+
+					case SDL_SCANCODE_RIGHT:
+						DO_KEY_PRESS(KEY_RIGHT)
+
+					case SDL_SCANCODE_UP:
+						DO_KEY_PRESS(KEY_UP)
+
+					case SDL_SCANCODE_DOWN:
+						DO_KEY_PRESS(KEY_DOWN)
+
+					case SDL_SCANCODE_X:
+						DO_KEY_PRESS(KEY_X)
+
+					case SDL_SCANCODE_Z:
+						DO_KEY_PRESS(KEY_Z)
+
+					case SDL_SCANCODE_S:
+						DO_KEY_PRESS(KEY_ARMS)
+
+					case SDL_SCANCODE_A:
+						DO_KEY_PRESS(KEY_ARMSREV)
+
+					case SDL_SCANCODE_RSHIFT:
+					case SDL_SCANCODE_LSHIFT:
+						DO_KEY_PRESS(KEY_SHIFT)
+
+					case SDL_SCANCODE_F1:
+						DO_KEY_PRESS(KEY_F1)
+
+					case SDL_SCANCODE_F2:
+						DO_KEY_PRESS(KEY_F2)
+
+					case SDL_SCANCODE_Q:
+						DO_KEY_PRESS(KEY_ITEM)
+
+					case SDL_SCANCODE_COMMA:
+						DO_KEY_PRESS(KEY_ALT_LEFT)
+
+					case SDL_SCANCODE_PERIOD:
+						DO_KEY_PRESS(KEY_ALT_DOWN)
+
+					case SDL_SCANCODE_SLASH:
+						DO_KEY_PRESS(KEY_ALT_RIGHT)
+
+					case SDL_SCANCODE_L:
+						DO_KEY_PRESS(KEY_ALT_UP)
+
+					case SDL_SCANCODE_SEMICOLON:
+						DO_KEY_PRESS(KEY_PLUS)
+						
+					case SDL_SCANCODE_F5:
+						gbUseJoystick = false;
+						break;
+
+					default:
+						break;
+				}
+				break;
+			#else
+				switch (event.key.keysym.sym)
+				{
+					case SDLK_ESCAPE:
+						DO_KEY_PRESS(KEY_ESCAPE)
+
+					case SDLK_w:
+						DO_KEY_PRESS(KEY_MAP)
+
+					case SDLK_LEFT:
+						DO_KEY_PRESS(KEY_LEFT)
+
+					case SDLK_RIGHT:
+						DO_KEY_PRESS(KEY_RIGHT)
+
+					case SDLK_UP:
+						DO_KEY_PRESS(KEY_UP)
+
+					case SDLK_DOWN:
+						DO_KEY_PRESS(KEY_DOWN)
+
+					case SDLK_x:
+						DO_KEY_PRESS(KEY_X)
+
+					case SDLK_z:
+						DO_KEY_PRESS(KEY_Z)
+
+					case SDLK_s:
+						DO_KEY_PRESS(KEY_ARMS)
+
+					case SDLK_a:
+						DO_KEY_PRESS(KEY_ARMSREV)
+
+					case SDLK_RSHIFT:
+					case SDLK_LSHIFT:
+						DO_KEY_PRESS(KEY_SHIFT)
+
+					case SDLK_F1:
+						DO_KEY_PRESS(KEY_F1)
+
+					case SDLK_F2:
+						DO_KEY_PRESS(KEY_F2)
+
+					case SDLK_q:
+						DO_KEY_PRESS(KEY_ITEM)
+
+					case SDLK_COMMA:
+						DO_KEY_PRESS(KEY_ALT_LEFT)
+
+					case SDLK_PERIOD:
+						DO_KEY_PRESS(KEY_ALT_DOWN)
+
+					case SDLK_SLASH:
+						DO_KEY_PRESS(KEY_ALT_RIGHT)
+
+					case SDLK_l:
+						DO_KEY_PRESS(KEY_ALT_UP)
+
+					case SDLK_SEMICOLON:
+						DO_KEY_PRESS(KEY_PLUS)
+						
+					case SDLK_F5:
+						gbUseJoystick = false;
+						break;
+				}
+				break;
+			#endif
+		}
+	}
+	
+	//Run joystick code
+	if (gbUseJoystick)
+		JoystickProc();
+	
+	return true;
+}
--- a/src/Types.h
+++ b/src/Types.h
@@ -1,3 +1,3 @@
-#pragma once
-
-//This was originally some sort of POSIX standard thing? leftover from the linux port
+#pragma once
+
+//This was originally some sort of POSIX standard thing? leftover from the linux port
--- a/src/WindowsWrapper.h
+++ b/src/WindowsWrapper.h
@@ -1,32 +1,32 @@
-#pragma once
-
-int rep_rand();
-void rep_srand(unsigned int seed);
-
-typedef int BOOL;
-
-#ifndef FALSE
-#define FALSE 0
-#endif
-
-#ifndef TRUE
-#define TRUE 1
-#endif
-
-struct RECT
-{
-	union
-	{
-		int left;
-		int front;
-	};
-	int top;
-	union
-	{
-		int right;
-		int back;
-	};
-	int bottom;
-};
-
-bool SystemTask();
+#pragma once
+
+int rep_rand();
+void rep_srand(unsigned int seed);
+
+typedef int BOOL;
+
+#ifndef FALSE
+#define FALSE 0
+#endif
+
+#ifndef TRUE
+#define TRUE 1
+#endif
+
+struct RECT
+{
+	union
+	{
+		int left;
+		int front;
+	};
+	int top;
+	union
+	{
+		int right;
+		int back;
+	};
+	int bottom;
+};
+
+bool SystemTask();