This is my game engine for the Arduino UNO (8-bit Atmega328 development board). It generates composite output, with scrolling tilemap backgrounds and sprites, designed for action games. The engine runs at a constant 50fps, and generates the display by "racing the beam". There is no frame-buffer, which allows a much higher resolution and faster animation. The effective resolution is 256x256 pixels, with up to 9 16x16 sprites on screen at once.
This game is a port of the arcade game Scramble, which is a side-scrolling shooter, with 6 different levels, and increasing difficulty after blowing up the enemy base! The player controls a ship with a cannon and bombs to destroy enemies on the landscape, and in the air. The level data has been converted from the original arcade ROMs, and the graphics have been modified from the originals, to suit a single-color display.
The Github repo also contains the older Manic Miner, and Space Invaders games. I also have a design for a Arduino shield (all of the design files, gerbers and production files to have the boards fully made and populated) which can plug into the UNO to make it easy to connect to a composite monitor/TV, and a Nintendo control pad (along with buttons on the shield if a pad is not available).
The schematics are very simple, and anyone should be able to breadboard this out if they have the spare parts. The resistor values are pretty flexible, so anything close to the values in the schematic should be fine!
Please note this is for PAL composite TVs/monitors (modern TVs may be able to auto-switch between PAL/NTSC) as I have no way to test with NTSC currently. If someone would like to modify the game to run on NTSC though it should just be a matter to changing the timings in the code.
🛠️ เจาะลึกเบื้องหลังการทำงาน (Deep Dive / Technical Analysis)
Building a game on a tiny OLED screen is one thing. Outputting real analog composite video signals directly into a massive 50-inch CRT television using nothing but an Arduino Uno is absolute programming black magic. The Scramble Arcade (8-bit) project utilizes the TVout library, forcing the Uno to completely hijack its internal processor timing to mathematically draw 8-bit scanlines 60 times a second!
The NTSC/PAL Sync Signal Physics (TVout)
A TV expects a terrifyingly precise analog electrical signal perfectly synchronized at 15.7kHz.
- The Uno does not have a video card. It has 2 kilobytes of RAM!
- The
TVout.hlibrary assigns two specific Pins (Sync=Pin 9, Video=Pin 7). - The Custom DAC Resistors: You must physically solder a 470 Ohm resistor to the Sync pin and a 1000 Ohm resistor to the Video pin, merging them into the center pin of a Yellow RCA cable. This mathematically creates a raw, primitive Digital-to-Analog converter!
- The Uno creates an invisible
128 x 96pixel shadow-buffer in its SRAM, consuming nearly 50% of the entire microcontroller's memory instantly!
The Scramble Game Engine Array
Because the video processing takes almost the entire processor core, the game logic must be ruthlessly optimized.
- The player’s spaceship is a tiny byte matrix
PROGMEMsprite. - The scrolling terrain (the hardest part of Scramble) is an array of height integers pointing into drawing mathematically calculated vertical lines
TV.drawLine(x, startY, x, endY, WHITE);. - The Execution Frame-Rate:
TV.delay(1)is not a normaldelay(). It physically waits for the exact moment the electron beam on the massive TV finishes painting the bottom of the screen (the V-BLANK phase)! - The Uno then violently calculates collision physics and inputs exactly during that microscopic invisible blink, preventing tearing!
Analog Entertainment Hardware
- Arduino Uno/Nano (Mega is rarely supported, as TVout relies on highly specific ATmega328 Timer1 hardware architecture).
- A massive vintage CRT Television or a modern TV with the Yellow Composite Video RCA input.
- Resistors (470 Ohm & 1K Ohm) to manually forge the analog video signals!
- A generic RCA Video Cable (You must physically cut the cable with scissors, stripping it to find the internal signal wire and the outer ground shielding mesh!).
- Arcade Joystick components.