From 072cb17bcbb9cdcf7700589654029f8ca81a9208 Mon Sep 17 00:00:00 2001
From: AnonymusRaccoon
Date: Thu, 13 Feb 2020 18:57:31 +0100
Subject: [PATCH] Finishing the SEP
---
sources/CPU/CPU.cpp | 2 ++
sources/CPU/CPU.hpp | 4 ++-
.../CPU/Instructions/InternalInstruction.cpp | 2 +-
tests/CPU/testInternal.cpp | 36 ++++++++++---------
4 files changed, 25 insertions(+), 19 deletions(-)
diff --git a/sources/CPU/CPU.cpp b/sources/CPU/CPU.cpp
index cffc368..d6e8e70 100644
--- a/sources/CPU/CPU.cpp
+++ b/sources/CPU/CPU.cpp
@@ -277,6 +277,8 @@ namespace ComSquare::CPU
case Instructions::LDY_ABSY: this->LDY(this->_getAbsoluteIndexedByYAddr()); return 4 + !this->_registers.p.m + this->_hasIndexCrossedPageBoundary;
case Instructions::LDY_DPY: this->LDY(this->_getDirectIndexedByYAddr()); return 4 + !this->_registers.p.m + this->_registers.dl != 0;
+ case Instructions::SEP: this->SEP(this->_getImmediateAddr()); return 3;
+
default:
throw InvalidOpcode("CPU", opcode);
}
diff --git a/sources/CPU/CPU.hpp b/sources/CPU/CPU.hpp
index de2ecaa..f416468 100644
--- a/sources/CPU/CPU.hpp
+++ b/sources/CPU/CPU.hpp
@@ -258,7 +258,9 @@ namespace ComSquare::CPU
LDY_ABS = 0xAC,
LDY_DP = 0xA4,
LDY_ABSY = 0xBC,
- LDY_DPY = 0xB4
+ LDY_DPY = 0xB4,
+
+ SEP = 0xE2
};
//! @brief The main CPU
diff --git a/sources/CPU/Instructions/InternalInstruction.cpp b/sources/CPU/Instructions/InternalInstruction.cpp
index ab20ed9..4fb7490 100644
--- a/sources/CPU/Instructions/InternalInstruction.cpp
+++ b/sources/CPU/Instructions/InternalInstruction.cpp
@@ -8,6 +8,6 @@ namespace ComSquare::CPU
{
void CPU::SEP(uint24_t addr)
{
-
+ this->_registers.p.flags |= this->_bus->read(addr);
}
}
\ No newline at end of file
diff --git a/tests/CPU/testInternal.cpp b/tests/CPU/testInternal.cpp
index f7473d6..998518d 100644
--- a/tests/CPU/testInternal.cpp
+++ b/tests/CPU/testInternal.cpp
@@ -9,20 +9,22 @@
#include "../../sources/SNES.hpp"
#include "../../sources/Memory/MemoryBus.hpp"
using namespace ComSquare;
-//
-//Test(SEP, setall)
-//{
-// auto pair = Init();
-// pair.second.wram->_data[0] = 0xFF;
-// pair.second.cpu->SEP(0x0);
-// auto data = pair.second.cpu->_registers.p.flags;
-// cr_assert_eq(data, 0xFF, "The flag should be 0xFF but it was %b", data);
-//}
-//
-//Test(SEP, setsome)
-//{
-// auto pair = Init();
-// pair.second.wram->_data[0] = 0b10110101;
-// pair.second.cpu->SEP(0x0);
-// cr_assert_eq(pair.second.cpu->_registers.p.flags, 0xFF);
-//}
\ No newline at end of file
+
+Test(SEP, setall)
+{
+ auto pair = Init();
+ pair.second.wram->_data[0] = 0xFF;
+ pair.second.cpu->SEP(0x0);
+ auto data = pair.second.cpu->_registers.p.flags;
+ cr_assert_eq(data, 0xFF, "The flag should be 0xFF but it was %x", data);
+}
+
+Test(SEP, setsome)
+{
+ auto pair = Init();
+ pair.second.wram->_data[0] = 0b10110101;
+ pair.second.cpu->_registers.p.flags = 0b01000000;
+ pair.second.cpu->SEP(0x0);
+ auto data = pair.second.cpu->_registers.p.flags;
+ cr_assert_eq(data, 0b11110101, "The flag should be 245 but it was %i", data);
+}
\ No newline at end of file