using a map created by MDPPY

Ask anything your want about Megadrive/Genesis programming.

Moderator: BigEvilCorporation

Post Reply
oofwill
Very interested
Posts: 173
Joined: Mon May 03, 2010 6:12 pm
Location: France - Niort

using a map created by MDPPY

Post by oofwill » Thu Dec 20, 2012 8:45 pm

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?

djcouchycouch
Very interested
Posts: 710
Joined: Sat Feb 18, 2012 2:44 am

Post by djcouchycouch » Thu Dec 20, 2012 10:02 pm

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.
Last edited by djcouchycouch on Thu Dec 20, 2012 10:24 pm, edited 1 time in total.

oofwill
Very interested
Posts: 173
Joined: Mon May 03, 2010 6:12 pm
Location: France - Niort

Post by oofwill » Thu Dec 20, 2012 10:20 pm

Merveillous, it's working!

I've so many things to learn...

Thanks for your help!

djcouchycouch
Very interested
Posts: 710
Joined: Sat Feb 18, 2012 2:44 am

Post by djcouchycouch » Fri Dec 21, 2012 1:14 am

oofwill wrote:Merveillous, it's working!

I've so many things to learn...

Thanks for your help!
Good to know you're progressing!

oofwill
Very interested
Posts: 173
Joined: Mon May 03, 2010 6:12 pm
Location: France - Niort

Post by oofwill » Sat Dec 22, 2012 10:48 am

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

Image

that's wha's expected: (blue is color 0, transparent then)

Image

Seems only one line/2 is drawned...
tilemap is 160*30 tiles.

djcouchycouch
Very interested
Posts: 710
Joined: Sat Feb 18, 2012 2:44 am

Post by djcouchycouch » Sat Dec 22, 2012 11:08 am

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).

oofwill
Very interested
Posts: 173
Joined: Mon May 03, 2010 6:12 pm
Location: France - Niort

Post by oofwill » Sat Dec 22, 2012 12:21 pm

In fact, if i write x+y*160, result is:

Image

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);

djcouchycouch
Very interested
Posts: 710
Joined: Sat Feb 18, 2012 2:44 am

Post by djcouchycouch » Sat Dec 22, 2012 12:38 pm

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).

oofwill
Very interested
Posts: 173
Joined: Mon May 03, 2010 6:12 pm
Location: France - Niort

Post by oofwill » Sat Dec 22, 2012 1:37 pm

Result is the same, but VDP_setTileMap(plan, tile, x, y) is really fast! :shock:

Moon-Watcher
Very interested
Posts: 117
Joined: Sun Jan 02, 2011 9:14 pm
Contact:

Post by Moon-Watcher » Sat Dec 22, 2012 2:08 pm

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

djcouchycouch
Very interested
Posts: 710
Joined: Sat Feb 18, 2012 2:44 am

Post by djcouchycouch » Sat Dec 22, 2012 2:15 pm

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?

oofwill
Very interested
Posts: 173
Joined: Mon May 03, 2010 6:12 pm
Location: France - Niort

Post by oofwill » Sat Dec 22, 2012 3:15 pm

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...

oofwill
Very interested
Posts: 173
Joined: Mon May 03, 2010 6:12 pm
Location: France - Niort

Post by oofwill » Sat Dec 22, 2012 4:33 pm

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 :)

Post Reply