Page 1 of 1
using a map created by MDPPY
Posted: Thu Dec 20, 2012 8:45 pm
by oofwill
I've always problems using files exported by MDPPY.
I create this new post in order to keep clean djcouchycouch topic.
I have 3 files :
-palette (it's ok)
-tiles (loading in vram ok thanks to Chilly Willy)
-mapping
The problem is, i have thins kind of asm file:
Code: Select all
.globl level1_backg
level1_backg:
; line 0
dc.w 0x1
dc.w 0x2
dc.w 0x3
...
; line 0
dc.w 0x4
dc.w 0x5
dc.w 0x6
I'm triying to draw my map, but i don't know where to start
i tried this to know what tile draw
Code: Select all
if ((level1_backg[i*j])==0) {address=13728;}
...
then when address of the tile is known:
Code: Select all
VDP_fillTileMapRectInc(APLAN, TILE_ATTR(2,0,0,0)+(address/32), k, l, 8/8, 8/8);
a tile is drawing, but never the good one.
For sure
level1_backg[i*j])==0 isn't the good way to retrive the info on tilemap but i don't know how to do this correctly.
Someone to help me?
Posted: Thu Dec 20, 2012 10:02 pm
by djcouchycouch
To index a 2d array linearly, the formula is x + (y * array_width)
So assuming i is x and j is y, then it's level1_backg[i + (j * background_width)])
EDIT: that method isn't the most efficient way to get at an element in the array, though. There's at least one multiply which is slow.
If you're iterating an array, instead of indexing an array like above, you probably should first set a pointer to the beginning of the array and then increment that pointer.
If you're indexing an item in the array, it's probably better to do it like:
*(level1_backg + (i + (j << 6))) // assuming your map is 64 (2 ^ 6)
Which is a shift and some additions. Harder to read but should be faster.
Of course I'm not an expert and there are probably better methods.
Posted: Thu Dec 20, 2012 10:20 pm
by oofwill
Merveillous, it's working!
I've so many things to learn...
Thanks for your help!
Posted: Fri Dec 21, 2012 1:14 am
by djcouchycouch
oofwill wrote:Merveillous, it's working!
I've so many things to learn...
Thanks for your help!
Good to know you're progressing!
Posted: Sat Dec 22, 2012 10:48 am
by oofwill
How could i tretrieve value from an asm tilemap?
This is working from a C table, but it's more convenient for me to do a map in asm format.
Unfortunately, this is not working...
I wrote this
Code: Select all
for (i=0; i<=45; i++) //affichage de notre niveau visible
{
k++;
l=0;
for(j=0; j<=30; j++)
{
VDP_fillTileMapRectInc(APLAN, TILE_ATTR(1,0,0,0)+(level1_map[i+j*80]+1), k, l, 8/8, 8/8);
l++;
}
}
And that's my screen
that's wha's expected: (blue is color 0, transparent then)
Seems only one line/2 is drawned...
tilemap is 160*30 tiles.
Posted: Sat Dec 22, 2012 11:08 am
by djcouchycouch
Looking at it quickly, if your tile map is 160 tiles wide then the 80 you're using to index the Array is wrong.
If that's not it try simplifying the code to the bare minimum to prove that it works. I'm not sure what the k and l are doing but they might be confusing things.
The order of the expression I+j*80 should be okay because of operator rules but its probably a good practice to write that as I+(j*80).
Posted: Sat Dec 22, 2012 12:21 pm
by oofwill
In fact, if i write x+y*160, result is:
This was working with C file, but in asm, here is what i have...
Seems this (x+y*160) is not correct because when i want to simplify my code and just drawx a tile, this is never the good one
Code: Select all
VDP_fillTileMapRectInc(APLAN, TILE_ATTR(1,0,0,0)+(level1_map[0+(2*160)]+1), 20, 0, 8/8, 8/8);
Posted: Sat Dec 22, 2012 12:38 pm
by djcouchycouch
oofwill wrote:Code: Select all
VDP_fillTileMapRectInc(APLAN, TILE_ATTR(1,0,0,0)+(level1_map[0+(2*160)]+1), 20, 0, 8/8, 8/8);
If you're just filling a map then VDP_fillTileMapRect() is probably what you want. VDP_fillTileMapRectInc() does something with tile indexes which I'm not sure what it does exactly, but I don't think you want it.
If you're only setting one tile at a time, you can also try VDP_setTileMap(plan, tile, x, y).
Posted: Sat Dec 22, 2012 1:37 pm
by oofwill
Result is the same, but VDP_setTileMap(plan, tile, x, y) is really fast!

