gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Hardware > REG_VCOUNT different on hardware?

#40453 - Ultima2876 - Mon Apr 18, 2005 11:44 pm

I've got a problem with my hblank routine. I'm trying to tilt a sprite like this:

http://img39.echo.cx/img39/9305/11tn.jpg

It works absolutely fine in emulators. But when I try it on hardware, it does this:

http://img39.echo.cx/img39/9711/23zn.jpg

It uses the REG_VCOUNT register to apply some pre-calculated settings to the scanline in question, using this code (in the hblank):

Code:
CODE_IN_IWRAM void hblank_tilt(void)
   {
      ((u16*)0x070003E2)[0] = hsetting[REG_VCOUNT];
      ((u16*)0x070003EA)[0] = hsetting1[REG_VCOUNT];
      ((u16*)0x070003F2)[0] = hsetting2[REG_VCOUNT];
   }


To reproduce the problem so that it happened on emulator (and subsequently fixed it on hardware), I did this:

Code:
CODE_IN_IWRAM void hblank_tilt(void)
   {
      ((u16*)0x070003E2)[0] = hsetting[REG_VCOUNT - 1];
      ((u16*)0x070003EA)[0] = hsetting1[REG_VCOUNT - 1];
      ((u16*)0x070003F2)[0] = hsetting2[REG_VCOUNT - 1];
   }


Is REG_VCOUNT different on hardware or something? or could it be something else (emulator bug of some kind)? As you can see, there's no other sprites on those scanlines, so I highly doubt its a speed issue.

It does this in Boycott Advance, VisualBoy Advance and No$GBA...

And now for another related question - how could I fix this so that it looks right both on hardware and emulator? I've tried using various little "hacks" to make the game detect whether its running on emulator, but these don't work for all emulators (the main problematic one being VBA 1.8.0 Beta, which seems to have fixed all of these emulation "gaps"). So surely there's some small thing I'm missing?

More code is available if needed.

Thanks very much to anyone who can help.

#40458 - DekuTree64 - Tue Apr 19, 2005 12:45 am

Err, this may sound dumb, but I can't tell the difference in the screens. Is it something on the main rocket sprite, or on the HUD?

Either way, the problem is that HBlank happens at the END of each scanline, so your values will be off by 1 unless you compensate for it, by subtracting 1 from VCOUNT like you did. I thought sure VBA properly emulated that though...

Also you should be aware that when using HBlank effects, the first scanline will draw before any interrupt happens. Unless you set the first line's value sometime during VBlank, it will be left as whatever it was on the last line from the previous frame. (EDIT: Just to clarify, I don't think you need to worry about this for this particular case, just thought I'd mention it for future reference)
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#40461 - tepples - Tue Apr 19, 2005 1:14 am

The compression of the JPEG screenshot made it hard for me to see what you were talking about; please use PNG next time.

Anyway, most games that use an effect similar to what you're trying to create don't tilt their sprites at runtime, instead preferring pre-tilted sprite cels.

One thing to watch out for is that sprite generator hardware often read OAM one scanline early so that they can find what sprites will be visible on the next scanline and set up their pixel pipelines accordingly. You might try making mental analogies to another Nintendo-designed sprite generator which has been reverse-engineered in detail; see "Sprite Evaluation" on this page.

In the end, if you can't get the program to run the same on both VBA and hardware, then put a humorous note in the documentation stating that copy protection features will degrade the image if you play on an emulator.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#40506 - Ultima2876 - Tue Apr 19, 2005 4:51 pm

Thanks for the replies, looks like there isn't much I can do.

In case you're still wondering, the sprite in question is attached to the bottom of the HUD, at the top left of the "game screen". If you look closely, the correctly tilted sprite has crosses in it, and in the wrongly tilted sprite the cross jsut look like 3 lines.

#40509 - ampz - Tue Apr 19, 2005 5:20 pm

Ultima2876 wrote:
Thanks for the replies, looks like there isn't much I can do.

In case you're still wondering, the sprite in question is attached to the bottom of the HUD, at the top left of the "game screen". If you look closely, the correctly tilted sprite has crosses in it, and in the wrongly tilted sprite the cross jsut look like 3 lines.

I can't make out any lines. Please use png when posting screenshots.