Skip to content

Commit

Permalink
Switch: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
usineur committed Apr 19, 2020
1 parent aba63cc commit 892b903
Show file tree
Hide file tree
Showing 9 changed files with 365 additions and 5 deletions.
10 changes: 10 additions & 0 deletions docs/README.md
Expand Up @@ -168,6 +168,16 @@ make
```
You need to have *DevkitPro PPC* and *SDL 1.2* for Wii portlib installed.

Nintendo Switch
---------------

To build the game, please go to the root of the source code tree and type:
```shell
cd switch
make
```
You need to have *DevkitPro A64* and *SDL 2.0* for Switch portlib installed.

PS Vita
-------

Expand Down
9 changes: 8 additions & 1 deletion main.c
Expand Up @@ -468,7 +468,11 @@ main(
--*/
{
#if !defined( __EMSCRIPTEN__ ) && !defined(__WINRT__)
#ifdef __SWITCH__
socketInitializeDefault();
nxlinkStdio();
#endif
#if !defined( __EMSCRIPTEN__ ) && !defined(__WINRT__) && !defined(__SWITCH__)
memset(gExecutablePath,0,PAL_MAX_PATH);
strncpy(gExecutablePath, argv[0], PAL_MAX_PATH);
#endif
Expand All @@ -483,6 +487,9 @@ main(
// A longjmp is made, should exit here
SDL_Quit();
UTIL_Platform_Quit();
#ifdef __SWITCH__
socketExit();
#endif
return g_exit_code;
}
#endif
Expand Down
3 changes: 3 additions & 0 deletions mini_glloader.c
Expand Up @@ -26,6 +26,8 @@
#if PAL_HAS_GLSL
#include "mini_glloader.h"

#ifndef __SWITCH__

PFNGLCREATESHADERPROC glCreateShader;
PFNGLSHADERSOURCEPROC glShaderSource;
PFNGLCOMPILESHADERPROC glCompileShader;
Expand Down Expand Up @@ -100,3 +102,4 @@ int initGLExtensions(int major) {
}
#endif
#endif
#endif
9 changes: 7 additions & 2 deletions mini_glloader.h
Expand Up @@ -36,15 +36,20 @@
#define GL_GLEXT_PROTOTYPES
#endif
#include <SDL_video.h>
#ifdef __SWITCH__
#include <GLES3/gl3.h>
#include <GLES3/gl32.h>
#else
#include <SDL_opengl.h>
#endif
#endif

#if __IOS__ || __ANDROID__ || __EMSCRIPTEN__ || __WINRT__ || SDL_VIDEO_DRIVER_RPI
#if __IOS__ || __ANDROID__ || __EMSCRIPTEN__ || __WINRT__ || SDL_VIDEO_DRIVER_RPI || __SWITCH__
#define GLES 1
#undef FORCE_OPENGL_CORE_PROFILE
#endif

#if !defined(__APPLE__)
#if !defined(__APPLE__) && !defined(__SWITCH__)

//avoid manually imported glfuncs conflicts with platform-builtin ones, like emscripten
#define glCreateShader _glCreateShader
Expand Down
40 changes: 40 additions & 0 deletions switch/Makefile
@@ -0,0 +1,40 @@
TARGET = sdlpal

INTER = .switch

PREFIX = aarch64-none-elf

SOURCES = . .. ../adplug
CFILES = $(foreach dir, $(SOURCES), $(wildcard $(dir)/*.c))
CPPFILES = $(foreach dir, $(SOURCES), $(wildcard $(dir)/*.cpp))
OFILES = $(CFILES:.c=$(INTER).o) $(CPPFILES:.cpp=$(INTER).o)

CCFLAGS = -D__SWITCH__ -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE -O3 -I. -I..
CCFLAGS += -I$(DEVKITPRO)/portlibs/switch/include -I$(DEVKITPRO)/portlibs/switch/include/SDL2 -I$(DEVKITPRO)/libnx/include
CXXFLAGS = $(CCFLAGS) -std=c++11
CFLAGS = $(CCFLAGS) -std=gnu99 -D_GNU_SOURCE
LDFLAGS = -L/opt/devkitpro/portlibs/switch/lib -lSDL2 -L/opt/devkitpro/libnx/lib -lGLESv2
LDFLAGS += -lEGL -lglapi -ldrm_nouveau -lnx -specs=$(DEVKITPRO)/libnx/switch.specs

all: $(TARGET).nro

$(TARGET).nro: $(TARGET).elf
nacptool --create "sdlpal" "usineur" "1.0-nx" $(TARGET).nacp
elf2nro $(TARGET).elf $(TARGET).nro --icon=icon.jpg --nacp=$(TARGET).nacp

$(TARGET).elf: $(OFILES)
@$(PREFIX)-g++ $(CXXFLAGS) $(OFILES) -o $@ $(LDFLAGS)

%$(INTER).o: %.c
@echo [CC] $<
@$(PREFIX)-gcc $(CFLAGS) -c $< -o $@

%$(INTER).o: %.cpp
@echo [CC] $<
@$(PREFIX)-g++ $(CXXFLAGS) -c $< -o $@

nxlink: $(TARGET).nro
nxlink -a $(SWITCHIP) $(TARGET).nro -s -p $(TARGET)/$(TARGET).nro

clean:
@rm -rf $(OFILES) $(TARGET).nro $(TARGET).nacp $(TARGET).elf
Binary file added switch/icon.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 53 additions & 0 deletions switch/pal_config.h
@@ -0,0 +1,53 @@
#ifndef PAL_CONFIG_H
# define PAL_CONFIG_H

# define PAL_HAS_GLSL 1
# define PAL_HAS_JOYSTICKS 1
# define PAL_HAS_MOUSE 0
# define PAL_HAS_MP3 0
# define PAL_HAS_OGG 0
# define PAL_HAS_OPUS 0
# define PAL_PREFIX "."
# define PAL_SAVE_PREFIX "."

# define PAL_DEFAULT_WINDOW_WIDTH 640
# define PAL_DEFAULT_WINDOW_HEIGHT 480

# define PAL_VIDEO_INIT_FLAGS (SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE)
# define PAL_SDL_INIT_FLAGS (SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK)
# define PAL_SCALE_SCREEN TRUE

# define PAL_PLATFORM "Nintendo Switch"
# define PAL_CREDIT "usineur"
# define PAL_PORTYEAR "2020"

# define PAL_FILESYSTEM_IGNORE_CASE 1
# define PAL_HAS_PLATFORM_SPECIFIC_UTILS 1
# define PAL_HAS_PLATFORM_STARTUP 1

# include <strings.h>
# include <switch.h>

# define SWITCH_SCREEN_W 1280
# define SWITCH_SCREEN_H 720

# define BTN_A 0
# define BTN_B 1
# define BTN_X 2
# define BTN_Y 3
# define BTN_L 6
# define BTN_R 7
# define BTN_ZL 8
# define BTN_ZR 9
# define BTN_PLUS 10
# define BTN_MINUS 11
# define BTN_LEFT 12
# define BTN_UP 13
# define BTN_RIGHT 14
# define BTN_DOWN 15
# define STICK_UP 0
# define STICK_DOWN 1
# define STICK_LEFT 2
# define STICK_RIGHT 3

#endif

0 comments on commit 892b903

Please sign in to comment.