#6980 - Wildginger - Thu Jun 05, 2003 7:01 pm
Hi,
I made a 256x256 map using GBA Map Editor, exported it to code, then converted my tileset to code, coded it up, and jobs a good en, all worked fine.
I then made a 512x512 map, using the same tileset as before, did exactly the same procedure as previously, and it doesnt appear correctly on the screen - the tiles are all mixed up.
Im using the following code to load the map:
Code: |
void MakeBKG()
{
u16 loop;
for(loop = 0; loop < 256; loop++)
BGPaletteMem[loop] = Chips16x16TilesPalette[loop];
for(loop = 0; loop < Chips16x16Tiles_WIDTH*Chips16x16Tiles_HEIGHT/2; loop++)
BGTileMem[loop] = Chips16x16TilesData[loop];
for(loop = 0; loop < 64*64; loop++)
VideoBuffer[loop] = CHIPS_L1[loop];
}
|
CHIPS_L1 is indeed a 64x64 array, it is a 256 palette, so I dont know what is going on.
Does anyone have any ideas?
TIA
Jim
_________________
---
Wildginger (aka JimTownsend)
#6981 - niltsair - Thu Jun 05, 2003 7:15 pm
A 512x512 Map is treated as 4 256x256Maps.
That mean you have to load each individually, you can't load say line 0, column 40 as if it was column 40. Each Map contains 32x32Tiles, to reach column 40, you have to skip first Map(32x32) then it's col 8 of Map1.
Code: |
0-------31-32--------63
0| | |
| Map 0 | Map 1 |
31| | |
--------------------------
32| | |
| Map 2 | Map 3 |
63| | |
-------------------------- |
So you basicly have to check Row/Col to find in which maps the tile belongs to. And then store it in the right map by finding it's memory location ( Map0Address + (MapNum*32x32) )
I apologize for the poor ascii art :P
#6985 - Wildginger - Thu Jun 05, 2003 7:49 pm
Thanks for the reply, and the ascii was the easiest bit to follow!
Ok, so I have a 512x512 map, and I have to treat it as 4 seperate maps.
So do I have to load 0,0 to 0,31 as map1, row 1 and then 1,0 to 1,31 as map1, row 2 etc? And then do this for the 4 maps?
So do I still load the tiles in to memory from 0 to 64x64, or does it not work that way?
Sorry for the newbie questions, but thats exactly what I am!
If you felt like posting a little c code, that would be great too ;)
Thanks again,
Jim.
_________________
---
Wildginger (aka JimTownsend)
#6988 - niltsair - Thu Jun 05, 2003 8:06 pm
Yes, it's as you said earlier, you load:
- Line 0-Line 31 of Map 0 then
- Line 0-Line 31 of Map 1 then
- Line 0-Line 31 of Map 2 and finally
- Line 0-Line 31 of Map 3
Code: |
#define MAPADR(num) ((32x32)*num)
u16 x(0);
u16 y(16);
u16* VideoMap;
VideoMap = ... //Where you want to store the map in vide memory;
//Load Tile's entries of Map 0
for( y = 0; y < 32; y++)
for( x = 0; x < 32; x++)
VideoMap[ MAPADR(0) + ( (y-0) *32 ) + (x-0) ] = CHIPS_L1[y*64+x];
//Load Tile's entries of Map 1
for( y = 0; y < 32; y++)
for( x = 32; x < 64; x++)
VideoMap[ MAPADR(1) + ( (y-0) *32 ) + (x-32) ] = CHIPS_L1[y*64+x];
//Load Tile's entries of Map 2
for( y = 0; y < 32; y++)
for( x = 0; x < 32; x++)
VideoMap[ MAPADR(2) + ( (y-32) *32 ) + (x-0) ] = CHIPS_L1[y*64+x];
//Load Tile's entries of Map 3
for( y = 0; y < 32; y++)
for( x = 0; x < 32; x++)
VideoMap[ MAPADR(3) + ( (y-32) *32 ) + (x-32) ] = CHIPS_L1[y*64+x]; |
Now, this code might need some adjustement, i just typed it like this, without testing. And it's far form optimized, i wanted clarity.
#6991 - Wildginger - Thu Jun 05, 2003 8:44 pm
Thanks for the code, much appreciated, I am now much closer to getting this working now.
I now have "map 0" ie the top left quarter of the map displayed, and when I scroll, that map is repeated over and over.
so I have:
map 0 map 0
map 0 map 0
instead of:
map 0 map 1
map 2 map 3
Do I have to do anything specific to make sure all maps are viewable? Ive enabled backgrounds 0-3, but I dont know if thats correct?
Thanks for all this help,
Jim.
_________________
---
Wildginger (aka JimTownsend)
#6994 - niltsair - Thu Jun 05, 2003 8:57 pm
No, you only need to enable 1 background. And for this background, tell it to use a 512x512 size, using starting position of Map 0 (in Screen Block).
Defines from the Pern Project :
///BGCNT defines ///
#define BG_MOSAIC_ENABLE 0x40
#definee BG_COLOR_256 0x80
#define BG_COLOR_16 0x0
#define TEXTBG_SIZE_256x256 0x0
#define TEXTBG_SIZE_256x512 0x8000
#define TEXTBG_SIZE_512x256 0x4000
#define TEXTBG_SIZE_512x512 0xC000
#define ROTBG_SIZE_128x128 0x0
#define ROTBG_SIZE_256x256 0x4000
#define ROTBG_SIZE_512x512 0x8000
#define ROTBG_SIZE_1024x1024 0xC000
#define WRAPAROUND 0x2000
#define ScreenBaseBlock(n) (((n)*0x800)+0x6000000)
REG_BG0CNT = TEXTBG_SIZE_512x512 | BG_COLOR_256 | ScreenBaseBlock( BlockOfYourMap0 ) | WRAPAROUND;
Background 0-3 are just layers that you can view, one on top of the other.
#6996 - Wildginger - Thu Jun 05, 2003 9:22 pm
You'll be getting tired of me . . .
ok, I follow everything you've said to a certain degree, but Im not sure what I should be passing into ScreenBaseBlock() . . .
Jim.
_________________
---
Wildginger (aka JimTownsend)
#6997 - niltsair - Thu Jun 05, 2003 9:35 pm
Which screen block you used to store your Map.
In your first excerp of code you stored it there : VideoBuffer[loop]
Which is wrong. Map and Tiles share the same area of memory. So one can overwrite the other one. We usually store the tiles starting from VideoMemory and up (Char Base Block 0) adn the Map from the end of Video Memory and down (Screen Base Block 31)
http://www.thepernproject.com/index2.htm check the first table, it explains the video memory layout for Tile Display mode.
So what you should do is, use Char Block 0 to store your tiles. Use Screen Block 28 to store your maps (28,29,30,31 in fact) So, in my previous code, VideoMap = ScreenBaseBlock(28)
and for the Background register :
REG_BG0CNT = TEXTBG_SIZE_512x512 | BG_COLOR_256 | (28<<SCREEN_SHIFT) | WRAPAROUND; (i made a mistake in prevous post, ScreenBaseBlock(x) return the address in memory, and not the block value to put in the register, i changed it to 28<<SCREEN_SHIFT.
#7019 - Wildginger - Fri Jun 06, 2003 9:45 am
hello again,
Well, in the end I decided to start over, went back to examples/tutorials, with your info in mind, and now it works, and I even think I understand it :)
I have my 512x512 map, I even have my character walking round it.
On to collision detection . . .
Lookout for my next questions and thanks for the help!
Jim
_________________
---
Wildginger (aka JimTownsend)