From 26ea447f24200c2ba4159819d1c6a9ce7992770b Mon Sep 17 00:00:00 2001
From: Anonymus Raccoon
Date: Wed, 8 Apr 2020 17:13:00 +0200
Subject: [PATCH] Implementing the XBA
---
sources/CPU/CPU.hpp | 4 +++-
.../Instructions/MathematicalOperations.cpp | 10 ++++++++++
tests/CPU/Math/testOthersMath.cpp | 20 +++++++++++++++++++
3 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/sources/CPU/CPU.hpp b/sources/CPU/CPU.hpp
index 1b0cd41..2d72b91 100644
--- a/sources/CPU/CPU.hpp
+++ b/sources/CPU/CPU.hpp
@@ -417,6 +417,8 @@ namespace ComSquare::CPU
int TYX(uint24_t, AddressingMode);
//! @brief Test and Set Memory Bits Against Accumulator
int TSB(uint24_t, AddressingMode);
+ //! @brief Exchange the B and A Accumulators
+ int XBA(uint24_t, AddressingMode);
//! @brief All the instructions of the CPU.
//! @info Instructions are indexed by their opcode
@@ -656,7 +658,7 @@ namespace ComSquare::CPU
{&CPU::INX, 2, "inx", AddressingMode::Implied, 1}, // E8
{&CPU::SBC, 2, "sbc", AddressingMode::ImmediateForA, 2}, // E9
{&CPU::NOP, 2, "nop", AddressingMode::Implied, 1}, // EA
- {&CPU::BRK, 7, "xba #-#", AddressingMode::Implied, 2}, // EB
+ {&CPU::XBA, 3, "xba", AddressingMode::Implied, 1}, // EB
{&CPU::CPX, 4, "cpx", AddressingMode::Absolute, 3}, // EC
{&CPU::SBC, 4, "sbc", AddressingMode::Absolute, 3}, // ED
{&CPU::INC, 6, "inc", AddressingMode::Absolute, 3}, // EE
diff --git a/sources/CPU/Instructions/MathematicalOperations.cpp b/sources/CPU/Instructions/MathematicalOperations.cpp
index f723978..7d95161 100644
--- a/sources/CPU/Instructions/MathematicalOperations.cpp
+++ b/sources/CPU/Instructions/MathematicalOperations.cpp
@@ -398,4 +398,14 @@ namespace ComSquare::CPU
}
return cycles;
}
+
+ int CPU::XBA(uint24_t, AddressingMode)
+ {
+ int tmp = this->_registers.ah;
+ this->_registers.ah = this->_registers.al;
+ this->_registers.al = tmp;
+ this->_registers.p.n = this->_registers.al & 0x80u;
+ this->_registers.p.z = this->_registers.al == 0;
+ return 0;
+ }
}
\ No newline at end of file
diff --git a/tests/CPU/Math/testOthersMath.cpp b/tests/CPU/Math/testOthersMath.cpp
index 294f4f9..a8a6093 100644
--- a/tests/CPU/Math/testOthersMath.cpp
+++ b/tests/CPU/Math/testOthersMath.cpp
@@ -321,3 +321,23 @@ Test(EOR, zero)
cr_assert_eq(snes.cpu->_registers.p.n, false, "The negative flags should not be set.");
cr_assert_eq(snes.cpu->_registers.p.z, true, "The zero flags should be set.");
}
+
+Test(XBA, zero)
+{
+ Init()
+ snes.cpu->_registers.a = 0x0001;
+ snes.cpu->XBA(0x0, ComSquare::CPU::AddressingMode::Implied);
+ cr_assert_eq(snes.cpu->_registers.a, 0x0100, "The accumulator's value should be 0x0100 but it was 0x%x.", snes.cpu->_registers.a);
+ cr_assert_eq(snes.cpu->_registers.p.n, false, "The negative flags should not be set.");
+ cr_assert_eq(snes.cpu->_registers.p.z, true, "The zero flags should be set.");
+}
+
+Test(XBA, negative)
+{
+ Init()
+ snes.cpu->_registers.a = 0x8001;
+ snes.cpu->XBA(0x0, ComSquare::CPU::AddressingMode::Implied);
+ cr_assert_eq(snes.cpu->_registers.a, 0x0180, "The accumulator's value should be 0x0180 but it was 0x%x.", snes.cpu->_registers.a);
+ cr_assert_eq(snes.cpu->_registers.p.n, true, "The negative flags should be set.");
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flags should be not set.");
+}