Skip to content

Free games for graphing calculators: NumWorks, TI-Nspire CX, Casio fx-CG50 and soon TI-84 Plus CE. Balatro, Celeste, Hollow Knight, Minecraft and more.

Kit: the big games are NumPlay games too, for Enlarged Extra Apps

Mason3634ee76cb4bfbd
diff --git a/Makefile b/Makefile
index 91ae80c1..ddfce6f9 100644
--- a/Makefile
+++ b/Makefile
@@ -27,6 +27,10 @@ CUSTOM_RAM = 133652
BIG_APPS = Celeste HollowKnight Undertale ChampionIsland FinalEarth2 NumPowder NumBlocks NumDrive SubwaySurfers FiveNightsAtFreddys Doom BindingOfIsaac HillClimbRacing PlantsVsZombies SonicTheHedgehog CookieClicker LevelDevil
# the calculator's space for installed apps (0x90200000 to 0x903F0000 in its flash)
APP_SPACE = 2031616
+# with Enlarged Extra Apps (nwagyu's Nwagra), the app loader is told the space goes on to the end of the
+# external flash (0x90800000), over the second copy of the calculator's software: a NumPlay of the big
+# games (games.json "xl", made with the customizer website from `make kit`) is for that
+XL_APP_SPACE = 6291456
# Upsilon, the N0110 and N0115's custom software, gives .nwa apps less RAM: NumPlay-Upsilon.nwa has
# the games that fit it (NumPlay draws their text there: see launcher/src/compat.c)
UPSILON_RAM = 107674
@@ -54,7 +58,7 @@ $(B)/games.mk: games/games.json tools/games_mk.py | $(B)
-include $(B)/games.mk
LAUNCHER_SRC = $(wildcard launcher/src/*.c)
-LAUNCHER_H = $(wildcard launcher/src/*.h)
+LAUNCHER_H = $(wildcard launcher/src/*.h games/common/*.h)
# the release version, shown in NumPlay's settings (a release is tagged v$(VERSION))
VERSION := $(shell cat VERSION)
ARM_CFLAGS = -std=gnu11 $(EADK_CFLAGS) -DNP_VERSION='"$(VERSION)"' -Os -Wall -Wextra -Wno-unused-parameter -fno-math-errno \
@@ -90,13 +94,17 @@ $(B)/tetris/raw.o: FORCE | $(B)
$(ARM_LD) -r -z noexecstack --gc-sections -e np_tetris_main -u np_tetris_main \
games/tetris/tetris/target/thumbv7em-none-eabihf/release/libtetris.a -o $@
+# A big game (XL_GAMES) becomes one from its own .nwa, which has its libraries in it. Its heap is the
+# RAM after its own in the arena: its _heap_start is np_<game>_heap and its malloc's _sbrk the launcher's.
$(B)/modules/%.o: FORCE | $(B)
- @if [ "$*" != tetris ]; then $(MAKE) --no-print-directory -C games/$* module NWLINK="$(NWLINK)"; \
- else $(MAKE) --no-print-directory $(MOD_tetris); fi
- $(ARM_LD) -r -d -T tools/module.ld $(MOD_$*) -o $(B)/modules/$*.1.o
+ @if [ "$*" = tetris ]; then $(MAKE) --no-print-directory $(MOD_tetris); \
+ elif [ -n "$(filter $*,$(XL_GAMES))" ]; then $(MAKE) --no-print-directory -C games/$* build NWLINK="$(NWLINK)"; \
+ else $(MAKE) --no-print-directory -C games/$* module NWLINK="$(NWLINK)"; fi
+ $(ARM_LD) -r -d -z noexecstack --force-group-allocation -T tools/module.ld $(MOD_$*) -o $(B)/modules/$*.1.o
$(ARM_OBJCOPY) --keep-global-symbol=$(or $(ENTRY_$*),$(ENTRY)) \
--redefine-sym eadk_keyboard_scan=np_keyboard_scan --redefine-sym eadk_event_get=np_event_get \
--redefine-sym eadk_display_draw_string=np_display_draw_string \
+ --redefine-sym _heap_start=np_$*_heap --redefine-sym _sbrk=np_sbrk \
$(B)/modules/$*.1.o $(B)/modules/$*.2.o
$(PY) tools/npmodule.py $(B)/modules/$*.2.o $@ --game $* --index $(INDEX_$*) \
--entry $(or $(ENTRY_$*),$(ENTRY)) --json $(B)/modules/$*.json
@@ -107,7 +115,9 @@ $(foreach g,$(STD_GAMES),$(eval MOD_$(g) = games/$(g)/output/module.o)$(eval SIM
MODULES = $(foreach g,$(GAMES),$(B)/modules/$(g).o)
# ------------------------------------------------------------------ generated glue
-$(B)/gen/numplay.ld: games/games.json tools/gen_games.py $(foreach g,$(KIT_ALL),$(B)/modules/$(g).o)
+$(B)/gen/numplay.ld: games/games.json tools/gen_games.py $(foreach g,$(GAMES) $(OPTIONAL_GAMES),$(B)/modules/$(g).o)
+# (and the big games' modules, which take minutes: only for the kit)
+$(B)/gen/numplay.ld: $(if $(filter kit,$(MAKECMDGOALS)),$(foreach g,$(XL_GAMES),$(B)/modules/$(g).o))
$(PY) tools/gen_games.py games/games.json $(B)/modules $(B)/gen
$(B)/gen/shots_%.c: games/games.json tools/shots.py $$(SHOTS_$$*) | $(B)
@@ -118,9 +128,10 @@ $(B)/gen/shots_%.c: games/games.json tools/shots.py $$(SHOTS_$$*) | $(B)
# for a NumPlay with the games you pick (site/): base.o, the launcher with every library function
# a game calls; arena.o, the RAM the games share; the app's name and icon; and one object per game
# with its module, its entry in the launcher's table, its screenshots and the marks of its block.
-# Games marked "default": false in games.json (OPTIONAL_GAMES) are only in the kit.
+# Games marked "default": false in games.json (OPTIONAL_GAMES) are only in the kit, and so are the big
+# games (XL_GAMES, "xl": true), for calculators with Enlarged Extra Apps: a NumPlay with several of them.
KIT = $(B)/kit
-KIT_ALL = $(GAMES) $(OPTIONAL_GAMES)
+KIT_ALL = $(GAMES) $(OPTIONAL_GAMES) $(XL_GAMES)
LAUNCHER_OBJS = $(patsubst launcher/src/%.c,$(B)/arm/%.o,$(LAUNCHER_SRC))
KIT_GAMES = $(foreach g,$(KIT_ALL),$(KIT)/games/$(g).o)
NP_GAMES = $(foreach g,$(GAMES),$(KIT)/games/$(g).o)
@@ -141,10 +152,15 @@ $(KIT)/games/%.o: $(B)/modules/%.o $(B)/arm/entry_%.o $(B)/arm/shots_%.o $(B)/ar
$(ARM_LD) -r -z noexecstack $^ -o $@
# Every symbol a game needs from the C library, libm or libgcc goes in base.o; each stays a
# section of its own (tools/kit_base.ld), so the final link keeps only those its games call.
-$(KIT)/base.o: $(LAUNCHER_OBJS) $(KIT_GAMES) tools/kit_base.ld
+# The big games bring their libraries along: they only call the launcher (KIT_API, which tools/kit.py
+# checks), so base.o is the same without them.
+KIT_API = numplay_launcher np_keyboard_scan np_event_get np_display_draw_string np_sbrk
+KIT_SMALL = $(foreach g,$(GAMES) $(OPTIONAL_GAMES),$(KIT)/games/$(g).o)
+$(KIT)/base.o: $(LAUNCHER_OBJS) $(KIT_SMALL) tools/kit_base.ld
$(ARM_CC) $(ARM_CFLAGS) -nostartfiles --specs=nano.specs -Wl,--relocatable -Wl,--unique -Wl,--gc-sections \
-Wl,-e,main -Wl,-u,eadk_api_level -Wl,-T,tools/kit_base.ld -flinker-output=nolto-rel $(LAUNCHER_OBJS) \
- $$(arm-none-eabi-nm -u $(KIT_GAMES) | awk '$$1 == "U" || $$1 == "w" {print "-Wl,-u," $$2}' | sort -u) -lm -lgcc -o $@
+ $(foreach s,$(KIT_API),-Wl,-u,$(s)) \
+ $$(arm-none-eabi-nm -u $(KIT_SMALL) | awk '$$1 == "U" || $$1 == "w" {print "-Wl,-u," $$2}' | sort -u) -lm -lgcc -o $@
.SECONDARY: $(foreach v,$(VARIANTS),$(B)/variant/$(v)-name.o $(B)/variant/$(v)-icon.o) \
$(foreach g,$(KIT_ALL),$(B)/arm/shots_$(g).o $(B)/arm/entry_$(g).o $(B)/arm/marks_$(g).o)
@@ -168,8 +184,8 @@ $(B)/%.nwa: $(KIT)/base.o $(B)/arm/arena.o $(NP_GAMES) $(B)/variant/%-name.o $(B
kit: $(KIT)/base.o $(B)/arm/arena.o $(KIT_GAMES) $(B)/NumPlay.nwa \
$(foreach v,$(VARIANTS),$(B)/variant/$(v)-name.o $(B)/variant/$(v)-icon.o)
$(PY) tools/kit.py games/games.json $(B) $(B)/site-kit --version $(VERSION) --variants "$(VARIANTS)" \
- --default "$(GAMES)" --upsilon "$(UPSILON_GAMES)" --app-space $(APP_SPACE) --ram $(CUSTOM_RAM) \
- --upsilon-ram $(UPSILON_RAM) --nwlink "$(NWLINK)"
+ --default "$(GAMES)" --upsilon "$(UPSILON_GAMES)" --app-space $(APP_SPACE) --xl-app-space $(XL_APP_SPACE) \
+ --ram $(CUSTOM_RAM) --ram-limit $(RAM_LIMIT) --upsilon-ram $(UPSILON_RAM) --nwlink "$(NWLINK)"
check: nwa apps
@x=$$(cat $(B)/gen/arena_extra); \
@@ -240,6 +256,8 @@ APP_pvz = games/pvz/output/pvz.nwa:PlantsVsZombies.nwa
APP_sonic = games/sonic/output/sonic.nwa:SonicTheHedgehog.nwa
APP_cookieclicker = games/cookieclicker/output/cookieclicker.nwa:CookieClicker.nwa
APP_leveldevil = games/leveldevil/output/leveldevil.nwa:LevelDevil.nwa
+# the big games' modules are made from these (the kit)
+$(foreach g,$(XL_GAMES),$(eval MOD_$(g) = $$(word 1,$$(subst :, ,$$(APP_$(g))))))
apps: | $(B)
$(MAKE) -C games/numdash build NWLINK="node node_modules/nwlink/bin/nwlink"
diff --git a/games/celeste/Makefile b/games/celeste/Makefile
index 9f41c579..1364c1c0 100644
--- a/games/celeste/Makefile
+++ b/games/celeste/Makefile
@@ -15,7 +15,7 @@ GAME = src/res.c src/gfx.c src/util.c src/ent.c src/level.c src/tiles.c src/styl
SRC = $(GAME) src/plat_eadk.c src/main.c
HEADERS = $(wildcard src/*.h) ../common/epsilon_app.h ../common/epsilon_files.h
-CFLAGS = -std=gnu11 $(shell $(NWLINK) eadk-cflags-device) -DDATA_BIN='"src/data.bin"'
+CFLAGS = -std=gnu11 $(shell $(NWLINK) eadk-cflags-device) -DEPSILON_XL=1 -DDATA_BIN='"src/data.bin"'
CFLAGS += -O2 -Wall -Wextra -Wno-unused-parameter -fno-math-errno -fsingle-precision-constant
CFLAGS += -fno-tree-loop-distribute-patterns -flto -fno-fat-lto-objects -fwhole-program -fvisibility=internal
CFLAGS += -ffunction-sections -fdata-sections $(EXTRA)
diff --git a/games/championisland/Makefile b/games/championisland/Makefile
index 8ea5b1d6..e96717ee 100644
--- a/games/championisland/Makefile
+++ b/games/championisland/Makefile
@@ -21,7 +21,7 @@ SRC = $(GAME) src/plat_eadk.c src/main.c
COLD_OBJ = $(patsubst src/%.c,$(BUILD_DIR)/cold/%.o,$(COLD))
HEADERS = $(wildcard src/*.h) ../common/epsilon_app.h ../common/epsilon_files.h
-CFLAGS = -std=gnu11 $(shell $(NWLINK) eadk-cflags-device) -DDATA_BIN='"src/data.bin"'
+CFLAGS = -std=gnu11 $(shell $(NWLINK) eadk-cflags-device) -DEPSILON_XL=1 -DDATA_BIN='"src/data.bin"'
CFLAGS += -O2 -Wall -Wextra -Wno-unused-parameter -fno-math-errno -fsingle-precision-constant
CFLAGS += -fno-tree-loop-distribute-patterns -flto -fno-fat-lto-objects -fwhole-program -fvisibility=internal
CFLAGS += -ffunction-sections -fdata-sections $(EXTRA)
diff --git a/games/common/epsilon_app.h b/games/common/epsilon_app.h
index 7334c8db..c919dfea 100644
--- a/games/common/epsilon_app.h
+++ b/games/common/epsilon_app.h
@@ -13,7 +13,11 @@
* Files. The file system is found through the userland header of the
* software that runs this app: at the start of the userland of either
* firmware slot, 64 KiB later on models with an extra data sector. Only
- * addresses in external flash are probed, which exist on every model.
+ * addresses in external flash are probed, which exist on every model. The
+ * header is the one whose app area holds this app. Built with EPSILON_XL (the
+ * big games), an app past that area takes the one header left: Enlarged Extra
+ * Apps fill the other slot with apps, and a NumPlay with big games puts them
+ * there (its own games come first, in the app area).
*
* Upsilon. The custom software of the N0110 and N0115 runs .nwa apps too. Its
* header has the same first words but no device name (the footer comes two
@@ -50,17 +54,24 @@ __attribute__((unused)) static const epsilon_userland_t *epsilon_userland_of(boo
uint32_t self = (uint32_t)(uintptr_t)&epsilon_userland_of;
const epsilon_userland_t *found = NULL;
bool ups = false;
- for (unsigned i = 0; i < sizeof where / sizeof where[0]; i++) {
- const volatile epsilon_userland_t *h = (const volatile epsilon_userland_t *)(uintptr_t)where[i];
- const volatile uint32_t *w = (const volatile uint32_t *)(uintptr_t)where[i];
- if (h->magic != 0xDEC0EDFEu) continue;
- bool official = h->footer == 0xDEC0EDFEu, omega = w[9] == 0xDEC0EDFEu && w[10] == 0xEFBEADDEu;
- if (!official && !omega) continue;
- if (self < h->apps_flash_start || self >= h->apps_flash_end) continue;
- if (found) return NULL; /* ambiguous: better not guess */
- found = (const epsilon_userland_t *)h;
- ups = omega;
- }
+#if EPSILON_XL
+ /* then, when no app area holds this app: Enlarged Extra Apps (nwagyu's Nwagra) install apps past
+ * it, into the other slot of the external flash, whose software is gone then */
+ for (int past = 0; past < 2 && !found; past++)
+#else
+ const bool past = false;
+#endif
+ for (unsigned i = 0; i < sizeof where / sizeof where[0]; i++) {
+ const volatile epsilon_userland_t *h = (const volatile epsilon_userland_t *)(uintptr_t)where[i];
+ const volatile uint32_t *w = (const volatile uint32_t *)(uintptr_t)where[i];
+ if (h->magic != 0xDEC0EDFEu) continue;
+ bool official = h->footer == 0xDEC0EDFEu, omega = w[9] == 0xDEC0EDFEu && w[10] == 0xEFBEADDEu;
+ if (!official && !omega) continue;
+ if (self < h->apps_flash_start || self >= (past ? 0x90800000u : h->apps_flash_end)) continue;
+ if (found) return NULL; /* ambiguous: better not guess */
+ found = (const epsilon_userland_t *)h;
+ ups = omega;
+ }
if (upsilon) *upsilon = found && ups;
return found;
}
diff --git a/games/cookieclicker/Makefile b/games/cookieclicker/Makefile
index 5baa75e1..2e814c0b 100644
--- a/games/cookieclicker/Makefile
+++ b/games/cookieclicker/Makefile
@@ -24,7 +24,7 @@ COLD_OBJ = $(patsubst %.c,$(BUILD_DIR)/cold/%.o,$(notdir $(COLD)))
HEADERS = $(wildcard src/*.h) ../common/epsilon_app.h ../common/epsilon_files.h
# (its numbers are doubles, as the game's: no -fsingle-precision-constant)
-CFLAGS = -std=gnu11 $(shell $(NWLINK) eadk-cflags-device) -DDATA_BIN='"src/data.bin"'
+CFLAGS = -std=gnu11 $(shell $(NWLINK) eadk-cflags-device) -DEPSILON_XL=1 -DDATA_BIN='"src/data.bin"'
CFLAGS += -O2 -Wall -Wextra -Wno-unused-parameter -fno-math-errno
CFLAGS += -fno-tree-loop-distribute-patterns -flto -fno-fat-lto-objects -fwhole-program -fvisibility=internal
CFLAGS += -ffunction-sections -fdata-sections $(EXTRA)
diff --git a/games/doom/Makefile b/games/doom/Makefile
index 2e1d6ca2..b366df9d 100644
--- a/games/doom/Makefile
+++ b/games/doom/Makefile
@@ -40,7 +40,7 @@ ENGINE_W = -Wno-unused-function -Wno-unused-variable -Wno-unused-but-set-variabl
-Wno-cast-function-type -Wno-pointer-sign -Wno-char-subscripts -Wno-parentheses -Wno-address -Wno-unused-value \
-Wno-int-in-bool-context -Wno-array-bounds -Wno-stringop-overflow -Wno-absolute-value -Wno-dangling-pointer
-ARCH = $(shell $(NWLINK) eadk-cflags-device)
+ARCH = $(shell $(NWLINK) eadk-cflags-device) -DEPSILON_XL=1
COMMON = $(ARCH) $(INC) -Os -fno-math-errno -fno-unwind-tables -fno-asynchronous-unwind-tables -fsingle-precision-constant -fno-tree-loop-distribute-patterns \
-ffunction-sections -fdata-sections -fwrapv -flto -fno-fat-lto-objects -fvisibility=internal -DNDEBUG $(EXTRA)
CFLAGS = -std=gnu11 $(COMMON)
diff --git a/games/finalearth2/Makefile b/games/finalearth2/Makefile
index 42023ce1..f9032b84 100644
--- a/games/finalearth2/Makefile
+++ b/games/finalearth2/Makefile
@@ -22,7 +22,7 @@ COLD = $(filter-out $(HOT) src/plat_host.c src/plat_eadk.c,$(wildcard src/*.c))
COLD_OBJ = $(patsubst src/%.c,$(BUILD_DIR)/cold/%.o,$(COLD))
HEADERS = $(wildcard src/*.h) ../common/epsilon_app.h ../common/epsilon_files.h
-CFLAGS = -std=gnu11 $(shell $(NWLINK) eadk-cflags-device) -DDATA_BIN='"src/data.bin"'
+CFLAGS = -std=gnu11 $(shell $(NWLINK) eadk-cflags-device) -DEPSILON_XL=1 -DDATA_BIN='"src/data.bin"'
CFLAGS += -O2 -Wall -Wextra -Wno-unused-parameter -fno-math-errno -fsingle-precision-constant
CFLAGS += -fno-tree-loop-distribute-patterns -flto -fno-fat-lto-objects -fwhole-program -fvisibility=internal
CFLAGS += -ffunction-sections -fdata-sections $(EXTRA)
diff --git a/games/fnaf/Makefile b/games/fnaf/Makefile
index ad93c724..d8cbd105 100644
--- a/games/fnaf/Makefile
+++ b/games/fnaf/Makefile
@@ -22,7 +22,7 @@ COLD = $(filter-out $(HOT) src/plat_host.c src/plat_eadk.c,$(wildcard src/*.c))
COLD_OBJ = $(patsubst src/%.c,$(BUILD_DIR)/cold/%.o,$(COLD))
HEADERS = $(wildcard src/*.h) ../common/epsilon_app.h ../common/epsilon_files.h
-CFLAGS = -std=gnu11 $(shell $(NWLINK) eadk-cflags-device) -DDATA_BIN='"src/data.bin"'
+CFLAGS = -std=gnu11 $(shell $(NWLINK) eadk-cflags-device) -DEPSILON_XL=1 -DDATA_BIN='"src/data.bin"'
CFLAGS += -O2 -Wall -Wextra -Wno-unused-parameter -fno-math-errno -fsingle-precision-constant
CFLAGS += -fno-tree-loop-distribute-patterns -flto -fno-fat-lto-objects -fwhole-program -fvisibility=internal
CFLAGS += -ffunction-sections -fdata-sections $(EXTRA)
diff --git a/games/games.json b/games/games.json
index da6b4a76..481594f5 100644
--- a/games/games.json
+++ b/games/games.json
@@ -450,5 +450,352 @@
],
"app": "Sokoban.nwa",
"repo": "https://github.com/Mason363/NumPlay/tree/main/games/sokoban"
+ },
+ {
+ "id": "celeste",
+ "title": "Celeste",
+ "tagline": "Climb the mountain",
+ "credit": "Based on Celeste by Maddy Makes Games",
+ "top": "0x5865C8",
+ "bottom": "0x161A3A",
+ "accent": "0xFF5A6E",
+ "colors": 16,
+ "records": [
+ "celeste.sav",
+ "celeste_saves.py"
+ ],
+ "shots": [
+ "docs/forsaken.png"
+ ],
+ "repo": "https://github.com/Mason363/NumPlay/tree/main/games/celeste",
+ "default": false,
+ "xl": true
+ },
+ {
+ "id": "hollowknight",
+ "title": "Hollow Knight",
+ "tagline": "Explore Hallownest",
+ "credit": "Based on Hollow Knight by Team Cherry",
+ "top": "0x4C5E7E",
+ "bottom": "0x0B0F17",
+ "accent": "0xE8EEF5",
+ "colors": 16,
+ "heap": 20480,
+ "records": [
+ "hk1.sav",
+ "hk2.sav",
+ "hk3.sav",
+ "hk4.sav",
+ "hollowknight_saves.py"
+ ],
+ "shots": [
+ "docs/kingspass.png"
+ ],
+ "repo": "https://github.com/Mason363/NumPlay/tree/main/games/hollowknight",
+ "default": false,
+ "xl": true
+ },
+ {
+ "id": "undertale",
+ "title": "Undertale",
+ "tagline": "Fall into the Underground",
+ "credit": "Based on Undertale by Toby Fox",
+ "top": "0x3A3A46",
+ "bottom": "0x050506",
+ "accent": "0xE8241C",
+ "colors": 16,
+ "records": [
+ "undertale.sav",
+ "utresume.sav",
+ "utconfig.sav",
+ "undertale_saves.py"
+ ],
+ "reset": [
+ "undertale.sav",
+ "utresume.sav",
+ "undertale_saves.py"
+ ],
+ "shots": [
+ "docs/flowers.png"
+ ],
+ "repo": "https://github.com/Mason363/NumPlay/tree/main/games/undertale",
+ "default": false,
+ "xl": true
+ },
+ {
+ "id": "championisland",
+ "title": "Champion Island",
+ "tagline": "Seven sports, one island",
+ "credit": "Based on Google's Champion Island Games",
+ "top": "0x3FA9F5",
+ "bottom": "0x15507A",
+ "accent": "0xF5B83D",
+ "colors": 16,
+ "heap": 24576,
+ "records": [
+ "champion.sav",
+ "champion_saves.py"
+ ],
+ "shots": [
+ "docs/pingpong.png"
+ ],
+ "repo": "https://github.com/Mason363/NumPlay/tree/main/games/championisland",
+ "default": false,
+ "xl": true
+ },
+ {
+ "id": "finalearth2",
+ "title": "The Final Earth 2",
+ "tagline": "Build a city in space",
+ "credit": "Based on the game by Florian van Strien",
+ "top": "0x4B3B8F",
+ "bottom": "0x140F33",
+ "accent": "0x6EDC5A",
+ "colors": 16,
+ "records": [
+ "finalearth2.sav",
+ "fe2meta.dat",
+ "finalearth2_saves.py"
+ ],
+ "shots": [
+ "docs/city.png"
+ ],
+ "repo": "https://github.com/Mason363/NumPlay/tree/main/games/finalearth2",
+ "default": false,
+ "xl": true
+ },
+ {
+ "id": "numpowder",
+ "title": "NumPowder",
+ "tagline": "Sand, water, fire and more",
+ "credit": "Inspired by The Powder Toy",
+ "top": "0xC9A15A",
+ "bottom": "0x3B2A12",
+ "accent": "0x3C8DFF",
+ "colors": 16,
+ "heap": 53000,
+ "records": [
+ "numpowder.cfg",
+ "numpowder.sav",
+ "numpowder1.sav",
+ "numpowder2.sav",
+ "numpowder3.sav",
+ "numpowder4.sav",
+ "numpowder_saves.py"
+ ],
+ "reset": [
+ "numpowder.cfg",
+ "numpowder.sav",
+ "numpowder_saves.py"
+ ],
+ "shots": [
+ "docs/sand_water.png"
+ ],
+ "repo": "https://github.com/Mason363/NumPlay/tree/main/games/numpowder",
+ "default": false,
+ "xl": true
+ },
+ {
+ "id": "subway",
+ "title": "Subway Surfers",
+ "tagline": "Dodge the trains",
+ "credit": "Based on Subway Surfers by SYBO and Kiloo",
+ "top": "0x3A8FD8",
+ "bottom": "0x173A5E",
+ "accent": "0xFFC93C",
+ "colors": 16,
+ "heap": 101920,
+ "records": [
+ "subway.sav",
+ "subway_saves.py"
+ ],
+ "shots": [
+ "docs/run.png"
+ ],
+ "repo": "https://github.com/Mason363/NumPlay/tree/main/games/subway",
+ "default": false,
+ "xl": true
+ },
+ {
+ "id": "fnaf",
+ "title": "Five Nights at Freddy's",
+ "tagline": "Survive five nights",
+ "credit": "Based on the game by Scott Cawthon",
+ "top": "0x4A3A30",
+ "bottom": "0x0A0806",
+ "accent": "0xD8A93A",
+ "colors": 16,
+ "records": [
+ "fnaf.sav",
+ "fnafres.sav",
+ "fnaf_saves.py"
+ ],
+ "shots": [
+ "docs/office.png"
+ ],
+ "repo": "https://github.com/Mason363/NumPlay/tree/main/games/fnaf",
+ "default": false,
+ "xl": true
+ },
+ {
+ "id": "doom",
+ "title": "Doom",
+ "tagline": "Rip and tear",
+ "credit": "Based on Doom by id Software",
+ "top": "0x6B4A2E",
+ "bottom": "0x1A0F08",
+ "accent": "0xD8261C",
+ "colors": 16,
+ "heap": 20480,
+ "records": [
+ "doomsav0.dsg",
+ "doomsav1.dsg",
+ "doomsav2.dsg",
+ "doomsav3.dsg",
+ "doomsav4.dsg",
+ "doomsav5.dsg",
+ "doomres.sav",
+ "doom.cfg",
+ "doom_saves.py"
+ ],
+ "reset": [
+ "doomsav0.dsg",
+ "doomsav1.dsg",
+ "doomsav2.dsg",
+ "doomsav3.dsg",
+ "doomsav4.dsg",
+ "doomsav5.dsg",
+ "doomres.sav",
+ "doom_saves.py"
+ ],
+ "shots": [
+ "docs/hangar.png"
+ ],
+ "repo": "https://github.com/Mason363/NumPlay/tree/main/games/doom",
+ "default": false,
+ "xl": true
+ },
+ {
+ "id": "isaac",
+ "title": "The Binding of Isaac",
+ "tagline": "Cry through the basement",
+ "credit": "Based on the game by Edmund McMillen",
+ "top": "0x7A5A44",
+ "bottom": "0x23170F",
+ "accent": "0xE04848",
+ "colors": 16,
+ "records": [
+ "isaac.sav",
+ "isaacrun.sav",
+ "isaac_saves.py"
+ ],
+ "shots": [
+ "docs/basement.png"
+ ],
+ "repo": "https://github.com/Mason363/NumPlay/tree/main/games/isaac",
+ "default": false,
+ "xl": true
+ },
+ {
+ "id": "hillclimb",
+ "title": "Hill Climb Racing",
+ "tagline": "Drive up, don't flip",
+ "credit": "Based on Hill Climb Racing by Fingersoft",
+ "top": "0x5BBEF0",
+ "bottom": "0x2D5A1A",
+ "accent": "0xE53935",
+ "colors": 16,
+ "heap": 32768,
+ "records": [
+ "hillclimb.sav",
+ "hillclimb_saves.py"
+ ],
+ "shots": [
+ "docs/countryside.png"
+ ],
+ "repo": "https://github.com/Mason363/NumPlay/tree/main/games/hillclimb",
+ "default": false,
+ "xl": true
+ },
+ {
+ "id": "pvz",
+ "title": "Plants vs. Zombies",
+ "tagline": "Plant your lawn",
+ "credit": "Based on the game by PopCap Games",
+ "top": "0x6CC04A",
+ "bottom": "0x1F4A17",
+ "accent": "0xFFE040",
+ "colors": 16,
+ "records": [
+ "pvz.sav",
+ "pvzlevel.sav",
+ "pvz_saves.py"
+ ],
+ "shots": [
+ "docs/day.png"
+ ],
+ "repo": "https://github.com/Mason363/NumPlay/tree/main/games/pvz",
+ "default": false,
+ "xl": true
+ },
+ {
+ "id": "sonic",
+ "title": "Sonic the Hedgehog",
+ "tagline": "Run through six zones",
+ "credit": "Based on the game by Sonic Team",
+ "top": "0x2E6FE0",
+ "bottom": "0x0E2766",
+ "accent": "0xFFD000",
+ "colors": 16,
+ "records": [
+ "sonic.sav",
+ "sonic_saves.py"
+ ],
+ "shots": [
+ "docs/ghz.png"
+ ],
+ "repo": "https://github.com/Mason363/NumPlay/tree/main/games/sonic",
+ "default": false,
+ "xl": true
+ },
+ {
+ "id": "cookieclicker",
+ "title": "Cookie Clicker",
+ "tagline": "Bake billions of cookies",
+ "credit": "Based on Cookie Clicker by Orteil",
+ "top": "0x4E6E9E",
+ "bottom": "0x1A2438",
+ "accent": "0xD9A35A",
+ "colors": 16,
+ "records": [
+ "cookieclicker.sav",
+ "cookieclicker_saves.py"
+ ],
+ "shots": [
+ "docs/shot.png"
+ ],
+ "repo": "https://github.com/Mason363/NumPlay/tree/main/games/cookieclicker",
+ "default": false,
+ "xl": true
+ },
+ {
+ "id": "leveldevil",
+ "title": "Level Devil",
+ "tagline": "Run to the door",
+ "credit": "Based on Level Devil by Unept",
+ "top": "0xF2A33C",
+ "bottom": "0x6E3A12",
+ "accent": "0xE8402A",
+ "colors": 16,
+ "records": [
+ "leveldevil.sav",
+ "leveldevil_saves.py"
+ ],
+ "shots": [
+ "docs/title.png"
+ ],
+ "repo": "https://github.com/Mason363/NumPlay/tree/main/games/leveldevil",
+ "default": false,
+ "xl": true
}
]
diff --git a/games/hillclimb/Makefile b/games/hillclimb/Makefile
index f97cbbe8..b1b63bd0 100644
--- a/games/hillclimb/Makefile
+++ b/games/hillclimb/Makefile
@@ -28,7 +28,7 @@ BOX2D_H = $(wildcard src/box2d/Box2D/*/*.h src/box2d/Box2D/*/*/*.h)
PHYS = src/car.cpp $(BOX2D)
PHYS_OBJ = $(patsubst src/%.cpp,$(BUILD_DIR)/phys/%.o,$(PHYS))
-CFLAGS = -std=gnu11 $(shell $(NWLINK) eadk-cflags-device) -DDATA_BIN='"src/data.bin"'
+CFLAGS = -std=gnu11 $(shell $(NWLINK) eadk-cflags-device) -DEPSILON_XL=1 -DDATA_BIN='"src/data.bin"'
CFLAGS += -O2 -Wall -Wextra -Wno-unused-parameter -fno-math-errno -fsingle-precision-constant
CFLAGS += -fno-tree-loop-distribute-patterns -flto -fno-fat-lto-objects -fwhole-program -fvisibility=internal
CFLAGS += -ffunction-sections -fdata-sections $(EXTRA)
diff --git a/games/hollowknight/Makefile b/games/hollowknight/Makefile
index ebee2546..eae9dcc2 100644
--- a/games/hollowknight/Makefile
+++ b/games/hollowknight/Makefile
@@ -13,7 +13,7 @@ GAME = src/res.c src/tex.c src/room.c src/gfx.c src/phys.c src/anim.c src/hero.c
SRC = $(GAME) src/plat_eadk.c src/main.c
HEADERS = $(wildcard src/*.h) ../common/epsilon_app.h ../common/epsilon_files.h
-CFLAGS = -std=gnu11 $(shell $(NWLINK) eadk-cflags-device) -DDATA_BIN='"src/data.bin"'
+CFLAGS = -std=gnu11 $(shell $(NWLINK) eadk-cflags-device) -DEPSILON_XL=1 -DDATA_BIN='"src/data.bin"'
CFLAGS += -O2 -Wall -Wextra -Wno-unused-parameter -fno-math-errno -fsingle-precision-constant
CFLAGS += -fno-tree-loop-distribute-patterns -flto -fno-fat-lto-objects -fwhole-program -fvisibility=internal
CFLAGS += -ffunction-sections -fdata-sections $(EXTRA)
diff --git a/games/isaac/Makefile b/games/isaac/Makefile
index 5dd8e6b4..e7660570 100644
--- a/games/isaac/Makefile
+++ b/games/isaac/Makefile
@@ -22,7 +22,7 @@ COLD = $(filter-out $(HOT) src/plat_host.c src/plat_eadk.c,$(wildcard src/*.c))
COLD_OBJ = $(patsubst src/%.c,$(BUILD_DIR)/cold/%.o,$(COLD))
HEADERS = $(wildcard src/*.h) ../common/epsilon_app.h ../common/epsilon_files.h
-CFLAGS = -std=gnu11 $(shell $(NWLINK) eadk-cflags-device) -DDATA_BIN='"src/data.bin"'
+CFLAGS = -std=gnu11 $(shell $(NWLINK) eadk-cflags-device) -DEPSILON_XL=1 -DDATA_BIN='"src/data.bin"'
CFLAGS += -O2 -Wall -Wextra -Wno-unused-parameter -fno-math-errno -fsingle-precision-constant
CFLAGS += -fno-tree-loop-distribute-patterns -flto -fno-fat-lto-objects -fwhole-program -fvisibility=internal
CFLAGS += -ffunction-sections -fdata-sections $(EXTRA)
diff --git a/games/leveldevil/Makefile b/games/leveldevil/Makefile
index ed14e559..a657745b 100644
--- a/games/leveldevil/Makefile
+++ b/games/leveldevil/Makefile
@@ -17,7 +17,7 @@ ROOMS = $(BUILD_DIR)/rooms.inc
HEADERS = ../common/epsilon_app.h ../common/epsilon_files.h ../common/np_text.h ../../launcher/src/gfx.h \
../../launcher/src/np.h ../../launcher/src/font.h
-CFLAGS = -std=c11 $(shell $(NWLINK) eadk-cflags-device) -I$(BUILD_DIR)
+CFLAGS = -std=c11 $(shell $(NWLINK) eadk-cflags-device) -DEPSILON_XL=1 -I$(BUILD_DIR)
CFLAGS += -O2 -Wall -Wextra -Wno-unused-parameter -fno-math-errno -fsingle-precision-constant
CFLAGS += -fno-tree-loop-distribute-patterns -flto -fno-fat-lto-objects -fwhole-program -fvisibility=internal
LDFLAGS = -Wl,--relocatable -nostartfiles --specs=nano.specs
diff --git a/games/numpowder/Makefile b/games/numpowder/Makefile
index 240f339b..eb2104b2 100644
--- a/games/numpowder/Makefile
+++ b/games/numpowder/Makefile
@@ -22,7 +22,7 @@ COLD = $(filter-out $(HOT) src/plat_host.c src/plat_eadk.c,$(wildcard src/*.c))
COLD_OBJ = $(patsubst src/%.c,$(BUILD_DIR)/cold/%.o,$(COLD))
HEADERS = $(wildcard src/*.h) ../common/epsilon_app.h ../common/epsilon_files.h
-CFLAGS = -std=gnu11 $(shell $(NWLINK) eadk-cflags-device)
+CFLAGS = -std=gnu11 $(shell $(NWLINK) eadk-cflags-device) -DEPSILON_XL=1
CFLAGS += -O2 -Wall -Wextra -Wno-unused-parameter -fno-math-errno -fsingle-precision-constant
CFLAGS += -fno-tree-loop-distribute-patterns -flto -fno-fat-lto-objects -fwhole-program -fvisibility=internal
CFLAGS += -ffunction-sections -fdata-sections $(EXTRA)
diff --git a/games/pvz/Makefile b/games/pvz/Makefile
index 8764a092..b218319c 100644
--- a/games/pvz/Makefile
+++ b/games/pvz/Makefile
@@ -22,7 +22,7 @@ COLD = $(filter-out $(HOT) src/plat_host.c src/plat_eadk.c,$(wildcard src/*.c))
COLD_OBJ = $(patsubst %.c,$(BUILD_DIR)/cold/%.o,$(notdir $(COLD)))
HEADERS = $(wildcard src/*.h) ../common/epsilon_app.h ../common/epsilon_files.h
-CFLAGS = -std=gnu11 $(shell $(NWLINK) eadk-cflags-device) -DDATA_BIN='"src/data.bin"'
+CFLAGS = -std=gnu11 $(shell $(NWLINK) eadk-cflags-device) -DEPSILON_XL=1 -DDATA_BIN='"src/data.bin"'
CFLAGS += -O2 -Wall -Wextra -Wno-unused-parameter -fno-math-errno -fsingle-precision-constant
CFLAGS += -fno-tree-loop-distribute-patterns -flto -fno-fat-lto-objects -fwhole-program -fvisibility=internal
CFLAGS += -ffunction-sections -fdata-sections $(EXTRA)
diff --git a/games/sonic/Makefile b/games/sonic/Makefile
index 5a34a21d..920ed3e9 100644
--- a/games/sonic/Makefile
+++ b/games/sonic/Makefile
@@ -22,7 +22,7 @@ COLD = $(filter-out $(HOT) src/plat_host.c src/plat_eadk.c,$(wildcard src/*.c))
COLD_OBJ = $(patsubst src/%.c,$(BUILD_DIR)/cold/%.o,$(COLD))
HEADERS = $(wildcard src/*.h) ../common/epsilon_app.h ../common/epsilon_files.h
-CFLAGS = -std=gnu11 $(shell $(NWLINK) eadk-cflags-device) -DDATA_BIN='"src/data.bin"'
+CFLAGS = -std=gnu11 $(shell $(NWLINK) eadk-cflags-device) -DEPSILON_XL=1 -DDATA_BIN='"src/data.bin"'
CFLAGS += -O2 -Wall -Wextra -Wno-unused-parameter -fno-math-errno -fsingle-precision-constant -fwrapv
CFLAGS += -fno-tree-loop-distribute-patterns -flto -fno-fat-lto-objects -fwhole-program -fvisibility=internal
CFLAGS += -ffunction-sections -fdata-sections $(EXTRA)
diff --git a/games/subway/Makefile b/games/subway/Makefile
index 342606d0..66c888ef 100644
--- a/games/subway/Makefile
+++ b/games/subway/Makefile
@@ -20,7 +20,7 @@ BUILD_DIR = output
SRC = $(filter-out src/plat_host.c,$(wildcard src/*.c))
HEADERS = $(wildcard src/*.h) ../common/epsilon_app.h ../common/epsilon_files.h
-CFLAGS = -std=gnu11 $(shell $(NWLINK) eadk-cflags-device)
+CFLAGS = -std=gnu11 $(shell $(NWLINK) eadk-cflags-device) -DEPSILON_XL=1
CFLAGS += -O2 -Wall -Wextra -Wno-unused-parameter -fno-math-errno -fsingle-precision-constant
CFLAGS += -fno-tree-loop-distribute-patterns -flto -fno-fat-lto-objects -fwhole-program -fvisibility=internal
CFLAGS += -ffunction-sections -fdata-sections $(EXTRA)
diff --git a/games/undertale/Makefile b/games/undertale/Makefile
index 9d85865a..a55cda4a 100644
--- a/games/undertale/Makefile
+++ b/games/undertale/Makefile
@@ -22,7 +22,7 @@ COLD = $(filter-out $(HOT) src/plat_host.c src/plat_eadk.c,$(wildcard src/*.c))
COLD_OBJ = $(patsubst src/%.c,$(BUILD_DIR)/cold/%.o,$(COLD))
HEADERS = $(wildcard src/*.h) ../common/epsilon_app.h ../common/epsilon_files.h
-CFLAGS = -std=gnu11 $(shell $(NWLINK) eadk-cflags-device) -DDATA_BIN='"src/data.bin"'
+CFLAGS = -std=gnu11 $(shell $(NWLINK) eadk-cflags-device) -DEPSILON_XL=1 -DDATA_BIN='"src/data.bin"'
CFLAGS += -O2 -Wall -Wextra -Wno-unused-parameter -fno-math-errno -fsingle-precision-constant
CFLAGS += -fno-tree-loop-distribute-patterns -flto -fno-fat-lto-objects -fwhole-program -fvisibility=internal
CFLAGS += -ffunction-sections -fdata-sections $(EXTRA)
diff --git a/launcher/src/games.c b/launcher/src/games.c
index 6c9603be..7adcc6d7 100644
--- a/launcher/src/games.c
+++ b/launcher/src/games.c
@@ -35,23 +35,35 @@ uint32_t np_game_size(int i) {
#endif
}
+/* where the game's heap starts in the arena: after its .data, then its .bss (np_<game>_heap, tools/gen_games.py) */
+static uint8_t *heap_of(const np_game_t *g) { return (uint8_t *)(((uintptr_t)(g->bss + g->bss_size) + 7) & ~(uintptr_t)7); }
+
uint32_t np_game_ram_missing(int i) {
#if NP_SIMULATOR
(void)i;
return 0;
#else
const np_game_t *g = &np_games[i];
- uint32_t data = (uint32_t)(g->data + g->data_size - np_arena), bss = (uint32_t)(g->bss + g->bss_size - np_arena);
- uint32_t need = data > bss ? data : bss, room = np_arena_room();
+ uint32_t need = (uint32_t)(heap_of(g) - np_arena) + g->heap, room = np_arena_room();
return need > room ? need - room : 0;
#endif
}
+/* (the heap of the game running now: from its own RAM's end to the app's, _heap_end) */
+static uint8_t *heap_top;
+void *np_sbrk(ptrdiff_t incr) {
+ uint8_t *old = heap_top;
+ if (incr > (ptrdiff_t)(np_arena + np_arena_room() - old)) return (void *)-1;
+ heap_top += incr;
+ return old;
+}
+
void np_game_run(int i) {
const np_game_t *g = &np_games[i];
if (np_game_ram_missing(i)) return; /* (the home screen says so and doesn't start it) */
/* fresh RAM, as if the game had just been launched from the home screen */
if (g->data_size) memcpy(g->data, g->data_init, g->data_size);
if (g->bss_size) memset(g->bss, 0, g->bss_size);
+ heap_top = heap_of(g);
g->main();
}
diff --git a/launcher/src/np.h b/launcher/src/np.h
index 05c48f30..590217e8 100644
--- a/launcher/src/np.h
+++ b/launcher/src/np.h
@@ -60,10 +60,15 @@ typedef struct {
uint8_t nshots;
const char *const *records; /* save files, deleted on uninstall (name*: all starting so) */
const char *const *progress; /* the ones Reset deletes (not levels made in an editor) */
+#if NP_SIMULATOR
uint32_t est_size; /* code and data, for the simulator */
+#else
+ uint32_t heap; /* the least RAM the game takes after its own (its heap) */
+#endif
} np_game_t;
-#define NP_MAX_GAMES 32 /* tools/gen_games.py checks games.json against it */
+/* every game of games.json, the kit's too, can be in one NumPlay (tools/gen_games.py checks it) */
+#define NP_MAX_GAMES 48
#if NP_SIMULATOR
extern const np_game_t np_games[];
extern const int np_game_count;
@@ -77,6 +82,9 @@ bool np_game_installed(int i);
uint32_t np_game_size(int i); /* bytes of flash */
uint32_t np_game_ram_missing(int i); /* the bytes of RAM a game needs more than there is, or 0 */
void np_game_run(int i);
+/* The C library's malloc of a big game takes its memory here (the build renames the game's _sbrk):
+ * the RAM after the running game's own, as _heap_start is for it (np_<game>_heap) */
+void *np_sbrk(ptrdiff_t incr);
/* ---- storage (storage.c): Epsilon's record file system */
bool np_storage_delete(const char *name); /* true if gone (or never there) */
diff --git a/launcher/src/storage.c b/launcher/src/storage.c
index 8ca7f8b8..af2c17cb 100644
--- a/launcher/src/storage.c
+++ b/launcher/src/storage.c
@@ -158,13 +158,23 @@ static bool lz_scratch(uint32_t largest) {
return lz_table && lz_buf;
}
+/* a game that keeps a copy of its saves in a script of its own (one of its records), as the big
+ * games do: the installer keeps scripts, so its saves come back without NumPlay's copy */
+static bool own_copy(int g) {
+ for (const char *const *r = np_games[g].records; r && *r; r++) {
+ size_t n = strlen(*r);
+ if (n > 3 && !strcmp(*r + n - 3, ".py")) return true;
+ }
+ return false;
+}
+
/* Every save file NumPlay knows, each name once (a name ending with '*': every record there is that
* starts with the rest, like NumBlocks' regions); false when i is past the end */
static bool save_name(int i, char out[64]) {
if (i-- == 0) return strcpy(out, CONFIG_NAME), true;
if (i-- == 0) return strcpy(out, BG_NAME), true; /* the home screen's background */
for (int g = 0; g < np_game_count; g++)
- for (const char *const *r = np_games[g].records; r && *r; r++) {
+ for (const char *const *r = own_copy(g) ? NULL : np_games[g].records; r && *r; r++) {
bool seen = false;
for (int h = 0; h <= g && !seen; h++)
for (const char *const *q = np_games[h].records; q && *q && q != r && !seen; q++) seen = !strcmp(*q, *r);
diff --git a/launcher/src/sys.c b/launcher/src/sys.c
index 4acaa349..cbf55b0b 100644
--- a/launcher/src/sys.c
+++ b/launcher/src/sys.c
@@ -24,7 +24,7 @@
/* 1 for Epsilon's header, 2 for Upsilon's (no device name: the footer two words sooner, then
* Omega's magic; and none of the system calls for Home, checksums or flash), 0 if neither */
-static int header_kind(uint32_t address) {
+static int header_kind(uint32_t address, bool past) {
/* the userland header sits at the start of the userland, after the kernel
* (and an optional extra data sector) of either firmware slot */
if (address != 0x90010000 && address != 0x90020000 && address != 0x90410000 && address != 0x90420000) return 0;
@@ -32,9 +32,9 @@ static int header_kind(uint32_t address) {
const volatile uint32_t *w = (const volatile uint32_t *)address;
if (h->magic != USERLAND_MAGIC) return 0;
int kind = h->footer == USERLAND_MAGIC ? 1 : w[9] == USERLAND_MAGIC && w[10] == 0xEFBEADDEu ? 2 : 0;
- /* this app must run from the app area it describes */
- uint32_t self = (uint32_t)(uintptr_t)&header_kind;
- bool inside = h->apps_flash_start < h->apps_flash_end && self >= h->apps_flash_start && self < h->apps_flash_end &&
+ /* this app must run from the app area it describes (past: or after it, up to the flash's end) */
+ uint32_t self = (uint32_t)(uintptr_t)&header_kind, end = past ? 0x90800000u : h->apps_flash_end;
+ bool inside = h->apps_flash_start < end && self >= h->apps_flash_start && self < end &&
h->apps_flash_start % 0x10000 == 0;
return inside ? kind : 0;
}
@@ -47,19 +47,23 @@ const np_userland_t *np_userland(void) {
if (done) return cached;
done = true;
/* Only external flash is probed: it exists on every model (RAM addresses
- * differ between models, and reading a missing one faults). */
+ * differ between models, and reading a missing one faults). Then, when no
+ * app area holds this app: Enlarged Extra Apps (nwagyu's Nwagra) install
+ * apps past it, into the other slot of the external flash, whose software
+ * is gone then, so the one header left is this app's. */
static const uint32_t candidates[] = {0x90010000, 0x90020000, 0x90410000, 0x90420000};
- for (unsigned i = 0; i < 4; i++) {
- int kind = header_kind(candidates[i]);
- if (!kind) continue;
- if (cached) { /* two matches: refuse to guess */
- cached = 0;
- upsilon = false;
- return 0;
+ for (int past = 0; past < 2 && !cached; past++)
+ for (unsigned i = 0; i < 4; i++) {
+ int kind = header_kind(candidates[i], past);
+ if (!kind) continue;
+ if (cached) { /* two matches: refuse to guess */
+ cached = 0;
+ upsilon = false;
+ return 0;
+ }
+ cached = (const np_userland_t *)candidates[i];
+ upsilon = kind == 2;
}
- cached = (const np_userland_t *)candidates[i];
- upsilon = kind == 2;
- }
return cached;
}
diff --git a/tests/test_games.py b/tests/test_games.py
index a5957003..97628a3d 100644
--- a/tests/test_games.py
+++ b/tests/test_games.py
@@ -390,7 +390,7 @@ def main():
ap.add_argument("--numplay", help="play the games inside this NumPlay.nwa instead")
a = ap.parse_args()
order = [g["id"] for g in json.load(open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "games",
- "games.json")))]
+ "games.json"))) if g.get("default", True)]
os.makedirs(a.out, exist_ok=True)
failed = False
for name, (nwa, save, keys1, home1, keys2, home2) in GAMES.items():
diff --git a/tests/test_progress.py b/tests/test_progress.py
index 2e5a6eb3..57301e9c 100644
--- a/tests/test_progress.py
+++ b/tests/test_progress.py
@@ -140,6 +140,7 @@ def main():
a = ap.parse_args()
os.makedirs(a.out, exist_ok=True)
games = json.load(open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "games", "games.json")))
+ games = [g for g in games if g.get("default", True)] # (NumPlay.nwa's)
rnd = random.Random(7)
script = ("pi.py", b"\x01print(3.14159)\n\x00")
# a save for every file the games write (binary, zeros included), and NumPlay's settings
diff --git a/tests/test_uninstall.py b/tests/test_uninstall.py
index a2db0a05..a8802295 100644
--- a/tests/test_uninstall.py
+++ b/tests/test_uninstall.py
@@ -41,7 +41,7 @@ def main():
c = emu.Calculator(a.nwa)
manifest = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "games", "games.json")
manifest = json.load(open(manifest))
- games = [g["id"] for g in manifest]
+ games = [g["id"] for g in manifest if f"np_{g['id']}_begin" in c.symbols] # (the games of this NumPlay)
order = sorted(games, key=lambda g: c.symbols[f"np_{g}_begin"])
target = a.game
if target not in order:
diff --git a/tools/games_mk.py b/tools/games_mk.py
index 526cbbae..077d7bad 100644
--- a/tools/games_mk.py
+++ b/tools/games_mk.py
@@ -4,13 +4,20 @@
A game with an "app" entry (its release file, e.g. "Snake.nwa") is in the
standard layout of games/numvisuals: its Makefile's `build`, `module` and
`sim-module` targets make output/<id>.nwa, module.o and sim-module.o, so the
-top-level Makefile needs nothing else for it (STD_GAMES)."""
+top-level Makefile needs nothing else for it (STD_GAMES).
+
+GAMES are the games of NumPlay.nwa; OPTIONAL_GAMES, those marked "default": false, are only
+in the kit the customizer website links a NumPlay of your own from, and so are XL_GAMES, marked
+"xl": true (not in OPTIONAL_GAMES): the big games, each a release file of its own too, whose
+module is made from that .nwa, for a NumPlay on calculators with Enlarged Extra Apps (Makefile)."""
import json
import sys
games = json.load(open(sys.argv[1]))
print("# Generated by tools/games_mk.py from games/games.json")
-print("GAMES := " + " ".join(g["id"] for g in games))
+print("GAMES := " + " ".join(g["id"] for g in games if g.get("default", True)))
+print("OPTIONAL_GAMES := " + " ".join(g["id"] for g in games if not g.get("default", True) and not g.get("xl")))
+print("XL_GAMES := " + " ".join(g["id"] for g in games if g.get("xl")))
for n, g in enumerate(games, 1):
i = g["id"]
print(f"INDEX_{i} := {n}")
diff --git a/tools/gen_games.py b/tools/gen_games.py
index 6dbea4ce..3d3541ba 100644
--- a/tools/gen_games.py
+++ b/tools/gen_games.py
@@ -7,7 +7,9 @@ From games/games.json and the module sizes written by npmodule.py:
games it links in a row, np_games to np_games_end, so a NumPlay with any set of games is
linked from the same objects (the customizer website does it in the browser);
- arena.s: the RAM arena, and the symbols that place each game's .data and
- .bss inside it (games never run together). It is the last of NumPlay's RAM
+ .bss inside it (games never run together), then its heap (np_<game>_heap, the
+ game's _heap_start: a big game takes the RAM after its own, its "heap" in
+ games.json the least it needs, and its malloc np_sbrk's). It is the last of NumPlay's RAM
and holds what the launcher needs; a game uses it and the RAM after it, up to
the end of what the calculator's software gives apps (_heap_end), so NumPlay
installs with a smaller userland too and a game that doesn't fit there says
@@ -59,8 +61,8 @@ def main():
games = [g for g in games if g.get("default", True)] # the others only come from the website
np_h = open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "launcher", "src", "np.h")).read()
limit = int(re.search(r"#define NP_MAX_GAMES (\d+)", np_h).group(1))
- if len(games) > limit:
- raise SystemExit(f"{len(games)} games, but the launcher holds {limit} (NP_MAX_GAMES in launcher/src/np.h)")
+ if len(manifest) > limit: # (the website may link them all)
+ raise SystemExit(f"{len(manifest)} games, but the launcher holds {limit} (NP_MAX_GAMES in launcher/src/np.h)")
os.makedirs(a.out, exist_ok=True)
sizes = {}
for g in manifest:
@@ -76,9 +78,10 @@ def main():
s = sizes[g["id"]]
data = s["data"]
bss_off = (data + 7) & ~7
- layout[g["id"]] = (0, bss_off)
+ heap_off = (bss_off + s["bss"] + 7) & ~7
+ layout[g["id"]] = (0, bss_off, heap_off)
if g in games:
- need = max(need, bss_off + s["bss"])
+ need = max(need, heap_off + g.get("heap", 0))
need = (need + 7) & ~7
# (the simulator's arena, a C array, keeps the hungriest game's size)
arena = need if a.simulator else LAUNCHER_RAM
@@ -105,7 +108,8 @@ def main():
return [f" {{{c_str(i)}, {c_str(g['title'])}, {c_str(g['tagline'])}, {c_str(g.get('credit'))},",
f" {g['top']}, {g['bottom']}, {g['accent']}, np_{i}_begin, np_{i}_end, np_{i}_main,",
f" {r(f'np_{i}_data')}, {r(f'np_{i}_init')}, {z(s['data'])}, {r(f'np_{i}_bss')}, {z(s['bss'])},",
- f" np_{i}_shots, {len(g['shots'])}, {prefix}records, {prefix}progress, {est}}}"]
+ f" np_{i}_shots, {len(g['shots'])}, {prefix}records, {prefix}progress, "
+ f"{g.get('heap', 0) if ram else est}}}"] # (the calculator: its heap; the simulator: its size)
if a.simulator:
# ---- gametable.c: the simulator has no flash blocks and gives each game its own RAM
@@ -148,9 +152,10 @@ def main():
f" .word {arena}"]
for g in kit:
i = g["id"]
- d, b = layout[i]
+ d, b, h = layout[i]
S += [f" .global np_{i}_data", f" .set np_{i}_data, np_arena + {d}",
- f" .global np_{i}_bss", f" .set np_{i}_bss, np_arena + {b}"]
+ f" .global np_{i}_bss", f" .set np_{i}_bss, np_arena + {b}",
+ f" .global np_{i}_heap", f" .set np_{i}_heap, np_arena + {h}"]
open(os.path.join(a.out, "arena.s"), "w").write("\n".join(S) + "\n")
open(os.path.join(a.out, "arena_extra"), "w").write(f"{need - arena}\n")
diff --git a/tools/kit.py b/tools/kit.py
index 9759ff8b..c7df9983 100644
--- a/tools/kit.py
+++ b/tools/kit.py
@@ -6,10 +6,18 @@ NumPlay.nwa from: base.o (the launcher), arena.o (the RAM the games share), an a
icon, and one object per game, with a script made of script.json's parts (tools/gen_games.py).
This copies them to OUT, gzipped, with kit.json (the games, their sizes, colours and
limits), each game's icon and thumbnail, and checks that linking the default games from OUT
-gives NumPlay.nwa's bytes on the calculator.
+gives NumPlay.nwa's bytes on the calculator, and that each big game ("xl", for calculators
+with Enlarged Extra Apps: up to xlAppSpace bytes of apps) links with the launcher alone. The
+blocks of the script go in the games' order ("index"), so the big games come last: past the
+app area, where Enlarged Extra Apps put them, only they look for the calculator's files there
+(EPSILON_XL in games/common/epsilon_app.h).
+
+A game's "ram" in kit.json is what it takes in the arena (its .data, its .bss and the least heap
+it needs): it fits a calculator when ram + launcherRam (NumPlay's own RAM, before the arena) is
+at most what the calculator's software gives apps ("ram", "ramLimit", "upsilonRam").
Usage: kit.py games.json BUILD OUT --version V --variants "..." --default "ids" --upsilon "ids"
- --app-space N --ram N --upsilon-ram N --nwlink NWLINK
+ --app-space N --xl-app-space N --ram N --ram-limit N --upsilon-ram N --nwlink NWLINK
"""
import argparse
import gzip
@@ -89,7 +97,9 @@ def main():
ap.add_argument("--default", required=True)
ap.add_argument("--upsilon", default="")
ap.add_argument("--app-space", type=int, required=True)
+ ap.add_argument("--xl-app-space", type=int, required=True)
ap.add_argument("--ram", type=int, required=True)
+ ap.add_argument("--ram-limit", type=int, default=148928)
ap.add_argument("--upsilon-ram", type=int, required=True)
ap.add_argument("--nwlink", default="nwlink")
a = ap.parse_args()
@@ -134,7 +144,7 @@ def main():
flash = (flash + s[4] - 1) & ~(s[4] - 1)
flash += s[3]
mod = json.load(open(os.path.join(B, "modules", i + ".json")))
- ram = ((mod["data"] + 7) & ~7) + mod["bss"]
+ ram = ((((mod["data"] + 7) & ~7) + mod["bss"] + 7) & ~7) + g.get("heap", 0)
icon = icon_of(i)
if icon:
shutil.copy(icon, os.path.join(O, "icons", i + ".png"))
@@ -144,28 +154,34 @@ def main():
games.append({
"id": i, "index": n, "title": g["title"], "tagline": g["tagline"], "credit": g.get("credit"),
"top": g["top"], "bottom": g["bottom"], "accent": g["accent"],
- "flash": flash, "ram": ram, "default": i in default, "upsilon": i in upsilon,
+ "flash": flash, "ram": ram, "heap": g.get("heap", 0), "default": i in default, "upsilon": i in upsilon,
"roms": bool(g.get("roms")), "xl": bool(g.get("xl")),
"bytes": os.path.getsize(os.path.join(O, "games", i + ".o.gz")),
"icon": bool(icon), "thumb": os.path.exists(thumb)})
# ---- check: the default games, linked from the kit, are NumPlay.nwa on the calculator
- ld_script = os.path.join(tmp, "custom.ld")
- open(ld_script, "w").write(script["head"] + "".join(script["blocks"][i] for i in default) + script["tail"])
+ def link(ids, nwa):
+ ld_script = nwa[:-4] + ".ld"
+ open(ld_script, "w").write(script["head"] + "".join(script["blocks"][i] for i in ids) + script["tail"])
+ subprocess.run(["arm-none-eabi-ld"] + LINK + ["-T", ld_script, local["base.o"], local["arena.o"],
+ local["NumPlay-name.o"], local["NumPlay-icon.o"]] + [local[i] for i in ids] +
+ ["-o", nwa], check=True)
+ subprocess.run(["arm-none-eabi-strip", "--strip-unneeded", nwa], check=True)
+ # only what the installer gives may be left undefined (a game's weak `numplay_launcher`, say,
+ # must find the launcher's; a game's heap is in the arena, its malloc's the launcher's)
+ nm = subprocess.run(["arm-none-eabi-nm", "-u", nwa], capture_output=True, text=True, check=True).stdout
+ loose = [l.split()[-1] for l in nm.splitlines()
+ if not re.match(r"(eadk_|_heap_end$|_data_section_|_bss_section_)", l.split()[-1])
+ and l.split() not in (["w", "__sf"], ["w", "_printf_float"])] # (newlib's own weak hooks)
+ if loose:
+ sys.exit(f"kit: {ids[0] if len(ids) == 1 else 'NumPlay'} leaves undefined: {' '.join(loose)}")
nwa = os.path.join(tmp, "custom.nwa")
- subprocess.run(["arm-none-eabi-ld"] + LINK + ["-T", ld_script, local["base.o"], local["arena.o"],
- local["NumPlay-name.o"], local["NumPlay-icon.o"]] + [local[i] for i in default] +
- ["-o", nwa], check=True)
- subprocess.run(["arm-none-eabi-strip", "--strip-unneeded", nwa], check=True)
- # only what the installer gives may be left undefined (a game's weak `numplay_launcher`, say,
- # must find the launcher's)
- nm = subprocess.run(["arm-none-eabi-nm", "-u", nwa], capture_output=True, text=True, check=True).stdout
- loose = [l.split()[-1] for l in nm.splitlines()
- if not re.match(r"(eadk_|_heap_|_data_section_|_bss_section_|_sbrk$)", l.split()[-1])
- and l.split() not in (["w", "__sf"], ["w", "_printf_float"])] # (newlib's own weak hooks)
- if loose:
- sys.exit(f"kit: left undefined: {' '.join(loose)}")
- ram = 148928
+ link(default, nwa)
+ # a big game calls nothing in base.o but the launcher (KIT_API in the Makefile): linked alone with it
+ for g in games:
+ if g["xl"]:
+ link([g["id"]], os.path.join(tmp, f"xl-{g['id']}.nwa"))
+ ram = a.ram_limit
bins = []
for f in (nwa, os.path.join(B, "NumPlay.nwa")):
b = f + ".bin" if f == nwa else os.path.join(tmp, "make.bin")
@@ -179,8 +195,15 @@ def main():
if not 0 <= runtime < 4096:
sys.exit(f"kit: installed_size says {installed_size(nwa)}, nwlink {len(bins[0])}")
base = len(bins[0]) - sum(g["flash"] for g in games if g["default"])
-
- kit = {"version": a.version, "appSpace": a.app_space, "ram": a.ram, "upsilonRam": a.upsilon_ram,
+ # NumPlay's own RAM before the arena (the installer's few bytes too), as the calculator lays it out
+ elf = os.path.join(tmp, "custom.elf")
+ subprocess.run([a.nwlink, "nwa-elf", nwa, elf, "--ram-start", "0x20000000", "--ram-length", str(ram)],
+ check=True, stdout=subprocess.DEVNULL)
+ nm = subprocess.run(["arm-none-eabi-nm", elf], capture_output=True, text=True, check=True).stdout
+ launcher_ram = next(int(l.split()[0], 16) for l in nm.splitlines() if l.split()[-1] == "np_arena") - 0x20000000
+
+ kit = {"version": a.version, "appSpace": a.app_space, "xlAppSpace": a.xl_app_space, "ram": a.ram,
+ "ramLimit": a.ram_limit, "upsilonRam": a.upsilon_ram, "launcherRam": launcher_ram,
"arena": int(re.search(r"\.space (\d+)", open(os.path.join(B, "gen", "arena.s")).read()).group(1)),
"base": base, "runtime": runtime, "numplay": len(bins[0]), "link": LINK, "variants": variants,
"script": script, "games": games}
diff --git a/tools/lang.py b/tools/lang.py
index 18d2a8a6..6f27108f 100644
--- a/tools/lang.py
+++ b/tools/lang.py
@@ -34,7 +34,8 @@ SKIP = re.compile(r"\.(gif|mp4|mov)$")
def parts():
out = {"launcher": [os.path.join(ROOT, "launcher")]}
for g in json.load(open(os.path.join(ROOT, "games", "games.json"))):
- out[g["id"]] = [os.path.join(ROOT, "games", g["id"])]
+ if g.get("default", True): # (the kit's games are not in the language builds)
+ out[g["id"]] = [os.path.join(ROOT, "games", g["id"])]
return out
@@ -63,6 +64,8 @@ def strings(part):
found.append(s)
if part == "launcher":
for g in json.load(open(os.path.join(ROOT, "games", "games.json"))):
+ if not g.get("default", True):
+ continue
for k in ("title", "tagline", "credit"):
if not g.get(k):
continue
diff --git a/tools/module.ld b/tools/module.ld
index 9983a8a4..a4dbba90 100644
--- a/tools/module.ld
+++ b/tools/module.ld
@@ -1,10 +1,13 @@
/* First step of a NumPlay module: `ld -r -d -T tools/module.ld game.o`.
Merges a game into one code section, one .data and one .bss, and drops what
- the launcher does not need (the game's own name, icon and unwind tables). */
+ the launcher does not need (the game's own name, icon and unwind tables, and
+ its constructor lists: the installer's start code never runs them, so a game
+ on its own doesn't either). */
SECTIONS {
/DISCARD/ : {
*(.rodata.eadk_app_name) *(.rodata.eadk_app_icon) *(.rodata.eadk_api_level)
*(.ARM.exidx*) *(.ARM.extab*) *(.comment) *(.note*) *(.debug*)
+ *(.init_array*) *(.fini_array*) *(.preinit_array*)
}
.text : {
*(.text .text.* .rodata .rodata.* .glue_7 .glue_7t .vfp11_veneer .v4_bx)
diff --git a/tools/release.py b/tools/release.py
index e1c01922..6c16c0cc 100644
--- a/tools/release.py
+++ b/tools/release.py
@@ -91,7 +91,7 @@ def main():
ap.add_argument("--notes", required=True)
ap.add_argument("--build", default="build")
a = ap.parse_args()
- games = json.load(open(os.path.join(ROOT, "games", "games.json")))
+ games = [g for g in json.load(open(os.path.join(ROOT, "games", "games.json"))) if g.get("default", True)]
apps = standalone_names()
count = sum(1 for g in games if g["id"] not in EXTRAS)
extras = " and ".join(g["title"] for g in games if g["id"] in EXTRAS)