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
Champion Island: the streets by the blue team's headquarters stay at 30 frames a second
Mason3633ed9af8c9e84
diff --git a/games/championisland/src/game.c b/games/championisland/src/game.cindex 01551ff6..e30f7932 100644--- a/games/championisland/src/game.c+++ b/games/championisland/src/game.c@@ -11,9 +11,11 @@ Input in;Game game;bool game_running = true;-/* the big memory: the background layer (if the scene has one) and the sprite cache. On the calculator, the RAM after- * the game's own (_heap_start to _heap_end), ARENA_BYTES of it at most: software 25.2 and newer gives apps 153676- * bytes of RAM, 23.2 and 24 give 148928 and some builds of it less, and the sprite cache takes what there is */+/* the big memory: the background layer (if the scene has one) and the sprite cache. On the calculator, all the RAM+ * after the game's own (_heap_start to _heap_end): software 25.2 and newer gives apps 153676 bytes of RAM (an arena+ * of 121 KB), 23.2 and 24 give 148928 (116 KB) and some builds of it less (101 KB), and the sprite cache takes what+ * there is. It used to stop at 100000 bytes, which left the island's cache 18 KB on every calculator: by the blue+ * team's headquarters a frame needs more, and its pictures were decoded again and again (Mason363/NumPlay#90) */#ifdef HOSTstatic uint8_t arena_mem[ARENA_BYTES] __attribute__((aligned(4)));#define arena arena_mem@@ -21,10 +23,7 @@ static uint32_t arena_size(void) { return ARENA_BYTES; }#elseextern char _heap_start[], _heap_end[];#define arena ((uint8_t *)(((uintptr_t)_heap_start + 7) & ~(uintptr_t)7))-static uint32_t arena_size(void) {- uint32_t n = (uint32_t)((uintptr_t)_heap_end - (uintptr_t)arena);- return n < ARENA_BYTES ? n : ARENA_BYTES;-}+static uint32_t arena_size(void) { return (uint32_t)((uintptr_t)_heap_end - (uintptr_t)arena); }#endif/* the arena: the scene's state, then its background layer, then the sprite cache */diff --git a/games/championisland/src/game.h b/games/championisland/src/game.hindex ccf74861..b6eef403 100644--- a/games/championisland/src/game.h+++ b/games/championisland/src/game.h@@ -47,8 +47,10 @@ typedef struct {} Game;extern Game game;-/* all the RAM the app has left (tests can ask for another size): the island- * needs its 328 x 244 layer and a cache of 12 KB or more */+/* the host's arena, as the calculators with the least RAM have it (on the+ * calculator, all the RAM the app has left: see game.c; tests can ask for+ * another size): the island needs its 328 x 244 layer and a cache of 12 KB+ * or more */#ifndef ARENA_BYTES#define ARENA_BYTES 100000#endifdiff --git a/games/championisland/src/gfx.c b/games/championisland/src/gfx.cindex 113f89c4..ef920be9 100644--- a/games/championisland/src/gfx.c+++ b/games/championisland/src/gfx.c@@ -1054,6 +1054,19 @@ static uint32_t band_need(uint16_t stream_sp, const bool *dirty) {return most;}+/* a stream is read top down: a sprite drawn more than once is read again+ * for each, one below the other (not in the same band) */+static bool streamable(int big) {+ for (int i = 0; i < nitems; i++) {+ const Item *a = &items[i];+ if (i == big || (a->kind == DI_SPRITE ? a->ref : a->kind == DI_AFFINE ? a->color : NONE16) != items[big].ref) continue;+ if (a->kind != DI_SPRITE || (a->flags & (DF_FLIPY | DF_OPAQUE)) || a->y1 - a->y0 != items[big].y1 - items[big].y0) return false; /* (nor a stretched copy) */+ for (int j = 0; j < nitems; j++)+ if (j != i && items[j].kind == DI_SPRITE && items[j].ref == a->ref && a->y0 < items[j].y1 + BAND && items[j].y0 < a->y1 + BAND) return false;+ }+ return true;+}+#ifdef HOSTint gfx_peak_items, gfx_peak_affs; /* tests: the most a frame used */int gfx_missing; /* tests: items the last frame left for the next (not cached) */@@ -1190,16 +1203,11 @@ void gfx_end(void) {continue;Sprite t;sprite_info(it->ref, &t);- if (t.kind <= 1 && t.rle > bigsz && it->y1 - it->y0 == t.h) { big = i; bigsz = t.rle; } /* (a stream is not stretched) */- }- /* a stream is read top down: a sprite drawn more than once is read- * again for each, one below the other (not in the same band) */- for (int i = 0; big >= 0 && i < nitems; i++) {- const Item *a = &items[i];- if (i == big || (a->kind == DI_SPRITE ? a->ref : a->kind == DI_AFFINE ? a->color : NONE16) != items[big].ref) continue;- if (a->kind != DI_SPRITE || (a->flags & (DF_FLIPY | DF_OPAQUE)) || a->y1 - a->y0 != items[big].y1 - items[big].y0) big = -1; /* (nor a stretched copy) */- for (int j = 0; big >= 0 && j < nitems; j++)- if (j != i && items[j].kind == DI_SPRITE && items[j].ref == a->ref && a->y0 < items[j].y1 + BAND && items[j].y0 < a->y1 + BAND) big = -1;+ /* (a stream is not stretched) the biggest that can stream: a house+ * drawn twice side by side (by the blue team's headquarters) cannot,+ * and when it was the biggest the frame was decoded band by band,+ * its biggest pictures 4 times each */+ if (t.kind <= 1 && t.rle > bigsz && it->y1 - it->y0 == t.h && streamable(i)) { big = i; bigsz = t.rle; }}uint32_t bs = big >= 0 && !stream_already ? (bigsz + 3) & ~3u : 0;/* (a little too much: the last small ones come next frame) */diff --git a/games/championisland/tests/check.py b/games/championisland/tests/check.pyindex f5658401..383de0c7 100644--- a/games/championisland/tests/check.py+++ b/games/championisland/tests/check.py@@ -361,6 +361,17 @@ for place, room, y_max in (("conveniencestore", "convenienceStore1", 990), ("gazcheck(f"the door at {place} stops Lucky and lets him in", stopped and f" scene interior:{room}" in err,f"at {p} after walking up, scenes {[l.split(' scene ')[1] for l in err.splitlines() if ' scene ' in l]}")+# after the ending (the petals redraw the whole view every third frame), the+# streets west of the blue team's headquarters decode little: two of a house+# drawn side by side could not stream as the bands go down, and the frame was+# decoded band by band, its biggest pictures four times each (250 KB a frame:+# Mason363/NumPlay#90 saw 2 frames a second there on an N0120)+_, err, _ = run("overworld@blueteamhq", 120, env={"CI_ENDING": "1", "CI_POS": "-1420,880", "CI_ZFRAME": "1"})+kb = {int(m[1]): float(m[2]) for m in re.finditer(r"^f(\d+) decoded ([\d.]+) KB", err, re.M)}+still = [kb.get(f, 0) for f in range(60, 120)]+check("the streets by the blue team's headquarters decode little after the ending", sum(still) / 60 < 40 and max(still) < 120,+ f"{sum(still) / 60:.0f} KB a frame, at most {max(still):.0f} KB")+if failures:print("\n".join(failures))sys.exit(1)