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.

Beginners > vertical interlacing bug

#12350 - Zicher - Sat Nov 08, 2003 6:00 pm

Hey all,
I'm trying to figure out some of the tutorials around here, and I'm having some trouble getting a Mode 4 piece to work. The object of the code is to display an image on the screen.

The sample code works fine, but unfortunately when I change the image even a little bit, the screen draws as if I'm "skipping" a line per x-coordinate, which makes it look like vertical interlacing lines. Let me give some examples:

This code works with the ORIGINAL image provided with the tutorial (loaded in from a header file):

Code:

SetMode(MODE_4 | BG2_ENABLE);

  for(loop = 0; loop < 256; loop++) 
     BGPaletteMem[loop] = master_Palette[loop];
     while(1)
     {
        for(y = 0; y < 160; y++)   
        {
            for(x = 0; x < 120; x++)   
            {
                  PlotPixel(x,y, mytile_Bitmap[(y*120)+x]);   
            }               
        }
     }


Tried to clean that up for the post.. hopefully it worked. Anyway, if I use a image converting program (any, I've tried dozens), and just change out the image data in the header file, the above bug happens. Also, strangely enough, even if I change the PlotPixel line to:

Code:

PlotPixel(x,y, 5);


for example, the bug also happens!

I do not think this has to do with the 16-bit word problem of Mode 4, as the code works with the original image.

Here is the PlotPixel function for completeness:

Code:

void PlotPixel(int x,int y, unsigned short c)
{
      VideoBuffer[(y) * 120 + (x)] = (c);
}


Oh GBA Gods, can thee help me?

#12352 - yaustar - Sat Nov 08, 2003 6:52 pm

Can you post some pictures onto the web. it night help.

Off hand, the only thing I can think of is that the image is not being converted properly. Try pcx2gba by Jesder
_________________
[Blog] [Portfolio]

#12353 - Zicher - Sat Nov 08, 2003 7:22 pm

Here are two examples of what I'm seeing (the code that produces the example is in the screenshot):

First, the working example:

http://www.davekahler.com/gba/output_good.jpg

Now, the bad example. Note that the image data is being bypassed completely (it's simply drawing one solid color.. or _should_ be).

http://www.davekahler.com/gba/output_bad.jpg

#12355 - ampz - Sat Nov 08, 2003 8:19 pm

Try this line in the "bad" example:

Code:
Plotpixel( x, y, 0x55);


Mode 4 is a 8bit mode, and the plotpixel function writes two pixels, not one.

#12356 - tepples - Sat Nov 08, 2003 8:25 pm

It looks like the converter is outputting in a 16bpp format designed for mode 3, not mode 4. Please read your converter's manual to learn how to fix this.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#12359 - Zicher - Sat Nov 08, 2003 9:19 pm

tepples wrote:
It looks like the converter is outputting in a 16bpp format designed for mode 3, not mode 4. Please read your converter's manual to learn how to fix this.


thanks tepples, you nailed it! ahhh, I almost forgot what it feels like to be a n00b :)

#12367 - Zicher - Sun Nov 09, 2003 6:21 am

Okay... part 2:

I can't seem to dig up anything good about the best way to get good performance using Mode 4. My test program is getting awful performance (a few frames a second).

What I'm trying to do is basically a full screen pixel-by-pixel write (2 pixels at a time of course because of mode 4) that completely refreshes every frame. Is this a no-no? Am I dreaming?

I swear I've seen mode 4 demos (i.e. 3d engines) that do just this and perform great. What am I missing?

#12371 - yaustar - Sun Nov 09, 2003 2:42 pm

Find a way to optimise the program. Consider the loop at the moment, you are doing 9600 operations per cycle of the while loop. Donr forget about the backbuffer that you can use whilst the other one is being shown and swap between the buffers (Mode 4 does have a back buffer right?)
_________________
[Blog] [Portfolio]

#12381 - sajiimori - Sun Nov 09, 2003 7:41 pm

You're probably not missing anything in particular. GBA games such as Doom aren't fast because of any single thing -- it takes lots of trickery and sacrifices to get that kind of speed. Optimization methods depend completely on what you're actually doing.

Some general tips:

- Start simple -- get something to run fast, even if it's just filling the screen with a solid color
- Take advantage of specialized hardware, such as DMA and the sprite engine
- Precalculate as much as possible
- Find out which parts of your program take the most time
- Optimize your algorithm and general approach before you do low-level optimizations such as assembly rewrites
- Make your innermost loops as simple as possible
- Sacrifice quality for speed if you have to