Sir Box-a-Lot Recreates Sokoban as a DIY Handheld Electronic Game
Now in color! (Where available.)
When it comes to handheld video games, the puzzle genre transcends age groups. So, to help introduce their children to video games and use up parts lying around, parent and security author Michal Zalewski developed handheld games. The latest project uses an eight-bit microcontroller on a protoboard called Sir Box-a-Lot. It is a recreation of the puzzle game Sokoban.
In the past, we wrote about Zalewski's journey of developing handheld video games with simple hardware. Each game increased the hardware's sophistication and added a new feature or gameplay element. Sir Box-a-Lot continues that path. This new game now upgrades the output from mono-color to a 160x128 pixel RGB (color) OLED!
The core microcontroller is a Microchip eight-bit AVR128DA. Internally it has 128 kilobytes of flash, 16 kilobytes of SRAM, and 512 bytes of EEPROM for its memories. But, of course, it has no display-specific hardware, so all graphics are rendered in software.
A little bit of quick math says 160 pixels times 128 pixels with three bits of color requires 61,440 bytes of RAM, which presents a problem for a microcontroller with only 16 kilobytes of SRAM! So, how did Zalewski solve the minor issue of drawing a frame?
One solution would be to use the 1980s Apple II's method of only supporting 16 colors. Another approach is to use GIF's method to employ an indexed color palette that limits the displayed colors to a certain number from a much larger palette.
However, Zalewski settled on creating 6x6 "text" characters that could contain 256 colors. In addition, they have a 10-pixel offset option to make them (more) lively animations. The next challenge was how to update the screen. Instead of doing full-frame updates, Zalewski's code updates the parts of the screen that need to change. That approach works well for a game like Sokoban.
In Sokoban, you play the part of a warehouse worker who has to move boxes around. There are specific locations on the map to store boxes. Once stored in the proper places, you move on to the next level. This seemingly simple mechanic is ripe for increasing difficulty and many map variations. But more importantly, only a handful of pixels ever need to change at a time. So, there is no need to update the entire screen's frame very often.
While it seems like the next limitation is the flash memory size of the AVR128DA, it is barely an issue. There is enough room for a couple of hundred levels! The actual limit is the AVR128DB28's 512 bytes of EEPROM. That is only enough memory to keep track of high scores for about 100 maps.
We're excited to see Zalewski's latest handheld gaming development. It's so simple you could build one. No exotic hardware is involved, and you can download the microcontroller source code for Sir Box-a-Lot at the bottom of this blog post. Check out that post for a comprehensive look at some challenges when adapting this puzzle game to the AVR128DB28.
Electronics enthusiast, Bald Engineer, AddOhms on YouTube and KN6FGY.