Skip to content

Commit

Permalink
generalize data copiers a bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
coornio committed Dec 1, 2024
1 parent 063a2b4 commit 718f76b
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 39 deletions.
33 changes: 8 additions & 25 deletions src/Systems/CHIP8/Chip8_CoreInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ void Chip8_CoreInterface::startAudio(const s32 duration, const s32 tone) noexcep
void Chip8_CoreInterface::startAudioAtChannel(const u32 index, const s32 duration, const s32 tone) noexcept {
if (index >= STREAM::COUNT) { return; }

mAudioTimer[index] = duration & 0xFF;
mPhaseStep[index] = (160.0f + (tone ? tone
mAudioTimer[index] = static_cast<u8>(duration);
mPhaseStep[index] = (sTonalOffset + (tone ? tone
: 8 * ((mCurrentPC >> 1) + mStackTop + 1 & 0x3E)
)) / ASB->getFrequency();
}
Expand Down Expand Up @@ -324,33 +324,16 @@ bool Chip8_CoreInterface::getPermaRegs(const u32 X) noexcept {

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

void Chip8_CoreInterface::copyGameToMemory(
u8* dest, const u32 offset
) noexcept {
std::copy_n(
std::execution::unseq,
HDM->getFileData(),
HDM->getFileSize(),
dest + offset
);
void Chip8_CoreInterface::copyGameToMemory(void* dest) noexcept {
std::memcpy(dest, HDM->getFileData(), HDM->getFileSize());
}

void Chip8_CoreInterface::copyFontToMemory(
u8* dest, const u32 offset, const usz size
) noexcept {
std::copy_n(
std::execution::unseq,
sFontsData.begin(), size, dest + offset
);
void Chip8_CoreInterface::copyFontToMemory(void* dest, const usz size) noexcept {
std::memcpy(dest, std::data(sFontsData), size);
}

void Chip8_CoreInterface::copyColorsToCore(
u32* dest, const usz size
) noexcept {
std::copy_n(
std::execution::unseq,
sBitColors.begin(), size, dest
);
void Chip8_CoreInterface::copyColorsToCore(void* dest) noexcept {
std::memcpy(dest, std::data(sBitColors), std::size(sBitColors) * sizeof(decltype(sBitColors)::value_type));
}

/*==================================================================*/
Expand Down
7 changes: 4 additions & 3 deletions src/Systems/CHIP8/Chip8_CoreInterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Chip8_CoreInterface : public EmuInterface {
protected:
static inline Path* sPermaRegsPath{};
static inline Path* sSavestatePath{};
static inline f32 sTonalOffset{ 160.0f };

std::unique_ptr<AudioSpecBlock> ASB;

Expand Down Expand Up @@ -169,9 +170,9 @@ class Chip8_CoreInterface : public EmuInterface {
bool setPermaRegs(const u32 X) noexcept;
bool getPermaRegs(const u32 X) noexcept;

void copyGameToMemory(u8* dest, const u32 offset) noexcept;
void copyFontToMemory(u8* dest, const u32 offset, const usz size) noexcept;
void copyColorsToCore(u32* dest, const usz size) noexcept;
void copyGameToMemory(void* dest) noexcept;
void copyFontToMemory(void* dest, const usz size) noexcept;
void copyColorsToCore(void* dest) noexcept;

virtual void handlePreFrameInterrupt() noexcept;
virtual void handleEndFrameInterrupt() noexcept;
Expand Down
5 changes: 3 additions & 2 deletions src/Systems/CHIP8/Cores/CHIP8_MODERN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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"
Expand All @@ -21,8 +22,8 @@ CHIP8_MODERN::CHIP8_MODERN() {
mMemoryBank.end(), u8{ 0xFF }
);

copyGameToMemory(mMemoryBank.data(), cGameLoadPos);
copyFontToMemory(mMemoryBank.data(), 0x0, 0x50);
copyGameToMemory(mMemoryBank.data() + cGameLoadPos);
copyFontToMemory(mMemoryBank.data(), 0x50);

setDisplayResolution(cScreenSizeX, cScreenSizeY);

Expand Down
4 changes: 2 additions & 2 deletions src/Systems/CHIP8/Cores/MEGACHIP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ MEGACHIP::MEGACHIP()
{
if (getCoreState() != EmuState::FATAL) {

copyGameToMemory(mMemoryBank.data(), cGameLoadPos);
copyFontToMemory(mMemoryBank.data(), 0x0, 0xB4);
copyGameToMemory(mMemoryBank.data() + cGameLoadPos);
copyFontToMemory(mMemoryBank.data(), 0xB4);

mForegroundBuffer.resize(false, cScreenMegaY, cScreenMegaX);
mBackgroundBuffer.resize(false, cScreenMegaY, cScreenMegaX);
Expand Down
4 changes: 2 additions & 2 deletions src/Systems/CHIP8/Cores/SCHIP_LEGACY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ SCHIP_LEGACY::SCHIP_LEGACY()
mMemoryBank.end(), u8{ 0xFF }
);

copyGameToMemory(mMemoryBank.data(), cGameLoadPos);
copyFontToMemory(mMemoryBank.data(), 0x0, 0xB4);
copyGameToMemory(mMemoryBank.data() + cGameLoadPos);
copyFontToMemory(mMemoryBank.data(), 0xB4);

setDisplayResolution(cScreenSizeX, cScreenSizeY);

Expand Down
4 changes: 2 additions & 2 deletions src/Systems/CHIP8/Cores/SCHIP_MODERN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ SCHIP_MODERN::SCHIP_MODERN()
mMemoryBank.end(), u8{ 0xFF }
);

copyGameToMemory(mMemoryBank.data(), cGameLoadPos);
copyFontToMemory(mMemoryBank.data(), 0x0, 0xF0);
copyGameToMemory(mMemoryBank.data() + cGameLoadPos);
copyFontToMemory(mMemoryBank.data(), 0xF0);

setDisplayResolution(cScreenSizeX, cScreenSizeY);

Expand Down
6 changes: 3 additions & 3 deletions src/Systems/CHIP8/Cores/XOCHIP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ XOCHIP::XOCHIP()
mMemoryBank.end(), u8{ 0xFF }
);

copyGameToMemory(mMemoryBank.data(), cGameLoadPos);
copyFontToMemory(mMemoryBank.data(), 0x0, 0x50);
copyColorsToCore(mBitColors.data(), mBitColors.size());
copyGameToMemory(mMemoryBank.data() + cGameLoadPos);
copyFontToMemory(mMemoryBank.data(), 0x50);
copyColorsToCore(mBitColors.data());

setDisplayResolution(cScreenSizeX, cScreenSizeY);

Expand Down

0 comments on commit 718f76b

Please sign in to comment.