This commit is contained in:
CocoSimone
2022-05-15 21:35:27 +02:00
parent 429541ab0c
commit 072f5bb847
7 changed files with 90 additions and 25 deletions

View File

@@ -4,4 +4,4 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_library(gb Core.hpp Core.cpp Cpu.hpp Cpu.cpp Ppu.hpp Ppu.cpp) add_library(gb Core.hpp Core.cpp Cpu.hpp Cpu.cpp Ppu.hpp Ppu.cpp)
target_include_directories(gb PUBLIC . ..) target_include_directories(gb PUBLIC .)

View File

@@ -0,0 +1,5 @@
#include <Core.hpp>
namespace natsukashii::core {
Core::Core() {}
}

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include <Cpu.hpp> #include "Cpu.hpp"
#include <Ppu.hpp> #include "Ppu.hpp"
namespace natsukashii::core { namespace natsukashii::core {
struct Core { struct Core {

View File

@@ -0,0 +1,6 @@
#include <Cpu.hpp>
namespace natsukashii::core {
Cpu::Cpu() {
}
}

View File

@@ -1,34 +1,86 @@
#pragma once #pragma once
#include <common.hpp> #include "../common.hpp"
namespace natsukashii::core { namespace natsukashii::core {
template <class A, class B> #define af regs.AF
struct RegisterPair { #define bc regs.BC
A low; #define de regs.DE
B high; #define hl regs.HL
auto operator=(const u16& rhs) {
low = rhs & 0xff; #define a af.A
high = rhs >> 8; #define f af.F
#define b bc.B
#define c bc.C
#define d de.D
#define e de.E
#define h hl.H
#define l hl.L
#define REGIMPL(type1, reg1, type2, reg2) \
struct reg##reg1##reg2 { \
reg##reg1##reg2() {} \
union { \
type1 reg1; \
type2 reg2; \
}; \
u16 raw = 0; \
reg##reg1##reg2& operator=(const u16& rhs) { \
reg1 = rhs >> 8; \
reg2 = rhs & 0xff; \
return *this; \
} \
} reg1##reg2
struct RegF {
RegF() : raw(0) {}
RegF(const u8& val) : raw(val) {}
u8 raw = 0;
RegF& operator=(const u8& rhs) {
raw |= ((rhs >> 7) << 7);
raw |= ((rhs >> 6) << 6);
raw |= ((rhs >> 5) << 5);
raw |= ((rhs >> 4) << 4);
return *this; return *this;
} }
bool zero() { return (raw >> 7) & 1; }
bool negative() { return (raw >> 6) & 1; }
bool halfcarry() { return (raw >> 5) & 1; }
bool carry() { return (raw >> 4) & 1; }
void zero(const bool& rhs) {
raw &= ~0xF;
raw |= (rhs << 7);
}
void negative(const bool& rhs) {
raw &= ~0xF;
raw |= (rhs << 6);
}
void halfcarry(const bool& rhs) {
raw &= ~0xF;
raw |= (rhs << 5);
}
void carry(const bool& rhs) {
raw &= ~0xF;
raw |= (rhs << 4);
}
}; };
union RegF { struct Registers {
struct { REGIMPL(u8, A, RegF, F);
unsigned z:1; REGIMPL(u8, B, u8, C);
unsigned n:1; REGIMPL(u8, C, u8, E);
unsigned h:1; REGIMPL(u8, D, u8, L);
unsigned c:1;
unsigned:4;
};
u8 raw;
}; };
struct Cpu { struct Cpu {
Cpu();
private: private:
RegisterPair<u8, RegF> af; Registers regs;
RegisterPair<u8, u8> bc;
RegisterPair<u8, u8> de;
RegisterPair<u8, u8> hl;
}; };
} }

View File

@@ -6,5 +6,5 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(SDL2 REQUIRED) find_package(SDL2 REQUIRED)
add_library(frontend Frontend.cpp Frontend.hpp) add_library(frontend Frontend.cpp Frontend.hpp)
target_include_directories(frontend PUBLIC .) target_include_directories(frontend PUBLIC . ../../core)
target_link_libraries(frontend PUBLIC SDL2) target_link_libraries(frontend PUBLIC SDL2)

View File

@@ -1,5 +1,6 @@
#pragma once #pragma once
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include <gb/Core.hpp>
namespace natsukashii::frontend { namespace natsukashii::frontend {
struct App { struct App {
@@ -11,5 +12,6 @@ private:
SDL_Renderer *renderer = nullptr; SDL_Renderer *renderer = nullptr;
Uint32 id; Uint32 id;
bool quit = false; bool quit = false;
core::Core gb;
}; };
} }