From bd681c49a1e3e7878690c9c6a105c034a6447e91 Mon Sep 17 00:00:00 2001
From: AnonymusRaccoon
Date: Mon, 10 Feb 2020 11:39:32 +0100
Subject: [PATCH] Reworking the test for the CPU
---
CMakeLists.txt | 12 ++++++---
sources/CPU/CPU.cpp | 25 -------------------
sources/CPU/Instructions/Interrupts.cpp | 21 ++++++++++++++++
.../Instructions/MathematicalOperations.cpp | 13 ++++++++++
tests/CPU/testAddressingMode.cpp | 18 +++++++++++++
tests/{ => CPU}/testCPU.cpp | 8 +++---
tests/communism.hpp | 12 ---------
tests/testMemoryBus.cpp | 16 +-----------
tests/tests.cpp | 24 ++++++++++++++++++
tests/tests.hpp | 15 +++++++++++
10 files changed, 103 insertions(+), 61 deletions(-)
create mode 100644 sources/CPU/Instructions/Interrupts.cpp
create mode 100644 sources/CPU/Instructions/MathematicalOperations.cpp
create mode 100644 tests/CPU/testAddressingMode.cpp
rename tests/{ => CPU}/testCPU.cpp (88%)
delete mode 100644 tests/communism.hpp
create mode 100644 tests/tests.cpp
create mode 100644 tests/tests.hpp
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b2788c3..74174d5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -9,9 +9,9 @@ add_compile_options(-W -Wall -Wextra -Wshadow)
# make unit tests
add_executable(unit_tests
- tests/testCPU.cpp
+ tests/CPU/testCPU.cpp
tests/testMemoryBus.cpp
- tests/communism.hpp
+ tests/tests.hpp
sources/SNES.cpp
sources/SNES.hpp
sources/Memory/MemoryBus.cpp
@@ -49,7 +49,10 @@ add_executable(unit_tests
sources/CPU/Instructions/CommonInstructions.cpp
sources/CPU/Instructions/CommonInstructions.hpp
sources/Exceptions/InvalidOpcode.hpp
- )
+ sources/CPU/Instructions/Interrupts.cpp
+ sources/CPU/Instructions/MathematicalOperations.cpp
+ tests/CPU/testAddressingMode.cpp
+ tests/tests.cpp)
# include criterion & coverage
target_link_libraries(unit_tests criterion -lgcov)
@@ -101,7 +104,8 @@ add_executable(ComSquare
sources/CPU/Instructions/CommonInstructions.cpp
sources/CPU/Instructions/CommonInstructions.hpp
sources/Exceptions/InvalidOpcode.hpp
- )
+ sources/CPU/Instructions/Interrupts.cpp
+ sources/CPU/Instructions/MathematicalOperations.cpp)
target_link_libraries(ComSquare
sfml-graphics
diff --git a/sources/CPU/CPU.cpp b/sources/CPU/CPU.cpp
index afcf96d..69420cc 100644
--- a/sources/CPU/CPU.cpp
+++ b/sources/CPU/CPU.cpp
@@ -248,29 +248,4 @@ namespace ComSquare::CPU
{
return 0;
}
-
-
-
- int CPU::BRK()
- {
- this->_registers.pc += 2;
-
- this->_registers.p.i = true;
- if (this->_isEmulationMode)
- this->_registers.pc = this->_cartridgeHeader.emulationInterrupts.brk;
- else
- this->_registers.pc = this->_cartridgeHeader.nativeInterrupts.brk;
- this->_registers.p.d = false;
- return 7 + !this->_isEmulationMode;
- }
-
-
- ////////////////////////////////////////////////////////////////////
- /// Mathematical operations
- ////////////////////////////////////////////////////////////////////
-
- int CPU::ADC()
- {
-// this->_registers.a +=
- }
}
\ No newline at end of file
diff --git a/sources/CPU/Instructions/Interrupts.cpp b/sources/CPU/Instructions/Interrupts.cpp
new file mode 100644
index 0000000..e07534a
--- /dev/null
+++ b/sources/CPU/Instructions/Interrupts.cpp
@@ -0,0 +1,21 @@
+//
+// Created by anonymus-raccoon on 2/10/20.
+//
+
+#include "../CPU.hpp"
+
+namespace ComSquare::CPU
+{
+ int CPU::BRK()
+ {
+ this->_registers.pc += 2;
+
+ this->_registers.p.i = true;
+ if (this->_isEmulationMode)
+ this->_registers.pc = this->_cartridgeHeader.emulationInterrupts.brk;
+ else
+ this->_registers.pc = this->_cartridgeHeader.nativeInterrupts.brk;
+ this->_registers.p.d = false;
+ return 7 + !this->_isEmulationMode;
+ }
+}
\ No newline at end of file
diff --git a/sources/CPU/Instructions/MathematicalOperations.cpp b/sources/CPU/Instructions/MathematicalOperations.cpp
new file mode 100644
index 0000000..fb53ff2
--- /dev/null
+++ b/sources/CPU/Instructions/MathematicalOperations.cpp
@@ -0,0 +1,13 @@
+//
+// Created by anonymus-raccoon on 2/10/20.
+//
+
+#include "../CPU.hpp"
+
+namespace ComSquare::CPU
+{
+ int CPU::ADC()
+ {
+// this->_registers.a +=
+ }
+}
\ No newline at end of file
diff --git a/tests/CPU/testAddressingMode.cpp b/tests/CPU/testAddressingMode.cpp
new file mode 100644
index 0000000..696b0af
--- /dev/null
+++ b/tests/CPU/testAddressingMode.cpp
@@ -0,0 +1,18 @@
+//
+// Created by anonymus-raccoon on 2/10/20.
+//
+
+#include
+#include
+#include "../tests.hpp"
+#include "../../sources/SNES.hpp"
+using namespace ComSquare;
+
+
+Test(AddrMode, Immediate)
+{
+ auto pair = Init();
+ pair.second.cpu->_registers.pc = 0x15;
+ cr_assert_eq(pair.second.cpu->_GetImmediateAddr(), 0x15);
+ cr_assert_eq(pair.second.cpu->_registers.pc, 0x16);
+}
\ No newline at end of file
diff --git a/tests/testCPU.cpp b/tests/CPU/testCPU.cpp
similarity index 88%
rename from tests/testCPU.cpp
rename to tests/CPU/testCPU.cpp
index 92ab3fe..5191176 100644
--- a/tests/testCPU.cpp
+++ b/tests/CPU/testCPU.cpp
@@ -5,13 +5,11 @@
#include
#include
#include
-#include "communism.hpp"
-#include "../sources/SNES.hpp"
-#include "../sources/Memory/MemoryBus.hpp"
+#include "../tests.hpp"
+#include "../../sources/SNES.hpp"
+#include "../../sources/Memory/MemoryBus.hpp"
using namespace ComSquare;
-std::pair Init();
-
Test(CPU_emulated, BRK)
{
auto pair = Init();
diff --git a/tests/communism.hpp b/tests/communism.hpp
deleted file mode 100644
index f6fd1ea..0000000
--- a/tests/communism.hpp
+++ /dev/null
@@ -1,12 +0,0 @@
-//
-// Created by Melefp on 05/02/2020.
-//
-
-#ifndef COMSQUARE_COMMUNISM_HPP
-#define COMSQUARE_COMMUNISM_HPP
-
-#define private public
-#define protected public
-#define class struct
-
-#endif //COMSQUARE_COMMUNISM_HPP
diff --git a/tests/testMemoryBus.cpp b/tests/testMemoryBus.cpp
index 55379dd..80b368f 100644
--- a/tests/testMemoryBus.cpp
+++ b/tests/testMemoryBus.cpp
@@ -5,7 +5,7 @@
#include
#include
#include
-#include "communism.hpp"
+#include "tests.hpp"
#include "../sources/Memory/MemoryBus.hpp"
#include "../sources/Memory/IMemory.hpp"
#include "../sources/SNES.hpp"
@@ -17,20 +17,6 @@
using namespace ComSquare;
-std::pair Init()
-{
- Memory::MemoryBus bus;
- Renderer::NoRenderer norenderer(0, 0, 0);
- SNES snes(std::make_shared(bus), "", norenderer);
- snes.cartridge->_size = 10;
- snes.cartridge->_data = new uint8_t[snes.cartridge->_size];
- snes.cartridge->header.mappingMode = Cartridge::LoRom;
- snes.sram->_size = 10;
- snes.sram->_data = new uint8_t[snes.cartridge->_size];
- bus.mapComponents(snes);
- return std::make_pair(bus, snes);
-}
-
//////////////////////////////////
// //
// MemoryBus::getAccessor tests //
diff --git a/tests/tests.cpp b/tests/tests.cpp
new file mode 100644
index 0000000..395f61d
--- /dev/null
+++ b/tests/tests.cpp
@@ -0,0 +1,24 @@
+//
+// Created by anonymus-raccoon on 2/10/20.
+//
+
+#include
+#include "tests.hpp"
+#include "../sources/Renderer/NoRenderer.hpp"
+#include "../sources/SNES.hpp"
+
+using namespace ComSquare;
+
+std::pair Init()
+{
+ Memory::MemoryBus bus;
+ Renderer::NoRenderer norenderer(0, 0, 0);
+ SNES snes(std::make_shared(bus), "", norenderer);
+ snes.cartridge->_size = 10;
+ snes.cartridge->_data = new uint8_t[snes.cartridge->_size];
+ snes.cartridge->header.mappingMode = Cartridge::LoRom;
+ snes.sram->_size = 10;
+ snes.sram->_data = new uint8_t[snes.cartridge->_size];
+ bus.mapComponents(snes);
+ return std::make_pair(bus, snes);
+}
\ No newline at end of file
diff --git a/tests/tests.hpp b/tests/tests.hpp
new file mode 100644
index 0000000..7aa7359
--- /dev/null
+++ b/tests/tests.hpp
@@ -0,0 +1,15 @@
+//
+// Created by Melefo on 05/02/2020.
+//
+
+#ifndef COMSQUARE_TESTS_HPP
+#define COMSQUARE_TESTS_HPP
+
+#define private public
+#define protected public
+#define class struct
+
+#include "../sources/Memory/MemoryBus.hpp"
+std::pair Init();
+
+#endif //COMSQUARE_TESTS_HPP