diff --git a/README.md b/README.md index 0bb6c261..5b112db9 100644 --- a/README.md +++ b/README.md @@ -12,12 +12,12 @@ The main goal of this project is to be able to play Pokemon on my own emulator. **More will be added if neccessary (and by neccessary I mean if games I want to play will require them)** -## How to use +## Building -### Building +### Desktop ```shell -cargo build --release --features [optional_features] +cargo build --release --package gb --features [optional_features] ``` #### Optional features: * `sdl` - Link to sdl2 (On by default) @@ -32,7 +32,7 @@ On by default > **Note** to turn off on by default features pass `--no-default-features` when building -### Key bindings: +#### Key bindings: | Joypad | Keyboard | | ---------- | ----------- | @@ -45,17 +45,38 @@ On by default | Dpad Left | Left arrow | | Dpad Right | Right arrow | -### Running +### Raspberry Pi Baremetal (with ili9341 display and gpio buttons) -#### Desktop +1. Install the rust nightly toolchain for `armv7a-none-eabihf`: +```shell +rustup target add armv7a-none-eabihf --toolchain nightly +rustup +nightly component add rust-src +``` + +Unfurtuantly `armv7a-none-eabihf` is a [tier3](https://doc.rust-lang.org/nightly/rustc/platform-support.html#tier-3) target for the Rust compiler so building for it requires the nightly toolchain - [source](https://stackoverflow.com/questions/67352828/how-to-build-for-tier-3-target-not-included-in-rustup-target-list) + +> **Notice** Verify that you install the `armv7a-none-eabihf` target and not the `armv7a-none-eabi` target, as the later doesn't have support for hardware floats. + +2. Install Cargo Binutils: +```shell +cargo install cargo-binutils +rustup component add llvm-tools-preview +``` + +3. Edit the relevant settings in `configuration.rs` +4. Run `build.sh` or `build.bat` which will compile and create an bootable image called `kernel7.img` + +## Running + +### Desktop ```sh magenboy [path_to_rom] [other_optional_flags] ``` -#### Raspberry Pi +### Raspberry Pi Desktop with peripherals See - [RealMagenBoy](docs/RealMagenBoy.md) -### Optional flags +#### Optional flags * `--file-audio` - Saves the audio to a file * `--full-screen` - Full screen mode @@ -66,6 +87,37 @@ 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](https://github.com/raspberrypi/firmware/tree/master/boot) onto the SD card: + - [fixup4.dat](https://github.com/raspberrypi/firmware/raw/master/boot/fixup4.dat) + - [start4.elf](https://github.com/raspberrypi/firmware/raw/master/boot/start4.elf) + - [bcm2711-rpi-4-b.dtb](https://github.com/raspberrypi/firmware/raw/master/boot/bcm2711-rpi-4-b.dtb) +* 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: +```shell +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 @@ -125,4 +177,15 @@ Choose a game with the Joypad bindings (Dpad and A to confirm) - [Raspberry Pi docs](https://www.raspberrypi.com/documentation/computers/processors.html) - [juj/fbcp-ili9341 as a refference](https://github.com/juj/fbcp-ili9341) - [Raspberry Pi DMA programming in C](https://iosoft.blog/2020/05/25/raspberry-pi-dma-programming/) -- [Ili9341 docs](https://cdn-shop.adafruit.com/datasheets/ILI9341.pdf) \ No newline at end of file +- [Ili9341 docs](https://cdn-shop.adafruit.com/datasheets/ILI9341.pdf) +#### BareMetal RaspberryPi +- [Bare-metal Boot Code for ARMv8-A](http://classweb.ece.umd.edu/enee447.S2021/baremetal_boot_code_for_ARMv8_A_processors.pdf) +- [Low performance Baremetal code Blog post](https://forums.raspberrypi.com/viewtopic.php?t=219212) +- [Raspberry-Pi-Multicode examples by LdB-ECM](https://github.com/LdB-ECM/Raspberry-Pi) +- [RaspberryPi official Linux fork](https://github.com/raspberrypi/linux) +- ARM official Docs + - [ARM Cortex-A72 manual](https://developer.arm.com/documentation/100095/0003) + - [ARMv7-A Architecture Reference Manual](https://developer.arm.com/documentation/ddi0406/cb/?lang=en) + - [ARMv8-A Architecture Reference Manual](https://developer.arm.com/documentation/ddi0487/ia/?lang=en) + - [ARMv8-A Registers](https://developer.arm.com/documentation/ddi0595/2021-12/AArch32-Registers/CCSIDR--Current-Cache-Size-ID-Register?lang=en) + - [ARMv7-A programmer Guide](https://developer.arm.com/documentation/den0013/latest/) \ No newline at end of file