]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Added Nintendo Switch Make target
authorLockl00p <97256723+Lockl00p@users.noreply.github.com>
Thu, 23 May 2024 23:47:34 +0000 (18:47 -0500)
committerLockl00p <97256723+Lockl00p@users.noreply.github.com>
Thu, 23 May 2024 23:47:34 +0000 (18:47 -0500)
This time, it actually works!

.gitignore
README.md
fs.c
makefile
makefile.inc
sys.h
sys_shared.c
sys_switch.c [new file with mode: 0644]
vid_sdl.c

index 4c4c53c9aedc82d5ecf50e147a54518cae8cee0f..3e912282f10fc591407002fa54df5682ac1a9a1a 100644 (file)
@@ -3,6 +3,7 @@ obj/
 *.o
 *.i
 *.s
+*.nro
 
 # MSVC build objects
 Debug-darkplaces-sdl2-vs*/
index df037d5c395d915012a76c835b768496c7d7751f..ae5eddd26c059721d61b53f0db1b33c955a21363 100644 (file)
--- a/README.md
+++ b/README.md
@@ -109,6 +109,17 @@ The Release build crashes. The Debug x64 build doesn't crash (but is rather slow
 To get a build suitable for playing you'll need to use MinGW GCC, or download the autobuild from Xonotic (see above).
 
 
+### Switch (devkitpro)
+Note: This requires a modded switch.
+1. Install [devkitpro](https://devkitpro.org/wiki/Getting_Started)
+2. Run this command:
+```
+(sudo) dkp-pacman -Syu switch-dev switch-sdl switch-libjpeg-turbo switch-zlib
+```
+3. Build using `DP_MAKE_TARGET=switch make sdl-release`.
+4. Copy `darkplaces-sdl.nro` to your switch's SD Card
+
+(Basedir is `/switch/darkplaces/(switch username)`)
 ## Contributing
 
 [DarkPlaces Contributing Guidelines](CONTRIBUTING.md)
diff --git a/fs.c b/fs.c
index 6e4259717b0c3ffbd733557a995f23d0ece5e296..bbab3b57a25bf46516f88957e5a9636ed26d83d8 100644 (file)
--- a/fs.c
+++ b/fs.c
@@ -53,6 +53,9 @@
 #include "utf8lib.h"
 #endif
 
+#ifdef __SWITCH__
+#include <switch.h>
+#endif
 // Win32 requires us to add O_BINARY, but the other OSes don't have it
 #ifndef O_BINARY
 # define O_BINARY 0
@@ -2193,6 +2196,24 @@ static void FS_Init_Dir (void)
                                }
                        }
                }
+#elif defined(__SWITCH__)
+       AccountUid userID = {0};;
+       AccountProfile profile = {0};
+       AccountProfileBase profileBase = {0};
+       Result result = accountGetPreselectedUser(&userID);
+       if(R_FAILED(result)){
+               StartupError("Unable to get selected user.\nApplet mode is not supported.");
+       }
+       accountGetProfile(&profile, userID);
+       accountProfileGet(&profile,NULL,&profileBase);
+
+       dpsnprintf(fs_basedir, sizeof(fs_basedir), "/switch/darkplaces/%s",profileBase.nickname);
+       //No idea why I need to make this weird struct to use stat but stackoverflow decreed I must, so I shall.
+       struct stat sb;
+       if(stat(fs_basedir,&sb) == -1){
+       //Also did not know about mkdir function so thank you stack overflow.
+               mkdir(fs_basedir,0777);
+       }
 #else
                // use the working directory
                getcwd(fs_basedir, sizeof(fs_basedir));
index b62194cd42dc9a93e07649c33aec7b33817f054b..619a7c5d15e1ed48a243662ce24d9f33e923277d 100644 (file)
--- a/makefile
+++ b/makefile
@@ -110,6 +110,43 @@ ifeq ($(DP_MAKE_TARGET), linux)
        DP_LINK_XMP?=dlopen
 endif
 
