Backport fixes from .Net EightBit library to C++

Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon 2019-08-16 21:56:48 +01:00
parent 5e9014997a
commit 5ed01b61d1
5 changed files with 23 additions and 18 deletions

View File

@ -177,7 +177,7 @@ namespace EightBit {
void stc();
void cmc();
void xhtl();
void xhtl(register16_t& exchange);
void writePort(uint8_t port);
void writePort();

View File

@ -237,14 +237,15 @@ void EightBit::Intel8080::cmc() {
clearFlag(F(), CF, F() & CF);
}
void EightBit::Intel8080::xhtl() {
void EightBit::Intel8080::xhtl(register16_t& exchange) {
MEMPTR().low = busRead(SP());
busWrite(L());
L() = MEMPTR().low;
++BUS().ADDRESS();
MEMPTR().high = busRead();
busWrite(H());
H() = MEMPTR().high;
busWrite(exchange.high);
exchange.high = MEMPTR().high;
--BUS().ADDRESS();
busWrite(exchange.low);
exchange.low = MEMPTR().low;
}
void EightBit::Intel8080::writePort(const uint8_t port) {
@ -543,7 +544,7 @@ void EightBit::Intel8080::execute(const int x, const int y, const int z, const i
tick(11);
break;
case 4: // EX (SP),HL
xhtl();
xhtl(HL());
tick(19);
break;
case 5: // EX DE,HL

View File

@ -343,7 +343,7 @@ namespace EightBit {
void ccf();
void cpl();
void xhtl();
void xhtl(register16_t& exchange);
void blockCompare(register16_t source, register16_t& counter);

View File

@ -487,14 +487,15 @@ void EightBit::Z80::ccf() {
adjustXY<Z80>(F(), A());
}
void EightBit::Z80::xhtl() {
void EightBit::Z80::xhtl(register16_t& exchange) {
MEMPTR().low = busRead(SP());
busWrite(HL2().low);
HL2().low = MEMPTR().low;
++BUS().ADDRESS();
MEMPTR().high = busRead();
busWrite(HL2().high);
HL2().high = MEMPTR().high;
busWrite(exchange.high);
exchange.high = MEMPTR().high;
--BUS().ADDRESS();
busWrite(exchange.low);
exchange.low = MEMPTR().low;
}
void EightBit::Z80::blockCompare(const register16_t source, register16_t& counter) {
@ -592,9 +593,9 @@ bool EightBit::Z80::indr() {
void EightBit::Z80::blockOut(const register16_t source, register16_t& destination) {
const auto value = busRead(source);
destination.high = decrement(destination.high);
BUS().ADDRESS() = destination;
writePort();
destination.high = decrement(destination.high);
MEMPTR() = destination;
setFlag(F(), NF, value & Bit7);
setFlag(F(), HC | CF, (L() + value) > 0xff);
@ -790,7 +791,8 @@ void EightBit::Z80::executeCB(const int x, const int y, const int z) {
tick(7);
} else {
busWrite(operand);
R2(z, operand);
if (LIKELY(!memoryZ))
R2(z, operand);
tick(15);
}
}
@ -1377,7 +1379,7 @@ void EightBit::Z80::executeOther(const int x, const int y, const int z, const in
tick(11);
break;
case 4: // EX (SP),HL
xhtl();
xhtl(HL2());
tick(19);
break;
case 5: // EX DE,HL

View File

@ -161,9 +161,11 @@ namespace EightBit {
}
auto jrConditional(const int condition) {
const int8_t offset = fetchByte();
if (condition)
const auto offsetAddress = PC()++;
if (condition) {
const auto offset = busRead(offsetAddress);
jr(offset);
}
return !!condition;
}