Understanding sprite tile flipping

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
DarylTechNES
Posts: 10
Joined: Sun May 10, 2015 5:01 pm

Understanding sprite tile flipping

Post by DarylTechNES »

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: Select all

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: Select all

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: Select all

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: Select all

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.
User avatar
Dwedit
Posts: 4921
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Understanding sprite tile flipping

Post by Dwedit »

You have 'horizontal flipping' and 'vertical flipping' switched in your post.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
User avatar
Zepper
Formerly Fx3
Posts: 3262
Joined: Fri Nov 12, 2004 4:59 pm
Location: Brazil
Contact:

Re: Understanding sprite tile flipping

Post by Zepper »

Code: Select all

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;
Post Reply