Skip to content

Commit

Permalink
Fixed error in opcodes 0x22 and 0x32
Browse files Browse the repository at this point in the history
  • Loading branch information
velllu committed Sep 5, 2023
1 parent 7ce15ee commit 04c3a5d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,6 @@ impl GameBoy {
0x02 => { self.bus.write_byte(self.registers.get_bc(), self.registers.a); (1, 2) },
0x08 => todo!(), // this is a strange one,
0x12 => { self.bus.write_byte(self.registers.get_de(), self.registers.a); (1, 2) },
0x22 => { self.bus.write_byte(self.registers.get_hl(), self.registers.a.wrapping_add(1)); (1, 2) },
0x32 => { self.bus.write_byte(self.registers.get_hl(), self.registers.a.wrapping_sub(1)); (1, 2) },
0x36 => { self.bus.write_byte(self.registers.get_hl(), self.next(1)); (2, 3) },
0x70 => { self.bus.write_byte(self.registers.get_hl(), self.registers.b); (1, 2) },
0x71 => { self.bus.write_byte(self.registers.get_hl(), self.registers.c); (1, 2) },
Expand All @@ -212,6 +210,18 @@ impl GameBoy {
0x75 => { self.bus.write_byte(self.registers.get_hl(), self.registers.l); (1, 2) },
0x77 => { self.bus.write_byte(self.registers.get_hl(), self.registers.a); (1, 2) },

0x22 => {
self.bus.write_byte(self.registers.get_hl(), self.registers.a);
self.registers.set_hl(self.registers.get_hl().wrapping_add(1));
(1, 2)
},

0x32 => {
self.bus.write_byte(self.registers.get_hl(), self.registers.a);
self.registers.set_hl(self.registers.get_hl().wrapping_sub(1));
(1, 2)
},

// Jump
// When we jump, we set 0 bytes, because if we returned the "correct" amount
// of bytes, the program will add them to PC after the jump
Expand Down
3 changes: 2 additions & 1 deletion src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ mod cpu {

gb.step();

assert_eq!(0x02, gb.bus.read(gb.registers.get_hl()));
assert_eq!(0x01, gb.bus.read(gb.registers.get_hl().wrapping_sub(1)));
assert_eq!(0x01, gb.registers.l);
}

// Jumps vary so much, so it's better to have more tests
Expand Down

0 comments on commit 04c3a5d

Please sign in to comment.