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 > My first game works only in the emulator but not in the gba

#177312 - tuket - Fri Apr 06, 2012 12:30 am

I have created a very simple game for gba and it work in the amulator but not in the cartridge. I have an EZ flash IV. It is just a red pixel that moves on the screen. When I start the game in the gameboy it apears the leters of GAMEBOY but where it should be written NINTENDO there are some random pixels like when it has dust inside. Here is the code
Code:
#define RGB16(r,g,b)  ((r)+(g<<5)+(b<<10))
#include "keypad.h"
   unsigned short* Screen = (unsigned short*)0x6000000; 
   void showpo(char* x,char* y);
   void dele(char* x, char* y);
int main()
{   
   *(unsigned long*)0x4000000 = 0x403; // mode3, bg2 on
   struct p{
      char x;
      char y;
   };
   struct p p={0,0};
   showpo(&p.x,&p.y);
   char x,y; 

   // clear screen, and draw a blue back ground
   for(x = 0; x<240;x++)   //loop through all x
   {
      for(y = 0; y<160; y++)  //loop through all y
      {
         Screen[x+y*240] = RGB16(0,0,0); 
      }
   }

   while(1){
      if(!((*KEYS) & KEY_UP)){dele(&p.x,&p.y);--p.y;showpo(&p.x,&p.y);}
      if(!((*KEYS) & KEY_DOWN)){dele(&p.x,&p.y);++p.y;showpo(&p.x,&p.y);}
      if(!((*KEYS) & KEY_RIGHT)){dele(&p.x,&p.y);++p.x;showpo(&p.x,&p.y);}
      if(!((*KEYS) & KEY_LEFT)){dele(&p.x,&p.y);--p.x;showpo(&p.x,&p.y);}
      char i;
      for(i=0;i<100;i++){
         char j;
         for(j=0;j<100;j++);
         }
      }   //loop forever
}

void showpo(char* x,char* y){
   Screen[(*x)+(*y)*240]=RGB16(31,0,0);
}
void dele(char* x, char* y){
   Screen[(*x)+(*y)*240]=RGB16(0,0,0);
}


I hope you can help me. :)

#177313 - dantheman - Fri Apr 06, 2012 3:37 am

Ah, a very simple fix. Just run the output GBA file through a program that fixes the header (which is the cause for the garbled Nintendo logo). GBATA can do it, and I think the command-line "gbafix" program is included with DevKitARM which would also do the job.

EDIT: also, quick note, in that RGB macro at the top, be sure to put "g" and "b" in parenthesis just like the "r" currently is. This will make it safe when you try to send in something more than just an integer value as an argument to the macro.

#177317 - tuket - Fri Apr 06, 2012 2:25 pm

Thank you very much that utility worked fine. I had devKitAdv so I had to download devKitARM. Now I wonder why this happens. I think divkitAdv should be not depending on that tool "gbafix" it should have its own tool to fix the gba games. As I said thank you very much, the answer was accurate :)

#177318 - gauauu - Fri Apr 06, 2012 3:09 pm

Here's a good explanation of what was going on, from http://gameboy.mongenel.com/dmg/asmmemmap.html
Quote:
This area in the GameBoy address space contains information about the cartridge that is inserted, including; type of cartridge, size of rom, size of ram, a Nintendo logo, and other information. Also, at $0100, there is a NOP instruction, followed by a JUMP to the start of the program, usually $0150. The GameBoy's CPU begins execution at $0100, that is why this is included. If the Nintendo logo bytes are not correct, the GameBoy will not execute the game. Upon power up, the system ROM in a GameBoy will verify that the logo is correct. Nintendo has tried to use the logo to keep only authorized developers from publishing games, since the logo is a registered trademark of Nintendo. But, a legal precedent was set in the United States in a case of Sega vs. Accolade (c.1993). Sega's Genesis console also has a signature that is a copyright of Sega, and Accolade used this logo so that their games, which were not approved by Sega, would be able to play on the Genesis console. The judge ruled in favor of Accolade, stating that using a logo to that degree was an anti-competetive practice, and therefore, Accolade was allowed to continue selling their games. At least, that's what I heard. =P


As to why devkitAdv doesn't deal with it? I don't really know why a tool to fix the header wasn't bundled with devkitAdv. But you are better off using devkitARM anyway. It's more up-to-date and maintained, has better tools, and better support from this community.

#177319 - tuket - Fri Apr 06, 2012 3:38 pm

Now it makes total sense.
I am going to use devKitARM from now. Thanks :)