Skip to content

Commit

Permalink
Handle screenover in mode 7
Browse files Browse the repository at this point in the history
  • Loading branch information
twvd committed Dec 9, 2023
1 parent 0be34e1 commit 6b33c97
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/snes/ppu/render_m7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
13 changes: 13 additions & 0 deletions src/test/peterlemon_ppu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);

0 comments on commit 6b33c97

Please sign in to comment.