+# Switch configuration
+ifeq ($(DP_MAKE_TARGET), switch)
+       ifeq ($(strip $(DEVKITPRO)),)
+$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
+       endif
+
+       CC=$(DEVKITPRO)/devkitA64/bin/aarch64-none-elf-gcc
+       DP_SSE=0
+       
+       CFLAGS_EXTRA=$(CFLAGS_SWITCH)
+       OBJ_ICON=
+       OBJ_ICON_NEXUIZ=
+       
+       SYS_OBJ=sys_switch.o
+       LDFLAGS_SV=$(LDFLAGS_SWITCHSV)
+       LDFLAGS_SDL=$(LDFLAGS_SWITCHSDL)
+       SDL_CONFIG=$(DEVKITPRO)/portlibs/switch/bin/sdl2-config
+       SDLCONFIG_CFLAGS=$(SDLCONFIG_UNIXCFLAGS)
+       SDLCONFIG_LIBS=$(SDLCONFIG_UNIXLIBS) 
+       SDLCONFIG_STATICLIBS=$(SDLCONFIG_UNIXSTATICLIBS) 
+
+       EXE_SV=$(EXE_UNIXSV)
+       EXE_SDL=$(EXE_UNIXSDL)
+       EXE_SVNEXUIZ=$(EXE_UNIXSVNEXUIZ)
+       EXE_SDLNEXUIZ=$(EXE_UNIXSDLNEXUIZ)
+       STRIP=elf2nro
+       STRIPARGS=$(EXE) $(EXE).nro
+
+       DP_LINK_SDL?=shared
+       DP_LINK_ZLIB?=shared
+       DP_LINK_JPEG?=shared
+       DP_LINK_ODE?=
+       DP_LINK_CRYPTO?=dlopen
+       DP_LINK_CRYPTO_RIJNDAEL?=dlopen
+       DP_LINK_XMP?=dlopen
+endif
+
 # Mac OS X configuration
 ifeq ($(DP_MAKE_TARGET), macosx)
        OBJ_ICON=
index 33cbc0438525ef568d77e9858a68673580f2f160..4c5bfe3ba133b9c74db672f25ef2db4135f43078 100644 (file)
@@ -4,7 +4,7 @@ CHECKLEVEL2 = @if [ "$(LEVEL)" != 2 ]; then $(MAKE) help; false; fi
 
 
 STRIP?=strip
-
+STRIPARGS?=$(EXE)
 
 ###### Sound #####
 
@@ -126,8 +126,9 @@ OBJ_MENU= \
 # note that builddate.c is very intentionally not compiled to a .o before
 # being linked, because it should be recompiled every time an executable is
 # built to give the executable a proper date string
+SYS_OBJ ?= sys_sdl.o
 OBJ_SV= builddate.c sys_null.o vid_null.o thread_null.o $(OBJ_SND_NULL) $(OBJ_COMMON)
-OBJ_SDL= builddate.c sys_sdl.o vid_sdl.o thread_sdl.o $(OBJ_MENU) $(OBJ_SND_COMMON) $(OBJ_SND_XMP) snd_sdl.o $(OBJ_VIDEO_CAPTURE) $(OBJ_COMMON)
+OBJ_SDL= builddate.c $(SYS_OBJ) vid_sdl.o thread_sdl.o $(OBJ_MENU) $(OBJ_SND_COMMON) $(OBJ_SND_XMP) snd_sdl.o $(OBJ_VIDEO_CAPTURE) $(OBJ_COMMON)
 
 
 # Compilation
@@ -227,6 +228,13 @@ LDFLAGS_LINUXSV=$(LDFLAGS_UNIXCOMMON) -lrt -ldl -rdynamic
 LDFLAGS_LINUXSDL=$(LDFLAGS_UNIXCOMMON) -lrt -ldl -rdynamic $(LDFLAGS_UNIXSDL)
 
 
+##### Switch specific variables #####
+
+CFLAGS_SWITCH= -D__SWITCH__ -I$(DEVKITPRO)/libnx/include -I$(DEVKITPRO)/portlibs/switch/include -fPIE -DNOSUPPORTIPV6 -DDEBUGSDLEVENTS 
+LDFLAGS_SWITCHSV=-L$(DEVKITPRO)/libnx/lib -L$(DEVKITPRO)/portlibs/switch/lib $(LDFLAGS_UNIXCOMMON) -specs=$(DEVKITPRO)/libnx/switch.specs -g -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE -lm -lnx
+LDFLAGS_SWITCHSDL=-L$(DEVKITPRO)/libnx/lib -L$(DEVKITPRO)/portlibs/switch/lib $(LDFLAGS_UNIXCOMMON) -specs=$(DEVKITPRO)/libnx/switch.specs -g -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE $(LDFLAGS_UNIXSDL) -lm -lnx
+
+
 ##### Mac OS X specific variables #####
 
 # Link
