Changing the sprite height during rendering

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

Post Reply
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Changing the sprite height during rendering

Post by tokumaru »

Quick question: does anyone know for sure what happens if you change the sprite size during HBlank?

I'd imagine that since they were evaluated through the whole scanline with a certain height, the following scanline would show the sprites as if they had the previous height, but from the next scanline on, they'd be displayed according to the new setting.

That is, if a mid-frame $2000 write takes effect immediately. Has anyone ever tried this?
User avatar
blargg
Posts: 3717
Joined: Mon Sep 27, 2004 8:33 am
Location: Central Texas, USA
Contact:

Post by blargg »

I just set up a test that put 8 sprites in a horizontal row in the middle of the screen, then changed height from 8x16 to 8x8 at various points during their rendering. As the change moved later and later, it took effect on the sprites from left to right, so it can be changed mid-scanline and affect only some sprites from that line. I set up a second test that did the same, then changed the size back to 8x16 a couple of scanlines later. The sprites appeared with a couple of rows missing, and again slowly changing from left to right as the change time moved forward. When I changed the test to start with 8x8, then change to 8x16 then 8x8 a couple of lines later, there were glitches to the right of the sprites during the change as the time passed through them.

So, I'd say you can change it during H-blank just fine.
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Post by tokumaru »

Thanks for testing it out blargg. I haven't had much time near my NES, so I couldn't do this myself.

Now, I just didn't understand one thing:
blargg wrote:When I changed the test to start with 8x8, then change to 8x16 then 8x8 a couple of lines later, there were glitches to the right of the sprites during the change as the time passed through them.
What do you mean "glitches to the right of the sprites"? Since the meaning of the tile index changes depending on the mode, I'd expect some weird patterns whenever that setting is changed. Are you saying something like that?
So, I'd say you can change it during H-blank just fine.
By "fine" you mean "without unexpected glitches"? If I change their height during HBlank, along with the sprite patterns (through MMC3 bankswitching), what I'll see in the next scanline are the sprites that were evaluated using the old height, the old patterns, old everything, right? So, if the patterns were all transparent before, I'd see no sprites at all, but on the next scanline they'd be displayed according to the new parameters. Did I get that right?

EDIT: I'm really not sure about the patterns. I don't know if the sprite patterns are buffered during the evaluation or fetched as they are displayed...
User avatar
blargg
Posts: 3717
Joined: Mon Sep 27, 2004 8:33 am
Location: Central Texas, USA
Contact:

Post by blargg »

Meh, I did another test and could switch height after the first 8 rows of the sprites had been drawn, either from 8 to 16 or 16 to 8, and have it appear properly. I was able to vary the switch time within a window of around +57 to +120 CPU clocks relative to the beginning of the scanline without glitches. So the answer is, yes you can change sprite height mid-frame without glitches.
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Post by tokumaru »

Thanks blargg, I'll give this a shot soon.

Do you (or anyone else who knows about the sprite evaluation process) know exactly when the sprite patterns are fetched? If by any chance they are buffered during the evaluation process or if they are only loaded when they are displayed?
Post Reply