πŸ‘Ύ Run WebAssembly (WASM-4) games on small devices (like PyBadge)

Overview

πŸ‘Ύ gamgee

Run WebAssembly (WASM-4) games on small devices.

Gamgee is a WASM-4 games emulator written in Rust and designed to be executed on devices with very little memory and space available. Currently, it supports only Adafruit PyBadge but we plan to add more in the future.

Features:

  • πŸ’Ύ Small size. The binary is just about 270 Kb, and it includes wasm interpreter, allocator, graphics library, a custom font, etc.
  • 🐜 Small memory requirements. The runtime itself needs just a few kilobytes of RAM and the rest is fully available to the running game.
  • πŸ•Ή WASM-4 compatible. It can run any WASM-4 game (and there are quite a few) as long as it fits into memory.

photo of pybadge running tetris

πŸ”§ Installation and usage

  1. Install Rust.
  2. Install task.
  3. Connect PyBadge and turn it on.
  4. Press the "reset" button twice on PyBadge to put it into the bootloader mode.
  5. Flash a game onto the device: task flash -- $PWD/watris.wasm. The path must be absolute (hence $PWD).
  6. Press the "reset" button on PyBadge once to refresh the screen.

πŸ™… Limitations

  1. PyBadge screen size is 160x138. WASM-4 games expect 160x160. To fit the image, we skip every 5th line.
  2. WASM-4 games expect 60 FPS but the PyBadge screen is limited to 20 FPS and then there is often just not enough CPU to keep up. The solution is to try calling the update callback as many times as possible but draw only every 5th frame. However, the games can still be slower than they should.
  3. PyBadge screen uses 16 bits per pixel for colors. WASM-4 color palette is defined as 24 bits for each color. We translate the color palette to pybadge colors as close as possible but the colors might look a bit different from (not as vibrant as) what you see on your PC screen.
  4. PyBadge has 192KB of RAM, and a few Kb are needed for the runtime itself. WebAssembly memory is allocated in pages of 64 Kb. So, we can allocate only 2 pages (128 Kb) of memory for the game to use before crashing with OOM. It's enough for most of the games but not all of them.
  5. Unsupported: tone (playing sounds). PyBadge doesn't have a speaker by default. You can attach your own but I don't have one yet. PyBadge has a built-in buzzer but that's not enough for WASM-4 games.
  6. Unsupported: diskw and diskr (persistent storage). The unused flash space can be used to store additional data, and we might use it for these two functions. However, I haven't seen a game yet that would use them. WASM-4 provides game save by dumping the whole game state, so games don't neet to implement their own save system.

πŸ™ Acknowledgments

I want to thank:

And thank you for using the project β™₯️

You might also like...
witgen is a library to generate .wit files for WebAssembly in Rust

witgen witgen is a library to help you generate wit definitions in a wit file for WebAssembly. Using this lib in addition to wit-bindgen will help you

Build frontend browser apps with Rust + WebAssembly. Supports server side rendering.
Build frontend browser apps with Rust + WebAssembly. Supports server side rendering.

Percy Build frontend browser apps with Rust + WebAssembly. Supports server side rendering. The Percy Book This README gives a light introduction to Pe

Dependency solver for Elm, made in WebAssembly

Dependency solver for Elm, made in WebAssembly This repo holds a dependency solver for the elm ecosystem compiled to a WebAssembly module. The wasm mo

A simple code for checking crate 'prost' on WebAssembly (πŸ¦€ + πŸ•ΈοΈ = πŸ’–)

rust-wasm-prost This repository is a simple code for checking crate 'prost' on WebAssembly ( πŸ¦€ + πŸ•ΈοΈ = πŸ’– ). What is prost? prost is a Protocol Buffe

Version of Clue made to be compilable in WebAssembly (WIP)
Version of Clue made to be compilable in WebAssembly (WIP)

Clue is a programming language that compiles into Lua code with a syntax similar to languages like C or Rust. Clue tries to be almost as simple as Lua

Vite + Webassembly starter project
Vite + Webassembly starter project

Vite + Typescript+ Webassembly A starter project for you to create a blazingly fast web application Before getting started You need to get these prere

Rust bindings for Supabase JavaScript library via WebAssembly.

supabase-js-rs Rust bindings for Supabase JavaScript library via WebAssembly. Usage Add supabase-js-rs to Cargo.toml supabase-js-rs = { version = "0.1

An attempt to build full-featured WebAssembly-based monolith charts

Graphima Graphima (Greek: γράφημα) is an attempt to build full-featured WebAssembly-based monolith charts. See "Can I Use" WebAssembly for browser sup

plugy empowers you to construct agnostic dynamic plugin systems using Rust and WebAssembly.

plugy plugy is a plugin system designed to enable the seamless integration of Rust-based plugins into your application. It provides a runtime environm

Owner
Orsinium Labs
Experiments and small projects by @orsinium. See also @life4 for big and popular projects.
Orsinium Labs
`wasm-snip` replaces a WebAssembly function's body with an `unreachable`

wasm-snip wasm-snip replaces a Wasm function's body with an unreachable instruction. API Docs | Contributing | Chat Built with ?? ?? by The Rust and W

Rust and WebAssembly 177 Dec 28, 2022
WebAssembly (Wasm) interpreter.

Continuous Integration Test Coverage Documentation Crates.io wasmi- WebAssembly (Wasm) Interpreter wasmi was conceived as a component of parity-ethere

Parity Technologies 1k Jan 4, 2023
Mod_wasm - an extension module for the Apache HTTP Server (httpd) that enables the usage of WebAssembly (Wasm).

mod_wasm is an extension module for the Apache HTTP Server (httpd) that enables the usage of WebAssembly (Wasm). This module will allow to execute certain tasks in the backend in a very efficient and secure way.

VMware  Labs 67 Dec 21, 2022
Low level tooling for WebAssembly in JavaScript using wasm-tools

js-wasm-tools js-wasm-tools compiles some of the API of wasm-tools to JavaScript and WebAssembly via wasm-bindgen. This offers low level tooling for W

Dominic Elm 59 Dec 19, 2022
Distribute a wasm SPA as HTML by wrapping it as a polyglot "html+wasm+zip"

A packer that adds a webpage to WASM module, making it self-hosted! Motivation At the moment, Browsers can not execute WebAssembly as a native single

Andreas Molzer 3 Jan 2, 2023
A command-line tool for extensible LED matrix control with Raspberry Pi devices.

Matricks "Teach an old matrix new tricks..." Matricks is a WASM-based extensible LED matrix control tool intended for use on Raspberry Pi devices. LED

Will McGloughlin 3 May 1, 2023
Run Java code from Rust!

Java Native Interface Bindings for Rust This library provides complete FFI bindings to the Java Native Interface, as well as a safe and intuitive wrap

Ben Anderson 66 Nov 28, 2022
WebAssembly implementation from scratch in Safe Rust with zero dependencies

wain wain is a WebAssembly INterpreter written in Rust from scratch with zero dependencies. An implementation of WebAssembly. Features: No unsafe code

Linda_pp 328 Jan 2, 2023
A notebook app integrated with todo lists utility. Developed with Rust, WebAssembly, Yew and Trunk.

Flow.er A notebook app integrated with todo-list utility. Project flow.er is a Rust WASM app running in browser. Taking advantage of Yew and Trunk, it

null 45 Dec 31, 2022
NPM package distributing biscuit in WebAssembly for web components

Biscuit playground This is an example application for Biscuit tokens, where you can manipulate tokens and their verification in your browser. build wi

null 0 Dec 30, 2021