Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Megahello

Example Sega Megadrive hello world written in Rust. This example is built on top of megadrive-sys.

Tested on rustc 1.99.0-nightly (87e5904f5 2026-07-20) and cargo 1.99.0-nightly (3efb1f477 2026-07-17).

Prerequisites

Dependencies

The megadrive-sys dependency needs to be patched for m68k-unknown-none-elf. Run these on the megahello folder:

git clone https://github.com/ricky26/rust-mega-drive.git
cd rust-mega-drive
git checkout c9353be # get the correct commit
git apply ../rust-mega-drive.patch

Building

Build the Megadrive ROM. Note that this uses the .cargo/config.toml configuration parameters and the link-megadrive.ld linker script to build the ROM.

cargo +nightly build --target m68k-unknown-none-elf --release

Convert the ELF file to a Megadrive binary ROM with the .bin file suffix:

m68k-linux-gnu-objcopy -O binary target/m68k-unknown-none-elf/release/megahello target/m68k-unknown-none-elf/release/megahello.bin

Debugging

Note that the Rust 1.99 compiler has many bugs for m68k and LLVM has more bugs for m68k. It is very likely that the generated code is bad or the compiler crashes. Avoid building debug builds, always build release builds.

View the memory map:

cat target/Output.map

Dump the sections of the ELF file:

m68k-linux-gnu-objdump -x target/m68k-unknown-none-elf/release/megahello

Disassemble machine code instructions from the ELF file:

m68k-linux-gnu-objdump --disassemble --no-show-raw-ins --visualize-jumps -S target/m68k-unknown-none-elf/release/megahello

License

0BSD

About

Sega Megadrive hello world written in Rust

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages