From fa9af3227e734d01b7052976f4ea2d0b057ef3cc Mon Sep 17 00:00:00 2001 From: yksoft1 Date: Thu, 14 May 2020 23:47:00 +0800 Subject: [PATCH 1/5] Make the code buildable on MinGW.org (not mingw-w64) and MSYS1. --- include/PR/ultratypes.h | 4 ++++ include/ultra64.h | 6 ++++++ src/pc/gfx/gfx_pc.c | 14 ++++++++++++++ tools/utils.h | 3 ++- 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/include/PR/ultratypes.h b/include/PR/ultratypes.h index 8a00490a..8d590542 100644 --- a/include/PR/ultratypes.h +++ b/include/PR/ultratypes.h @@ -38,7 +38,11 @@ typedef s32 ptrdiff_t; #else #include #include +#if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) +typedef long ssize_t; +#else typedef ptrdiff_t ssize_t; #endif +#endif #endif diff --git a/include/ultra64.h b/include/ultra64.h index 409a3cf7..94bbc388 100644 --- a/include/ultra64.h +++ b/include/ultra64.h @@ -30,4 +30,10 @@ #include #include +#if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) +#include +#define bzero(b,len) (memset((b), '\0', (len)), (void) 0) +#define bcopy(s1, s2, n) memmove((s2), (s1), (n)) +#endif + #endif diff --git a/src/pc/gfx/gfx_pc.c b/src/pc/gfx/gfx_pc.c index d674a4d6..72147886 100644 --- a/src/pc/gfx/gfx_pc.c +++ b/src/pc/gfx/gfx_pc.c @@ -153,7 +153,21 @@ static size_t buf_vbo_num_tris; static struct GfxWindowManagerAPI *gfx_wapi; static struct GfxRenderingAPI *gfx_rapi; +#if defined(_WIN32) && !defined(__MINGW64_VERSION_MAJOR) +#include +#define CLOCK_MONOTONIC 0 +//https://stackoverflow.com/questions/5404277/porting-clock-gettime-to-windows +struct timespec { long tv_sec; long tv_nsec; }; //header part +int clock_gettime(int arg, struct timespec *spec) //C-file part +{ __int64 wintime; GetSystemTimeAsFileTime((FILETIME*)&wintime); + wintime -=116444736000000000LL; //1jan1601 to 1jan1970 + spec->tv_sec =wintime / 10000000LL; //seconds + spec->tv_nsec =wintime % 10000000LL*100; //nano-seconds + return 0; +} +#else #include +#endif static unsigned long get_time(void) { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); diff --git a/tools/utils.h b/tools/utils.h index dff1d6a3..03f482d0 100644 --- a/tools/utils.h +++ b/tools/utils.h @@ -7,8 +7,9 @@ // printing size_t varies by compiler #if defined(_MSC_VER) || defined(__MINGW32__) + #include #define SIZE_T_FORMAT "%Iu" - #define realpath(N,R) _fullpath((R),(N),_MAX_PATH) + #define realpath(N,R) _fullpath((R),(N),MAX_PATH) #else #define SIZE_T_FORMAT "%zu" #endif From 1b03e251bb59b205fc277877306ebd81c454f5d4 Mon Sep 17 00:00:00 2001 From: yksoft1 Date: Fri, 15 May 2020 00:26:56 +0800 Subject: [PATCH 2/5] Better way to detect mingw-w64; fix bettercamera for mingw.org; close .assets-local.txt before deleting it. --- extract_assets.py | 1 + include/PR/ultratypes.h | 5 ++++- include/ultra64.h | 5 ++++- src/game/bettercamera.inc.h | 5 ++++- src/pc/gfx/gfx_pc.c | 5 ++++- 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/extract_assets.py b/extract_assets.py index 706fc728..7c29358b 100755 --- a/extract_assets.py +++ b/extract_assets.py @@ -47,6 +47,7 @@ def remove_file(fname): def clean_assets(local_asset_file): assets = set(read_asset_map().keys()) assets.update(read_local_asset_list(local_asset_file)) + local_asset_file.close() for fname in list(assets) + [".assets-local.txt"]: if fname.startswith("@"): continue diff --git a/include/PR/ultratypes.h b/include/PR/ultratypes.h index 8d590542..62f14f31 100644 --- a/include/PR/ultratypes.h +++ b/include/PR/ultratypes.h @@ -38,11 +38,14 @@ typedef s32 ptrdiff_t; #else #include #include -#if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) +#if defined(__MINGW32__) +#include <_mingw.h> +#if !defined(__MINGW64_VERSION_MAJOR) typedef long ssize_t; #else typedef ptrdiff_t ssize_t; #endif #endif +#endif #endif diff --git a/include/ultra64.h b/include/ultra64.h index 94bbc388..e78ded49 100644 --- a/include/ultra64.h +++ b/include/ultra64.h @@ -30,10 +30,13 @@ #include #include -#if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) +#if defined(__MINGW32__) +#include <_mingw.h> +#if !defined(__MINGW64_VERSION_MAJOR) #include #define bzero(b,len) (memset((b), '\0', (len)), (void) 0) #define bcopy(s1, s2, n) memmove((s2), (s1), (n)) #endif +#endif #endif diff --git a/src/game/bettercamera.inc.h b/src/game/bettercamera.inc.h index 6c9592b8..b48f5d4c 100644 --- a/src/game/bettercamera.inc.h +++ b/src/game/bettercamera.inc.h @@ -9,8 +9,11 @@ #include "include/text_strings.h" #include "engine/surface_collision.h" #include "pc/configfile.h" +#if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) +//quick and dirty fix for some older MinGW.org mingwrt +#else #include - +#endif /** diff --git a/src/pc/gfx/gfx_pc.c b/src/pc/gfx/gfx_pc.c index 72147886..570c5305 100644 --- a/src/pc/gfx/gfx_pc.c +++ b/src/pc/gfx/gfx_pc.c @@ -153,7 +153,9 @@ static size_t buf_vbo_num_tris; static struct GfxWindowManagerAPI *gfx_wapi; static struct GfxRenderingAPI *gfx_rapi; -#if defined(_WIN32) && !defined(__MINGW64_VERSION_MAJOR) +#if defined(__MINGW32__) +#include <_mingw.h> +#if !defined(__MINGW64_VERSION_MAJOR) #include #define CLOCK_MONOTONIC 0 //https://stackoverflow.com/questions/5404277/porting-clock-gettime-to-windows @@ -168,6 +170,7 @@ int clock_gettime(int arg, struct timespec *spec) //C-file part #else #include #endif +#endif static unsigned long get_time(void) { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); From 072025d24339661af332ce2cce213d77d843b385 Mon Sep 17 00:00:00 2001 From: yksoft1 Date: Sun, 17 May 2020 19:01:13 +0800 Subject: [PATCH 3/5] Fix cliopts on MinGW.org. --- src/pc/cliopts.c | 1 + src/pc/cliopts.h | 1 + 2 files changed, 2 insertions(+) diff --git a/src/pc/cliopts.c b/src/pc/cliopts.c index 1e3b29c8..50487134 100644 --- a/src/pc/cliopts.c +++ b/src/pc/cliopts.c @@ -1,6 +1,7 @@ #include "cliopts.h" #include #include +#define __NO_MINGW_LFS //Mysterious error in MinGW.org stdio.h #include struct PCCLIOptions gCLIOpts; diff --git a/src/pc/cliopts.h b/src/pc/cliopts.h index 1844c44c..75d78e8b 100644 --- a/src/pc/cliopts.h +++ b/src/pc/cliopts.h @@ -1,3 +1,4 @@ +#include #include "sm64.h" struct PCCLIOptions From ee795fa7af4baf6118004fda6d9b02fb44a1c6dc Mon Sep 17 00:00:00 2001 From: yksoft1 Date: Tue, 19 May 2020 20:15:25 +0800 Subject: [PATCH 4/5] My hacks to cliopts.h is not necessary anymore. --- src/pc/cliopts.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/pc/cliopts.h b/src/pc/cliopts.h index 75d78e8b..d20dcb4f 100644 --- a/src/pc/cliopts.h +++ b/src/pc/cliopts.h @@ -1,13 +1,14 @@ -#include -#include "sm64.h" +#ifndef _CLIOPTS_H +#define _CLIOPTS_H -struct PCCLIOptions -{ - u8 SkipIntro; - u8 FullScreen; - char * ConfigFile; +struct PCCLIOptions { + unsigned int SkipIntro; + unsigned int FullScreen; + char ConfigFile[1024]; }; extern struct PCCLIOptions gCLIOpts; void parse_cli_opts(int argc, char* argv[]); + +#endif // _CLIOPTS_H From 5cb3bfd2f6e66cabdd703b2e648b5cc1413adb83 Mon Sep 17 00:00:00 2001 From: yksoft1 Date: Tue, 19 May 2020 20:39:01 +0800 Subject: [PATCH 5/5] Fix types.h include guard to avoid any conflict with . --- include/types.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/types.h b/include/types.h index 483c894f..870223eb 100644 --- a/include/types.h +++ b/include/types.h @@ -1,5 +1,5 @@ -#ifndef _TYPES_H_ -#define _TYPES_H_ +#ifndef _SM64_TYPES_H_ +#define _SM64_TYPES_H_ // This file contains various data types used in Super Mario 64 that don't yet // have an appropriate header.