mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2025-01-11 02:29:50 +00:00
Easier to read flag handling in the 6809
Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
parent
21e8360dc1
commit
adb6433737
@ -235,6 +235,7 @@ namespace EightBit {
|
|||||||
int zero() { return CC() & ZF; }
|
int zero() { return CC() & ZF; }
|
||||||
int overflow() { return CC() & VF; }
|
int overflow() { return CC() & VF; }
|
||||||
int carry() { return CC() & CF; }
|
int carry() { return CC() & CF; }
|
||||||
|
int halfCarry() { return CC() & HF; }
|
||||||
|
|
||||||
bool BLS() { return carry() | (zero() >> 2); } // (C OR Z)
|
bool BLS() { return carry() | (zero() >> 2); } // (C OR Z)
|
||||||
bool BHI() { return !BLS(); } // !(C OR Z)
|
bool BHI() { return !BLS(); } // !(C OR Z)
|
||||||
|
@ -31,7 +31,7 @@ int EightBit::mc6809::step() {
|
|||||||
void EightBit::mc6809::reset() {
|
void EightBit::mc6809::reset() {
|
||||||
Processor::reset();
|
Processor::reset();
|
||||||
DP() = 0; // Reestablish zero page
|
DP() = 0; // Reestablish zero page
|
||||||
CC() |= (IF & FF); // Disable IRQ and FIRQ
|
setFlag(CC(), IF | FF); // Disable IRQ and FIRQ
|
||||||
jump(getWordPaged(0xff, RESETvector));
|
jump(getWordPaged(0xff, RESETvector));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,17 +46,17 @@ void EightBit::mc6809::handleIRQ() {
|
|||||||
raise(IRQ());
|
raise(IRQ());
|
||||||
addCycles(21);
|
addCycles(21);
|
||||||
saveEntireRegisterState();
|
saveEntireRegisterState();
|
||||||
CC() |= IF; // Disable IRQ
|
setFlag(CC(), IF); // Disable IRQ
|
||||||
jump(getWordPaged(0xff, IRQvector));
|
jump(getWordPaged(0xff, IRQvector));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EightBit::mc6809::handleFIRQ() {
|
void EightBit::mc6809::handleFIRQ() {
|
||||||
addCycles(12);
|
addCycles(12);
|
||||||
raise(FIRQ());
|
raise(FIRQ());
|
||||||
CC() &= ~EF; // Clear the EF flag. i.e. this only saves PC and CC
|
clearFlag(CC(), EF); // Clear the EF flag. i.e. this only saves PC and CC
|
||||||
pushWordS(PC());
|
pushWordS(PC());
|
||||||
pushS(CC());
|
pushS(CC());
|
||||||
CC() |= (IF & FF); // Disable IRQ and FIRQ
|
setFlag(CC(), IF | FF); // Disable IRQ and FIRQ
|
||||||
jump(getWordPaged(0xff, FIRQvector));
|
jump(getWordPaged(0xff, FIRQvector));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -707,7 +707,7 @@ EightBit::register16_t EightBit::mc6809::AM_extended_word() {
|
|||||||
//
|
//
|
||||||
|
|
||||||
void EightBit::mc6809::saveEntireRegisterState() {
|
void EightBit::mc6809::saveEntireRegisterState() {
|
||||||
CC() |= EF;
|
setFlag(CC(), EF); // Entire flag set saved
|
||||||
pushWordS(PC());
|
pushWordS(PC());
|
||||||
pushWordS(U());
|
pushWordS(U());
|
||||||
pushWordS(Y());
|
pushWordS(Y());
|
||||||
@ -721,7 +721,7 @@ void EightBit::mc6809::saveEntireRegisterState() {
|
|||||||
//
|
//
|
||||||
|
|
||||||
uint8_t EightBit::mc6809::adc(uint8_t operand, uint8_t data) {
|
uint8_t EightBit::mc6809::adc(uint8_t operand, uint8_t data) {
|
||||||
return add(operand, data, CC() & CF);
|
return add(operand, data, carry());
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t EightBit::mc6809::add(uint8_t operand, uint8_t data, int carry) {
|
uint8_t EightBit::mc6809::add(uint8_t operand, uint8_t data, int carry) {
|
||||||
@ -745,7 +745,7 @@ uint8_t EightBit::mc6809::andr(uint8_t operand, uint8_t data) {
|
|||||||
uint8_t EightBit::mc6809::asl(uint8_t operand) {
|
uint8_t EightBit::mc6809::asl(uint8_t operand) {
|
||||||
setFlag(CC(), CF, operand & Bit7);
|
setFlag(CC(), CF, operand & Bit7);
|
||||||
adjustNZ(operand <<= 1);
|
adjustNZ(operand <<= 1);
|
||||||
const auto overflow = (CC() & CF) ^ ((CC() & NF) >> 3);
|
const auto overflow = (carry() ^ (negative() >> 3);
|
||||||
setFlag(CC(), VF, overflow);
|
setFlag(CC(), VF, overflow);
|
||||||
return operand;
|
return operand;
|
||||||
}
|
}
|
||||||
@ -789,8 +789,8 @@ uint8_t EightBit::mc6809::da(uint8_t operand) {
|
|||||||
clearFlag(CC(), VF);
|
clearFlag(CC(), VF);
|
||||||
setFlag(CC(), CF, A() > 0x99);
|
setFlag(CC(), CF, A() > 0x99);
|
||||||
|
|
||||||
const auto lowAdjust = (CC() & HF) || (lowNibble(A()) > 9);
|
const auto lowAdjust = halfCarry() || (lowNibble(A()) > 9);
|
||||||
const auto highAdjust = (CC() & CF) || (A() > 0x99);
|
const auto highAdjust = carry() || (A() > 0x99);
|
||||||
|
|
||||||
if (lowAdjust)
|
if (lowAdjust)
|
||||||
A() += 6;
|
A() += 6;
|
||||||
@ -1049,20 +1049,20 @@ void EightBit::mc6809::pulu(uint8_t data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint8_t EightBit::mc6809::rol(uint8_t operand) {
|
uint8_t EightBit::mc6809::rol(uint8_t operand) {
|
||||||
const auto carry = CC() & CF;
|
const auto carryIn = carry();
|
||||||
setFlag(CC(), CF, operand & Bit7);
|
setFlag(CC(), CF, operand & Bit7);
|
||||||
setFlag(CC(), VF, ((operand & Bit7) >> 7) ^ ((operand & Bit6) >> 6));
|
setFlag(CC(), VF, ((operand & Bit7) >> 7) ^ ((operand & Bit6) >> 6));
|
||||||
operand <<= 1;
|
operand <<= 1;
|
||||||
operand |= carry;
|
operand |= carryIn;
|
||||||
adjustNZ(operand);
|
adjustNZ(operand);
|
||||||
return operand;
|
return operand;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t EightBit::mc6809::ror(uint8_t operand) {
|
uint8_t EightBit::mc6809::ror(uint8_t operand) {
|
||||||
const auto carry = CC() & CF;
|
const auto carryIn = carry();
|
||||||
setFlag(CC(), CF, operand & Bit0);
|
setFlag(CC(), CF, operand & Bit0);
|
||||||
operand >>= 1;
|
operand >>= 1;
|
||||||
operand |= (carry << 7);
|
operand |= (carryIn << 7);
|
||||||
adjustNZ(operand);
|
adjustNZ(operand);
|
||||||
return operand;
|
return operand;
|
||||||
}
|
}
|
||||||
@ -1134,7 +1134,7 @@ EightBit::register16_t EightBit::mc6809::st(register16_t data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint8_t EightBit::mc6809::sbc(uint8_t operand, uint8_t data) {
|
uint8_t EightBit::mc6809::sbc(uint8_t operand, uint8_t data) {
|
||||||
return sub(operand, data, CC() & CF);
|
return sub(operand, data, carry());
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t EightBit::mc6809::sub(uint8_t operand, uint8_t data, int carry) {
|
uint8_t EightBit::mc6809::sub(uint8_t operand, uint8_t data, int carry) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user