Skip to content

Commit

Permalink
Minor Fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
Aviii06 committed Feb 28, 2024
1 parent cbc4ad4 commit fd60bbf
Show file tree
Hide file tree
Showing 32 changed files with 816 additions and 156 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ build/
cmake-build-debug/
.idea/
src/.vscode/
src/dmg_boot.gb
roms/*
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ if (DEBUG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDEBUG")
endif()

add_executable(${PROJECT_NAME} src/main.cpp)
add_subdirectory(src)
add_subdirectory(vendor)
add_subdirectory(src)
Binary file added roms/Tetris.gb
Binary file not shown.
Binary file added roms/dmg_boot.gb
Binary file not shown.
27 changes: 17 additions & 10 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
#add_subdirectory(core)

add_executable(${PROJECT_NAME} main.cpp)

add_subdirectory(gui)
set(SOURCES
# -------
# Source Files
cpu.cpp
gameBoy.cpp
mmap.cpp
graphics.cpp
core/cpu.cpp
core/gameBoy.cpp
core/mmap.cpp
core/graphics.cpp
# -------
# Header Files
cpu.h
gameBoy.h
mmap.h
types.h
graphics.h
core/cpu.h
core/gameBoy.h
core/mmap.h
common/types.h
core/graphics.h
)

target_sources(${PROJECT_NAME} PRIVATE ${SOURCES})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS})

file(COPY ../roms DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/)

if (MSVC)
set_target_properties(
${PROJECT_NAME} PROPERTIES
VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/")
endif ()

target_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARIES})
target_link_libraries(${PROJECT_NAME} gui_gbemu)

set(SDL2_INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}/include")
94 changes: 94 additions & 0 deletions src/common/maths/vec.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#pragma once

#include <cmath>

// Structure to standardize the vertices used in the meshes
struct Vec4
{
float x, y, z, w;

Vec4()
: x(0.0f)
, y(0.0f)
, z(0.0f)
, w(0.0f)
{
}

Vec4(float x, float y, float z, float w)
: x(x)
, y(y)
, z(z)
, w(w)
{
}

Vec4 operator*(float scalar) { return Vec4(x * scalar, y * scalar, z * scalar, w * scalar); }

Vec4 operator+(Vec4 other) { return Vec4(x + other.x, y + other.y, z + other.z, w + other.w); }
};

struct Vec3
{
float x, y, z;

Vec3()
: x(0.0f)
, y(0.0f)
, z(0.0f)
{
}

Vec3(float x, float y, float z)
: x(x)
, y(y)
, z(z)
{
}

Vec3(const Vec3& other)
: x(other.x)
, y(other.y)
, z(other.z)
{
}

Vec3 operator*(float scalar) { return Vec3(x * scalar, y * scalar, z * scalar); }

Vec3 operator+(Vec3 other) { return Vec3(x + other.x, y + other.y, z + other.z); }

Vec3 operator-(Vec3 other) { return Vec3(x - other.x, y - other.y, z - other.z); }
};

struct Vec2
{
float x, y;

Vec2()
: x(0.0f)
, y(0.0f)
{
}

Vec2(float x, float y)
: x(x)
, y(y)
{
}

Vec2 operator*(float scalar) { return Vec2(x * scalar, y * scalar); }

Vec2 operator*(double scalar) { return Vec2(x * scalar, y * scalar); }

Vec2 operator+(Vec2 other) { return Vec2(x + other.x, y + other.y); }

Vec2 operator-(Vec2 other) { return Vec2(x - other.x, y - other.y); }

Vec2 Perpendicular() { return Vec2(-y, x); }

Vec2 Normalize()
{
float length = std::sqrt(x * x + y * y);
return Vec2(x / length, y / length);
}
};
File renamed without changes.
30 changes: 30 additions & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
set(SOURCES
# -------
# Source Files
cpu.cpp
gameBoy.cpp
mmap.cpp
graphics.cpp
# -------
# Header Files
cpu.h
gameBoy.h
mmap.h
../common/types.h
graphics.h
)

target_sources(${PROJECT_NAME} PRIVATE ${SOURCES})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS})

if (MSVC)
set_target_properties(
${PROJECT_NAME} PROPERTIES
VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/")
endif ()

target_link_libraries(${PROJECT_NAME} gui_gbemu)

set(SDL2_INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}/include")
2 changes: 1 addition & 1 deletion src/cpu.cpp → src/core/cpu.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "types.h"
#include "common/types.h"
#include "cpu.h"
#include <stdio.h>
#ifndef DEBUG
Expand Down
2 changes: 1 addition & 1 deletion src/cpu.h → src/core/cpu.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "types.h"
#include "common/types.h"
#include "mmap.h"
#include "graphics.h"

Expand Down
8 changes: 4 additions & 4 deletions src/gameBoy.cpp → src/core/gameBoy.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "types.h"
#include "common/types.h"
#include "cpu.h"
#include "gameBoy.h"

Expand Down Expand Up @@ -27,11 +27,11 @@ GBE::GBE()
gbe_graphics->init();

// Open the Boot ROM
if ((bootROM = fopen("../src/dmg_boot.gb", "rb")) == NULL)
if ((bootROM = fopen("./roms/dmg_boot.gb", "rb")) == NULL)
printf("boot rom file not opened");

// Open the Game ROM
if ((gameROM = fopen("../tests/Tetris.gb", "rb")) == NULL)
if ((gameROM = fopen("./roms/Tetris.gb", "rb")) == NULL)
printf("game rom file not opened");

// Set the Boot ROM
Expand Down Expand Up @@ -107,7 +107,7 @@ void GBE::update()
// Update function of the GBE
// Will be called every frame
// GB has 59.73 frames per second
while (true)
// while (true)
{
// Execute the next instruction
s_Cycles += gbe_cpu->executeNextInstruction();
Expand Down
15 changes: 10 additions & 5 deletions src/gameBoy.h → src/core/gameBoy.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "types.h"
#include "common/types.h"
#include "cpu.h"
#include "mmap.h"
#include "graphics.h"
Expand Down Expand Up @@ -34,10 +34,7 @@ class GBE
// File pointer for game ROM
FILE* gameROM;

// Update function of the GBE
// Will be called every frame
// GB has 59.73 frames per second
void update();


// cycle counter of the gameboy
// used by CPU, PPU, APU so declared here
Expand All @@ -52,6 +49,14 @@ class GBE
// Initializes the CPU
GBE();

// Update function of the GBE
// Will be called every frame
// GB has 59.73 frames per second
void update();

// Returns the CPU
CPU* getCPU() { return gbe_cpu; };
color* getRenderArray() const { return gbe_graphics->getRenderArray(); }

SDL_Texture* getSDLTexture() const { return gbe_graphics->getSDLTexture(); }
};
Loading

0 comments on commit fd60bbf

Please sign in to comment.