Some things (namely shift.rotate instructions) don't need to be quite so close to the Z80 implementation.

Signed-off-by: Adrian.Conlon <adrian.conlon@gmail.com>
This commit is contained in:
Adrian.Conlon 2017-07-21 19:23:36 +01:00
parent beca76d733
commit 0a02c32695
2 changed files with 37 additions and 47 deletions

View File

@ -184,17 +184,17 @@ namespace EightBit {
static void orr(uint8_t& f, uint8_t& operand, uint8_t value);
static void compare(uint8_t& f, uint8_t check, uint8_t value);
static uint8_t& rlc(uint8_t& f, uint8_t& operand);
static uint8_t& rrc(uint8_t& f, uint8_t& operand);
static uint8_t& rl(uint8_t& f, uint8_t& operand);
static uint8_t& rr(uint8_t& f, uint8_t& operand);
static uint8_t& sla(uint8_t& f, uint8_t& operand);
static uint8_t& sra(uint8_t& f, uint8_t& operand);
static uint8_t& srl(uint8_t& f, uint8_t& operand);
static void rlc(uint8_t& f, uint8_t& operand);
static void rrc(uint8_t& f, uint8_t& operand);
static void rl(uint8_t& f, uint8_t& operand);
static void rr(uint8_t& f, uint8_t& operand);
static void sla(uint8_t& f, uint8_t& operand);
static void sra(uint8_t& f, uint8_t& operand);
static void srl(uint8_t& f, uint8_t& operand);
static uint8_t& bit(uint8_t& f, int n, uint8_t& operand);
static uint8_t& res(int n, uint8_t& operand);
static uint8_t& set(int n, uint8_t& operand);
static void bit(uint8_t& f, int n, uint8_t& operand);
static void res(int n, uint8_t& operand);
static void set(int n, uint8_t& operand);
static void daa(uint8_t& a, uint8_t& f);
@ -202,6 +202,6 @@ namespace EightBit {
static void ccf(uint8_t& a, uint8_t& f);
static void cpl(uint8_t& a, uint8_t& f);
uint8_t& swap(uint8_t& f, uint8_t& operand);
static void swap(uint8_t& f, uint8_t& operand);
};
}

View File

