8x16 Sprites
Page 1 of 1

Author:  Anes [ Sat Mar 19, 2005 9:05 pm ]
Post subject:  8x16 Sprites

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?

Author:  Disch [ Sat Mar 19, 2005 10:30 pm ]
Post subject: 

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

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)

  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)

Author:  Anes [ Sat Mar 19, 2005 10:41 pm ]
Post subject: 

thx disch!!

Author:  Anes [ Sun Mar 20, 2005 9:58 pm ]
Post subject: 

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


Author:  Disch [ Mon Mar 21, 2005 12:03 am ]
Post subject: 

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.

Author:  Anes [ Tue Mar 22, 2005 12:14 pm ]
Post subject: 

thx disch now it works ok :D

Page 1 of 1 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group