Game & Watch MAME emulator build for TrimUI Brick

Despite the fact that Game & Watch handhelds are ultra low end, and you can emulate their 4-bit 32kHz CPU on basically anything, there is only one emulator for this platform - MAME. MAMEs priority is high precision emulation and not performance. So basically it’s an emulator for powerful devices (e.g. your laptop). While it works great on my laptop and graphics is crisp, I think the best way to experience Game & Watch games is on handheld with dedicated buttons and D-pad.
I have TrimUI Brick with beautiful screen. 400 PPI will allow sprites to be rendered without visible pixelation. Perfect device for g&w gaming, but there is no emulator. Okay there is libretro core for Game & Watch, which works on this device, but it’s a simulator, not emulator. It means games were reimplemented, so timing might be slightly different and not all games are supported, some of my favorite are missing (Mario’s Cement Factory, Climber, Octopus, Chef).
First I tried to compile MAME Game & Watch emulator for linux/arm64 and run it on Brick. After some tinkering it worked, but super slow, like 30% of the normal speed. Turned out while CPU emulation is easy, because we don’t have a normal pixel-based display, all graphics is composed of multiple layers of high resolution PNG files and on each “tick” we rerender everything. It’s very memory intensive and RAM-throughput of small handheld devices is a bottleneck, also everything is done by CPU, and we don’t utilize hardware accelerators for image manipulation. The easiest way to fix the performance was to downscale layer-pictures first and compose final result from smaller resolution images. I also tried to skip rerendering if nothing changed (and it rarely changes because there is no smooth animation on segment LCD). This worked, and now it runs at 100% speed.
Later I created a PAK for NextUI, so other owners of the Brick can enjoy perfect Game & Watch emulation!

game selection meny chef donkey kong jr

Also, I recommend to read this interview with creators of MAME G&W emulator. It was a great team effort and in the beginning to be able to fetch the ROMs they had to dissolve chips in acid and read bits directly from MCU memory high resolution photos :-)