From c5286054ec711bdd17424f29adf20c1eca5b0994 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=A3=CF=84=CE=AD=CF=86=CE=B1=CE=BD=CE=BF=CF=82=20=22Coor?= =?UTF-8?q?nio/8924th=22=20=CE=92=CE=BB=CE=B1=CF=83=CF=84=CF=8C=CF=82?= <8924th@gmail.com> Date: Sun, 15 Sep 2024 18:48:43 +0300 Subject: [PATCH] Fix mistake in SCHIP_MODERN drawing causing incorrect clipping, fix mistake in XOCHIP which would prevent multi-plane sprites from rendering correctly when partially clipped and wrapping was disabled. --- src/Systems/CHIP8/Cores/SCHIP_MODERN.cpp | 12 +++++++----- src/Systems/CHIP8/Cores/XOCHIP.cpp | 18 +++++++++--------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/Systems/CHIP8/Cores/SCHIP_MODERN.cpp b/src/Systems/CHIP8/Cores/SCHIP_MODERN.cpp index 0cceb08..100815a 100644 --- a/src/Systems/CHIP8/Cores/SCHIP_MODERN.cpp +++ b/src/Systems/CHIP8/Cores/SCHIP_MODERN.cpp @@ -16,6 +16,8 @@ SCHIP_MODERN::SCHIP_MODERN() : mDisplayBuffer{ {cScreenSizeY, cScreenSizeX} } { if (getCoreState() != EmuState::FAILED) { + Quirk.shiftVX = true; + Quirk.idxRegNoInc = true; copyGameToMemory(mMemoryBank.data(), cGameLoadPos); copyFontToMemory(mMemoryBank.data(), 0x0, 0xF0); @@ -576,7 +578,7 @@ void SCHIP_MODERN::scrollDisplayRT() { { drawByte(pX + 0, tY, readMemoryI(tN + 0)); drawByte(pX + 8, tY, readMemoryI(tN + 1)); - if (!Quirk.wrapSprite && pY == mDisplayHb) { break; } + if (!Quirk.wrapSprite && tY == mDisplayHb) { break; } else { tN += 2; ++tY &= mDisplayHb; } } break; @@ -586,7 +588,7 @@ void SCHIP_MODERN::scrollDisplayRT() { for (auto tN{ 0 }, tY{ pY }; tN < N;) { drawByte(pX, tY, readMemoryI(tN)); - if (!Quirk.wrapSprite && pY == mDisplayHb) { break; } + if (!Quirk.wrapSprite && tY == mDisplayHb) { break; } else { tN += 1; ++tY &= mDisplayHb; } } break; @@ -627,7 +629,7 @@ void SCHIP_MODERN::scrollDisplayRT() { mSoundTimer = mRegisterV[X] + (mRegisterV[X] == 1); } void SCHIP_MODERN::instruction_Fx1E(const s32 X) noexcept { - mRegisterI = mRegisterI + mRegisterV[X] & 0xFFF; + mRegisterI = mRegisterI + mRegisterV[X] & 0xFFFF; } void SCHIP_MODERN::instruction_Fx29(const s32 X) noexcept { mRegisterI = (mRegisterV[X] & 0xF) * 5; @@ -644,13 +646,13 @@ void SCHIP_MODERN::scrollDisplayRT() { for (auto idx{ 0 }; idx <= N; ++idx) { writeMemoryI(mRegisterV[idx], idx); } if (!Quirk.idxRegNoInc) [[likely]] - { mRegisterI = mRegisterI + N + 1 & 0xFFF; } + { mRegisterI = mRegisterI + N + 1 & 0xFFFF; } } void SCHIP_MODERN::instruction_FN65(const s32 N) noexcept { for (auto idx{ 0 }; idx <= N; ++idx) { mRegisterV[idx] = readMemoryI(idx); } if (!Quirk.idxRegNoInc) [[likely]] - { mRegisterI = mRegisterI + N + 1 & 0xFFF; } + { mRegisterI = mRegisterI + N + 1 & 0xFFFF; } } void SCHIP_MODERN::instruction_FN75(const s32 N) noexcept { if (setPermaRegs(N + 1)) [[unlikely]] diff --git a/src/Systems/CHIP8/Cores/XOCHIP.cpp b/src/Systems/CHIP8/Cores/XOCHIP.cpp index bc5d87e..c3593d6 100644 --- a/src/Systems/CHIP8/Cores/XOCHIP.cpp +++ b/src/Systems/CHIP8/Cores/XOCHIP.cpp @@ -683,24 +683,24 @@ void XOCHIP::scrollDisplayRT() { mRegisterV[0xF] = 0; if (N == 0) { - for (auto P{ 0 }, I{ 0 }; P < 4; ++P) { + for (auto P{ 0 }, I{ 0 }; P < 4; ++P, I += 32) { if (!(mPlanarMask & 1 << P)) { continue; } - for (auto tN{ 0 }, tY{ pY }; tN < 16; ++tN) { - drawByte(pX + 0, tY, P, readMemoryI(I + 0)); - drawByte(pX + 8, tY, P, readMemoryI(I + 1)); + for (auto tN{ 0 }, tY{ pY }; tN < 32;) { + drawByte(pX + 0, tY, P, readMemoryI(I + tN + 0)); + drawByte(pX + 8, tY, P, readMemoryI(I + tN + 1)); if (!Quirk.wrapSprite && tY == mDisplayHb) { break; } - else { I += 2; ++tY &= mDisplayHb; } + else { tN += 2; ++tY &= mDisplayHb; } } } } else [[likely]] { - for (auto P{ 0 }, I{ 0 }; P < 4; ++P) { + for (auto P{ 0 }, I{ 0 }; P < 4; ++P, I += N) { if (!(mPlanarMask & 1 << P)) { continue; } - for (auto tN{ 0 }, tY{ pY }; tN < N; ++tN) { - drawByte(pX, tY, P, readMemoryI(I)); + for (auto tN{ 0 }, tY{ pY }; tN < N;) { + drawByte(pX, tY, P, readMemoryI(I + tN)); if (!Quirk.wrapSprite && tY == mDisplayHb) { break; } - else { I += 1; ++tY &= mDisplayHb; } + else { tN += 1; ++tY &= mDisplayHb; } } } }