shithub: cstory

Download patch

ref: 406ff1890954a97738f9522e88c0c51ab8cb8a01
parent: e4a20a983e43757948b339adf110fc9e843009dc
author: Clownacy <Clownacy@users.noreply.github.com>
date: Fri Mar 13 17:35:51 EDT 2020

Add CMakeLists.txt and Visual Studio 6 support

The CMake file allows you to compile the accurate branch with
whatever version of Visual Studio you have lying around, without
having to clumbsily convert the VS2003 project.

I've tested this with VS2019, VS2003, and VS6. VS6 is goofy - it's
missing a few types and constants, and it's not smart enough to
realise that ints and longs are the same in ILP32 data models. I've
added a few small hacks to address this. Might undo them. Who knows.

For now, I want to support VS6 because Mint compiled CSE2 with it
before, and because VS6 uses `msvcrt.dll` as its C runtime, which
apparently comes pre-installed in Windows, as opposed to all those
other annoying runtime versions that require they be installed
separately (which is why MinGW targets it specifically).

Also, VS6 *should* give us Win95-compatible builds. The internet says
MSVC2003 is Win95-compatible too, but Mint claims the vanilla EXE
doesn't run on there. I imagine it has something to do with its
static runtime library (VS2003 links the static one by default for
some reason).

