mirror of
https://github.com/zoriya/ComSquare.git
synced 2026-06-05 10:59:38 +00:00
Finishing the registers for the CPU
This commit is contained in:
+11
-2
@@ -8,11 +8,20 @@ project(ComSquare)
|
|||||||
add_compile_options(-W -Wall -Wextra -Wshadow)
|
add_compile_options(-W -Wall -Wextra -Wshadow)
|
||||||
|
|
||||||
# make unit tests
|
# make unit tests
|
||||||
add_executable(unit_tests sources/hello.cpp tests/hello.cpp)
|
add_executable(unit_tests
|
||||||
|
tests/testCPU.cpp
|
||||||
|
)
|
||||||
|
|
||||||
# include criterion & coverage
|
# include criterion & coverage
|
||||||
target_link_libraries(unit_tests criterion -lgcov)
|
target_link_libraries(unit_tests criterion -lgcov)
|
||||||
target_compile_options(unit_tests PUBLIC -fprofile-arcs -ftest-coverage)
|
target_compile_options(unit_tests PUBLIC -fprofile-arcs -ftest-coverage)
|
||||||
|
|
||||||
# make app
|
# 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)
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
int HelloWorld(void);
|
//
|
||||||
|
// Created by anonymus-raccoon on 1/24/20.
|
||||||
|
//
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
return HelloWorld();
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
//
|
||||||
|
// Created by anonymus-raccoon on 1/24/20.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "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
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
|
|
||||||
int HelloWorld(void)
|
|
||||||
{
|
|
||||||
std::cout << "Hello, World!" << std::endl;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
#include <criterion/criterion.h>
|
|
||||||
|
|
||||||
int HelloWorld(void);
|
|
||||||
|
|
||||||
Test(HelloWorld, hello)
|
|
||||||
{
|
|
||||||
int result = HelloWorld();
|
|
||||||
|
|
||||||
cr_assert_eq(result, 0);
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
//
|
||||||
|
// Created by anonymus-raccoon on 1/24/20.
|
||||||
|
//
|
||||||
|
|
||||||
Reference in New Issue
Block a user