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.

Graphics > Problem loading map data. [Renamed]

#95153 - christosterone - Fri Jul 28, 2006 2:03 am

I stopped gba programming for like 6 months and now im getting back into it, but im having trouble loading the map... im retarded. i dont knwo what im doing wrong;

in map.c
Code:
const unsigned int mapData[2048]=
{
   0x00a800a7,0x003600a9,0x00380037,0x003a0039,0x003c003b,0x00000000,0x00000000,0x00000000,


in main.c
Code:
   for(loop = 0; loop < 128*128/2; loop++)
      ground.mapData[loop] = mapData[loop];


for some reason its only showing up half the pixels and blanks or something i dont know.... its probably really somehting stupid.
i think i may need to shift the bits over because ints and u16s have 1/2 the amt of bits as an int.... im not sure

i bet its really simple and im sorry to waste your time... i feel retarded

-chris

#95177 - DrkMatter_ - Fri Jul 28, 2006 3:47 am

You should ask yourself the following questions: are you...

    - only writing to VRAM during VBlank?
    - writing to VRAM 16 bits at a time?
    - certain your original data is in little endian?

#95184 - tepples - Fri Jul 28, 2006 4:21 am

Take screenshots of VisualBoyAdvance's tile viewer and map viewer, as needed to demonstrate the problem, save them in PNG format, and make them available on some image hosting site.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#95226 - christosterone - Fri Jul 28, 2006 7:28 am

DrkMatter_ wrote:
- only writing to VRAM during VBlank?

yes, i the code loads the 512x512 text background right at the beginning and then the program goes into an infinite loop.

DrkMatter_ wrote:
- writing to VRAM 16 bits at a time?

no i am not; i believe the int is 32 bits whereas i need 16 bits. The only map editor i know which doesnt suck is mirach, but it only outputs in integer format. i could either bitsplit the integer (im not exactly sure how) or use another mapping program (any suggestions?).

DrkMatter_ wrote:
- certain your original data is in little endian?

im not sure what that means.

this is waht the map is: and what it should look like:
http://moop.gotdns.com/~christosterone/screenshot/map.PNG

this is what the gba is outputting:
http://moop.gotdns.com/~christosterone/screenshot/shot.PNG
_________________
http://moop.gotdns.com/~christosterone

#95240 - Cearn - Fri Jul 28, 2006 10:50 am

christosterone wrote:
DrkMatter_ wrote:
- writing to VRAM 16 bits at a time?

no i am not; i believe the int is 32 bits whereas i need 16 bits. The only map editor i know which doesnt suck is mirach, but it only outputs in integer format. i could either bitsplit the integer (im not exactly sure how) or use another mapping program (any suggestions?).


Or you could just cast the source or destination pointers to match the other, or use a dedicated copy routine like memcpy, dma or CpuFastSet.

Code:
u32 size= size_in_bytes_of_mapData;

// casting to u32*. 2x faster than u16 copies
u32 *dst= (u32*)ground.mapData, *src= (u32*)mapData;
for(ii=0; ii<size/4; ii++)
    *dst++ = *src++;

// memcpy; 3x faster than u16 copies
memcpy(ground.mapData, mapData, size);

// GBA specific copiers; ~8x faster
dma_cpy(ground.mapData, mapData, size/4);
CpuFastSet(mapData, ground.mapData, size/4);

But even then, the output seems too weird for that to be the only problem. But it's a start. Also check the tile/map viewers (not just the final screen) to see what the problem is.

FIX: src is a pointer, duh >_<


Last edited by Cearn on Fri Jul 28, 2006 8:07 pm; edited 1 time in total

#95328 - FluBBa - Fri Jul 28, 2006 8:05 pm

Is your ground.mapData short/u16 cast it to int when in the loop.
The problem looks as if you read twice as much as you write.
_________________
I probably suck, my not is a programmer.

#95350 - christosterone - Fri Jul 28, 2006 11:21 pm

eureka!

thanks so much for the help >_<

-chris
_________________
http://moop.gotdns.com/~christosterone