Posted: Sat Dec 22, 2012 2:08 pm
by Moon-Watcher
I've been working in some scrolling functions. It doesn't works at 100% but may help you...
main.c -
http://pastebin.com/q4ND2m3r
scroll.c -
http://pastebin.com/zZdHEsgH
scroll.h -
http://pastebin.com/DP9u3jBG
Posted: Sat Dec 22, 2012 2:15 pm
by djcouchycouch
you don't have to use different iterators for looping in your array and drawing into the plane.
Code: Select all
for (i=0; i<=45; i++)
{
for(j=0; j<=30; j++)
{
VDP_setTileMap(APLAN, TILE_ATTR(1,0,0,0)+(level1_map[i+(j*160)] + 1), i, j);
}
}
Just to be sure, are you certain your map is 160 x 80?
Is the data stored as single bytes or as 2-byte words?
is the i variable meant to be used as your horizontal axis and the j variable as the vertical?
what happens if you manually force the tile to be drawn?
Code: Select all
for (i=0; i<=45; i++)
{
for(j=0; j<=30; j++)
{
VDP_setTileMap(APLAN, TILE_ATTR(1,0,0,0) + 1), i, j);
}
}
does that code behave correctly?
EDIT: you're using MDPPY++ and exporting as assembly? Is there a difference if you export as C?
Posted: Sat Dec 22, 2012 3:15 pm
by oofwill
Thanks moon watcher, i will have a look at this
Djcouchycouch,
Code: Select all
for (i=0; i<=45; i++)
{
for(j=0; j<=30; j++)
{
VDP_setTileMap(APLAN, TILE_ATTR(1,0,0,0) + 1), i, j);
}
}
doesn't work at all, an argument is missing
Sure my map is 160*30.
I'm not using MDPPY++ anymore. I'm drawing my map in 16 color, then export it with genitile.
I've then 3 file : tiles, palette, and tilemap.
ex ok my map:
Code: Select all
* ---------------------------
.global level1_map
level1_map:
* ---------------------------
* size:9600 bytes
dc.w 0x0068
dc.w 0x005d
dc.w 0x005e
dc.w 0x005f
dc.w 0x0060
dc.w 0x005d
dc.w 0x005e
dc.w 0x005f
dc.w 0x0060
dc.w 0x005d
dc.w 0x005e
dc.w 0x005f
dc.w 0x0060
dc.w 0x005d
dc.w 0x005e
dc.w 0x005f
dc.w 0x0060
dc.w 0x005d
-
-
-
dc.w 0x0068
dc.w 0x005d
dc.w 0x005e
dc.w 0x005f
dc.w 0x0060
dc.w 0x005d
dc.w 0x005e
dc.w 0x005f
dc.w 0x0060
dc.w 0x005d
dc.w 0x005e
dc.w 0x005f
dc.w 0x0060
dc.w 0x005d
dc.w 0x005e
dc.w 0x005f
dc.w 0x0060
dc.w 0x005d
I suppose my acces to the tilemap file (level1_map) is wrong...
Or value i'm reading are not value i'm expecting.
what should be return : level1_map[10+(10*160)]?
We're supposing wanted to know what is the tile at place 10*10 in the map...
Posted: Sat Dec 22, 2012 4:33 pm
by oofwill
It's working! I don't know why but it's working.
I've tried and tried again, and finally it's working:
Code: Select all
for (i=0; i<=45; i++) //affichage de notre niveau visible
{
k++;
l=0;
for(j=0; j<=30; j++)
{
VDP_setTileMap(APLAN, TILE_ATTR(1,0,0,0)+(level1_map[i+j*160]+1), k, l);
l++;
}
}
Many thanks djcouchycouch to look at my problem
