how and when to invert sprite virtically ?

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
how and when to invert sprite virtically ?
by on (#21373)
how and when do i invert sprites vertically ? (sprite_attribute & 0x80)

matt

by on (#21375)
When the sprite is evaluated -- the attributes are fetched first to see if they're to be flipped vertically.

The 'normal' CHR is determined by the subtraction of the current scanline and the sprite Y coord (also used to determine whether or not the sprite is in-range). Ex:

Code:
u16 is_in_range = current_scanline - sprite_Y;
if(is_in_range < 8)
{
  // sprite is in range
  //  fetch CHR according to is_in_range
  //  ie:  if is_in_range == 5, CHR comes from $xxx5 and $xxxD
}


To flip vertically -- simply XOR is_in_range with $7 (8x8 sprites) or $F (8x16 sprites) after the sprite is found to be in range.

by on (#21385)
In case anyone misses it, Disch is using a trick of unsigned values in the comparison with 8. These are equivalent:
Code:
unsigned n = current_scanline - sprite_y;
if ( n < 8 )
    ...

int n = current_scanline - sprite_y;
if ( n >= 0 && n < 8 )
    ...

This works because a negative value converted to unsigned becomes a large positive value. It's a good trick to learn.

by on (#21392)
There's a detail which I handle inside the own rendering core: the PPU clipping. So, instead of ">= 0" I use ">= ppu_clip_sprites", 0 or 8.

by on (#21409)
I think you're mixing up sprite clipping with in-range evaluations.

by on (#21414)
I guess so... :lol:
Anyway, thanks for the unsigned tip.