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.

UwU meow mrow purr

Lily Pitiotf730661a3834
diff --git a/games/hillclimb/src/data.bin b/games/hillclimb/src/data.bin
index 308c70f9..7ad6d10d 100644
Binary files a/games/hillclimb/src/data.bin and b/games/hillclimb/src/data.bin differ
diff --git a/games/hillclimb/src/gfx.c b/games/hillclimb/src/gfx.c
index a81d4af5..b5953424 100644
--- a/games/hillclimb/src/gfx.c
+++ b/games/hillclimb/src/gfx.c
@@ -456,6 +456,77 @@ __attribute__((noinline)) static void paint_font_rle_row(const Glyph *g, const u
}
}
+/* HC_MENU_TILES_EXPERIMENT_V1: bilinear sampling uses the same math and palettes. */
+__attribute__((noinline)) static void paint_image_tiled(const Cmd *k, int y0, int y1) {
+ const Img *im = k->image.im;
+ const uint32_t *pal = img_pal(im);
+ const uint8_t *px = img_px(im);
+ int w = im->w, h = im->h;
+ int32_t umax = (w - 1) << 16, vmax = (h - 1) << 16;
+ uint32_t ga = k->alpha;
+ for (int y = y0; y < y1; y++) {
+ int32_t ur = k->image.u0 + k->image.ub * y, vr = k->image.v0 + k->image.vb * y;
+ int x0 = k->x0, x1 = k->x1;
+ span(ur, k->image.ua, 0, umax, &x0, &x1);
+ span(vr, k->image.va, 0, vmax, &x0, &x1);
+ if (x0 >= x1) continue;
+ int32_t u = ur + k->image.ua * x0, v = vr + k->image.va * x0;
+ uint16_t *p = band + (y - by0) * SCREEN_W + x0;
+ for (int x = x0; x < x1; x++, p++, u += k->image.ua, v += k->image.va) {
+ int iu = u >> 16, iv = v >> 16;
+ if ((unsigned)iu > (unsigned)(w - 1) || (unsigned)iv > (unsigned)(h - 1)) continue; /* (rounding at the ends) */
+ int iu1 = iu < w - 1 ? iu + 1 : iu, iv1 = iv < h - 1 ? w : 0;
+ uint32_t c00 = pal[img_tile_index(im, px, iu, iv)];
+ uint32_t c01 = pal[img_tile_index(im, px, iu1, iv)];
+ uint32_t c10 = pal[img_tile_index(im, px, iu, iv + (iv1 ? 1 : 0))];
+ uint32_t c11 = pal[img_tile_index(im, px, iu1, iv + (iv1 ? 1 : 0))];
+ if (!((c00 | c01 | c10 | c11) >> 24)) continue; /* (all four see-through) */
+ uint32_t fu = (u >> 12) & 15, fv = (v >> 12) & 15;
+ uint32_t w11 = fu * fv, w01 = fu * (16 - fv), w10 = (16 - fu) * fv, w00 = 256 - w11 - w01 - w10;
+ uint32_t rb = ((c00 & 0xFF00FF) * w00 + (c01 & 0xFF00FF) * w01 + (c10 & 0xFF00FF) * w10 + (c11 & 0xFF00FF) * w11) >> 8;
+ uint32_t ag = (((c00 >> 8) & 0xFF00FF) * w00 + ((c01 >> 8) & 0xFF00FF) * w01 + ((c10 >> 8) & 0xFF00FF) * w10 +
+ ((c11 >> 8) & 0xFF00FF) * w11) >> 8;
+ if (ga < 255) rb = (rb & 0xFF00FF) * ga >> 8, ag = (ag & 0xFF00FF) * ga >> 8;
+ uint32_t a = (ag >> 16) & 255;
+ if (a < 3) continue;
+ over(p, rb & 255, ag & 255, (rb >> 16) & 255, a);
+ }
+ }
+}
+
+/* HC_MENU_TILES_EXPERIMENT_V1: menu-only tile blitting; original hot blit unchanged. */
+__attribute__((noinline)) static void paint_blit_tiled(const Cmd *k, int y0, int y1) {
+ const Img *im = k->blit.im;
+ const uint32_t *pal = img_pal(im);
+ const uint8_t *px = img_px(im);
+ int x0 = k->x0, x1 = k->x1;
+ uint32_t ga = k->alpha;
+ if (im->flags & IMG_CROPPED) {
+ const uint8_t *c = img_crop(im);
+ if (x0 < k->blit.x + c[0]) x0 = k->blit.x + c[0];
+ if (x1 > k->blit.x + c[0] + c[2]) x1 = k->blit.x + c[0] + c[2];
+ if (y0 < k->blit.y + c[1]) y0 = k->blit.y + c[1];
+ if (y1 > k->blit.y + c[1] + c[3]) y1 = k->blit.y + c[1] + c[3];
+ }
+ if (x0 >= x1 || y0 >= y1) return;
+ bool solid = (im->flags & IMG_OPAQUE) && ga == 255;
+ const uint16_t *pal565 = solid ? img_pal565(im) : NULL;
+ for (int y = y0; y < y1; y++) {
+ uint16_t *p = band + (y - by0) * SCREEN_W;
+ for (int x = x0; x < x1; x++) {
+ uint8_t index = img_tile_index(im, px, x - k->blit.x, y - k->blit.y);
+ if (solid) { p[x] = pal565[index]; continue; }
+ uint32_t c = pal[index], a = c >> 24;
+ if (!a) continue;
+ if (ga < 255) {
+ uint32_t rb = (c & 0xFF00FF) * ga >> 8, g = ((c >> 8) & 0xFF00FF) * ga >> 8;
+ c = (rb & 0xFF00FF) | (g & 0xFF00FF) << 8, a = c >> 24;
+ }
+ over(p + x, c & 255, (c >> 8) & 255, (c >> 16) & 255, a);
+ }
+ }
+}
+
__attribute__((noinline)) static void paint_text(const Cmd *k, int y0, int y1) {
const Font *f = font(k->text.font);
const Glyph *gl = font_glyphs(f);
@@ -612,9 +683,11 @@ void gfx_end(void) {
case C_RRECT: paint_rrect(k, y0, y1); break;
case C_VGRAD: paint_vgrad(k, y0, y1); break;
case C_ROWS: paint_rows(k, y0, y1); break;
- case C_IMAGE: if (k->image.im->flags & IMG_CROPPED) paint_image_cropped(k, y0, y1);
+ case C_IMAGE: if (k->image.im->flags & IMG_TILED) paint_image_tiled(k, y0, y1);
+ else if (k->image.im->flags & IMG_CROPPED) paint_image_cropped(k, y0, y1);
else paint_image(k, y0, y1); break;
- case C_BLIT: if (k->blit.im->flags & IMG_CROPPED) paint_blit_cropped(k, y0, y1);
+ case C_BLIT: if (k->blit.im->flags & IMG_TILED) paint_blit_tiled(k, y0, y1);
+ else if (k->blit.im->flags & IMG_CROPPED) paint_blit_cropped(k, y0, y1);
else paint_blit(k, y0, y1); break;
case C_TEXT: paint_text(k, y0, y1); break;
case C_CIRCLE: paint_circle(k, y0, y1, false); break;
diff --git a/games/hillclimb/src/res.h b/games/hillclimb/src/res.h
index a8706448..f86b8358 100644
--- a/games/hillclimb/src/res.h
+++ b/games/hillclimb/src/res.h
@@ -10,7 +10,7 @@ typedef struct {
int16_t px4, py4; /* its pivot x 4 */
uint16_t pad; /* if cropped, original clear palette index */
} Img;
-enum { IMG_OPAQUE = 1, IMG_CROPPED = 2 };
+enum { IMG_OPAQUE = 1, IMG_CROPPED = 2, IMG_TILED = 4 };
typedef struct {
uint8_t w, h;
@@ -41,6 +41,34 @@ static inline uint8_t img_crop_index(const Img *i, const uint8_t *px, int x, int
if (xx >= c[2] || yy >= c[3]) return (uint8_t)i->pad;
return px[yy * c[2] + xx];
}
+/* HC_MENU_TILES_EXPERIMENT_V1: direct-access 8x8 local palette image indices.
+ * No allocation. Only used for menu-only IMG_TILED records. */
+static inline uint8_t img_tile_index(const Img *i, const uint8_t *px, int x, int y) {
+ unsigned w = i->w, h = i->h;
+ if (i->flags & IMG_CROPPED) {
+ const uint8_t *c = img_crop(i);
+ unsigned xx = (unsigned)(x - c[0]), yy = (unsigned)(y - c[1]);
+ if (xx >= c[2] || yy >= c[3]) return (uint8_t)i->pad;
+ x = (int)xx; y = (int)yy; w = c[2]; h = c[3];
+ }
+ unsigned cols = (w + 7) >> 3, rows = (h + 7) >> 3;
+ unsigned ti = ((unsigned)y >> 3) * cols + ((unsigned)x >> 3);
+ const uint8_t *payload = px + 2 * cols * rows;
+ unsigned off = px[2 * ti] | ((unsigned)px[2 * ti + 1] << 8);
+ const uint8_t *t = payload + off;
+ unsigned n = *t++;
+ unsigned tw = w - ((unsigned)x & ~7u);
+ if (tw > 8) tw = 8;
+ unsigned pos = ((unsigned)y & 7u) * tw + ((unsigned)x & 7u);
+ if (!n) return t[pos];
+ if (n == 1) return t[0];
+ unsigned bits = n == 2 ? 1 : n <= 4 ? 2 : 4;
+ const uint8_t *indices = t + n;
+ unsigned bit = pos * bits;
+ unsigned v = (indices[bit >> 3] >> (8 - bits - (bit & 7u))) & ((1u << bits) - 1u);
+ return t[v];
+}
+
const Font *font(int id);
static inline const Glyph *font_glyphs(const Font *f) { return (const Glyph *)(const void *)(f + 1); }
static inline const uint8_t *font_bits(const Font *f) { return (const uint8_t *)(font_glyphs(f) + f->count); }
diff --git a/games/hillclimb/tools/pack.py b/games/hillclimb/tools/pack.py
index ea20b227..2ea460bd 100644
--- a/games/hillclimb/tools/pack.py
+++ b/games/hillclimb/tools/pack.py
@@ -326,6 +326,55 @@ def _hc_compact_palette_blob(blob):
out += bytes((-len(out)) % 4)
return bytes(out) if len(out) < len(blob) else bytes(blob)
+# HC_MENU_TILES_EXPERIMENT_V1: lossless local-palette 8x8 menu images (16-bit tile offsets).
+def _hc_menu_tile_blob(blob, name):
+ if not (name in {'MENU_BG', 'LOGO', 'LOCK', 'START'} or
+ name.startswith(('STAGE_', 'ICON_', 'UP_', 'THUMB_V', 'THUMB_S'))):
+ return blob
+ w, h, n, flags, _, _, _, _ = struct.unpack_from('<HHHHHhhH', blob)
+ if flags & 4:
+ raise ValueError('tile encoding applied twice')
+ p = 16 + n*4 + (2*n if flags&1 else 0)
+ if flags&2:
+ cx, cy, cw, ch=blob[p:p+4]
+ p+=4
+ else:
+ cw, ch=w,h
+ pixels=blob[p:p+cw*ch]
+ if len(pixels)!=cw*ch:
+ raise ValueError('truncated input for menu tiling')
+ cols=(cw+7)//8;rows=(ch+7)//8
+ offsets=[];tiles=[];length=0
+ for ty in range(rows):
+ for tx in range(cols):
+ tw=min(8,cw-8*tx);th=min(8,ch-8*ty)
+ raw=b''.join(pixels[(8*ty+dy)*cw+8*tx:(8*ty+dy)*cw+8*tx+tw] for dy in range(th))
+ cmap={}; pal=[]; codes=[]
+ for val in raw:
+ if val not in cmap:
+ cmap[val]=len(pal);pal.append(val)
+ codes.append(cmap[val])
+ count=len(pal)
+ if count<=16:
+ bits=0 if count==1 else 1 if count==2 else 2 if count<=4 else 4
+ t=bytearray((count,))+bytearray(pal)
+ if bits:
+ for k in range(0,len(codes),8//bits):
+ v=0
+ for j,c in enumerate(codes[k:k+8//bits]):
+ v|=c<<(8-bits*(j+1))
+ t.append(v)
+ if len(t)>=1+len(raw):t=b'\0'+raw
+ else:
+ t=b'\0'+raw
+ offsets.append(length);tiles.append(bytes(t));length+=len(t)
+ if length>=65536:return blob
+ data=b''.join(struct.pack('<H',o) for o in offsets)+b''.join(tiles)
+ out=bytearray(blob[:p])+data
+ struct.pack_into('<H',out,6,flags|4)
+ while len(out)%4:out.append(0)
+ return bytes(out) if len(blob)-len(out)>=96 and len(out)*100<=len(blob)*96 else blob
+
def sized(im, how, crop):
if crop == "trim":
im = im.crop(im.getbbox())
@@ -581,7 +630,7 @@ def main():
colors[name] = more[0]
vp, art_lines = vehicle_pictures(ref)
pics += vp
- blobs = [_hc_compact_palette_blob(_hc_crop_picture_blob(picture(im, ppm, pv, opaque, colors.get(name, 256)), name))
+ blobs = [_hc_menu_tile_blob(_hc_compact_palette_blob(_hc_crop_picture_blob(picture(im, ppm, pv, opaque, colors.get(name, 256)), name)), name)
for name, im, ppm, pv, opaque in pics]
ttf = os.path.join(ref, "fonts", "Teko.ttf")
fonts = [font_data(ttf, cap, wt, ol) for _, cap, wt, ol in FONTS]