From cf32f37fc36b2dabbccf48d70c62ff2c71a43d66 Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Sun, 7 Oct 2018 10:48:27 +0100 Subject: [PATCH] Add test for ASRA inherent. And fix resulting bugs exposed! Signed-off-by: Adrian Conlon --- MC6809/src/mc6809.cpp | 6 ++++-- MC6809/unittest/mc6809_tests.cpp | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/MC6809/src/mc6809.cpp b/MC6809/src/mc6809.cpp index afd6c2c..421c01c 100644 --- a/MC6809/src/mc6809.cpp +++ b/MC6809/src/mc6809.cpp @@ -783,8 +783,10 @@ uint8_t EightBit::mc6809::asl(uint8_t operand) { } uint8_t EightBit::mc6809::asr(uint8_t operand) { - setFlag(CC(), CF, operand & Bit7); - adjustNZ(operand >>= 1); + setFlag(CC(), CF, operand & Bit0); + operand >>= 1; + operand |= Bit7; + adjustNZ(operand); return operand; } diff --git a/MC6809/unittest/mc6809_tests.cpp b/MC6809/unittest/mc6809_tests.cpp index 7a4c621..1567507 100644 --- a/MC6809/unittest/mc6809_tests.cpp +++ b/MC6809/unittest/mc6809_tests.cpp @@ -104,3 +104,22 @@ TEST_CASE("Shift Accumulator or Memory Byte Left", "[ASL][ASLA]") { REQUIRE(cpu.cycles() == 2); } } + +TEST_CASE("Shift Accumulator or Memory Byte Right", "[ASR][ASRA]") { + + Board board; + board.initialise(); + auto& cpu = board.CPU(); + cpu.step(); // Step over the reset + + SECTION("Inherent") { + board.poke(0, 0x47); + cpu.A() = 0xcb; + cpu.step(); + REQUIRE(cpu.A() == 0xe5); + REQUIRE((cpu.CC() & EightBit::mc6809::CF) != 0); + REQUIRE((cpu.CC() & EightBit::mc6809::ZF) == 0); + REQUIRE((cpu.CC() & EightBit::mc6809::NF) != 0); + REQUIRE(cpu.cycles() == 2); + } +}