timdoug's tidbits


2022-06-03

Play Super Mario 64 natively on an M1 Mac

Checkout https://github.com/sm64-port/sm64-port.git, apply the following super hacky diff, brew install gcc mingw-w64 make pkg-config sdl2 glew libusb, copy the ROM per the docs, and run gmake (for the newer brew version, not the old OS one).

$ file build/us_pc/sm64.us
build/us_pc/sm64.us: Mach-O 64-bit executable arm64
$ otool -L build/us_pc/sm64.us
build/us_pc/sm64.us:
	/opt/homebrew/opt/libusb/lib/libusb-1.0.0.dylib (compatibility version 4.0.0, current version 4.0.0)
	/opt/homebrew/opt/sdl2/lib/libSDL2-2.0.0.dylib (compatibility version 23.0.0, current version 23.0.0)
	/opt/homebrew/opt/glew/lib/libGLEW.2.2.dylib (compatibility version 2.2.0, current version 2.2.0)
	/opt/homebrew/opt/gcc/lib/gcc/11/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.29.0)
	/System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL (compatibility version 1.0.0, current version 1.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.100.3)
$

Fascinating how we've gotten here, no?

diff --git a/Makefile b/Makefile
index cfac1e8..cf62291 100644
--- a/Makefile
+++ b/Makefile
@@ -456,10 +456,10 @@ export LANG := C
 
 else # TARGET_N64
 
-AS := as
+AS := i686-w64-mingw32-as
 ifneq ($(TARGET_WEB),1)
-  CC := gcc
-  CXX := g++
+  CC := gcc-11
+  CXX := g++-11
 else
   CC := emcc
 endif
@@ -468,8 +468,8 @@ ifeq ($(CXX_FILES),"")
 else
   LD := $(CXX)
 endif
-OBJDUMP := objdump
-OBJCOPY := objcopy
+OBJDUMP := i686-w64-mingw32-objdump
+OBJCOPY := i686-w64-mingw32-objcopy
 PYTHON := python3
 
 # Platform-specific compiler and linker flags
@@ -479,7 +479,7 @@ ifeq ($(TARGET_WINDOWS),1)
 endif
 ifeq ($(TARGET_LINUX),1)
   PLATFORM_CFLAGS  := -DTARGET_LINUX `pkg-config --cflags libusb-1.0`
-  PLATFORM_LDFLAGS := -lm -lpthread `pkg-config --libs libusb-1.0` -lasound -lpulse -no-pie
+  PLATFORM_LDFLAGS := -lm -lpthread `pkg-config --libs libusb-1.0` -no-pie
 endif
 ifeq ($(TARGET_WEB),1)
   PLATFORM_CFLAGS  := -DTARGET_WEB
@@ -497,8 +497,8 @@ ifeq ($(ENABLE_OPENGL),1)
     GFX_LDFLAGS += $(shell sdl2-config --libs) -lglew32 -lopengl32 -lwinmm -limm32 -lversion -loleaut32 -lsetupapi
   endif
   ifeq ($(TARGET_LINUX),1)
-    GFX_CFLAGS  += $(shell sdl2-config --cflags)
-    GFX_LDFLAGS += -lGL $(shell sdl2-config --libs) -lX11 -lXrandr
+    GFX_CFLAGS  += $(shell sdl2-config --cflags) -I/opt/homebrew/include
+    GFX_LDFLAGS += $(shell sdl2-config --libs) -L/opt/homebrew/lib -lGLEW -framework OpenGL
   endif
   ifeq ($(TARGET_WEB),1)
     GFX_CFLAGS  += -s USE_SDL=2
diff --git a/include/PR/os_libc.h b/include/PR/os_libc.h
index 94111c0..6a43358 100644
--- a/include/PR/os_libc.h
+++ b/include/PR/os_libc.h
@@ -3,8 +3,6 @@
 
 #include "ultratypes.h"
 
-// Old deprecated functions from strings.h, replaced by memcpy/memset.
-extern void bcopy(const void *, void *, size_t);
-extern void bzero(void *, size_t);
+#include <string.h>
 
 #endif /* !_OS_LIBC_H_ */
diff --git a/src/pc/controller/wup.c b/src/pc/controller/wup.c
index 9de54c1..35a37d3 100644
--- a/src/pc/controller/wup.c
+++ b/src/pc/controller/wup.c
@@ -1,4 +1,4 @@
-#if !defined(__MINGW32__) && !defined(__BSD__) && !defined(TARGET_WEB)
+#if !defined(__MINGW32__) && !defined(__BSD__) && !defined(TARGET_WEB) && !defined(__APPLE__)
 // See LICENSE for license
 
 #define _XOPEN_SOURCE 600
diff --git a/src/pc/gfx/gfx_opengl.c b/src/pc/gfx/gfx_opengl.c
index 7bc9745..51824cc 100644
--- a/src/pc/gfx/gfx_opengl.c
+++ b/src/pc/gfx/gfx_opengl.c
@@ -8,7 +8,7 @@
 #endif
 #include <PR/gbi.h>
 
-#ifdef __MINGW32__
+#if defined(__MINGW32__) || defined(__APPLE__)
 #define FOR_WINDOWS 1
 #else
 #define FOR_WINDOWS 0
diff --git a/src/pc/gfx/gfx_sdl2.c b/src/pc/gfx/gfx_sdl2.c
index 4fd5c43..79622a5 100644
--- a/src/pc/gfx/gfx_sdl2.c
+++ b/src/pc/gfx/gfx_sdl2.c
@@ -2,7 +2,7 @@
 
 #if !defined(__linux__) && !defined(__BSD__) && defined(ENABLE_OPENGL)
 
-#ifdef __MINGW32__
+#if defined(__MINGW32__) || defined(__APPLE__)
 #define FOR_WINDOWS 1
 #else
 #define FOR_WINDOWS 0
diff --git a/src/pc/pc_main.c b/src/pc/pc_main.c
index 89aa1fa..d1fde8d 100644
--- a/src/pc/pc_main.c
+++ b/src/pc/pc_main.c
@@ -196,7 +196,7 @@ void main_func(void) {
         audio_api = &audio_alsa;
     }
 #endif
-#ifdef TARGET_WEB
+#if defined(TARGET_WEB) || defined(__APPLE__)
     if (audio_api == NULL && audio_sdl.init()) {
         audio_api = &audio_sdl;
     }

[/osx] permanent link


© 2006-24 timdoug | email: "me" at this domain
So necessary