Skip to content

Commit

Permalink
Fixed wrong bitwise operation instruction
Browse files Browse the repository at this point in the history
For example, `or c` used to modify the c register,
but it should store the results in the a register
instead
  • Loading branch information
velllu committed Nov 23, 2023
1 parent 1597f9e commit 24d20a8
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/cpu/opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,14 @@ impl GameBoy {
// Bitwise operation functions
impl GameBoy {
fn bitwise_operation_r(&mut self, register: OneByteRegister, operation: BitwiseOperation) {
let register_a = *self.registers.get_r(OneByteRegister::A);
let register = self.registers.get_r(register);
let register = *self.registers.get_r(register);

let result = match operation {
BitwiseOperation::Or => *register | register_a,
BitwiseOperation::Xor => *register ^ register_a,
BitwiseOperation::Or => register | self.registers.a,
BitwiseOperation::Xor => register ^ self.registers.a,
};

*register = result;

self.registers.a = result;
self.flags.update_zero_flag(result);
}
}
Expand Down

0 comments on commit 24d20a8

Please sign in to comment.