Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,35 @@ jobs:
name: "tic80-nintendo-3ds"
path: build/bin/tic80.3dsx

# === Nintendo Switch build ===
nintendo-switch:
runs-on: ubuntu-latest
container: devkitpro/devkita64:20250728

steps:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0

- name: Install Host toolchain
run: |
apt-get update
apt-get install --assume-yes build-essential ruby-full

- name: Build
run: |
cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=$DEVKITPRO/cmake/Switch.cmake \
-DCMAKE_BUILD_TYPE=MinSizeRel -DBUILD_WITH_ALL=ON -DBUILD_SDLGPU=ON \
-DBUILD_WITH_YUE=OFF
cmake --build build --parallel

- name: Deploy
uses: actions/upload-artifact@v4
with:
name: "tic80-nintendo-switch"
path: build/bin/tic80.nro

# === MacOS 14 / arm64 ===
macos-arm64:
runs-on: macos-14
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ CMakeSettings.json
tic_mruby_build_config.rb.lock
tic_mruby_wasm_build_config.rb.lock
build/mruby_vendor-prefix/
# switch
build/*.nro
build/*.nacp
build/*.lst
build/*.map
**/.zig-cache
**/zig-out
.cache
Expand Down
20 changes: 14 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,19 @@ message("VERSION_HASH: ${VERSION_HASH}")

configure_file("${PROJECT_SOURCE_DIR}/version.h.in" "${CMAKE_CURRENT_BINARY_DIR}/version.h")

if(ANDROID OR EMSCRIPTEN OR NINTENDO_3DS OR BAREMETALPI)
if(ANDROID OR EMSCRIPTEN OR NINTENDO_3DS OR NINTENDO_SWITCH OR BAREMETALPI)
set(BUILD_STATIC_DEFAULT ON)
else()
set(BUILD_STATIC_DEFAULT OFF)
endif()

set(BUILD_PLAYER_DEFAULT OFF)
set(BUILD_LIBRETRO_DEFAULT OFF)
set(BUILD_TOUCH_INPUT_DEFAULT ${ANDROID})
if(ANDROID OR NINTENDO_SWITCH)
set(BUILD_TOUCH_INPUT_DEFAULT ON)
else()
set(BUILD_TOUCH_INPUT_DEFAULT OFF)
endif()
set(BUILD_WITH_ALL_DEFAULT OFF)

option(BUILD_STATIC "Static runtime" ${BUILD_STATIC_DEFAULT})
Expand Down Expand Up @@ -60,6 +64,10 @@ if(NOT BUILD_SDL)
set(BUILD_SDLGPU OFF)
endif()

if(NINTENDO_SWITCH)
set(PREFER_SYSTEM_LIBRARIES ON)
endif()

add_library(runtime INTERFACE)

if(BUILD_STATIC)
Expand All @@ -77,13 +85,12 @@ message("BUILD_SDLGPU: ${BUILD_SDLGPU}")
message("BUILD_TOUCH_INPUT: ${BUILD_TOUCH_INPUT}")
message("BUILD_WITH_ALL: ${BUILD_WITH_ALL}")

if (NINTENDO_3DS)
if(NINTENDO_3DS OR BAREMETALPI)
set(BUILD_SDL OFF)
set(PREFER_SYSTEM_LIBRARIES ON)
endif()

if (BAREMETALPI)
set(BUILD_SDL OFF)
if (NINTENDO_3DS)
set(PREFER_SYSTEM_LIBRARIES ON)
endif()

if(UNIX AND NOT APPLE AND NOT EMSCRIPTEN AND NOT ANDROID)
Expand Down Expand Up @@ -178,5 +185,6 @@ include(cmake/studio.cmake)
include(cmake/sdl.cmake)
include(cmake/libretro.cmake)
include(cmake/n3ds.cmake)
include(cmake/nswitch.cmake)

