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.

Coding > Need help with maps again!!

#11029 - mandarin - Tue Sep 23, 2003 8:53 pm

Hi all,

Lately I've been working on something and I got a problem with the maps.

What I want to do is load a image and prompt the player to press start then once pressed the map of the first level gets loaded but somehow I can't get it to work.

you can find the code at the following urls

http://galileo.spaceports.com/~mandarin/project1.zip
http://galileo.spaceports.com/~mandarin/h.zip
http://galileo.spaceports.com/~mandarin/images.zip

project1.zip is the actual code
h.zip are the header files
images.zip are the tiles and map

help will be appreciated
thanx

#11062 - sajiimori - Thu Sep 25, 2003 12:34 am

Broken links.

Reduce the code to something small that just loads a map and see if that works. If not, post it here with a main().

#11443 - yaustar - Tue Oct 07, 2003 4:03 am

they are not broken, just copy and paste the address into the tool bar. (it's a domian thing)

From just the rom image and the c file (please bear in mind it is 4:30am):

It is going into mode 1 striaght away, instead of waiting at mode 4 for the player to press start. I think this is due to:
Code:
while (*KEYS & KEY_START)
[still not sure]

any way here is the code for the rest to see

Code:
#include "h/gba.h"
#include "h/screenmode.h"
#include "h/keypad.h"
#include "h/bg.h"
#include "h/sprites.h"
#include "h/bg.cpp"
#include "h/math.h"

#include "images/start1.h"
#include "images/start2.h"
#include "images/map.c"
#include "images/tiles.h"

Bg bg2;

#define RGB(r,g,b)(r+(g<<5)+(b<<10))
void WaitForVsync()
{
   while((volatile u16)REG_VCOUNT != 160){}
}


void Flip()
{
   if(REG_DISPCNT & BACKBUFFER)
   {
      REG_DISPCNT &=~BACKBUFFER;
      theVideoBuffer = theBackBuffer;
   }
   else
   {
      REG_DISPCNT |= BACKBUFFER;
      theVideoBuffer = theBackBuffer;
   }
}


void WaitForVBlank()
{
   #define ScanlineCounter *(volatile u16*)0x4000006
   while(ScanlineCounter<160){}
}


void level1()
{
u16* temp;
   u16 loop;
   
   SetMode(MODE_1 |BG2_ENABLE | OBJ_ENABLE | OBJ_MAP_1D);


   bg2.number = 2;
   bg2.charBaseBlock =0;
   bg2.screenBaseBlock =28;
   bg2.colorMode = BG_COLOR_256;
   bg2.size = ROTBG_SIZE_512x512;
   bg2.mosaic=0;
   bg2.x_scroll=120;
   bg2.y_scroll=80;

   EnableBackground(&bg2);
   

   for(loop = 0; loop <256; loop++)
      BGPaletteMem[loop] = TILESPalette[loop];

   for(loop = 0; TILES_WIDTH*TILES_HEIGHT/2;loop++)
      bg2.tileData[loop] = TILESData[loop];

   temp = (u16*)map;

   for(loop = 0; loop<64*64/2; loop++)
      bg2.mapData[loop] = temp[loop];


   while(1)
{
   UpdateBackground(&bg2);
   WaitForVSync();
   
}
}


int start()
{
     while (*KEYS & KEY_START)
      {
         SetMode(MODE_4 | BG2_ENABLE);
         u16 i;
         
         for(i=0;i<256;i++)
            BGPaletteMem[i]=START1Palette[i];
         
         
         u16 x,y;
         
         for(x=0;x<120;x++)
            for(y=0;y<160;y++)
               PlotPixel(x,y, START1Data[y*120+x]);   
               WaitForVBlank();
         for(x=0;x<120;x++)
            for(y=0;y<160;y++)
               PlotPixel(x,y, START2Data[y*120+x]);

               
         }
   


 level1();

         
         


      
         
}
            


int main()
{
SetMode(MODE_1 | OBJ_ENABLE | OBJ_MAP_1D);




   while(1)
{
   start();
   
   
}



}

_________________
[Blog] [Portfolio]