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.

Ports: CI for the TI-84 Plus CE, TI-Nspire, fx-CG50, web and computer builds

Mason363bf8b4895ea8a
diff --git a/.github/workflows/ports.yml b/.github/workflows/ports.yml
new file mode 100644
index 00000000..6beb81f1
--- /dev/null
+++ b/.github/workflows/ports.yml
@@ -0,0 +1,313 @@
+name: Ports
+
+# NumPlay's games on its other targets (platform/README.md): each target builds the games whose "ports" (games.json)
+# list it, with its toolchain from the cache or made by platform/<target>/toolchain.sh (again only when the script
+# changes), and packs them. The computer builds are played for a few seconds each. NumPlay Studio gets each calculator
+# game's file in the kit (ports/ on the branch "kit"), and on a v* tag the calculators' zips go on its release.
+
+on:
+ push:
+ branches: [main]
+ tags: ["v*"]
+ workflow_dispatch:
+
+permissions:
+ contents: read
+
+concurrency:
+ group: ports-${{ github.ref }}
+ cancel-in-progress: false
+
+jobs:
+ calculator:
+ name: ${{ matrix.target }}
+ runs-on: ubuntu-24.04
+ timeout-minutes: 300
+ strategy:
+ fail-fast: false
+ matrix:
+ include:
+ - target: ti84ce
+ zip: NumPlay-TI84CE.zip
+ toolchain: CEDEV=$HOME/toolchains/ti84ce
+ - target: nspire
+ zip: NumPlay-Nspire.zip
+ toolchain: NDLESS_SDK=$HOME/toolchains/nspire/ndless-sdk
+ apt: >-
+ build-essential git curl libgmp-dev libmpfr-dev libmpc-dev zlib1g-dev libboost-program-options-dev
+ texinfo flex bison
+ # (genzehn runs with Boost's library)
+ runtime: libboost-program-options-dev
+ - target: casio-cg
+ zip: NumPlay-CasioCG.zip
+ toolchain: FXCG=$HOME/toolchains/casio-cg
+ apt: build-essential git curl libgmp-dev libmpfr-dev libmpc-dev zlib1g-dev texinfo
+ steps:
+ - uses: actions/checkout@v4
+
+ - uses: actions/setup-python@v5
+ with:
+ python-version: "3.12"
+
+ - uses: actions/cache/restore@v4
+ id: cache
+ with:
+ path: ~/toolchains/${{ matrix.target }}
+ key: ${{ matrix.target }}-ubuntu-24.04-${{ hashFiles(format('platform/{0}/toolchain.sh', matrix.target)) }}
+
+ - name: Toolchain
+ if: steps.cache.outputs.cache-hit != 'true'
+ env:
+ APT: ${{ matrix.apt }}
+ TARGET: ${{ matrix.target }}
+ run: |
+ # shellcheck disable=SC2086
+ if [ -n "$APT" ]; then sudo apt-get update -q && sudo apt-get install -yq $APT; fi
+ bash "platform/$TARGET/toolchain.sh" "$HOME/toolchains/$TARGET"
+
+ # (saved as soon as it's made, so a game that fails to build doesn't cost the next run the toolchain)
+ - uses: actions/cache/save@v4
+ if: steps.cache.outputs.cache-hit != 'true'
+ with:
+ path: ~/toolchains/${{ matrix.target }}
+ key: ${{ steps.cache.outputs.cache-primary-key }}
+
+ - name: Build
+ env:
+ RUNTIME: ${{ matrix.runtime }}
+ TARGET: ${{ matrix.target }}
+ ZIP: ${{ matrix.zip }}
+ run: |
+ # shellcheck disable=SC2086
+ if [ -n "$RUNTIME" ]; then sudo apt-get update -q && sudo apt-get install -yq $RUNTIME; fi
+ pip install -q pillow
+ export ${{ matrix.toolchain }}
+ python3 tools/ports.py build "$TARGET" -j 4
+ python3 tools/ports.py pack "$TARGET" "build/ports/$ZIP"
+
+ - uses: actions/upload-artifact@v4
+ with:
+ name: ${{ matrix.zip }}
+ path: build/ports/${{ matrix.zip }}
+ if-no-files-found: error
+
+ web:
+ runs-on: ubuntu-24.04
+ timeout-minutes: 90
+ env:
+ EMSDK_VERSION: 6.0.13
+ steps:
+ - uses: actions/checkout@v4
+
+ - uses: actions/setup-python@v5
+ with:
+ python-version: "3.12"
+
+ - uses: actions/cache/restore@v4
+ id: cache
+ with:
+ path: ~/emsdk
+ key: emsdk-${{ env.EMSDK_VERSION }}-ubuntu-24.04
+
+ - name: Emscripten
+ if: steps.cache.outputs.cache-hit != 'true'
+ # emsdk at the same version, then SDL 3 and the libraries a game links, made once for the cache
+ run: |
+ git clone -q --depth 1 --branch "$EMSDK_VERSION" https://github.com/emscripten-core/emsdk.git ~/emsdk
+ ~/emsdk/emsdk install "$EMSDK_VERSION"
+ ~/emsdk/emsdk activate "$EMSDK_VERSION"
+ # shellcheck source=/dev/null
+ source ~/emsdk/emsdk_env.sh
+ cd "$RUNNER_TEMP"
+ printf '#include <SDL3/SDL.h>\nint f(void);\nint main(void) { return SDL_Init(0) ? f() : 1; }\n' > t.c
+ printf 'struct A { virtual int g() { return 0; } };\nextern "C" int f(void) { A a; return a.g(); }\n' > t.cpp
+ em++ -g0 -O2 -std=gnu++11 -fno-exceptions -fno-rtti -fno-threadsafe-statics -c t.cpp -o t.o
+ emcc -g0 -O2 --use-port=sdl3 -sASYNCIFY -sALLOW_MEMORY_GROWTH -sENVIRONMENT=web t.c t.o -o t.html
+ rm -rf ~/emsdk/downloads
+
+ - uses: actions/cache/save@v4
+ if: steps.cache.outputs.cache-hit != 'true'
+ with:
+ path: ~/emsdk
+ key: ${{ steps.cache.outputs.cache-primary-key }}
+
+ - name: Build
+ run: |
+ # shellcheck source=/dev/null
+ source ~/emsdk/emsdk_env.sh
+ python3 tools/ports.py build web -j 4
+ python3 tools/ports.py pack web build/ports/NumPlay-Web.zip
+
+ - uses: actions/upload-artifact@v4
+ with:
+ name: NumPlay-Web.zip
+ path: build/ports/NumPlay-Web.zip
+ if-no-files-found: error
+
+ sdl:
+ runs-on: ubuntu-24.04
+ timeout-minutes: 60
+ env:
+ SDL_VERSION: 3.4.16
+ SDL_SHA256: 7322236cd12090c3eb40b9728be4d49c76f66ad17d04369584d4ecad5cf77c68
+ steps:
+ - uses: actions/checkout@v4
+
+ - uses: actions/setup-python@v5
+ with:
+ python-version: "3.12"
+
+ - uses: actions/cache/restore@v4
+ id: cache
+ with:
+ path: ~/sdl3
+ key: sdl3-${{ env.SDL_VERSION }}-ubuntu-24.04
+
+ - name: SDL 3
+ if: steps.cache.outputs.cache-hit != 'true'
+ # (Ubuntu 24.04 has no SDL 3: its release, built with the offscreen video and the software renderer the tests
+ # use, without X11 or Wayland)
+ run: |
+ cd "$RUNNER_TEMP"
+ curl -fsSL -o sdl.tar.gz "https://github.com/libsdl-org/SDL/releases/download/release-$SDL_VERSION/SDL3-$SDL_VERSION.tar.gz"
+ echo "$SDL_SHA256 sdl.tar.gz" | sha256sum -c -
+ tar -xzf sdl.tar.gz
+ cmake -S "SDL3-$SDL_VERSION" -B sdl-build -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$HOME/sdl3" \
+ -DCMAKE_INSTALL_LIBDIR=lib -DSDL_TESTS=OFF -DSDL_EXAMPLES=OFF -DSDL_UNIX_CONSOLE_BUILD=ON -DSDL_X11=OFF \
+ -DSDL_WAYLAND=OFF -DSDL_OFFSCREEN=ON -DSDL_RENDER_SW=ON
+ cmake --build sdl-build --parallel 4
+ cmake --install sdl-build
+
+ - uses: actions/cache/save@v4
+ if: steps.cache.outputs.cache-hit != 'true'
+ with:
+ path: ~/sdl3
+ key: ${{ steps.cache.outputs.cache-primary-key }}
+
+ - name: Build
+ run: |
+ echo "PKG_CONFIG_PATH=$HOME/sdl3/lib/pkgconfig" >> "$GITHUB_ENV"
+ echo "LD_LIBRARY_PATH=$HOME/sdl3/lib" >> "$GITHUB_ENV"
+ export PKG_CONFIG_PATH="$HOME/sdl3/lib/pkgconfig"
+ pkg-config --modversion sdl3
+ pip install -q pillow
+ python3 tools/ports.py build sdl -j 4
+
+ - name: Run
+ # each game headless for 7 seconds: it must draw, and save and quit when Home is held
+ run: python3 tools/ports.py run -j 4
+
+ - name: Run in a window
+ # one game in a window again, on SDL's offscreen video with the software renderer
+ run: |
+ g=$(python3 tools/ports.py list sdl | sed -n 1p)
+ cd "games/$g"
+ SDL_VIDEO_DRIVER=offscreen SDL_RENDER_DRIVER=software NP_SAVES="$RUNNER_TEMP" NP_QUIT_MS=4000 \
+ NP_SHOTS="3000:$RUNNER_TEMP/window.ppm" timeout 30 "build/sdl/$g"
+ test -s "$RUNNER_TEMP/window.ppm"
+
+ - uses: actions/upload-artifact@v4
+ if: always()
+ with:
+ name: shots
+ path: build/ports/shots.png
+ if-no-files-found: ignore
+
+ release:
+ needs: calculator
+ if: startsWith(github.ref, 'refs/tags/v')
+ runs-on: ubuntu-24.04
+ timeout-minutes: 45
+ permissions:
+ contents: write
+ steps:
+ - uses: actions/download-artifact@v4
+ with:
+ pattern: NumPlay-*
+ merge-multiple: true
+ path: zips
+
+ - name: Attach to the release
+ env:
+ GH_TOKEN: ${{ github.token }}
+ GH_REPO: ${{ github.repository }}
+ # Build makes the release once its tests pass: this waits for it, 30 minutes at most
+ run: |
+ tag="$GITHUB_REF_NAME"
+ for i in $(seq 60); do
+ [ "$(gh release view "$tag" --json isDraft --jq .isDraft 2>/dev/null)" = false ] && break
+ if [ "$i" = 60 ]; then echo "no release $tag after 30 minutes"; exit 1; fi
+ sleep 30
+ done
+ n() { unzip -Z1 "zips/$1" | grep -vc '^README.txt$'; }
+ for _ in 1 2 3; do
+ gh release upload "$tag" --clobber \
+ "zips/NumPlay-TI84CE.zip#NumPlay-TI84CE.zip · $(n NumPlay-TI84CE.zip) games for the TI-84 Plus CE and TI-83 Premium CE" \
+ "zips/NumPlay-Nspire.zip#NumPlay-Nspire.zip · $(n NumPlay-Nspire.zip) games for the TI-Nspire CX and CX II, with Ndless" \
+ "zips/NumPlay-CasioCG.zip#NumPlay-CasioCG.zip · $(n NumPlay-CasioCG.zip) games for the Casio fx-CG50 and Graph 90+E" \
+ && exit 0
+ sleep 30
+ done
+ exit 1
+
+ kit:
+ needs: calculator
+ if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
+ runs-on: ubuntu-24.04
+ timeout-minutes: 90
+ permissions:
+ contents: write
+ actions: write
+ steps:
+ - uses: actions/checkout@v4
+
+ - uses: actions/download-artifact@v4
+ with:
+ pattern: NumPlay-*
+ merge-multiple: true
+ path: build/zips
+
+ - name: The ports in the kit
+ env:
+ GH_TOKEN: ${{ github.token }}
+ GH_REPO: ${{ github.repository }}
+ # NumPlay Studio's files: ports/<target>/<file> and ports/ports.json on the branch "kit". Build replaces the kit
+ # (one commit) for each newer commit of main, so this waits for the kit of this commit (an hour at most) and
+ # adds ports/ on top. Its message ends with the kit's commit, the one Build reads.
+ run: |
+ mkdir -p build/kit
+ unzip -q build/zips/NumPlay-TI84CE.zip -x README.txt -d build/kit/ti84ce
+ unzip -q build/zips/NumPlay-Nspire.zip -x README.txt -d build/kit/nspire
+ unzip -q build/zips/NumPlay-CasioCG.zip -x README.txt -d build/kit/casio-cg
+ python3 tools/ports.py kit build/kit
+ for _ in $(seq 60); do
+ kit=$(gh api "repos/$GH_REPO/commits/kit" --jq .commit.message 2>/dev/null | grep -o '[0-9a-f]\{40\}' | tail -1 || true)
+ how=none
+ if [ -n "$kit" ]; then how=$(gh api "repos/$GH_REPO/compare/$kit...$GITHUB_SHA" --jq .status 2>/dev/null || echo unknown); fi
+ if [ "$how" = identical ]; then break; fi
+ if [ "$how" = behind ]; then echo "(the kit is from $kit, newer: its own run adds its ports)"; exit 0; fi
+ left=$(gh run list --workflow build.yml --commit "$GITHUB_SHA" --json status --jq 'map(select(.status != "completed")) | length' || echo 1)
+ if [ "$left" = 0 ]; then echo "(Build made no kit of this commit: the kit is from $kit)"; break; fi
+ sleep 60
+ done
+ url="https://x-access-token:[email protected]/$GH_REPO.git"
+ if ! git ls-remote --exit-code --heads "$url" kit > /dev/null; then echo "(no kit yet)"; exit 0; fi
+ version=$(tr -d '[:space:]' < VERSION)
+ for _ in 1 2 3 4 5; do
+ rm -rf build/site-kit
+ git clone -q --depth 1 --branch kit "$url" build/site-kit
+ base=$(git -C build/site-kit log -1 --format=%B | grep -o '[0-9a-f]\{40\}' | tail -1 || true)
+ rm -rf build/site-kit/ports
+ cp -R build/kit build/site-kit/ports
+ git -C build/site-kit add -A ports
+ if git -C build/site-kit diff --cached --quiet; then echo "(the kit has these ports)"; exit 0; fi
+ git -C build/site-kit -c user.name="github-actions[bot]" \
+ -c user.email="41898282+github-actions[bot]@users.noreply.github.com" \
+ commit -q -m "Ports of NumPlay $version, from $GITHUB_SHA, on the kit from $base"
+ if git -C build/site-kit push -q origin HEAD:kit; then
+ gh workflow run pages.yml --ref main || echo "(the site was not deployed again)"
+ exit 0
+ fi
+ sleep 20
+ done
+ exit 1
diff --git a/platform/casio-cg/README.md b/platform/casio-cg/README.md
index 6a0d643f..c0938fc3 100644
--- a/platform/casio-cg/README.md
+++ b/platform/casio-cg/README.md
@@ -6,7 +6,7 @@ The fx-CG50, Graph 90+E, fx-CG10 and fx-CG20, as add-ins (`.g3a`), with [libfxcg
make port TARGET=casio-cg (in a game's folder): build/casio-cg/<game>.g3a
```
-`FXCG` points to the folder `toolchain.sh` fills: GCC and binutils for `sh3eb-elf`, newlib built for the calculator's calling convention, libfxcg. No Planet Casio tools are needed.
+`FXCG` points to the folder `toolchain.sh` fills: GCC and binutils for `sh3eb-elf`, newlib built for the calculator's calling convention, libstdc++, libfxcg. No Planet Casio tools are needed. `platform/casio-cg/toolchain.sh DIR` builds them in DIR from their sources, on Linux or macOS (about an hour).
The game's 320 x 240 picture sits in the middle of the 384 x 216 screen, one row in ten left out. An add-in can be 2 MB at most: Celeste and FNAF World are bigger.
diff --git a/platform/casio-cg/toolchain.sh b/platform/casio-cg/toolchain.sh
new file mode 100755
index 00000000..f1901815
--- /dev/null
+++ b/platform/casio-cg/toolchain.sh
@@ -0,0 +1,135 @@
+#!/usr/bin/env bash
+# The fx-CG50's toolchain (port.mk's FXCG), built from its makers' sources in the folder given: GNU binutils 2.44 and
+# GCC 14.2 for sh3eb-elf, newlib 4.5 (sourceware.org) for the add-ins' calling convention, GCC again with newlib for
+# C++ and libstdc++, and libfxcg (github.com/Jonimoose/libfxcg) in libfxcg.a. Linux and macOS, about an hour.
+# Ubuntu: sudo apt install build-essential git curl libgmp-dev libmpfr-dev libmpc-dev zlib1g-dev texinfo
+# macOS: brew install gmp mpfr libmpc
+# platform/casio-cg/toolchain.sh ~/toolchains/casio
+set -euo pipefail
+unset CPATH LIBRARY_PATH # (the cross compiler would take the computer's headers)
+BINUTILS=binutils-2.44.tar.bz2 BINUTILS_SUM=f66390a661faa117d00fab2e79cf2dc9d097b42cc296bf3f8677d1e7b452dc3a
+GCC=gcc-14.2.0.tar.xz GCC_SUM=a7b39bc69cbf9e25826c5a60ab26477001f7c08d85cec04bc0e29cabed6f3cc9
+NEWLIB=newlib-4.5.0.20241231.tar.gz NEWLIB_SUM=33f12605e0054965996c25c1382b3e463b0af91799001f5bb8c0630f2ec8c852
+LIBFXCG=daa76d9e37758ab5b9b0f614b7e0aa6acfbe2e18
+DIR=${1:?usage: toolchain.sh DIR}
+mkdir -p "$DIR"
+DIR=$(cd "$DIR" && pwd)
+SRC=$DIR/src B=$DIR/build
+JOBS=${JOBS:-$(getconf _NPROCESSORS_ONLN)}
+export PATH="$DIR/sh3eb/bin:$PATH"
+
+sha256() { if command -v sha256sum > /dev/null; then sha256sum "$1"; else shasum -a 256 "$1"; fi | cut -d' ' -f1; }
+# fetch FILE SUM URL...: the source tarball from the first place that has it as released, unpacked in SRC
+fetch() {
+ local f=$1 sum=$2 url
+ shift 2
+ [ -d "$SRC/${f%.tar.*}" ] && return
+ mkdir -p "$SRC"
+ for url; do
+ curl -fsSL --retry 3 -o "$SRC/$f" "$url/$f" && [ "$(sha256 "$SRC/$f")" = "$sum" ] && break
+ rm -f "$SRC/$f"
+ done
+ [ -f "$SRC/$f" ] || { echo "toolchain.sh: no $f as released" >&2; exit 1; }
+ tar -xf "$SRC/$f" -C "$SRC"
+}
+# built STEP VERSIONS: whether that step is done, with these versions
+built() { [ "$(cat "$DIR/.built-$1" 2>/dev/null)" = "$2" ]; }
+
+HOST=""
+if [ "$(uname -s)" = Darwin ]; then
+ b=$(brew --prefix)
+ HOST="--with-gmp=$b/opt/gmp --with-mpfr=$b/opt/mpfr --with-mpc=$b/opt/libmpc"
+ [ -d "$b/opt/isl" ] && HOST="$HOST --with-isl=$b/opt/isl"
+fi
+# (GCC's sources nest brackets deeper than clang allows by default)
+if cc -v 2>&1 | grep clang > /dev/null; then export CXXFLAGS="-fbracket-depth=512 -O2"; fi
+
+if ! built binutils "$BINUTILS"; then
+ fetch "$BINUTILS" "$BINUTILS_SUM" https://ftpmirror.gnu.org/gnu/binutils https://mirrors.kernel.org/gnu/binutils
+ rm -rf "$B/binutils" && mkdir -p "$B/binutils" && cd "$B/binutils"
+ "$SRC/${BINUTILS%.tar.*}/configure" --target=sh3eb-elf --prefix="$DIR/sh3eb" --disable-nls --disable-werror \
+ --with-sysroot --disable-gdb --disable-gprofng --with-system-zlib --enable-warn-rwx-segments=no
+ make -j"$JOBS"
+ make install
+ echo "$BINUTILS" > "$DIR/.built-binutils"
+fi
+
+# GCC, C only, to build newlib with
+if ! built gcc "$GCC"; then
+ fetch "$GCC" "$GCC_SUM" "https://ftpmirror.gnu.org/gnu/gcc/${GCC%.tar.*}" \
+ "https://mirrors.kernel.org/gnu/gcc/${GCC%.tar.*}"
+ rm -rf "$B/gcc" && mkdir -p "$B/gcc" && cd "$B/gcc"
+ # shellcheck disable=SC2086
+ "$SRC/${GCC%.tar.*}/configure" --target=sh3eb-elf --prefix="$DIR/sh3eb" --with-pkgversion=NumPlay \
+ --without-headers --enable-languages=c --disable-tls --disable-nls --disable-threads --disable-shared \
+ --disable-libssp --disable-libvtv --disable-libada --disable-libquadmath --disable-libgomp \
+ --with-endian=big --with-multilib-list=m4a-nofpu --with-system-zlib --disable-werror $HOST
+ make -j"$JOBS" inhibit_libc=true all-gcc
+ make install-gcc
+ make -j"$JOBS" inhibit_libc=true all-target-libgcc
+ make install-target-libgcc
+ echo "$GCC" > "$DIR/.built-gcc"
+fi
+
+if ! built newlib "$NEWLIB"; then
+ fetch "$NEWLIB" "$NEWLIB_SUM" https://sourceware.org/pub/newlib
+ rm -rf "$B/newlib" && mkdir -p "$B/newlib" && cd "$B/newlib"
+ export CFLAGS_FOR_TARGET="-mb -m4a-nofpu -mhitachi -Os -ffunction-sections -fdata-sections -DMALLOC_PROVIDED \
+-DABORT_PROVIDED -DMISSING_SYSCALL_NAMES"
+ "$SRC/${NEWLIB%.tar.*}/configure" --target=sh-elf CC_FOR_TARGET=sh3eb-elf-gcc AR_FOR_TARGET=sh3eb-elf-ar \
+ RANLIB_FOR_TARGET=sh3eb-elf-ranlib AS_FOR_TARGET=sh3eb-elf-as LD_FOR_TARGET=sh3eb-elf-ld \
+ NM_FOR_TARGET=sh3eb-elf-nm OBJCOPY_FOR_TARGET=sh3eb-elf-objcopy --prefix="$DIR/newlib" \
+ --disable-newlib-supplied-syscalls --disable-multilib --enable-newlib-nano-formatted-io \
+ --disable-newlib-io-float --disable-nls
+ make -j"$JOBS"
+ make install
+ echo "$NEWLIB" > "$DIR/.built-newlib"
+fi
+
+# GCC again, C and C++, with newlib where it looks for its C library: libstdc++, for the fx-CG like newlib
+if ! built gcc-cxx "$GCC $NEWLIB"; then
+ fetch "$GCC" "$GCC_SUM" "https://ftpmirror.gnu.org/gnu/gcc/${GCC%.tar.*}" \
+ "https://mirrors.kernel.org/gnu/gcc/${GCC%.tar.*}"
+ mkdir -p "$DIR/sh3eb/sh3eb-elf/include" "$DIR/sh3eb/sh3eb-elf/lib"
+ cp -R "$DIR/newlib/sh-elf/include/." "$DIR/sh3eb/sh3eb-elf/include/"
+ cp "$DIR"/newlib/sh-elf/lib/lib{c,m,g}.a "$DIR/sh3eb/sh3eb-elf/lib/"
+ rm -rf "$B/gcc-cxx" && mkdir -p "$B/gcc-cxx" && cd "$B/gcc-cxx"
+ export CFLAGS_FOR_TARGET="-mb -m4a-nofpu -mhitachi -Os -ffunction-sections -fdata-sections"
+ export CXXFLAGS_FOR_TARGET="$CFLAGS_FOR_TARGET"
+ # shellcheck disable=SC2086
+ "$SRC/${GCC%.tar.*}/configure" --target=sh3eb-elf --prefix="$DIR/sh3eb" --with-pkgversion=NumPlay --with-newlib \
+ --enable-languages=c,c++ --disable-tls --disable-nls --disable-threads --disable-shared --disable-libssp \
+ --disable-libvtv --disable-libada --disable-libquadmath --disable-libgomp --disable-libstdcxx-verbose \
+ --disable-libstdcxx-pch --with-endian=big --with-multilib-list=m4a-nofpu --with-system-zlib --disable-werror \
+ $HOST
+ make -j"$JOBS" all-gcc
+ make install-gcc
+ make -j"$JOBS" all-target-libgcc
+ make install-target-libgcc
+ make -j"$JOBS" all-target-libstdc++-v3
+ make install-target-libstdc++-v3
+ echo "$GCC $NEWLIB" > "$DIR/.built-gcc-cxx"
+fi
+
+# libfxcg: its syscalls and helpers compiled one by one (its own Makefiles want a toolchain set up its way)
+if ! built libfxcg "$LIBFXCG"; then
+ if [ "$(git -C "$DIR/libfxcg" rev-parse HEAD 2>/dev/null)" != "$LIBFXCG" ]; then
+ rm -rf "$DIR/libfxcg"
+ git init -q "$DIR/libfxcg"
+ git -C "$DIR/libfxcg" fetch -q --depth 1 https://github.com/Jonimoose/libfxcg.git "$LIBFXCG"
+ git -C "$DIR/libfxcg" checkout -q FETCH_HEAD
+ fi
+ rm -rf "$B/fxcg" && mkdir -p "$B/fxcg" "$DIR/sdk/lib"
+ flags=(-ffunction-sections -fdata-sections -Os -mb -m4a-nofpu -mhitachi -ffreestanding -std=gnu99
+ -I"$DIR/libfxcg/include")
+ for f in "$DIR"/libfxcg/libfxcg/syscalls/*.S "$DIR"/libfxcg/libfxcg/misc/*.S "$DIR"/libfxcg/libfxcg/misc/*.c; do
+ sh3eb-elf-gcc "${flags[@]}" -c "$f" -o "$B/fxcg/$(basename "$f").o"
+ done
+ rm -f "$DIR/sdk/lib/libfxcg.a"
+ sh3eb-elf-ar rcs "$DIR/sdk/lib/libfxcg.a" "$B"/fxcg/*.o
+ echo "$LIBFXCG" > "$DIR/.built-libfxcg"
+fi
+
+rm -rf "$B" "$SRC"
+sh3eb-elf-g++ --version | sed -n 1p
+echo "The fx-CG50's toolchain is in $DIR (FXCG)"
diff --git a/platform/nspire/README.md b/platform/nspire/README.md
index 73ad9992..b12919e3 100644
--- a/platform/nspire/README.md
+++ b/platform/nspire/README.md
@@ -6,7 +6,7 @@ The TI-Nspire CX and CX II (and their CAS models), with [Ndless](https://ndless.
make port TARGET=nspire (in a game's folder): build/nspire/<game>.tns
```
-`NDLESS_SDK` points to Ndless's `ndless-sdk` folder, with its toolchain built (`toolchain/build_toolchain.sh`), then `make build-libsyscalls build-libndls build-thirdparty build-tools` in it.
+`NDLESS_SDK` points to Ndless's `ndless-sdk` folder, with its toolchain built (`toolchain/build_toolchain.sh`), then `make build-libsyscalls build-libndls build-thirdparty build-tools` in it. `platform/nspire/toolchain.sh DIR` does all of it from Ndless's source, on Linux or macOS (about an hour): `NDLESS_SDK` is then `DIR/ndless-sdk`.
| Key | NumWorks key |
| --- | --- |
diff --git a/platform/nspire/toolchain.sh b/platform/nspire/toolchain.sh
new file mode 100755
index 00000000..5c34531b
--- /dev/null
+++ b/platform/nspire/toolchain.sh
@@ -0,0 +1,51 @@
+#!/usr/bin/env bash
+# Ndless's SDK for the TI-Nspire, built from its source (github.com/ndless-nspire/Ndless, r2023 and the build fixes
+# after it) in the folder given: its GCC 14 and newlib (ndless-sdk/toolchain/build_toolchain.sh, without GDB), then
+# libsyscalls, libndls, the third-party libraries and the tools (genzehn, make-prg, luna). port.mk's NDLESS_SDK is
+# then DIR/ndless-sdk. Linux and macOS, about an hour.
+# Ubuntu: sudo apt install build-essential git curl libgmp-dev libmpfr-dev libmpc-dev zlib1g-dev \
+# libboost-program-options-dev texinfo flex bison
+# macOS: brew install gmp mpfr libmpc boost texinfo
+# platform/nspire/toolchain.sh ~/toolchains/ndless
+set -euo pipefail
+REV=e52415fb568e92cd36ed049067b3e9c2727b84af
+DIR=${1:?usage: toolchain.sh DIR}
+mkdir -p "$DIR"
+DIR=$(cd "$DIR" && pwd)
+SDK=$DIR/ndless-sdk
+JOBS=${JOBS:-$(getconf _NPROCESSORS_ONLN)}
+
+# the source at REV, with its submodules (nspire-io, zlib, freetype, luna)
+if [ "$(git -C "$DIR" rev-parse HEAD 2>/dev/null)" != "$REV" ]; then
+ [ -d "$DIR/.git" ] || git -C "$DIR" init -q
+ git -C "$DIR" fetch -q --depth 1 https://github.com/ndless-nspire/Ndless.git "$REV"
+ git -C "$DIR" checkout -q FETCH_HEAD
+fi
+git -C "$DIR" submodule update -q --init --depth 1 || git -C "$DIR" submodule update -q --init
+
+# the compiler: build_toolchain.sh skips what its .built_* files name, so GDB is left out
+cd "$SDK/toolchain"
+sed -n 's/^GDB=\([^ ]*\).*/\1/p' build_toolchain.sh | tr -d '\n' > .built_gdb
+script=build_toolchain.sh
+if [ "$(uname -s)" = Darwin ]; then
+ # (Homebrew's GMP, MPFR and MPC, as build_toolchain.sh says to add)
+ b=$(brew --prefix)
+ sed "s|^OPTIONS_GCC=\"|OPTIONS_GCC=\"--with-gmp=$b/opt/gmp --with-mpfr=$b/opt/mpfr --with-mpc=$b/opt/libmpc |" \
+ build_toolchain.sh > .numplay_build_toolchain.sh
+ script=.numplay_build_toolchain.sh
+ export LIBRARY_PATH="$b/lib"
+fi
+PYTHON='' PARALLEL=-j$JOBS CFLAGS="${CFLAGS:--O2 -std=gnu17}" sh "./$script"
+rm -rf download build build-gcc .numplay_build_toolchain.sh
+
+# the SDK's libraries and tools
+export PATH="$SDK/bin:$SDK/toolchain/install/bin:$PATH"
+if [ "$(uname -s)" = Darwin ]; then
+ # (genzehn's Makefile has no place for Homebrew's Boost: built here, make then finds it made)
+ (cd "$SDK/tools/genzehn" && c++ -Wall -std=c++11 -O2 -I elfio-3.2 -I"$b/include" genzehn.cpp -L"$b/lib" \
+ -lboost_program_options -lz -o ../../bin/genzehn)
+fi
+make -C "$SDK" -j"$JOBS" build-libsyscalls build-libndls build-thirdparty build-tools
+nspire-gcc --version | sed -n 1p
+for t in genzehn make-prg; do [ -x "$SDK/bin/$t" ] || { echo "toolchain.sh: no $t" >&2; exit 1; }; done
+echo "Ndless's SDK is in $SDK (NDLESS_SDK)"
diff --git a/platform/ti84ce/README.md b/platform/ti84ce/README.md
index 93033cf3..ee4c95d6 100644
--- a/platform/ti84ce/README.md
+++ b/platform/ti84ce/README.md
@@ -6,7 +6,7 @@ The TI-84 Plus CE, TI-84 Plus CE Python and TI-83 Premium CE, with the [CE C too
make port TARGET=ti84ce (in a game's folder): build/ti84ce/<game>/bin/<GAME>.8xp
```
-`CEDEV` points to the toolchain (default `~/Documents/Assets/toolchains/CEdev`).
+`CEDEV` points to the toolchain (default `~/Documents/Assets/toolchains/CEdev`). `platform/ti84ce/toolchain.sh DIR` puts its release (v15.0) in DIR, on Linux or macOS.
| Key | NumWorks key |
| --- | --- |
diff --git a/platform/ti84ce/toolchain.sh b/platform/ti84ce/toolchain.sh
new file mode 100755
index 00000000..ecff8141
--- /dev/null
+++ b/platform/ti84ce/toolchain.sh
@@ -0,0 +1,37 @@
+#!/usr/bin/env bash
+# The CE C toolchain (CEdev v15.0) in the folder given, as its makers build it for Linux and macOS
+# (github.com/CE-Programming/toolchain/releases). port.mk's CEDEV is that folder.
+# platform/ti84ce/toolchain.sh ~/toolchains/CEdev
+set -euo pipefail
+V=v15.0
+DIR=${1:?usage: toolchain.sh DIR}
+case "$(uname -s)-$(uname -m)" in
+ Linux-x86_64) F=CEdev-Linux.tar.gz SUM=85f4794a617b134249a9cba8a084414e86e16d2a68377b1d72ace30c636dbdf9 ;;
+ Darwin-arm64) F=CEdev-macOS-arm.dmg SUM=3cc6cbe542ca851f8c9f55fbfc0add512b1b8e05853e33e3bbf1de9951f9d30e ;;
+ Darwin-x86_64) F=CEdev-macOS-intel.dmg SUM=231d84d1af49c07d42a22e39e08bdb9f92538a53f4fd9bfbd37b2650b9e39115 ;;
+ *) echo "toolchain.sh: CEdev $V has no build for $(uname -sm)" >&2; exit 1 ;;
+esac
+if [ "$(cat "$DIR/.numplay" 2>/dev/null)" = "$F $SUM" ] && [ -x "$DIR/bin/cedev-config" ]; then
+ echo "CEdev $V is in $DIR"
+ exit 0
+fi
+
+sha256() { if command -v sha256sum > /dev/null; then sha256sum "$1"; else shasum -a 256 "$1"; fi | cut -d' ' -f1; }
+tmp=$(mktemp -d)
+trap 'rm -rf "$tmp"' EXIT
+curl -fsSL --retry 3 -o "$tmp/$F" "https://github.com/CE-Programming/toolchain/releases/download/$V/$F"
+[ "$(sha256 "$tmp/$F")" = "$SUM" ] || { echo "toolchain.sh: $F isn't the one released" >&2; exit 1; }
+mkdir -p "$tmp/x" "$DIR"
+case $F in
+ *.tar.gz) tar -xzf "$tmp/$F" -C "$tmp/x" ;;
+ *.dmg)
+ hdiutil attach -quiet -nobrowse -readonly -mountpoint "$tmp/mnt" "$tmp/$F"
+ cp -R "$tmp/mnt/CEdev" "$tmp/x/"
+ hdiutil detach -quiet "$tmp/mnt" ;;
+esac
+# (only CEdev's own folders are replaced: DIR may hold other things)
+for d in "$tmp"/x/CEdev/*; do rm -rf "${DIR:?}/$(basename "$d")"; done
+cp -R "$tmp/x/CEdev/." "$DIR/"
+echo "$F $SUM" > "$DIR/.numplay"
+"$DIR/bin/cedev-config" --version
+echo "CEdev $V is in $DIR"
diff --git a/tools/ports.py b/tools/ports.py
index f0b3b2e3..7b229f81 100644
--- a/tools/ports.py
+++ b/tools/ports.py
@@ -5,8 +5,13 @@
python3 tools/ports.py build TARGET [game...] [-j N]
`make port TARGET=...` in each game's folder, a line each
python3 tools/ports.py run [game...] the computer build (sdl) run headless for a few seconds, its
- screen saved to build/ports/shots/<game>.png
+ screen saved to build/ports/shots/<game>.png; fails if one doesn't run
+ python3 tools/ports.py list TARGET the games ported to TARGET
+ python3 tools/ports.py pack TARGET out.zip [game...]
+ the built files in a zip, with a README.txt on installing them
+ python3 tools/ports.py kit DIR DIR/ports.json for NumPlay Studio, from DIR/<target>/ (the zips' files)
+Without games named, build, run and pack take the games whose "ports" (games.json) list the target.
`probe` reads the calculator build's own commands (make -Bn build), so a game's Makefile stays the one
list of its sources."""
import concurrent.futures as cf
@@ -16,20 +21,170 @@ import re
import shlex
import subprocess
import sys
+import zipfile
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
GAMES = os.path.join(ROOT, "games")
NWLINK = os.environ.get("NWLINK", "npx --yes -- [email protected]")
SKIP = {"common", "numdance", "tetris"} # tetris: Rust, for the calculator's ARM only
+TARGETS = ("sdl", "web", "ti84ce", "nspire", "casio-cg")
+CALCULATORS = ("ti84ce", "nspire", "casio-cg")
+LIMIT = {"casio-cg": 2 << 20} # (an add-in's largest size)
-def games(args):
+def entries():
+ gs = json.load(open(os.path.join(GAMES, "games.json")))
+ bad = sorted({p for g in gs for p in g.get("ports", []) if p not in TARGETS})
+ if bad:
+ raise SystemExit(f"games.json: no target {', '.join(bad)} ({', '.join(TARGETS)})")
+ return gs
+
+
+def games(args, target=None):
+ """The games named, or the games whose "ports" list the target, or with no target every game with a Makefile."""
if args:
return args
- ids = [g["id"] for g in json.load(open(os.path.join(GAMES, "games.json")))]
+ if target:
+ if target not in TARGETS:
+ raise SystemExit(f"ports: no target {target} ({', '.join(TARGETS)})")
+ return [g["id"] for g in entries() if target in g.get("ports", [])]
+ ids = [g["id"] for g in entries()]
return [g for g in ids if g not in SKIP and os.path.exists(os.path.join(GAMES, g, "Makefile"))]
+def ce_name(g):
+ """The game's program name on the TI-84 Plus CE, as port.mk makes it: 8 letters and digits."""
+ return re.sub(r"[^A-Z0-9]", "", g.upper())[:8]
+
+
+def outputs(target, g):
+ """The files `make port` leaves for the calculator: (the path, its name in a zip)."""
+ b = os.path.join(GAMES, g, "build", target)
+ if target == "ti84ce":
+ return [(os.path.join(b, g, "bin", ce_name(g) + ".8xp"), ce_name(g) + ".8xp")]
+ if target == "nspire":
+ return [(os.path.join(b, g + ".tns"), g + ".tns")]
+ if target == "casio-cg":
+ return [(os.path.join(b, g + ".g3a"), g + ".g3a")]
+ if target == "web":
+ return [(os.path.join(b, g + ext), f"{g}/{g}{ext}") for ext in (".html", ".js", ".wasm")]
+ raise SystemExit(f"ports: nothing to pack for {target}")
+
+
+README = {
+ "ti84ce": """NumPlay for the TI-84 Plus CE and the TI-83 Premium CE
+
+How to install
+1. Send the .8xp files to the calculator with TI Connect CE (education.ti.com).
+2. Send clibs.8xg too. It's the CE C libraries the games need, from
+ github.com/CE-Programming/libraries/releases
+3. On OS 5.5 and later the calculator won't start the games by itself.
+ Install arTIfiCE (yvantt.github.io/arTIfiCE) and start them from it.
+ On an older OS, press prgm, pick a game and press enter twice.
+
+Keys
+Arrows move, enter is OK, clear is Back, mode saves and quits.
+When a game says EXE, press 2nd.
+""",
+ "nspire": """NumPlay for the TI-Nspire CX and CX II
+
+How to install
+1. Install Ndless on the calculator (ndless.me). It runs on the OS versions listed there.
+2. Send the .tns files to the calculator with TI-Nspire Computer Link or the TI-Nspire
+ software, into any folder.
+3. Open a game from My Documents.
+
+Keys
+Arrows move, enter is OK, esc is Back, home saves and quits.
+When a game says EXE, press the return key.
+""",
+ "casio-cg": """NumPlay for the Casio fx-CG50 and Graph 90+E (and the fx-CG10 and fx-CG20)
+
+How to install
+1. Connect the calculator to the computer with its USB cable and choose USB Flash (F1).
+2. Copy the .g3a files onto the calculator's drive.
+3. Eject the drive. The games are in the main menu.
+
+Keys
+Arrows move, EXE is OK, EXIT is Back, MENU saves and quits.
+When a game says EXE, press F1.
+""",
+ "web": """NumPlay in a web browser
+
+Browsers don't run these straight from the disk. Serve this folder, for example with
+ python3 -m http.server
+run in it, then open http://localhost:8000 and a game's .html file.
+
+Keys
+Arrows move, Enter is OK, Escape is Back, Home saves and quits.
+When a game says EXE, press Space.
+""",
+}
+
+
+def pack(target, out, todo):
+ """The built files of the games in a zip, flat (a folder a game for the web), with README.txt."""
+ if not todo:
+ raise SystemExit(f"pack: no game lists {target} in its ports (games.json)")
+ titles = {g["id"]: g["title"] for g in entries()}
+ files, missing = [], []
+ for g in todo:
+ fs = outputs(target, g)
+ if not all(os.path.exists(p) for p, _ in fs):
+ missing.append(g)
+ files += [(g, p, n) for p, n in fs]
+ if missing:
+ raise SystemExit(f"pack: not built for {target}: {' '.join(missing)} (python3 tools/ports.py build {target})")
+ names = [n.lower() for _, _, n in files]
+ twice = sorted({n for n in names if names.count(n) > 1})
+ if twice:
+ raise SystemExit(f"pack: two games make {' '.join(twice)}")
+ first = {}
+ for g, _, n in files:
+ first.setdefault(g, n.split("/")[0])
+ w = max(len(n) for n in first.values())
+ readme = README[target] + "\nThe games\n" + "".join(f"{first[g]:<{w}} {titles.get(g, g)}\n" for g in todo) + \
+ "\ngithub.com/Mason363/NumPlay\n"
+ os.makedirs(os.path.dirname(os.path.abspath(out)), exist_ok=True)
+ with zipfile.ZipFile(out, "w", zipfile.ZIP_DEFLATED, compresslevel=9) as z:
+ z.writestr("README.txt", readme)
+ for _, p, n in files:
+ z.write(p, n)
+ print(f"{out}: {len(todo)} games for {target}, {os.path.getsize(out) // 1024} KB")
+ for _, p, n in files:
+ if os.path.getsize(p) > LIMIT.get(target, 1 << 62):
+ print(f" {n} is {os.path.getsize(p)} bytes: the calculator takes {LIMIT[target]} at most")
+
+
+def kit(d):
+ """DIR/ports.json, what NumPlay Studio reads: each target's games, their file in DIR/<target>/ and its size."""
+ version = open(os.path.join(ROOT, "VERSION")).read().strip()
+ commit = os.environ.get("GITHUB_SHA") or subprocess.run(["git", "-C", ROOT, "rev-parse", "HEAD"],
+ capture_output=True, text=True).stdout.strip()
+ targets = {}
+ for t in CALCULATORS:
+ folder = os.path.join(d, t)
+ if not os.path.isdir(folder):
+ continue
+ there = set(os.listdir(folder)) - {"README.txt"}
+ listed = {}
+ for g in games([], t):
+ (_, name), = outputs(t, g)
+ if name not in there:
+ raise SystemExit(f"kit: {t}/{name} ({g}) missing")
+ listed[g] = {"file": name, "size": os.path.getsize(os.path.join(folder, name))}
+ extra = there - {v["file"] for v in listed.values()}
+ if extra:
+ raise SystemExit(f"kit: {t}/ has files of no game: {' '.join(sorted(extra))}")
+ targets[t] = listed
+ if not targets:
+ raise SystemExit(f"kit: no {', '.join(CALCULATORS)} folder in {d}")
+ with open(os.path.join(d, "ports.json"), "w") as f:
+ json.dump({"version": version, "commit": commit, "targets": targets}, f, indent=1)
+ f.write("\n")
+ print(f"{d}/ports.json: " + ", ".join(f"{len(v)} {t}" for t, v in targets.items()))
+
+
def probe(g):
"""The C and assembly files and the -D/-I flags of the game's calculator build."""
out = os.path.join(ROOT, "build", "data", "games", g)
@@ -136,7 +291,10 @@ def main():
print(f"{g}\n PORT_SRC = {' '.join(src)}\n PORT_ASM = {' '.join(asm)}\n PORT_FLAGS = {' '.join(flags)}")
elif cmd == "build":
target = a.pop(0)
- todo = games(a)
+ todo = games(a, target)
+ if not todo:
+ print(f"no game lists {target} in its ports (games.json)")
+ return 0
ok = 0
with cf.ThreadPoolExecutor(jobs) as ex:
for g, (good, err) in zip(todo, ex.map(lambda g: build(target, g), todo)):
@@ -145,13 +303,25 @@ def main():
print(f"{ok}/{len(todo)} build for {target}")
return 0 if ok == len(todo) else 1
elif cmd == "run":
- todo = games(a)
+ todo = games(a, "sdl")
+ if not todo:
+ print("no game lists sdl in its ports (games.json)")
+ return 0
with cf.ThreadPoolExecutor(jobs) as ex:
results = [(g, *r) for g, r in zip(todo, ex.map(run, todo))]
for g, how, _ in results:
print(f"{'ok ' if how == 'ok' else 'BAD '} {g}: {how}")
sheet(results, os.path.join(ROOT, "build", "ports", "shots.png"))
- print(f"{sum(h == 'ok' for _, h, _ in results)}/{len(results)} run; build/ports/shots.png")
+ good = sum(h == "ok" for _, h, _ in results)
+ print(f"{good}/{len(results)} run; build/ports/shots.png")
+ return 0 if good == len(results) else 1
+ elif cmd == "list" and len(a) == 1:
+ print("\n".join(games([], a[0])))
+ elif cmd == "pack" and len(a) >= 2:
+ target, out = a[0], a[1]
+ pack(target, out, games(a[2:], target))
+ elif cmd == "kit" and len(a) == 1:
+ kit(a[0])
else:
print(__doc__)
return 1