Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.
Swift apple-siliconcustom-formathomebrewiosipaipadipadosiphonemetalnative-portnintendo-switchnxnativeromfsswitch-games
A test for the contract between the Controls page and the front end
LNPANDY0bb128ace10f
diff --git a/dm/host/tests/Makefile b/dm/host/tests/Makefileindex 82414b20..8945c283 100644--- a/dm/host/tests/Makefile+++ b/dm/host/tests/Makefile@@ -7,7 +7,7 @@ PYTHON ?= python3GINC = $(if $(strip $(GAME)),-I../gen/$(GAME) -I../../games/$(GAME),$(error GAME is not set: make GAME=<base game title ID>: $(shell python3 ../../games/game.py list | awk -F'\t' '{printf "%s (%s) ", $$1, $$3}')))$(B)/t_fs $(B)/t_fs_case $(B)/t_fs_commit_list $(B)/t_fs_commit_list_tsan: ../romfs_image.hGAME_H = ../gen/$(GAME)/game_profile.h-run: $(B)/t_heap_size $(B)/t_touch $(B)/t_gesture $(B)/t_oe $(B)/t_fs $(B)/t_fs_commit_list $(B)/t_thread_leak $(B)/t_fs_case $(B)/t_audio $(B)/t_audio_spsc $(B)/t_swkbd $(B)/t_altstack $(B)/t_condvar $(B)/t_condvar_old $(B)/t_pctl $(B)/t_time $(B)/t_shared_font $(B)/t_vorbis $(B)/t_vorbis_divides $(B)/t_hid $(B)/t_input_map $(B)/t_haptics $(B)/t_haptics_apple $(B)/t_touchpad_geometry+run: $(B)/t_heap_size $(B)/t_touch $(B)/t_gesture $(B)/t_oe $(B)/t_fs $(B)/t_fs_commit_list $(B)/t_thread_leak $(B)/t_fs_case $(B)/t_audio $(B)/t_audio_spsc $(B)/t_swkbd $(B)/t_altstack $(B)/t_condvar $(B)/t_condvar_old $(B)/t_pctl $(B)/t_time $(B)/t_shared_font $(B)/t_vorbis $(B)/t_vorbis_divides $(B)/t_hid $(B)/t_input_map $(B)/t_launcher_contract $(B)/t_haptics $(B)/t_haptics_apple $(B)/t_touchpad_geometry$(B)/t_heap_size$(B)/t_touch$(B)/t_gesture@@ -36,6 +36,7 @@ run: $(B)/t_heap_size $(B)/t_touch $(B)/t_gesture $(B)/t_oe $(B)/t_fs $(B)/t_fs_$(B)/t_movie_vpx$(B)/t_hid$(B)/t_input_map+ $(B)/t_launcher_contract$(B)/t_haptics$(B)/t_haptics_apple$(B)/t_touchpad_geometry@@ -120,6 +121,8 @@ $(B)/t_shared_font: t_shared_font.c ../hle_sdk16.c ../hle.h ../dm.h $(GAME_H) |clang -O1 -Wall -Werror -Wno-unused-function -Wno-frame-address -I.. $(GINC) -o $@ t_shared_font.c ../hle_profile.c$(B)/t_input_map: t_input_map.c ../input_map.h ../dm_input.h | $(B)clang -O1 -Wall -Werror -Wno-unused-function -I.. -o $@ t_input_map.c+$(B)/t_launcher_contract: t_launcher_contract.c ../input_map.h ../dm_input.h | $(B)+ clang -O1 -Wall -Werror -Wno-unused-function -I.. -o $@ t_launcher_contract.c$(B)/t_hid: t_hid.c ../hle_hid.c ../hle_haptics.c ../hle_haptics.h ../pad_slots.h ../dm_input.h ../hle.h ../dm.h $(GAME_H) | $(B)clang -O1 -Wall -Werror -Wno-unused-function -I.. $(GINC) -o $@ t_hid.c ../hle_haptics.c$(B)/t_hid_tsan: t_hid.c ../hle_hid.c ../hle_haptics.c ../hle_haptics.h ../pad_slots.h ../dm_input.h ../hle.h ../dm.h $(GAME_H) | $(B)diff --git a/dm/host/tests/t_launcher_contract.c b/dm/host/tests/t_launcher_contract.cnew file mode 100644index 00000000..136b4035--- /dev/null+++ b/dm/host/tests/t_launcher_contract.c@@ -0,0 +1,35 @@+/* The write half is ControlLayout.environment in frontend/Sources/NSPortBuilder/Controls.swift;+ the read half is input_map.h. The launcher sends exactly these strings, so this checks the+ contract between the two: a rename on either side, or a change of syntax, fails here rather+ than at a player's keyboard. */+#include "../input_map.h"+static int checks, fails;+#define CHECK(c, msg) do { checks++; if (!(c)) { fails++; fprintf(stderr, "FAIL: %s\n", msg); } } while (0)+int main(void) {+ key_map k; key_map_default(&k);+ /* Settings: A moved onto K (40), B left on none — ControlsTests' first case */+ CHECK(key_map_parse(&k, "A=40,B=none") == 0, "A=40,B=none parses");+ CHECK(key_map_fn(&k, 40) == 0, "K now sends A");+ int bfound = 0; for (int c = 0; c < IM_KEYS; c++) if (k.fn[c] == 1) bfound = 1;+ CHECK(!bfound, "B is on no key");++ pad_map m; pad_map_default(&m);+ /* Settings: A and B swapped, Minus sends nothing */+ CHECK(pad_map_parse(&m, "A=B,B=A,Minus=none") == 0, "A=B,B=A,Minus=none parses");+ CHECK(pad_map_apply(&m, DM_BTN_A) == DM_BTN_B, "pad A sends B");+ CHECK(pad_map_apply(&m, DM_BTN_B) == DM_BTN_A, "pad B sends A");+ CHECK(pad_map_apply(&m, DM_BTN_MINUS) == 0, "Minus sends nothing");+ CHECK(pad_map_apply(&m, DM_BTN_Y) == DM_BTN_Y, "untouched buttons stay");++ /* the right stick on I, as the Controls sheet's own capture sets it */+ key_map_default(&k);+ CHECK(key_map_parse(&k, "RUp=34") == 0, "RUp=34 parses");+ CHECK(key_map_fn(&k, 34) == IM_RUP, "I now sends RUp (and Y left I)");+ int yfound = 0; for (int c = 0; c < IM_KEYS; c++) if (k.fn[c] == 3) yfound = 1;+ CHECK(!yfound, "Y is on no key any more");+ int rup = 0; for (int c = 0; c < IM_KEYS; c++) if (k.fn[c] == IM_RUP) rup = 1;+ CHECK(rup, "RUp is on a key");++ printf("launcher contract: %d checks, %d failed\n", checks, fails);+ return fails != 0;+}diff --git a/scripts/sync_upstream.py b/scripts/sync_upstream.pyindex 21620b29..44c55146 100644--- a/scripts/sync_upstream.py+++ b/scripts/sync_upstream.py@@ -51,6 +51,7 @@ OURS = {'dm/host/romfs_arc.c', 'dm/host/romfs_arc.h', 'dm/tools/romfs_arc.py',# front_mac.m read them. Fork-only until #386 merges, so a sync must not delete them.'dm/host/input_map.h','dm/host/tests/t_input_map.c',+ 'dm/host/tests/t_launcher_contract.c', # the write→read contract with the Controls page# The Increased Memory Limit guide the README links to; upstream has no such file, and the# first wholesale sync deleted it.'dm/ios/ENTITLEMENTS.md',@@ -382,7 +383,13 @@ def patch_tests_makefile(t):if rule_anchor not in t: fail(f'{TESTS_MK}: t_hid rule missing')t = t.replace(rule_anchor,'$(B)/t_input_map: t_input_map.c ../input_map.h ../dm_input.h | $(B)\n'- '\tclang -O1 -Wall -Werror -Wno-unused-function -I.. -o $@ t_input_map.c\n' + rule_anchor, 1)+ '\tclang -O1 -Wall -Werror -Wno-unused-function -I.. -o $@ t_input_map.c\n'+ '$(B)/t_launcher_contract: t_launcher_contract.c ../input_map.h ../dm_input.h | $(B)\n'+ '\tclang -O1 -Wall -Werror -Wno-unused-function -I.. -o $@ t_launcher_contract.c\n' + rule_anchor, 1)+ body_old2 = '\t$(B)/t_input_map\n'+ t = t.replace(body_old2, body_old2 + '\t$(B)/t_launcher_contract\n', 1)+ run2 = '$(B)/t_input_map $(B)/t_haptics'+ if run2 in t: t = t.replace(run2, '$(B)/t_input_map $(B)/t_launcher_contract $(B)/t_haptics', 1)done('tests/Makefile input map test')# the prerequisites too, so a change to the reader rebuilds them — and hle_profile.h, so a# change to the runtime profile does