@@ -396,7 +404,7 @@ bin-release :
                DP_MAKE_TARGET=$(DP_MAKE_TARGET) \
                CFLAGS='$(CFLAGS_COMMON) $(CFLAGS_FEATURES) $(CFLAGS_EXTRA) $(CFLAGS_RELEASE) $(OPTIM_RELEASE)'\
                LDFLAGS='$(LDFLAGS_RELEASE) $(LDFLAGS_COMMON)' LEVEL=2
-       $(STRIP) $(EXE)
+       $(STRIP) $(STRIPARGS)
 
 bin-release-profile :
        $(CHECKLEVEL1)
@@ -407,7 +415,7 @@ bin-release-profile :
                DP_MAKE_TARGET=$(DP_MAKE_TARGET) \
                CFLAGS='$(CFLAGS_COMMON) $(CFLAGS_FEATURES) $(CFLAGS_EXTRA) $(CFLAGS_RELEASE_PROFILE) $(OPTIM_RELEASE)'\
                LDFLAGS='$(LDFLAGS_RELEASE) $(LDFLAGS_COMMON)' LEVEL=2
-       $(STRIP) $(EXE)
+       $(STRIP) $(STRIPARGS)
 
 prepare :
        $(CMD_MKDIR) $(BUILD_DIR)
@@ -497,6 +505,7 @@ $(EXE_SDLNEXUIZ): $(OBJ_SDL) $(OBJ_ICON_NEXUIZ)
 clean:
        -$(CMD_RM) $(EXE_SV)
        -$(CMD_RM) $(EXE_SDL)
+       -$(CMD_RM) $(EXE_SDL).nro
        -$(CMD_RM) $(EXE_SVNEXUIZ)
        -$(CMD_RM) $(EXE_SDLNEXUIZ)
        -$(CMD_RM) *.o
diff --git a/sys.h b/sys.h
index a5c6b275b2e08d9d2c5e2d45251d4c8a1e3d5e11..a93690905dbdfa817e68435ee2c7b87ff9bdf420 100644 (file)
--- a/sys.h
+++ b/sys.h
@@ -87,6 +87,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #  define DP_OS_NAME   "SunOS"
 #  define DP_OS_STR            "sunos"
 # endif
+#elif defined(__SWITCH__)
+# define DP_OS_NAME            "Horizon OS"
+# define DP_OS_STR             "HOS"
 #else
 # define DP_OS_NAME            "Unknown"
 # define DP_OS_STR             "unknown"
@@ -151,6 +154,8 @@ typedef struct sys_s
 extern sys_t sys;
 
 
+
+
 //
 // DLL management
 //
index 46cec64247666a080dd3ea44f17c09ea6acd5e23..ef8f966d5453bc6e66d8d3cbab87a97cf157310c 100644 (file)
@@ -3,9 +3,9 @@
 #  define _WIN32_WINNT 0x0502
 # endif
 #endif
-
+#ifndef __SWITCH__
 #define SUPPORTDLL
-
+#endif
 #ifdef WIN32
 # include <windows.h>
 # include <mmsystem.h> // timeGetTime
 # include <fcntl.h>
 # include <sys/time.h>
 # include <time.h>
+#ifndef __SWITCH__
 # ifdef SUPPORTDLL
 #  include <dlfcn.h>
 # endif
 #endif
+#endif
 
 #include <signal.h>
 
@@ -119,7 +121,9 @@ qbool Sys_LoadSelf(dllhandle_t *handle)
 #ifdef WIN32
        dllhandle = LoadLibrary (NULL);
 #else
-       dllhandle = dlopen (NULL, RTLD_NOW | RTLD_GLOBAL);
+       #ifndef __SWITCH__
+               dllhandle = dlopen (NULL, RTLD_NOW | RTLD_GLOBAL);
+       #endif
 #endif
        *handle = dllhandle;
        return true;