--- /dev/null
+++ b/CMakeLists.txt
@@ -1,0 +1,216 @@
+cmake_minimum_required(VERSION 3.12)
+
+set(ASSETS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/assets")
+
+option(JAPANESE "Enable the Japanese-language build" OFF)
+option(FIX_BUGS "Fix various bugs in the game" ON)
+option(DEBUG_SAVE "Re-enable the ability to drag-and-drop save files onto the window" OFF)
+
+project(CSE2 LANGUAGES C CXX)
+
+#if(MSVC)
+	# Statically-link the CRT (vcpkg static libs do this)
+#	foreach(flag_var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
+#		if(${flag_var} MATCHES "/MD")
+#			string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
+#		endif()
+#	endforeach()
+#endif()
+
+##
+# CSE2
+##
+
+add_executable(CSE2
+	"src/ArmsItem.cpp"
+	"src/ArmsItem.h"
+	"src/Back.cpp"
+	"src/Back.h"
+	"src/Boss.cpp"
+	"src/Boss.h"
+	"src/BossAlmo1.cpp"
+	"src/BossAlmo1.h"
+	"src/BossAlmo2.cpp"
+	"src/BossAlmo2.h"
+	"src/BossBallos.cpp"
+	"src/BossBallos.h"
+	"src/BossFrog.cpp"
+	"src/BossFrog.h"
+	"src/BossIronH.cpp"
+	"src/BossIronH.h"
+	"src/BossLife.cpp"
+	"src/BossLife.h"
+	"src/BossOhm.cpp"
+	"src/BossOhm.h"
+	"src/BossPress.cpp"
+	"src/BossPress.h"
+	"src/BossTwinD.cpp"
+	"src/BossTwinD.h"
+	"src/BossX.cpp"
+	"src/BossX.h"
+	"src/BulHit.cpp"
+	"src/BulHit.h"
+	"src/Bullet.cpp"
+	"src/Bullet.h"
+	"src/Caret.cpp"
+	"src/Caret.h"
+	"src/CommonDefines.h"
+	"src/Config.cpp"
+	"src/Config.h"
+	"src/Dialog.cpp"
+	"src/Dialog.h"
+	"src/Draw.cpp"
+	"src/Draw.h"
+	"src/Ending.cpp"
+	"src/Ending.h"
+	"src/Escape.cpp"
+	"src/Escape.h"
+	"src/Fade.cpp"
+	"src/Fade.h"
+	"src/Flags.cpp"
+	"src/Flags.h"
+	"src/Flash.cpp"
+	"src/Flash.h"
+	"src/Frame.cpp"
+	"src/Frame.h"
+	"src/Game.cpp"
+	"src/Game.h"
+	"src/Generic.cpp"
+	"src/Generic.h"
+	"src/GenericLoad.cpp"
+	"src/GenericLoad.h"
+	"src/Input.cpp"
+	"src/Input.h"
+	"src/KeyControl.cpp"
+	"src/KeyControl.h"
+	"src/Main.cpp"
+	"src/Main.h"
+	"src/Map.cpp"
+	"src/Map.h"
+	"src/MapName.cpp"
+	"src/MapName.h"
+	"src/MiniMap.cpp"
+	"src/MiniMap.h"
+	"src/MyChar.cpp"
+	"src/MyChar.h"
+	"src/MycHit.cpp"
+	"src/MycHit.h"
+	"src/MycParam.cpp"
+	"src/MycParam.h"
+	"src/NpcAct.h"
+	"src/NpcAct000.cpp"
+	"src/NpcAct020.cpp"
+	"src/NpcAct040.cpp"
+	"src/NpcAct060.cpp"
+	"src/NpcAct080.cpp"
+	"src/NpcAct100.cpp"
+	"src/NpcAct120.cpp"
+	"src/NpcAct140.cpp"
+	"src/NpcAct160.cpp"
+	"src/NpcAct180.cpp"
+	"src/NpcAct200.cpp"
+	"src/NpcAct220.cpp"
+	"src/NpcAct240.cpp"
+	"src/NpcAct260.cpp"
+	"src/NpcAct280.cpp"
+	"src/NpcAct300.cpp"
+	"src/NpcAct320.cpp"
+	"src/NpcAct340.cpp"
+	"src/NpChar.cpp"
+	"src/NpChar.h"
+	"src/NpcHit.cpp"
+	"src/NpcHit.h"
+	"src/NpcTbl.cpp"
+	"src/NpcTbl.h"
+	"src/Organya.cpp"
+	"src/Organya.h"
+	"src/PixTone.cpp"
+	"src/PixTone.h"
+	"src/Profile.cpp"
+	"src/Profile.h"
+	"src/SelStage.cpp"
+	"src/SelStage.h"
+	"src/Shoot.cpp"
+	"src/Shoot.h"
+	"src/Sound.cpp"
+	"src/Sound.h"
+	"src/Stage.cpp"
+	"src/Stage.h"
+	"src/Star.cpp"
+	"src/Star.h"
+	"src/TextScr.cpp"
+	"src/TextScr.h"
+	"src/Triangle.cpp"
+	"src/Triangle.h"
+	"src/ValueView.cpp"
+	"src/ValueView.h"
+	"src/WindowsWrapper.h"
+)
+
+# Handle options
+if(JAPANESE)
+	set(BUILD_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/game_japanese")
+	target_compile_definitions(CSE2 PRIVATE JAPANESE)
+else()
+	set(BUILD_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/game_english")
+endif()
+
+if(FIX_BUGS)
+	target_compile_definitions(CSE2 PRIVATE FIX_BUGS)
+endif()
+
+if(DEBUG_SAVE)
+	target_compile_definitions(CSE2 PRIVATE DEBUG_SAVE)
+endif()
+
+# Make some tweaks if we're targetting Windows
+#if(WIN32)
+	target_sources(CSE2 PRIVATE "${ASSETS_DIRECTORY}/resources/CSE2.rc")
+	set_target_properties(CSE2 PROPERTIES WIN32_EXECUTABLE YES)	# Disable the console window
+#endif()
+
+# Make some tweaks if we're using MSVC
+if(MSVC)
+	target_compile_definitions(CSE2 PRIVATE _CRT_SECURE_NO_WARNINGS)	# Disable warnings that normally fire up on MSVC when using "unsafe" functions instead of using MSVC's "safe" _s functions
+endif()
+
+# Make it so source files are recognized as UTF-8 by MSVC
+if(MSVC)
+	target_compile_options(CSE2 PRIVATE "/utf-8")
+endif()
+
+# Force strict C90
+set_target_properties(CSE2 PROPERTIES
+	C_STANDARD 90
+	C_STANDARD_REQUIRED ON
+	C_EXTENSIONS OFF
+)
+
+# Force strict C++98
+set_target_properties(CSE2 PROPERTIES
+	CXX_STANDARD 98
+	CXX_STANDARD_REQUIRED ON
+	CXX_EXTENSIONS OFF
+)
+
+# 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
+	RUNTIME_OUTPUT_DIRECTORY ${BUILD_DIRECTORY}
+	RUNTIME_OUTPUT_DIRECTORY_RELEASE ${BUILD_DIRECTORY}
+	RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${BUILD_DIRECTORY}
+	RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${BUILD_DIRECTORY}
+	RUNTIME_OUTPUT_DIRECTORY_DEBUG ${BUILD_DIRECTORY}
+)
+
+# Link libraries
+target_link_libraries(CSE2 PRIVATE ddraw.lib dsound.lib Version.lib ShLwApi.Lib Imm32.lib WinMM.lib dxguid.lib)
+
+# Newer MSVC is missing `dinput.lib`
+if(MSVC AND MSVC_VERSION GREATER_EQUAL 1500)
+	target_link_libraries(CSE2 PRIVATE dinput8.lib)
+else()
+	target_link_libraries(CSE2 PRIVATE dinput.lib)
+endif()
--- a/src/Main.cpp
+++ b/src/Main.cpp
@@ -22,6 +22,23 @@
 #include "Sound.h"
 #include "Triangle.h"
 
+// Visual Studio 6 is missing these, so define them here just in case
+#ifndef VK_OEM_PLUS
+#define VK_OEM_PLUS 0xBB
+#endif
+
+#ifndef VK_OEM_COMMA
+#define VK_OEM_COMMA 0xBC
+#endif
+
+#ifndef VK_OEM_PERIOD
+#define VK_OEM_PERIOD 0xBE
+#endif
+
+#ifndef VK_OEM_2
+#define VK_OEM_2 0xBF
+#endif
+
 LRESULT __stdcall WindowProcedure(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
 
 char gModulePath[MAX_PATH];
@@ -676,12 +693,12 @@
 			switch (LOWORD(wParam))
 			{
 				case 40001:
-					if (DialogBoxParamA(ghInstance, "DLG_YESNO", hWnd, QuitDialog, (LPARAM)"Quit?") == 1)
+					if (DialogBoxParamA(ghInstance, "DLG_YESNO", hWnd, (DLGPROC)QuitDialog, (LPARAM)"Quit?") == 1)
 						PostMessageA(hWnd, WM_CLOSE, 0, 0);
 					break;
 
 				case 40002:
-					DialogBoxParamA(ghInstance, "DLG_ABOUT", hWnd, VersionDialog, 0);
+					DialogBoxParamA(ghInstance, "DLG_ABOUT", hWnd, (DLGPROC)VersionDialog, 0);
 					break;
 
 				case 40004:
@@ -690,11 +707,11 @@
 					break;
 
 				case 40005:
-					DialogBoxParamA(ghInstance, "DLG_SAVE", hWnd, DebugSaveDialog, 0);
+					DialogBoxParamA(ghInstance, "DLG_SAVE", hWnd, (DLGPROC)DebugSaveDialog, 0);
 					break;
 
 				case 40007:
-					DialogBoxParamA(ghInstance, "DLG_MUTE", hWnd, DebugMuteDialog, 0);
+					DialogBoxParamA(ghInstance, "DLG_MUTE", hWnd, (DLGPROC)DebugMuteDialog, 0);
 					break;
 			}
 
--- a/src/Organya.cpp
+++ b/src/Organya.cpp
@@ -22,6 +22,11 @@
 
 #include "Sound.h"
 
+// Visual Studio 6 is missing this
+#ifndef DWORD_PTR
+#define DWORD_PTR DWORD
+#endif
+
 #define PANDUMMY 0xFF
 #define VOLDUMMY 0xFF
 #define KEYDUMMY 0xFF