OAM reverse engineering

Discussion of hardware and software development for Super NES and Super Famicom.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
Post Reply
qwertymodo
Posts: 775
Joined: Mon Jul 02, 2012 7:46 am

OAM reverse engineering

Post by qwertymodo »

I'm working on a ROM hack of A Link to the Past, and one of the sprites is using the wrong palette, so I'm currently trying to backtrace the sprite loading routine in order to find where the palette is being loaded from and fix it. Unfortunately, I'm a bit lost. First of all, what I know.

Here is the NO$SNS OAM view of the sprite in question

Image

It is currently using palette OBP2, the correct palette is OBP4.

I've managed to trace the exact DMA transfer that loads this particular sprite into VRAM

Code: Select all

808bb0 stz $2102     [802102] A:0000 X:0000 Y:0080 S:01f0 D:0000 DB:80 nvmXdIZC V:252 H:  96 F: 2
808bb3 lda #$0400             A:0000 X:0000 Y:0080 S:01f0 D:0000 DB:80 nvmXdIZC V:252 H: 126 F: 2
808bb6 sta $4300     [804300] A:0400 X:0000 Y:0080 S:01f0 D:0000 DB:80 nvmXdIzC V:252 H: 144 F: 2
808bb9 lda #$0800             A:0400 X:0000 Y:0080 S:01f0 D:0000 DB:80 nvmXdIzC V:252 H: 174 F: 2
808bbc sta $4302     [804302] A:0800 X:0000 Y:0080 S:01f0 D:0000 DB:80 nvmXdIzC V:252 H: 192 F: 2
808bbf stz $4304     [804304] A:0800 X:0000 Y:0080 S:01f0 D:0000 DB:80 nvmXdIzC V:252 H: 222 F: 2
808bc2 lda #$0220             A:0800 X:0000 Y:0080 S:01f0 D:0000 DB:80 nvmXdIzC V:252 H: 252 F: 2
808bc5 sta $4305     [804305] A:0220 X:0000 Y:0080 S:01f0 D:0000 DB:80 nvmXdIzC V:252 H: 270 F: 2
808bc8 ldy #$01               A:0220 X:0000 Y:0080 S:01f0 D:0000 DB:80 nvmXdIzC V:252 H: 300 F: 2
808bca sty $420b     [80420b] A:0220 X:0000 Y:0001 S:01f0 D:0000 DB:80 nvmXdIzC V:252 H: 312 F: 2
If I understand this correctly, the OAM buffer is at $000800 (aka $7E0800), and is $220 bytes long, which sounds exactly right for OAM. I don't really understand the OAM Address field in the NO$SNS viewer. It seems to be displaying sprite_index * 2, but aren't OAM entries 4 bytes? So, the shield sprite is at index 0x0F, which would put its data at 0x3C-0x3F in the buffer, right? And the palette should be in the last byte, so I'm looking for the last write to $7E083F before this DMA? Is that correct?
qwertymodo
Posts: 775
Joined: Mon Jul 02, 2012 7:46 am

Re: OAM reverse engineering

Post by qwertymodo »

Looks like I got it right, chalk one up for rubber duck debugging...

Image
Post Reply