EightBit/MC6809/unittest/mc6809_tests.cpp
Adrian Conlon 1f4a84b803 Add test for ADDA immediate. Seems to be working.
Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
2018-10-07 09:47:10 +01:00

69 lines
1.8 KiB
C++

#include "pch.h"
#include "Board.h"
// 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]") {
Board board;
board.initialise();
auto& cpu = board.CPU();
cpu.step(); // Step over the reset
SECTION("Inherent") {
board.poke(0, 0x3a);
cpu.B() = 0x84;
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);
}
}
TEST_CASE("Add Memory to Accumulator A", "[ADD][ADDA]") {
Board board;
board.initialise();
auto& cpu = board.CPU();
cpu.step(); // Step over the reset
SECTION("Immediate (byte)") {
board.poke(0, 0x8b);
board.poke(1, 0x8b);
EightBit::Chip::setFlag(cpu.CC(), EightBit::mc6809::CF);
cpu.A() = 0x24;
cpu.step();
REQUIRE(cpu.A() == 0xaf);
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);
}
}