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 displaying tiles

#7987 - jcpredator - Mon Jun 30, 2003 12:38 am

When I try to load my first attempt at using tile modes into VBA I get the following results:

[Images not permitted - Click here to view it]

Here is the code:

Quote:
// Defines For Constants/Boolean //
#define boolean unsigned char
#define true 1
#define false 0
#define SCREEN_MAX_X 240
#define SCREEN_MAX_Y 160
///////////////////////////////////

// Required Included Files //
#include <predo_start.c>
#include <dispcnt.h>
#include <gba.h>
#include <keypad.h>
#include <Bg.h>
#include <tile_test.h>
#include <test_tile_map.c>
/////////////////////////////

// Structures for Sprites/BGs //
typedef struct OAMEntry
{
u16 attribute0;
u16 attribute1;
u16 attribute2;
u16 attribute3;
} OAMEntry;

OAMEntry sprites[128];

void titleScreen(void);
void initGameMode(void);
void Wait(u16 seconds);
void enableBackground(Bg* bg);

void AgbMain(void)
{
titleScreen();
initGameMode();


while(1);
}

void titleScreen(void)
{
u16 loop, x, y;

SetMode(MODE_3 | OBJ_MAP_1D | BG2_ENABLE | OBJ_ENABLE);

for(y=0;y<SCREEN_MAX_Y; y++)
for(x=0;x<SCREEN_MAX_X; x++)
VideoBuffer[y*SCREEN_MAX_X+x] = predodata[y*SCREEN_MAX_X+x];

while(1)
{
if(!(*KEYS & KEY_START)) break;
}

for(loop=0; loop<38400; loop++)
VideoBuffer[loop] = 0x0000;
}

void initGameMode(void)
{
u16 loop;
u16* temp;
SetMode(MODE_0 | OBJ_MAP_1D | BG0_ENABLE |
BG1_ENABLE | BG2_ENABLE | BG3_ENABLE |
OBJ_ENABLE);// Mode 0, OBJ Enabled, All BG's

Bg Bg3;
Bg3.number = 3;
Bg3.charBaseBlock = 0;
Bg3.screenBaseBlock = 28;
Bg3.colorMode = BG_COLOR_256;
Bg3.size = TEXTBG_SIZE_256x256;
Bg3.mosaic = 0;
Bg3.x_scroll = 120;
Bg3.y_scroll = 80;

enableBackground(&Bg3);

for(loop=0;loop<256;loop++)
{
BGPaletteMem[loop] = tile_testPalette[loop];
}
for(loop=0;loop<tile_test_WIDTH * tile_test_HEIGHT /2;loop++)
{
Bg3.tileData[loop] = tile_testData[loop];
}

temp = (u16*)test_tile_map;
for(loop=0;loop<16*16/2;loop++)
Bg3.mapData[loop] = temp[loop];
}

void Wait(u16 seconds)
{
//Start the timer
REG_TM0CNT = 0x0 | 0x80;
//zero the timer
REG_TM0D = 0;
while(seconds--)
{
while(REG_TM0D <= 16386){} //wait
REG_TM0D = 0; //reset the timmer
}
}

void enableBackground(Bg* bg)
{
u16 temp;

bg->tileData = (u16*)CharBaseBlock(bg->charBaseBlock);
bg->mapData = (u16*)ScreenBaseBlock(bg->screenBaseBlock);
temp = bg->size | (bg->charBaseBlock<<SCREEN_SHIFT)|
bg->colorMode | bg->mosaic;

switch(bg->number)
{
case 0:
{
REG_BG0CNT = temp;
REG_DISPCNT |= BG0_ENABLE;
}break;
case 1:
{
REG_BG1CNT = temp;
REG_DISPCNT |= BG1_ENABLE;
}break;
case 2:
{
REG_BG2CNT = temp;
REG_DISPCNT |= BG2_ENABLE;
}break;
case 3:
{
REG_BG3CNT = temp;
REG_DISPCNT |= BG3_ENABLE;
}break;
default:break;
}
}


Any help would be greatly appreciated, thanks...
_________________
There is no spoon...

#7992 - Ninja - Mon Jun 30, 2003 4:13 am

This problem drove me nuts for days when I encountered it. :)

Code:

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


The problem should be that line. Change it to this:

Code:

for(loop=0; loop < 16*16; loop++)
     Bg3.mapData[loop] = temp[loop];


and see if that fixes things. Let me know if it doesn't, and I will take a closer look at your code.

#8023 - jcpredator - Mon Jun 30, 2003 8:56 pm

Yeah well this problem was very irritating to me also but I finally got it working.

I changed the following code:

Quote:
for(loop=0;loop<256;loop++)
{
BGPaletteMem[loop] = tile_testPalette[loop];
}
for(loop=0;loop<tile_test_WIDTH * tile_test_HEIGHT /2;loop++)
{
Bg3.tileData[loop] = tile_testData[loop];
}

temp = (u16*)test_tile_map;
for(loop=0;loop<16*16/2;loop++)
Bg3.mapData[loop] = temp[loop];


To this:

Quote:
for(loop=0;loop<14;loop++)
{
BGPaletteMem[loop] = tile_testpalette[loop];
}


for(loop=0; loop<64*2; loop++)
Bg3.tileData[loop] = obj0[loop];

temp = (const u16*)map;
for(loop=0;loop<32*32/2;loop++)
Bg3.mapData[loop] = temp[loop];


For some reason it works fine now but my tiles where not displaying right still after the above changes. I went into the tile viewer in VisualBoy Advance and noticed that both of my tiles where not converted right. I used a diff tool for the conversion and the tiles where displayed correctly.

Sad thing is I couldn't really tell you why or how the above code fixed it, maybe someone could explain this to me.

I also changed the SetMode function that instead of enabling all the BGs I only have the BG3 enabled. Funny thing is that im still getting things displayed in the other 3 BGs, not sure if thats normal or not, but either way its not effecting the BG that is being displayed.

My brother, sgt_soup is programming a conversion tool for me so I can have a more realiable and more efficient tool.

Thanks again,
_________________
There is no spoon...

#8725 - jmp_eax - Fri Jul 18, 2003 5:29 pm

try it on a cart... that's all that matters.