Skip to content

Commit

Permalink
some prep work for gameboy hmmmmm???
Browse files Browse the repository at this point in the history
  • Loading branch information
coornio committed Sep 21, 2024
1 parent c6fa84b commit 09b0987
Show file tree
Hide file tree
Showing 8 changed files with 239 additions and 2 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ project(CubeChip)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
Expand Down Expand Up @@ -41,6 +40,9 @@ add_executable(CubeChip
src/Systems/BYTEPUSHER/BytePusher_CoreInterface.cpp
src/Systems/BYTEPUSHER/Cores/BYTEPUSHER_STANDARD.cpp

src/Systems/GAMEBOY/GameBoy_CoreInterface.cpp
src/Systems/GAMEBOY/Cores/GAMEBOY_CLASSIC.cpp

src/Systems/CHIP8/Chip8_CoreInterface.cpp
src/Systems/CHIP8/Cores/CHIP8_MODERN.cpp
src/Systems/CHIP8/Cores/SCHIP_MODERN.cpp
Expand All @@ -61,5 +63,5 @@ endif()
if(MSVC)
target_compile_options(CubeChip PRIVATE /W4 /std:c++latest)
else()
target_compile_options(CubeChip PRIVATE -Wall -Wextra --std=c++23)
target_compile_options(CubeChip PRIVATE -Wall -Wextra -stdlib=libc++ --std=c++23)
endif()
4 changes: 4 additions & 0 deletions CubeChip (SDL).vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
<ClCompile Include="src\Systems\CHIP8\Cores\SCHIP_MODERN.cpp" />
<ClCompile Include="src\Systems\CHIP8\Cores\XOCHIP.cpp" />
<ClCompile Include="src\Systems\EmuInterface.cpp" />
<ClCompile Include="src\Systems\GAMEBOY\Cores\GAMEBOY_CLASSIC.cpp" />
<ClCompile Include="src\Systems\GAMEBOY\GameBoy_CoreInterface.cpp" />
<ClCompile Include="src\Systems\GameFileChecker.cpp" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -64,6 +66,8 @@
<ClInclude Include="src\Systems\CHIP8\Cores\SCHIP_MODERN.hpp" />
<ClInclude Include="src\Systems\CHIP8\Cores\XOCHIP.hpp" />
<ClInclude Include="src\Systems\EmuInterface.hpp" />
<ClInclude Include="src\Systems\GAMEBOY\Cores\GAMEBOY_CLASSIC.hpp" />
<ClInclude Include="src\Systems\GAMEBOY\GameBoy_CoreInterface.hpp" />
<ClInclude Include="src\Systems\GameFileChecker.hpp" />
<ClInclude Include="src\_nlohmann\json.hpp" />
<ClInclude Include="src\_nlohmann\json_fwd.hpp" />
Expand Down
18 changes: 18 additions & 0 deletions CubeChip (SDL).vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
<Filter Include="Source Files\Systems\CHIP8\Cores">
<UniqueIdentifier>{a31d04cb-4539-415a-9bab-f85e2fb0f2b7}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\Systems\GAMEBOY">
<UniqueIdentifier>{00a2d494-a57a-4ba3-9210-3d04cb91f4e5}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\Systems\GAMEBOY\Cores">
<UniqueIdentifier>{5b33560e-ded9-4795-ba66-939d71046c56}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\CubeChip.cpp">
Expand Down Expand Up @@ -95,6 +101,12 @@
<ClCompile Include="src\Systems\CHIP8\Cores\MEGACHIP.cpp">
<Filter>Source Files\Systems\CHIP8\Cores</Filter>
</ClCompile>
<ClCompile Include="src\Systems\GAMEBOY\GameBoy_CoreInterface.cpp">
<Filter>Source Files\Systems\GAMEBOY</Filter>
</ClCompile>
<ClCompile Include="src\Systems\GAMEBOY\Cores\GAMEBOY_CLASSIC.cpp">
<Filter>Source Files\Systems\GAMEBOY\Cores</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\_nlohmann\json_fwd.hpp">
Expand Down Expand Up @@ -178,5 +190,11 @@
<ClInclude Include="src\Systems\CHIP8\Cores\MEGACHIP.hpp">
<Filter>Source Files\Systems\CHIP8\Cores</Filter>
</ClInclude>
<ClInclude Include="src\Systems\GAMEBOY\GameBoy_CoreInterface.hpp">
<Filter>Source Files\Systems\GAMEBOY</Filter>
</ClInclude>
<ClInclude Include="src\Systems\GAMEBOY\Cores\GAMEBOY_CLASSIC.hpp">
<Filter>Source Files\Systems\GAMEBOY\Cores</Filter>
</ClInclude>
</ItemGroup>
</Project>
39 changes: 39 additions & 0 deletions src/Systems/GAMEBOY/Cores/GAMEBOY_CLASSIC.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#include "../../../Assistants/HomeDirManager.hpp"
#include "../../../Assistants/BasicVideoSpec.hpp"
#include "../../../Assistants/BasicAudioSpec.hpp"
#include "../../../Assistants/Well512.hpp"

#include "GAMEBOY_CLASSIC.hpp"

/*==================================================================*/

GAMEBOY_CLASSIC::GAMEBOY_CLASSIC() {
if (getSystemState() != EmuState::FAILED) {

BVS->createTexture(cScreenSizeX, cScreenSizeY);
BVS->setAspectRatio(cScreenSizeX, cScreenSizeY, +2);

mActiveCPF = 0;
mFramerate = cRefreshRate;
}
}

/*==================================================================*/

void GAMEBOY_CLASSIC::instructionLoop() noexcept {

}

void GAMEBOY_CLASSIC::renderAudioData() {

}

void GAMEBOY_CLASSIC::renderVideoData() {

}
33 changes: 33 additions & 0 deletions src/Systems/GAMEBOY/Cores/GAMEBOY_CLASSIC.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#pragma once

#include "../GameBoy_CoreInterface.hpp"

/*==================================================================*/

class GAMEBOY_CLASSIC final : public GameBoy_CoreInterface {
static constexpr u32 cTotalMemory{ 0x2000 };
static constexpr u32 cSafezoneOOB{ 8 };
static constexpr f32 cRefreshRate{ 59.72750f };
static constexpr s32 cAudioLength{ 256 };
static constexpr s32 cScreenSizeX{ 160 };
static constexpr s32 cScreenSizeY{ 144 };
static constexpr s32 cScreenSizeT{ 160 * 144 };

private:
void instructionLoop() noexcept override;
void renderAudioData() override;
void renderVideoData() override;

public:
GAMEBOY_CLASSIC();

static constexpr bool testGameSize(const usz size) noexcept {
return size <= cTotalMemory;
}
};
74 changes: 74 additions & 0 deletions src/Systems/GAMEBOY/GameBoy_CoreInterface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#include "../../Assistants/BasicInput.hpp"
#include "../../Assistants/HomeDirManager.hpp"
#include "../../Assistants/BasicAudioSpec.hpp"

#include "GameBoy_CoreInterface.hpp"

/*==================================================================*/

fsPath* GameBoy_CoreInterface::sSavestatePath{};

GameBoy_CoreInterface::GameBoy_CoreInterface() noexcept
: ASB{ std::make_unique<AudioSpecBlock>(SDL_AUDIO_S8, 1, 48'000) }
{
sSavestatePath = HDM->addSystemDir("savestate", "GAMEBOY");
if (!sSavestatePath) { addCoreState(EmuState::FAILED); }

loadPresetBinds();
}

GameBoy_CoreInterface::~GameBoy_CoreInterface() noexcept {}

/*==================================================================*/

void GameBoy_CoreInterface::processFrame() {
if (isSystemStopped()) { return; }
else [[likely]] { ++mTotalFrames; }

instructionLoop();
renderAudioData();
renderVideoData();
}

void GameBoy_CoreInterface::loadPresetBinds() {
static constexpr auto _{ SDL_SCANCODE_UNKNOWN };
static constexpr SimpleKeyMapping defaultKeyMappings[]{
{0x1, KEY(1), _}, {0x2, KEY(2), _}, {0x3, KEY(3), _}, {0xC, KEY(4), _},
{0x4, KEY(Q), _}, {0x5, KEY(W), _}, {0x6, KEY(E), _}, {0xD, KEY(R), _},
{0x7, KEY(A), _}, {0x8, KEY(S), _}, {0x9, KEY(D), _}, {0xE, KEY(F), _},
{0xA, KEY(Z), _}, {0x0, KEY(X), _}, {0xB, KEY(C), _}, {0xF, KEY(V), _},
};

loadCustomBinds(defaultKeyMappings);
}

void GameBoy_CoreInterface::loadCustomBinds(std::span<const SimpleKeyMapping> binds) {
mCustomBinds.assign(binds.begin(), binds.end());
}

u32 GameBoy_CoreInterface::getKeyStates() const {
auto keyStates{ 0u };

for (const auto& mapping : mCustomBinds) {
if (binput::kb.areAnyHeld(mapping.key, mapping.alt)) {
keyStates |= 1u << mapping.idx;
}
}

return keyStates;
}

void GameBoy_CoreInterface::copyGameToMemory(u8* dest) noexcept {
std::copy_n(
std::execution::unseq,
HDM->getFileData(),
HDM->getFileSize(),
dest
);
}
65 changes: 65 additions & 0 deletions src/Systems/GAMEBOY/GameBoy_CoreInterface.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#pragma once

#include "../EmuInterface.hpp"

/*==================================================================*/

class GameBoy_CoreInterface : public EmuInterface {

protected:
static fsPath* sSavestatePath;

std::unique_ptr<AudioSpecBlock> ASB;

std::vector<SimpleKeyMapping> mCustomBinds;

u32 getKeyStates() const;
void loadPresetBinds();
void loadCustomBinds(std::span<const SimpleKeyMapping> binds);

u64 mTotalCycles{};
u32 mTotalFrames{};

u32 mCoreState{};
f32 mFramerate{};
s32 mActiveCPF{};

void addCoreState(const EmuState state) noexcept { mCoreState |= state; }
void subCoreState(const EmuState state) noexcept { mCoreState &= ~state; }
void xorCoreState(const EmuState state) noexcept { mCoreState ^= state; }

void setCoreState(const EmuState state) noexcept { mCoreState = state; }
auto getCoreState() const noexcept { return mCoreState; }

bool isSystemStopped() const noexcept override { return getCoreState() || getSystemState(); }
bool isCoreStopped() const noexcept override { return getCoreState(); }

void copyGameToMemory(u8* dest) noexcept;

virtual void instructionLoop() noexcept = 0;
virtual void renderAudioData() = 0;
virtual void renderVideoData() = 0;

public:
GameBoy_CoreInterface() noexcept;
~GameBoy_CoreInterface() noexcept override;

void processFrame() override;

u32 getTotalFrames() const noexcept override { return mTotalFrames; }
u64 getTotalCycles() const noexcept override { return mTotalCycles; }

s32 getCPF() const noexcept override { return mActiveCPF; }
f32 getFramerate() const noexcept override { return mFramerate; }

s32 changeCPF(const s32) noexcept override { return mActiveCPF; }

protected:

};
2 changes: 2 additions & 0 deletions src/Systems/GameFileChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ using json = nlohmann::json;

#include "BYTEPUSHER/Cores/BYTEPUSHER_STANDARD.hpp"

#include "GAMEBOY/Cores/GAMEBOY_CLASSIC.hpp"

/*==================================================================*/

GameCoreType GameFileChecker::sEmuCore{};
Expand Down

0 comments on commit 09b0987

Please sign in to comment.