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.

add chrome dino testing

Lily Pitiot231dd6078211
diff --git a/.github/workflows/dinorun-quick.yml b/.github/workflows/dinorun-quick.yml
new file mode 100644
index 00000000..5697b5c5
--- /dev/null
+++ b/.github/workflows/dinorun-quick.yml
@@ -0,0 +1,44 @@
+name: Dino Run (quick test build)
+
+# Fast build for the standalone game only. No release publishing.
+# Works on any feature branch when the new files are pushed.
+on:
+ push:
+ paths:
+ - 'games/dinorun/**'
+ - '.github/workflows/dinorun-quick.yml'
+ workflow_dispatch:
+
+permissions:
+ contents: read
+
+jobs:
+ dino:
+ runs-on: ubuntu-24.04
+ steps:
+ - uses: actions/checkout@v4
+
+ - name: ARM compiler
+ run: |
+ v=15.2.1-1.1
+ curl -fsSL "https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases/download/v$v/xpack-arm-none-eabi-gcc-$v-linux-x64.tar.gz" | tar -xz -C "$RUNNER_TEMP"
+ echo "$RUNNER_TEMP/xpack-arm-none-eabi-gcc-$v/bin" >> "$GITHUB_PATH"
+
+ - uses: actions/setup-node@v4
+ with:
+ node-version: 20
+
+ - name: NumWorks compiler helpers
+ run: npm install -g [email protected]
+
+ - name: Host unit tests
+ run: make -C games/dinorun host-test
+
+ - name: Build native calculator app
+ run: make -C games/dinorun check NWLINK=nwlink
+
+ - uses: actions/upload-artifact@v4
+ with:
+ name: DinoRun-nwa
+ path: games/dinorun/output/dinorun.nwa
+ if-no-files-found: error
diff --git a/games/dinorun/Makefile b/games/dinorun/Makefile
new file mode 100644
index 00000000..981d0605
--- /dev/null
+++ b/games/dinorun/Makefile
@@ -0,0 +1,45 @@
+# Dino Run: stand-alone app; NumPlay module target is ready when there's flash room.
+Q ?= @
+CC = arm-none-eabi-gcc
+NWLINK ?= npx --yes -- [email protected]
+OUT = output
+SRC = src/main.c
+HEADERS = ../common/epsilon_app.h ../common/epsilon_files.h
+FLAGS = -std=c11 $(shell $(NWLINK) eadk-cflags-device) -Os -Wall -Wextra -Wno-unused-parameter \
+ -fno-math-errno -fno-tree-loop-distribute-patterns -flto -fno-fat-lto-objects \
+ -fwhole-program -fvisibility=internal
+LINK = -Wl,--relocatable -nostartfiles --specs=nano.specs -Wl,-e,main \
+ -Wl,-u,eadk_app_name -Wl,-u,eadk_app_icon -Wl,-u,eadk_api_level \
+ -Wl,--gc-sections -flinker-output=nolto-rel
+
+.PHONY: build check clean module sim-module host-test
+build: $(OUT)/dinorun.nwa
+$(OUT):
+ $(Q) mkdir -p $(OUT)
+$(OUT)/icon.o: src/icon.png | $(OUT)
+ $(Q) $(NWLINK) png-icon-o $< $@
+$(OUT)/dinorun.nwa: $(SRC) $(HEADERS) $(OUT)/icon.o
+ $(Q) $(CC) $(FLAGS) $(LINK) $(SRC) $(OUT)/icon.o -o $@
+ $(Q) arm-none-eabi-strip --strip-unneeded $@
+check: $(OUT)/dinorun.nwa
+ $(Q) $(NWLINK) nwa-bin $< $(OUT)/dinorun.bin
+ @echo "Dino Run installable size: $$(wc -c < $(OUT)/dinorun.bin) bytes"
+clean:
+ $(Q) rm -rf $(OUT)
+
+# NumPlay's module linker can use this when the combined app has enough flash space.
+module: $(OUT)/module.o
+$(OUT)/module.o: $(SRC) $(HEADERS) | $(OUT)
+ $(Q) $(CC) $(FLAGS) -Wl,--relocatable -nostartfiles -nostdlib -Wl,-e,main \
+ -flinker-output=nolto-rel $(SRC) -o $@
+sim-module: $(OUT)/sim-module.o
+$(OUT)/sim-module.o: $(SRC) $(HEADERS) | $(OUT)
+ $(Q) mkdir -p $(OUT)/sim
+ $(Q) cc -std=c11 -O2 -fPIC $(shell $(NWLINK) eadk-cflags-simulator) \
+ -Dmain=np_dinorun_main -c $(SRC) -o $(OUT)/sim/main.o
+ $(Q) ld -r $(OUT)/sim/main.o -exported_symbol _np_dinorun_main -o $@
+
+host-test:
+ cc -std=c11 -O2 -Wall -Wextra -Wno-unused-parameter -DHOST -DPLATFORM_DEVICE=0 \
+ -Itests tests/test_dino.c -o /tmp/dinorun-host-test
+ /tmp/dinorun-host-test
diff --git a/games/dinorun/README.md b/games/dinorun/README.md
new file mode 100644
index 00000000..7cd627ab
--- /dev/null
+++ b/games/dinorun/README.md
@@ -0,0 +1,45 @@
+# Dino Run — NumWorks native C game (prototype)
+
+An original endless runner inspired by offline dinosaur games, including the Chrome Dino game from Lily's NumWorks Python collection. The **C source code, pixel drawings and assets are independently written**; the Python version's code and sprites have not been copied. Unofficial, not affiliated with Google.
+
+![Gameplay screenshot](docs/shot.png)
+
+## Controls
+
+| Key | Action |
+|---|---|
+| **OK**, EXE, Up / 8 | Jump / start / restart |
+| **Down** / 2 (hold) | Duck (and fall faster mid-air) |
+| **Back** or Backspace | Pause / resume |
+| **SHIFT** at title | Help screen |
+| **HOME** | Exit back to calculator |
+
+The game features cacti, flying dinosaurs/birds, gradually increasing speed, day/night changes, high-score storage (`dinorun.sav`) and instant restart.
+
+## Build as an individual NumWorks app
+
+Requires the same EADK GCC + `nwlink` environment as the rest of NumPlay.
+
+```sh
+make -C games/dinorun check
+```
+
+Result: `games/dinorun/output/dinorun.nwa`.
+
+You can also use `.github/workflows/dinorun-quick.yml` without installing build tools on Windows. It triggers on a push to a branch with changes in `games/dinorun/**`, runs a simple host test, builds the app and uploads **DinoRun-nwa**.
+
+Install the `.nwa` using https://my.numworks.com/apps (Chrome/Edge). **NumPlay is already close to the calculator's entire app-space budget, so installing Dino Run separately may replace your existing NumPlay installation. Back up scripts and saves and reinstall NumPlay afterward.**
+
+## Integration into the combined NumPlay launcher
+
+`module` and `sim-module` targets are already included to support future integration. At present, **Dino Run is intentionally not added to `games/games.json`**, because the full NumPlay app was already close to the 2 MB flash cap. Adding the manifest entry now would make the full build fail unless enough flash is freed. See `INTEGRATION.md` in the standalone patch.
+
+## Development checks
+
+```sh
+make -C games/dinorun host-test
+```
+
+Host tests cover jump motion, ducking, collision, game over, restart, and rendering. They do **not** replace on-calculator testing or NumPlay's ARM emulator suite.
+
+The game is made as an independently coded fan-style runner, with a deliberately small screen buffer (16 RGB565 rows) to avoid allocating a full 320x240 framebuffer.
diff --git a/games/dinorun/docs/game.png b/games/dinorun/docs/game.png
new file mode 100644
index 00000000..ae9ba62b
Binary files /dev/null and b/games/dinorun/docs/game.png differ
diff --git a/games/dinorun/docs/shot.png b/games/dinorun/docs/shot.png
new file mode 100644
index 00000000..ae9ba62b
Binary files /dev/null and b/games/dinorun/docs/shot.png differ
diff --git a/games/dinorun/docs/title.png b/games/dinorun/docs/title.png
new file mode 100644
index 00000000..be379b08
Binary files /dev/null and b/games/dinorun/docs/title.png differ
diff --git a/games/dinorun/src/icon.png b/games/dinorun/src/icon.png
new file mode 100644
index 00000000..4fd2ab4a
Binary files /dev/null and b/games/dinorun/src/icon.png differ
diff --git a/games/dinorun/src/main.c b/games/dinorun/src/main.c
new file mode 100644
index 00000000..6458cac9
--- /dev/null
+++ b/games/dinorun/src/main.c
@@ -0,0 +1,297 @@
+/* Dino Run — an original native endless runner for NumWorks / NumPlay.
+ * Gameplay inspiration: offline dinosaur runners; no third-party source/sprites copied.
+ * 320x240, 30 fps, RGB565; draws 16-row bands rather than using a full frame buffer.
+ * Keyboard: OK/Up/Exe jump, Down duck, Back/Backspace pause, Home exit.
+ */
+#include <eadk.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include "../../common/epsilon_app.h"
+#include "../../common/epsilon_files.h"
+
+#ifdef __ELF__
+const char eadk_app_name[] __attribute__((section(".rodata.eadk_app_name"))) = "Dino Run";
+const uint32_t eadk_api_level __attribute__((section(".rodata.eadk_api_level"))) = 0;
+#endif
+
+#define W 320
+#define H 240
+#define GROUND 194
+#define DX 34
+#define DY (GROUND - 40)
+#define BAND 16
+#define KEY(k) (1ull << (k))
+#define RGB(c) (uint16_t)((((c) >> 8) & 0xF800u) | (((c) >> 5) & 0x07E0u) | (((c) >> 3) & 0x1Fu))
+#define JUMP (KEY(eadk_key_ok) | KEY(eadk_key_exe) | KEY(eadk_key_up) | KEY(eadk_key_eight))
+#define DUCK (KEY(eadk_key_down) | KEY(eadk_key_two))
+#define PAUSE (KEY(eadk_key_back) | KEY(eadk_key_backspace))
+#define SAVE_NAME "dinorun.sav"
+
+typedef uint16_t color;
+typedef struct { int16_t x, y; uint8_t w, h, kind; } obstacle;
+enum { TITLE, HELP, PLAY, PAUSED, DEAD };
+enum { CACTUS, LARGE_CACTUS, BIRD };
+
+static color pixels[W * BAND];
+static int band_y, scene;
+static color bg, ink, faint;
+static obstacle obstacles[8];
+static int count, dino_y, dino_vy, duck, score, high_score, speed, spawn_left;
+static uint32_t rng=0xA319F4B5u, ticks, distance_px;
+static bool new_record;
+
+static uint32_t random32(void) {
+ rng ^= rng << 13; rng ^= rng >> 17; rng ^= rng << 5;
+ return rng;
+}
+static int randint(int n) { return (int)(random32() % (uint32_t)n); }
+
+static void rect(int x, int y, int w, int h, color c) {
+ if (w <= 0 || h <= 0) return;
+ int x0=x<0?0:x, x1=x+w>W?W:x+w;
+ int y0=y<band_y?band_y:y, y1=y+h>band_y+BAND?band_y+BAND:y+h;
+ if (x0 >= x1 || y0 >= y1) return;
+ for (int yy=y0; yy<y1; ++yy) {
+ color *p=pixels + (yy-band_y)*W + x0;
+ for (int xx=x0; xx<x1; ++xx) *p++=c;
+ }
+}
+
+/* Compact 5 x 7 uppercase font. Each byte holds one row's five bits. */
+typedef struct { char ch; uint8_t row[7]; } glyph;
+static const glyph FONT[] = {
+ {'A',{14,17,17,31,17,17,17}}, {'B',{30,17,17,30,17,17,30}},
+ {'C',{14,17,16,16,16,17,14}}, {'D',{30,17,17,17,17,17,30}},
+ {'E',{31,16,16,30,16,16,31}}, {'F',{31,16,16,30,16,16,16}},
+ {'G',{14,17,16,23,17,17,14}}, {'H',{17,17,17,31,17,17,17}},
+ {'I',{31,4,4,4,4,4,31}}, {'J',{7,2,2,2,18,18,12}},
+ {'K',{17,18,20,24,20,18,17}}, {'L',{16,16,16,16,16,16,31}},
+ {'M',{17,27,21,21,17,17,17}}, {'N',{17,25,21,19,17,17,17}},
+ {'O',{14,17,17,17,17,17,14}}, {'P',{30,17,17,30,16,16,16}},
+ {'Q',{14,17,17,17,21,18,13}}, {'R',{30,17,17,30,20,18,17}},
+ {'S',{15,16,16,14,1,1,30}}, {'T',{31,4,4,4,4,4,4}},
+ {'U',{17,17,17,17,17,17,14}}, {'V',{17,17,17,17,17,10,4}},
+ {'W',{17,17,17,21,21,21,10}}, {'X',{17,17,10,4,10,17,17}},
+ {'Y',{17,17,10,4,4,4,4}}, {'Z',{31,1,2,4,8,16,31}},
+ {'0',{14,17,19,21,25,17,14}}, {'1',{4,12,4,4,4,4,14}},
+ {'2',{14,17,1,2,4,8,31}}, {'3',{30,1,1,14,1,1,30}},
+ {'4',{2,6,10,18,31,2,2}}, {'5',{31,16,30,1,1,17,14}},
+ {'6',{6,8,16,30,17,17,14}}, {'7',{31,1,2,4,8,8,8}},
+ {'8',{14,17,17,14,17,17,14}}, {'9',{14,17,17,15,1,2,12}},
+ {':',{0,4,4,0,4,4,0}}, {'/',{1,1,2,4,8,16,16}},
+ {'!',{4,4,4,4,4,0,4}}, {'-',{0,0,0,31,0,0,0}},
+ {'+',{0,4,4,31,4,4,0}}, {'.',{0,0,0,0,0,12,12}}
+};
+static const uint8_t *glyph_rows(char c) {
+ for (unsigned i=0;i<sizeof FONT/sizeof FONT[0];i++) if(FONT[i].ch==c) return FONT[i].row;
+ return 0;
+}
+static int text_width(const char *s, int scale) { int n=0; while (*s++) n++; return n*6*scale; }
+static void text_at(int x,int y,const char *s,int scale,color c) {
+ for (;*s;s++,x+=6*scale) {
+ const uint8_t *r=glyph_rows(*s);
+ if (!r) continue;
+ for (int yy=0;yy<7;yy++) for (int xx=0;xx<5;xx++)
+ if (r[yy] & (1u << (4-xx))) rect(x+xx*scale,y+yy*scale,scale,scale,c);
+ }
+}
+static void centered(int y,const char *s,int scale,color c) { text_at((W-text_width(s,scale))/2,y,s,scale,c); }
+static void number(int x,int y,unsigned n,int min_digits,int scale,color c) {
+ char s[12]; int i=0;
+ do {s[i++]=(char)('0'+n%10);n/=10;} while (n && i<10);
+ while(i<min_digits && i<10) s[i++]='0';
+ for(int j=0;j<i/2;j++) {char t=s[j];s[j]=s[i-1-j];s[i-1-j]=t;}
+ s[i]=0;text_at(x,y,s,scale,c);
+}
+
+static void dino(int x,int y,bool crouch,int step) {
+ if (crouch) {
+ rect(x+7,y+15,24,12,ink); rect(x+20,y+10,16,10,ink);
+ rect(x+32,y+17,7,5,ink); rect(x+3,y+19,9,4,ink);
+ rect(x+25,y+13,2,2,bg); rect(x+10,y+27,7,3,ink); rect(x+26,y+27,7,3,ink);
+ } else {
+ rect(x+15,y+1,17,14,ink); rect(x+23,y+13,14,5,ink);
+ rect(x+17,y+17,14,5,ink);rect(x+10,y+15,16,21,ink);
+ rect(x+5,y+22,10,6,ink); rect(x+1,y+19,5,4,ink);
+ rect(x+22,y+22,9,3,ink);rect(x+23,y+26,4,4,ink);
+ rect(x+24,y+4,3,3,bg);rect(x+30,y+15,7,2,bg);
+ if (step&1) {rect(x+12,y+35,5,6,ink);rect(x+25,y+34,6,3,ink);}
+ else {rect(x+12,y+34,7,3,ink);rect(x+25,y+35,5,6,ink);}
+ }
+}
+static void cactus(obstacle *o) {
+ int x=o->x,y=o->y;
+ if (o->kind==LARGE_CACTUS) {
+ rect(x+8,y,10,o->h,ink);rect(x+4,y+12,6,6,ink);
+ rect(x,y+5,5,15,ink);rect(x+16,y+17,7,5,ink);
+ rect(x+19,y+8,5,18,ink);
+ } else {
+ rect(x+6,y,7,o->h,ink);rect(x+2,y+13,5,5,ink);
+ rect(x,y+7,4,12,ink);rect(x+12,y+18,5,4,ink);
+ rect(x+15,y+11,4,13,ink);
+ }
+}
+static void bird(obstacle *o) {
+ int x=o->x,y=o->y;
+ rect(x+6,y+7,20,7,ink);rect(x+25,y+9,7,3,ink);rect(x+3,y+10,5,3,ink);
+ rect(x+22,y+8,2,2,bg);
+ if ((ticks/7)&1) {rect(x+13,y,8,8,ink);rect(x+9,y+3,5,4,ink);}
+ else {rect(x+11,y+13,10,7,ink);rect(x+8,y+16,5,4,ink);}
+}
+static void scenery(void) {
+ rect(0,GROUND+1,W,2,ink);
+ /* Daytime clouds; tiny stars replace them in the night. */
+ if ((score/300)&1) {
+ for(int i=0;i<23;i++) {
+ int x=(i*101+23 - (int)(distance_px/8)%570 +570)%570-80;
+ int y=34+(i*47)%102;
+ rect(x,y,2,2,faint);
+ }
+ } else {
+ for(int i=0;i<4;i++) {
+ int x=(i*143+330 - (int)(distance_px/5)%620 +620)%620-85;
+ int y=49+(i*31)%70;
+ rect(x+10,y,31,2,faint);rect(x+17,y-7,18,2,faint);
+ rect(x+9,y-5,2,7,faint);rect(x+35,y-5,2,7,faint);
+ rect(x+16,y-9,3,3,faint);
+ }
+ }
+ for(int i=0;i<25;i++) {
+ int x=(i*43+17 - (int)(distance_px%1075)+1075)%1075;
+ if (x < W) rect(x,GROUND+9+(i*7)%21,3+(i%3),1,faint);
+ }
+}
+static bool overlap(int x,int y,int w,int h,int xx,int yy,int ww,int hh) {
+ return x<xx+ww && x+w>xx && y<yy+hh && y+h>yy;
+}
+static bool collision(void) {
+ int y=(dino_y+255)/256;
+ int x=DX+8, top=y+4, w=24,h=37;
+ if (duck && y>=DY) {x=DX+7;top=GROUND-26;w=32;h=26;}
+ for(int i=0;i<count;i++) {
+ obstacle *o=&obstacles[i];
+ int ox=o->x+2, oy=o->y+2, ow=o->w-4, oh=o->h-3;
+ if (o->kind==BIRD) {oy=o->y+6;oh=10;ox=o->x+5;ow=22;}
+ if(overlap(x,top,w,h,ox,oy,ow,oh))return true;
+ }
+ return false;
+}
+static void start_game(void) {
+ scene=PLAY;count=0;score=0;speed=4;spawn_left=260;distance_px=0;
+ duck=0;dino_y=DY*256;dino_vy=0;ticks=0;new_record=false;
+}
+static void spawn(void) {
+ if(count>=8)return;
+ obstacle *o=&obstacles[count++];
+ o->x=W+5;
+ if(score>350 && randint(5)==0) {
+ o->kind=BIRD;o->w=33;o->h=22;
+ o->y=randint(2)?GROUND-46:GROUND-75;
+ } else {
+ o->kind=randint(3)==0?LARGE_CACTUS:CACTUS;
+ o->w=o->kind==LARGE_CACTUS?24:19;
+ o->h=o->kind==LARGE_CACTUS?43:32;
+ o->y=GROUND-o->h;
+ }
+}
+static void lose(void) {
+ scene=DEAD;
+ if(score>high_score) {
+ high_score=score;new_record=true;
+ uint32_t data[2]={0x4F4E4944u,(uint32_t)high_score};
+ ef_write(SAVE_NAME,data,sizeof data);
+ }
+}
+static void update(bool jump,bool down) {
+ ticks++;score=(int)(ticks/4);speed=4+(score/140);if(speed>10)speed=10;
+ if(jump && dino_y>=DY*256 && !down) dino_vy=-2600;
+ duck=down && dino_y>=DY*256;
+ if(dino_y<DY*256 || dino_vy<0) {
+ if(down)dino_vy+=220;
+ dino_y+=dino_vy;dino_vy+=155;
+ if(dino_y>=DY*256){dino_y=DY*256;dino_vy=0;}
+ }
+ distance_px+=(uint32_t)speed;
+ for(int i=0;i<count;) {
+ obstacles[i].x-=(int16_t)speed;
+ if(obstacles[i].x+obstacles[i].w<0) {
+ for(int j=i+1;j<count;j++) obstacles[j-1]=obstacles[j];
+ count--;
+ } else i++;
+ }
+ spawn_left-=speed;
+ if(spawn_left<=0) {
+ spawn();spawn_left=200+randint(95)+(speed-4)*13;
+ }
+ if(collision())lose();
+}
+static void frame(void) {
+ bool night=((score/300)&1)!=0;
+ bg=RGB(night?0x181D2A:0xF7F7F7);
+ ink=RGB(night?0xF1F1F1:0x404040);
+ faint=RGB(night?0x7A8193:0xBBBBBB);
+ for(band_y=0;band_y<H;band_y+=BAND) {
+ for(int i=0;i<W*BAND;i++)pixels[i]=bg;
+ scenery();
+ if(scene==PLAY || scene==PAUSED || scene==DEAD) {
+ for(int i=0;i<count;i++) {
+ if(obstacles[i].kind==BIRD)bird(&obstacles[i]);else cactus(&obstacles[i]);
+ }
+ dino(DX,(dino_y+128)/256,duck,ticks/5);
+ text_at(11,11,"HI",2,faint);number(47,11,high_score,5,2,ink);
+ number(245,11,(unsigned)score,5,2,ink);
+ } else {
+ dino(134,101,0,ticks/8);
+ centered(40,"DINO RUN",3,ink);
+ centered(170,scene==HELP?"OK OR UP JUMP":"PRESS OK TO PLAY",2,ink);
+ centered(209,scene==HELP?"DOWN DUCK":"SHIFT FOR HELP",2,faint);
+ if(scene==HELP) centered(230,"BACK PAUSE",1,faint);
+ else {text_at(9,230,"BEST",1,faint);number(46,230,high_score,5,1,ink);}
+ }
+ if(scene==DEAD) {
+ rect(46,61,228,90,bg);
+ centered(73,"GAME OVER",3,ink);
+ centered(108,new_record?"NEW RECORD!":"TRY AGAIN!",1,ink);
+ centered(127,"OK TO RESTART",2,ink);
+ } else if(scene==PAUSED) {
+ rect(75,70,170,76,bg);
+ centered(82,"PAUSED",3,ink);
+ centered(119,"BACK TO RESUME",1,ink);
+ }
+ eadk_display_push_rect((eadk_rect_t){0,(uint16_t)band_y,W,BAND},pixels);
+ }
+}
+
+int main(void) {
+ np_app_begin();
+ uint32_t len=0;
+ const uint8_t *save=ef_read(SAVE_NAME,&len);
+ if(save && len==8 && save[0]=='D' && save[1]=='I' && save[2]=='N' && save[3]=='O') {
+ uint32_t value=(uint32_t)save[4]|(uint32_t)save[5]<<8|(uint32_t)save[6]<<16|(uint32_t)save[7]<<24;
+ if(value<100000000u)high_score=(int)value;
+ }
+ rng^=(uint32_t)eadk_timing_millis()*2654435761u;
+ scene=TITLE; dino_y=DY*256;
+ uint64_t held=eadk_keyboard_scan();
+ for(;;) {
+ uint32_t now=(uint32_t)eadk_timing_millis();
+ uint64_t keys=eadk_keyboard_scan(),hit=keys & ~held;
+ held=keys;
+ if(keys&(KEY(eadk_key_home)|KEY(eadk_key_on_off)))break;
+ if(scene==TITLE || scene==HELP) {
+ if(hit&JUMP) start_game();
+ else if(hit&KEY(eadk_key_shift))scene=scene==TITLE?HELP:TITLE;
+ } else if(scene==PLAY) {
+ if(hit&PAUSE)scene=PAUSED;
+ else update((hit&JUMP)!=0,(keys&DUCK)!=0);
+ } else if(scene==PAUSED) {
+ if(hit&PAUSE)scene=PLAY;
+ } else if(scene==DEAD) {
+ if(hit&JUMP)start_game();
+ }
+ frame();
+ uint32_t elapsed=(uint32_t)eadk_timing_millis()-now;
+ if(elapsed<33)eadk_timing_msleep(33-elapsed);
+ }
+ return np_app_end();
+}
diff --git a/games/dinorun/tests/eadk.h b/games/dinorun/tests/eadk.h
new file mode 100644
index 00000000..57ef7707
--- /dev/null
+++ b/games/dinorun/tests/eadk.h
@@ -0,0 +1,14 @@
+#ifndef DINO_FAKE_EADK_H
+#define DINO_FAKE_EADK_H
+#include <stdint.h>
+typedef struct {uint16_t x,y,width,height;} eadk_rect_t;
+/* Test-only names; the real NumWorks SDK supplies these. */
+enum {eadk_key_left=0,eadk_key_up=1,eadk_key_down=2,eadk_key_right=3,
+ eadk_key_ok=4,eadk_key_back=5,eadk_key_home=6,eadk_key_on_off=8,
+ eadk_key_shift=12,eadk_key_backspace=17,eadk_key_eight=31,
+ eadk_key_two=43,eadk_key_exe=52};
+uint64_t eadk_keyboard_scan(void);
+uint32_t eadk_timing_millis(void);
+void eadk_timing_msleep(uint32_t ms);
+void eadk_display_push_rect(eadk_rect_t rect,const uint16_t *px);
+#endif
diff --git a/games/dinorun/tests/test_dino.c b/games/dinorun/tests/test_dino.c
new file mode 100644
index 00000000..fb61d6f8
--- /dev/null
+++ b/games/dinorun/tests/test_dino.c
@@ -0,0 +1,58 @@
+/* Host gameplay and rendering test of the ACTUAL native source. */
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#define main dino_app_main
+#include "../src/main.c"
+#undef main
+static uint16_t screen[W*H];
+uint64_t eadk_keyboard_scan(void) {return 0;}
+uint32_t eadk_timing_millis(void) {return 0;}
+void eadk_timing_msleep(uint32_t ms) {(void)ms;}
+void eadk_display_push_rect(eadk_rect_t r,const uint16_t *px) {
+ assert(r.x+r.width<=W && r.y+r.height<=H);
+ for(int y=0;y<r.height;y++) for(int x=0;x<r.width;x++)
+ screen[(y+r.y)*W+x+r.x]=px[y*r.width+x];
+}
+static void screenshot(const char *f) {
+ FILE *fp=fopen(f,"wb"); assert(fp);
+ fprintf(fp,"P6\n%d %d\n255\n",W,H);
+ for(int i=0;i<W*H;i++) {
+ uint16_t c=screen[i];
+ unsigned char rgb[3]={(unsigned char)(((c>>11)&31)*255/31),
+ (unsigned char)(((c>>5)&63)*255/63),
+ (unsigned char)((c&31)*255/31)};
+ fwrite(rgb,1,3,fp);
+ }
+ fclose(fp);
+}
+int main(int argc,char **argv) {
+ scene=TITLE;dino_y=DY*256;score=0;
+ frame();
+ if(argc>=2)screenshot(argv[1]);
+ start_game();assert(scene==PLAY && score==0 && count==0);
+ int y=dino_y;
+ update(true,false);assert(dino_y<y && dino_vy<0);
+ for(int t=0;t<80;t++)update(false,false);
+ assert(dino_y==DY*256);
+ update(false,true);assert(duck);
+ update(false,false);assert(!duck);
+ /* Force a collision, test the game-over state and restart. */
+ count=1;obstacles[0]=(obstacle){DX+12,GROUND-32,19,32,CACTUS};
+ update(false,false);assert(scene==DEAD && high_score==score);
+ start_game();assert(scene==PLAY && score==0 && count==0);
+ for(int i=0;i<160;i++){
+ if(scene==DEAD)start_game();
+ update((i%31)==1,false);
+ }
+ start_game();
+ score=328; ticks=1312;distance_px=2100;
+ count=3;
+ obstacles[0]=(obstacle){244,GROUND-32,19,32,CACTUS};
+ obstacles[1]=(obstacle){304,GROUND-43,24,43,LARGE_CACTUS};
+ obstacles[2]=(obstacle){152,GROUND-75,33,22,BIRD};
+ frame();
+ if(argc>=3)screenshot(argv[2]);
+ printf("Host test passed: jump, crouch, collision, restart, rendering.\n");
+ return 0;
+}