Skip to content

howprice/MegaDrive

Repository files navigation

Mega Drive

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)

Building the sample

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.

GNU Toolchain

Windows

  1. Run build_data.bat to build the XGM2 data.
  2. Run build_gnu.bat to build the ROM.

Other platforms

TODO: Add makefile

VBCC Toolchain

Windows

  1. Run build_data.bat to build the XGM2 data.
  2. Run build_vbcc.bat to build the ROM.

Other platforms

TODO: Add makefile

Rebuilding libmd.a manually

Prebuilt libmd.a (SGDK commit #0377311330ed0d64c2132234e88097accc87ba30 with -ffunction-sections -fdata-sections to reduce ROM size) can be found in lib folder.

To rebuild manually:

  1. Clone https://github.com/Stephane-D/SGDK
  2. Modify SGDK/makelib.gen to add -ffunction-sections -fdata-sections to DEFAULT_FLAGS_LIB (See Stephane-D/SGDK#346)
  3. Follow SGDK Installation instructions to build libmd.a: make -f makelib.gen
  4. Copy SGDK/lib/libmd.a libgcc.a to this repo's lib folder

What to stick where

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

Thanks and credits

References

Toolchain:

Mega Drive:

Emulators

  • MAME is good for single stepping through the code
  • Regen debugger build e.g. Regen 0.972D

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published