This project is a minimal, "bare metal" template for programming Mega Drive (Genesis) games and applications in C.
It's in early stages. Watch out!!
- Less External Libraries as possible
- Dockerized Toolchain
- Hardware Direct Access
| File | Description |
|---|---|
boot.s |
Assembly Startup: Sets the Vector Table, writes the SEGA security header, initializes the stack, and jumps to C. |
main.c |
Game Logic: The C entry point. Initializes the VDP registers and cycles background colors. |
sega.ld |
Linker Script: Maps code to Cartridge ROM ($000000) and variables to Console RAM ($FF0000). |
Dockerfile |
Toolchain: Builds a Linux environment with m68k-elf-gcc and binutils pre-installed. |
build.sh |
Build Helper: Automates the Docker build and compilation process. |
- Docker Desktop (or Docker Engine on Linux)
- Bash terminal (Linux, macOS, or WSL on Windows)
-
Clone the repository
-
Make the script executable:
chmod +x build.sh
-
Run the build script:
./build.sh
What happens next?
- The script checks for the
md-toolchainDocker image. If it doesn't exist, it builds it (this takes a minute the first time). - It mounts your current directory into the container.
- It compiles
boot.sandmain.cusingm68k-elf-gcc. - It links them using
sega.ld. - It extracts the raw binary to create
game.bin.
The linker script (sega.ld) enforces the standard Genesis memory map:
- ROM:
0x000000to0x3FFFFF(4MB Cartridge space) - RAM:
0xFF0000to0xFFFFFF(64KB Work RAM)
Unlike modern PCs, the Mega Drive VDP is not initialized by an OS. The main.c includes a vdp_init() function that manually sends 19 commands to the VDP Control Port to:
- Enable the Display (Reg 1, Bit 6).
- Set the resolution to 320x224 (H40 mode).
- Define memory locations for Scroll Planes and Sprites.
We use specific GCC flags to generate ROM-compatible code:
-m68000: Target the specific M68k CPU found in the console.-ffreestanding: Tells GCC there is no Standard C Library (noprintf, nostdio.h).-O2: Optimization level 2.
This project is open source. Do whatever you want.