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
Celeste: pause and the moves can go on any key, as in the game's Keyboard Config
Mason3632988250162d1
diff --git a/games/celeste/Makefile b/games/celeste/Makefileindex 1364c1c0..1be82caa 100644--- a/games/celeste/Makefile+++ b/games/celeste/Makefile@@ -30,7 +30,8 @@ build: $(BUILD_DIR)/celeste.nwa# 148928 on 23.2; checked against the leastcheck: $(BUILD_DIR)/celeste.nwa$(Q) $(NWLINK) nwa-bin --ram-length 148928 $< $(BUILD_DIR)/celeste.bin- @echo "BIN $(BUILD_DIR)/celeste.bin: $$(wc -c < $(BUILD_DIR)/celeste.bin) bytes"+ @n=$$(wc -c < $(BUILD_DIR)/celeste.bin); echo "BIN $(BUILD_DIR)/celeste.bin: $$n bytes ($$((2031616 - n)) to spare)"; \+ [ $$n -le 2031616 ] || { echo "Celeste is bigger than the calculator's app space (2031616 bytes)"; exit 1; }$(BUILD_DIR)/data.o: src/data.S src/data.bin | $(BUILD_DIR)$(Q) $(CC) -c -DDATA_BIN='"src/data.bin"' $< -o $@diff --git a/games/celeste/src/celeste.h b/games/celeste/src/celeste.hindex 592df130..fab3fd59 100644--- a/games/celeste/src/celeste.h+++ b/games/celeste/src/celeste.h@@ -60,9 +60,11 @@ enum {K_ANY = 1 << 15};uint32_t plat_keys(void);-extern uint8_t g_bind[4]; /* jump, dash, grab, talk: EADK keys */+#define BINDS 9+extern uint8_t g_bind[BINDS]; /* jump, dash, grab, talk, pause, left, right, up, down: EADK keys (the arrows+ always move too) */#define KEY_BACK 5 /* (EADK keys) */-#define KEY_BACKSPACE 17 /* pause */+#define KEY_BACKSPACE 17 /* pause, unless it was moved */const char *key_label(int k); /* an EADK key's name, as on the key sheet */void plat_default_binds(void);int plat_key_pressed(void); /* the EADK key that went down this frame, -1 if none */diff --git a/games/celeste/src/level.h b/games/celeste/src/level.hindex 45da584f..e79b4e06 100644--- a/games/celeste/src/level.h+++ b/games/celeste/src/level.h@@ -192,7 +192,9 @@ typedef struct {/* since 1.6.1 */uint8_t cheat_mode; /* CheatMode */uint8_t binds_set; /* 1: bind holds 1.6.1's keys or the player's own (1.6.0's defaults are replaced) */- uint8_t pad_[2];+ /* since 1.15.1 */+ uint8_t bind2[5]; /* pause, left, right, up, down: EADK keys (0: the defaults, in older saves) */+ uint8_t pad_[1];uint32_t checksum;} SaveData;#define OPT_ROOM 16@@ -200,6 +202,7 @@ extern SaveData g_save;#define g_session (g_save.session)void save_load(void);+void save_keep_binds(void); /* g_bind into g_save (save_write writes it) */bool save_write(void); /* false: storage full */bool save_write_quick(void); /* the same, without the copy in celeste_saves.py */ModeStats *save_mode(void); /* the current side's */diff --git a/games/celeste/src/menu.c b/games/celeste/src/menu.cindex e3b96ad7..d9c8c820 100644--- a/games/celeste/src/menu.c+++ b/games/celeste/src/menu.c@@ -206,22 +206,24 @@ void menu_open_main(void) { go(S_MAIN, 0); }/* ---------------------------------------------------------------- the key sheet (as NumBlocks has it) */const char *key_label(int k) {static const char *const names[53] = {- [4] = "OK", [5] = "Back", [6] = "Home", [12] = "shift", [13] = "alpha", [14] = "x,n,t", [15] = "var", [16] = "toolbox",+ [0] = "arrow", [1] = "arrow", [2] = "arrow", [3] = "arrow", [4] = "OK", [5] = "Back", [6] = "Home", [12] = "shift", [13] = "alpha", [14] = "x,n,t", [15] = "var", [16] = "toolbox",[17] = "<x", [18] = "e^x", [19] = "ln", [20] = "log", [21] = "i", [22] = ",", [23] = "x^y", [24] = "sin",[25] = "cos", [26] = "tan", [27] = "pi", [28] = "sqrt", [29] = "x^2", [30] = "7", [31] = "8", [32] = "9",[33] = "(", [34] = ")", [36] = "4", [37] = "5", [38] = "6", [39] = "x", [40] = "/", [42] = "1", [43] = "2",[44] = "3", [45] = "+", [46] = "-", [48] = "0", [49] = ".", [50] = "x10^x", [51] = "ans", [52] = "EXE"};return k < 53 && names[k] ? names[k] : "?";}-static const char *const ACTION_KEYS[4] = {"KEY_CONFIG_JUMP", "KEY_CONFIG_DASH", "KEY_CONFIG_GRAB", "KEY_CONFIG_TALK"};-static const char *action_on(int k) { /* what a key does: its actions, or pause */+static const char *const BIND_KEYS[BINDS] = {"KEY_CONFIG_JUMP", "KEY_CONFIG_DASH", "KEY_CONFIG_GRAB", "KEY_CONFIG_TALK",+ "KEY_CONFIG_PAUSE", "KEY_CONFIG_LEFT", "KEY_CONFIG_RIGHT", "KEY_CONFIG_UP",+ "KEY_CONFIG_DOWN"};+static const uint8_t ARROW[4] = {0, 3, 1, 2}; /* the moves' own arrows (EADK keys): left, right, up, down */+static const char *action_on(int k) { /* what a key does: its actions, pause, a move */static char what[48];- if (k == KEY_BACKSPACE) return ui_str("KEY_CONFIG_PAUSE");what[0] = 0;- for (int a = 0; a < 4; a++)- if (g_bind[a] == k && strlen(what) + strlen(ui_str(ACTION_KEYS[a])) + 3 < sizeof what) {+ for (int a = 0; a < BINDS; a++)+ if (g_bind[a] == k && strlen(what) + strlen(ui_str(BIND_KEYS[a])) + 3 < sizeof what) {if (what[0]) strcat(what, ", ");- strcat(what, ui_str(ACTION_KEYS[a]));+ strcat(what, ui_str(BIND_KEYS[a]));}return what[0] ? what : NULL;}@@ -539,38 +541,54 @@ static void options_update(void) {else go(S_MAIN, 1);}}-static bool bindable(int k) { /* OK, Back and the keys under the arrows but backspace (pause) */- return k == 4 || k == KEY_BACK || (k >= 12 && k <= 51 && k != KEY_BACKSPACE && k != 35 && k != 41 && k != 47);+/* a key for bind a: OK, Back or a key under the arrows; actions may share one, pause and the moves get their own */+static bool bindable(int a, int k) {+ if (a >= 5 && k == ARROW[a - 5]) return true; /* (a move back on its arrow alone) */+ if (!(k == 4 || k == KEY_BACK || (k >= 12 && k <= 51 && k != 35 && k != 41 && k != 47))) return false;+ for (int b = 0; b < BINDS; b++)+ if (b != a && g_bind[b] == k && (a >= 4 || b >= 4)) return false;+ return true;}+/* KeyboardConfigUI's list: MOVEMENT, ACTIONS, then pause under MENU, and Reset to Default; scrolled to the row chosen */+static const int8_t KEY_ROWS[BINDS] = {5, 6, 7, 8, 0, 1, 2, 3, 4};+static float key_row_y(int r) { return 420 + r * ITEM_H + (r >= 4) * 110 + (r >= 8) * 110 + (r >= 9) * 40; }+static void keys_draw(void) {if (M.back == S_MAIN) backdrop();else box(0, 0, 1920, 1080, 0, 178);- say(ui_str("KEY_CONFIG_TITLE"), 960, 200, 0.5f, 0.5f, 2, GRAY, 255);- say(ui_str("KEY_CONFIG_GAMEPLAY"), 960, 330, 0.5f, 0.5f, 0.6f, GRAY, 255);- for (int a = 0; a < 4; a++) menu_item(ui_str(ACTION_KEYS[a]), M.binding == a ? "..." : key_label(g_bind[a]), a, 410 + a * ITEM_H, false);- menu_item(ui_str("KEY_CONFIG_RESET"), NULL, 4, 450 + ITEM_H * 4, false);- if (M.binding >= 0) {+ if (M.binding >= 0) { /* (KeyboardConfigUI: the key asked for, alone in the middle) */char w[48];strcpy(w, ui_str("KEY_CONFIG_CHANGING"));strcat(w, " ");- strcat(w, ui_str(ACTION_KEYS[M.binding]));- say(w, 960, 900, 0.5f, 0.5f, 0.8f, WHITE, 255);+ strcat(w, ui_str(BIND_KEYS[M.binding]));+ say(w, 960, 540, 0.5f, 0.5f, 1, WHITE, 255);+ return;+ }+ float o = fmaxf(0, key_row_y(M.sel) - 900); /* (the row chosen stays on the screen) */+ say(ui_str("KEY_CONFIG_TITLE"), 960, 180 - o, 0.5f, 0.5f, 2, GRAY, 255);+ say(ui_str("KEY_CONFIG_MOVEMENT"), 960, key_row_y(0) - 80 - o, 0.5f, 0.5f, 0.6f, GRAY, 255);+ say(ui_str("KEY_CONFIG_GAMEPLAY"), 960, key_row_y(4) - 80 - o, 0.5f, 0.5f, 0.6f, GRAY, 255);+ say(ui_str("KEY_CONFIG_MENUS"), 960, key_row_y(8) - 80 - o, 0.5f, 0.5f, 0.6f, GRAY, 255);+ for (int r = 0; r < BINDS; r++) {+ int a = KEY_ROWS[r];+ menu_item(ui_str(BIND_KEYS[a]), key_label(g_bind[a]), r, key_row_y(r) - o, false);}+ menu_item(ui_str("KEY_CONFIG_RESET"), NULL, BINDS, key_row_y(BINDS) - o, false);}static void keys_update(void) {if (M.binding >= 0) { /* the next key pressed */int k = plat_key_pressed();if (k < 0) return;- if (bindable(k)) g_bind[M.binding] = (uint8_t)k, memcpy(g_save.bind, g_bind, 4), save_write();+ if (bindable(M.binding, k)) g_bind[M.binding] = (uint8_t)k, save_keep_binds(), save_write();M.binding = -1;btn_consume(&g_in.confirm);return;}int d = dir_pressed(1);- if (d) M.sel = (int8_t)((M.sel + d + 5) % 5);+ if (d) M.sel = (int8_t)((M.sel + d + BINDS + 1) % (BINDS + 1));if (confirm()) {- if (M.sel < 4) M.binding = M.sel, plat_key_pressed();- else plat_default_binds(), memcpy(g_save.bind, g_bind, 4), save_write();+ if (M.sel < BINDS) M.binding = KEY_ROWS[M.sel], plat_key_pressed();+ else plat_default_binds(), save_keep_binds(), save_write();} else if (cancel())go(S_OPTIONS, 0);}diff --git a/games/celeste/src/npc.c b/games/celeste/src/npc.cindex 50c06c16..04396ce1 100644--- a/games/celeste/src/npc.c+++ b/games/celeste/src/npc.c@@ -207,7 +207,7 @@ Ent *hahaha_new(V2 at, const char *ifset) {/* ---------------------------------------------------------------- BirdTutorialGui */Tutorial g_tuts[2]; /* (one bird shows its bubbles at a time) *//* the calculator's keys (Input.GuiButton): a key cap with the name of the key bound */-static const char *key_name(int action) { return key_label(action < 4 ? g_bind[action] : KEY_BACKSPACE); }+static const char *key_name(int action) { return key_label(g_bind[action < 4 ? action : 4]); }/* the width of a control in interface pixels */static float control_width(const GuiControl *c) {switch (c->kind) {diff --git a/games/celeste/src/plat_eadk.c b/games/celeste/src/plat_eadk.cindex 652d91fb..13da9842 100644--- a/games/celeste/src/plat_eadk.c+++ b/games/celeste/src/plat_eadk.c@@ -7,9 +7,11 @@#define KEY(k) ((uint64_t)1 << (k))/* key bindings: one EADK key per game action (settings can change them) */-uint8_t g_bind[4]; /* jump, dash, grab, talk */+uint8_t g_bind[BINDS]; /* jump, dash, grab, talk, pause, left, right, up, down */void plat_default_binds(void) {g_bind[0] = eadk_key_ok, g_bind[1] = eadk_key_back, g_bind[2] = eadk_key_toolbox, g_bind[3] = eadk_key_back;+ g_bind[4] = eadk_key_backspace;+ g_bind[5] = eadk_key_left, g_bind[6] = eadk_key_right, g_bind[7] = eadk_key_up, g_bind[8] = eadk_key_down;}static uint64_t scan, scan_prev;/* the key that went down this frame (an EADK key), -1 if none */@@ -22,17 +24,17 @@ uint32_t plat_keys(void) {uint64_t k = eadk_keyboard_scan();scan_prev = scan, scan = k;uint32_t r = 0;- if (k & KEY(eadk_key_left)) r |= K_LEFT;- if (k & KEY(eadk_key_right)) r |= K_RIGHT;- if (k & KEY(eadk_key_up)) r |= K_UP;- if (k & KEY(eadk_key_down)) r |= K_DOWN;+ if (k & (KEY(eadk_key_left) | KEY(g_bind[5]))) r |= K_LEFT; /* (the arrows, and the keys given to the moves) */+ if (k & (KEY(eadk_key_right) | KEY(g_bind[6]))) r |= K_RIGHT;+ if (k & (KEY(eadk_key_up) | KEY(g_bind[7]))) r |= K_UP;+ if (k & (KEY(eadk_key_down) | KEY(g_bind[8]))) r |= K_DOWN;if (k & KEY(g_bind[0])) r |= K_JUMP;if (k & KEY(g_bind[1])) r |= K_DASH;if (k & KEY(g_bind[2])) r |= K_GRAB;if (k & KEY(g_bind[3])) r |= K_TALK;if (k & (KEY(eadk_key_ok) | KEY(eadk_key_exe))) r |= K_OK;if (k & KEY(eadk_key_back)) r |= K_BACK; /* (menus: cancel) */- if (k & KEY(eadk_key_backspace)) r |= K_PAUSE;+ if (k & KEY(g_bind[4])) r |= K_PAUSE;if (k & KEY(eadk_key_var)) r |= K_JOURNAL; /* (Input.MenuJournal: only the cheat code reads it) */if (k & (KEY(eadk_key_home) | KEY(eadk_key_on_off))) r |= K_HOME;if (k) r |= K_ANY;diff --git a/games/celeste/src/plat_host.c b/games/celeste/src/plat_host.cindex d5862c64..a1dc840b 100644--- a/games/celeste/src/plat_host.c+++ b/games/celeste/src/plat_host.c@@ -8,8 +8,11 @@ uint16_t host_fb[SCREEN_W * SCREEN_H];uint32_t host_time, host_keys;uint32_t plat_keys(void) { return host_keys; }-uint8_t g_bind[4];-void plat_default_binds(void) { g_bind[0] = 4, g_bind[1] = 5, g_bind[2] = 16, g_bind[3] = 5; }+uint8_t g_bind[BINDS];+void plat_default_binds(void) {+ g_bind[0] = 4, g_bind[1] = 5, g_bind[2] = 16, g_bind[3] = 5, g_bind[4] = 17;+ g_bind[5] = 0, g_bind[6] = 3, g_bind[7] = 1, g_bind[8] = 2;+}int plat_key_pressed(void) { return -1; }uint32_t plat_millis(void) { return host_time; }void plat_sleep(uint32_t ms) { host_time += ms; }diff --git a/games/celeste/src/res.c b/games/celeste/src/res.cindex de8ee504..0df8d79c 100644--- a/games/celeste/src/res.c+++ b/games/celeste/src/res.c@@ -1,3 +1,6 @@+#if defined(__GNUC__) && !defined(__clang__)+#pragma GCC optimize("Os") /* (loads and decodes at room changes: smaller over faster) */+#endif/* data.bin: sections, textures, palettes, and the texture cache.** Textures are either "direct" (row RLE in flash, drawn from there) ordiff --git a/games/celeste/src/save.c b/games/celeste/src/save.cindex 10563905..b7e68ca0 100644--- a/games/celeste/src/save.c+++ b/games/celeste/src/save.c@@ -9,10 +9,12 @@#define SAVE_NAME "celeste.sav"#define SAVE_MAGIC 0x43454C53u /* "CELS" */-#define SAVE_VERSION 2-/* 1.6.0's saves (version 1): the same up to its checksum, at the end; what came after goes after it */+#define SAVE_VERSION 3+/* 1.6.0's saves (version 1) and those before 1.15.1 (version 2, without bind2): the same up to their checksum, at+ * their end; what came after goes after it */#define V1_SIZE 1552#define V1_CHECKSUM 1544+#define V2_SIZE 1680SaveData g_save;@@ -26,8 +28,9 @@ static uint32_t checksum(uint32_t n) { /* of the first n bytes */* 1.6.0 had not zero) */static bool whole(uint32_t n) {uint8_t *b = (uint8_t *)&g_save;- uint32_t at = n == sizeof g_save ? offsetof(SaveData, checksum) : n == V1_SIZE ? V1_CHECKSUM : 0, ck;- if (!at || g_save.magic != SAVE_MAGIC || g_save.size != n || g_save.version != (n == V1_SIZE ? 1 : SAVE_VERSION))+ uint32_t at = n == sizeof g_save ? offsetof(SaveData, checksum) : n == V2_SIZE ? V2_SIZE - 4 : n == V1_SIZE ? V1_CHECKSUM : 0, ck;+ if (!at || g_save.magic != SAVE_MAGIC || g_save.size != n ||+ g_save.version != (n == V1_SIZE ? 1 : n == V2_SIZE ? 2 : SAVE_VERSION))return false;memcpy(&ck, b + at, 4);if (ck != checksum(at)) return false;@@ -43,10 +46,15 @@ static void save_new(void) {g_save.version = SAVE_VERSION;g_save.size = sizeof g_save;plat_default_binds();- memcpy(g_save.bind, g_bind, 4);+ save_keep_binds();g_save.binds_set = 1;}+void save_keep_binds(void) { /* g_bind into the save (written with the next save_write) */+ memcpy(g_save.bind, g_bind, 4);+ memcpy(g_save.bind2, g_bind + 4, 5);+}+/* The copy: installing apps from the NumWorks website keeps only Python scripts, so the save is* also kept in one, as a comment line "#>celeste.sav:base64" (the way NumPlay keeps its games'* saves), and comes back from it when the save itself is gone. */@@ -121,8 +129,10 @@ void save_load(void) {if (g_save.bind[a] == KEY_BACKSPACE) g_save.bind[a] = KEY_BACK;g_save.binds_set = 1;}+ plat_default_binds();if (g_save.bind[0] && g_save.bind[1] && g_save.bind[2] && g_save.bind[3]) memcpy(g_bind, g_save.bind, 4);- else plat_default_binds(), memcpy(g_save.bind, g_bind, 4);+ if (g_save.bind2[0]) memcpy(g_bind + 4, g_save.bind2, 5); /* (pause is never 0: older saves keep the defaults) */+ save_keep_binds();}bool save_write(void) {diff --git a/games/celeste/tests/check.py b/games/celeste/tests/check.pyindex f402d613..3d3b4ba5 100644--- a/games/celeste/tests/check.py+++ b/games/celeste/tests/check.py@@ -95,7 +95,19 @@ d = tempfile.mkdtemp(prefix="celeste_check_")run(["--chapter", "0", "--room", "-1", "--nowipe"], 400,"20-21:l,30-31:r,40-41:n,50-51:g,60-61:u,70-71:u,80-81:d,90-91:l,100-101:g,110-111:o", saves=d, what="the cheat code")sav = open(d + "/celeste.sav", "rb").read() if os.path.exists(d + "/celeste.sav") else b""-check(len(sav) == 1680 and sav[1672] == 1 and sav[1066] == 10, "the cheat code did not turn cheat mode on")+check(len(sav) == 1688 and sav[1672] == 1 and sav[1066] == 10, "the cheat code did not turn cheat mode on")++# a save from before 1.15.1 (version 2, without pause and the moves' keys): its keys stay, pause and the moves get+# their defaults+v2 = bytearray(sav[:1674]) + bytes(2)+struct.pack_into("<HH", v2, 4, 2, 1680)+v2[1100:1104] = bytes([36, 5, 16, 5])+v2 += struct.pack("<I", fnv(v2))+d2 = tempfile.mkdtemp(prefix="celeste_check_")+open(d2 + "/celeste.sav", "wb").write(v2)+out2 = run([], 10, saves=d2, what="a 1.15.0 save's keys")+check("keys 36 5 16 5 17 0 3 1 2" in out2, f"a 1.15.0 save's keys did not come back with pause and the moves: {out2[-80:]}")+shutil.rmtree(d2, ignore_errors=True)out = run([], 700, "40-41:o,100-101:o,160-161:o," + ",".join("%d-%d:r" % (f, f + 1) for f in range(200, 360, 30))+ ",380-381:o,420-421:u,440-441:o,470-471:d,490-491:d,510-511:r,540-541:o", saves=d, what="the room picker")check("room 07 " in out and "area 6 mode 0" in out, f"the room picker did not start 6A in room 07: {out[-200:]}")diff --git a/games/celeste/tests/play.c b/games/celeste/tests/play.cindex ededdeac..8e8768f5 100644--- a/games/celeste/tests/play.c+++ b/games/celeste/tests/play.c@@ -197,6 +197,8 @@ int main(int argc, char **argv) {printf("session: chapter %d area %d mode %d deaths %u time %u berries %llx; save berries %llx deaths %u\n",g_session.chapter, g_session.area, g_session.mode, g_session.deaths, g_session.time,(unsigned long long)g_session.berries, (unsigned long long)save_mode()->berries, save_mode()->deaths);- printf("keys %d %d %d %d\n", g_bind[0], g_bind[1], g_bind[2], g_bind[3]);+ printf("keys");+ for (int a = 0; a < BINDS; a++) printf(" %d", g_bind[a]);+ printf("\n");return 0;}