8x16 Sprites

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
User avatar
Anes
Posts: 703
Joined: Tue Dec 21, 2004 8:35 pm
Location: Mendoza, Argentina

8x16 Sprites

Post by Anes »

I really dont know how exactly memory is arranged in 8x16 sprites. I mean i know when to use ppu addr 0x0000 and 0x1000 but i have tested displaying sprites as the sprite Y as a whole two diferent chunk of 16 bytes, one for bit 0 and the other for bit 1.
This method didnt worked so i thought it was like the top half of the sprites was 0..7 and 16...23 and the lower half 8...15 and 24..31:

The second method worked a little, some sprites in Castlevania (player) looks fine, but for example the items dont show correctly.

im making the emulator scan line based so to obtain FineY for sprites i do:
SLNumber - Sprite.Y.

All this work for ok for 8x8 sprites, and i have emulated hflip and vflip too
but i cant find the problem in 8x16.

I know maybe i should put some code here, so it were easier to help me, but its a little large.

Any Suggestions?
ANes
User avatar
Disch
Posts: 1848
Joined: Wed Nov 10, 2004 6:47 pm

Post by Disch »

If you're a C/C++ guy, here's some pseudo-code to give the idea:

Code: Select all

tempY = (BYTE)(scanline - sprite_y);
if(temp < 16)  // sprite is in range
{
  if( Vertical_Flip_Flag_On )
    tempY ^= 0xF;

  tile_to_use = sprite_tile & 0xFE;
  if(tempY & 8)
    tile_to_use++;

  tempY &= 7;

  //draw line tempY using tile_to_use here
  // pattern table determined by (sprite_tile & 0x01)
}
For that in English:

The tile number to draw is the tile number in Sprite RAM with the low bit chopped off (since the low bit determines which pattern table to use). If you're drawing the lower half of the sprite (line 8+), you simply use the next tile in the pattern table.

The top half of an 8x16 sprite will always draw an even numbered tile.
The bottom half of an 8x16 sprite will always draw an odd numbered tile.

(Reverse those for a v-flipped sprite, since the bottom would be drawn on top)
User avatar
Anes
Posts: 703
Joined: Tue Dec 21, 2004 8:35 pm
Location: Mendoza, Argentina

Post by Anes »

thx disch!!
ANes
User avatar
Anes
Posts: 703
Joined: Tue Dec 21, 2004 8:35 pm
Location: Mendoza, Argentina

Post by Anes »

Dish i asking you again cos i cant make it to work. Could you explain it me in detail?

Thanks
ANes
User avatar
Disch
Posts: 1848
Joined: Wed Nov 10, 2004 6:47 pm

Post by Disch »

8x16 sprites draw from two tiles. Tile "A" is drawn on top... and tile "B" is drawn on bottom.

The tile numbers for each tile are found through the sprite's tile ID number in Sprite RAM (hereon "ID").

The tile to use when drawing tile A is: (ID & 0xFE)
The tile to use when drawing tile B is: (ID & 0xFE) + 1 -or- (ID | 0x01)

The pattern table to use (ppu $0000 or $1000) is determined by (ID & 0x01). Bit 3 of $2000 does not matter when using 8x16 sprites.


Vertically flipping works as expected -- tile B is drawn on top of tile A, and both tiles are flipped vertically.
User avatar
Anes
Posts: 703
Joined: Tue Dec 21, 2004 8:35 pm
Location: Mendoza, Argentina

Post by Anes »

thx disch now it works ok :D
ANes
Post Reply