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 > I need some help with a Mode 3 issue.

#31111 - ghostils - Tue Dec 07, 2004 11:52 pm

Ok so here we go.... I wrote some simple code to display a box with configurable border size.. However after I call it... if I exec any other code taht writes to video memory in MODE 3 the pixels blink... this includes single pixels or if I use my write_text function to show some text the text written blinks.. but nothing else... the Box with border and bg is fine......

The piece of commented code in the fill portion of the draw_box routine, if I set bgcolor == 0, then call draw_box then call othe routines to write vmem its fine.. it only seems if I write to all the video memory something is messed up and it won't let me overwrite other pixels? Do I have to redraw the whole screen each time?

Any ideas?

I'll post the code below for the draw_box routine.

Code:

void draw_box(int pos_x1, int pos_x2, int pos_y1, int pos_y2, int size_border, u16 fgcolor, u16 bgcolor, int bevel)
{

   int x = 0, y = 0;

   //-Draw first line:
   for (y = pos_y1; y < pos_y1 + size_border; y++)
   {
      for (x = pos_x1 + size_border; x < pos_x2 - size_border; x++)
      {
         theVideoBuffer[ x + y * 240 ] = fgcolor;   
      }
   }

   //-Draw 2nd line:
   for( y = pos_y1; y < pos_y2 - size_border; y++)
   {
      for(x = pos_x1; x < pos_x1 + size_border; x++)
      {
         theVideoBuffer[ x + y * 240 ] = fgcolor;   
      }
   }

   //-Draw 3rd line:
   for(y = pos_y2 - size_border; y < pos_y2; y++)
   {
      for(x = pos_x1; x < pos_x2 - size_border; x++)
      {
         theVideoBuffer[ x + y * 240 ] = fgcolor;   
      }
   }
   //x2->x2 * border, y1->y2
   for (y = pos_y1; y < pos_y2; y++)
   {
      for(x = pos_x2 - size_border; x < pos_x2; x++)
      {
         theVideoBuffer[ x + y * 240 ] = fgcolor;
      }
   }



   //-Fill with bgcolor: x1 + border to x2 - border y1 + border -> y2 - border
         //-Why?
         //-if(bgcolor == 0) {return;}
   for(y = pos_y1 + size_border; y < pos_y2 - size_border; y++)
   {
      for(x = pos_x1 + size_border; x < pos_x2 - size_border; x++)
      {
         theVideoBuffer[ x + y * 240 ] = bgcolor;
      }
   }


   //-TODO: add bevel:
}






Here are some of my test cases from my "main":

Code:

u16 fgcolor = RGB(31,31,31);
         u16 bgcolor = RGB(10,16,24);


         
         draw_box (0, 240, 0, 160, 3, fgcolor, 0, 1);

         
         mx = 10;my = 10;
         theVideoBuffer[ mx + my * 240 ] = RGB( 31, 31, 31 );
         mx = 11;my = 10;
         theVideoBuffer[ mx + my * 240 ] = RGB( 31, 31, 31 );
         mx = 12;my = 10;
         theVideoBuffer[ mx + my * 240 ] = RGB( 31, 31, 31 );
         

         //WaitForVblank();
         write_text("Whoops???\0",11,8,fgcolor, bgcolor);
         write_text("Whoops???\0",11,16,fgcolor, bgcolor);







Thanks,
-ghost[iLs]

#31118 - ghostils - Wed Dec 08, 2004 1:00 am

I guess if the GBA doesn't have a loop after it executes your code just goes nutz and can't take the pressure of standing still lol...


I put a while(1){} loop after my code instead of returning in main, and now the problem goes away. Awesome eh?


-ghost[iLs]

#31177 - poslundc - Wed Dec 08, 2004 6:24 pm

ghostils wrote:
I guess if the GBA doesn't have a loop after it executes your code just goes nutz and can't take the pressure of standing still lol...


It's quite sensible, really. Since there is no OS on the GBA to return control to when a process exits, the system simply reboots itself.

Dan.

#31216 - ghostils - Wed Dec 08, 2004 10:36 pm

after working with boot code on the x86 platform. But two different animals I guess hehe.

-ghost[iLs]

#31268 - FluBBa - Thu Dec 09, 2004 12:53 pm

But you surely had somekind of DiscOperatingSystem on it?
_________________
I probably suck, my not is a programmer.

#31291 - Fatnickc - Thu Dec 09, 2004 6:15 pm

^
|
Was that 'DiscOperatingSystem' thing was meant to represent DOS? Because after reading 'Accidental Empires' (old book) I thought it stood for Dirty Operating System, having originally been QDOS, for Quick and Dirty Operating System, and after having been bought by Microsoft, theQ went. Anyhoo..