From 6b33c97881d67cf0318ab0bfd9a1802219feb339 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 9 Dec 2023 06:22:45 +0100 Subject: [PATCH] Handle screenover in mode 7 --- src/snes/ppu/render_m7.rs | 20 ++++++++++++++++++-- src/test/peterlemon_ppu.rs | 13 +++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/snes/ppu/render_m7.rs b/src/snes/ppu/render_m7.rs index a768af6..61a0fd2 100644 --- a/src/snes/ppu/render_m7.rs +++ b/src/snes/ppu/render_m7.rs @@ -7,8 +7,24 @@ where TRenderer: Renderer, { fn mode7_vram_to_color(&self, vram_x: i32, vram_y: i32) -> u8 { - let tile_x = ((vram_x as u32 >> 11) & 0x7f) as u16; - let tile_y = ((vram_y as u32 >> 11) & 0x7f) as u16; + let screenover = (self.m7sel >> 6) & 0x03; + let overflow = (vram_x >> 18) | (vram_y >> 18) != 0; + + if overflow && (screenover == 2) { + // Overflow -> transparent + return 0; + } + + let (tile_x, tile_y) = if overflow && (screenover == 3) { + // Overflow -> Tile 0 + (0, 0) + } else { + // Overflow -> Wrap + ( + ((vram_x as u32 >> 11) & 0x7f) as u16, + ((vram_y as u32 >> 11) & 0x7f) as u16, + ) + }; let pixel_x = ((vram_x >> 8) & 0x07) as u16; let pixel_y = ((vram_y >> 8) & 0x07) as u16; diff --git a/src/test/peterlemon_ppu.rs b/src/test/peterlemon_ppu.rs index c65def1..776232c 100644 --- a/src/test/peterlemon_ppu.rs +++ b/src/test/peterlemon_ppu.rs @@ -98,3 +98,16 @@ ppu_test!( "Window/WindowMultiHDMA/WindowMultiHDMA.sfc", "688de105142b1b28b1c0bb0473e518f1beada64623c9352e58f71341da1dbf19" ); + +// Mode 7 tests +ppu_test!( + Mode7RotZoom, + "Mode7/RotZoom/RotZoom.sfc", + "4235ddbbc79e0a5f3f2ebe075eb23e328a63a8ba0de6949d320747668790ab91" +); +ppu_test!( + // Tests screenover (transoarent) + Mode7Perspective, + "Mode7/Perspective/Perspective.sfc", + "48993ffece6707ea3c64ad4a9c3096ec81215fd5dda1f9a5aaff18ee31e6c616" +);