diff --git a/Makefile b/Makefile index 2225045..27f433f 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ all: build reset: - powershell -executionpolicy bypass .\scripts\reset_build.ps1 + powershell cutionpolicy bypass .\scripts\reset_build.ps1 build: meson compile -j 4 -C builddir @@ -15,13 +15,13 @@ debug_build: meson compile -j 4 -C builddir run: build - ./builddir/b8rk.exe 1 120 ./roms/pong.ch8 + ./builddir/b8rk 1 120 ./roms/pong.ch8 debug: build - gdb --nx -x .gdbinit --ex run --args builddir/runtests.exe + gdb --nx -x .gdbinit --ex run --args builddir/runtests debug_run: build - gdb --nx -x .gdbinit --batch --ex run --ex bt --ex q --args builddir/b8rk.exe 1 120 ./roms/pong.ch8 + gdb --nx -x .gdbinit --batch --ex run --ex bt --ex q --args builddir/b8rk 1 120 ./roms/pong.ch8 clean: meson compile --clean -C builddir diff --git a/src/chip8.cpp b/src/chip8.cpp index 3490baf..68cdc3a 100644 --- a/src/chip8.cpp +++ b/src/chip8.cpp @@ -283,9 +283,8 @@ void Chip8::OP_Dxyn() { uint8_t Vy = (opcode & 0x00F0u) >> 4u; uint8_t height = opcode & 0x00Fu; - // wrap if going beyond the screen boundaries - uint8_t xPos = registers[Vx] % CHIP8_WIDTH; - uint8_t yPos = registers[Vy] % CHIP8_HEIGHT; + uint8_t xPos = registers[Vx]; + uint8_t yPos = registers[Vy]; registers[0xF] = 0; @@ -295,7 +294,11 @@ void Chip8::OP_Dxyn() { for(size_t col = 0; col < 8; ++col) { uint8_t spritePixel = spriteByte & (0x80u >> col); - size_t pixel_at = (yPos + row) * CHIP8_WIDTH + (xPos + col); + // wrap if going beyond the screen boundaries + size_t draw_row = (yPos + row) % CHIP8_HEIGHT; + size_t draw_col = (xPos + col) % CHIP8_WIDTH; + + size_t pixel_at = draw_row * CHIP8_WIDTH + draw_col; uint32_t* screenPixel = &video[pixel_at];