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
optimiseeee meowww
Lily Pitiotc866030f7885
diff --git a/games/pvz/src/data.bin b/games/pvz/src/data.binindex b74a17d4..3d329bbf 100644Binary files a/games/pvz/src/data.bin and b/games/pvz/src/data.bin differdiff --git a/games/pvz/src/gfx.c b/games/pvz/src/gfx.cindex aff7f88b..38b2160e 100644--- a/games/pvz/src/gfx.c+++ b/games/pvz/src/gfx.c@@ -248,11 +248,23 @@ static void decode_row(const uint8_t *p, const uint8_t *e, int bpp, uint8_t *idx}}-/* the start of row r of a frame, and its end */+/* PVZ_SHARED_RLE_ROWS_V1: a marked length 255 carries a 4-byte descriptor.+ * Bits 0..23: absolute offset of an earlier encoded row; bits 24..31: size.+ * Legacy 4-bit frames and all 8-bit frames retain their previous format. */static const uint8_t *row_at(const Frame *f, int bpp, int r, const uint8_t **end) {if (bpp == 4) {const uint8_t *p = f->rows + f->h;- for (int i = 0; i < r; i++) p += f->rows[i];+ if (f->shared_rows) {+ for (int i = 0; i < r; i++) p += f->rows[i] == 255 ? 4 : f->rows[i];+ if (f->rows[r] == 255) {+ uint32_t ref = rd32(p);+ const uint8_t *shared = pvz_bin + (ref & 0x00ffffffu);+ *end = shared + (ref >> 24);+ return shared;+ }+ } else {+ for (int i = 0; i < r; i++) p += f->rows[i];+ }*end = p + f->rows[r];return p;}@@ -302,10 +314,29 @@ static void blit_frame(const Item *it, int fi, const uint16_t *pal, int bpp, intint ya = imax(y0, oy), yb = imin(y1, oy + f.h);if (ya >= yb) return;const uint8_t *e, *p = row_at(&f, bpp, ya - oy, &e);+ /* PVZ_SHARED_RLE_ROWS_V1: streaming cursor avoids quadratic row rescans. */+ const uint8_t *cursor = NULL;+ if (bpp == 4 && f.shared_rows) {+ cursor = f.rows + f.h;+ for (int r = 0; r < ya - oy; r++) cursor += f.rows[r] == 255 ? 4 : f.rows[r];+ }for (int y = ya; y < yb; y++) {int r = y - oy;- if (bpp == 4) e = p + f.rows[r];- else {+ if (bpp == 4) {+ if (f.shared_rows) {+ int length = f.rows[r];+ if (length == 255) {+ uint32_t ref = rd32(cursor);+ p = pvz_bin + (ref & 0x00ffffffu);+ e = p + (ref >> 24);+ cursor += 4;+ } else {+ p = cursor;+ e = p + length;+ cursor += length;+ }+ } else e = p + f.rows[r];+ } else {p = f.rows + rd16(f.rows + 2 * r);e = r + 1 < f.h ? f.rows + rd16(f.rows + 2 * r + 2) : p + 4 * f.w + 8;}@@ -341,7 +372,7 @@ static void blit_frame(const Item *it, int fi, const uint16_t *pal, int bpp, intout[dx] = alpha >= 32 ? col : mix565(col, out[dx], alpha);}}- if (bpp == 4) p = e;+ if (bpp == 4 && !f.shared_rows) p = e;}}diff --git a/games/pvz/src/res.h b/games/pvz/src/res.hindex a48a8687..bd762807 100644--- a/games/pvz/src/res.h+++ b/games/pvz/src/res.h@@ -28,14 +28,18 @@ static inline int anim_frames(int a) { return table(T_ANIMS)[12 * a + 8]; }/* the frame of animation a shown t hundredths of a second into it (looping) */int anim_frame_at(int a, uint32_t t);+/* PVZ_SHARED_RLE_ROWS_V1: bit 31 on a 4-bit frame offset enables row references. */typedef struct {int16_t x, y; /* top-left from the anchor */uint16_t w, h;const uint8_t *rows;+ uint8_t shared_rows;} Frame;static inline Frame frame_info(int f) {const uint8_t *p = table(T_FRAMES) + 12 * f;- return (Frame){rds16(p), rds16(p + 2), rd16(p + 4), rd16(p + 6), pvz_bin + rd32(p + 8)};+ uint32_t off = rd32(p + 8);+ return (Frame){rds16(p), rds16(p + 2), rd16(p + 4), rd16(p + 6),+ pvz_bin + (off & 0x7fffffffu), (uint8_t)(off >> 31)};}/* a palette: its colours (RGB565, aligned) */static inline const uint16_t *pal_colors(int p, int *n) {diff --git a/games/pvz/tools/pack.py b/games/pvz/tools/pack.pyindex 844ce252..55dd68f5 100644--- a/games/pvz/tools/pack.py+++ b/games/pvz/tools/pack.py@@ -457,6 +457,9 @@ class Pack:frame_bpp[fi] = bitsif any(bits not in (4, 8) for bits in frame_bpp):raise ValueError("frame pixel format missing")+ # PVZ_SHARED_RLE_ROWS_V1: rows deduplicated from earlier physical frames.+ # High bit of a 4-bit frame's offset flags 255 row-length markers.+ row_bank = {}shared_4bit = {}for i, (x, y, w, h, data) in enumerate(self.frames):key = (w, h, data) if frame_bpp[i] == 4 else None@@ -469,7 +472,35 @@ class Pack:if len(out) % 2:out.append(0)frame_off = len(out)- out += data+ if frame_bpp[i] == 4:+ if len(data) < h or h + sum(data[:h]) != len(data):+ raise ValueError("bad 4-bit frame row lengths")+ sizes = data[:h]+ can_share_rows = not after_8bit and all(n < 255 for n in sizes)+ lengths = bytearray()+ bodies = bytearray()+ src = h+ has_refs = False+ for n in sizes:+ row = data[src:src + n]+ src += n+ if can_share_rows and n > 4 and row in row_bank:+ ptr = row_bank[row]+ if ptr >= (1 << 24):+ raise ValueError("row reference offset exceeds 24 bits")+ lengths.append(255)+ bodies += struct.pack("<I", (n << 24) | ptr)+ has_refs = True+ else:+ lengths.append(n)+ if n > 4:+ row_bank.setdefault(row, frame_off + h + len(bodies))+ bodies += row+ out += lengths + bodies+ if has_refs:+ frame_off |= 0x80000000+ else:+ out += dataif key is not None:shared_4bit.setdefault(key, frame_off)struct.pack_into("<hhHHI", out, frame_at + 12 * i, x, y, w, h, frame_off)