Add DAA to the 6809 processor.

Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon 2018-08-21 12:25:58 +01:00
parent 0882513762
commit 00ca20dbe4
2 changed files with 21 additions and 1 deletions

View File

@ -185,6 +185,7 @@ namespace EightBit {
void cmp(register16_t operand, register16_t data);
uint8_t com(uint8_t operand);
void cwai(uint8_t data);
uint8_t da(uint8_t operand);
uint8_t neg(uint8_t operand);
register16_t m_d;

View File

@ -158,6 +158,9 @@ int EightBit::mc6809::executeUnprefixed(uint8_t opcode) {
// CWAI
case 0x3c: addCycles(20); cwai(AM_direct_byte()); break; // CWAI (CWAI direct)
// DAA
case 0x19: addCycles(2); A() = da(A()); break; // DAA (DAA implied)
default:
UNREACHABLE;
}
@ -464,4 +467,20 @@ void EightBit::mc6809::cwai(uint8_t data) {
push(A());
push(CC());
halt();
}
}
uint8_t EightBit::mc6809::da(uint8_t operand) {
clearFlag(CC(), VF);
setFlag(CC(), CF, A() > 0x99);
const auto lowAdjust = (CC() & HF) || (lowNibble(A()) > 9);
const auto highAdjust = (CC() & CF) || (A() > 0x99);
if (lowAdjust)
A() += 6;
if (highAdjust)
A() += 0x60;
adjustNZ(A());
}