A complete fantasy console built from the very scratch — with the explicit goal of being extremely portable ("compiles and runs on any chip").
See GOALS.md for the full ambitious vision, success criteria, "any chip" portability requirements, non-negotiables, and how the agent swarm is building it in parallel tracks.
Current status: The portable #![no_std] core (graphics primitives, Console, Cart trait, 3 demos) is in src/lib.rs and already cross-checks for desktop + wasm + embedded targets. The desktop runner is now a thin layer on top. Chiptune audio, editors, real cartridge format (.s8), web runtime, and many game examples are being built right now by the swarm.
New in this pass (Documentation & Examples track):
docs/TUTORIAL.md— write your first interactive cart in ~15 minutesdocs/HARDWARE.md,docs/CARTRIDGE_FORMAT.md(in progress)examples/pong.rsandexamples/snake.rs— two polished, self-contained, fully documented game carts using only the public API (plus more planned)TODO.md— master task tracker for the swarm
All new material prioritizes clarity, the "from the very scratch" philosophy, and concrete copy-paste-ready code.
Everything that matters is implemented by us:
- 128×128 pixel display, locked to a 16-color palette (PICO-8 inspired).
- A pure-Rust software framebuffer. All drawing primitives (
pset,rect,circ,line(Bresenham),printwith a hand-authored 4×6 font, etc.) are written pixel-by-pixel with no external 2D drawing libraries. - 60 FPS locked loop.
- Classic 6-button + mouse input.
- Cartridge system via a tiny
Carttrait. Making a new "game" means writing a small Rust struct that calls theConsoleAPI.
This is the real core of a fantasy console — the machine and the constraints — not a wrapper around a game engine.
- ✅ 128×128 × 16 colors, enforced by design (16 KB "VRAM")
- ✅ All drawing primitives from scratch (Bresenham line, midpoint-ish circle, filled shapes, custom font)
- ✅ 3 playable demo carts (built into the core for immediate use):
- BOUNCER — classic bouncing ball that changes color + uses lines
- PAINTER — mouse painting with trails + pget demo
- PARTICLES — gravity fountain you can influence with Z/X
- ✅ Cart switching with 1/2/3 keys (exactly the fantasy console feel)
- ✅ Frame counter, btn/btnp style input
- ✅ Boot screen
- ✅ High-quality standalone examples in
examples/: Pong and Snake (see below) - ✅ World-class starting documentation: TUTORIAL.md + HARDWARE.md seed + CARTRIDGE_FORMAT.md seed + this README + rustdoc
- ✅ Chiptune Audio (audio-chiptune track complete): Full from-scratch PSG in
src/audio.rs(feature "audio").- 4 channels: pulse (variable duty 12.5/25/50/75%), triangle, LFSR noise.
- Envelopes (simple decay+release), vibrato (triangle LFO), frequency slide/portamento.
- PICO-8 style API:
tone(freq, dur, vol, wave),sfx(id, vol),play_music(pattern, bpm)+ low-level. - Pattern player: multi-voice tracker-style sequencer (fixed arrays, sample-accurate).
- Mixer:
fill_buffer_i16/fill_buffer_f32— pure math, any sample rate, no_std friendly. - Desktop: cpal real-time output wired; press 4 for the CHIPTUNE demo cart (plays a bouncy pattern + live sfx on Z/X, visualizer).
- All synthesis (phase accum, osc math, 16-bit LFSR, state machines) written by hand — zero synth crates.
Not yet implemented (but planned):
- Sprites + tilemaps +
spr()/map()API + sprite editor - Sprites + tilemaps +
spr()/map()API + sprite editor - In-console code + sprite + map + music editors
- Real cartridge file format (
.s8or PNG-encoded like PICO-8) - Custom scripting language or first-class WASM cart support (so non-Rust people can write carts easily)
- Export to web / standalone player
See TODO.md for the detailed swarm task list (game-examples, documentation, etc.).
cd ~/projects/scratch8
cargo run --release- Escape to quit
- 1 / 2 / 3 to switch demo carts
- Arrows + Z/X (or O/K) for input inside carts
- Mouse works in PAINTER
See examples/ for two additional high-quality standalone games (Pong, Snake) you can study or integrate. The docs/TUTORIAL.md gives a complete guided path.
Best starting point: Read docs/TUTORIAL.md ("Your first cart in 15 minutes"). It walks you from a blank struct all the way to a complete playable catcher game with physics, scoring, multiple primitives, and input.
-
Study a complete working example:
examples/pong.rsorexamples/snake.rs. They are self-contained, heavily commented, and demonstrate real gameplay using only the publicConsole+CartAPI. -
Copy the struct +
impl Cartpattern (or the whole file) into your project. -
For now (until the
.s8loader + editors land), register it in the desktop runner:
Open src/main.rs and add your cart (copy one of the existing ones as a template):
struct MyGame {
// your state here
}
impl Cart for MyGame {
fn name(&self) -> &'static str { "MY GAME" }
fn init(&mut self, c: &mut Console) {
c.cls(0);
}
fn update(&mut self, c: &mut Console) {
c.cls(1);
// draw whatever you want using the pure primitives
c.print("HELLO FROM SCRATCH", 10, 50, 7);
if c.btn[4] {
c.circ(64, 64, 20, 8);
}
}
}Add it to the list in main():
let mut carts: Vec<Box<dyn Cart>> = vec![
Box::new(Bouncer::new()),
Box::new(MyGame::new()),
...
];That's it. cargo run --release — your cart is now a first-class citizen switchable with 1/2/3.
The carts in examples/ include a small main() that runs a headless simulation loop. This lets you do:
cargo check --examples
cargo run --example pong
cargo run --example snakeThese always succeed using only the library (no windowing required) and prove your code is a valid, portable consumer of the Console + Cart public surface.
All the "hardware" (the Console methods) is deliberately tiny and constrained so that the experience feels like a real 8-bit fantasy machine. Full API reference is in the rustdoc (cargo doc --open) and the source comments in src/lib.rs.
- Built-in (always available, switch with 1/2/3):
- BOUNCER, PAINTER, PARTICLES (see
src/lib.rs)
- BOUNCER, PAINTER, PARTICLES (see
- Standalone polished games (in
examples/— copy thestruct + impl Cart):pong.rs— classic Pong with AI opponent, serve, scoring to 7, english on bounces, full use of rect/circ/line/printsnake.rs— full Snake on a 32×32 grid using fixed arrays (portable), timed steps, btnp turns, growth, death/restart
- Guided path:
docs/TUTORIAL.mdbuilds a complete "Catcher" paddle game from zero.
More examples (Breakout stub, platformer, shooter, paint toy, music visualizer) are coming as part of the 6–8 target in GOALS.md. Each will have a comment header and exercise multiple machine features.
┌─────────────────────────────────────────────────────────────┐
│ Host Platform │
│ (minifb+cpal desktop | Canvas+WebAudio | bare-metal LCD) │
│ │
│ implements Host trait + calls console.update_input() │
└───────────────────────────────┬─────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ scratch8 (core lib) #![no_std] │
│ │
│ Console { buffer:[u8;16384], frame, btn, mouse, ... } │
│ ├── pset / pget / rect / rectb / circ / circb / line │
│ ├── print (hand-rolled 4x6 font) │
│ ├── cls, tick, to_rgb_buffer, update_input, btnp │
│ └── (future: tone/sfx, spr, map under features) │
│ │
│ trait Cart { name, init, update(&mut self, &mut Console) } │
│ trait Host { present, push_audio } │
│ │
│ Built-in demos (Bouncer, Painter, Particles) + │
│ your carts (Pong, Snake, ...) │
└─────────────────────────────────────────────────────────────┘
- Core is sacred and portable. Everything that makes the machine is in
src/lib.rs(and soonsrc/audio/etc.). - Carts are the software. Implement
Cart(Rust today; WASM/bytecode tomorrow). - Host is a thin adapter. See
src/main.rsfor the desktop example. Embedded and web will have their own ~50-200 line hosts. - Full hardware details:
docs/HARDWARE.md - First cart walkthrough:
docs/TUTORIAL.md - Cartridge file format (future):
docs/CARTRIDGE_FORMAT.md
The public API surface you program against as a game author is tiny by design (Console methods + Cart trait).
The entire machine logic is #![no_std] + alloc and contains zero platform-specific code. Platform details live only in hosts.
cargo run --release --features full
# or
cargo run --releaseSee "Running it" above. Uses minifb (window + input) + cpal (audio when ready).
./scripts/verify-portability.shIt runs:
cargo check --lib --no-default-features(pure core)- Desktop full
cargo check --lib --target wasm32-unknown-unknown --features wasm- Embedded:
thumbv7em-none-eabihf(Cortex-M) andriscv32imac-unknown-none-elf
rustup target add wasm32-unknown-unknown
cargo check --lib --target wasm32-unknown-unknown --features wasmA real web runtime (Canvas + requestAnimationFrame + Web Audio) is being built by the WASM specialist. The exact same Cart you write here will run in the browser.
# Cortex-M4F etc.
rustup target add thumbv7em-none-eabihf
cargo check --lib --target thumbv7em-none-eabihf --no-default-features --features embedded
# RISC-V
rustup target add riscv32imac-unknown-none-elf
...For a real device you will:
- Implement
Host(or call the present/push_audio hooks). - Feed input via
console.update_input(...)every frame from your buttons/ADC. - Drive the 60 Hz loop yourself (timer interrupt or busy loop).
- Use
NoopHost(exported) for headless tests or early bring-up. - For the absolute smallest chips without alloc you can avoid
Box<dyn Cart>and use a fixed enum or concrete type.
See src/lib.rs comments around Host, NoopHost, builtin_carts, and the portability notes. The verify script + target checks are the proof.
All carts (including the ones in examples/) are written against the public API and therefore are automatically portable once a host exists for the target.
- No game engine. No Bevy, ggez, macroquad, etc.
- No graphics crate for drawing. We literally write to a
[u8; 16384]palette buffer. - minifb is only used for "give me a window and some input events + present this buffer". It is one of the thinnest possible layers. We can later replace it with winit + softbuffer if we want to go even deeper.
- The font, the circle algorithm, the line algorithm, the input mapping, the cart abstraction — all authored here.
- ✅ Audio (full 4-ch PSG + mixer + tone/sfx/pattern player + cpal desktop output — done by Chiptune Audio Wizard)
- Sprite RAM +
spr(x, y, sx, sy, w, h, flip)+ a built-in sprite editor (press TAB or E) - Map / tile layer
- Cartridge persistence (save/load .s8 files containing code + gfx + sfx)
- Either:
- A tiny custom bytecode VM + text language for carts (maximum "scratch" purity), or
- WASM cart support (like WASM-4 — users write in Rust/Zig/C and compile to .wasm)
- Polish, better font, more demo carts, web target (wasm + canvas)
If you want any of these next, or changes to the current spec (different resolution? different palette? different input buttons? pure terminal version first?), just say the word.
Start with the docs:
docs/TUTORIAL.md— your first cartdocs/HARDWARE.md— the exact machine specGOALS.md— the full visionTODO.md— what the swarm is working on right now
This already proves the answer to your question:
Yes. We can (and just did) build a real fantasy console from the very scratch.
Enjoy playing with it — and let's keep extending the machine.