diff --git a/src/Assistants/BasicAudioSpec.hpp b/src/Assistants/BasicAudioSpec.hpp index 4f087a4..66a4f3b 100644 --- a/src/Assistants/BasicAudioSpec.hpp +++ b/src/Assistants/BasicAudioSpec.hpp @@ -94,7 +94,7 @@ class AudioSpecBlock { auto getVolumeNorm() const noexcept { return mVolume / 255.0f; } auto getSampleRate(f32 framerate) const noexcept { - return framerate ? mSpec.freq / framerate : 0.0f; + return std::fabs(framerate) > 1e-6f ? mSpec.freq / framerate : 0.0f; } void setVolume(s32 value) noexcept { diff --git a/src/Assistants/BasicInput.cpp b/src/Assistants/BasicInput.cpp index 4272a31..48566f9 100644 --- a/src/Assistants/BasicInput.cpp +++ b/src/Assistants/BasicInput.cpp @@ -16,7 +16,7 @@ void BasicKeyboard::updateCopy() { std::copy_n( std::execution::par_unseq, SDL_GetKeyboardState(nullptr), - static_cast(SDL_NUM_SCANCODES), + SDL_SCANCODE_COUNT, oldState.data() ); } diff --git a/src/Assistants/BasicInput.hpp b/src/Assistants/BasicInput.hpp index 5e58279..f1a53bf 100644 --- a/src/Assistants/BasicInput.hpp +++ b/src/Assistants/BasicInput.hpp @@ -30,7 +30,7 @@ enum BIC_Button { #pragma region BasicKeyboard Singleton Class class BasicKeyboard final { - std::array oldState{}; + std::array oldState{}; BasicKeyboard() noexcept = default; ~BasicKeyboard() noexcept = default; diff --git a/src/Assistants/BasicVideoSpec.cpp b/src/Assistants/BasicVideoSpec.cpp index 75d52e1..2636412 100644 --- a/src/Assistants/BasicVideoSpec.cpp +++ b/src/Assistants/BasicVideoSpec.cpp @@ -10,8 +10,11 @@ #include #ifdef SDL_PLATFORM_WIN32 + #pragma warning(push) + #pragma warning(disable : 5039) #include #pragma comment (lib, "Dwmapi") + #pragma warning(pop) #endif #include "BasicVideoSpec.hpp" @@ -23,7 +26,7 @@ BasicVideoSpec::BasicVideoSpec() noexcept : enableBuzzGlow{ true } { if (!SDL_InitSubSystem(SDL_INIT_VIDEO)) { - showErrorBox("Failed SDL_INIT_VIDEO!"); + showErrorBox("Failed SDL_INIT_VIDEO"); return; } @@ -46,20 +49,20 @@ void BasicVideoSpec::createWindow(const s32 window_W, const s32 window_H) { window = SDL_CreateWindow(nullptr, window_W, window_H, 0); if (!window) { - showErrorBox("Failed to create SDL_Window!"); + showErrorBox("Failed to create SDL_Window"); } else { const auto windowHandle{ - static_cast(SDL_GetPointerProperty( + SDL_GetPointerProperty( SDL_GetWindowProperties(window), SDL_PROP_WINDOW_WIN32_HWND_POINTER, nullptr - )) + ) }; if (windowHandle) { const auto windowRound{ DWMWCP_DONOTROUND }; DwmSetWindowAttribute( - windowHandle, + static_cast(windowHandle), DWMWA_WINDOW_CORNER_PREFERENCE, &windowRound, sizeof(windowRound) @@ -74,7 +77,7 @@ void BasicVideoSpec::createRenderer() { renderer = SDL_CreateRenderer(window, nullptr); if (!renderer) { - showErrorBox("Failed to create SDL_Renderer!"); + showErrorBox("Failed to create SDL_Renderer"); } } @@ -92,7 +95,7 @@ void BasicVideoSpec::createTexture(s32 texture_W, s32 texture_H) { ); if (!texture) { - showErrorBox("Failed to create SDL_Texture!"); + showErrorBox("Failed to create SDL_Texture"); } else { SDL_SetTextureScaleMode(texture, SDL_SCALEMODE_NEAREST); ppitch = texture_W * 4; diff --git a/src/Assistants/HomeDirManager.cpp b/src/Assistants/HomeDirManager.cpp index 637012c..bfeb60f 100644 --- a/src/Assistants/HomeDirManager.cpp +++ b/src/Assistants/HomeDirManager.cpp @@ -17,11 +17,13 @@ /*==================================================================*/ +[[maybe_unused]] static auto getFileModTime(const fsPath& filePath) noexcept { std::error_code error; return std::filesystem::last_write_time(filePath, error); } +[[maybe_unused]] static auto getFileSize(const fsPath& filePath) noexcept { std::error_code error; return std::filesystem::file_size(filePath, error); diff --git a/src/Systems/BYTEPUSHER/BytePusher_CoreInterface.hpp b/src/Systems/BYTEPUSHER/BytePusher_CoreInterface.hpp index ec4e6d9..e2fee3b 100644 --- a/src/Systems/BYTEPUSHER/BytePusher_CoreInterface.hpp +++ b/src/Systems/BYTEPUSHER/BytePusher_CoreInterface.hpp @@ -48,7 +48,7 @@ class BytePusher_CoreInterface : public EmuInterface { public: BytePusher_CoreInterface() noexcept; - ~BytePusher_CoreInterface() noexcept; + ~BytePusher_CoreInterface() noexcept override; void processFrame() override; diff --git a/src/Systems/CHIP8/Chip8_CoreInterface.cpp b/src/Systems/CHIP8/Chip8_CoreInterface.cpp index daa46d3..6543bdc 100644 --- a/src/Systems/CHIP8/Chip8_CoreInterface.cpp +++ b/src/Systems/CHIP8/Chip8_CoreInterface.cpp @@ -306,7 +306,7 @@ void Chip8_CoreInterface::copyGameToMemory( } void Chip8_CoreInterface::copyFontToMemory( - u8* dest, const u32 offset, const u32 size + u8* dest, const u32 offset, const usz size ) noexcept { std::copy_n( std::execution::unseq, @@ -315,7 +315,7 @@ void Chip8_CoreInterface::copyFontToMemory( } void Chip8_CoreInterface::copyColorsToCore( - u32* dest, const u32 size + u32* dest, const usz size ) noexcept { std::copy_n( std::execution::unseq, diff --git a/src/Systems/CHIP8/Chip8_CoreInterface.hpp b/src/Systems/CHIP8/Chip8_CoreInterface.hpp index b80d9a5..f75cc33 100644 --- a/src/Systems/CHIP8/Chip8_CoreInterface.hpp +++ b/src/Systems/CHIP8/Chip8_CoreInterface.hpp @@ -145,8 +145,8 @@ class Chip8_CoreInterface : public EmuInterface { bool getPermaRegs(const s32 X) noexcept; void copyGameToMemory(u8* dest, const u32 offset) noexcept; - void copyFontToMemory(u8* dest, const u32 offset, const u32 size) noexcept; - void copyColorsToCore(u32* dest, const u32 size) noexcept; + void copyFontToMemory(u8* dest, const u32 offset, const usz size) noexcept; + void copyColorsToCore(u32* dest, const usz size) noexcept; virtual void handlePreFrameInterrupt() noexcept; virtual void handleEndFrameInterrupt() noexcept; @@ -166,7 +166,7 @@ class Chip8_CoreInterface : public EmuInterface { public: Chip8_CoreInterface() noexcept; - ~Chip8_CoreInterface() noexcept; + ~Chip8_CoreInterface() noexcept override; void processFrame() override; diff --git a/src/Systems/CHIP8/Cores/CHIP8_MODERN.cpp b/src/Systems/CHIP8/Cores/CHIP8_MODERN.cpp index 301db39..aebf60b 100644 --- a/src/Systems/CHIP8/Cores/CHIP8_MODERN.cpp +++ b/src/Systems/CHIP8/Cores/CHIP8_MODERN.cpp @@ -339,25 +339,25 @@ void CHIP8_MODERN::renderVideoData() { } void CHIP8_MODERN::instruction_8xy5(const s32 X, const s32 Y) noexcept { const bool nborrow{ mRegisterV[X] >= mRegisterV[Y] }; - mRegisterV[X] = mRegisterV[X] - mRegisterV[Y]; - mRegisterV[0xF] = nborrow; + mRegisterV[X] = static_cast(mRegisterV[X] - mRegisterV[Y]); + mRegisterV[0xF] = static_cast(nborrow); } void CHIP8_MODERN::instruction_8xy7(const s32 X, const s32 Y) noexcept { const bool nborrow{ mRegisterV[Y] >= mRegisterV[X] }; - mRegisterV[X] = mRegisterV[Y] - mRegisterV[X]; - mRegisterV[0xF] = nborrow; + mRegisterV[X] = static_cast(mRegisterV[Y] - mRegisterV[X]); + mRegisterV[0xF] = static_cast(nborrow); } void CHIP8_MODERN::instruction_8xy6(const s32 X, const s32 Y) noexcept { if (!Quirk.shiftVX) { mRegisterV[X] = mRegisterV[Y]; } const bool lsb{ (mRegisterV[X] & 1) == 1 }; - mRegisterV[X] = mRegisterV[X] >> 1; - mRegisterV[0xF] = lsb; + mRegisterV[X] = static_cast(mRegisterV[X] >> 1); + mRegisterV[0xF] = static_cast(lsb); } void CHIP8_MODERN::instruction_8xyE(const s32 X, const s32 Y) noexcept { if (!Quirk.shiftVX) { mRegisterV[X] = mRegisterV[Y]; } const bool msb{ (mRegisterV[X] >> 7) == 1 }; - mRegisterV[X] = mRegisterV[X] << 1; - mRegisterV[0xF] = msb; + mRegisterV[X] = static_cast(mRegisterV[X] << 1); + mRegisterV[0xF] = static_cast(msb); } #pragma endregion diff --git a/src/Systems/CHIP8/Cores/MEGACHIP.cpp b/src/Systems/CHIP8/Cores/MEGACHIP.cpp index 3ca2e22..321150d 100644 --- a/src/Systems/CHIP8/Cores/MEGACHIP.cpp +++ b/src/Systems/CHIP8/Cores/MEGACHIP.cpp @@ -29,7 +29,7 @@ MEGACHIP::MEGACHIP() mFramerate = cRefreshRate; prepDisplayArea(Resolution::LO); - setNewBlendAlgorithm(BlendMode::NORMAL); + setNewBlendAlgorithm(BlendMode::ALPHA_BLEND); initializeFontColors(); } } @@ -461,7 +461,7 @@ void MEGACHIP::setNewBlendAlgorithm(const s32 mode) noexcept { break; default: - case BlendMode::NORMAL: + case BlendMode::ALPHA_BLEND: fpBlendAlgorithm = [](const f32 src, const f32) noexcept { return src; }; break; @@ -735,23 +735,23 @@ void MEGACHIP::scrollBuffersRT() { } void MEGACHIP::instruction_8xy5(const s32 X, const s32 Y) noexcept { const bool nborrow{ mRegisterV[X] >= mRegisterV[Y] }; - mRegisterV[X] = mRegisterV[X] - mRegisterV[Y]; - mRegisterV[0xF] = nborrow; + mRegisterV[X] = static_cast(mRegisterV[X] - mRegisterV[Y]); + mRegisterV[0xF] = static_cast(nborrow); } void MEGACHIP::instruction_8xy7(const s32 X, const s32 Y) noexcept { const bool nborrow{ mRegisterV[Y] >= mRegisterV[X] }; - mRegisterV[X] = mRegisterV[Y] - mRegisterV[X]; - mRegisterV[0xF] = nborrow; + mRegisterV[X] = static_cast(mRegisterV[Y] - mRegisterV[X]); + mRegisterV[0xF] = static_cast(nborrow); } void MEGACHIP::instruction_8xy6(const s32 X, const s32 ) noexcept { const bool lsb{ (mRegisterV[X] & 1) == 1 }; - mRegisterV[X] = mRegisterV[X] >> 1; - mRegisterV[0xF] = lsb; + mRegisterV[X] = static_cast(mRegisterV[X] >> 1); + mRegisterV[0xF] = static_cast(lsb); } void MEGACHIP::instruction_8xyE(const s32 X, const s32 ) noexcept { const bool msb{ (mRegisterV[X] >> 7) == 1 }; - mRegisterV[X] = mRegisterV[X] << 1; - mRegisterV[0xF] = msb; + mRegisterV[X] = static_cast(mRegisterV[X] << 1); + mRegisterV[0xF] = static_cast(msb); } #pragma endregion @@ -926,13 +926,13 @@ void MEGACHIP::scrollBuffersRT() { const auto originX{ mRegisterV[X] & 0x78 }; const auto originY{ mRegisterV[Y] & 0x3F }; - mRegisterV[0xF] = 0; + auto collisions{ 0 }; if (N == 0) { for (auto rowN{ 0 }; rowN < 16; ++rowN) { const auto offsetY{ originY + rowN }; - mRegisterV[0xF] += drawSingleBytes( + collisions += drawSingleBytes( originX, offsetY, offsetX ? 24 : 16, (readMemoryI(2 * rowN + 0) << 8 | \ readMemoryI(2 * rowN + 1)) << offsetX @@ -943,13 +943,14 @@ void MEGACHIP::scrollBuffersRT() { for (auto rowN{ 0 }; rowN < N; ++rowN) { const auto offsetY{ originY + rowN }; - mRegisterV[0xF] += drawSingleBytes( + collisions += drawSingleBytes( originX, offsetY, offsetX ? 16 : 8, readMemoryI(rowN) << offsetX ); if (offsetY == 0x3F) { break; } } } + mRegisterV[0xF] = static_cast(collisions); } else { const auto offsetX{ 8 - (mRegisterV[X] * 2 & 7) }; @@ -957,17 +958,18 @@ void MEGACHIP::scrollBuffersRT() { const auto originY{ mRegisterV[Y] * 2 & 0x3F }; const auto lengthN{ N == 0 ? 16 : N }; - mRegisterV[0xF] = 0; + auto collisions{ 0 }; for (auto rowN{ 0 }; rowN < lengthN; ++rowN) { const auto offsetY{ originY + rowN * 2 }; - mRegisterV[0xF] |= drawDoubleBytes( + collisions += drawDoubleBytes( originX, offsetY, offsetX ? 24 : 16, bitBloat(readMemoryI(rowN)) << offsetX ); if (offsetY == 0x3E) { break; } } + mRegisterV[0xF] = static_cast(collisions != 0); } } } diff --git a/src/Systems/CHIP8/Cores/MEGACHIP.hpp b/src/Systems/CHIP8/Cores/MEGACHIP.hpp index d489241..5d32fab 100644 --- a/src/Systems/CHIP8/Cores/MEGACHIP.hpp +++ b/src/Systems/CHIP8/Cores/MEGACHIP.hpp @@ -52,7 +52,7 @@ class MEGACHIP final : public Chip8_CoreInterface { u32 blendPixel(const u32 srcPixel, const u32 dstPixel) const noexcept; enum BlendMode { - NORMAL = 0, + ALPHA_BLEND = 0, LINEAR_DODGE = 4, MULTIPLY = 5, }; diff --git a/src/Systems/CHIP8/Cores/SCHIP_LEGACY.cpp b/src/Systems/CHIP8/Cores/SCHIP_LEGACY.cpp index 8652345..e2c8798 100644 --- a/src/Systems/CHIP8/Cores/SCHIP_LEGACY.cpp +++ b/src/Systems/CHIP8/Cores/SCHIP_LEGACY.cpp @@ -412,23 +412,23 @@ void SCHIP_LEGACY::scrollDisplayRT() { } void SCHIP_LEGACY::instruction_8xy5(const s32 X, const s32 Y) noexcept { const bool nborrow{ mRegisterV[X] >= mRegisterV[Y] }; - mRegisterV[X] = mRegisterV[X] - mRegisterV[Y]; - mRegisterV[0xF] = nborrow; + mRegisterV[X] = static_cast(mRegisterV[X] - mRegisterV[Y]); + mRegisterV[0xF] = static_cast(nborrow); } void SCHIP_LEGACY::instruction_8xy7(const s32 X, const s32 Y) noexcept { const bool nborrow{ mRegisterV[Y] >= mRegisterV[X] }; - mRegisterV[X] = mRegisterV[Y] - mRegisterV[X]; - mRegisterV[0xF] = nborrow; + mRegisterV[X] = static_cast(mRegisterV[Y] - mRegisterV[X]); + mRegisterV[0xF] = static_cast(nborrow); } void SCHIP_LEGACY::instruction_8xy6(const s32 X, const s32 ) noexcept { const bool lsb{ (mRegisterV[X] & 1) == 1 }; - mRegisterV[X] = mRegisterV[X] >> 1; - mRegisterV[0xF] = lsb; + mRegisterV[X] = static_cast(mRegisterV[X] >> 1); + mRegisterV[0xF] = static_cast(lsb); } void SCHIP_LEGACY::instruction_8xyE(const s32 X, const s32 ) noexcept { const bool msb{ (mRegisterV[X] >> 7) == 1 }; - mRegisterV[X] = mRegisterV[X] << 1; - mRegisterV[0xF] = msb; + mRegisterV[X] = static_cast(mRegisterV[X] << 1); + mRegisterV[0xF] = static_cast(msb); } #pragma endregion @@ -537,13 +537,13 @@ void SCHIP_LEGACY::scrollDisplayRT() { const auto originX{ mRegisterV[X] & 0x78 }; const auto originY{ mRegisterV[Y] & 0x3F }; - mRegisterV[0xF] = 0; + auto collisions{ 0 }; if (N == 0) { for (auto rowN{ 0 }; rowN < 16; ++rowN) { const auto offsetY{ originY + rowN }; - mRegisterV[0xF] += drawSingleBytes( + collisions += drawSingleBytes( originX, offsetY, offsetX ? 24 : 16, (readMemoryI(2 * rowN + 0) << 8 | \ readMemoryI(2 * rowN + 1)) << offsetX @@ -554,13 +554,14 @@ void SCHIP_LEGACY::scrollDisplayRT() { for (auto rowN{ 0 }; rowN < N; ++rowN) { const auto offsetY{ originY + rowN }; - mRegisterV[0xF] += drawSingleBytes( + collisions += drawSingleBytes( originX, offsetY, offsetX ? 16 : 8, readMemoryI(rowN) << offsetX ); if (offsetY == 0x3F) { break; } } } + mRegisterV[0xF] = static_cast(collisions); } else { const auto offsetX{ 8 - (mRegisterV[X] * 2 & 7) }; @@ -568,17 +569,19 @@ void SCHIP_LEGACY::scrollDisplayRT() { const auto originY{ mRegisterV[Y] * 2 & 0x3F }; const auto lengthN{ N == 0 ? 16 : N }; - mRegisterV[0xF] = 0; + auto collisions{ 0 }; for (auto rowN{ 0 }; rowN < lengthN; ++rowN) { const auto offsetY{ originY + rowN * 2 }; - mRegisterV[0xF] |= drawDoubleBytes( + collisions += drawDoubleBytes( originX, offsetY, offsetX ? 24 : 16, bitBloat(readMemoryI(rowN)) << offsetX ); + if (offsetY == 0x3E) { break; } } + mRegisterV[0xF] = static_cast(collisions != 0); } } diff --git a/src/Systems/CHIP8/Cores/SCHIP_MODERN.cpp b/src/Systems/CHIP8/Cores/SCHIP_MODERN.cpp index 5de8557..727e739 100644 --- a/src/Systems/CHIP8/Cores/SCHIP_MODERN.cpp +++ b/src/Systems/CHIP8/Cores/SCHIP_MODERN.cpp @@ -418,25 +418,25 @@ void SCHIP_MODERN::scrollDisplayRT() { } void SCHIP_MODERN::instruction_8xy5(const s32 X, const s32 Y) noexcept { const bool nborrow{ mRegisterV[X] >= mRegisterV[Y] }; - mRegisterV[X] = mRegisterV[X] - mRegisterV[Y]; - mRegisterV[0xF] = nborrow; + mRegisterV[X] = static_cast(mRegisterV[X] - mRegisterV[Y]); + mRegisterV[0xF] = static_cast(nborrow); } void SCHIP_MODERN::instruction_8xy7(const s32 X, const s32 Y) noexcept { const bool nborrow{ mRegisterV[Y] >= mRegisterV[X] }; - mRegisterV[X] = mRegisterV[Y] - mRegisterV[X]; - mRegisterV[0xF] = nborrow; + mRegisterV[X] = static_cast(mRegisterV[Y] - mRegisterV[X]); + mRegisterV[0xF] = static_cast(nborrow); } void SCHIP_MODERN::instruction_8xy6(const s32 X, const s32 Y) noexcept { if (!Quirk.shiftVX) { mRegisterV[X] = mRegisterV[Y]; } const bool lsb{ (mRegisterV[X] & 1) == 1 }; - mRegisterV[X] = mRegisterV[X] >> 1; - mRegisterV[0xF] = lsb; + mRegisterV[X] = static_cast(mRegisterV[X] >> 1); + mRegisterV[0xF] = static_cast(lsb); } void SCHIP_MODERN::instruction_8xyE(const s32 X, const s32 Y) noexcept { if (!Quirk.shiftVX) { mRegisterV[X] = mRegisterV[Y]; } const bool msb{ (mRegisterV[X] >> 7) == 1 }; - mRegisterV[X] = mRegisterV[X] << 1; - mRegisterV[0xF] = msb; + mRegisterV[X] = static_cast(mRegisterV[X] << 1); + mRegisterV[0xF] = static_cast(msb); } #pragma endregion diff --git a/src/Systems/CHIP8/Cores/XOCHIP.cpp b/src/Systems/CHIP8/Cores/XOCHIP.cpp index 37310cd..66ad8aa 100644 --- a/src/Systems/CHIP8/Cores/XOCHIP.cpp +++ b/src/Systems/CHIP8/Cores/XOCHIP.cpp @@ -297,10 +297,11 @@ void XOCHIP::renderVideoData() { textureBuffer.end(), [&](u8& pixel) noexcept { const auto idx{ &pixel - textureBuffer.data() }; - pixel = mDisplayBuffer[3].at_raw(idx) << 3 - | mDisplayBuffer[2].at_raw(idx) << 2 - | mDisplayBuffer[1].at_raw(idx) << 1 - | mDisplayBuffer[0].at_raw(idx); + pixel = static_cast( + mDisplayBuffer[3].at_raw(idx) << 3 | + mDisplayBuffer[2].at_raw(idx) << 2 | + mDisplayBuffer[1].at_raw(idx) << 1 | + mDisplayBuffer[0].at_raw(idx)); } ); @@ -549,25 +550,25 @@ void XOCHIP::scrollDisplayRT() { } void XOCHIP::instruction_8xy5(const s32 X, const s32 Y) noexcept { const bool nborrow{ mRegisterV[X] >= mRegisterV[Y] }; - mRegisterV[X] = mRegisterV[X] - mRegisterV[Y]; - mRegisterV[0xF] = nborrow; + mRegisterV[X] = static_cast(mRegisterV[X] - mRegisterV[Y]); + mRegisterV[0xF] = static_cast(nborrow); } void XOCHIP::instruction_8xy7(const s32 X, const s32 Y) noexcept { const bool nborrow{ mRegisterV[Y] >= mRegisterV[X] }; - mRegisterV[X] = mRegisterV[Y] - mRegisterV[X]; - mRegisterV[0xF] = nborrow; + mRegisterV[X] = static_cast(mRegisterV[Y] - mRegisterV[X]); + mRegisterV[0xF] = static_cast(nborrow); } void XOCHIP::instruction_8xy6(const s32 X, const s32 Y) noexcept { if (!Quirk.shiftVX) { mRegisterV[X] = mRegisterV[Y]; } const bool lsb{ (mRegisterV[X] & 1) == 1 }; - mRegisterV[X] = mRegisterV[X] >> 1; - mRegisterV[0xF] = lsb; + mRegisterV[X] = static_cast(mRegisterV[X] >> 1); + mRegisterV[0xF] = static_cast(lsb); } void XOCHIP::instruction_8xyE(const s32 X, const s32 Y) noexcept { if (!Quirk.shiftVX) { mRegisterV[X] = mRegisterV[Y]; } const bool msb{ (mRegisterV[X] >> 7) == 1 }; - mRegisterV[X] = mRegisterV[X] << 1; - mRegisterV[0xF] = msb; + mRegisterV[X] = static_cast(mRegisterV[X] << 1); + mRegisterV[0xF] = static_cast(msb); } #pragma endregion