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.

NumDrive: 10 KB less RAM, its strip's colours on main's stack (Mason363/NumPlay#48)

Mason Chen9700d8c9d240
diff --git a/games/numdrive/src/main.c b/games/numdrive/src/main.c
index 896aa47e..57f49728 100644
--- a/games/numdrive/src/main.c
+++ b/games/numdrive/src/main.c
@@ -106,6 +106,8 @@ int main(int argc, char **argv) {
#ifdef ARMTEST
environ = argv + 1; /* semihosting has no environment: pass KEY=VALUE arguments */
#endif
+ uint16_t strip[SCREEN_W * STRIP_H] __attribute__((aligned(4)));
+ render_set_buffer(strip);
plat_begin();
if (!world_init()) return plat_end(1);
save_load();
diff --git a/games/numdrive/src/render.c b/games/numdrive/src/render.c
index f62c3c76..719cd629 100644
--- a/games/numdrive/src/render.c
+++ b/games/numdrive/src/render.c
@@ -25,10 +25,12 @@ static vec3 light_to; /* direction towards the light */
static const float AMB[3] = {0.764f, 0.773f, 0.839f};
static const float LEFF[3] = {0.444f, 0.423f, 0.304f};
-static uint16_t cbuf[SCREEN_W * STRIP_H] __attribute__((aligned(4)));
-/* the depth of the strip being drawn: on render_strip's stack (the calculator gives apps 32 KB of it,
- * the game uses a few), not in the RAM that calculator software since 23.2 gives apps (148928 bytes) */
+/* the strip's colours: on main's stack (render_set_buffer); the depth of the strip being drawn: on
+ * render_strip's stack (the calculator gives apps 32 KB of stack apart from their RAM, and some calculator
+ * software gives apps less RAM than 23.2's 148928 bytes) */
+static uint16_t *cbuf;
static uint16_t *zbuf;
+void render_set_buffer(uint16_t *b) { cbuf = b; }
typedef uint32_t __attribute__((may_alias)) u32a;
static int strip_y0, strip_y1; /* current strip rows [y0, y1) */
static int clip_x0, clip_x1;
diff --git a/games/numdrive/src/render.h b/games/numdrive/src/render.h
index 2536973f..36213c2f 100644
--- a/games/numdrive/src/render.h
+++ b/games/numdrive/src/render.h
@@ -27,6 +27,7 @@ void render_frame(void (*post)(uint16_t *px, int y, int n)); /* full screen, pos
void render_prepare(int x0, int x1); /* per-view object culling */
uint16_t *render_strip(int y, int n, int x0, int x1); /* world into the strip buffer */
uint16_t *render_buffer(void);
+void render_set_buffer(uint16_t *b); /* SCREEN_W * STRIP_H colours, on main's stack */
void cam_default(void);
void cam_view(float cx, float cy, float zoom_mul, float roll);
void cam_update(void);