-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
some prep work for gameboy hmmmmm???
- Loading branch information
Showing
8 changed files
with
239 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters