Minesweeper-nw is a Minesweeper game written in Rust no_std (bare metal, no OS) for the NumWorks graphing calculator. It is my second Rust project, learned self-taught, and also my second low-level embedded project (in fact, I’ve only done bare-metal Rust so far).
The NumWorks allocates around 100 KB of RAM (stack and heap combined) to external applications, and uses a Cortex-M7 processor.
This project is built on Eadkp (my first Rust project), a framework I developed myself to abstract the hardware and the different NumWorks models in Rust. It handles display, keyboard input, storage, images, battery management, and also includes a PC simulator for development. I created it to avoid rewriting the same boilerplate for every project.
There is no game engine available for this hardware.
The screen suffers from heavy screen tearing, making full redraws every frame impractical. Because of that, I designed an event-driven graphics rendering pipeline: only the elements that actually need updating are redrawn. The system relies on a list of RenderCommands generated by the game logic and consumed by the renderer.
Since RAM is the critical resource, the game board uses bitpacking.
All data for a cell (mine, revealed, flagged, adjacent mine count) is stored in a single byte using bitmask manipulation. A 10*10 grid therefore uses only 100 bytes instead of 0.39 KB with a naïve struct layout.
The reveal propagation also uses an iterative BFS with an explicit stack instead of recursion, to avoid blowing the stack (stack overflow) on the Cortex-M7.
The current game is automatically saved when closing the app and restored on the next launch, without affecting the timer. This feature was planned from the very beginning of the architecture, which made implementing it much less painful than I had imagined.
If you would like more technical details about optimization, see the documentation page: Optimization (French version available).
Demo video (Compilation + Gameplay):
https://youtu.be/Im5sqfB5wsw?si=7NMjHolD1MnU9g4v
Statistics:
- 1435 lines of code (excluding Eadkp)
- Two difficulty modes
- Win/loss/time statistics
- Current game save system
For months, I had wanted to create a game for the NumWorks calculator. It would have been infinitely faster and easier to make it in C/C++, since you can build on existing projects and the limited community documentation.
But I chose Rust because I don’t particularly like C or C++, and I built a framework because I would have had to write that code anyway, and now I can easily reuse it for future projects.
PS: Now I love doing this (bare metal dev) 🙂