Close
0%
0%

Gaming on the ESP32 / Odroid-Go

The ESP32 is a powerful microcontroller, but what games can it actually run?

Similar projects worth following
There's a video of DOOM running on the ESP32, so I wondered if I can get this running myself?

This led me into trying out what other games I could get running on it... If it can run games that a 486 could, there should be plenty of others that will run on it too!

This project details my efforts in experimenting with running games on the ESP32, and porting new games to it.

I started off with an ESP32 WROVER DevKit, added an SPI LCD screen (type ILI9341), SPI SD Card slot, amp + speaker, and a few buttons.  Using an ESP32 WROVER is important, because the WROVER contains 4MB ram - which is essential for running games. Now I had everything I need to start running games.

DOOM

I started off trying to run DOOM.  But it used the onboard SPI Flash to hold the game data.  An ESP32 only has a max of 16Mb spiflash - which means that this would be a limitation to what games could be run, and how easy is is for others to run these games.

So my first task was getting DOOM to run from the SD Card - this was a fairly easy swap. 

Also I added back in the code to have sound working, and modified it to use the i2s sound output.  The ESP32 can internally connect the i2s output to it's DACs, so it can directly product sound output, it just needs some amplification...

Code: https://github.com/jkirsons/Doom


Development Environment

At this stage I was using PlatformIO + VSCode as my development environment.  It was easy to initially setup, but I quickly hit limits using PlatformIO.

PlatformIO didn't give me the ability to run "make menuconfig" where you can directly change lots of memory/spi/rtos related settings.

My next step was to install the full ESP-IDF toolchain:

https://docs.espressif.com/projects/esp-idf/en/latest/get-started/

This let me unlock lots more potential from the ESP32, and gives valuable debug tools (including backtrace code address resolution).  The good this is, I can still use VSCode as my IDE.

If you're using Mac or Linux, you can even compile/monitor/menuconfig directly from a terminal in the IDE:

OpenTyrian

My next step was to port a new game over to the ESP32 - one that no one has ported yet.  So what game has been ported to nearly every platform?  Tyrian!

OpenTyrian has the advantage that nearly all the platform dependent code (ie video, sound, input, disk) has been removed, and handled by one library.  That library is SDL (https://www.libsdl.org/).

I ended up making my own "mini" SDL library for the ESP32.  I call it mini, as it only implemented the functions that OpenTyrian needed.  The screen writing code was used from Doom (ie flipping a memory array (SDL Surface) to the screen), Input events re-written to use GPIO inputs, sound re-written to use i2s sound output, and initialisation of the SD Card before any disk I/O calls.

Here is the result:

Code: https://github.com/jkirsons/OpenTyrian

Alright, I've ported my first game!  What's next?  I have a partial SDL 1.2 library that can make porting the next game a bit easier, so I just need an SDL port of an old classic DOS game that would run in an early 486.

I found this: Chocolate Duke Nukem 3D
http://fabiensanglard.net/duke3d/chocolate_duke_nukem_3D.php

Duke Nukem 3D

So I stated at getting Duke Nukem 3D to compile on the ESP32.

My first problem was memory.  Duke Nukem 3D had lots of (large) arrays.  An array takes up DRAM, of which the ESP32 only has around 290kb.  The 4Mb SPI RAM can only be used by malloc() calls.  OpenTyrian was ok because there were not too many arrays, but Duke Nukem 3D has lots of arrays.

At this point, I found in one of the later ESP-IDF releases, an attribute was introduced that lets the array be allocated in SPI RAM instead of DRAM.  It is EXT_RAM_ATTR - and I used this a lot:

So now I had Duke Nukem 3D compiling and running on an ESP32!!!

Code: https://github.com/jkirsons/Duke3D

The next level - ODROID-GO

OK, now I have proven that I old DOS games can be ported to the ESP32, it's time to take it to the next level.  The breadboard works, but if you wobble things too much it might crash, and most importantly,...

Read more »

  • Commander Keen

    Jason02/28/2019 at 15:28 0 comments

    Commander Keen

    Well it's not quite Commander Keen, but a clone called CloneKeen, which plays Keen 1, 2 & 3.

    The sound functions in this were quite easy.  The sound files just tell a routine what frequency to play, and the function generates a square wave at this frequency.

    The harder part was getting all the scroll surfaces to fit in memory.

    https://github.com/jkirsons/CloneKeen

View project log

Enjoy this project?

Share

Discussions

Bastian.Y wrote 05/30/2019 at 21:51 point

Looks great! Nice job. 

  Are you sure? yes | no

Alexander wrote 01/29/2019 at 16:31 point

Absolutely incredible work! This is so neat. I'm just about to start tinkering with the ESP32 and it's neat to see what it can do. What made you choose to use FreeRTOS instead of programming it by hand? Just time-saving?

  Are you sure? yes | no

Jason wrote 01/18/2019 at 15:07 point

That's right, all the videos are the ESP32 natively running games that were recompiled for it from source code - it definitely is not emulating x86 architecture.  I was just meaning that the 240Mhz ESP32 is not going to run a game that has minimum requirements of a modern PC.

  Are you sure? yes | no

Vitaly Rudik wrote 01/18/2019 at 14:51 point

I've found the video: https://youtu.be/y6PP_IBbOTY
It very cool but it doesn't emulate i486. DOOM is compiled for the ESP32.

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates