mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2025-01-11 02:29:50 +00:00
Add LEA instruction to the 6809 processor
Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
parent
a917fb0d4c
commit
05ca4166c7
@ -127,8 +127,10 @@ namespace EightBit {
|
||||
// Flag adjustment
|
||||
|
||||
template<class T> void adjustZero(T datum) { clearFlag(CC(), ZF, datum); }
|
||||
void adjustZero(register16_t datum) { clearFlag(CC(), ZF, datum.word); }
|
||||
void adjustNegative(uint8_t datum) { setFlag(CC(), NF, datum & Bit7); }
|
||||
void adjustNegative(uint16_t datum) { setFlag(CC(), NF, datum & Bit15); }
|
||||
void adjustNegative(register16_t datum) { adjustNegative(datum.word); }
|
||||
|
||||
template<class T> void adjustNZ(T datum) {
|
||||
adjustZero(datum);
|
||||
@ -137,9 +139,11 @@ namespace EightBit {
|
||||
|
||||
void adjustCarry(uint16_t datum) { setFlag(CC(), CF, datum & Bit8); } // 8-bit addition
|
||||
void adjustCarry(uint32_t datum) { setFlag(CC(), CF, datum & Bit16); } // 16-bit addition
|
||||
void adjustCarry(register16_t datum) { adjustCarry(datum.word); }
|
||||
|
||||
void adjustBorrow(uint16_t datum) { clearFlag(CC(), CF, datum & Bit8); } // 8-bit subtraction
|
||||
void adjustBorrow(uint32_t datum) { clearFlag(CC(), CF, datum & Bit16); } // 16-bit subtraction
|
||||
void adjustBorrow(register16_t datum) { adjustBorrow(datum.word); }
|
||||
|
||||
void adjustOverflow(uint8_t before, uint8_t data, uint8_t after) {
|
||||
setFlag(CC(), VF, (before ^ data) & (before ^ after) & Bit7);
|
||||
@ -148,33 +152,44 @@ namespace EightBit {
|
||||
void adjustOverflow(uint16_t before, uint16_t data, uint16_t after) {
|
||||
setFlag(CC(), VF, (before ^ data) & (before ^ after) & Bit15);
|
||||
}
|
||||
void adjustOverflow(register16_t before, register16_t data, register16_t after) {
|
||||
adjustOverflow(before.word, data.word, after.word);
|
||||
}
|
||||
|
||||
void adjustAddition(uint8_t before, uint8_t data, register16_t after) {
|
||||
const auto result = after.low;
|
||||
adjustNZ(result);
|
||||
adjustCarry(after.word);
|
||||
adjustCarry(after);
|
||||
adjustOverflow(before, data, result);
|
||||
}
|
||||
|
||||
void adjustAddition(uint16_t before, uint16_t data, uint32_t after) {
|
||||
const register16_t result = after & Mask16;
|
||||
adjustNZ(result.word);
|
||||
adjustNZ(result);
|
||||
adjustCarry(after);
|
||||
adjustOverflow(before, data, result.word);
|
||||
adjustOverflow(before, data, result);
|
||||
}
|
||||
|
||||
void adjustAddition(register16_t before, register16_t data, uint32_t after) {
|
||||
adjustAddition(before.word, data.word, after);
|
||||
}
|
||||
|
||||
void adjustSubtraction(uint8_t before, uint8_t data, register16_t after) {
|
||||
const auto result = after.low;
|
||||
adjustNZ(result);
|
||||
adjustBorrow(after.word);
|
||||
adjustBorrow(after);
|
||||
adjustOverflow(before, data, result);
|
||||
}
|
||||
|
||||
void adjustSubtraction(uint16_t before, uint16_t data, uint32_t after) {
|
||||
const register16_t result = after & Mask16;
|
||||
adjustNZ(result.word);
|
||||
adjustNZ(result);
|
||||
adjustBorrow(after);
|
||||
adjustOverflow(before, data, result.word);
|
||||
adjustOverflow(before, data, result);
|
||||
}
|
||||
|
||||
void adjustSubtraction(register16_t before, register16_t data, uint32_t after) {
|
||||
adjustSubtraction(before.word, data.word, after);
|
||||
}
|
||||
|
||||
// Instruction implementations
|
||||
|
@ -236,6 +236,12 @@ int EightBit::mc6809::executeUnprefixed(uint8_t opcode) {
|
||||
case 0xae: addCycles(5); X() = ld(AM_indexed_word()); break; // LD (LDX indexed)
|
||||
case 0xbe: addCycles(6); X() = ld(AM_extended_word()); break; // LD (LDX extended)
|
||||
|
||||
// LEA
|
||||
case 0x30: addCycles(4); adjustZero(X() = Address_indexed()); break; // LEA (LEAX indexed)
|
||||
case 0x31: addCycles(4); adjustZero(Y() = Address_indexed()); break; // LEA (LEAY indexed)
|
||||
case 0x32: addCycles(4); S() = Address_indexed(); break; // LEA (LEAS indexed)
|
||||
case 0x33: addCycles(4); U() = Address_indexed(); break; // LEA (LEAU indexed)
|
||||
|
||||
default:
|
||||
UNREACHABLE;
|
||||
}
|
||||
@ -475,7 +481,7 @@ uint8_t EightBit::mc6809::neg(uint8_t operand) {
|
||||
const register16_t result = 0 - operand;
|
||||
operand = result.low;
|
||||
adjustNZ(operand);
|
||||
adjustCarry(result.word);
|
||||
adjustCarry(result);
|
||||
return operand;
|
||||
}
|
||||
|
||||
@ -491,7 +497,7 @@ uint8_t EightBit::mc6809::add(uint8_t operand, uint8_t data, int carry) {
|
||||
|
||||
EightBit::register16_t EightBit::mc6809::add(register16_t operand, register16_t data) {
|
||||
const uint32_t addition = operand.word + data.word;
|
||||
adjustAddition(operand.word, data.word, addition);
|
||||
adjustAddition(operand, data, addition);
|
||||
return addition & Mask16;
|
||||
}
|
||||
|
||||
@ -531,7 +537,7 @@ void EightBit::mc6809::cmp(const uint8_t operand, const uint8_t data) {
|
||||
|
||||
void EightBit::mc6809::cmp(register16_t operand, register16_t data) {
|
||||
const uint32_t difference = operand.word - data.word;
|
||||
adjustSubtraction(operand.word, data.word, difference);
|
||||
adjustSubtraction(operand, data, difference);
|
||||
}
|
||||
|
||||
uint8_t EightBit::mc6809::com(uint8_t operand) {
|
||||
@ -648,6 +654,6 @@ uint8_t EightBit::mc6809::ld(uint8_t data) {
|
||||
|
||||
EightBit::register16_t EightBit::mc6809::ld(register16_t data) {
|
||||
clearFlag(CC(), VF);
|
||||
adjustNZ(data.word);
|
||||
adjustNZ(data);
|
||||
return data;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user