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.

Tests: NumPlays with big games, linked from the kit and played in the emulator

Mason3634a9759f0340b
diff --git a/tests/test_games.py b/tests/test_games.py
index 97628a3d..f027135d 100644
--- a/tests/test_games.py
+++ b/tests/test_games.py
@@ -349,12 +349,13 @@ def records(buf):
raise ValueError("no end of the record list")
-def through_launcher(index, keys, home):
- """The same session, started from NumPlay's carousel (game `index`)."""
+def through_launcher(index, keys, home, start=800):
+ """The same session, started from NumPlay's carousel (game `index`); the game's keys come `start` ms
+ after OK on its card."""
lead = [(1200 + 300 * i, 1290 + 300 * i, K["right"]) for i in range(index)]
ok = 1500 + 300 * index
lead.append((ok, ok + 90, K["ok"]))
- shift = ok + 800
+ shift = ok + start
return lead + [(a + shift, b + shift, k) for a, b, k in keys], home + shift
@@ -382,6 +383,77 @@ def run_once(nwa, storage, keys, home, out, tag, quit_key="home"):
return c, problems, stack
+def play(name, path, out, index=None, copy=None, tag=None, start=800):
+ """The two sessions of a game, in the app at path (a NumPlay when index, the game's place in its
+ carousel, is given; start: when its keys begin after OK on its card). copy: the script that holds the
+ game's own copy of its saves: only the scripts are left before the second session, as after installing
+ the app again. The problems, the stack used and the files after the first session."""
+ nwa, save, keys1, home1, keys2, home2 = GAMES[name]
+ tag = tag or name
+ if index is not None: # Home in a game quits NumPlay altogether
+ keys1, home1 = through_launcher(index, keys1, home1, start)
+ keys2, home2 = through_launcher(index, keys2, home2, start)
+ with tempfile.TemporaryDirectory() as d:
+ storage = os.path.join(d, "storage.bin")
+ # the calculator already has a script
+ pre = [("pi.py", b"\x01print(3.14159)\n")]
+ if name in SEEDS:
+ pre.append((save, SEEDS[name]))
+ buf = bytearray(emu.STORAGE_SIZE)
+ p = 0
+ for rn, content in pre:
+ size = 2 + len(rn) + 1 + len(content)
+ struct.pack_into("<H", buf, p, size)
+ buf[p + 2:p + size] = rn.encode() + b"\0" + content
+ p += size
+ open(storage, "wb").write(buf)
+ c, problems, stack = run_once(path, storage, keys1, home1, out, f"{tag}_1")
+ recs = dict(records(open(storage, "rb").read()))
+ if recs.get("pi.py") != pre[0][1]:
+ problems.append("pi.py changed")
+ if save and save not in recs:
+ problems.append(f"{save} not written")
+ elif name in CHECKS and not CHECKS[name][0](recs[save]):
+ problems.append(f"{save} not updated")
+ # a script added after the save, then a second session
+ buf = bytearray(open(storage, "rb").read())
+ lst = records(buf)
+ if copy:
+ text = dict(lst).get(copy, b"")
+ mark = b"#>" + save.encode() + b":"
+ line = text[text.find(mark) + len(mark):].split(b"\n")[0] if mark in text else b""
+ if not line or __import__("base64").b64decode(line) != dict(lst).get(save):
+ problems.append(f"{copy} does not hold {save}")
+ lst = [(n, v) for n, v in lst if n.endswith(".py")]
+ buf = bytearray(emu.STORAGE_SIZE)
+ q = 0
+ for n, v in lst:
+ struct.pack_into("<H", buf, q, 2 + len(n) + 1 + len(v))
+ buf[q + 2:q + 3 + len(n) + len(v)] = n.encode() + b"\0" + v
+ q += 2 + len(n) + 1 + len(v)
+ p = sum(2 + len(n) + 1 + len(v) for n, v in lst)
+ late = b"\x01print('later')\n"
+ size = 2 + len("late.py") + 1 + len(late)
+ struct.pack_into("<H", buf, p, size)
+ buf[p + 2:p + size] = b"late.py\0" + late
+ struct.pack_into("<H", buf, p + size, 0)
+ open(storage, "wb").write(buf)
+ # (quitting with On/Off this time: it saves and leaves as Home does)
+ c2, problems2, stack2 = run_once(path, storage, keys2, home2, out, f"{tag}_2", "onoff")
+ problems += [f"second run: {x}" for x in problems2]
+ try:
+ recs2 = dict(records(open(storage, "rb").read()))
+ if recs2.get("pi.py") != pre[0][1] or recs2.get("late.py") != late:
+ problems.append("second run: other files changed")
+ if save and save not in recs2:
+ problems.append(f"second run: {save} lost")
+ elif name in CHECKS and not CHECKS[name][1](recs2[save]):
+ problems.append(f"second run: {save} not updated")
+ except ValueError as e:
+ problems.append(f"second run: file system corrupt ({e})")
+ return problems, max(stack, stack2), recs
+
+
def main():
ap = argparse.ArgumentParser()
ap.add_argument("apps")
@@ -393,75 +465,16 @@ def main():
"games.json"))) if g.get("default", True)]
os.makedirs(a.out, exist_ok=True)
failed = False
- for name, (nwa, save, keys1, home1, keys2, home2) in GAMES.items():
+ for name in GAMES:
if a.game and a.game != name or a.numplay and name not in order: # (a big game: on its own only)
continue
- path = os.path.join(a.apps, nwa)
- if a.numplay: # Home in a game quits NumPlay altogether
- path = a.numplay
- keys1, home1 = through_launcher(order.index(name), keys1, home1)
- keys2, home2 = through_launcher(order.index(name), keys2, home2)
- with tempfile.TemporaryDirectory() as d:
- storage = os.path.join(d, "storage.bin")
- # the calculator already has a script
- pre = [("pi.py", b"\x01print(3.14159)\n")]
- if name in SEEDS:
- pre.append((save, SEEDS[name]))
- buf = bytearray(emu.STORAGE_SIZE)
- p = 0
- for rn, content in pre:
- size = 2 + len(rn) + 1 + len(content)
- struct.pack_into("<H", buf, p, size)
- buf[p + 2:p + size] = rn.encode() + b"\0" + content
- p += size
- open(storage, "wb").write(buf)
- c, problems, stack = run_once(path, storage, keys1, home1, a.out, f"{name}_1")
- recs = dict(records(open(storage, "rb").read()))
- if recs.get("pi.py") != pre[0][1]:
- problems.append("pi.py changed")
- if save and save not in recs:
- problems.append(f"{save} not written")
- elif name in CHECKS and not CHECKS[name][0](recs[save]):
- problems.append(f"{save} not updated")
- # a script added after the save, then a second session
- buf = bytearray(open(storage, "rb").read())
- lst = records(buf)
- if name in COPIES and not a.numplay: # (NumPlay's own copy, packed: tests/test_progress.py)
- copy = dict(lst).get(COPIES[name], b"")
- tag = b"#>" + save.encode() + b":"
- line = copy[copy.find(tag) + len(tag):].split(b"\n")[0] if tag in copy else b""
- if not line or __import__("base64").b64decode(line) != dict(lst).get(save):
- problems.append(f"{COPIES[name]} does not hold {save}")
- lst = [(n, v) for n, v in lst if n.endswith(".py")]
- buf = bytearray(emu.STORAGE_SIZE)
- q = 0
- for n, v in lst:
- struct.pack_into("<H", buf, q, 2 + len(n) + 1 + len(v))
- buf[q + 2:q + 3 + len(n) + len(v)] = n.encode() + b"\0" + v
- q += 2 + len(n) + 1 + len(v)
- p = sum(2 + len(n) + 1 + len(v) for n, v in lst)
- late = b"\x01print('later')\n"
- size = 2 + len("late.py") + 1 + len(late)
- struct.pack_into("<H", buf, p, size)
- buf[p + 2:p + size] = b"late.py\0" + late
- struct.pack_into("<H", buf, p + size, 0)
- open(storage, "wb").write(buf)
- # (quitting with On/Off this time: it saves and leaves as Home does)
- c2, problems2, stack2 = run_once(path, storage, keys2, home2, a.out, f"{name}_2", "onoff")
- problems += [f"second run: {x}" for x in problems2]
- try:
- recs2 = dict(records(open(storage, "rb").read()))
- if recs2.get("pi.py") != pre[0][1] or recs2.get("late.py") != late:
- problems.append("second run: other files changed")
- if save and save not in recs2:
- problems.append(f"second run: {save} lost")
- elif name in CHECKS and not CHECKS[name][1](recs2[save]):
- problems.append(f"second run: {save} not updated")
- except ValueError as e:
- problems.append(f"second run: file system corrupt ({e})")
+ if a.numplay: # (NumPlay keeps its own copy, packed: tests/test_progress.py)
+ problems, stack, recs = play(name, a.numplay, a.out, order.index(name))
+ else:
+ problems, stack, recs = play(name, os.path.join(a.apps, GAMES[name][0]), a.out, copy=COPIES.get(name))
status = "ok" if not problems else "FAIL"
failed |= bool(problems)
- print(f"{name:11s} {status} stack {max(stack, stack2)} bytes, files {sorted(recs)}", flush=True)
+ print(f"{name:11s} {status} stack {stack} bytes, files {sorted(recs)}", flush=True)
for x in problems:
print(" ", x)
sys.exit(1 if failed else 0)
diff --git a/tests/test_kit.py b/tests/test_kit.py
new file mode 100644
index 00000000..25a13fd5
--- /dev/null
+++ b/tests/test_kit.py
@@ -0,0 +1,252 @@
+#!/usr/bin/env python3
+"""Links NumPlays of your own from the kit (`make kit`), the way the customizer website does (GNU ld on
+the kit's objects, with a script of script.json's parts), and plays their games through the launcher
+in the ARM emulator, with tests/test_games.py's sessions:
+
+- alone: each big game alone in a NumPlay of the calculator's app space (APP_SPACE), where it fits;
+- sets: several big games, and big games with small ones, in a NumPlay for Enlarged Extra Apps (up to
+ 6291456 bytes, 0x90200000 to the external flash's end: the emulator's apps go on there while the
+ userland header still says the app area ends at 0x903F0000, as on a calculator with nwagyu's Nwagra);
+- ram: each big game's RAM inside NumPlay, against custom builds of 25.2 (133652 bytes), 23.2 (148928)
+ and Upsilon (107674). The games play with the least the calculators give where they fit, and where
+ one doesn't, OK on its card doesn't start it (the card says how much it lacks);
+- probe: each big game alone with --ram bytes of RAM, whatever it needs (to find the least it plays in).
+
+In each session the game starts and plays, saves, and finds its saves again from its own copy as after
+installing NumPlay again; Home and On/Off take you back out of NumPlay, which clears the RAM, with no
+access outside the app's RAM, no write to flash or to the firmware's RAM. nwlink nwa-bin links each
+NumPlay at the app area's start with its whole space (6 MB for the sets).
+
+Usage: test_kit.py [--kit build/site-kit] [--only alone,sets,ram,probe] [--game ID] [--set N] [--ram N]
+ [--out DIR]
+"""
+import argparse
+import gzip
+import json
+import os
+import subprocess
+import sys
+import tempfile
+
+sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "tools"))
+sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
+import emu # noqa: E402
+import test_games # noqa: E402
+from unicorn import UC_HOOK_CODE # noqa: E402
+from unicorn.arm_const import UC_ARM_REG_R0 # noqa: E402
+
+ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
+CUSTOM_RAM, RAM_LIMIT, UPSILON_RAM = 133652, 148928, 107674
+MANIFEST = json.load(open(os.path.join(ROOT, "games", "games.json")))
+XL = [g["id"] for g in MANIFEST if g.get("xl")] # the big games
+SMALL = [g["id"] for g in MANIFEST if g.get("default", True)] # NumPlay's own
+# NumPlays for Enlarged Extra Apps: the three biggest; five more; four more; three with all of NumPlay's games
+SETS = [
+ ["celeste", "hollowknight", "championisland"],
+ ["undertale", "doom", "pvz", "numpowder", "leveldevil"],
+ ["cookieclicker", "subway", "fnaf", "isaac"],
+ SMALL + ["sonic", "hillclimb", "finalearth2"],
+]
+
+
+class Kit:
+ def __init__(self, path, tmp):
+ self.path, self.tmp = path, tmp
+ self.k = json.load(open(os.path.join(path, "kit.json")))
+ self.games = {g["id"]: g for g in self.k["games"]}
+
+ def obj(self, rel):
+ out = os.path.join(self.tmp, rel.replace("/", "_"))
+ if not os.path.exists(out):
+ with gzip.open(os.path.join(self.path, rel + ".gz")) as f, open(out, "wb") as g:
+ g.write(f.read())
+ return out
+
+ def link(self, ids, out):
+ """A NumPlay with these games, in games.json's order (the big games last, past the small ones)."""
+ ids = sorted(ids, key=lambda i: self.games[i]["index"])
+ s = self.k["script"]
+ script = out[:-4] + ".ld"
+ open(script, "w").write(s["head"] + "".join(s["blocks"][i] for i in ids) + s["tail"])
+ objs = [self.obj("base.o"), self.obj("arena.o"), self.obj("variants/NumPlay-name.o"),
+ self.obj("variants/NumPlay-icon.o")] + [self.obj(f"games/{i}.o") for i in ids]
+ subprocess.run(["arm-none-eabi-ld"] + self.k["link"] + ["-T", script] + objs + ["-o", out], check=True)
+ subprocess.run(["arm-none-eabi-strip", "--strip-unneeded", out], check=True)
+ return ids
+
+ def ram(self, i):
+ """what a game needs of the RAM apps get, inside NumPlay"""
+ return self.k["launcherRam"] + self.games[i]["ram"]
+
+
+def installed(nwa, space, ram=RAM_LIMIT):
+ """the bytes nwlink installs, linked at the app area's start with this much space"""
+ b = nwa[:-4] + ".bin"
+ r = subprocess.run(["nwlink", "nwa-bin", "--flash-start", hex(emu.EXT_FLASH_START), "--flash-length", str(space),
+ "--ram-length", str(ram), nwa, b], capture_output=True, text=True)
+ return os.path.getsize(b) if r.returncode == 0 else None, (r.stdout + r.stderr).strip()
+
+
+def watch(c, kit_ids):
+ """the games' entries and the heap their malloc takes (np_sbrk), as the emulator runs"""
+ c.entered, c.heap, c.heap_max = {}, 0, 0
+ for i in kit_ids:
+ a = c.symbols.get(f"np_{i}_main")
+ if a is not None:
+ c.uc.hook_add(UC_HOOK_CODE, lambda uc, addr, size, gid: c.entered.setdefault(gid, c.now_ms), i,
+ begin=a & ~1, end=(a & ~1) + 1)
+ a = c.symbols.get("np_sbrk")
+ if a is not None:
+ def sbrk(uc, addr, size, data):
+ n = uc.reg_read(UC_ARM_REG_R0)
+ c.heap += n - (1 << 32) if n & 0x80000000 else n
+ c.heap_max = max(c.heap_max, c.heap)
+ c.uc.hook_add(UC_HOOK_CODE, sbrk, begin=a & ~1, end=(a & ~1) + 1)
+
+
+# the emulator's Calculator, watched (test_games.run_once makes its own)
+_Calculator = emu.Calculator
+LAST = []
+
+
+class Watched(_Calculator):
+ def __init__(self, *a, **k):
+ super().__init__(*a, **k)
+ watch(self, XL + SMALL)
+ LAST.append(self)
+
+
+emu.Calculator = Watched
+
+
+def started(nwa, index):
+ """how long after OK on its card the game at index starts in this NumPlay"""
+ c = Watched(nwa)
+ keys, _ = test_games.through_launcher(index, [], 0)
+ c.keys = keys
+ ok = keys[-1][0]
+ while not c.entered and c.now_ms < ok + 5000:
+ c.run(c.now_ms + 100)
+ return int(min(c.entered.values()) - ok) + 1 if c.entered else 800
+
+
+def session(nwa, ids, name, out, tag):
+ """test_games' two sessions of a game in this NumPlay, with its keys from when it starts (as on its own);
+ its own copy brings its saves back"""
+ start = started(nwa, ids.index(name))
+ LAST.clear()
+ problems, stack, recs = test_games.play(name, nwa, out, ids.index(name), copy=test_games.COPIES.get(name)
+ if name in XL else None, tag=tag, start=start)
+ for c in LAST:
+ if name not in c.entered:
+ problems.append("the game did not start")
+ heap = max((c.heap_max for c in LAST), default=0)
+ return problems, stack, heap
+
+
+def report(tag, problems, extra=""):
+ print(f"{tag:34s} {'ok' if not problems else 'FAIL'} {extra}", flush=True)
+ for x in problems:
+ print(" ", x)
+ return bool(problems)
+
+
+def main():
+ ap = argparse.ArgumentParser()
+ ap.add_argument("--kit", default=os.path.join(ROOT, "build", "site-kit"))
+ ap.add_argument("--only", default="alone,sets,ram")
+ ap.add_argument("--game", help="only this big game (alone, ram)")
+ ap.add_argument("--set", type=int, help="only this set (0, 1...)")
+ ap.add_argument("--ram", type=int, help="the RAM apps get (alone, sets; default: the least they fit in)")
+ ap.add_argument("--out", default=os.path.join(ROOT, "build", "test_kit"))
+ a = ap.parse_args()
+ os.makedirs(a.out, exist_ok=True)
+ only = a.only.split(",")
+ failed = False
+ tmp = tempfile.mkdtemp()
+ kit = Kit(a.kit, tmp)
+ k = kit.k
+ xl = [i for i in XL if not a.game or i == a.game]
+ print(f"kit {k['version']}: NumPlay's own flash {k['base']} bytes, its own RAM {k['launcherRam']} bytes, "
+ f"app space {k['appSpace']} ({k['xlAppSpace']} with Enlarged Extra Apps)")
+
+ if "alone" in only:
+ for i in xl:
+ nwa = os.path.join(tmp, f"alone-{i}.nwa")
+ ids = kit.link([i], nwa)
+ size, msg = installed(nwa, k["appSpace"])
+ g = kit.games[i]
+ if size is None or size > k["appSpace"]:
+ # too big for the app space next to the launcher: then only with Enlarged Extra Apps
+ big, msg2 = installed(nwa, k["xlAppSpace"])
+ problems = [] if big and big > k["appSpace"] else [f"nwa-bin: {msg or msg2}"]
+ failed |= report(f"alone {i}", problems, f"{big} bytes, {big - k['appSpace']} over the app space: "
+ "only with Enlarged Extra Apps" if big else "")
+ continue
+ emu.configure("n0120", "epsilon", a.ram or (CUSTOM_RAM if kit.ram(i) <= CUSTOM_RAM else RAM_LIMIT))
+ problems, stack, heap = session(nwa, ids, i, a.out, f"alone_{i}")
+ failed |= report(f"alone {i}", problems, f"{size} bytes ({k['appSpace'] - size} to spare), RAM "
+ f"{emu.EXT_RAM_LEN}, stack {stack}, malloc {heap}, game flash {g['flash']}")
+
+ if "probe" in only: # (each big game alone, with --ram bytes of RAM whatever it needs, 6 MB of app space)
+ for i in xl:
+ nwa = os.path.join(tmp, f"probe-{i}.nwa")
+ ids = kit.link([i], nwa)
+ emu.configure("n0120", "epsilon", a.ram, xl=True)
+ problems, stack, heap = session(nwa, ids, i, a.out, f"probe_{i}_{a.ram}")
+ failed |= report(f"probe {i}", problems, f"RAM {emu.EXT_RAM_LEN} (it needs {kit.ram(i)}), malloc {heap}")
+
+ if "sets" in only:
+ for n, s in enumerate(SETS):
+ if a.set is not None and a.set != n:
+ continue
+ nwa = os.path.join(tmp, f"set{n}.nwa")
+ ids = kit.link(s, nwa)
+ size, msg = installed(nwa, k["xlAppSpace"])
+ if size is None or size > k["xlAppSpace"]:
+ failed |= report(f"set {n}", [f"does not install in {k['xlAppSpace']} bytes: {msg}"])
+ continue
+ print(f"set {n}: {len(ids)} games, {size} bytes ({k['xlAppSpace'] - size} to spare of 6 MB)", flush=True)
+ emu.configure("n0120", "epsilon", a.ram, xl=True)
+ # the big games, and a few of the small ones, played where they are
+ for i in [x for x in ids if x in XL] + [x for x in ids if x in SMALL][:3]:
+ problems, stack, heap = session(nwa, ids, i, a.out, f"set{n}_{i}")
+ failed |= report(f" set {n}: {i}", problems, f"stack {stack}, malloc {heap}")
+
+ if "ram" in only:
+ print(f"{'RAM in NumPlay':18s} {'needs':>7s} {'133652':>8s} {'148928':>8s} {'107674':>8s}")
+ for i in xl:
+ need = kit.ram(i)
+ fit = ["fits" if need <= r else f"-{need - r}" for r in (CUSTOM_RAM, RAM_LIMIT, UPSILON_RAM)]
+ print(f" {i:16s} {need:7d} {fit[0]:>8s} {fit[1]:>8s} {fit[2]:>8s} (heap {kit.games[i]['heap']})",
+ flush=True)
+ # where a game doesn't fit, its card's OK doesn't start it, and Home leaves cleanly
+ for i in xl:
+ short = [r for r in (UPSILON_RAM, CUSTOM_RAM, RAM_LIMIT) if kit.ram(i) > r]
+ if not short:
+ continue
+ nwa = os.path.join(tmp, f"alone-{i}.nwa")
+ ids = kit.link([i], nwa)
+ r = max(short)
+ emu.configure("n0120", "epsilon", r, xl=True)
+ st = os.path.join(tmp, f"short-{i}.bin")
+ open(st, "wb").write(bytes(emu.STORAGE_SIZE))
+ c = Watched(nwa, storage_file=st)
+ c.enable_checks(reads=True)
+ keys, home = test_games.through_launcher(0, [], 1500)
+ c.keys = keys + [(home + 1500, home + 1900, emu.KEYS["home"])]
+ c.pending_shots = [(home, os.path.join(a.out, f"short_{i}_{r}.png"))]
+ c.run(home + 5000)
+ problems = sorted(set(c.violations))[:8]
+ if i in c.entered:
+ problems.append(f"started with {r} bytes of RAM, {kit.ram(i) - r} too few")
+ if not c.exited:
+ problems.append("did not quit on Home")
+ if not c.app_ram_clean():
+ problems.append("RAM not cleared on exit")
+ failed |= report(f"short {i} ({r})", problems, "not started: its card says it needs more")
+ sys.exit(1 if failed else 0)
+
+
+if __name__ == "__main__":
+ main()
diff --git a/tests/test_uninstall.py b/tests/test_uninstall.py
index a8802295..e9f85fe8 100644
--- a/tests/test_uninstall.py
+++ b/tests/test_uninstall.py
@@ -86,7 +86,7 @@ def main():
keys.append((t, t + 90, emu.KEYS["right"])) # choose Uninstall
hold = t + 500
keys.append((hold, hold + 1800, emu.KEYS["ok"])) # hold OK to confirm
- t = hold + 1800 + 5000
+ t = hold + 1800 + 5000 + 400 * ((end - begin) // SECTOR) # (a big game's sectors take a while to erase)
done = t - 200
keys.append((t, t + 90, emu.KEYS["ok"])) # dismiss "was uninstalled"
t += 1000
diff --git a/tools/emu.py b/tools/emu.py
index 7bab5af3..e798db03 100644
--- a/tools/emu.py
+++ b/tools/emu.py
@@ -50,19 +50,25 @@ EXT_RAM_START = EXT_RAM_END - EXT_RAM_LEN
STACK_TOP = 0x2403F000
EXT_FLASH_START = 0x90200000
EXT_FLASH_END = 0x903F0000
+# where installed apps may reach: the app area's end, or with Enlarged Extra Apps (nwagyu's Nwagra, which
+# tells the app loader the space goes on over the second copy of the software) the external flash's end
+APPS_END = EXT_FLASH_END
+XL_APPS_END = 0x90800000
CPU_HZ = 216_000_000
MODEL, SYSTEM = "n0120", "epsilon"
-def configure(model="n0120", system="epsilon", ram_length=None):
+def configure(model="n0120", system="epsilon", ram_length=None, xl=False):
"""The calculator to emulate: the N0120 (RAM at 0x24000000, the userland after an extra data
sector) or the N0110/N0115 (RAM at 0x20000000); Epsilon or Upsilon (its userland header has no
device name, apps get 107674 bytes of RAM, its file system is Epsilon 15's and it has none of
the system calls for Home, checksums or flash). ram_length: the RAM apps get, when another
- build of the software gives them another amount."""
+ build of the software gives them another amount. xl: Enlarged Extra Apps, an app up to the
+ external flash's end (its userland header still says the app area ends at 0x903F0000)."""
global MODEL, SYSTEM, SRAM, USERLAND_HEADER, STORAGE, STORAGE_SIZE, EXT_RAM_END, EXT_RAM_LEN, EXT_RAM_START, \
- STACK_TOP
+ STACK_TOP, APPS_END
MODEL, SYSTEM = model, system
+ APPS_END = XL_APPS_END if xl else EXT_FLASH_END
SRAM = 0x20000000 if model == "n0110" else 0x24000000
USERLAND_HEADER = 0x90010000 if model == "n0110" else 0x90020000
STORAGE = SRAM + 0x1000
@@ -173,7 +179,7 @@ class Calculator:
with tempfile.TemporaryDirectory() as d:
elf = os.path.join(d, "app.elf")
cmd = [nwlink, "nwa-elf", nwa, elf, "--flash-start", hex(flash_start), "--flash-length",
- hex(EXT_FLASH_END - flash_start), "--ram-start", hex(EXT_RAM_START), "--ram-length",
+ hex(APPS_END - flash_start), "--ram-start", hex(EXT_RAM_START), "--ram-length",
str(EXT_RAM_LEN), "--trampoline-start", hex(TRAMPOLINE)]
if external_data:
cmd += ["--external-data", external_data]
@@ -565,12 +571,13 @@ def main():
ap.add_argument("--model", choices=["n0120", "n0110"], default="n0120")
ap.add_argument("--system", choices=["epsilon", "upsilon"], default="epsilon")
ap.add_argument("--ram-length", type=int, help="the RAM apps get (default: the system's)")
+ ap.add_argument("--xl", action="store_true", help="Enlarged Extra Apps: an app up to 6 MB")
ap.add_argument("--records", action="store_true", help="list storage records at the end")
ap.add_argument("--frames", help="save raw RGB565 frames here (for tools/record.py --frames)")
ap.add_argument("--profile", type=int, default=0,
help="print the N functions the CPU was found in most (build the .nwa without stripping it)")
a = ap.parse_args()
- configure(a.model, a.system, a.ram_length)
+ configure(a.model, a.system, a.ram_length, a.xl)
os.makedirs(a.out, exist_ok=True)
c = Calculator(a.nwa, a.flash_start, a.storage, a.nwlink)
c.keys = parse_keys(a.keys)