From 298af90a9daa258c44b68c7c40c817da6f129dd5 Mon Sep 17 00:00:00 2001 From: leonmavr <0xleo.git@gmail.com> Date: Tue, 20 Aug 2024 19:41:32 +0200 Subject: [PATCH] Quirks: implement screen clipping if off --- src/chip8.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/chip8.cpp b/src/chip8.cpp index 7ea1095..592960d 100644 --- a/src/chip8.cpp +++ b/src/chip8.cpp @@ -313,11 +313,20 @@ void Chip8::Exec(const opcode_t& opc) { Vf = 0; \ for (uint8_t row = 0; row < n; row++) { \ uint8_t sprite = ram_[I + row]; \ + size_t index = 0; \ + bool quirk_clipped = false; \ for (uint8_t col = 0; col < 8; col++) { \ if ((sprite & 0x80) != 0) { \ - size_t x = (x0 + col) % COLS; \ - size_t y = (y0 + row) % ROWS; \ - size_t index = y * COLS + x; \ + size_t x = x0 + col; \ + size_t y = y0 + row; \ + if (use_quirks_) { \ + size_t x = x % COLS; \ + size_t y = y % ROWS; \ + } \ + quirk_clipped = (x >= COLS) || \ + (y >= ROWS); \ + if (quirk_clipped) continue; \ + index = y * COLS + x; \ if (frame_buffer_[index] == 1) \ Vf = 1; \ frame_buffer_[index] ^= 1; \