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
Retro-Go: your own keys for every button
Mason363cae34c445c98
diff --git a/docs/play.md b/docs/play.mdindex 006de2bb..db78c5af 100644--- a/docs/play.md+++ b/docs/play.md@@ -1067,6 +1067,6 @@ NumVisuals comes on its own, as NumVisuals.nwa, or in a NumPlay of your own from| **Backspace** | Retro-Go's menu: save, load, reset, options || **Home** | Save and quit |-Game Boy, Game Boy Color, NES, Master System and Game Gear games you pick on NumPlay's customizer website. Open a game for New game, or Resume game from one of its 4 save slots. In a game, Backspace opens Retro-Go's menu: Save & Continue, Save & Quit, Load game, Reset and Options, where the picture can be 1x, Fit or Full screen. The cartridges' own saves are kept as well.+Game Boy, Game Boy Color, NES, Master System and Game Gear games you pick on NumPlay's customizer website. Open a game for New game, or Resume game from one of its 4 save slots. In a game, Backspace opens Retro-Go's menu: Save & Continue, Save & Quit, Load game, Reset, Options, where the picture can be 1x, Fit or Full screen, and Controls, where you give any button the key you want: pick it, press **OK**, then its new key. The cartridges' own saves are kept as well.<br clear="right">diff --git a/games/retrogo/README.md b/games/retrogo/README.mdindex 3c49b543..07e95e13 100644--- a/games/retrogo/README.md+++ b/games/retrogo/README.md@@ -42,7 +42,7 @@ You pick the games on NumPlay's customizer website: it puts them inside your Num| Backspace | Options, Controls, About | Retro-Go's menu || Home | Quit | Save and quit |-In 1x on the Game Boy and the Game Gear, the keys are written on the side of the screen. The first time you play, Retro-Go shows them, and Controls in its menu shows them again.+In 1x on the Game Boy and the Game Gear, the keys are written on the side of the screen. The first time you play, Retro-Go shows them, and Controls in its menu shows them again and changes them: pick a button, press OK, then the key you want for it (the D-pad asks for its four). Default keys puts them back.## Good to knowdiff --git a/games/retrogo/lang/fr.txt b/games/retrogo/lang/fr.txtindex 996273b5..809ef846 100644--- a/games/retrogo/lang/fr.txt+++ b/games/retrogo/lang/fr.txt@@ -39,6 +39,17 @@ Options OptionsMenu MenuQuit QuitterHome (saves) Accueil (sauve)+left gauche+up haut+down bas+right droite+toolbox boîte à outils+Up Haut+Down Bas+Left Gauche+Right Droite+Press its new key Appuyez sur sa nouvelle touche+Default keys Touches par défautControls TouchesRetro-Go Retro-GoPort Portagediff --git a/games/retrogo/lang/zh.txt b/games/retrogo/lang/zh.txtindex 3dc50ed2..c33d26b7 100644--- a/games/retrogo/lang/zh.txt+++ b/games/retrogo/lang/zh.txt@@ -39,6 +39,17 @@ Options 选项Menu 菜单Quit 退出Home (saves) 主页(会保存)+left 左+up 上+down 下+right 右+toolbox 工具箱+Up 上+Down 下+Left 左+Right 右+Press its new key 请按它的新按键+Default keys 默认按键Controls 按键Retro-Go Retro-GoPort 移植diff --git a/games/retrogo/src/main.c b/games/retrogo/src/main.cindex cb32b916..5ea81d9b 100644--- a/games/retrogo/src/main.c+++ b/games/retrogo/src/main.c@@ -88,23 +88,59 @@ static struct {uint8_t flags; /* 1: the controls were shown */uint8_t tab, browse;uint8_t cursor[RG_SYS_COUNT];+ uint8_t keys[8]; /* the calculator's key for each of the pad's buttons, in pad_bits' order */} cfg;#define CFG_NAME "retrogo.cfg"+/* ------------------------------------------------------------ the keys */+/* the pad's buttons: the D-pad, then A, B, Select and Start */+static const uint8_t pad_bits[8] = {RG_PAD_UP, RG_PAD_DOWN, RG_PAD_LEFT, RG_PAD_RIGHT,+ RG_PAD_A, RG_PAD_B, RG_PAD_SELECT, RG_PAD_START};+static const uint8_t default_keys[8] = {eadk_key_up, eadk_key_down, eadk_key_left, eadk_key_right,+ eadk_key_ok, eadk_key_back, eadk_key_shift, eadk_key_exe};+/* the calculator's keys by name; NULL for those a button can't have (Home, On/Off and Backspace, Retro-Go's menu) */+static const char *const key_names[eadk_key_exe + 1] = {+ [eadk_key_left] = T("left"), [eadk_key_up] = T("up"), [eadk_key_down] = T("down"), [eadk_key_right] = T("right"),+ [eadk_key_ok] = "OK", [eadk_key_back] = T("Back"), [eadk_key_shift] = T("shift"), [eadk_key_alpha] = "alpha",+ [eadk_key_xnt] = "x,n,t", [eadk_key_var] = "var", [eadk_key_toolbox] = T("toolbox"), [eadk_key_exp] = "e^x",+ [eadk_key_ln] = "ln", [eadk_key_log] = "log", [eadk_key_imaginary] = "i", [eadk_key_comma] = ",",+ [eadk_key_power] = "x^y", [eadk_key_sine] = "sin", [eadk_key_cosine] = "cos", [eadk_key_tangent] = "tan",+ [eadk_key_pi] = "pi", [eadk_key_sqrt] = "sqrt", [eadk_key_square] = "x^2", [eadk_key_seven] = "7",+ [eadk_key_eight] = "8", [eadk_key_nine] = "9", [eadk_key_left_parenthesis] = "(",+ [eadk_key_right_parenthesis] = ")", [eadk_key_four] = "4", [eadk_key_five] = "5", [eadk_key_six] = "6",+ [eadk_key_multiplication] = "*", [eadk_key_division] = "/", [eadk_key_one] = "1", [eadk_key_two] = "2",+ [eadk_key_three] = "3", [eadk_key_plus] = "+", [eadk_key_minus] = "-", [eadk_key_zero] = "0", [eadk_key_dot] = ".",+ [eadk_key_ee] = "x10^x", [eadk_key_ans] = "ans", [eadk_key_exe] = "EXE"};++/* the keys are for buttons, one each */+static bool keys_ok(const uint8_t *k) {+ for (int i = 0; i < 8; i++) {+ if (k[i] > eadk_key_exe || !key_names[k[i]]) return false;+ for (int j = 0; j < i; j++)+ if (k[j] == k[i]) return false;+ }+ return true;+}+static void cfg_defaults(void) {memset(&cfg, 0, sizeof cfg);- cfg.magic = 'R', cfg.version = 1;+ cfg.magic = 'R', cfg.version = 2;cfg.scaling = SCALE_FIT, cfg.speed = 1;cfg.gb_palette = GB_PAL_DMG, cfg.nes_palette = NES_PAL_NTSC;cfg.overscan = 1, cfg.crop_sides = 0, cfg.sprite_limit = 1, cfg.autosave = 10;+ memcpy(cfg.keys, default_keys, sizeof cfg.keys);}static void cfg_load(void) {uint32_t len = 0;const uint8_t *d = np_file_read(CFG_NAME, &len);cfg_defaults();- if (!d || len != sizeof cfg || d[0] != 'R' || d[1] != 1) return;- memcpy(&cfg, d, sizeof cfg);+ /* (version 1: the same, before the keys) */+ if (!d || d[0] != 'R' || (!(len == sizeof cfg && d[1] == 2) && !(len == sizeof cfg - sizeof cfg.keys && d[1] == 1)))+ return;+ memcpy(&cfg, d, len);+ cfg.version = 2;+ if (!keys_ok(cfg.keys)) memcpy(cfg.keys, default_keys, sizeof cfg.keys);/* whatever it holds, settings Retro-Go has */if (cfg.scaling >= SCALE_COUNT) cfg.scaling = SCALE_FIT;if (cfg.speed > 4) cfg.speed = 1;@@ -835,7 +871,16 @@ static const char *button_name(int k) {static const char *const sms[] = {T("D-pad"), "2", "1", NULL, T("Pause")};return k == 4 && sys_now == RG_SYS_GG ? T("Start") : sms[k];}-static const char *const button_keys[] = {T("arrows"), T("OK"), T("Back"), T("shift"), T("EXE")};+/* the D-pad's keys: "arrows", else the four (up, down, left, right) */+static char *dpad_keys(char *b) {+ if (!memcmp(cfg.keys, default_keys, 4)) return strcpy(b, T("arrows"));+ b[0] = 0;+ for (int i = 0; i < 4; i++) {+ if (i) strcat(b, " ");+ strcat(b, key_names[cfg.keys[i]]);+ }+ return b;+}/* the game's picture again, with what is around it */static void borders_scene(void *ctx) {@@ -844,9 +889,10 @@ static void borders_scene(void *ctx) {if (view.x < 72) return;/* (room on the sides: the keys) */const char *keys[7][2];+ char dpad[42];int n = 0;for (int k = 0; k < 5; k++)- if (button_name(k)) keys[n][0] = button_keys[k], keys[n][1] = button_name(k), n++;+ if (button_name(k)) keys[n][0] = k ? key_names[cfg.keys[k + 3]] : dpad_keys(dpad), keys[n][1] = button_name(k), n++;keys[n][0] = T("Backspace"), keys[n++][1] = T("menu");keys[n][0] = T("Home"), keys[n++][1] = T("quit");for (int i = 0; i < n; i++) {@@ -1005,17 +1051,51 @@ static int options_menu(void) {return r;}+/* a button's new key, pressed; false when Backspace, Home or On/Off is (nothing changed) */+static bool ask_key(const char *title, int b) {+ message_box(title, T("Press its new key"));+ wait_release();+ uint64_t k;+ while (!(k = eadk_keyboard_scan())) eadk_timing_msleep(10);+ int key = 0;+ while (!(k >> key & 1)) key++;+ wait_release();+ if (key > eadk_key_exe || !key_names[key]) return false;+ for (int j = 0; j < 8; j++) /* (a key another button had: that one takes this one's) */+ if (j != b && cfg.keys[j] == key) cfg.keys[j] = cfg.keys[b];+ cfg.keys[b] = (uint8_t)key;+ return true;+}+static int key_cb(item_t *it, int ev) {+ int b = (int)it->arg;+ if (ev == EV_ENTER) {+ static const char *const dirs[] = {T("Up"), T("Down"), T("Left"), T("Right")};+ if (b) ask_key(it->label, b);+ else+ for (int i = 0; i < 4 && ask_key(dirs[i], i); i++) {}+ }+ if (b) strcpy(it->value, key_names[cfg.keys[b]]);+ else dpad_keys(it->value);+ return CB_NONE;+}+static int default_keys_cb(item_t *it, int ev) {+ (void)it;+ if (ev == EV_ENTER) memcpy(cfg.keys, default_keys, sizeof cfg.keys);+ return CB_NONE;+}static int controls(void) {- item_t items[8];- static const char *const keys[] = {T("arrows"), "OK", T("Back"), T("shift"), "EXE", T("Backspace"),- T("Home (saves)")};- for (int i = 0; i < 7; i++) {- const char *label = i < 5 ? button_name(i) : i == 5 ? T("Menu") : T("Quit");- items[i] = (item_t){0, label ? label : "", "", label ? IT_MESSAGE : IT_HIDDEN, 1, NULL, 0};- strcpy(items[i].value, keys[i]);+ item_t items[9];+ for (int i = 0; i < 5; i++) {+ const char *label = button_name(i);+ items[i] = (item_t){0, label ? label : "", "", label ? IT_NORMAL : IT_HIDDEN, 1, key_cb, i ? i + 3 : 0};}- items[7] = (item_t)ITEM(1, T("OK"));- return dialog_run(T("Controls"), items, 8, 7);+ items[5] = (item_t){0, T("Menu"), "", IT_MESSAGE, 1, NULL, 0}, strcpy(items[5].value, T("Backspace"));+ items[6] = (item_t){0, T("Quit"), "", IT_MESSAGE, 1, NULL, 0}, strcpy(items[6].value, T("Home (saves)"));+ items[7] = (item_t){0, T("Default keys"), "", IT_NORMAL, 0, default_keys_cb, 0};+ items[8] = (item_t)ITEM(1, T("OK"));+ int r = dialog_run(T("Controls"), items, 9, 8);+ cfg_save();+ return r;}static int about(void) {@@ -1176,14 +1256,8 @@ static int play(const rg_rom_t *r, int slot) {continue;}int pad = 0;- if (k & KEY(eadk_key_up)) pad |= RG_PAD_UP;- if (k & KEY(eadk_key_down)) pad |= RG_PAD_DOWN;- if (k & KEY(eadk_key_left)) pad |= RG_PAD_LEFT;- if (k & KEY(eadk_key_right)) pad |= RG_PAD_RIGHT;- if (k & KEY(eadk_key_ok)) pad |= RG_PAD_A;- if (k & KEY(eadk_key_back)) pad |= RG_PAD_B;- if (k & KEY(eadk_key_shift)) pad |= RG_PAD_SELECT;- if (k & KEY(eadk_key_exe)) pad |= RG_PAD_START;+ for (int i = 0; i < 8; i++)+ if (k & KEY(cfg.keys[i])) pad |= pad_bits[i];uint32_t t0 = millis();bool draw = skip == 0;diff --git a/games/retrogo/tests/test_app.py b/games/retrogo/tests/test_app.pyindex 3a0ae7e7..94a3733b 100644--- a/games/retrogo/tests/test_app.py+++ b/games/retrogo/tests/test_app.py@@ -6,6 +6,9 @@ goes on from where it was. All along: what tests/test_games.py checks (Home andRAM handed back clean, no write to flash, so nothing written into a cartridge read in place, nounaligned multi-word read of the file system, the firmware's RAM untouched, the stack).+Then the keys: a Game Boy cartridge that keeps the buttons it saw, A given 7 and the D-pad 8 2 4 6 in Controls,+and 7 and 8 held in the game: it saw A and Up.+usage: test_app.py [--keep DIR] (builds output/test/retrogo-full.nwa with ROMS set to the three games)"""import argparseimport os@@ -38,6 +41,28 @@ def gb_rom():return bytes(rom)+def pad_rom():+ """MBC1 + RAM + battery: the buttons seen pressed at $A000 (A 1, B 2, Select 4, Start 8), the D-pad at $A001+ (Right 1, Left 2, Up 4, Down 8), each frame."""+ rom = bytearray(0x8000)+ rom[0x100:0x104] = bytes([0x00, 0xC3, 0x50, 0x01]) # nop; jp $0150+ rom[0x134:0x13C] = b"PADS\0\0\0\0"+ rom[0x147], rom[0x148], rom[0x149] = 0x03, 0x00, 0x02+ code = [0x3E, 0x0A, 0xEA, 0x00, 0x00, # ld a,$0A; ld ($0000),a: RAM on+ 0xAF, 0xEA, 0x00, 0xA0, 0xEA, 0x01, 0xA0, # xor a; ld ($A000),a; ld ($A001),a+ 0x21, 0x00, 0xA0, 0x0E, 0x10, # loop: ld hl,$A000; ld c,$10 (the buttons)+ 0x79, 0xE0, 0x00, 0xF0, 0x00, 0xF0, 0x00, # read: ld a,c; ldh ($00),a; ldh a,($00) twice+ 0x2F, 0xE6, 0x0F, 0xB6, 0x77, # cpl; and $0F; or (hl); ld (hl),a+ 0x23, 0x0E, 0x20, # inc hl; ld c,$20 (the D-pad)+ 0x79, 0xE0, 0x00, 0xF0, 0x00, 0xF0, 0x00,+ 0x2F, 0xE6, 0x0F, 0xB6, 0x77,+ 0xF0, 0x44, 0xFE, 0x90, 0x20, 0xFA, # wait for LY = 144+ 0xF0, 0x44, 0xFE, 0x91, 0x20, 0xFA, # then 145+ 0x18, 0xD2] # jr loop+ rom[0x150:0x150 + len(code)] = bytes(code)+ return bytes(rom)++def nes_rom():"""NROM, battery: a 16-bit count at $6000, one more each frame (each vertical blank)."""prg = bytearray(0x4000)@@ -134,6 +159,34 @@ def session(nwa, storage, keys, quit_at, quit_key, problems, tag):return records(open(storage, "rb").read()), c.stack_used()+def keys_test(out, problems):+ rom = os.path.join(out, "Pads.gb")+ open(rom, "wb").write(pad_rom())+ nwa = os.path.join(out, "retrogo-pads.nwa")+ subprocess.run(["make", "-C", game, "output/retrogo-full.nwa", "ROMS=" + rom,+ "NWLINK=" + os.environ.get("NWLINK", "nwlink")], check=True, stdout=subprocess.DEVNULL)+ os.replace(os.path.join(game, "output", "retrogo-full.nwa"), nwa)+ with tempfile.TemporaryDirectory() as d:+ storage = os.path.join(d, "storage.bin")+ # Backspace, Controls (on OK: five up is A), 7; up to the D-pad, 8 2 4 6; Back. Then the game: its tab, the+ # game, a new game, the controls the first time; 7 and 8 held+ t, keys = 600, []+ for k in ["backspace", "down", "ok"] + ["up"] * 5 + ["ok", "7", "up", "ok", "8", "2", "4", "6", "back",+ "ok", "ok", "ok", "ok"]:+ keys.append(f"{t}-{t + 100}:{k}")+ t += 400+ keys += [f"{t + 500}-{t + 1100}:7", f"{t + 1500}-{t + 2100}:8"]+ recs, _ = session(nwa, storage, ",".join(keys), t + 2600, "home", problems, "Keys")+ cfg = recs.get("retrogo.cfg", b"")+ if cfg[19:27] != bytes([31, 43, 36, 38, 30, 5, 12, 52]):+ problems.append(f"Keys: retrogo.cfg holds the keys {list(cfg[19:27])}")+ srm = [n for n in recs if n.endswith(".srm")]+ seen = battery(recs, srm[0]) if srm else -1+ if seen != 0x0401:+ problems.append(f"Keys: the game saw buttons {seen & 255:#x} and the D-pad {seen >> 8:#x}, not A and Up")+ print(f"{'ok ' if not problems else 'FAIL'} Keys: A on 7 and the D-pad on 8 2 4 6, the game saw A and Up")++def main():ap = argparse.ArgumentParser()ap.add_argument("--keep")@@ -181,6 +234,7 @@ def main():problems.append(f"{label}: the count went {count1}, then {count2}")print(f"{'ok ' if not problems else 'FAIL'} {label}: counted {count1} frames, then {count2} after Resume")print(f" stack {stack} bytes at most, records {sorted(recs)}")+ keys_test(out, problems)for p in problems:print(" ", p)sys.exit(1 if problems else 0)diff --git a/tests/test_games.py b/tests/test_games.pyindex a5981f74..3fdde809 100644--- a/tests/test_games.py+++ b/tests/test_games.py@@ -605,8 +605,9 @@ CHECKS = {# a game kept (Easy, the guide read) with the two digits the hints wrote (the digits at 109); then three"sudoku": (lambda v: len(v) == 352 and v[:4] == b"S\1\3\0" and sum(1 <= b <= 9 for b in v[109:190]) == 2,lambda v: v[2] & 1 and sum(1 <= b <= 9 for b in v[109:190]) == 3),- # the scaling (third byte): Full, then 1x- "retrogo": (lambda v: len(v) == 19 and v[:2] == b"R\1" and v[2] == 2, lambda v: v[2] == 0),+ # the scaling (third byte): Full, then 1x; the keys (at 19) the first ones+ "retrogo": (lambda v: len(v) == 27 and v[:2] == b"R\2" and v[2] == 2 and v[19:27] == bytes([1, 2, 0, 3, 4, 5, 12, 52]),+ lambda v: v[2] == 0),}