Skip to content

Commit

Permalink
Corrected OAM scan timing issue. Pixels now generated at the end of O…
Browse files Browse the repository at this point in the history
…AM scan mode
  • Loading branch information
TylerBloom committed Oct 28, 2024
1 parent a6acd9c commit b0e93b3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
11 changes: 8 additions & 3 deletions spirit/src/mem/vram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ use serde_with::serde_as;
use tracing::{info, trace};

use super::{
io::{BgPaletteIndex, ObjPaletteIndex}, BgTileDataIndex, BgTileDataInnerIndex, BgTileMapAttrIndex, BgTileMapAttrInnerIndex, BgTileMapIndex, BgTileMapInnerIndex, OamObjectIndex, ObjTileDataIndex
io::{BgPaletteIndex, ObjPaletteIndex},
BgTileDataIndex, BgTileDataInnerIndex, BgTileMapAttrIndex, BgTileMapAttrInnerIndex,
BgTileMapIndex, BgTileMapInnerIndex, OamObjectIndex, ObjTileDataIndex,
};

static DEAD_READ_ONLY_BYTE: u8 = 0xFF;
Expand Down Expand Up @@ -175,7 +177,7 @@ impl Index<(ObjTileDataIndex, bool)> for VRam {
(ObjTileDataIndex(index, bank), size): (ObjTileDataIndex, bool),
) -> &Self::Output {
let bank = if bank { &self.vram[1] } else { &self.vram[0] };
let start = 16 * (index & (!(size as u8))) as usize;
let start = 16 * (if size { index & !0b1 } else { index } as usize);
let end = start + 16 + if size { 16 } else { 0 };
&bank[start..end]
}
Expand All @@ -198,7 +200,10 @@ impl Index<BgTileMapInnerIndex> for VRam {
impl Index<BgTileMapAttrInnerIndex> for VRam {
type Output = u8;

fn index(&self, BgTileMapAttrInnerIndex { x, y, second_map }: BgTileMapAttrInnerIndex) -> &Self::Output {
fn index(
&self,
BgTileMapAttrInnerIndex { x, y, second_map }: BgTileMapAttrInnerIndex,
) -> &Self::Output {
let x = x as usize / 8;
let y = y as usize / 8;
let index = 0x1800 + (second_map as usize * 0x400) + (y * 32) + x;
Expand Down
15 changes: 6 additions & 9 deletions spirit/src/ppu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,8 @@ impl PpuInner {
match self {
PpuInner::OamScan { dots } if *dots == 79 => {
*self = Self::Drawing { dots: 0 };
mem.inc_ppu_status(self.state());
}
PpuInner::OamScan { dots } if *dots == 0 => {
obj.oam_scan(bg.y, mem);
*dots += 1;
mem.inc_ppu_status(self.state());
}
PpuInner::OamScan { dots } => *dots += 1,
PpuInner::Drawing { dots, .. } if bg.x == 160 => {
Expand Down Expand Up @@ -648,11 +645,11 @@ impl OamObject {
);
let mut index = y - self.y;
if check_bit_const::<6>(self.attrs) {
// If vertically flipped, we need to reverse the order of the bytes in the obj. Or, we
// need to invert our indices. We know that `index` is between 0 and 8 (or 16), so we
// can just mask out the upper half of the inverted index to bring it back into range.
let mask = if obj.len() == 32 { 0xF } else { 0x7 };
index = (!index) & mask;
index = if obj.len() == 32 {
15 - index
} else {
7 - index
};
}
let index = index as usize;
let lo = obj[2 * index];
Expand Down

0 comments on commit b0e93b3

Please sign in to comment.