From ce161df9dc65384ae4fd8af5479da2d06eb02e67 Mon Sep 17 00:00:00 2001 From: OpenSauce Date: Sat, 22 Feb 2025 14:25:49 +0000 Subject: [PATCH 1/3] Update readme and few other housekeeping things --- .gitignore | 1 + README.md | 35 +++++++++++++++++++++++++++++++++-- src/emulator/cpu.rs | 6 +++--- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 6e771f8..2f724ee 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ target/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ +.zed/ diff --git a/README.md b/README.md index 72e7a8f..b1675c5 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,38 @@ -# emulator +# GameBoy Emulator + +A work-in-progress GameBoy emulator written in Rust. + +## Useful Links +- [Pan Docs](https://gbdev.io/pandocs/) – Official GameBoy hardware documentation. +- [How to Write an Emulator in Rust](https://gbdev.io/hardware/DMG01) – A guide to building your own emulator in Rust. +- [Cheatsheet](https://gbdev.io/pandocs/CPU_Instructions.html) – A quick reference for CPU instructions. +- [CPU Breakdown](https://rgbds.gbdev.io/docs/v0.9.1) – Detailed documentation of CPU operations. + +## Getting Started + +### Prerequisites +- **Rust:** Install the latest stable version from [rust-lang.org](https://www.rust-lang.org/tools/install). + +### Running the Emulator +Launch the emulator with a GameBoy ROM: +```bash +cargo run -- path/to/game.gb +``` + +### Testing +Run the test suite, which includes a set of GameBoy test ROMs: +```bash +cargo test +``` + +## Contributing +Contributions are welcome! Please review our [CONTRIBUTING](CONTRIBUTING.md) guidelines for details on our code of conduct and the process for submitting pull requests. ## License -This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. +This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. ### Third-Party Licenses - The test ROMs in `roms/` are from [Christoph Sprenger's Game Boy tests](https://github.com/CTSRD-CHRIS/gb-tests) and are licensed under the MIT License. See [LICENSE-THIRD-PARTY](LICENSE-THIRD-PARTY). + +## Acknowledgements +Special thanks to the GameBoy development community for the wealth of documentation and resources that have helped shape this project. diff --git a/src/emulator/cpu.rs b/src/emulator/cpu.rs index e4a55a6..c667c68 100644 --- a/src/emulator/cpu.rs +++ b/src/emulator/cpu.rs @@ -101,7 +101,7 @@ impl Cpu { println!("Add HL Not implemented"); } }, - Instruction::Jpnz() => { + Instruction::Jp() => { println!("JPNZ Not implemented"); } Instruction::Rlc(_target) => { @@ -137,7 +137,7 @@ impl fmt::Debug for Cpu { enum Instruction { Add(ArithmaticTarget), Nop(), - Jpnz(), + Jp(), Halt(), Rlc(ArithmaticTarget), } @@ -170,7 +170,7 @@ impl Instruction { 0x85 => Some(Instruction::Add(ArithmaticTarget::L)), 0x86 => Some(Instruction::Add(ArithmaticTarget::HL)), 0x87 => Some(Instruction::Add(ArithmaticTarget::A)), - 0xC3 => Some(Instruction::Jpnz()), + 0xC3 => Some(Instruction::Jp()), _ => None, } } From b79e2cf49bd335f60d6878e25cd1ac0ec3b743c6 Mon Sep 17 00:00:00 2001 From: OpenSauce Date: Sat, 22 Feb 2025 14:48:04 +0000 Subject: [PATCH 2/3] Clippy --- src/emulator/cpu.rs | 6 +++--- src/emulator/flags.rs | 5 +---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/emulator/cpu.rs b/src/emulator/cpu.rs index c667c68..ce3f5b2 100644 --- a/src/emulator/cpu.rs +++ b/src/emulator/cpu.rs @@ -214,7 +214,7 @@ impl Registers { } fn get_bc(&self) -> u16 { - (self.b as u16) << 8 | self.c as u16 + ((self.b as u16) << 8) | self.c as u16 } fn set_bc(&mut self, value: u16) { @@ -223,7 +223,7 @@ impl Registers { } fn get_de(&self) -> u16 { - (self.d as u16) << 8 | self.e as u16 + ((self.d as u16) << 8) | self.e as u16 } fn set_de(&mut self, value: u16) { @@ -232,7 +232,7 @@ impl Registers { } fn get_hl(&self) -> u16 { - (self.h as u16) << 8 | self.l as u16 + ((self.h as u16) << 8) | self.l as u16 } fn set_hl(&mut self, value: u16) { diff --git a/src/emulator/flags.rs b/src/emulator/flags.rs index 8847104..c3cc019 100644 --- a/src/emulator/flags.rs +++ b/src/emulator/flags.rs @@ -13,10 +13,7 @@ const CARRY_FLAG_BYTE_POSITION: u8 = 4; impl From for u8 { fn from(flag: FlagsRegister) -> u8 { - (if flag.zero { 1 } else { 0 }) << ZERO_FLAG_BYTE_POSITION - | (if flag.subtract { 1 } else { 0 }) << SUBTRACT_FLAG_BYTE_POSITION - | (if flag.half_carry { 1 } else { 0 }) << HALF_CARRY_FLAG_BYTE_POSITION - | (if flag.carry { 1 } else { 0 }) << CARRY_FLAG_BYTE_POSITION + ((if flag.zero { 1 } else { 0 }) << ZERO_FLAG_BYTE_POSITION) | ((if flag.subtract { 1 } else { 0 }) << SUBTRACT_FLAG_BYTE_POSITION) | ((if flag.half_carry { 1 } else { 0 }) << HALF_CARRY_FLAG_BYTE_POSITION) | ((if flag.carry { 1 } else { 0 }) << CARRY_FLAG_BYTE_POSITION) } } From 51a9b4e0dac2d6bdb02db72971c2c76032fe8fbf Mon Sep 17 00:00:00 2001 From: OpenSauce Date: Sat, 22 Feb 2025 14:49:04 +0000 Subject: [PATCH 3/3] Formatting --- src/emulator/flags.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/emulator/flags.rs b/src/emulator/flags.rs index c3cc019..18309e2 100644 --- a/src/emulator/flags.rs +++ b/src/emulator/flags.rs @@ -13,7 +13,10 @@ const CARRY_FLAG_BYTE_POSITION: u8 = 4; impl From for u8 { fn from(flag: FlagsRegister) -> u8 { - ((if flag.zero { 1 } else { 0 }) << ZERO_FLAG_BYTE_POSITION) | ((if flag.subtract { 1 } else { 0 }) << SUBTRACT_FLAG_BYTE_POSITION) | ((if flag.half_carry { 1 } else { 0 }) << HALF_CARRY_FLAG_BYTE_POSITION) | ((if flag.carry { 1 } else { 0 }) << CARRY_FLAG_BYTE_POSITION) + ((if flag.zero { 1 } else { 0 }) << ZERO_FLAG_BYTE_POSITION) + | ((if flag.subtract { 1 } else { 0 }) << SUBTRACT_FLAG_BYTE_POSITION) + | ((if flag.half_carry { 1 } else { 0 }) << HALF_CARRY_FLAG_BYTE_POSITION) + | ((if flag.carry { 1 } else { 0 }) << CARRY_FLAG_BYTE_POSITION) } }