(See all posts about the port)

I started porting Loser Corps, a video game I and a few friends made in the old days of 1998-1999, to the ESP32.

I'm using bitluni's ESP32Lib to generate the VGA output, and I'm still using my crappy homemade DAC with 2 bits per color component I showed in the last post. The only new addition is a little board I made to connect the pins from the ESP32 devkit to the VGA breakout board without the mess I had in the breadboard, and an improvised cardboard box to hold the VGA plug in place (it works surprisingly well). I'll probably make a nicer board and box when I add joystick input and sound output.

The code currently renders a static screen with the background filled with tiles, some sprites and some foreground tiles. It's probably a reasonable test of how fast things will render:

The whole setup
The whole setup

The game images look a little rough when converted to 64 colors, especially since the palette is fixed by the hardware, but I think I can get used to it:

Screenshot of the game
Screenshot of the game

I managed to get a descent render speed after I started writing to the screen 4 pixels at a time. The annoying thing about this whole thing is that because of the way the ESP32 I2S DMA works, the data in the framebuffer has to be set in a weird order:

pixels01234567...
address[2][3][0][1][6][7][4][5]...

Another annoying thing is that the VSync and HSync bits for the VGA signal have to go inside every pixel in the framebuffer. To make things fast, I pre-baked these bits in the image data, which means that if I want to change to a VGA mode that happens to have different VSync or HSync polarity, I'll have to re-convert the images and recompile everything. Not a big deal, but it's annoying.

Currently my code only supports placing images aligned horizontally to 4 pixels (i.e., the x coordinate must be a multiple of 4). With that, the trick of writing 4 pixels at a time, and not clearing the screen every frame (since I'm going to overwrite everything anyway), I managed to get around 150 frames per second. We'll have to see how bad it gets once I remove the restriction on the horizontal alignment.

All in all, I'm very pleased with the progress.