Skip to content

Commit

Permalink
Fixed GameBoy.call() instruction
Browse files Browse the repository at this point in the history
Look at the comment I added to see the problem
  • Loading branch information
velllu committed Nov 19, 2023
1 parent d586dd7 commit 3ce263d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/cpu/opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ impl GameBoy {
// Call functions
impl GameBoy {
fn call(&mut self) {
let (p, c) = split_u16_into_two_u8s(self.registers.pc);
// We need to add 3 to the PC because the `call` instruction uses the PC of the
// next instruction, a `call` instruction is 3 bytes long so we need to skip
// 3 bytes. Please do not ask how much this took me to debug.
let (p, c) = split_u16_into_two_u8s(self.registers.pc + 3);

self.registers.sp = self.registers.sp.wrapping_sub(1);
self.bus[self.registers.sp] = c;
Expand Down

0 comments on commit 3ce263d

Please sign in to comment.