@ -240,84 +240,76 @@ void EightBit::LR35902::compare(uint8_t& f, uint8_t check, uint8_t value) {
#pragma region Shift and rotate
uint8_t& EightBit::LR35902::rlc(uint8_t& f, uint8_t& operand) {
void EightBit::LR35902::rlc(uint8_t& f, uint8_t& operand) {
clearFlag(f, NF | HC);
setFlag(f, CF, operand & Bit7);
operand = _rotl8(operand, 1);
adjustZero<LR35902>(f, operand);
return operand;
}
uint8_t& EightBit::LR35902::rrc(uint8_t& f, uint8_t& operand) {
void EightBit::LR35902::rrc(uint8_t& f, uint8_t& operand) {
clearFlag(f, NF | HC);
setFlag(f, CF, operand & Bit0);
operand = _rotr8(operand, 1);
adjustZero<LR35902>(f, operand);
return operand;
}
uint8_t& EightBit::LR35902::rl(uint8_t& f, uint8_t& operand) {
void EightBit::LR35902::rl(uint8_t& f, uint8_t& operand) {
clearFlag(f, NF | HC);
const auto carry = (f & CF) >> 4;
setFlag(f, CF, operand & Bit7);
operand = (operand << 1) | carry;
adjustZero<LR35902>(f, operand);
return operand;
}
uint8_t& EightBit::LR35902::rr(uint8_t& f, uint8_t& operand) {
void EightBit::LR35902::rr(uint8_t& f, uint8_t& operand) {
clearFlag(f, NF | HC);
const auto carry = (f & CF) >> 4;
setFlag(f, CF, operand & Bit0);
operand = (operand >> 1) | (carry << 7);
adjustZero<LR35902>(f, operand);
return operand;
}
//
uint8_t& EightBit::LR35902::sla(uint8_t& f, uint8_t& operand) {
void EightBit::LR35902::sla(uint8_t& f, uint8_t& operand) {
clearFlag(f, NF | HC);
setFlag(f, CF, operand & Bit7);
operand <<= 1;
adjustZero<LR35902>(f, operand);
return operand;
}
uint8_t& EightBit::LR35902::sra(uint8_t& f, uint8_t& operand) {
void EightBit::LR35902::sra(uint8_t& f, uint8_t& operand) {
clearFlag(f, NF | HC);
setFlag(f, CF, operand & Bit0);
operand = (operand >> 1) | operand & Bit7;
adjustZero<LR35902>(f, operand);
return operand;
}
uint8_t& EightBit::LR35902::srl(uint8_t& f, uint8_t& operand) {
void EightBit::LR35902::srl(uint8_t& f, uint8_t& operand) {
clearFlag(f, NF | HC);
setFlag(f, CF, operand & Bit0);
operand = (operand >> 1) & ~Bit7;
adjustZero<LR35902>(f, operand);
return operand;
}
#pragma endregion Shift and rotate
#pragma region BIT/SET/RES
uint8_t& EightBit::LR35902::bit(uint8_t& f, int n, uint8_t& operand) {
void EightBit::LR35902::bit(uint8_t& f, int n, uint8_t& operand) {
auto carry = f & CF;
uint8_t discarded = operand;
andr(f, discarded, 1 << n);
setFlag(f, CF, carry);
return operand;
}
uint8_t& EightBit::LR35902::res(int n, uint8_t& operand) {
return operand &= ~(1 << n);
void EightBit::LR35902::res(int n, uint8_t& operand) {
operand &= ~(1 << n);
}
uint8_t& EightBit::LR35902::set(int n, uint8_t& operand) {
return operand |= (1 << n);
void EightBit::LR35902::set(int n, uint8_t& operand) {
operand |= (1 << n);
}
#pragma endregion BIT/SET/RES
@ -358,18 +350,16 @@ void EightBit::LR35902::scf(uint8_t& a, uint8_t& f) {
}
void EightBit::LR35902::ccf(uint8_t& a, uint8_t& f) {
auto carry = f & CF;
clearFlag(f, CF, carry);
clearFlag(f, NF | HC);
clearFlag(f, CF, f & CF);
}
uint8_t& EightBit::LR35902::swap(uint8_t& f, uint8_t& operand) {
void EightBit::LR35902::swap(uint8_t& f, uint8_t& operand) {
auto low = lowNibble(operand);
auto high = highNibble(operand);
operand = promoteNibble(low) | demoteNibble(high);
adjustZero<LR35902>(f, operand);
clearFlag(f, NF | HC | CF);
return operand;
}
#pragma endregion Miscellaneous instructions
@ -410,28 +400,28 @@ void EightBit::LR35902::executeCB(int x, int y, int z, int p, int q) {
case 0: // rot[y] r[z]
switch (y) {
case 0:
adjustZero<LR35902>(f, rlc(f, R(z, a)));
rlc(f, R(z, a));
break;
case 1:
adjustZero<LR35902>(f, rrc(f, R(z, a)));
rrc(f, R(z, a));
break;
case 2:
adjustZero<LR35902>(f, rl(f, R(z, a)));
rl(f, R(z, a));
break;
case 3:
adjustZero<LR35902>(f, rr(f, R(z, a)));
rr(f, R(z, a));
break;
case 4:
adjustZero<LR35902>(f, sla(f, R(z, a)));
sla(f, R(z, a));
break;
case 5:
adjustZero<LR35902>(f, sra(f, R(z, a)));
sra(f, R(z, a));
break;
case 6:
adjustZero<LR35902>(f, swap(f, R(z, a)));
swap(f, R(z, a));
break;
case 7:
adjustZero<LR35902>(f, srl(f, R(z, a)));
srl(f, R(z, a));
break;
default:
__assume(0);
@ -607,16 +597,16 @@ void EightBit::LR35902::executeOther(int x, int y, int z, int p, int q) {
case 7: // Assorted operations on accumulator/flags
switch (y) {
case 0:
adjustZero<LR35902>(f, rlc(f, a));
rlc(f, a);
break;
case 1:
adjustZero<LR35902>(f, rrc(f, a));
rrc(f, a);
break;
case 2:
adjustZero<LR35902>(f, rl(f, a));
rl(f, a);
break;
case 3:
adjustZero<LR35902>(f, rr(f, a));
rr(f, a);
break;
case 4:
daa(a, f);