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 > Problem with a tutorial modification

#21529 - tornadokick - Mon May 31, 2004 2:06 am

Hey, I'm trying to get into this gba programming (so I'm new), and I was messing around with one of the tutorials. Alright. What I was trying to do was create an array which would hold information for the different colors, and then copy that array onto the screen. The Problem is that the program freezes. I've tried everything I could think of, but nothing changes. This is what I have:

Code:


#include <math.h>    //sign and cos stuff
#include "gba.h"         //GBA register definitions
#include "dispcnt.h"     //REG_DISPCNT register #defines
#include "keypad.h"      //button registers
//#include "bg.h"          //background definitions
//#include "function.h"

#define RGB(r,g,b) ((r) + ((g)<<5) + ((b)<<10))

u16* videoBuffer = (u16*) 0x6000000;
void PlotPixel(int x, int y, unsigned short int c) { videoBuffer[y*240 + x] = c; }

int main()      // start of program
{
   SetMode(MODE_3 | BG2_ENABLE);
   
   unsigned short int screen [240][160];

   for (int i = 0; i < 240; i++)
   {
      for (int j = 0; j < 160; j++)
      {
         screen[i][j] = RGB(31,31,31);  // most likely freezes here
      }
   }         

   for(int x = 0; x < 240; x++)
   {
      for(int y = 0; y < 160; y++)
      {
         PlotPixel(x, y, RGB(30,0,0));   //screen[x][y]);
      }
   }

   return 0;
}


It seems that the program freezes in the first for loop. If I comment that out, the program continues and goes to the second loop
Might the gba not be able to handle something like that?

Any help is appreciated.

#21531 - wintermute - Mon May 31, 2004 2:38 am

local variables are placed in IWRAM by default in most cases - it's only 32k so your code will instantly die with a local 240x160 array.

either use a global with __attribute__(section(".ewram")) or with devkitARM and it's built in linkscripts you can use __attribute__(section(".sbss")) or malloc

#21540 - niltsair - Mon May 31, 2004 2:33 pm

Also, at the end of main procedure, add a while(1); just before the return 0;, else the GBA reset.
_________________
-Inside every large program is a small program struggling to get out. (Hoare's Law of Large Programs)
-The man who can smile when things go wrong has thought of someone he can blame it on. (Nixon's Theorem)

#21542 - tornadokick - Mon May 31, 2004 3:44 pm

niltsair wrote:
Also, at the end of main procedure, add a while(1); just before the return 0;, else the GBA reset.


Hmm, that doesn't seem to be the case. If I comment out the line where i fill in the information for the screen to display, the program runs normally and fills the screen. The screen does not reset, so I doubt that the while(1) statement you suggested would do anything.

#21543 - zazery - Mon May 31, 2004 3:57 pm

From my experience it works fine in Visual Boy Advance without it depending on what you are doing. However on the actual hardware it doesn't work so nicely. You need to either include that or an infinite loop that contains calls to functions to process input and output. Never let your code end, that's pretty much the safest way to go about coding programs for the GBA.

#21545 - tornadokick - Mon May 31, 2004 4:44 pm

wintermute wrote:
local variables are placed in IWRAM by default in most cases - it's only 32k so your code will instantly die with a local 240x160 array.

either use a global with __attribute__(section(".ewram")) or with devkitARM and it's built in linkscripts you can use __attribute__(section(".sbss")) or malloc


alright, thanx for the knowledge.