Sample project. Build a ROM, written in assembly language using the SGDK XGM2 driver to play audio.
The ROM can be built using either the GNU or VBCC toolchains.
Windows binaries are included for convience.
SGDK library and custom tools are distributed under the MIT license (see lib/license.txt file). GCC compiler and libgcc are under GNU license (GPL3) and any software build from it (as the SGDK library) is under the GCC runtime library exception license (see bin/COPYING.RUNTIME file)
A vscode tasks.json file is included for convenience. It includes task to build the ROM using either the GNU or VBCC toolchains and to run the ROM in the Mame emulator/debugger.
If Python (py) is available, MAME debugger scripts will be generated which add symbols as comments.
- Run
build_data.bat
to build the XGM2 data. - Run
build_gnu.bat
to build the ROM.
TODO: Add makefile
- Run
build_data.bat
to build the XGM2 data. - Run
build_vbcc.bat
to build the ROM.
TODO: Add makefile
Prebuilt libmd.a (SGDK commit #0377311330ed0d64c2132234e88097accc87ba30 with -ffunction-sections -fdata-sections
to reduce ROM size) can be found in lib folder.
To rebuild manually:
- Clone https://github.com/Stephane-D/SGDK
- Modify SGDK/makelib.gen to add -ffunction-sections -fdata-sections to DEFAULT_FLAGS_LIB (See Stephane-D/SGDK#346)
- Follow SGDK Installation instructions to build libmd.a:
make -f makelib.gen
- Copy SGDK/lib/libmd.a libgcc.a to this repo's lib folder
If you are writing in assembly language:
Code (instructions) should be in asm CODE
sections. This will be placed in the ROM following the 68000 exception vector table and Mega Drive ROM header.
SECTION CODE,CODE
move.w #$2700,sr
...
Constant data should be placed in asm CODE
(or .rodata
) sections. This will be placed in the ROM with code, or after code and remain in the ROM.
SECTION CODE,CODE
...
lea Palette(pc),a0 ; can use PC-relative addressing to access nearby data in same section
...
dbra d0,.paletteLoop
jmp main
Palette:
dc.w $0000 ; Colour 0 - Transparent
dc.w $0002 ; Colour 1 - Red
...
or
SECTION .rodata,CODE
Palette:
dc.w $0000 ; Colour 0 - Transparent
dc.w $0002 ; Colour 1 - Red
"Data" means pre-initialised, non-zero, read-write data. Place this in DATA sections. This will be stored in ROM following code and read-only data and is copied to RAM at startup.
SECTION DATA,DATA
Flags:
dc.l $8000001
BSS means uninitialised (zero), read-write data. This takes up no space in the ROM. The Linker will allocate an address for BSS vars in RAM. It is zeroed at startup.
SECTION BSS,BSS
Variables:
dcb.b Vars_sizeof
FrameCount:
ds.l 0
- Stephane Dallongeville for the amazing SGDK
- djh0ffman and TTE for this fun task and dupport
- Frank Wille for the VBCC toolchain and amazing support
- Ice Dragon Dee for the cool music
Toolchain:
- GNU Binutils
- VBCC
- VASM
- VLink
- SGDK
- Everything You Never Wanted To Know About Linker Script by Miguel Young de la Sota aka mcyoung
- Using ld The GNU linker, especially Memory Layout section
- GNU Binutils list and docs
Mega Drive:
- Official Sega Genesis Technical Overview
- Sega, Sega megadrive maintenance manual
- Mega Drive / Genesis Architecture A practical analysis by Rodrigo Copetti
- Big Evil Corporation Megadrive Tutorial
- Sega Mega Drive memory map
- learning-megadrive repo
- MAME is good for single stepping through the code
- Regen debugger build e.g. Regen 0.972D