include(cmake/install.cmake)
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -424,3 +424,4 @@ You can find the compiled version ready download and install [on F-Droid](https:
* NuSan — [Github @TheNuSan](https://github.com/thenusan)
* Li Jin — [Github @pigpigyyy](https://github.com/pigpigyyy)
* Dania Rifki — [Github @Kaleidosium](https://github.com/Kaleidosium)
* Carsten Teibes — [GitHub @carstene1ns](https://github.com/carstene1ns)
19 changes: 19 additions & 0 deletions build/nswitch/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Switch build

## Requirements

* devkitA64 + the switch-dev meta package
* the following additional packages:
* switch-libpng
* switch-zlib
* switch-sdl2
* switch-curl

## Building instructions

```
cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=$DEVKITPRO/cmake/Switch.cmake
cmake --build build
```

You should now be able to find `tic80.nro` in build/bin.
Binary file added build/nswitch/icon.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion cmake/naett.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
# naett
################################

if(NOT RPI AND NOT NINTENDO_3DS AND NOT EMSCRIPTEN AND NOT BAREMETALPI)
if(RPI OR NINTENDO_3DS OR NINTENDO_SWITCH OR EMSCRIPTEN OR BAREMETALPI)
set(USE_NAETT FALSE)
else()
set(USE_NAETT TRUE)
endif()

Expand Down
32 changes: 32 additions & 0 deletions cmake/nswitch.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
################################
# TIC-80 app (Switch)
################################

if(NINTENDO_SWITCH)
if(BUILD_EDITORS)
target_sources(tic80studio PRIVATE
src/system/nswitch/net.c)
target_include_directories(tic80studio
PRIVATE ${TIC80LIB_DIR}/studio)
endif()

target_sources(${TIC80_TARGET} PRIVATE
src/system/nswitch/runtime.c)

find_package(PkgConfig)
pkg_search_module(CURL libcurl IMPORTED_TARGET)
target_link_libraries(tic80 PkgConfig::CURL)

nx_generate_nacp(tic80.nacp
NAME "TIC-80 tiny computer"
AUTHOR "Nesbox, carstene1ns"
VERSION ${PROJECT_VERSION})

nx_create_nro(${TIC80_TARGET}
NACP tic80.nacp
ICON ${CMAKE_SOURCE_DIR}/build/nswitch/icon.jpg
#ROMFS ${CMAKE_SOURCE_DIR}/build/nswitch/romfs
OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tic80.nro)

dkp_target_generate_symbol_list(${TIC80_TARGET})
endif()
2 changes: 1 addition & 1 deletion cmake/quickjs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ if(BUILD_WITH_JS)
target_compile_definitions(quickjs PRIVATE DUMP_LEAKS)
endif()

if(BAREMETALPI OR NINTENDO_3DS)
if(BAREMETALPI OR NINTENDO_3DS OR NINTENDO_SWITCH)
target_compile_definitions(quickjs PRIVATE POOR_CLIB)
endif()

Expand Down
4 changes: 4 additions & 0 deletions cmake/scheme.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ if(BUILD_WITH_SCHEME)
target_compile_definitions(scheme PRIVATE S7_N3DS)
endif()

if (NINTENDO_SWITCH)
target_compile_definitions(scheme PRIVATE S7_SWITCH)
endif()

if (BAREMETALPI)
target_compile_definitions(scheme PRIVATE S7_BAREMETALPI)
endif()
Expand Down
19 changes: 15 additions & 4 deletions cmake/sdl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
if(PREFER_SYSTEM_LIBRARIES)
find_package(SDL2)
if(SDL2_FOUND)
add_library(SDL2 ALIAS SDL2::SDL2)
add_library(SDL2-static ALIAS SDL2::SDL2)
if(NINTENDO_SWITCH)
add_library(SDL2 ALIAS SDL2::SDL2-static)
add_library(SDL2-static ALIAS SDL2::SDL2-static)
else()
add_library(SDL2 ALIAS SDL2::SDL2)
add_library(SDL2-static ALIAS SDL2::SDL2)
endif()
message(STATUS "Use system library: SDL2")
else()
message(WARNING "System library SDL2 not found")
Expand Down Expand Up @@ -89,7 +94,7 @@ set(SDLGPU_SRC
${SDLGPU_DIR}/externals/stb_image_write/stb_image_write.c
)

if(NOT ANDROID)
if(NOT ANDROID AND NOT NINTENDO_SWITCH)
list(APPEND SDLGPU_SRC
${SDLGPU_DIR}/renderer_GLES_1.c
${SDLGPU_DIR}/renderer_GLES_3.c
Expand All @@ -105,7 +110,7 @@ endif()

add_library(sdlgpu STATIC ${SDLGPU_SRC})

if(EMSCRIPTEN OR ANDROID)
if(EMSCRIPTEN OR ANDROID OR NINTENDO_SWITCH)
target_compile_definitions(sdlgpu PRIVATE GLEW_STATIC SDL_GPU_DISABLE_GLES_1 SDL_GPU_DISABLE_GLES_3 SDL_GPU_DISABLE_OPENGL)
else()
target_compile_definitions(sdlgpu PRIVATE GLEW_STATIC SDL_GPU_DISABLE_GLES SDL_GPU_DISABLE_OPENGL_3 SDL_GPU_DISABLE_OPENGL_4)
Expand Down Expand Up @@ -141,6 +146,12 @@ if(ANDROID)
)
endif()

if(NINTENDO_SWITCH)
find_package(PkgConfig REQUIRED)
pkg_search_module(GLES2 glesv2 REQUIRED IMPORTED_TARGET)
target_link_libraries(sdlgpu PkgConfig::GLES2)
endif()

if(NOT EMSCRIPTEN)
if(BUILD_STATIC)
target_link_libraries(sdlgpu SDL2-static)
Expand Down
2 changes: 1 addition & 1 deletion include/tic80_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@
# endif
#endif

#if defined(ANDROID) || defined(__ANDROID__) || defined(BAREMETALPI) || defined(__3DS__)
#if defined(ANDROID) || defined(__ANDROID__) || defined(BAREMETALPI) || defined(__3DS__) || defined(__SWITCH__)
# define TIC80_FFT_UNSUPPORTED 1
#endif
2 changes: 1 addition & 1 deletion src/ext/miniaudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -16137,7 +16137,7 @@ static ma_result ma_thread_create__posix(ma_thread* pThread, ma_thread_priority
int result;
pthread_attr_t* pAttr = NULL;

#if !defined(__EMSCRIPTEN__) && !defined(__3DS__)
#if !defined(__EMSCRIPTEN__) && !defined(__3DS__) && !defined(__SWITCH__)
/* Try setting the thread priority. It's not critical if anything fails here. */
pthread_attr_t attr;
if (pthread_attr_init(&attr) == 0) {
Expand Down
4 changes: 4 additions & 0 deletions src/studio/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ void tic_net_end(tic_net *net)
}
}

#elif defined(__SWITCH__)

// See net.c in src/system

#else

tic_net* tic_net_create(const char* host) {return NULL;}
Expand Down
2 changes: 2 additions & 0 deletions src/studio/studio.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@

#ifdef BAREMETALPI
#define TIC_LOCAL "../.tic80/"
#elif defined(__SWITCH__)
#define TIC_LOCAL "./data/"
#else
#define TIC_LOCAL ".local/"
#endif
Expand Down
Loading
Loading