I am writing a gameboy emulator and I am currently implementing 0xCB 0x19 instruction.
I am using this test rom: https://github.com/retrio/gb-test-roms/blob/master/cpu_instrs/individual/06-ld%20r%2Cr.gb and comparing my logs against https://github.com/wheremyfoodat/Gameboy-logs/blob/master/Blargg6LYStubbed.zip and I am stuck at as according to those logs the instruction 0xCB 0x19 will change the value in register C from 0x47 to 0x23 while my implementation changes it to 0xA3.
Here is my implementations:
pub fn rr_reg8(&mut self, register_name: RegisterName, register_byte: RegisterByteName) -> u64 {
self.clear_flag(Flag::HalfCarry);
self.clear_flag(Flag::Subtraction);
let shifted_bit = utils::data::check_bit(self.registers[register_name][register_byte], 0);
if shifted_bit {
self.set_flag(Flag::Carry);
} else {
self.clear_flag(Flag::Carry);
}
self.registers[register_name][register_byte] >>= 1;
if self.registers[register_name][register_byte] == 0 {
self.set_flag(Flag::Zero);
} else {
self.clear_flag(Flag::Zero);
}
if self.check_flag(Flag::Carry) {
utils::data::set_bit(&mut self.registers[register_name][register_byte], 7);
}
8
}
Is this not how rotate through carry should work? Or is there an issue with the logs?