Skip to content

Commit

Permalink
Refactor/tidy up the EmuHost class, things are much neater, and there…
Browse files Browse the repository at this point in the history
…'s a rudimentary automated MIPS "calculator" but it takes a while for it to wind up lol
  • Loading branch information
coornio committed Sep 1, 2024
1 parent d9ebaa7 commit 582162e
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 146 deletions.
1 change: 1 addition & 0 deletions CubeChip (SDL).vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@
<LanguageStandard_C>stdc17</LanguageStandard_C>
<DisableSpecificWarnings>
</DisableSpecificWarnings>
<AdditionalOptions>-Wunknown-pragmas %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand Down
4 changes: 0 additions & 4 deletions src/Assistants/BasicInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
#pragma region BasicKeyboard Singleton Class
/*==================================================================*/

BasicKeyboard& bic::kb{ *BasicKeyboard::create() };

void BasicKeyboard::updateCopy() {
std::copy_n(
std::execution::par_unseq,
Expand All @@ -32,8 +30,6 @@ void BasicKeyboard::updateCopy() {
#pragma region BasicMouse Singleton Class
/*==================================================================*/

BasicMouse& bic::mb{ *BasicMouse::create() };

void BasicMouse::updateCopy() {
const auto oldX{ posX };
const auto oldY{ posY };
Expand Down
2 changes: 1 addition & 1 deletion src/Assistants/BasicInput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class BasicMouse final {
#pragma endregion
/*VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV*/

namespace bic { // basic input class
namespace binput {
extern BasicKeyboard& kb;
extern BasicMouse& mb;
}
31 changes: 8 additions & 23 deletions src/CubeChip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

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

BasicLogger& blog{ *BasicLogger::create() };
BasicKeyboard& kb{ *BasicKeyboard::create() };
BasicMouse& mb{ *BasicMouse::create() };
BasicLogger& blog{ *BasicLogger::create() };
BasicKeyboard& binput::kb{ *BasicKeyboard::create() };
BasicMouse& binput::mb{ *BasicMouse::create() };

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

Expand Down Expand Up @@ -83,51 +83,36 @@ SDL_AppResult SDL_AppInit(void **Host, int argc, char* argv[]) {

SDL_AppResult SDL_AppIterate(void* pHost) {
auto& Host{ *static_cast<EmuHost*>(pHost) };
const std::lock_guard lock{ Host.Mutex };

Host.Mutex.lock();
switch (Host.runFrame()) {
case SDL_APP_SUCCESS:
Host.Mutex.unlock();
return SDL_APP_SUCCESS;

case SDL_APP_CONTINUE:
Host.Mutex.unlock();
return SDL_APP_CONTINUE;
Host.processFrame();

case SDL_APP_FAILURE:
Host.Mutex.unlock();
return SDL_APP_FAILURE;
}
return SDL_APP_CONTINUE;
}

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

SDL_AppResult SDL_AppEvent(void* pHost, const SDL_Event* Event) {
auto& Host{ *static_cast<EmuHost*>(pHost) };
const std::lock_guard lock{ Host.Mutex };

switch (Event->type) {
case SDL_EVENT_QUIT:
return SDL_APP_SUCCESS;

case SDL_EVENT_DROP_FILE:
Host.Mutex.lock();
Host.loadGameFile(Event->drop.data, true);
Host.Mutex.unlock();
break;

case SDL_EVENT_WINDOW_MINIMIZED:
Host.Mutex.lock();
Host.pauseSystem(true);
Host.Mutex.unlock();
break;

case SDL_EVENT_WINDOW_RESTORED:
Host.Mutex.lock();
Host.pauseSystem(false);
Host.Mutex.unlock();
break;
}

return SDL_APP_CONTINUE;
}

Expand Down
13 changes: 5 additions & 8 deletions src/GuestClass/EmuCores/CHIP8_MODERN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ CHIP8_MODERN::CHIP8_MODERN() noexcept {
mFramerate = cRefreshRate;
mCyclesPerFrame = Quirk.waitVblank ? cInstSpeedHi : 6000000;

initPlatform();
setDisplayResolution(64, 32);

BVS->setBackColor(cBitsColor[0]);
BVS->createTexture(mDisplayW, mDisplayH);
BVS->setAspectRatio(512, 256, +2);
}
}

Expand Down Expand Up @@ -278,10 +282,3 @@ void CHIP8_MODERN::renderVideoData() {
);
BVS->unlockTexture();
}

void CHIP8_MODERN::initPlatform() {
setDisplayResolution(64, 32);
BVS->setBackColor(cBitsColor[0]);
BVS->createTexture(mDisplayW, mDisplayH);
BVS->setAspectRatio(512, 256, +2);
}
5 changes: 2 additions & 3 deletions src/GuestClass/EmuCores/CHIP8_MODERN.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

class CHIP8_MODERN final : public Chip8_CoreInterface {
static constexpr u32 cTotalMemory{ 0x1000u };
static constexpr u32 cSafezoneOOB{ 0x0031u };
static constexpr u32 cGameLoadPos{ 0x0200u };
static constexpr u32 cStartOffset{ 0x0200u };
static constexpr f32 cRefreshRate{ 60.000f };
Expand Down Expand Up @@ -48,7 +49,7 @@ class CHIP8_MODERN final : public Chip8_CoreInterface {
std::array<u8, 2048>
mDisplayBuffer{};

std::array<u8, cTotalMemory + 31>
std::array<u8, cTotalMemory + cSafezoneOOB>
mMemoryBank{};

void writeMemoryI(const u32 value, const u32 pos) noexcept {
Expand All @@ -62,8 +63,6 @@ class CHIP8_MODERN final : public Chip8_CoreInterface {
}

private:
void initPlatform();

void renderAudioData();
void renderVideoData();

Expand Down
2 changes: 1 addition & 1 deletion src/GuestClass/HexInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void HexInput::updateKeyStates() noexcept {
mKeysCurr = 0;

for (const auto& mapping : mCustomBinds) {
if (bic::kb.areAnyHeld(mapping.key, mapping.alt)) {
if (binput::kb.areAnyHeld(mapping.key, mapping.alt)) {
mKeysCurr |= 1 << mapping.idx;
}
}
Expand Down
Loading

0 comments on commit 582162e

Please sign in to comment.