PPU OAM: Difference between revisions

From NESdev Wiki
Jump to navigationJump to search
(→‎Byte 1: just in case it wasn't clear)
Line 16: Line 16:
  |||||||+- Bank ($0000 or $1000) of tiles
  |||||||+- Bank ($0000 or $1000) of tiles
  +++++++-- Tile number of top of sprite (0 to 254; bottom half gets the next tile)
  +++++++-- Tile number of top of sprite (0 to 254; bottom half gets the next tile)
Thus, the pattern table memory map for 8x16 sprites looks like this:
*$00: $0000-$001F
*$01: $1000-$101F
*$02: $0020-$003F
*$03: $1020-$103F
*$04: $0040-$005F<br>[...]
*$FE: $0FE0-$0FFF
*$FF: $1FE0-$1FFF
 
=== Byte 2 ===
=== Byte 2 ===
Attributes
Attributes

Revision as of 20:06, 19 March 2010

OAM (Object Attribute Memory) contains a display list of up to 64 sprites, where each sprite's information occupies 4 bytes.

Byte 0

Y position of top of sprite

Sprite data is delayed by one scanline; you must subtract 1 from the sprite's Y coordinate before writing it here. Hide a sprite by writing any values in $EF-$FF here.

Byte 1

Tile index number

For 8x8 sprites, the tile number of this sprite. For 8x16 sprites:

76543210
||||||||
|||||||+- Bank ($0000 or $1000) of tiles
+++++++-- Tile number of top of sprite (0 to 254; bottom half gets the next tile)

Thus, the pattern table memory map for 8x16 sprites looks like this:

  • $00: $0000-$001F
  • $01: $1000-$101F
  • $02: $0020-$003F
  • $03: $1020-$103F
  • $04: $0040-$005F
    [...]
  • $FE: $0FE0-$0FFF
  • $FF: $1FE0-$1FFF

Byte 2

Attributes

76543210
||||||||
||||||++- Palette (4 to 7) of sprite
|||+++--- Unimplemented, reads back as 0
||+------ Priority (0: in front of background; 1: behind background)
|+------- Flip sprite horizontally
+-------- Flip sprite vertically

Byte 3

X position of left side of sprite

X-scroll values of F9-FF do NOT result in the sprite wrapping around to the left side of the screen.

Most programs write to a copy of OAM somewhere in CPU addressable RAM (often $0200-$02FF) and then copy it to OAM each frame using the OAM_DMA ($4014) register.