diff --git a/sys_switch.c b/sys_switch.c
new file mode 100644 (file)
index 0000000..eeac006
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * Include this BEFORE darkplaces.h because it breaks wrapping
+ * _Static_assert. Cloudwalk has no idea how or why so don't ask.
+ */
+#include <SDL.h>
+
+#include "darkplaces.h"
+#include <switch.h>
+#include <sys/stat.h>
+#include "quakedef.h"
+// =======================================================================
+// General routines
+// =======================================================================
+
+void Sys_SDL_Shutdown(void)
+{
+       socketExit();
+       accountExit();
+       SDL_Quit();
+}
+
+// Sys_Error early in startup might screw with automated
+// workflows or something if we show the dialog by default.
+static qbool nocrashdialog = true;
+void Sys_SDL_Dialog(const char *title, const char *string)
+{
+       if(!nocrashdialog)
+               SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, title, string, NULL);
+}
+
+char *Sys_SDL_GetClipboardData (void)
+{
+       char *data = NULL;
+       char *cliptext;
+
+       cliptext = SDL_GetClipboardText();
+       if (cliptext != NULL) {
+               size_t allocsize;
+               allocsize = min(MAX_INPUTLINE, strlen(cliptext) + 1);
+               data = (char *)Z_Malloc (allocsize);
+               dp_strlcpy (data, cliptext, allocsize);
+               SDL_free(cliptext);
+       }
+
+       return data;
+}
+
+void Sys_SDL_Init(void)
+{
+       // we don't know which systems we'll want to init, yet...
+       if (SDL_Init(0) < 0)
+               Sys_Error("SDL_Init failed: %s\n", SDL_GetError());
+
+       // COMMANDLINEOPTION: sdl: -nocrashdialog disables "Engine Error" crash dialog boxes
+       if(!Sys_CheckParm("-nocrashdialog"))
+               nocrashdialog = false;
+}
+
+qbool sys_supportsdlgetticks = true;
+unsigned int Sys_SDL_GetTicks (void)
+{
+       return SDL_GetTicks();
+}
+void Sys_SDL_Delay (unsigned int milliseconds)
+{
+       SDL_Delay(milliseconds);
+}
+
+int StartupError(char message[]){
+       consoleInit(NULL);
+       while(appletMainLoop()){
+               printf(message);
+               printf("\nPlease exit the app");
+               consoleUpdate(NULL);
+       }
+}
+
+int main(int argc, char *argv[])
+{
+       
+       socketInitializeDefault();
+       Result result = accountInitialize(AccountServiceType_Application);
+       if (R_FAILED(result))
+       {
+               StartupError("Unable to initialize account system");
+               
+
+       }
+       
+       return Sys_Main(argc, argv);
+}
index 79addbdf750b7ac3b241e1b054d8d6523dd69b67..21957a29cbe60de6d15efdf51a46b9d16301cf76 100644 (file)
--- a/vid_sdl.c
+++ b/vid_sdl.c
@@ -1123,6 +1123,33 @@ void Sys_SDL_HandleEvents(void)
                                }
                                break;
                        case SDL_JOYBUTTONDOWN:
+                       #ifdef __SWITCH__
+                               if(event.jbutton.button == 0){
+                                       Key_Event( K_ENTER, 0, true );
+                                       Key_Event( K_ENTER, 0, false );
+                               }
+                               else if(event.jbutton.button == 13){
+                                       Key_Event( K_UPARROW, 0, true );
+                                       Key_Event( K_UPARROW, 0, false );
+                               }
+                               else if(event.jbutton.button == 15){
+                                       Key_Event( K_DOWNARROW, 0, true );
+                                       Key_Event( K_DOWNARROW, 0, false );
+                               }
+                               else if(event.jbutton.button == 12){
+                                       Key_Event( K_LEFTARROW, 0, true );
+                                       Key_Event( K_LEFTARROW, 0, false );
+                               }
+                               else if(event.jbutton.button == 14){
+                                       Key_Event( K_RIGHTARROW, 0, true );
+                                       Key_Event( K_RIGHTARROW, 0, false );
+                               }
+                               else if(event.jbutton.button == 10){
+                                       Key_Event( K_ESCAPE, 0, true );
+                                       Key_Event( K_ESCAPE, 0, false );
+                               }
+                               break;
+                       #endif
                        case SDL_JOYBUTTONUP:
                        case SDL_JOYAXISMOTION:
                        case SDL_JOYBALLMOTION: