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
Retro-Go: ROMs without their padding
Mason363dadf1ee716cb
diff --git a/customize/app.js b/customize/app.jsindex dce89f4d..ad7458f3 100644--- a/customize/app.js+++ b/customize/app.js@@ -412,6 +412,18 @@render();}+ // A ROM without the padding its file has to reach a power of two (16 KB banks at its end, all 0xFF or all 0x00):+ // the cores repeat the banks a game has for those it lacks, as a flash cart does (tools/romtable.py's trim)+ function trimRom(bytes, sys) {+ const B = 16384;+ if (![1, 2, 4, 5, 6].includes(sys) || bytes.length % B) return bytes;+ const keep = sys <= 2 ? 0x8000 : bytes.length <= 0x8000 ? bytes.length : 0xC000, pad = bytes[bytes.length - 1];+ if (pad !== 0x00 && pad !== 0xFF) return bytes;+ let n = bytes.length;+ while (n - B >= keep && bytes.subarray(n - B, n).every((v) => v === pad)) n -= B;+ return n < bytes.length ? bytes.slice(0, n) : bytes;+ }+async function addRoms(files) {if (solo()) { bump($('#drop'), 'shake'); toast(byId[solo()].title + " takes the whole calculator, so there's no room for Retro-Go"); return; }const ok = new Set(rg && rg.systems ? rg.systems : [1, 2, 3]);@@ -421,7 +433,7 @@toast('Retro-Go plays ' + [...ok].map((s) => SYS[s].name).join(', ').replace(/, ([^,]*)$/, ' and $1') + ' games');continue;}- const bytes = new Uint8Array(await f.arrayBuffer());+ const bytes = trimRom(new Uint8Array(await f.arrayBuffer()), sys);const r = { key: ++romKey, sys, bytes, name: romName(f.name) };const over = total(ordered(), st.roms.concat([r])) - capacity();if (over > 0) { bump($('#drop'), 'shake'); tooBig(r) || overflow(over); continue; }diff --git a/games/retrogo/README.md b/games/retrogo/README.mdindex 38e25899..f3c583d0 100644--- a/games/retrogo/README.md+++ b/games/retrogo/README.md@@ -57,6 +57,7 @@ In 1x on the Game Boy and the Game Gear, the keys are written on the side of the## Good to know- No sound: the calculator has no speaker.+- Game Boy and Sega games go in without the empty space their files are padded with (up to a quarter of a game), so more of them fit.- The calculator has about 42 KB for every app's saves. A Game Boy or NES state takes 2 to 10 KB, a Master System or Game Gear one 3 to 15 KB, a Game Boy Color one up to 30 KB, so keep the slots you need and delete the others in the launcher (Delete save).- The calculator has no clock for apps: a Game Boy game's clock runs while you play, and you can set it in Options, RTC config.- Cartridges with more than 32 KB of RAM (a few Game Boy Color games) and NES mappers nofrendo doesn't have say so instead of starting.diff --git a/tools/romtable.py b/tools/romtable.pyindex 2d9b3ef7..492f0ebf 100644--- a/tools/romtable.py+++ b/tools/romtable.py@@ -40,13 +40,28 @@ def entry_name(path):return name[:k]+def trim(data, system):+ """The padding a ROM's file has to reach a power of two (16 KB banks at its end, all 0xFF or all 0x00) left out:+ the cores repeat the banks a game has for those it lacks, as a flash cart does, and games never read their padding.+ Not for NES files (their banks follow a header) or ColecoVision; the Master System's 32 KB rule stays as it was."""+ if system not in (1, 2, 4, 5, 6) or len(data) % 16384:+ return data+ keep = 0x8000 if system <= 2 else (len(data) if len(data) <= 0x8000 else 0xC000)+ pad, n = data[-1], len(data)+ if pad not in (0x00, 0xFF):+ return data+ while n - 16384 >= keep and data[n - 16384:n].count(pad) == 16384:+ n -= 16384+ return data[:n]++def table(paths):roms = []for p in paths:ext = os.path.splitext(p)[1].lower()if ext not in SYSTEMS:sys.exit(f"romtable: {p}: not a .gb, .gbc, .nes, .sms, .gg, .sg or .col file")- roms.append((open(p, "rb").read(), SYSTEMS[ext], entry_name(p)))+ roms.append((trim(open(p, "rb").read(), SYSTEMS[ext]), SYSTEMS[ext], entry_name(p)))out = bytearray(struct.pack("<III", MAGIC, VERSION, len(roms)))out += bytes(ENTRY * len(roms))for i, (data, system, name) in enumerate(roms):