Some *small* consistency changes. Perhaps some performance gains.

Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon
2018-04-11 23:53:26 +01:00
parent d818095815
commit 4b4f6b1a49
5 changed files with 39 additions and 47 deletions

View File

@@ -149,9 +149,9 @@ namespace EightBit {
void di(); void di();
void ei(); void ei();
bool returnConditionalFlag(uint8_t& f, int flag); bool returnConditionalFlag(uint8_t f, int flag);
bool jumpConditionalFlag(uint8_t& f, int flag); bool jumpConditionalFlag(uint8_t f, int flag);
bool callConditionalFlag(uint8_t& f, int flag); bool callConditionalFlag(uint8_t f, int flag);
static void add(uint8_t& f, register16_t& operand, register16_t value); static void add(uint8_t& f, register16_t& operand, register16_t value);
@@ -170,9 +170,9 @@ namespace EightBit {
static void daa(uint8_t& a, uint8_t& f); static void daa(uint8_t& a, uint8_t& f);
static void cma(uint8_t& a, uint8_t& f); static void cma(uint8_t& a);
static void stc(uint8_t& a, uint8_t& f); static void stc(uint8_t& f);
static void cmc(uint8_t& a, uint8_t& f); static void cmc(uint8_t& f);
void xhtl(register16_t& operand); void xhtl(register16_t& operand);

View File

@@ -47,7 +47,7 @@ void EightBit::Intel8080::decrement(uint8_t& f, uint8_t& operand) {
setFlag(f, AC, lowNibble(operand) != Mask4); setFlag(f, AC, lowNibble(operand) != Mask4);
} }
bool EightBit::Intel8080::jumpConditionalFlag(uint8_t& f, int flag) { bool EightBit::Intel8080::jumpConditionalFlag(const uint8_t f, const int flag) {
switch (flag) { switch (flag) {
case 0: // NZ case 0: // NZ
return jumpConditional(!(f & ZF)); return jumpConditional(!(f & ZF));
@@ -70,7 +70,7 @@ bool EightBit::Intel8080::jumpConditionalFlag(uint8_t& f, int flag) {
} }
} }
bool EightBit::Intel8080::returnConditionalFlag(uint8_t& f, int flag) { bool EightBit::Intel8080::returnConditionalFlag(const uint8_t f, const int flag) {
switch (flag) { switch (flag) {
case 0: // NZ case 0: // NZ
return returnConditional(!(f & ZF)); return returnConditional(!(f & ZF));
@@ -93,7 +93,7 @@ bool EightBit::Intel8080::returnConditionalFlag(uint8_t& f, int flag) {
} }
} }
bool EightBit::Intel8080::callConditionalFlag(uint8_t& f, int flag) { bool EightBit::Intel8080::callConditionalFlag(const uint8_t f, int flag) {
switch (flag) { switch (flag) {
case 0: // NZ case 0: // NZ
return callConditional(!(f & ZF)); return callConditional(!(f & ZF));
@@ -215,15 +215,15 @@ void EightBit::Intel8080::daa(uint8_t& a, uint8_t& f) {
setFlag(f, CF, carry); setFlag(f, CF, carry);
} }
void EightBit::Intel8080::cma(uint8_t& a, uint8_t& f) { void EightBit::Intel8080::cma(uint8_t& a) {
a = ~a; a = ~a;
} }
void EightBit::Intel8080::stc(uint8_t& a, uint8_t& f) { void EightBit::Intel8080::stc(uint8_t& f) {
setFlag(f, CF); setFlag(f, CF);
} }
void EightBit::Intel8080::cmc(uint8_t& a, uint8_t& f) { void EightBit::Intel8080::cmc(uint8_t& f) {
clearFlag(f, CF, f & CF); clearFlag(f, CF, f & CF);
} }
@@ -429,13 +429,13 @@ void EightBit::Intel8080::execute(uint8_t& a, uint8_t& f, int x, int y, int z, i
daa(a, f); daa(a, f);
break; break;
case 5: case 5:
cma(a, f); cma(a);
break; break;
case 6: case 6:
stc(a, f); stc(f);
break; break;
case 7: case 7:
cmc(a, f); cmc(f);
break; break;
default: default:
UNREACHABLE; UNREACHABLE;
@@ -509,7 +509,7 @@ void EightBit::Intel8080::execute(uint8_t& a, uint8_t& f, int x, int y, int z, i
addCycles(10); addCycles(10);
break; break;
case 2: // JP HL case 2: // JP HL
PC() = HL(); jump(HL());
addCycles(4); addCycles(4);
break; break;
case 3: // LD SP,HL case 3: // LD SP,HL
@@ -529,7 +529,7 @@ void EightBit::Intel8080::execute(uint8_t& a, uint8_t& f, int x, int y, int z, i
case 3: // Assorted operations case 3: // Assorted operations
switch (y) { switch (y) {
case 0: // JP nn case 0: // JP nn
jump(MEMPTR() = fetchWord()); jump(fetchWord());
addCycles(10); addCycles(10);
break; break;
case 2: // OUT (n),A case 2: // OUT (n),A
@@ -572,7 +572,7 @@ void EightBit::Intel8080::execute(uint8_t& a, uint8_t& f, int x, int y, int z, i
case 1: case 1:
switch (p) { switch (p) {
case 0: // CALL nn case 0: // CALL nn
call(MEMPTR() = fetchWord()); call(fetchWord());
addCycles(17); addCycles(17);
break; break;
} }

View File

@@ -688,7 +688,7 @@ void EightBit::GameBoy::LR35902::executeOther(uint8_t& a, uint8_t& f, int x, int
addCycles(4); addCycles(4);
break; break;
case 2: // JP HL case 2: // JP HL
PC() = HL(); jump(HL());
addCycle(); addCycle();
break; break;
case 3: // LD SP,HL case 3: // LD SP,HL
@@ -738,7 +738,7 @@ void EightBit::GameBoy::LR35902::executeOther(uint8_t& a, uint8_t& f, int x, int
switch (y) { switch (y) {
case 0: // JP nn case 0: // JP nn
MEMPTR() = fetchWord(); MEMPTR() = fetchWord();
jump(); jump(MEMPTR());
addCycles(4); addCycles(4);
break; break;
case 1: // CB prefix case 1: // CB prefix
@@ -770,7 +770,7 @@ void EightBit::GameBoy::LR35902::executeOther(uint8_t& a, uint8_t& f, int x, int
switch (p) { switch (p) {
case 0: // CALL nn case 0: // CALL nn
MEMPTR() = fetchWord(); MEMPTR() = fetchWord();
call(); call(MEMPTR());
addCycles(6); addCycles(6);
break; break;
} }

View File

@@ -47,7 +47,7 @@ int EightBit::MOS6502::step() {
void EightBit::MOS6502::reset() { void EightBit::MOS6502::reset() {
Processor::reset(); Processor::reset();
PC() = getWordPaged(0xff, RSTvector); jump(getWordPaged(0xff, RSTvector));
} }
EightBit::register16_t EightBit::MOS6502::getWordPaged(uint8_t page, uint8_t offset) { EightBit::register16_t EightBit::MOS6502::getWordPaged(uint8_t page, uint8_t offset) {
@@ -75,7 +75,7 @@ void EightBit::MOS6502::interrupt(uint8_t vector) {
pushWord(PC()); pushWord(PC());
push(P()); push(P());
setFlag(P(), IF); setFlag(P(), IF);
PC() = getWordPaged(0xff, vector); jump(getWordPaged(0xff, vector));
} }
int EightBit::MOS6502::execute(uint8_t cell) { int EightBit::MOS6502::execute(uint8_t cell) {
@@ -543,5 +543,5 @@ void EightBit::MOS6502::BRK() {
pushWord(PC()); pushWord(PC());
PHP(); PHP();
setFlag(P(), IF); setFlag(P(), IF);
PC() = getWordPaged(0xff, IRQvector); jump(getWordPaged(0xff, IRQvector));
} }

View File

@@ -495,20 +495,12 @@ void EightBit::Z80::cpd(const uint8_t a, uint8_t& f) {
bool EightBit::Z80::cpir(const uint8_t a, uint8_t& f) { bool EightBit::Z80::cpir(const uint8_t a, uint8_t& f) {
cpi(a, f); cpi(a, f);
MEMPTR() = PC(); return (f & PF) && !(f & ZF); // See CPI
const auto again = (f & PF) && !(f & ZF); // See CPI
if (LIKELY(again))
--MEMPTR().word;
return again;
} }
bool EightBit::Z80::cpdr(const uint8_t a, uint8_t& f) { bool EightBit::Z80::cpdr(const uint8_t a, uint8_t& f) {
cpd(a, f); cpd(a, f);
MEMPTR().word = PC().word - 1; return (f & PF) && !(f & ZF); // See CPD
const auto again = (f & PF) && !(f & ZF); // See CPD
if (UNLIKELY(!again))
--MEMPTR().word;
return again;
} }
void EightBit::Z80::blockLoad(const uint8_t a, uint8_t& f, const register16_t source, const register16_t destination) { void EightBit::Z80::blockLoad(const uint8_t a, uint8_t& f, const register16_t source, const register16_t destination) {
@@ -535,18 +527,12 @@ void EightBit::Z80::ldi(const uint8_t a, uint8_t& f) {
bool EightBit::Z80::ldir(const uint8_t a, uint8_t& f) { bool EightBit::Z80::ldir(const uint8_t a, uint8_t& f) {
ldi(a, f); ldi(a, f);
const auto again = (f & PF) != 0; return !!(f & PF); // See LDI
if (LIKELY(again)) // See LDI
MEMPTR().word = PC().word - 1;
return again;
} }
bool EightBit::Z80::lddr(const uint8_t a, uint8_t& f) { bool EightBit::Z80::lddr(const uint8_t a, uint8_t& f) {
ldd(a, f); ldd(a, f);
const auto again = (f & PF) != 0; return !!(f & PF); // See LDD
if (LIKELY(again)) // See LDR
MEMPTR().word = PC().word - 1;
return again;
} }
void EightBit::Z80::ini(uint8_t& f) { void EightBit::Z80::ini(uint8_t& f) {
@@ -999,13 +985,15 @@ void EightBit::Z80::executeED(uint8_t& a, uint8_t& f, const int x, const int y,
break; break;
case 6: // LDIR case 6: // LDIR
if (LIKELY(ldir(a, f))) { if (LIKELY(ldir(a, f))) {
PC().word -= 2; MEMPTR().word = --PC().word;
--PC().word;
addCycles(5); addCycles(5);
} }
break; break;
case 7: // LDDR case 7: // LDDR
if (LIKELY(lddr(a, f))) { if (LIKELY(lddr(a, f))) {
PC().word -= 2; MEMPTR().word = --PC().word;
--PC().word;
addCycles(5); addCycles(5);
} }
break; break;
@@ -1021,14 +1009,18 @@ void EightBit::Z80::executeED(uint8_t& a, uint8_t& f, const int x, const int y,
break; break;
case 6: // CPIR case 6: // CPIR
if (LIKELY(cpir(a, f))) { if (LIKELY(cpir(a, f))) {
PC().word -= 2; MEMPTR().word = --PC().word;
--PC().word;
addCycles(5); addCycles(5);
} }
break; break;
case 7: // CPDR case 7: // CPDR
if (LIKELY(cpdr(a, f))) { if (LIKELY(cpdr(a, f))) {
PC().word -= 2; MEMPTR().word = --PC().word;
--PC().word;
addCycles(5); addCycles(5);
} else {
MEMPTR().word = PC().word - 2;
} }
break; break;
} }
@@ -1382,7 +1374,7 @@ void EightBit::Z80::executeOther(uint8_t& a, uint8_t& f, const int x, const int
addCycles(4); addCycles(4);
break; break;
case 2: // JP HL case 2: // JP HL
PC() = HL2(); jump(HL2());
addCycles(4); addCycles(4);
break; break;
case 3: // LD SP,HL case 3: // LD SP,HL