A game written in Nim for the WASM-4 fantasy console.
Try it now on your browser! https://msakuta.github.io/InnerWilds/out.html
Wasm-4 is an interesting project that imitates 4-bit consoles with WebAssembly, but obviously it isn't true 4-bit console. In particular, WebAssembly is equipped fully capable IEEE 754 floating point processor instructions. Also an interesting thing to note about hardware specs is that it does not mention about CPU specification. This is because WebAssembly is designed to be architecture agnostic and it should run on any modern CPUs. It means we can leverage modern CPU architecture and speed in supposedly 4-bit-ish platform.
That said, RAM and ROM capacity is very limited (64kb for each), so we want something that can run with little memory. And what is a good example of that? Ray tracing!
Nim is a systems programming language suitable for low-end CPUs. Or I should say one of many of this kind.
At first, as Rust lover, I wanted to write in Rust. However, Rust compiles to a big Wasm binary as soon as I link trigonometric functions which are required by 3D graphics, and it exceeds ROM size specification pretty quickly. Apparently Wasm doesn't have mathematical functions as part of intrinsics, so the language has to implement them as library functions. Also, a lot of library codes seem to come from runtime, e.g. panic handlers.
Zig was another candidate, but for some reason it didn't compile in my environment.
Nim was the last candidate that can compile fairly small binary (~10kb). I could write in C or C++ since Nim compiles to C, but I took this opportunity to write something with a new language.
Build the cart by running:
nimble rel
Then run it with:
w4 run build/cart.wasm
For more info about setting up WASM-4, see the quickstart guide.
- Documentation: Learn more about WASM-4.
- Snake Tutorial: Learn how to build a complete game with a step-by-step tutorial.
- GitHub: Submit an issue or PR. Contributions are welcome!