Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
35 changes: 33 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
12 changes: 6 additions & 6 deletions src/emulator/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl Cpu {
println!("Add HL Not implemented");
}
},
Instruction::Jpnz() => {
Instruction::Jp() => {
println!("JPNZ Not implemented");
}
Instruction::Rlc(_target) => {
Expand Down Expand Up @@ -137,7 +137,7 @@ impl fmt::Debug for Cpu {
enum Instruction {
Add(ArithmaticTarget),
Nop(),
Jpnz(),
Jp(),
Halt(),
Rlc(ArithmaticTarget),
}
Expand Down Expand Up @@ -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,
}
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions src/emulator/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ const CARRY_FLAG_BYTE_POSITION: u8 = 4;

impl From<FlagsRegister> 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)
}
}

Expand Down