More i8080 and LR35902 consistency.

Signed-off-by: Adrian.Conlon <adrian.conlon@gmail.com>
This commit is contained in:
Adrian.Conlon 2017-07-25 21:22:15 +01:00
parent 1b11e0750b
commit 8535efb30d
2 changed files with 42 additions and 49 deletions

View File

@ -148,16 +148,16 @@ namespace EightBit {
static void orr(uint8_t& f, uint8_t& operand, uint8_t value); 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 void compare(uint8_t& f, uint8_t check, uint8_t value);
void rlc(); static void rlc(uint8_t& f, uint8_t& operand);
void rrc(); static void rrc(uint8_t& f, uint8_t& operand);
void ral(); static void rl(uint8_t& f, uint8_t& operand);
void rar(); static void rr(uint8_t& f, uint8_t& operand);
void daa(); static void daa(uint8_t& a, uint8_t& f);
void cma(); static void cma(uint8_t& a, uint8_t& f);
void stc(); static void stc(uint8_t& a, uint8_t& f);
void cmc(); static void cmc(uint8_t& a, uint8_t& f);
void xhtl(); void xhtl();

View File

@ -200,66 +200,59 @@ void EightBit::Intel8080::compare(uint8_t& f, uint8_t check, uint8_t value) {
#pragma region Shift and rotate #pragma region Shift and rotate
void EightBit::Intel8080::rlc() { void EightBit::Intel8080::rlc(uint8_t& f, uint8_t& operand) {
auto& a = A(); auto carry = operand & Bit7;
auto carry = a & Bit7; operand = (operand << 1) | (carry >> 7);
a = (a << 1) | (carry >> 7); setFlag(f, CF, carry);
setFlag(F(), CF, carry);
} }
void EightBit::Intel8080::rrc() { void EightBit::Intel8080::rrc(uint8_t& f, uint8_t& operand) {
auto& a = A(); auto carry = operand & Bit0;
auto carry = a & Bit0; operand = (operand >> 1) | (carry << 7);
a = (a >> 1) | (carry << 7); setFlag(f, CF, carry);
setFlag(F(), CF, carry);
} }
void EightBit::Intel8080::ral() { void EightBit::Intel8080::rl(uint8_t& f, uint8_t& operand) {
auto& a = A();
auto& f = F();
const auto carry = f & CF; const auto carry = f & CF;
setFlag(f, CF, a & Bit7); setFlag(f, CF, operand & Bit7);
a = (a << 1) | carry; operand = (operand << 1) | carry;
} }
void EightBit::Intel8080::rar() { void EightBit::Intel8080::rr(uint8_t& f, uint8_t& operand) {
auto& a = A();
auto& f = F();
const auto carry = f & CF; const auto carry = f & CF;
setFlag(f, CF, a & Bit0); setFlag(f, CF, operand & Bit0);
a = (a >> 1) | (carry << 7); operand = (operand >> 1) | (carry << 7);
} }
#pragma endregion Shift and rotate #pragma endregion Shift and rotate
#pragma region Miscellaneous instructions #pragma region Miscellaneous instructions
void EightBit::Intel8080::daa() { void EightBit::Intel8080::daa(uint8_t& a, uint8_t& f) {
const auto& a = A(); const auto& before = a;
auto& f = F();
auto carry = f & CF; auto carry = f & CF;
uint8_t addition = 0; uint8_t addition = 0;
if ((f & AC) || lowNibble(a) > 9) { if ((f & AC) || lowNibble(before) > 9) {
addition = 0x6; addition = 0x6;
} }
if ((f & CF) || highNibble(a) > 9 || (highNibble(a) >= 9 && lowNibble(a) > 9)) { if ((f & CF) || highNibble(before) > 9 || (highNibble(before) >= 9 && lowNibble(before) > 9)) {
addition |= 0x60; addition |= 0x60;
carry = true; carry = true;
} }
add(f, A(), addition); add(f, a, addition);
setFlag(f, CF, carry); setFlag(f, CF, carry);
} }
void EightBit::Intel8080::cma() { void EightBit::Intel8080::cma(uint8_t& a, uint8_t& f) {
A() = ~A(); a = ~a;
} }
void EightBit::Intel8080::stc() { void EightBit::Intel8080::stc(uint8_t& a, uint8_t& f) {
setFlag(F(), CF); setFlag(f, CF);
} }
void EightBit::Intel8080::cmc() { void EightBit::Intel8080::cmc(uint8_t& a, uint8_t& f) {
clearFlag(F(), CF, F() & CF); clearFlag(f, CF, f & CF);
} }
void EightBit::Intel8080::xhtl() { void EightBit::Intel8080::xhtl() {
@ -290,7 +283,7 @@ void EightBit::Intel8080::in() {
int EightBit::Intel8080::step() { int EightBit::Intel8080::step() {
ExecutingInstruction.fire(*this); ExecutingInstruction.fire(*this);
cycles = 0; cycles = 0;
return execute(fetchByte()); return fetchExecute();
} }
int EightBit::Intel8080::execute(uint8_t opcode) { int EightBit::Intel8080::execute(uint8_t opcode) {
@ -427,28 +420,28 @@ void EightBit::Intel8080::execute(int x, int y, int z, int p, int q) {
case 7: // Assorted operations on accumulator/flags case 7: // Assorted operations on accumulator/flags
switch (y) { switch (y) {
case 0: case 0:
rlc(); rlc(f, a);
break; break;
case 1: case 1:
rrc(); rrc(f, a);
break; break;
case 2: case 2:
ral(); rl(f, a);
break; break;
case 3: case 3:
rar(); rr(f, a);
break; break;
case 4: case 4:
daa(); daa(a, f);
break; break;
case 5: case 5:
cma(); cma(a, f);
break; break;
case 6: case 6:
stc(); stc(a, f);
break; break;
case 7: case 7:
cmc(); cmc(a, f);
break; break;
default: default:
__assume(0); __assume(0);