Thursday, October 10, 2024

Someone is Running Quake Game on Arduino Nano!

Nicola Wrachien, has achieved an impressive feat by porting the classic first-person shooter, Quake, onto an Arduino Nano Matter gamepad. This isn't just a basic implementation – Wrachien has crafted a full-fledged Quake experience complete with advanced graphics, physics, and sound, all running on a microcontroller with limited resources.

Wrachien, a Solutions Architect at Silicon Labs, was inspired by previous projects like the Doom port on a Sparkfun Thing Plus Matter MGM240P. He set his sights on the MGM240SD22VNA MCU, a chip with a mere 256KB of RAM – a far cry from Quake's original requirement of 8MB of RAM and a Pentium-class CPU. Undeterred, Wrachien tackled this challenge head-on.

He designed a custom PCB, shaped like a gamepad, that features buttons, joysticks, and a 320x240 pixel LCD. This board utilizes the Arduino Nano Matter, which boasts the MGM240SD22VNA MCU.



To port Quake to this tiny hardware, Wrachien employed a combination of clever engineering and clever coding. He used the SDLQuake1.09 codebase, a modern Windows-based version of the game, as a starting point. Key optimizations included:

  • Storing constants in flash memory: This freed up valuable RAM, but accessing data from external SPI flash memory is slow.

  • Overclocking the MCU: Pushing the MGM240 to 136 MHz provided a crucial performance boost.

  • Implementing various optimizations: These included a texture cache, asynchronous DMA texture loading, optimized enemy rendering, assembly language functions, and partial screen refresh.

Wrachien also developed additional tools to simplify the porting process:

  • Constant table generation: Made creating and managing game data more efficient.

  • QuakeC to C conversion: Allowed for easier adaptation of the game's codebase.

  • Entity getter-setter generation: Simplified the interaction between the game's code and the microcontroller.

  • Quake Pak converter: Optimized game data for rendering on the limited hardware.

The final result is a fully playable Quake experience, packed with features:

  • Enemy AI: Monsters move and react realistically.

  • Game logic: Includes triggers, doors, secrets, and teleporters.

  • 3D engine: Offers static and dynamic lighting, turbulent water surfaces, and Gouraud shading.

  • Sound: Features ambient, static, and dynamic sound effects.

  • Console: Allows for cheat activation.

  • Save game functionality: Saves the exact game state, including player and monster positions.

  • Customizable controls: Players can modify key mappings, gamma, and sound volume, with settings saved to non-volatile memory.

The game runs at a smooth average of 27 frames per second, ranging from 17 to 45 FPS at the 320x200 resolution of the original Quake. This remarkable achievement is made possible by the combination of hardware optimization and software ingenuity.

The Arduino Nano Matter gamepad, powered by the MGM240, packs a punch beyond its size. It utilizes 256KB of RAM, cleverly avoiding the radio RAM. 16 remappable buttons and two analog thumbsticks provide control. Two 16MB SPI flash ICs store the game data, uploaded via an SD card. Stereo speakers deliver the sounds, with a headphone jack for a more private experience. A charging circuit enables the use of LiPo batteries. The PCB is designed for through-hole components, making it easy to assemble.

This project is a testament to the power of ingenuity and the tenacity of developers who push the boundaries of gaming and technology. It demonstrates that even with limited resources, the classic Quake experience can be brought to life. You can learn more about this project on Next Hack’s GitHub repo or their website.

0 comments:

Post a Comment