From 923b78aa719c46d320d71ce73a05d2a7ee801279 Mon Sep 17 00:00:00 2001 From: Thomas Klausner Date: Tue, 14 Jul 2015 21:50:06 +0200 Subject: [PATCH 1/6] Implement missing osd_truncate(). Fixes linking on Unix when SDL is disabled. Signed-off-by: Thomas Klausner --- src/osd/osdmini/minifile.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/osd/osdmini/minifile.c b/src/osd/osdmini/minifile.c index f2f899744fc..c933238e710 100644 --- a/src/osd/osdmini/minifile.c +++ b/src/osd/osdmini/minifile.c @@ -101,6 +101,25 @@ file_error osd_write(osd_file *file, const void *buffer, UINT64 offset, UINT32 l } +//============================================================ +// osd_truncate +//============================================================ + +file_error osd_truncate(osd_file *file, UINT64 offset) +{ + UINT32 result; + + if (!file) + return FILERR_FAILURE; + + result = ftruncate(fileno((FILE *)file), offset); + if (!result) + return FILERR_FAILURE; + + return FILERR_NONE; +} + + //============================================================ // osd_rmfile //============================================================ From 257a18502c0c554d9395d270a80fd4a59224d383 Mon Sep 17 00:00:00 2001 From: Thomas Klausner Date: Tue, 14 Jul 2015 21:51:00 +0200 Subject: [PATCH 2/6] Fix build using a patch from upstream. https://github.com/bkaradzic/bgfx/commit/e1a564ca720ae66298b61928e6ef0e9d1ee40d30#diff-d51370988baf340d4de0bc2861591415 Signed-off-by: Thomas Klausner --- 3rdparty/bgfx/src/renderer_null.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/3rdparty/bgfx/src/renderer_null.cpp b/3rdparty/bgfx/src/renderer_null.cpp index ce5f812448b..5a86523fc57 100644 --- a/3rdparty/bgfx/src/renderer_null.cpp +++ b/3rdparty/bgfx/src/renderer_null.cpp @@ -33,7 +33,7 @@ namespace bgfx { namespace noop { } - void createIndexBuffer(IndexBufferHandle /*_handle*/, Memory* /*_mem*/, uint8_t /*_flags*/) BX_OVERRIDE + void createIndexBuffer(IndexBufferHandle /*_handle*/, Memory* /*_mem*/, uint16_t /*_flags*/) BX_OVERRIDE { } @@ -49,7 +49,7 @@ namespace bgfx { namespace noop { } - void createVertexBuffer(VertexBufferHandle /*_handle*/, Memory* /*_mem*/, VertexDeclHandle /*_declHandle*/, uint8_t /*_flags*/) BX_OVERRIDE + void createVertexBuffer(VertexBufferHandle /*_handle*/, Memory* /*_mem*/, VertexDeclHandle /*_declHandle*/, uint16_t /*_flags*/) BX_OVERRIDE { } @@ -57,7 +57,7 @@ namespace bgfx { namespace noop { } - void createDynamicIndexBuffer(IndexBufferHandle /*_handle*/, uint32_t /*_size*/, uint8_t /*_flags*/) BX_OVERRIDE + void createDynamicIndexBuffer(IndexBufferHandle /*_handle*/, uint32_t /*_size*/, uint16_t /*_flags*/) BX_OVERRIDE { } @@ -69,7 +69,7 @@ namespace bgfx { namespace noop { } - void createDynamicVertexBuffer(VertexBufferHandle /*_handle*/, uint32_t /*_size*/, uint8_t /*_flags*/) BX_OVERRIDE + void createDynamicVertexBuffer(VertexBufferHandle /*_handle*/, uint32_t /*_size*/, uint16_t /*_flags*/) BX_OVERRIDE { } From 24bfd3e8e85e5415ea9569ccc34ce81f89888fca Mon Sep 17 00:00:00 2001 From: Thomas Klausner Date: Tue, 14 Jul 2015 21:52:03 +0200 Subject: [PATCH 3/6] Add NetBSD support to bx. Will try sending this upstream as well. Signed-off-by: Thomas Klausner --- 3rdparty/bx/include/bx/os.h | 5 +++-- 3rdparty/bx/include/bx/platform.h | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/3rdparty/bx/include/bx/os.h b/3rdparty/bx/include/bx/os.h index 4fcd2c08079..5daae404b8c 100644 --- a/3rdparty/bx/include/bx/os.h +++ b/3rdparty/bx/include/bx/os.h @@ -17,11 +17,12 @@ || BX_PLATFORM_IOS \ || BX_PLATFORM_LINUX \ || BX_PLATFORM_NACL \ + || BX_PLATFORM_NETBSD \ || BX_PLATFORM_OSX \ || BX_PLATFORM_RPI # include // sched_yield -# if BX_PLATFORM_FREEBSD || BX_PLATFORM_IOS || BX_PLATFORM_NACL || BX_PLATFORM_OSX +# if BX_PLATFORM_FREEBSD || BX_PLATFORM_IOS || BX_PLATFORM_NACL || BX_PLATFORM_NETBSD || BX_PLATFORM_OSX # include // mach_port_t # endif // BX_PLATFORM_IOS || BX_PLATFORM_OSX || BX_PLATFORM_NACL @@ -93,7 +94,7 @@ namespace bx return (pid_t)::syscall(SYS_gettid); #elif BX_PLATFORM_IOS || BX_PLATFORM_OSX return (mach_port_t)::pthread_mach_thread_np(pthread_self() ); -#elif BX_PLATFORM_FREEBSD || BX_PLATFORM_NACL +#elif BX_PLATFORM_FREEBSD || BX_PLATFORM_NACL || BX_PLATFORM_NETBSD // Casting __nc_basic_thread_data*... need better way to do this. return *(uint32_t*)::pthread_self(); #else diff --git a/3rdparty/bx/include/bx/platform.h b/3rdparty/bx/include/bx/platform.h index 08b31bf787f..962a8a6fc6d 100644 --- a/3rdparty/bx/include/bx/platform.h +++ b/3rdparty/bx/include/bx/platform.h @@ -18,6 +18,7 @@ #define BX_PLATFORM_IOS 0 #define BX_PLATFORM_LINUX 0 #define BX_PLATFORM_NACL 0 +#define BX_PLATFORM_NETBSD 0 #define BX_PLATFORM_OSX 0 #define BX_PLATFORM_PS4 0 #define BX_PLATFORM_QNX 0 @@ -187,6 +188,9 @@ #elif defined(__FreeBSD__) # undef BX_PLATFORM_FREEBSD # define BX_PLATFORM_FREEBSD 1 +#elif defined(__NetBSD__) +# undef BX_PLATFORM_NETBSD +# define BX_PLATFORM_NETBSD 1 #else # error "BX_PLATFORM_* is not defined!" #endif // @@ -198,6 +202,7 @@ || BX_PLATFORM_IOS \ || BX_PLATFORM_LINUX \ || BX_PLATFORM_NACL \ + || BX_PLATFORM_NETBSD \ || BX_PLATFORM_OSX \ || BX_PLATFORM_QNX \ || BX_PLATFORM_RPI \ @@ -250,6 +255,8 @@ #elif BX_PLATFORM_NACL # define BX_PLATFORM_NAME "NaCl " \ BX_STRINGIZE(BX_PLATFORM_NACL) +#elif BX_PLATFORM_NETBSD +# define BX_PLATFORM_NAME "NetBSD" #elif BX_PLATFORM_OSX # define BX_PLATFORM_NAME "OSX" #elif BX_PLATFORM_PS4 From 910f0215e82c19cbd0c007f77ec007528e3eb3d0 Mon Sep 17 00:00:00 2001 From: Thomas Klausner Date: Tue, 14 Jul 2015 21:52:52 +0200 Subject: [PATCH 4/6] Add NetBSD support. Signed-off-by: Thomas Klausner --- makefile | 24 ++++++++++++++++++++++++ scripts/src/3rdparty.lua | 12 ++++++++++++ scripts/toolchain.lua | 29 ++++++++++++++++++++++++++++- 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/makefile b/makefile index 04d0a748baf..499d4ace282 100644 --- a/makefile +++ b/makefile @@ -296,6 +296,10 @@ ifeq ($(TARGETOS),freebsd) OSD := sdl endif +ifeq ($(TARGETOS),netbsd) +OSD := sdl +endif + ifeq ($(TARGETOS),solaris) OSD := sdl endif @@ -1004,6 +1008,26 @@ freebsd_x86: generate $(PROJECTDIR)/gmake-freebsd/Makefile $(SILENT) $(MAKE) -C $(PROJECTDIR)/gmake-freebsd config=$(CONFIG)32 +#------------------------------------------------- +# gmake-netbsd +#------------------------------------------------- + + +$(PROJECTDIR)/gmake-netbsd/Makefile: makefile $(SCRIPTS) $(GENIE) + $(SILENT) $(GENIE) $(PARAMS) --gcc=netbsd --gcc_version=$(GCC_VERSION) gmake + +.PHONY: netbsd_x64 +netbsd_x64: generate $(PROJECTDIR)/gmake-netbsd/Makefile + $(SILENT) $(MAKE) -C $(PROJECTDIR)/gmake-netbsd config=$(CONFIG)64 + +.PHONY: netbsd +netbsd: netbsd_x86 + +.PHONY: netbsd_x86 +netbsd_x86: generate $(PROJECTDIR)/gmake-netbsd/Makefile + $(SILENT) $(MAKE) -C $(PROJECTDIR)/gmake-netbsd config=$(CONFIG)32 + + #------------------------------------------------- # Clean/bootstrap #------------------------------------------------- diff --git a/scripts/src/3rdparty.lua b/scripts/src/3rdparty.lua index 889a6737cd5..5247517dce0 100644 --- a/scripts/src/3rdparty.lua +++ b/scripts/src/3rdparty.lua @@ -534,6 +534,13 @@ project "portmidi" MAME_DIR .. "3rdparty/portmidi/porttime/ptlinux.c", } end + if _OPTIONS["targetos"]=="netbsd" then + files { + MAME_DIR .. "3rdparty/portmidi/pm_linux/pmlinux.c", + MAME_DIR .. "3rdparty/portmidi/pm_linux/finddefault.c", + MAME_DIR .. "3rdparty/portmidi/porttime/ptlinux.c", + } + end if _OPTIONS["targetos"]=="macosx" then files { MAME_DIR .. "3rdparty/portmidi/pm_mac/pmmac.c", @@ -591,6 +598,11 @@ project "bgfx" MAME_DIR .. "3rdparty/bx/include/compat/freebsd", } + configuration { "netbsd" } + includedirs { + MAME_DIR .. "3rdparty/bx/include/compat/freebsd", + } + configuration { "gmake" } buildoptions { "-Wno-uninitialized", diff --git a/scripts/toolchain.lua b/scripts/toolchain.lua index 91d1f29884e..589db7bc6fa 100644 --- a/scripts/toolchain.lua +++ b/scripts/toolchain.lua @@ -24,6 +24,7 @@ newoption { { "mingw-clang", "MinGW (clang compiler)" }, { "nacl", "Native Client" }, { "nacl-arm", "Native Client - ARM" }, + { "netbsd", "NetBSD" }, { "osx", "OSX (GCC compiler)" }, { "osx-clang", "OSX (Clang compiler)" }, { "pnacl", "Native Client - PNaCl" }, @@ -147,6 +148,10 @@ function toolchain(_buildDir, _subDir) location (_buildDir .. "projects/" .. _subDir .. "/".. _ACTION .. "-freebsd") end + if "netbsd" == _OPTIONS["gcc"] then + location (_buildDir .. "projects/" .. _subDir .. "/".. _ACTION .. "-netbsd") + end + if "ios-arm" == _OPTIONS["gcc"] then premake.gcc.cc = "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" premake.gcc.cxx = "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++" @@ -590,7 +595,29 @@ function toolchain(_buildDir, _subDir) configuration { "freebsd", "x64", "Debug" } targetdir (_buildDir .. "freebsd" .. "/bin/x64/Debug") - + + configuration { "netbsd", "x32" } + objdir (_buildDir .. "netbsd" .. "/obj") + buildoptions { + "-m32", + } + configuration { "netbsd", "x32", "Release" } + targetdir (_buildDir .. "netbsd" .. "/bin/x32/Release") + + configuration { "netbsd", "x32", "Debug" } + targetdir (_buildDir .. "netbsd" .. "/bin/x32/Debug") + + configuration { "netbsd", "x64" } + objdir (_buildDir .. "netbsd" .. "/obj") + buildoptions { + "-m64", + } + configuration { "netbsd", "x64", "Release" } + targetdir (_buildDir .. "netbsd" .. "/bin/x64/Release") + + configuration { "netbsd", "x64", "Debug" } + targetdir (_buildDir .. "netbsd" .. "/bin/x64/Debug") + configuration { "android-*" } includedirs { "$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.8/include", From 456590ce3ead192a4e21f89824e38d6a3dac255b Mon Sep 17 00:00:00 2001 From: Thomas Klausner Date: Tue, 14 Jul 2015 21:54:21 +0200 Subject: [PATCH 5/6] Switch from ftime() to gettimeofday(). Even the Linux man page recommends avoiding ftime(). gettimeofday is in POSIX.1-2001 and more portable. Signed-off-by: Thomas Klausner --- 3rdparty/portmidi/porttime/ptlinux.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/3rdparty/portmidi/porttime/ptlinux.c b/3rdparty/portmidi/porttime/ptlinux.c index 768dd4847f7..c58107c36ad 100644 --- a/3rdparty/portmidi/porttime/ptlinux.c +++ b/3rdparty/portmidi/porttime/ptlinux.c @@ -38,7 +38,7 @@ CHANGE LOG #define FALSE 0 static int time_started_flag = FALSE; -static struct timeb time_offset = {0, 0, 0, 0}; +static struct timeval time_offset = {0, 0}; static pthread_t pt_thread_pid; static int pt_thread_created = FALSE; @@ -79,7 +79,7 @@ static void *Pt_CallbackProc(void *p) PtError Pt_Start(int resolution, PtCallback *callback, void *userData) { if (time_started_flag) return ptNoError; - ftime(&time_offset); /* need this set before process runs */ + gettimeofday(&time_offset, NULL); /* need this set before process runs */ if (callback) { int res; pt_callback_parameters *parms = (pt_callback_parameters *) @@ -121,10 +121,10 @@ int Pt_Started() PtTimestamp Pt_Time() { long seconds, milliseconds; - struct timeb now; - ftime(&now); - seconds = now.time - time_offset.time; - milliseconds = now.millitm - time_offset.millitm; + struct timeval now; + gettimeofday(&now, NULL); + seconds = now.tv_sec - time_offset.tv_sec; + milliseconds = now.tv_usec - time_offset.tv_usec; return seconds * 1000 + milliseconds; } From 7769689bd7625289fe2416a21d8971060f17fe2b Mon Sep 17 00:00:00 2001 From: Thomas Klausner Date: Tue, 14 Jul 2015 23:41:06 +0200 Subject: [PATCH 6/6] Fix error handling of osd_truncate. Noted by startaq in https://github.com/mamedev/mame/pull/257. Signed-off-by: Thomas Klausner --- src/osd/osdmini/minifile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/osd/osdmini/minifile.c b/src/osd/osdmini/minifile.c index c933238e710..86b816d3ce2 100644 --- a/src/osd/osdmini/minifile.c +++ b/src/osd/osdmini/minifile.c @@ -113,7 +113,7 @@ file_error osd_truncate(osd_file *file, UINT64 offset) return FILERR_FAILURE; result = ftruncate(fileno((FILE *)file), offset); - if (!result) + if (result) return FILERR_FAILURE; return FILERR_NONE;