Skip to content

Nintendo Switch port (using AI Claude) - #12

Closed
szczuru wants to merge 17 commits into
mszula:masterfrom
szczuru:port/ns-switch
Closed

Nintendo Switch port (using AI Claude)#12
szczuru wants to merge 17 commits into
mszula:masterfrom
szczuru:port/ns-switch

Conversation

@szczuru

@szczuru szczuru commented Jun 23, 2026

Copy link
Copy Markdown

Nintendo Switch homebrew port

Adds TARGET=switch — a devkitA64/libnx homebrew build that produces
a .nro launchable from hbmenu/Atmosphère. Tested on hardware (handheld
and docked mode).

Closes #


How to build

./tools/build-switch.sh   # requires Docker

or via the new GitHub Actions workflow (Switch build).

The player copies Dane_*.dta + their own WACKI.EXE to
sdmc:/switch/wacki/data/ and runs wacki.nro from hbmenu.


New files (Switch-only)

File Purpose
mk/switch.mk Build config: devkitA64, libnx, SDL2 portlib via pkg-config, elf2nro packaging
tools/build-switch.sh Docker wrapper (same pattern as build-ps2.sh)
.github/workflows/switch.yml CI producing dist/wacki.nro
src/platform/switch/switch.c Hooks provider: fullscreen + runtime WACKI.EXE load
src/platform/switch/storage_switch.c plat_save_read/write with fsdevCommitDevice("sdmc")
src/platform/switch/data_root_switch.c SD-card candidate paths (sdmc:/switch/wacki/…)
src/platform/switch/embedded_wacki_pe_stub.c Empty PE slice table (no copyrighted data in CI)
assets/icons/wacki-switch.jpg 256×256 JPEG icon for .nro

Changes to shared files

All changes are backwards-compatible and benefit other platforms too.

