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.

NumPlay opens on a game, never wipes a game by mistake, keeps every save

Mason36377335f34eee1
diff --git a/VERSION b/VERSION
index f0bb29e7..3a3cd8cc 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-1.3.0
+1.3.1
diff --git a/launcher/src/flash.c b/launcher/src/flash.c
index 6eeb8054..687a4088 100644
--- a/launcher/src/flash.c
+++ b/launcher/src/flash.c
@@ -130,6 +130,11 @@ void np_finish_pending_uninstalls(void) {
if (!range_ok(a, b)) continue;
uint32_t s0 = (a + SECTOR - 1) & ~(SECTOR - 1), s1 = b & ~(SECTOR - 1);
if (s1 < s0) s0 = s1 = b;
+ /* Only finish what an uninstall started: it clears the first word before
+ * anything else (then, when the block starts a sector, erases it). Any
+ * other value is not ours to wipe. */
+ uint32_t head = *(const volatile uint32_t *)a;
+ if (!(head == 0 || (a == s0 && head == 0xFFFFFFFFu))) continue;
if (zeroed(a, s0) && erased(s0, s1) && zeroed(s1, b)) continue;
np_interrupts_lock();
wipe(a, b, 0);
diff --git a/launcher/src/home.c b/launcher/src/home.c
index 5f8cce67..8bd9ddc0 100644
--- a/launcher/src/home.c
+++ b/launcher/src/home.c
@@ -190,7 +190,9 @@ int np_home(int *selected, bool returning) {
ui_init();
home_t h = {0};
build_items(&h);
- h.sel = h.n - 1;
+ /* the game played last, or else the first game there is: never Settings,
+ * unless it was just open or no game is left */
+ h.sel = 0;
for (int k = 0; k < h.n; k++)
if (h.item[k] == *selected) h.sel = k;
if (*selected == -1) h.sel = h.n - 1;
diff --git a/launcher/src/storage.c b/launcher/src/storage.c
index 107ceffe..0cc22258 100644
--- a/launcher/src/storage.c
+++ b/launcher/src/storage.c
@@ -98,6 +98,10 @@ static bool copy_line(const uint8_t *text, uint32_t n, uint32_t *at, char name[3
return false;
}
+/* Set when a save of the copy could not come back (no room): the copy is then
+ * left as it is, so what it holds is never lost. */
+static bool restore_incomplete;
+
void np_progress_restore(void) {
uint32_t n = 0;
const uint8_t *c = ef_read(COPY_NAME, &n);
@@ -106,14 +110,18 @@ void np_progress_restore(void) {
char name[32];
const uint8_t *data;
uint32_t at = 0, len;
- /* only after an update: while any of these files is here, they are newer */
- while (copy_line(c, n, &at, name, &data, &len))
- if (ef_read(name, &(uint32_t){0})) return;
+ /* Each save that is missing comes back; the ones that are here are newer and
+ * stay. Save by save, so that one file already made (a game played on its
+ * own before NumPlay, after an update) does not keep the others away. */
for (at = 0; copy_line(c, n, &at, name, &data, &len);) {
+ if (ef_read(name, &(uint32_t){0})) continue;
uint32_t size = len / 4 * 3, off = (uint32_t)(data - c);
if (len % 4 || !len) continue;
size -= (data[len - 1] == '=') + (data[len - 2] == '=');
- if (!ef_write(name, NULL, size)) continue; /* appended: the copy stays where it is */
+ if (!ef_write(name, NULL, size)) { /* appended: the copy stays where it is */
+ restore_incomplete = true;
+ continue;
+ }
c = ef_read(COPY_NAME, &n) + 1, n--;
data = c + off;
uint32_t got;
@@ -129,6 +137,7 @@ void np_progress_restore(void) {
}
void np_progress_backup(void) {
+ if (restore_incomplete) return;
const char *name;
uint32_t total = 1 + sizeof copy_head - 1 + 1, len; /* status byte, text, terminating zero */
for (int i = 0; save_name(i, &name); i++)