Add a test for ADCA immediate. Half carry and overflow flags incorrect!

Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon 2018-10-07 09:14:30 +01:00
parent 7e57efd4cd
commit 5dc185866e
2 changed files with 33 additions and 3 deletions

View File

@ -206,21 +206,27 @@ namespace EightBit {
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);
setFlag(CC(), VF, !!((before ^ data ^ after ^ (after >> 1)) & Bit7));
}
void adjustOverflow(uint16_t before, uint16_t data, uint16_t after) {
setFlag(CC(), VF, (before ^ data) & (before ^ after) & Bit15);
setFlag(CC(), VF, !!((before ^ data ^ after ^ (after >> 1)) & Bit15));
}
void adjustOverflow(register16_t before, register16_t data, register16_t after) {
adjustOverflow(before.word, data.word, after.word);
}
void adjustHalfCarry(uint8_t before, uint8_t data, uint8_t after) {
setFlag(CC(), HF, !!((before ^ data ^ after) & Bit4));
}
void adjustAddition(uint8_t before, uint8_t data, register16_t after) {
const auto result = after.low;
adjustNZ(result);
adjustCarry(after);
adjustOverflow(before, data, result);
adjustHalfCarry(before, data, result);
}
void adjustAddition(uint16_t before, uint16_t data, uint32_t after) {

View File

@ -4,7 +4,7 @@
// Using examples from 6809 Assembly Language Programming, by Lance A. Leventhal
// Just test the basics...
TEST_CASE("Add Accumulator B to Index Register X Unsigned ", "[ABX]") {
TEST_CASE("Add Accumulator B to Index Register X Unsigned", "[ABX]") {
Board board;
board.initialise();
@ -17,5 +17,29 @@ TEST_CASE("Add Accumulator B to Index Register X Unsigned ", "[ABX]") {
cpu.X() = 0x1097;
cpu.step();
REQUIRE(cpu.X() == 0x111b);
REQUIRE(cpu.cycles() == 3);
}
}
TEST_CASE("Add Memory Plus Carry to Accumulator A", "[ADC][ADCA]") {
Board board;
board.initialise();
auto& cpu = board.CPU();
cpu.step(); // Step over the reset
SECTION("Immediate (byte)") {
board.poke(0, 0x89);
board.poke(1, 0x7c);
EightBit::Chip::setFlag(cpu.CC(), EightBit::mc6809::CF);
cpu.A() = 0x3a;
cpu.step();
REQUIRE(cpu.A() == 0xb7);
REQUIRE((cpu.CC() & EightBit::mc6809::ZF) == 0);
REQUIRE((cpu.CC() & EightBit::mc6809::HF) != 0);
REQUIRE((cpu.CC() & EightBit::mc6809::VF) != 0);
REQUIRE((cpu.CC() & EightBit::mc6809::NF) != 0);
REQUIRE((cpu.CC() & EightBit::mc6809::CF) == 0);
REQUIRE(cpu.cycles() == 2);
}
}