src/platform/sdl/system_sdl.c — added #ifdef __SWITCH__ block
(mirrors the existing #ifdef __ANDROID__ block): mkdir + chdir to
sdmc:/switch/wacki/ before ConfigLoad(). hbmenu/nx-hbloader does not
guarantee a consistent cwd across launches (unlike a desktop shell or a
handheld launcher script that cds into the ROM folder), so without this
Wacki.sav and wacki.cfg land in a different place every relaunch.

src/platform/sdl/gamepad_sdl.c — two generic additions:

  1. Nintendo button-layout detection via SDL_GameControllerGetType():
    automatically swaps A/B and X/Y constants to match Nintendo's physical
    diamond (where SDL's BUTTON_A = south position = physical B on a
    Joy-Con). Works for any Nintendo pad on any SDL target (Pro Controller
    paired to a PortMaster device over Bluetooth gets the same correct
    mapping). On __SWITCH__ always active without a type query.
  2. Two new generic bindings: X (west) → platform_video_toggle_aspect_mode(),
    BACK/MINUSplatform_touch_cycle_mode(). Both are no-ops on
    targets where they don't apply.

src/platform/sdl/video_sdl.cg_aspect_mode ("stretch" /
"4:3"): in "4:3" mode SDL gets logical size 640×480 and
letterboxes automatically on a non-4:3 output. In "stretch" mode
SDL_RenderSetLogicalSize is disabled (0, 0) and the texture is
blitted with an explicit full-window SDL_Rect — SDL's
RenderSetLogicalSize always preserves AR (per its own docs), so
disproportionate fill requires bypassing it. Mouse coordinates are
manually scaled in stretch mode so the engine's hit-tests still work.

src/platform/sdl/platform_sdl.cg_touch_mode
("absolute" / "relative" / "off"):

  • "absolute" (default): SDL's built-in HINT_TOUCH_MOUSE_EVENTS ON —
    tap = click + position, two-finger tap = RMB. Zero extra code.
  • "relative": HINT_TOUCH_MOUSE_EVENTS OFF, whole panel as a laptop
    touchpad — delta between samples moves the cursor, touch never clicks.
    Designed to be reusable for future touch-capable ports (PS Vita, Wii U).
  • "off": ignores SDL_FINGER* entirely.

Cycled at runtime (MINUS/BACK on pad, F8 on desktop), persisted in
wacki.cfg.

src/config.c — two new keys: aspect_mode=stretch|4:3 and
touch_mode=absolute|relative|off. wacki.cfg is now created
automatically on first launch
on every platform (previously only the
desktop first-run picker path called ConfigSave(); handheld targets
never showed that picker so the file never materialised).

Makefile — three small changes:

  1. EMBEDDED_PE_SRC ?= + ifeq guard around the codegen rule — lets
    mk/switch.mk override it with the empty stub without triggering a
    data/WACKI.EXE missing build failure.
  2. .DEFAULT_GOAL := all — without this, make TARGET=switch silently
    built only the empty dist/ directory (because $(DIST): is defined
    before all: in the file) and exited with code 0.
  3. switch target registered in .PHONY + ./tools/build-switch.sh
    wrapper.

Button mapping (Joy-Con / Pro Controller)

Action Physical button
Cursor Left stick / D-pad
Left click A
Right click B
Toggle aspect mode (stretch ↔ 4:3) X
Cycle touch mode
Pause menu +
Quickload L
Quicksave R

Why WACKI.EXE is loaded at runtime

The public repo and CI cannot embed the copyrighted .rdata/.data
sections from WACKI.EXE. src/pe_loader.c's PeLoaderRead already
checks a dynamically-loaded image (set by PeLoaderInit) before falling
back to the embedded slice table, so the hooks provider
(src/platform/switch/switch.c) simply calls PeLoaderInit() with the
player's own file from the SD card — the rest of the engine is completely
unmodified.

@szczuru szczuru closed this Jun 23, 2026

@mszula mszula left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ogólnie wygląda spoko. Nie mam przekonania do niektórych rozwiązań.
Port Wii wywal.
Do tego brakuje dokumentacji i zmian na ./website

Comment thread .github/workflows/wii.yml
@@ -0,0 +1,31 @@
name: Wii build

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okładka niezgodna z resztą portu, popraw pls

Comment thread mk/wii.mk

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??

* labelled); every other SDL target asks SDL_GameControllerGetType(), which
* also catches a Joy-Con/Pro Controller plugged into a PC or paired to a
* PortMaster handheld. */
static int is_nintendo_layout(SDL_GameController *pad)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pomyśl nad tym żeby to wydzielić do osobnego hal. Mam obawy bo ten plik puchnie

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Przeniose to chyba do switch.c albo osobno do "nintendo.c" aby w przyszłości nie kopiować kodu do detekcji pada (gra rozpoznaje czy podłączony jest pad od nintendo - jeśli tak to zamienia miejscami funkcje A/B - w padach od nintendo A jest po prawo, B od dołu - a nadal akceptuje się A).

static SDL_FingerID s_touch_rel_id = 0;
static float s_touch_rel_last_x = 0.0f, s_touch_rel_last_y = 0.0f;

static void handle_finger_relative(const SDL_Event *ev)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Co to za zmiana pod Androida? Naprawia jakiś błąd? Z czego wynika?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To nowa funkcjonalność dla Switcha (i przyszłych portów z panelem dotykowym, np. PS Vita, Wii U): tryb 'relative' sprawia, że cały ekran dotykowy zachowuje się jak touchpad laptopa — przesuwanie palca przesuwa kursor o deltę, bez kliknięcia. Guard #ifndef ANDROID jest tam dlatego, że Android ma własny mechanizm dotyku (android_touch.h) i ten kod nie powinien tam działać. Blok #ifdef ANDROID powyżej w tym samym pliku już to obsługuje. Nie jest to fix błędu — to nowa opcja konfiguracyjna (touch_mode=relative w wacki.cfg).

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??

Comment thread src/platform/wii/wii.c

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??

Comment thread tools/build-wii.sh

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??

@szczuru

szczuru commented Jun 23, 2026

Copy link
Copy Markdown
Author

Wii przeniose chyba do soobnego brancha - powinno być lepiej. Wróce jutro do tematu jak naprawie to co popsułem ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants