Possible mistake in opcode function RLCr (CPU)?
ybchen97 opened this issue · 1 comments
ybchen97 commented
In the comment above the function it says that "the content of bit 7 is copied to the carry flag and also to bit 0." However, in the code below, bit 0 of r is set to the old carry flag instead of the old bit 7. Is there a possible mistake here?
Function here:
/*
RLC r
11001011(CB) 00000rrr
The contents of 8-bit register r are rotated left 1-bit position. The content of bit 7
is copied to the carry flag and also to bit 0. Operand r identifies register
B, C, D, E, H, L, or A.
8 Cycles
Flags affected(znhc): z00c
*/
unsigned long CPU::RLCr(const byte& opCode)
{
byte* r = GetByteRegister(opCode);
// Grab bit 7 and store it in the carryflag
ISBITSET(*r, 7) ? SetFlag(CarryFlag) : ClearFlag(CarryFlag);
// Shift r left
(*r) = *r << 1;
// Set bit 0 of r to the old CarryFlag
(*r) = IsFlagSet(CarryFlag) ? SETBIT((*r), 0) : CLEARBIT((*r), 0); // <== over here
// Affects Z, clears N, clears H, affects C
(*r == 0x00) ? SetFlag(ZeroFlag) : ClearFlag(ZeroFlag);
ClearFlag(SubtractFlag);
ClearFlag(HalfCarryFlag);
return 8;
}
ybchen97 commented
Oh oops my mistake, bit 7 is copied into the carry flag!