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.

Celeste: 16 KB less RAM, the strip and a frame's draw commands on main's stack (Mason363/NumPlay#48)

Mason Chena68702765c7f
diff --git a/games/celeste/src/celeste.h b/games/celeste/src/celeste.h
index f315e99f..8b4f391a 100644
--- a/games/celeste/src/celeste.h
+++ b/games/celeste/src/celeste.h
@@ -229,6 +229,9 @@ void blit_tex_ex(uint16_t *strip, int sy0, int sy1, uint16_t tex, float x, float
void gfx_camera(float x, float y); /* world position of the view's top left */
extern int g_camx, g_camy; /* floored */
void gfx_hud(bool on); /* following draws ignore the camera */
+#define GFX_STRIP_BYTES 9600 /* the strip, on main's stack on the calculator (gfx_set_memory) */
+#define GFX_CMD_BYTES 7200 /* a frame's draw commands, likewise */
+void gfx_set_memory(void *strip, void *cmd);
void gfx_present_all(void); /* letterbox and full redraw next frame */
void gfx_top_label(const char *s); /* a line of text in the top bar ("": none) */
static inline uint16_t rgb(uint32_t c) { return (uint16_t)(((c >> 8) & 0xF800) | ((c >> 5) & 0x7E0) | ((c >> 3) & 0x1F)); }
diff --git a/games/celeste/src/gfx.c b/games/celeste/src/gfx.c
index 0c7050a0..fa305a4f 100644
--- a/games/celeste/src/gfx.c
+++ b/games/celeste/src/gfx.c
@@ -13,7 +13,14 @@
#define MAX_CMDS 400
#define MAX_AFFINE 56
-uint16_t g_strip[VIEW_W * STRIP_H];
+/* the strip and the frame's draw commands: on main's stack (gfx_set_memory), the calculator gives apps 32 KB
+ * of it apart from their RAM, and some calculator software gives apps less RAM than 23.2's 148928 bytes */
+#ifdef HOST
+static uint16_t strip_mem[VIEW_W * STRIP_H];
+uint16_t *g_strip = strip_mem;
+#else
+uint16_t *g_strip;
+#endif
int g_camx, g_camy;
static float camx, camy;
static bool hud, ui; /* hud: screen coordinates; ui: the interface (drawn after the zoom) */
@@ -41,7 +48,15 @@ typedef struct {
typedef struct { StripFn fn; void *ctx; } Custom;
-static Cmd cmds[MAX_CMDS];
+#ifdef HOST
+static Cmd cmds_mem[MAX_CMDS];
+static Cmd *cmds = cmds_mem;
+#else
+static Cmd *cmds;
+#endif
+_Static_assert(VIEW_W * STRIP_H * sizeof(uint16_t) == GFX_STRIP_BYTES && MAX_CMDS * sizeof(Cmd) == GFX_CMD_BYTES,
+ "celeste.h's GFX_STRIP_BYTES, GFX_CMD_BYTES");
+void gfx_set_memory(void *strip, void *cmd) { g_strip = strip, cmds = cmd; }
static int ncmds;
static Affine affs[MAX_AFFINE];
static int naffs;
diff --git a/games/celeste/src/main.c b/games/celeste/src/main.c
index fe31e46b..0a20f37a 100644
--- a/games/celeste/src/main.c
+++ b/games/celeste/src/main.c
@@ -19,6 +19,8 @@ uint32_t perf_frames __attribute__((used)); /* read by tools/emu.py */
uint32_t perf_updates __attribute__((used));
int main(void) {
+ uint32_t strip[GFX_STRIP_BYTES / 4], cmds[GFX_CMD_BYTES / 4]; /* (gfx.c: here, out of the RAM apps get) */
+ gfx_set_memory(strip, cmds);
plat_begin();
cel_bin = cel_data;
game_init();
diff --git a/games/celeste/src/res.c b/games/celeste/src/res.c
index e8802573..de8ee504 100644
--- a/games/celeste/src/res.c
+++ b/games/celeste/src/res.c
@@ -35,7 +35,7 @@ bool pal_opaque(uint16_t pal) {
/* ---------------------------------------------------------------- LZMA streams */
#define DICT_SIZE 9600 /* (tools/pack.py DICT: the strip, all of it) */
-extern uint16_t g_strip[]; /* gfx.c: the ring buffer borrows the strip */
+extern uint16_t *g_strip; /* gfx.c: the ring buffer borrows the strip */
#define NPROBS (1984 + 768) /* NUM_BASE_PROBS + LZMA_LIT_SIZE << (lc + lp) */
static void pack_info(uint16_t p, const uint8_t **data, uint32_t *comp, uint32_t *raw) {