From 233fae545aff4f17389a1c62c7c93dff2b0910a9 Mon Sep 17 00:00:00 2001 From: Matthew Pomes Date: Wed, 8 Apr 2026 22:47:41 -0500 Subject: [PATCH] Fix large sprites --- src/ppu.rs | 71 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 26 deletions(-) diff --git a/src/ppu.rs b/src/ppu.rs index 08ee485..10c1dc7 100644 --- a/src/ppu.rs +++ b/src/ppu.rs @@ -164,7 +164,7 @@ impl OAM { OamState::ReadY => { let l = self.oam_read_buffer as usize; if self.count < 8 { - if l <= line && line < l + 8 { + if l <= line && line < l + if self.large_sprites { 16 } else { 8 } { self.secondary[self.count as usize * 4] = self.oam_read_buffer; self.state = OamState::ReadTile; } else { @@ -214,36 +214,55 @@ impl OAM { } else if run % 8 == 3 { self.sprite_output_units[run / 8].x_pos = self.secondary[(run / 8) * 4 + 3]; } else if run % 8 == 4 { - } else if run % 8 == 5 { - let off = line - self.sprite_output_units[run / 8].y_pos as usize; - let off = if self.sprite_output_units[run / 8].attrs.vflip() { - 7 - off - } else { - off - }; - let addr = if self.sprite_offset_0x1000 { - 0x1000 - } else { - 0x0000 - } + 16 * self.sprite_output_units[run / 8].tile as u16 - + off as u16; - self.sprite_output_units[run / 8].low = mem.read(addr).reg_map(|_, _| todo!()); + // } else if run % 8 == 5 { + // let off = line - self.sprite_output_units[run / 8].y_pos as usize; + // let off = if self.sprite_output_units[run / 8].attrs.vflip() { + // 7 - off + // } else { + // off + // }; + // let addr = if self.sprite_offset_0x1000 { + // 0x1000 + // } else { + // 0x0000 + // } + 16 * self.sprite_output_units[run / 8].tile as u16 + // + off as u16; + // self.sprite_output_units[run / 8].low = mem.read(addr).reg_map(|_, _| todo!()); } else if run % 8 == 6 { - } else if run % 8 == 7 { + } else if run % 8 == 5 || run % 8 == 7 { let off = line - self.sprite_output_units[run / 8].y_pos as usize; - let off = if self.sprite_output_units[run / 8].attrs.vflip() { - 7 - off + let addr = if self.large_sprites { + let off = if self.sprite_output_units[run / 8].attrs.vflip() { + 15 - off + } else { + off + }; + (if self.sprite_output_units[run / 8].tile & 1 == 1 { + 0x1000 + } else { + 0x0000 + } + 16 * (self.sprite_output_units[run / 8].tile & !1) as u16 + + off as u16 + if off > 7 { 8 } else { 0 }) } else { - off + let off = if self.sprite_output_units[run / 8].attrs.vflip() { + 7 - off + } else { + off + }; + (if self.sprite_offset_0x1000 { + 0x1000 + } else { + 0x0000 + } + 16 * self.sprite_output_units[run / 8].tile as u16 + + off as u16) }; - let addr = if self.sprite_offset_0x1000 { - 0x1000 + if run % 8 == 5 { + self.sprite_output_units[run / 8].low = + mem.read(addr).reg_map(|_, _| todo!()); } else { - 0x0000 - } + 16 * self.sprite_output_units[run / 8].tile as u16 - + off as u16 - + 8; - self.sprite_output_units[run / 8].high = mem.read(addr).reg_map(|_, _| todo!()); + self.sprite_output_units[run / 8].high = + mem.read(addr + 8).reg_map(|_, _| todo!()); + } } } }