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.

DS Misc > My background is moving. (Solved)

#142648 - HyperHacker - Thu Oct 11, 2007 5:22 am

In HBlank, I do this to create an 8-scanline gradient behing BG0, by hiding BG3 and adjusting the background colour:
Code:
void HBlankInterrupt()
{
   s32 Line;
   static bool BG3On = true;

   //Highlight selected menu option if enabled.
   if(HighlightSelOption && (HighlightLine >= 0))
   {
      Line = REG_VCOUNT - (HighlightLine - 1);
      if((!Line) && BG3On)
      {
         videoSetMode(MODE_5_2D | DISPLAY_BG0_ACTIVE);
         BG3On = false;
      }

      if((Line >= 0) && (Line < 8))
         BG_PALETTE[0] = SelOptionBG[(Line + HighlightAnim) & 7];
      else if((Line >= 8) && !BG3On)
      {
         videoSetMode(MODE_5_2D | DISPLAY_BG0_ACTIVE | DISPLAY_BG3_ACTIVE);
         BG3On = true;
      }
   }
}
BG0 has a text layer and BG3 has a 16-bit bitmap. When I do this, as I adjust HighlightLine to move the effect up and down the screen, the image on BG3 actually jumps up and down. It looks like instead of skipping 8 lines of BG3 when it's turned off, it actually moves the remaining portion down 8 lines. Is this normal? Is there a better way to hide BG3 so that the background colour can be seen through it?

Also, when I do this, about 8 pixels of the very top scanline become one of these colours too. Why is that? It looks like for some reason BG3 is off while these are drawn, so the last set background colour (that of the bottom scanline from the effect) is shown. I don't touch the backgrounds in VBlank though, and this is all HBlank is doing, and the effect doesn't reach anywhere near the bottom of the screen.

[edit] Yep, that's what it's doing alright. If I don't turn BG3 on until halfway down the screen, then the top half, not the bottom, gets shown. What the heck? It's not getting squished either, just 8 pixels are getting cut off the bottom.

What's even stranger is it looks like the gradient actually takes up about 10 scanlines. O_o
_________________
I'm a PSP hacker now, but I still <3 DS.


Last edited by HyperHacker on Fri Oct 12, 2007 3:44 am; edited 1 time in total

#142649 - DekuTree64 - Thu Oct 11, 2007 6:02 am

Some things to be aware of:

1. HBlank happens at the END of a line. So a lot of times you have to set up the first line during VBlank.

2. On GBA, it would take a few scanlines to turn on a BG layer, so you had to use tricks like setting it to display a blank screen map instead of turning it off entirely. Haven't tested if this still happens on DS.

3. Rotate/scale layers (this includes bitmaps) use accumulators for the current source position, and if you change the position registers, it sets the value of the accumulator, and that is the next pixel it fetches. Text BGs just fetch from screen position + scroll, so changing their scroll registers has a more intuitive effect. So on a rot/scale, if you're 20 lines down the screen, you'll probably want to set the Y position to 20, rather than 0.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#142651 - HyperHacker - Thu Oct 11, 2007 6:09 am

#1 shouldn't be an issue, since this effect will always be at least 16 lines from the top and 32 from the bottom of the screen. #2 sounds like something that might be worth trying, but can I do it without using up more VRAM? For #3, you're saying it's normal behaviour and I should just tweak the layer's Y position after toggling it and restore it in VBlank?

I never coded on the GBA, so I don't know a whole lot about the video system.
_________________
I'm a PSP hacker now, but I still <3 DS.

#142653 - DekuTree64 - Thu Oct 11, 2007 7:14 am

HyperHacker wrote:
#2 sounds like something that might be worth trying, but can I do it without using up more VRAM?

For a text layer, no. But since it's a bitmap layer that you're hiding, you could set it to not wrap around, and then scroll it offscreen.

Quote:
For #3, you're saying it's normal behaviour and I should just tweak the layer's Y position after toggling it and restore it in VBlank?

Yep
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#142691 - knight0fdragon - Thu Oct 11, 2007 11:32 pm

DekuTree64 wrote:
HyperHacker wrote:
#2 sounds like something that might be worth trying, but can I do it without using up more VRAM?

For a text layer, no. But since it's a bitmap layer that you're hiding, you could set it to not wrap around, and then scroll it offscreen.


if scrolling off the screen doesnt work, perhaps you can use AND and OR on the 15th bit? maybe that can turn off and on the BG in less scanlines
_________________
http://www.myspace.com/knight0fdragonds

MK DS FC: Dragon 330772 075464
AC WW FC: Anthony SamsClub 1933-3433-9458
MPFH: Dragon 0215 4231 1206

#142697 - tepples - Fri Oct 12, 2007 1:21 am

If you want to turn layers on and off without glitches, try doing so with the window registers.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#142709 - HyperHacker - Fri Oct 12, 2007 3:43 am

Thanks, scrolling it off the screen and back worked. Looks like the glitching in the top left corner is a problem with the routine that loads the image; for some reason those pixels aren't being written correctly. I'll have to look at it when I get the chance.
_________________
I'm a PSP hacker now, but I still <3 DS.