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
NumBlocks CE: the pixel loops run from the archive
Mason36344b499ac011c
diff --git a/games/numblocks/ce/flash/rsf.s b/games/numblocks/ce/flash/rsf.snew file mode 100644index 00000000..5eb1dba6--- /dev/null+++ b/games/numblocks/ce/flash/rsf.s@@ -0,0 +1,110 @@+; The 3D view's busiest loops again, to run from the archive (appended to NBCETEX): on the CE, code read from the+; flash's cache costs 2 or 3 cycles a byte, from RAM 4. Each at a fixed offset (rs.h: RSF_*), without an absolute+; address of its own (relative jumps only, what it needs handed in registers): they run wherever the appvar is.+ .assume adl=1+ .section .text++; ------------------------------------------------------------------------------------------------- 0: span_plain+; (rs.s's span sets up: de dst, hl the texture page, bc the shade row; other set: hl u, de du, bc dv; ix v;+; iy the end's low byte; ix pushed)+f_span_plain:+ ld a, (de)+ or a, a+ jr nz, .Lp_skip+ exx+ ld a, h+ exx+ ld l, a+ ld a, ixh+ and a, 0xF0+ or a, l+ ld l, a+ ld c, (hl)+ ld a, (bc)+ ld (de), a+.Lp_skip:+ inc de+ exx+ add hl, de+ add ix, bc+ exx+ ld a, e+ cp a, (iy)+ jr nz, f_span_plain+ pop ix+ ret++; ------------------------------------------------------------------------------------------------- 64: span_alpha+ .org 64+f_span_alpha:+ ld a, (de)+ or a, a+ jr nz, .La_skip+ exx+ ld a, h+ exx+ ld l, a+ ld a, ixh+ and a, 0xF0+ or a, l+ ld l, a+ ld a, (hl)+ or a, a+ jr z, .La_skip+ ld c, a+ ld a, (bc)+ ld (de), a+.La_skip:+ inc de+ exx+ add hl, de+ add ix, bc+ exx+ ld a, e+ cp a, (iy)+ jr nz, f_span_alpha+ pop ix+ ret++; ------------------------------------------------------------------------------------------------- 128: double+; b pixels from hl doubled to de (0: c, the row's sky), hl and de after them+ .org 128+f_double:+ ld a, (hl)+ inc hl+ or a, a+ jr nz, .Ld_set+ ld a, c+.Ld_set:+ ld (de), a+ inc de+ ld (de), a+ inc de+ ld a, (hl)+ inc hl+ or a, a+ jr nz, .Ld_set2+ ld a, c+.Ld_set2:+ ld (de), a+ inc de+ ld (de), a+ inc de+ djnz f_double+ ret++; ------------------------------------------------------------------------------------------------- 192: overlay+; b pixels from hl over de where not 0 (the HUD's layer), hl and de after them+ .org 192+f_overlay:+ ld a, (hl)+ inc hl+ or a, a+ jr z, .Lo_skip+ ld (de), a+.Lo_skip:+ inc de+ djnz f_overlay+ ret++ .org 224diff --git a/games/numblocks/ce/makefile b/games/numblocks/ce/makefileindex e4b0c537..db54c671 100644--- a/games/numblocks/ce/makefile+++ b/games/numblocks/ce/makefile@@ -16,3 +16,12 @@ target: bin/NBCEDAT.8xv bin/NBCETEX.8xvbin/%.8xv: gfx/%.bin@mkdir -p binconvbin -j bin -k 8xv -r -n $* -i $< -o $@+# the textures' appvar carries the busiest loops too (flash/rsf.s), run from the archive+obj/rsf.bin: flash/rsf.s+ @mkdir -p obj+ $(AS) -march=ez80+full $< -o obj/rsf.o+ $(OBJCOPY) -O binary -j .text obj/rsf.o $@+bin/NBCETEX.8xv: gfx/NBCETEX.bin obj/rsf.bin+ @mkdir -p bin+ cat $^ > obj/NBCETEX.bin+ convbin -j bin -k 8xv -r -n NBCETEX -i obj/NBCETEX.bin -o $@diff --git a/games/numblocks/ce/src/main.c b/games/numblocks/ce/src/main.cindex 7bec6658..36ca1373 100644--- a/games/numblocks/ce/src/main.c+++ b/games/numblocks/ce/src/main.c@@ -267,6 +267,26 @@ int main(void) {plat_exit();}#endif+#if NB_BENCH == 9+ {+ /* the picture with the archive's loops and without: the same? */+ in_game = true, gui = GUI_NONE;+ extern const uint8_t *rs_flash;+ const uint8_t *fl = rs_flash;+ uint32_t ha = 0, hb = 0;+ for (int pass = 0; pass < 2; pass++) {+ rs_flash = pass ? 0 : fl;+ render_stale = 1;+ render_frame();+ uint32_t h = 0;+ for (unsigned i = 0; i < RW * RH; i++) h = h * 31 + rbuf[i];+ if (pass) hb = h; else ha = h;+ }+ n += sprintf(out + n, "flash %p a %lx b %lx\n", (void *)fl, (unsigned long)ha, (unsigned long)hb);+ plat_save("NBBENCH", out, (unsigned)n, 0, 0);+ plat_exit();+ }+#endif#if NB_BENCH == 7{/* one picture, as the computer build makes it (to compare) */@@ -274,7 +294,7 @@ int main(void) {render_frame();hud_draw();compose(true, true);- for (uint32_t t = plat_ms(); plat_ms() - t < 3000;) plat_frame();+ for (uint32_t t = plat_ms(); plat_ms() - t < 6000;) plat_frame();plat_exit();}#endifdiff --git a/games/numblocks/ce/src/plat_ce.c b/games/numblocks/ce/src/plat_ce.cindex 51e46762..e2457af1 100644--- a/games/numblocks/ce/src/plat_ce.c+++ b/games/numblocks/ce/src/plat_ce.c@@ -15,21 +15,26 @@#include <ti/screen.h>#include <time.h>#include "nb.h"+#include "rs.h"uint8_t *scr = (uint8_t *)lcd_Ram;static uint8_t pal_live[256 * 3];bool vram_lost; /* the screen memory was cleared (a garbage collection): the window must be made again */-static const uint8_t *appvar(const char *name, unsigned size) {+static const uint8_t *appvar(const char *name, unsigned size, unsigned *got) {uint8_t h = ti_Open(name, "r");if (!h) return 0;- const uint8_t *p = ti_GetSize(h) == size ? ti_GetDataPtr(h) : 0;+ *got = ti_GetSize(h);+ const uint8_t *p = *got >= size ? ti_GetDataPtr(h) : 0;ti_Close(h);return p;}static void gfx_reload(void) {- gfx = appvar("NBCEDAT", GFX_SIZE);- texdat = appvar("NBCETEX", TEXDAT_SIZE);+ unsigned n;+ gfx = appvar("NBCEDAT", GFX_SIZE, &n);+ texdat = appvar("NBCETEX", TEXDAT_SIZE, &n);+ /* (the busiest loops' copy, after the tables: run where they are, in the archive) */+ rs_flash = texdat && n >= TEXDAT_SIZE + RSF_SIZE ? texdat + TEXDAT_SIZE : 0;}static void gc_before(void) { gfx_End(); }static void gc_after(void) {diff --git a/games/numblocks/ce/src/rs.c b/games/numblocks/ce/src/rs.cindex e4e5ddb1..75abf361 100644--- a/games/numblocks/ce/src/rs.c+++ b/games/numblocks/ce/src/rs.c@@ -255,6 +255,7 @@ uint8_t RS(rs_cells)(const uint8_t *mask, uint8_t slot, uint8_t up, uint8_t down}#ifndef __ez80__+const uint8_t *rs_flash;int rs_jY[65], rs_jZ[65], rs_jV[65];uint16_t rs_jS[128];uint8_t rs_fog[257];diff --git a/games/numblocks/ce/src/rs.h b/games/numblocks/ce/src/rs.hindex 9634058a..d6cb2169 100644--- a/games/numblocks/ce/src/rs.h+++ b/games/numblocks/ce/src/rs.h@@ -57,6 +57,9 @@ extern const uint16_t *rs_qsqi, *rs_qsqk;extern uint8_t rs_qsx, rs_qsz, rs_qxs0, rs_qzs0, rs_vd;extern int rs_x, rs_z, rs_ci, rs_X0;extern uint8_t rs_xs, rs_zs;+/* the busiest loops' copy in the archive (flash/rsf.s, after NBCETEX's tables; 0: none), RSF_SIZE bytes */+extern const uint8_t *rs_flash;+#define RSF_SIZE 224/* 2^28 / k for k 16..2560 (3 bytes each, from k = 16), and f * 256 / d for d 1..15, f < d ([d * 16 + f]): the* tables rs_poly divides with (in NBCETEX) */extern const uint8_t *rs_recip, *rs_ratio;diff --git a/games/numblocks/ce/src/rs.s b/games/numblocks/ce/src/rs.sindex e324a9c7..02e5cb00 100644--- a/games/numblocks/ce/src/rs.s+++ b/games/numblocks/ce/src/rs.s@@ -15,6 +15,9 @@.equ W_DIR, 20 ; 1 or n - 1.equ W_SIZE, 21.equ RW, 160+ .equ RSF_SPAN_ALPHA, 64 ; (flash/rsf.s's offsets)+ .equ RSF_DOUBLE, 128+ .equ RSF_OVERLAY, 192; ------------------------------------------------------------------------------------------------- rs_setup; void rs_setup(const uint8_t *tex, const uint8_t *cm, uint8_t alpha)@@ -28,12 +31,25 @@ _rs_setup:ld (r_tex), hlld hl, (iy+6)ld (r_cm), hl+ ; the loop: the archive's copy when there is one (flash/rsf.s: faster), else this one+ ld de, (_rs_flash)+ or a, a+ sbc hl, hl+ adc hl, de+ jr z, .Lsetup_ram+ ld a, (iy+9)+ or a, a+ jr z, .Lsetup_set+ ld de, RSF_SPAN_ALPHA+ add hl, de+ jr .Lsetup_set+.Lsetup_ram:ld hl, span_plainld a, (iy+9)or a, a- jr z, .Lsetup_plain+ jr z, .Lsetup_setld hl, span_alpha-.Lsetup_plain:+.Lsetup_set:ld (r_loop), hlret@@ -1103,6 +1119,29 @@ h_px:.equ HUD_W, 187_rs_expand:push ix+ ; the loops: the archive's when there is one (flash/rsf.s), written into the calls below+ ld de, (_rs_flash)+ or a, a+ sbc hl, hl+ adc hl, de+ jr z, .Lex_ram+ ld de, RSF_DOUBLE+ add hl, de+ ld (.Lex_c1 + 1), hl+ ld (.Lex_c2 + 1), hl+ ld de, RSF_OVERLAY - RSF_DOUBLE+ add hl, de+ ld (.Lex_c3 + 1), hl+ ld (.Lex_c4 + 1), hl+ jr .Lex_go+.Lex_ram:+ ld hl, r_double+ ld (.Lex_c1 + 1), hl+ ld (.Lex_c2 + 1), hl+ ld hl, r_overlay+ ld (.Lex_c3 + 1), hl+ ld (.Lex_c4 + 1), hl+.Lex_go:ld iy, 0add iy, spld hl, (iy+15)@@ -1126,19 +1165,9 @@ _rs_expand:cp a, (iy)jr c, .Lex_hudrowld c, (ix+0)- ld b, RW-.Lex_px:- ld a, (hl)- inc hl- or a, a- jr nz, .Lex_set- ld a, c-.Lex_set:- ld (de), a- inc de- ld (de), a- inc de- djnz .Lex_px+ ld b, RW / 2+.Lex_c1:+ call r_doublepush hlld hl, -320add hl, de@@ -1158,19 +1187,9 @@ _rs_expand:push deld de, r_lineld c, (ix+0)- ld b, RW-.Lex_hpx:- ld a, (hl)- inc hl- or a, a- jr nz, .Lex_hset- ld a, c-.Lex_hset:- ld (de), a- inc de- ld (de), a- inc de- djnz .Lex_hpx+ ld b, RW / 2+.Lex_c2:+ call r_doublepush hlld hl, r_lineld de, r_line2@@ -1178,8 +1197,12 @@ _rs_expand:ldirld de, r_line + HUD_Xld hl, (r_hud)+ ld b, HUD_W+.Lex_c3:call r_overlayld de, r_line2 + HUD_X+ ld b, HUD_W+.Lex_c4:call r_overlayld (r_hud), hlpop hl@@ -1191,10 +1214,33 @@ _rs_expand:pop hljr .Lex_next-; HUD_W pixels of the layer (hl) over de, 0 see-through; hl after them+; b pairs of pixels from hl doubled to de (0: c, the row's sky); hl and de after them (flash/rsf.s has it too)+r_double:+ ld a, (hl)+ inc hl+ or a, a+ jr nz, .Lrd_set+ ld a, c+.Lrd_set:+ ld (de), a+ inc de+ ld (de), a+ inc de+ ld a, (hl)+ inc hl+ or a, a+ jr nz, .Lrd_set2+ ld a, c+.Lrd_set2:+ ld (de), a+ inc de+ ld (de), a+ inc de+ djnz r_double+ ret++; b pixels of the layer (hl) over de, 0 see-through; hl and de after themr_overlay:- ld b, HUD_W-.Lov_px:ld a, (hl)inc hlor a, a@@ -1202,7 +1248,7 @@ r_overlay:ld (de), a.Lov_skip:inc de- djnz .Lov_px+ djnz r_overlayret@@ -2342,6 +2388,8 @@ _rs_eys: .db 0_rs_up: .db 0_rs_down: .db 0_rs_jbase: .db 0+ .global _rs_flash+_rs_flash: .d24 0.global _rs_qXi.global _rs_qYi.global _rs_qZidiff --git a/tools/ce_emu/ce_emu.c b/tools/ce_emu/ce_emu.cindex cc556c9c..b2f7f66e 100644--- a/tools/ce_emu/ce_emu.c+++ b/tools/ce_emu/ce_emu.c@@ -139,12 +139,12 @@ static uint64_t cycles_now(void) { return sched_total_cycles(); }uint64_t emu_ms(void) { return now_ms; }bool emu_key_held(int group, int bit) { return group >= 0 && group < 8 && bit >= 0 && bit < 8 && held[group][bit]; }uint32_t emu_key_presses(int group, int bit) { return group >= 0 && group < 8 && bit >= 0 && bit < 8 ? presses[group][bit] : 0; }-/* an OS routine's time: in steps of a millisecond, the scheduler's events between them (timers, the LCD, the- * seconds), as they go on while a calculator runs a long routine such as archiving; charged at once, a second's- * worth left events behind the second and stopped the core (sched_second's assertion) */+/* an OS routine's time; a long one's (from 0.1 s: archiving, a garbage collection) in steps of a millisecond, the+ * scheduler's events between them (timers, the LCD, the seconds), as they go on while a calculator runs it: charged+ * at once, a second's worth left events behind the second and stopped the core (sched_second's assertion) */static bool in_hook;void emu_charge(uint32_t cycles) {- if (!in_hook) {+ if (!in_hook || cycles < 4800000) {debug.cpuCycles += cycles;return;}