From 04c3a5d757688e5b8cf70c694fb4c3ac5e47a6e1 Mon Sep 17 00:00:00 2001 From: velllu <91963404+velllu@users.noreply.github.com> Date: Tue, 5 Sep 2023 18:14:14 +0200 Subject: [PATCH] Fixed error in opcodes `0x22` and `0x32` --- src/cpu.rs | 14 ++++++++++++-- src/tests.rs | 3 ++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/cpu.rs b/src/cpu.rs index f1df0f5..63d0719 100644 --- a/src/cpu.rs +++ b/src/cpu.rs @@ -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) }, @@ -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 diff --git a/src/tests.rs b/src/tests.rs index 54e0d95..7d0d8d0 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -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