Skip to content

Commit

Permalink
Implement sprite priority rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
twvd committed Dec 11, 2023
1 parent 74224ee commit 0fd4269
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
8 changes: 3 additions & 5 deletions src/snes/ppu/bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,10 @@ where
}
// OAMADDH - OAM Address and Priority Rotation (W)
0x2103 => {
self.oam_priority = val & 0x80 != 0;

let v = (self.oamadd.get() >> 1) & 0x00FF;
let val = val & 0x83; // bit 10-14 unused
if val & 0x80 != 0 {
// Obj priority
// TODO
}
let val = val & 0x01;
Some(self.oamadd.set((v | (val as u16) << 8) << 1))
}
// OAMDATA - OAM Data Write (W)
Expand Down
2 changes: 2 additions & 0 deletions src/snes/ppu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ pub struct PPU<TRenderer: Renderer> {
oamadd: Cell<u16>,
oam: [u8; OAM_SIZE],
oam_writebuf: u8,
oam_priority: bool,

inidisp: u8,

Expand Down Expand Up @@ -253,6 +254,7 @@ where
oamadd: Cell::new(0),
oam: [0; OAM_SIZE],
oam_writebuf: 0,
oam_priority: false,

inidisp: 0,

Expand Down
8 changes: 7 additions & 1 deletion src/snes/ppu/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,13 @@ where
}

for idx in 0..OAM_ENTRIES {
let e = self.get_oam_entry(idx);
let prio_idx = if self.oam_priority {
// Priority rotation enabled
(idx + self.oamadd.get() as usize) % OAM_ENTRIES
} else {
idx
};
let e = self.get_oam_entry(prio_idx);

if e.priority != priority {
continue;
Expand Down

0 comments on commit 0fd4269

Please sign in to comment.