Understanding sprite tile flipping

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Understanding sprite tile flipping
by on (#177858)
I'm having issues figuring out how to handle tile flipping (byte 2 of sprite OAM memory).

Consider if the bit is set to flip a sprite horizontally and its an 8x8 tile at 0,0 that looks like this (for simplicity):

Code:
a 0 0 0 0 0 0 b
e 0 0 0 0 0 0 f
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
c 0 0 0 0 0 0 d


Would a horizontal flip result in this? My rationale is that it flips in the middle, on a "horizon" as the pivot point.

Code:
c 0 0 0 0 0 0 d
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
e 0 0 0 0 0 0 f
a 0 0 0 0 0 0 b


For a vertical flip, same idea:

(Original)
Code:
a 0 0 0 0 0 0 b
e 0 0 0 0 0 0 f
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
c 0 0 0 0 0 0 d



(Vertical flip bit set)
Code:
b 0 0 0 0 0 0 a
f 0 0 0 0 0 0 e
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
d 0 0 0 0 0 0 c


Does any of this look right? Its rendering terribly in my emulator so I'm guessing I'm not interpreting this correctly.
Re: Understanding sprite tile flipping
by on (#177859)
You have 'horizontal flipping' and 'vertical flipping' switched in your post.
Re: Understanding sprite tile flipping
by on (#177861)
Code:
unsigned int vsize = (ppu_2000 & 0x20)? 0x0F: 0x07;

         /* attributes */
         attrib = sprites[2];
         /* horizontal position +flip
          */
         if(attrib & 0x40)
            xcomp ^= 7;

         /* vertical position +flip
          */
         drawline = (current_scanline - 22 - sprites[0]) & 0x0F;
         if(attrib & 0x80)
            drawline ^= vsize;