8x16 Sprites

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
8x16 Sprites
by on (#1614)
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?

by on (#1616)
If you're a C/C++ guy, here's some pseudo-code to give the idea:

Code:
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)

by on (#1617)
thx disch!!

by on (#1634)
Dish i asking you again cos i cant make it to work. Could you explain it me in detail?

Thanks

by on (#1635)
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.

by on (#1653)
thx disch now it works ok :D