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 > devkitpro map problem.

#64981 - skycladmonkey - Thu Dec 29, 2005 4:05 am

Hi
I am using devkitpro and im trying to make a map using the island 8 example from gbamappy.

if screenbase is set to 0 i see a corrupt map.
otherwise it doesnt show at all.
i believe im missing something with the screenbase and c har base flags.

can anyone help?

Code:

#include <gba_base.h>
#include <gba_video.h>
#include <gba_systemcalls.h>
#include <gba_interrupt.h>
#include <gba_input.h>
#include "island8.TXT"


// --------------------------------------------------------------------

int main() {
   // Set up the interrupt handlers
   InitInterrupt();
   // Enable Vblank Interrupt to allow VblankIntrWait
   EnableInterrupt(IE_VBL);

   // Allow Interrupts
   REG_IME = 1;
   
   // set screen H and V scroll positions
   BG0HOFS = 0; BG0VOFS = 0;

   // set the screen base to 31 (0x600F800) and char base to 0 (0x6000000)
   BGCTRL[0] = SCREEN_BASE(31);
   BGCTRL[0] = CHAR_BASE(0);

   // screen mode & background to display
   SetMode( MODE_0 | BG0_ON );
   REG_BG0CNT |=BG_256_COLOR;
   REG_BG0CNT |=BG_SIZE_0;
   //REG_BG0CNT |=CHAR_BASE(0);
   //REG_BG0CNT |=SCREEN_BASE(31);
   
   int i, x, y;
   u16 * gfxpt, * gfxpt2;
   u16 * mappt;

/* Copy the tile graphics to vram 16bits at a time (8bit transfers don't work) */
   gfxpt = (u16*)VRAM+0x2000;   /* This is actually +0x4000, but 0x2000 because of short ptr */
   gfxpt2 = (u16 *) island8_blockgfx;
   for (i=0;i<(sizeof(island8_blockgfx)/2);i++)
   {
      gfxpt[i] = gfxpt2[i];
   }
   
/* Copy the 256 colour palette*/
   for (i=0;i<256;i++)
   {
      BG_COLORS[i] = island8_cmap[i];
   }

/* Copy the data to the map memory */
   mappt = (u16 *) VRAM;//+0x600F800;
   for (y=0;y<32;y++)
   {
      for (x=0;x<32;x++)
      {
         mappt[(y*32)+x] = (u16) island8_map0[y] [x];
      }
   }
   
   
   while(1)
   {
      VBlankIntrWait();
      
      
      if(!(REG_KEYINPUT & KEY_LEFT))
            x--;
         
      if(!(REG_KEYINPUT & KEY_RIGHT))
            x++;
         
      if(!(REG_KEYINPUT & KEY_UP))
            y--;
         
      if(!(REG_KEYINPUT & KEY_DOWN))
            y++;

      BG0HOFS = x;
      BG0VOFS = (y)%(32*8);
   }

   return (0);   // we'll never reach here
}

#65000 - blindraccoon - Thu Dec 29, 2005 8:31 am

Without looking to hard, this jumped right out at me:

Code:

   // set the screen base to 31 (0x600F800) and char base to 0 (0x6000000)
   BGCTRL[0] = SCREEN_BASE(31);
   BGCTRL[0] = CHAR_BASE(0);

You set the screen base to 31 but then inadvertently reset it to 0 by assigning the char base, not oring it in. Should be :

Code:

   BGCTRL[0]  = SCREEN_BASE(31);
   BGCTRL[0] |= CHAR_BASE(0);

or better still

Code:

   BGCTRL[0]  = SCREEN_BASE(31) | BGCTRL[0] ;

_________________
There are exactly 10 types of people in the world, those that understand binary and those that don't.

#65016 - skycladmonkey - Thu Dec 29, 2005 4:11 pm

Aargh. I should have spotted that.

It still doesnt work right though. I get blue and black vertical stripes.

Am I loading the data into the right places?

#65018 - tepples - Thu Dec 29, 2005 4:22 pm

skycladmonkey wrote:
It still doesnt work right though. I get blue and black vertical stripes.

Could you take a PNG format screenshot of the screen and the tile viewer?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#65036 - skycladmonkey - Thu Dec 29, 2005 7:34 pm

Got it

Code:
gfxpt = (u16*)CHAR_BASE_ADR(0);
   gfxpt2 = (u16 *) island8_blockgfx;
   for (i=0;i<(sizeof(island8_blockgfx)/2);i++)
   {
      gfxpt[i] = gfxpt2[i];
   }


and
Code:
mappt = (u16 *) MAP_BASE_ADR(31);
   for (y=0;y<32;y++)
   {
      for (x=0;x<32;x++)
      {
         mappt[(y*32)+x] = (u16) island8_map0[y] [x];
      }
   }


were the culprits.

Thanks for the help folks!

#68192 - rychan - Mon Jan 23, 2006 1:18 am

Any chance of a url for he code of this mapping demo at all anyone?

Thanks to sgstair in irc last night again got my _SUBS sorted out and now have a lovely rotating sprite mmm shiny!