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.

Celeste: the CE version's menus answer at once

Mason36310c22f3e871b
diff --git a/games/celeste/ce/host/blit.c b/games/celeste/ce/host/blit.c
index a6e2eb76..c2422078 100644
--- a/games/celeste/ce/host/blit.c
+++ b/games/celeste/ce/host/blit.c
@@ -25,7 +25,9 @@ void blit_row(const Cell *cells, unsigned n, uint8_t *dst, unsigned rows) {
void blit_clip(const Cell *cell, uint8_t *dst, unsigned a, unsigned b, unsigned rows) {
if (cell->drawn & rows) tile_rows(cell, dst, a, b, rows);
}
-void blit_copy(uint8_t *dst, const uint8_t *src, unsigned n) { memcpy(dst, src, n); }
+void blit_copy(uint8_t *dst, const uint8_t *src, unsigned n) { /* (forwards a byte at a time, as LDIR) */
+ while (n--) *dst++ = *src++;
+}
void blit_rle(uint8_t *dst, const uint8_t *rows, unsigned nrows) {
for (unsigned r = 0; r < nrows; r++, dst += 320) {
uint8_t *d = dst;
@@ -88,3 +90,6 @@ void blit_rle_clip(uint8_t *dst, const uint8_t *rows, unsigned skip, unsigned nr
}
}
}
+void blit_remap(uint8_t *d, const uint8_t *tab, unsigned n) {
+ for (; n; n--, d++) *d = tab[*d];
+}
diff --git a/games/celeste/ce/src/blit.S b/games/celeste/ce/src/blit.S
index 1e2e17c9..cd5dff84 100644
--- a/games/celeste/ce/src/blit.S
+++ b/games/celeste/ce/src/blit.S
@@ -558,3 +558,23 @@ _blit_rle_clip:
.Lk_done:
pop ix
ret
+
+/* void blit_remap(uint8_t *d, const uint8_t *tab, unsigned n): d[i] = tab[d[i]], tab 256-aligned, 0 < n < 65536 */
+ .global _blit_remap
+ .type _blit_remap, @function
+_blit_remap:
+ ld iy, 0
+ add iy, sp
+ ld hl, (iy + 3)
+ ld de, (iy + 6)
+ ld bc, (iy + 9)
+.Lm_px:
+ ld e, (hl)
+ ld a, (de)
+ ld (hl), a
+ inc hl
+ dec bc
+ ld a, b
+ or a, c
+ jr nz, .Lm_px
+ ret
diff --git a/games/celeste/ce/src/ce.h b/games/celeste/ce/src/ce.h
index b2e56334..289541fb 100644
--- a/games/celeste/ce/src/ce.h
+++ b/games/celeste/ce/src/ce.h
@@ -149,6 +149,7 @@ void blit_copy(uint8_t *dst, const uint8_t *src, unsigned n);
void blit_rect(uint8_t *dst, const uint8_t *src, unsigned w, unsigned h, unsigned src_step);
void blit_rle(uint8_t *dst, const uint8_t *rows, unsigned nrows);
void blit_rle_flip(uint8_t *dst, const uint8_t *rows, unsigned nrows);
+void blit_remap(uint8_t *d, const uint8_t *tab, unsigned n); /* d[i] = tab[d[i]]; tab 256-aligned */
void blit_rle_clip(uint8_t *dst, const uint8_t *rows, unsigned skip, unsigned nrows, unsigned xa, unsigned xb); /* mirrored: dst the top row's rightmost */
void build_cells(const uint8_t *fg, const uint8_t *bg, const TEnt *table, Cell *ofg, Cell *obg, uint8_t *vis, unsigned n);
/* the view's cells (draw.c), kept while the camera stays in the same ones: 41 x 24 */
diff --git a/games/celeste/ce/src/draw.c b/games/celeste/ce/src/draw.c
index d00eceb0..180800fd 100644
--- a/games/celeste/ce/src/draw.c
+++ b/games/celeste/ce/src/draw.c
@@ -236,7 +236,7 @@ void draw_circle_fill(int cx, int cy, int r, uint8_t c) {
draw_rect(cx - w, cy + y, 2 * w + 1, 1, c);
}
}
-void draw_clear_screen(uint8_t c) { memset(g_fb, c, 320 * 240); }
+void draw_clear_screen(uint8_t c) { g_fb[0] = c, blit_copy(g_fb + 1, g_fb, 320 * 240 - 1); } /* (LDIR: the byte along) */
/* ---------------------------------------------------------------- the tile layers */
/* the view's cells: each one's fg and bg tiles (the current room's grid over the other's), and where the background
diff --git a/games/celeste/ce/src/game.c b/games/celeste/ce/src/game.c
index 7150fa92..bea95d16 100644
--- a/games/celeste/ce/src/game.c
+++ b/games/celeste/ce/src/game.c
@@ -245,9 +245,11 @@ static void pause_draw(void) {
text_center(FONT_TITLE, "PAUSED", 160, y - 14, C_GRAY, 0);
for (int i = 0; i < 3; i++) text_center(FONT_BODY, items[i], 160, y + 18 + i * 14, i == sel ? highlight() : C_WHITE, 0);
}
-static void fade_view(void) {
- uint8_t *p = g_fb + VIEW_Y * 320;
- for (unsigned n = 320 * VIEW_H; n; n--, p++) *p = g_remap_fade[*p];
+static void fade_view(void) { /* (the table copied to a 256-aligned place in the scratch RAM first) */
+ extern uint8_t *g_scratch;
+ uint8_t *tab = (uint8_t *)(((uintptr_t)g_scratch + 255) & ~(uintptr_t)255);
+ memcpy(tab, g_remap_fade, 256);
+ blit_remap(g_fb + VIEW_Y * 320, tab, 320 * VIEW_H);
}
void game_draw(void) {
static int paused; /* (frames drawn paused: the black goes into both buffers) */
diff --git a/games/celeste/ce/src/text.c b/games/celeste/ce/src/text.c
index 96a540c9..9f77c8a1 100644
--- a/games/celeste/ce/src/text.c
+++ b/games/celeste/ce/src/text.c
@@ -54,15 +54,17 @@ void text_draw(int font, const char *s, int x, int y, uint32_t rgb, uint32_t und
const uint8_t *g = glyph(f, c);
int gx = ((pen + 2) >> 2) + (int8_t)g[0], gy = y + (int8_t)g[1], w = g[2], h = g[3], stride = (w + 3) >> 2;
const uint8_t *bits = f + R16(g + 5);
- for (int r = 0; r < h; r++, bits += stride) {
- int sy = gy + r;
- if ((unsigned)sy >= 240) continue;
- uint8_t *d = g_fb + sy * 320;
- for (int i = 0; i < w; i++) {
- int a = bits[i >> 2] >> ((i & 3) * 2) & 3, sx = gx + i;
- if (a && (unsigned)sx < 320) d[sx] = shade[a];
+ if (gx < 0 || gx + w > 320 || gy < 0 || gy + h > 240) continue; /* (none of it, unless all of it fits) */
+ uint8_t *row = g_fb + gy * 320 + gx;
+ for (int r = 0; r < h; r++, bits += stride, row += 320) {
+ uint8_t *d = row;
+ for (int i = 0; i < stride; i++) { /* four pixels a byte, the first in its low bits */
+ uint8_t v = bits[i];
+ for (int k = 0; k < 4; k++, d++, v >>= 2)
+ if (v & 3) *d = shade[v & 3];
}
}
+ plat_poll(); /* (menus take a while to draw: a quick press still counts) */
pen += g[4];
if (printable((uint8_t)s[1])) pen += kern(f, c, (uint8_t)s[1]);
}