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.
C calculatorcalculator-gamescasiochesscrossy-roaddrive-madfx-cg50gamesgeometry-dashgraphing-calculatorndlessnumworksnumworks-appsnumworks-calculatornumworks-gamenumworks-gamestetristi-84-plus-ceti-nspire
Doom: runs on the calculator, every level in its RAM
Mason3634ab12b81c43d
diff --git a/games/doom/Makefile b/games/doom/Makefileindex aa1a9030..70fd6c2d 100644--- a/games/doom/Makefile+++ b/games/doom/Makefile@@ -30,13 +30,14 @@ ENGINE_W = -Wno-unused-function -Wno-unused-variable -Wno-unused-but-set-variabl-Wno-int-in-bool-context -Wno-array-bounds -Wno-stringop-overflow -Wno-absolute-value -Wno-dangling-pointerARCH = $(shell $(NWLINK) eadk-cflags-device)-COMMON = $(ARCH) $(INC) -Os -fno-math-errno -fsingle-precision-constant -fno-tree-loop-distribute-patterns \- -ffunction-sections -fdata-sections -fwrapv -flto -fno-fat-lto-objects -fvisibility=internal -DNDEBUG+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)CXXFLAGS = -std=gnu++17 -fno-exceptions -fno-rtti -fno-threadsafe-statics $(COMMON)LDFLAGS = -Wl,--relocatable -nostartfiles --specs=nano.specsLDFLAGS += -Wl,-e,main -Wl,-u,eadk_app_name -Wl,-u,eadk_app_icon -Wl,-u,eadk_api_level-LDFLAGS += -Wl,--gc-sections -flinker-output=nolto-rel+LDFLAGS += -Wl,--gc-sections -flinker-output=nolto-rel $(if $(MAP),-Wl$(comma)-Map$(comma)$(MAP))+comma = ,OBJ = $(patsubst src/%.c,$(BUILD_DIR)/obj/%.o,$(ENGINE) $(NW) src/nw/plat_eadk.c) $(BUILD_DIR)/obj/pd_render.odiff --git a/games/doom/src/doom/d_main.c b/games/doom/src/doom/d_main.cindex a069b8ee..eedb9696 100644--- a/games/doom/src/doom/d_main.c+++ b/games/doom/src/doom/d_main.c@@ -2126,6 +2126,12 @@ void D_DoomMain (void)// the calculator's keys and settings; the moment kept by Home, if there is one, comes backnw_input_init();nw_settings_load();+#ifdef NW_WARP+ autostart = true;+ startepisode = NW_WARP / 10;+ startmap = NW_WARP % 10;+ startskill = sk_hard;+#endifif (nw_resume_ready()){g_load_slot = NW_RESUME_SLOT;diff --git a/games/doom/src/nw/doomconf.h b/games/doom/src/nw/doomconf.hindex 4fc10ae6..4317e7a3 100644--- a/games/doom/src/nw/doomconf.h+++ b/games/doom/src/nw/doomconf.h@@ -78,6 +78,7 @@#define SAVE_COMPRESSED 1#define LOAD_COMPRESSED 1#define NO_USE_ARGS 1+#define NO_FILE_ACCESS 1 /* (saves are Epsilon's files: nw/saves.c) */#define NO_USE_SAVE_CONFIG 1#define NO_USE_FLOAT 1#define USE_VANILLA_KEYBOARD_MAPPING_ONLY 1@@ -109,6 +110,17 @@#ifndef __ASSEMBLER__#include <stdint.h>+#if !defined(HOST)+/* the calculator has no console and no files but Epsilon's: what the engine prints goes nowhere */+#include <stdio.h>+#define printf(...) ((void)0)+#define puts(s) ((void)0)+#define putchar(c) ((void)0)+#define fprintf(f, ...) ((void)0)+#define vfprintf(f, ...) ((void)0)+#define fputs(s, f) ((void)0)+#define fflush(f) ((void)0)+#endiftypedef unsigned int uint;#define __fast_mul(a, b) ((a) * (b))#define panic_unsupported() I_Error("unsupported")diff --git a/games/doom/src/nw/i_system.c b/games/doom/src/nw/i_system.cindex 892eaeba..b4bc5171 100644--- a/games/doom/src/nw/i_system.c+++ b/games/doom/src/nw/i_system.c@@ -1,5 +1,4 @@/* Doom on the calculator: the system (memory, time, errors, quitting). */-#include <setjmp.h>#include <stdarg.h>#include <stdio.h>#include <stdlib.h>@@ -49,6 +48,20 @@ void free(void *p) {void *realloc(void *p, size_t n) {I_Error("realloc");}+/* (and the C library's own, so that nothing else takes from the heap) */+struct _reent;+void *_malloc_r(struct _reent *r, size_t n) { return malloc(n); }+void _free_r(struct _reent *r, void *p) { free(p); }+void *_realloc_r(struct _reent *r, void *p, size_t n) { return realloc(p, n); }+void *_calloc_r(struct _reent *r, size_t a, size_t b) { return calloc(a, b); }+/* (no signals to raise: a division by zero gives 0, an abort is an error) */+int __aeabi_idiv0(int r) { return 0; }+long long __aeabi_ldiv0(long long r) { return 0; }+void abort(void) { I_Error("abort"); }+char *strdup(const char *s) {+ size_t n = strlen(s) + 1;+ return memcpy(malloc(n), s, n);+}#endifboolean drone = false; /* (a network game's watcher: never) */@@ -73,11 +86,11 @@ uint64_t time_us_64(void) { return (uint64_t)plat_millis() * 1000; }/* ------------------------------------------------------------------ the end */boolean nw_quit;-jmp_buf nw_exit;+void *nw_exit[5];void I_Quit(void) {nw_quit = true;- longjmp(nw_exit, 1);+ __builtin_longjmp(nw_exit, 1);}/* An error the game cannot go on from: said on the screen until a key is pressed, then the app quits. */@@ -93,5 +106,5 @@ void I_Error(const char *error, ...) {nw_show_error(msg);}nw_quit = true;- longjmp(nw_exit, 2);+ __builtin_longjmp(nw_exit, 1);}diff --git a/games/doom/src/nw/main.c b/games/doom/src/nw/main.cindex 38914dd0..d256afdb 100644--- a/games/doom/src/nw/main.c+++ b/games/doom/src/nw/main.c@@ -2,14 +2,14 @@** The game runs until Home or On/Off is pressed (the moment is saved, and comes back on the next start),* Quit is chosen in the menu, or an error stops it. */-#include <setjmp.h>#include <stdint.h>#include "doomtype.h"-#include "doom/d_main.h"#include "plat.h"#include "nw.h"+void D_DoomMain(void);+#if !defined(HOST)const char eadk_app_name[] __attribute__((section(".rodata.eadk_app_name"))) = "Doom";const uint32_t eadk_api_level __attribute__((section(".rodata.eadk_api_level"))) = 0;@@ -21,7 +21,7 @@ int nw_main(void);int main(void) {plat_begin();nw_saves_restore();- if (!setjmp(nw_exit)) {+ if (!__builtin_setjmp(nw_exit)) {D_DoomMain();// the main loop ended: Home or On/Offif (nw_home) nw_resume_save();diff --git a/games/doom/src/nw/nw.h b/games/doom/src/nw/nw.hindex a5731960..a5c895cd 100644--- a/games/doom/src/nw/nw.h+++ b/games/doom/src/nw/nw.h@@ -1,15 +1,15 @@/* Doom on the calculator: what the platform's parts say to each other. */#ifndef DOOM_NW_H#define DOOM_NW_H-#include <setjmp.h>#include "doomtype.h"/* the zone on a computer: as much as the calculator's own software leaves */#define NW_HOST_ZONE (60 * 1024)-/* i_system.c: Home, On/Off and Quit end the main loop; I_Error and I_Quit jump back to main */+/* i_system.c: Home, On/Off and Quit end the main loop; I_Error and I_Quit jump back to main+ * (__builtin_setjmp and __builtin_longjmp on nw_exit) */extern boolean nw_quit;-extern jmp_buf nw_exit;+extern void *nw_exit[5];/* i_video.c: an error message on the screen, until a key is pressed */void nw_show_error(const char *msg);diff --git a/games/doom/src/z_zone.c b/games/doom/src/z_zone.cindex 6fd7497a..9535f19f 100644--- a/games/doom/src/z_zone.c+++ b/games/doom/src/z_zone.c@@ -112,6 +112,10 @@ typedef structstatic memzone_t *mainzone;+#if NUMWORKS+// what the zone holds, and the most it held (tests read these)+uint32_t nw_zone_used, nw_zone_peak, nw_zone_size;+#endif#if !NO_ZONE_DEBUGstatic boolean zero_on_free;static boolean scan_on_free;@@ -131,6 +135,9 @@ void Z_Init (void)mainzone = (memzone_t *)I_ZoneBase (&size);mainzone->size = size;+#if NUMWORKS+ nw_zone_size = size;+#endifblock = (memblock_t *)( (byte *)mainzone + sizeof(memzone_t) );// set the entire zone to one free block@@ -229,6 +236,9 @@ void Z_Free (void* ptr)#ifdef USE_MEM_USE_TRACKINGmem_used -= memblock_size(block) + sizeof(memblock_t);#endif+#if NUMWORKS+ if (block->tag != PU_FREE) nw_zone_used -= memblock_size(block);+#endif// mark as freeblock->tag = PU_FREE;@@ -413,6 +423,10 @@ Z_MallocNoUserbase->id = ZONEID;#endif+#if NUMWORKS+ nw_zone_used += memblock_size(base);+ if (nw_zone_used > nw_zone_peak) nw_zone_peak = nw_zone_used;+#endif#ifdef USE_MEM_USE_TRACKINGmem_used += memblock_size(base) + sizeof(memblock_t);static int8_t pants;