Breakout and a synth
In this article, I ported a Breakout game running on a bare-metal MCU to my device and made it output sound-effects using an analog synthesizer. Get the source code with synth patches. A video of gameplay below.
Analog paddle
I have always been intrigued by the idea of using rotary dial, instead of buttons, to control a Pong game. The original Pong and Breakout games used rotary dials and were implemented as analog circuits without the use of computer or running code, and having a paddle position available as an analog voltage was very convenient.
Unfortunately I never got to play the original arcade games and all later versions (both arcade and those on computer or game consoles) used exclusively buttons or joystick.
Then one day I stumbled upon an article by lcamtuf about writing a bunch of games for a bare-metal MCU, one of which was a Breakout clone called Blockbuster. He was kind to include a source code so I figured I might just try to get it running on a hardware I had lying around and then modify the game to use a potentiometer for the paddle position input.
Porting
The hardware I used was one of my old projects: a device that translated foot-switch presses to MIDI CC values. It uses atmega328p and SSD1306 OLED display which are quite similar to what Blockbuster used.
As for porting:
MCU on my device has a lot less RAM, but Blockbuster isn't very memory hungry (1KB for display framebuffer and few state variables). No problem here.
the OLED controlled uses a bit different protocol so I used my ssd1306 library as a drop-in replacement
because my display uses I2C it is much slower to redraw the whole screen so I cranked up the I2C bus frequency to about 880KHz and changed the game timing constants to make it work
my I2C display is configured for different ordering of rows/columns - I have a hunch that I could’ve changed the order in the ssd1306 config registers but I haven’t felt like diving into the datasheet so I just changed the bit ordering in the drawing routines
Analog paddle
Implementing the analog paddle involved connecting a potentiometer to an analog input pin and reading it with an ADC, then filtering the readings to prevent paddle jitter. The code that determines the direction of the ball bounce also had to be modified, as it relied on information about the direction of paddle movement to alter the angle of the bounce. With a digital paddle, movement can be determined based on which button is pressed (for example, "up" button pressed means the paddle is moving up), but for an analog paddle, movement must be calculated based on previous paddle positions.
Synth sound effects
My device didn't have a built-in beeper but it did have a MIDI interface. So why not connect it to a synthesizer and let the synthesizer generate the effects?
[Hmm, the Korg Monologue synth has also an OLED display with the right resolution...]
The MIDI protocol represents the pitch of a sound as a semitone offset from a base frequency. I reused the notes from the original Blockbuster beeps, but I had to quantize them to the nearest semitone, which means the notes are slightly off in some places. However, I don't think this is a significant issue. [Note: The Korg Monologue synth I'm using supports tuning tables, so this issue may be fixed in the future].
As an added bonus, I have assigned different sound effects to different instruments - blippy sounds will accompany ball bounces, a proper synth will play the intro tune, and an organ will play the game-over sound. The patch files (in SYSEX format) are included with the source code. The sound effects are available below.