Skip to content

Commit

Permalink
Preliminary push of MEGACHIP core, along with amendments in all other…
Browse files Browse the repository at this point in the history
… cores and the Chip8 interface. Workable, but still some kinks to iron out from the porting process.
  • Loading branch information
coornio committed Sep 19, 2024
1 parent e3b4d14 commit 414f1ab
Show file tree
Hide file tree
Showing 16 changed files with 1,460 additions and 137 deletions.
2 changes: 2 additions & 0 deletions CubeChip (SDL).vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<ClCompile Include="src\Systems\BYTEPUSHER\Cores\BYTEPUSHER_STANDARD.cpp" />
<ClCompile Include="src\Systems\CHIP8\Chip8_CoreInterface.cpp" />
<ClCompile Include="src\Systems\CHIP8\Cores\CHIP8_MODERN.cpp" />
<ClCompile Include="src\Systems\CHIP8\Cores\MEGACHIP.cpp" />
<ClCompile Include="src\Systems\CHIP8\Cores\SCHIP_LEGACY.cpp" />
<ClCompile Include="src\Systems\CHIP8\Cores\SCHIP_MODERN.cpp" />
<ClCompile Include="src\Systems\CHIP8\Cores\XOCHIP.cpp" />
Expand All @@ -58,6 +59,7 @@
<ClInclude Include="src\Systems\BYTEPUSHER\Cores\BYTEPUSHER_STANDARD.hpp" />
<ClInclude Include="src\Systems\CHIP8\Chip8_CoreInterface.hpp" />
<ClInclude Include="src\Systems\CHIP8\Cores\CHIP8_MODERN.hpp" />
<ClInclude Include="src\Systems\CHIP8\Cores\MEGACHIP.hpp" />
<ClInclude Include="src\Systems\CHIP8\Cores\SCHIP_LEGACY.hpp" />
<ClInclude Include="src\Systems\CHIP8\Cores\SCHIP_MODERN.hpp" />
<ClInclude Include="src\Systems\CHIP8\Cores\XOCHIP.hpp" />
Expand Down
6 changes: 6 additions & 0 deletions CubeChip (SDL).vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@
<ClCompile Include="src\Systems\CHIP8\Cores\SCHIP_LEGACY.cpp">
<Filter>Source Files\Systems\CHIP8\Cores</Filter>
</ClCompile>
<ClCompile Include="src\Systems\CHIP8\Cores\MEGACHIP.cpp">
<Filter>Source Files\Systems\CHIP8\Cores</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\_nlohmann\json_fwd.hpp">
Expand Down Expand Up @@ -172,5 +175,8 @@
<ClInclude Include="src\Systems\CHIP8\Cores\SCHIP_LEGACY.hpp">
<Filter>Source Files\Systems\CHIP8\Cores</Filter>
</ClInclude>
<ClInclude Include="src\Systems\CHIP8\Cores\MEGACHIP.hpp">
<Filter>Source Files\Systems\CHIP8\Cores</Filter>
</ClInclude>
</ItemGroup>
</Project>
32 changes: 24 additions & 8 deletions src/Assistants/BasicVideoSpec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,11 @@ class BasicVideoSpec final {

static void showErrorBox(const char* const) noexcept;

void setBackColor (
const u32 color
) noexcept {
void setBackColor(const u32 color) noexcept {
frameBackColor = color;
}

void setFrameColor(
const u32 color_off,
const u32 color_on
) noexcept {
void setFrameColor(const u32 color_off, const u32 color_on) noexcept {
frameRectColor[0] = color_off;
frameRectColor[1] = color_on;
}
Expand All @@ -86,10 +81,14 @@ class BasicVideoSpec final {
[[nodiscard]]
u32* lockTexture();
void unlockTexture();

void modifyTexture(const std::span<u32> colorData);

template <typename T, typename Lambda>
void modifyTexture(const std::span<const T> pixelData, Lambda&& function) {
void modifyTexture(
const std::span<const T> pixelData,
Lambda&& function
) {
std::transform(
std::execution::unseq,
pixelData.begin(),
Expand All @@ -100,6 +99,23 @@ class BasicVideoSpec final {
unlockTexture();
}

template <typename T, typename Lambda>
void modifyTexture(
const std::span<const T> pixelData1,
const std::span<const T> pixelData2,
Lambda&& function
) {
std::transform(
std::execution::unseq,
pixelData1.begin(),
pixelData1.end(),
pixelData2.begin(),
lockTexture(),
function
);
unlockTexture();
}

void setTextureAlpha(usz);
void setAspectRatio(s32, s32, s32);

Expand Down
22 changes: 22 additions & 0 deletions src/Systems/CHIP8/Chip8_CoreInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,28 @@ void Chip8_CoreInterface::handleEndFrameInterrupt() noexcept {
}
}

void Chip8_CoreInterface::handleTimerTick() noexcept {
if (mDelayTimer) { --mDelayTimer; }
if (mSoundTimer) { --mSoundTimer; }
}

void Chip8_CoreInterface::nextInstruction() noexcept {
mCurrentPC += 2;
}

void Chip8_CoreInterface::skipInstruction() noexcept {
mCurrentPC += 2;
}

void Chip8_CoreInterface::performProgJump(const u32 next) noexcept {
const auto NNN{ next & 0xFFF };
if (mCurrentPC - 2u != NNN) [[likely]] {
mCurrentPC = NNN & 0xFFF;
} else {
triggerInterrupt(Interrupt::SOUND);
}
}

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

void Chip8_CoreInterface::processFrame() {
Expand Down
9 changes: 6 additions & 3 deletions src/Systems/CHIP8/Chip8_CoreInterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,17 @@ class Chip8_CoreInterface : public EmuInterface {
virtual void handlePreFrameInterrupt() noexcept;
virtual void handleEndFrameInterrupt() noexcept;

virtual void handleTimerTick() noexcept = 0;
virtual void handleTimerTick() noexcept;
virtual void instructionLoop() noexcept = 0;

virtual void nextInstruction() noexcept;
virtual void skipInstruction() noexcept;
virtual void performProgJump(const u32 next) noexcept;
virtual void prepDisplayArea(const Resolution mode) = 0;

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

virtual void prepDisplayArea(const Resolution mode) = 0;

f32 calcBuzzerTone() const noexcept;

public:
Expand Down
30 changes: 3 additions & 27 deletions src/Systems/CHIP8/Cores/CHIP8_MODERN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ CHIP8_MODERN::CHIP8_MODERN() {

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

void CHIP8_MODERN::handleTimerTick() noexcept {
if (mDelayTimer) { --mDelayTimer; }
if (mSoundTimer) { --mSoundTimer; }
}

void CHIP8_MODERN::instructionLoop() noexcept {

auto cycleCount{ 0 };
Expand Down Expand Up @@ -231,25 +226,6 @@ void CHIP8_MODERN::renderVideoData() {
);
}

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

void CHIP8_MODERN::nextInstruction() noexcept {
mCurrentPC += 2;
}

void CHIP8_MODERN::skipInstruction() noexcept {
mCurrentPC += 2;
}

void CHIP8_MODERN::jumpProgramTo(const u32 next) noexcept {
const auto NNN{ next & 0xFFF };
if (mCurrentPC - 2u != NNN) [[likely]] {
mCurrentPC = NNN & 0xFFF;
} else {
triggerInterrupt(Interrupt::SOUND);
}
}

/*==================================================================*/
#pragma region 0 instruction branch

Expand All @@ -274,7 +250,7 @@ void CHIP8_MODERN::jumpProgramTo(const u32 next) noexcept {
#pragma region 1 instruction branch

void CHIP8_MODERN::instruction_1NNN(const s32 NNN) noexcept {
jumpProgramTo(NNN);
performProgJump(NNN);
}

#pragma endregion
Expand All @@ -285,7 +261,7 @@ void CHIP8_MODERN::jumpProgramTo(const u32 next) noexcept {

void CHIP8_MODERN::instruction_2NNN(const s32 NNN) noexcept {
mStackBank[mStackTop++ & 0xF] = mCurrentPC;
jumpProgramTo(NNN);
performProgJump(NNN);
}

#pragma endregion
Expand Down Expand Up @@ -411,7 +387,7 @@ void CHIP8_MODERN::jumpProgramTo(const u32 next) noexcept {
#pragma region B instruction branch

void CHIP8_MODERN::instruction_BNNN(const s32 NNN) noexcept {
jumpProgramTo(NNN + mRegisterV[0]);
performProgJump(NNN + mRegisterV[0]);
}

#pragma endregion
Expand Down
5 changes: 0 additions & 5 deletions src/Systems/CHIP8/Cores/CHIP8_MODERN.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,13 @@ class CHIP8_MODERN final : public Chip8_CoreInterface {
}

private:
void handleTimerTick() noexcept override;
void instructionLoop() noexcept override;

void renderAudioData() override;
void renderVideoData() override;

void prepDisplayArea(const Resolution) override {}

void nextInstruction() noexcept;
void skipInstruction() noexcept;
void jumpProgramTo(const u32 next) noexcept;

/*==================================================================*/
#pragma region 0 instruction branch

Expand Down
Loading

0 comments on commit 414f1ab

Please sign in to comment.