Rearrange some of the shift/rotate code a little to make it easier to read.

Signed-off-by: Adrian.Conlon <adrian.conlon@gmail.com>
This commit is contained in:
Adrian.Conlon 2017-08-16 22:51:15 +01:00
parent 54ab96ea38
commit 039545bd08

View File

@ -220,54 +220,50 @@ void EightBit::LR35902::compare(uint8_t& f, uint8_t check, uint8_t value) {
uint8_t EightBit::LR35902::rlc(uint8_t& f, uint8_t operand) {
clearFlag(f, NF | HC | ZF);
setFlag(f, CF, operand & Bit7);
operand = _rotl8(operand, 1);
return operand;
return _rotl8(operand, 1);
}
uint8_t EightBit::LR35902::rrc(uint8_t& f, uint8_t operand) {
clearFlag(f, NF | HC | ZF);
setFlag(f, CF, operand & Bit0);
operand = _rotr8(operand, 1);
return operand;
return _rotr8(operand, 1);
}
uint8_t EightBit::LR35902::rl(uint8_t& f, uint8_t operand) {
clearFlag(f, NF | HC | ZF);
const auto carry = (f & CF) >> 4;
const auto carry = f & CF;
setFlag(f, CF, operand & Bit7);
operand = (operand << 1) | carry;
return operand;
return (operand << 1) | (carry >> 4); // CF at Bit4
}
uint8_t EightBit::LR35902::rr(uint8_t& f, uint8_t operand) {
clearFlag(f, NF | HC | ZF);
const auto carry = (f & CF) >> 4;
const auto carry = f & CF;
setFlag(f, CF, operand & Bit0);
operand = (operand >> 1) | (carry << 7);
return operand;
return (operand >> 1) | (carry << 3); // CF at Bit4
}
//
uint8_t EightBit::LR35902::sla(uint8_t& f, uint8_t operand) {
clearFlag(f, NF | HC | ZF);
setFlag(f, CF, operand & Bit7);
operand <<= 1;
return operand;
return operand << 1;
}
uint8_t EightBit::LR35902::sra(uint8_t& f, uint8_t operand) {
clearFlag(f, NF | HC | ZF);
setFlag(f, CF, operand & Bit0);
operand = (operand >> 1) | operand & Bit7;
return operand;
return (operand >> 1) | (operand & Bit7);
}
uint8_t EightBit::LR35902::swap(uint8_t& f, uint8_t operand) {
clearFlag(f, NF | HC | CF);
return promoteNibble(operand) | demoteNibble(operand);
}
uint8_t EightBit::LR35902::srl(uint8_t& f, uint8_t operand) {
clearFlag(f, NF | HC | ZF);
setFlag(f, CF, operand & Bit0);
operand = (operand >> 1) & ~Bit7;
return operand;
return (operand >> 1) & ~Bit7;
}
#pragma endregion Shift and rotate
@ -332,15 +328,6 @@ void EightBit::LR35902::ccf(uint8_t& a, uint8_t& f) {
clearFlag(f, CF, f & CF);
}
uint8_t EightBit::LR35902::swap(uint8_t& f, uint8_t operand) {
auto low = lowNibble(operand);
auto high = highNibble(operand);
operand = promoteNibble(low) | high;
adjustZero<LR35902>(f, operand);
clearFlag(f, NF | HC | CF);
return operand;
}
#pragma endregion Miscellaneous instructions
int EightBit::LR35902::step() {