From b36fb69804ecfd5b5d53453be95169e3936954ce Mon Sep 17 00:00:00 2001
From: AnonymusRaccoon
Date: Fri, 24 Jan 2020 17:32:19 +0100
Subject: [PATCH] Finishing the registers for the CPU
---
CMakeLists.txt | 13 +++++-
main.cpp | 6 ++-
sources/CPU/Cpu.cpp | 5 +++
sources/CPU/Cpu.hpp | 100 ++++++++++++++++++++++++++++++++++++++++++++
sources/hello.cpp | 7 ----
tests/hello.cpp | 10 -----
tests/testCPU.cpp | 4 ++
7 files changed, 124 insertions(+), 21 deletions(-)
create mode 100644 sources/CPU/Cpu.cpp
create mode 100644 sources/CPU/Cpu.hpp
delete mode 100644 sources/hello.cpp
delete mode 100644 tests/hello.cpp
create mode 100644 tests/testCPU.cpp
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 73d2f2f..8a988dd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,11 +8,20 @@ project(ComSquare)
add_compile_options(-W -Wall -Wextra -Wshadow)
# make unit tests
-add_executable(unit_tests sources/hello.cpp tests/hello.cpp)
+add_executable(unit_tests
+ tests/testCPU.cpp
+)
# include criterion & coverage
target_link_libraries(unit_tests criterion -lgcov)
target_compile_options(unit_tests PUBLIC -fprofile-arcs -ftest-coverage)
# make app
-add_executable(ComSquare main.cpp sources/hello.cpp sources/Memory/MemoryBus.cpp sources/Memory/MemoryBus.hpp sources/Memory/IMemory.hpp sources/Memory/IMemory.cpp)
+add_executable(ComSquare
+ main.cpp
+ sources/Memory/MemoryBus.cpp
+ sources/Memory/MemoryBus.hpp
+ sources/Memory/IMemory.hpp
+ sources/Memory/IMemory.cpp
+ sources/CPU/Cpu.cpp
+ sources/CPU/Cpu.hpp)
diff --git a/main.cpp b/main.cpp
index b92cc19..cffe016 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,6 +1,8 @@
-int HelloWorld(void);
+//
+// Created by anonymus-raccoon on 1/24/20.
+//
int main(void)
{
- return HelloWorld();
+ return 0;
}
\ No newline at end of file
diff --git a/sources/CPU/Cpu.cpp b/sources/CPU/Cpu.cpp
new file mode 100644
index 0000000..680b728
--- /dev/null
+++ b/sources/CPU/Cpu.cpp
@@ -0,0 +1,5 @@
+//
+// Created by anonymus-raccoon on 1/24/20.
+//
+
+#include "Cpu.hpp"
diff --git a/sources/CPU/Cpu.hpp b/sources/CPU/Cpu.hpp
new file mode 100644
index 0000000..ebcf8d7
--- /dev/null
+++ b/sources/CPU/Cpu.hpp
@@ -0,0 +1,100 @@
+//
+// Created by anonymus-raccoon on 1/24/20.
+//
+
+#ifndef COMSQUARE_CPU_HPP
+#define COMSQUARE_CPU_HPP
+
+#include "../Memory/IMemory.hpp"
+
+namespace ComSquare::CPU
+{
+ //! @brief Struct containing registers for the main CPU.
+ struct Registers {
+ //! @brief The Accumulator
+ union {
+ struct {
+ unsigned char al;
+ unsigned char ah;
+ };
+ unsigned short a;
+ };
+ //! @brief The Data Bank Register;
+ unsigned char dbr;
+ //! @brief The Direct register;
+ union {
+ struct {
+ unsigned char dl;
+ unsigned char dh;
+ };
+ unsigned short d;
+ };
+ //! @brief The program banK register;
+ unsigned char k;
+ //! @brief The Program Counter;
+ union {
+ struct {
+ unsigned char pcl;
+ unsigned char pch;
+ };
+ unsigned short pc;
+ };
+ //! @brief The Stack pointer
+ union {
+ struct {
+ unsigned char sl;
+ unsigned char sh;
+ };
+ unsigned short s;
+ };
+ //! @brief The X index register
+ union {
+ struct {
+ unsigned char xl;
+ unsigned char xh;
+ };
+ unsigned short x;
+ };
+ //! @brief The Y index register
+ union {
+ struct {
+ unsigned char yl;
+ unsigned char yh;
+ };
+ unsigned short y;
+ };
+
+ //! @brief The Emulation mode flag
+ bool e;
+ //! @brief The Processor status register;
+ union p {
+ //! @brief The Carry flag
+ bool c : 1;
+ //! @brief The Zero flag
+ bool z : 1;
+ //! @brief The Interrupt disable flag
+ bool i : 1;
+ //! @brief The Decimal mode flag
+ bool d : 1;
+ union {
+ //! @brief The indeX register width flag (in native mode only)
+ bool x : 1;
+ //! @brief The Break flag (in emulation mode only)
+ bool b : 1;
+ };
+ //! @brief The accumulator and Memory width flag (in native mode only)
+ bool m : 1;
+ //! @brief The oVerflow flag
+ bool v : 1;
+ //! @brief The Negative flag
+ bool n : 1;
+ };
+ };
+
+ class CPU : IMemory {
+ private:
+ Registers _registers;
+ };
+}
+
+#endif //COMSQUARE_CPU_HPP
diff --git a/sources/hello.cpp b/sources/hello.cpp
deleted file mode 100644
index b62ba07..0000000
--- a/sources/hello.cpp
+++ /dev/null
@@ -1,7 +0,0 @@
-#include
-
-int HelloWorld(void)
-{
- std::cout << "Hello, World!" << std::endl;
- return 0;
-}
\ No newline at end of file
diff --git a/tests/hello.cpp b/tests/hello.cpp
deleted file mode 100644
index b8f8842..0000000
--- a/tests/hello.cpp
+++ /dev/null
@@ -1,10 +0,0 @@
-#include
-
-int HelloWorld(void);
-
-Test(HelloWorld, hello)
-{
- int result = HelloWorld();
-
- cr_assert_eq(result, 0);
-}
\ No newline at end of file
diff --git a/tests/testCPU.cpp b/tests/testCPU.cpp
new file mode 100644
index 0000000..2ab4ec8
--- /dev/null
+++ b/tests/testCPU.cpp
@@ -0,0 +1,4 @@
+//
+// Created by anonymus-raccoon on 1/24/20.
+//
+