alloncm / MagenBoy

GameBoy and GameBoy Color emulator written in Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MagenBoy

A GameBoy emulator developed by me.

The main goal of this project is to be able to play Pokemon on my own emulator.

Implemented Cartridges Types

  • Rom (No MBC controller)
  • MBC1
  • MBC3
  • MBC5

More will be added if neccessary (and by neccessary I mean if games I want to play will require them)

Building

Install cargo-make

cargo install cargo-make

verify you have docker or podman installed

Desktop

cargo make sdl

or with more configuration options:

cargo build --release --package magenboy_sdl --features [optional_features]

Optional features:

  • static-sdl - will link statically to sdl2, On by default
  • sdl-resample - Use the audio resampler from sdl2 library and a manual one I wrote
  • push-audio - Use a push methododlogy instead of pull for the delivery of the sound samples to sdl2
  • u16pixel - pixels are represented by 16 bits and not 32 bits

Note to turn off on by default features pass --no-default-features when building

Key bindings:

Joypad Keyboard
A X
B Z
Start S
Select A
Dpad Up Up arrow
Dpad Down Down arrow
Dpad Left Left arrow
Dpad Right Right arrow

(WIP) Raspberry Pi Baremetal (with ili9341 display and gpio buttons)

Edit the relevant settings in configuration.rs install arm-none-eabi-gcc and then run:

cargo make -e [rpi_revision] rpibm 

This command will do the folowing:

  1. Install the rust source to compile for toolchain armv7a-none-eabihf:
rustup +nightly component add rust-src

Unfurtuantly armv7a-none-eabihf is a tier3 target for the Rust compiler so building for it requires the nightly toolchain - source

Notice We install the armv7a-none-eabihf target and not the armv7a-none-eabi target, as the later doesn't have support for hardware floats.

  1. Install Cargo Binutils:
cargo install cargo-binutils
rustup component add llvm-tools-preview
  1. Builds the image

Running

Desktop

magenboy [path_to_rom] [other_optional_flags]

Raspberry Pi Desktop with peripherals

See - RealMagenBoy

Optional flags

  • --file-audio - Saves the audio to a file
  • --full-screen - Full screen mode
  • --no-vsync - Disable vsync
  • --bootrom [path to bootrom file] - Specify the path for a bootrom (If not specified the emualtor will look for dmg_boot.bin at the cwd)
  • --rom-menu [path to roms folder] - Opens an interactive dialog uopn start to choose the rom from the folder Choose a game with the Joypad bindings (Dpad and A to confirm)
  • --mode [mahcine mode] - Override the auto machine detection for the game (mode can be: CGB - Gameboy color | DMG - Original Gameboy | ANY - default)
  • --shutdown-rpi - Requires rpi feature, shutdown the RPi upon shutdown of the program

Raspberry Pi Baremetal

Currently only Raspberry Pi 4 is supported using the following instructions:

  • Format a sd card and make a single FAT32 partition called boot
  • Copy the file config.txt to the root dir of the sd card
  • Copy the following files from the Raspberry Pi firmware repo onto the SD card:
  • Copy kernel7.img onto the SD card
  • Connect all the peripherals (ili9341 display and gpio buttons)
  • Insert the SD card to the RPI4 and boot it

Note: Should it not work on your RPi4, try renaming start4.elf to start.elf (without the 4) on the SD card.

QEMU

Currently Qemu doesn't support RPI4 in 32 bit mode, so in order to test it I added support for RPI2 mapping. To change to RPI2 mode build with the rpi2 feature and not the default rpi4 feature.

running with qemu:

qemu-system-arm.exe -M raspi2b -serial null -serial mon:stdio -kernel path_to_elf

Note Qemu takes the path to the elf generated by cargo not the image generated by binutils the UART output will be written to the console.

I think that not all the peripherals I use are implemented in QEMU so I used this mainly to debug boot and CPU initialization problems

GameBoy

Development Status

Games Tested

  • Pokemon Red
  • Tetris
  • Super Mario World
  • The Legend of Zelda: A Link to the Past

GameBoy Color

Developement Status

Games Tested

  • Pokemon Yellow
  • Tetris DX

Resources

Gameboy

RaspberryPi

BareMetal RaspberryPi

About

GameBoy and GameBoy Color emulator written in Rust

License:GNU General Public License v3.0


Languages

Language:Rust 97.0%Language:Assembly 2.4%Language:C 0.6%