From b9ff47584e40a6c813c712734680b2e67d7c11e9 Mon Sep 17 00:00:00 2001
From: Anonymus Raccoon
Date: Wed, 8 Apr 2020 11:39:43 +0200
Subject: [PATCH] Finishing the TSB
---
sources/CPU/Instructions/BitsInstructions.cpp | 7 +++++-
tests/CPU/testBits.cpp | 25 ++++++++++++++++++-
2 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/sources/CPU/Instructions/BitsInstructions.cpp b/sources/CPU/Instructions/BitsInstructions.cpp
index 95b91eb..737bdc9 100644
--- a/sources/CPU/Instructions/BitsInstructions.cpp
+++ b/sources/CPU/Instructions/BitsInstructions.cpp
@@ -2,6 +2,7 @@
// Created by anonymus-raccoon on 2/20/20.
//
+#include
#include "../../Models/Int24.hpp"
#include "../CPU.hpp"
@@ -9,9 +10,13 @@ namespace ComSquare::CPU
{
int CPU::TSB(uint24_t valueAddr, AddressingMode mode)
{
- uint8_t value = this->_bus->read(valueAddr);
+ uint16_t value = this->_bus->read(valueAddr);
+ if (!this->_registers.p.m)
+ value += this->_bus->read(valueAddr + 1) << 8u;
value |= this->_registers.a;
this->_bus->write(valueAddr, value);
+ if (!this->_registers.p.m)
+ this->_bus->write(valueAddr + 1, value >> 8u);
this->_registers.p.z = value == 0;
diff --git a/tests/CPU/testBits.cpp b/tests/CPU/testBits.cpp
index a06c7af..5c4b334 100644
--- a/tests/CPU/testBits.cpp
+++ b/tests/CPU/testBits.cpp
@@ -35,7 +35,6 @@ Test(AND, nativeNegative)
cr_assert_eq(snes.cpu->_registers.p.n, true, "The negative flag should be set.");
}
-
Test(AND, emulationTest)
{
Init()
@@ -48,3 +47,27 @@ Test(AND, emulationTest)
cr_assert_eq(snes.cpu->_registers.p.n, false, "The negative flag should not be set.");
}
+Test(TSB, emulationTest)
+{
+ Init()
+ snes.wram->_data[0] = 0b00110011;
+ snes.cpu->_registers.a = 0b00110111;
+ snes.cpu->_registers.p.m = true;
+ snes.cpu->TSB(0x0, ComSquare::CPU::AddressingMode::Implied);
+ cr_assert_eq(snes.wram->_data[0], 0b00110111, "The data in ram should be 0b00110111 but it was %x", snes.wram->_data[0]);
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flag should not be set.");
+}
+
+Test(TSB, nativeTest)
+{
+ Init()
+ snes.wram->_data[0] = 0xF0;
+ snes.wram->_data[1] = 0x0F;
+ snes.cpu->_registers.a = 0x8008;
+ snes.cpu->_registers.p.m = false;
+ snes.cpu->TSB(0x0, ComSquare::CPU::AddressingMode::Implied);
+ cr_assert_eq(snes.wram->_data[0], 0xF8, "The first data in ram should be 0xF8 but it was %x", snes.wram->_data[0]);
+ cr_assert_eq(snes.wram->_data[1], 0x8F, "The second data in ram should be 0x8F but it was %x", snes.wram->_data[1]);
+ cr_assert_eq(snes.cpu->_registers.p.z, false, "The zero flag should not be set.");
+}
+