Skip to content

Commit

Permalink
Fix: OAMADDx address is a word address, not a byte address
Browse files Browse the repository at this point in the history
  • Loading branch information
twvd committed Dec 9, 2023
1 parent 656a7ce commit 131685b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/snes/ppu/bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,18 @@ where
0x2101 => Some(self.obsel = val),
// OAMADDL - OAM Address and Priority Rotation (W)
0x2102 => {
let v = self.oamadd.get() & 0xFF00;
Some(self.oamadd.set(v | val as u16))
let v = (self.oamadd.get() >> 1) & 0xFF00;
Some(self.oamadd.set((v | val as u16) << 1))
}
// OAMADDH - OAM Address and Priority Rotation (W)
0x2103 => {
let v = self.oamadd.get() & 0x00FF;
let v = (self.oamadd.get() >> 1) & 0x00FF;
let val = val & 0x83; // bit 10-14 unused
if val & 0x80 != 0 {
// Obj priority
// TODO
}
Some(self.oamadd.set(v | (val as u16) << 8))
Some(self.oamadd.set((v | (val as u16) << 8) << 1))
}
// OAMDATA - OAM Data Write (W)
0x2104 => {
Expand Down
15 changes: 8 additions & 7 deletions src/snes/ppu/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ fn oam_write_seq() {
assert_eq!(p.oam[0..5], [0xAA, 0xBB, 0xCC, 0xDD, 0]);

// Test end of OAM towards the 32 byte extension table
p.write(0x2102, (510 & 0xFF) as u8);
p.write(0x2103, (510 >> 8) as u8);
p.write(0x2102, ((510 >> 1) & 0xFF) as u8);
p.write(0x2103, ((510 >> 1) >> 8) as u8);
assert_eq!(p.oam[510..513], [0, 0, 0]);
p.write(0x2104, 0xAA);
assert_eq!(p.oam[510..513], [0, 0, 0]);
Expand All @@ -216,8 +216,8 @@ fn oam_write_seq() {
fn oam_write_exttable() {
let mut p = ppu();
assert_eq!(p.oam[512], 0);
p.write(0x2102, (512 & 0xFF) as u8);
p.write(0x2103, (512 >> 8) as u8);
p.write(0x2102, ((512 >> 1) & 0xFF) as u8);
p.write(0x2103, ((512 >> 1) >> 8) as u8);
p.write(0x2104, 0xAA);
assert_eq!(p.oam[512], 0xAA);
}
Expand All @@ -226,8 +226,8 @@ fn oam_write_exttable() {
fn oam_write_exttable_mirror() {
let mut p = ppu();
assert_eq!(p.oam[512], 0);
p.write(0x2102, (0x220 & 0xFF) as u8);
p.write(0x2103, (0x220 >> 8) as u8);
p.write(0x2102, (0x120 & 0xFF) as u8);
p.write(0x2103, (0x120 >> 8) as u8);
p.write(0x2104, 0xAA);
assert_eq!(p.oam[512], 0xAA);
}
Expand All @@ -250,8 +250,9 @@ fn oam_read() {
p.oam[3] = 1;
p.oam[4] = 2;
p.oam[5] = 3;
p.write(0x2102, 3);
p.write(0x2102, 3 >> 1);
p.write(0x2103, 0);
assert_eq!(p.read(0x2138), Some(0));
assert_eq!(p.read(0x2138), Some(1));
assert_eq!(p.read(0x2138), Some(2));
assert_eq!(p.read(0x2138), Some(3));
Expand Down

0 comments on commit 131685b

Please sign in to comment.