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 > Not working on hardware

#8959 - VgSlag - Thu Jul 24, 2003 11:37 pm

Hi, I'm new to GBA programming but wanted t get a grip of the basics... I was testing this:

Code:

#include <mygba.h>

// Graphics Includes
// Bg
#include "gameBg.raw.c"
#include "gameBg.pal.c"

// Player
#include "player.raw.c"
#include "player.pal.c"

// Global Variables
u8 player; // Sprite index for the player
u8 player_x = 10;
u8 player_y = 10;
u16 player_rot = 0;

// Function definitions
void vblFunc();
void drawScreen();
void queryKeys();

int main(void) {

   ham_Init();

   // Setup the background mode
    ham_SetBgMode(4);

   // DMA the background picture
   TOOL_DMA1_SET(&gameBg_Bitmap,
                     MEM_BG_PTR,
                     SIZEOF_32BIT(gameBg_Bitmap),
                     DMA_TRANSFER_32BIT,
                     DMA_STARTAT_NOW)
   
   // Initialize the background palette
   ham_LoadBGPal(&gameBg_Palette,SIZEOF_16BIT(gameBg_Palette));

   // Initialize the sprite palette
   ham_LoadObjPal(&player_Palette, 256);

   // Setup the sprite
   player = ham_CreateObj(&player_Bitmap,0,2,
                        OBJ_MODE_NORMAL,1,0,1,0,0,0,0,player_x,player_y);

   // Set up the sprite for rotation
   ham_SetObjRotEnable(player, 1);

   // Set the rotation set number
   ham_SetObjRotSetSelect(player, 0);

   // Start the VBL interrupt handler
   ham_StartIntHandler(INT_TYPE_VBL,&vblFunc);

   while(TRUE) {

   }

   return 0;
}

void vblFunc() {

   // Copy block sprite to hardware
   ham_CopyObjToOAM();

   // Check which keys are down
   queryKeys();

   // Re-draw the screen
   drawScreen();

   return;
}

// Function to check the player keys
void queryKeys () {

   // Is Left pressed?
   if (F_CTRLINPUT_LEFT_PRESSED) {
      --player_x;
   }

   // Is Right pressed?
   if (F_CTRLINPUT_RIGHT_PRESSED) {
      ++player_x;
   }

   // Is Up pressed?
   if (F_CTRLINPUT_UP_PRESSED) {
      --player_y;
   }

   // Is Down pressed?
   if (F_CTRLINPUT_DOWN_PRESSED) {
      ++player_y;
   }

   // Is Start pressed?
   if (F_CTRLINPUT_START_PRESSED) {
      ++player_rot;
   }
}

// Function to draw the player movement
void drawScreen () {
   ham_SetObjXY(player, player_x, player_y);
   ham_RotObjDefineSet(0, player_rot % 360, 0x100, 0x100);
}

/* END OF FILE */


It works on the emu but not on the actual hardware... the bg doesn't display. Could anyone explain why please?

Thanks,

G

#8961 - yaustar - Fri Jul 25, 2003 12:51 am

Are you going through the transfer port or by flash cartridge?
_________________
[Blog] [Portfolio]

#8965 - funkeejeffou - Fri Jul 25, 2003 2:38 am

Haven't looked at your code, but did you put the "fix data" option in the flash software?
The header of your ROM must be valid otherwise it won't work.
There are also some hack utilities to fix this.

#8966 - yaustar - Fri Jul 25, 2003 2:48 am

If he/she is going through the transfer port via the boot cable (no cart) then the header does not matter but this line of code needs to be placed somewhere.

Code:

int __gba_multiboot = 0;


(taken from the faq on this board)

Just remove it when you are running from cart.
_________________
[Blog] [Portfolio]

#8974 - VgSlag - Fri Jul 25, 2003 7:05 am

I'm running it from the flash cart...

The sprite and control is working, just not the bg display?

#8975 - VgSlag - Fri Jul 25, 2003 7:13 am

The rom was working but I've fixed the header... still the same problem :(

The sprite is displayed and usable, just not the bg.

I don't really know what I'm talking about but could it be something to do with this:

"Sprites in display mode 3, 4, or 5 must use cel data from 0x06014000 to 0x06017FFF because the area in 0x06010000 to 0x06013FFF is reserved for the background. This cel data area corresponds to indices 512 to 1023 in sprite attribute 2.

In mode 3 and 5, sprites will not show up behind the background. Use mode 4 if you want this effect. "

#8981 - VgSlag - Fri Jul 25, 2003 2:45 pm

I'm at work now so can't test it but I think it's to do with this line:

TOOL_DMA1_SET ...

I think it should be TOOL_DMA3_SET...

Can anyone confirm this for me?

Thanks,

G