Page 1 of 2

Using a map

Posted: Tue Jan 22, 2013 8:53 pm
by oofwill
I'm trying to use a map generated by genitile.

I'm using two map. One for drawing foreground of level, the second for object to collect (ex gold pieces)

I'm able to read the map so i can draw my foreground.
Then, able too to place my gold pieces using the second map.

But while taking a gold piece, i want to write the map to delete the piece at this place, but it doesn't work :|

Maybe i'm not using the good method?

My code reading and placing the gold piece tile (working)

Code: Select all

VDP_setTileMap(BPLAN, TILE_ATTR(0,0,0,0)+(level1objets_map[i+j*40]+1), k, l);
My code, trying to delete one gold piece:

Code: Select all

level1objets_map[i+j*40]=0;
VDP_setTileMap(BPLAN, TILE_ATTR(0,0,0,0)+(level1objets_map[i+j*40]+1), k, l);
tile 0 is transparent. but level1objets_map[i+j*40]=0; don't seems to work...

Posted: Tue Jan 22, 2013 9:14 pm
by TmEE co.(TM)
Are you trying to modify what is in ROM ?

Posted: Tue Jan 22, 2013 9:20 pm
by oofwill
With your comment i begin to understand that what i'm trying to do is impossible. :lol:

So i suppose i can't modify a value in map because it's read directly from rom?

How can i do to have a plan of where my items are, and modify it when one item is taken?

Posted: Tue Jan 22, 2013 11:29 pm
by TmEE co.(TM)
Perhaps generate a compact table into main RAM from the ROM map and do modifications there, and then compare the 2 and decide if an item is taken or not.

Posted: Wed Jan 23, 2013 1:46 am
by djcouchycouch
You'll need a copy of the level objects in ROM so that you always know their initial state when starting the level.

When you're playing the level, you'll need to make a copy of the level objects in RAM so that you can know what their state is.

When you restart the level, recopy the level object data from ROM to the copy in RAM.

Posted: Wed Jan 23, 2013 5:47 pm
by oofwill
Thanks for advice, i've been thinking this night and this is the solve i found.

I'll create a table in wich i copy map of the objects, as you say.

Thanks again, it's always more easier to find response when problem is written on a board, and after a good night too :lol:

Posted: Tue Jan 29, 2013 12:30 pm
by oofwill
Hi,

I'm now able to use a map correctly as you can see here

However, map is just 320*1728 pxls.

I've tried to test with a big map (792*1920pxl) and the problem is i can't compile project anymore:

Code: Select all

-------------- Build: default in Miracle_World_MD ---------------

Using makefile: C:\SGDK\makefile.gen
ld: address 0x1002bd2 of out/rom.out section .bss is not within region ram
make: *** [out/rom.out] Error 1
Process terminated with status 2 (0 minutes, 3 seconds)
0 errors, 0 warnings
 
I suppose map file is to big right? (size:47520 bytes)
if not, what means this message?

Posted: Tue Jan 29, 2013 12:43 pm
by Pascal
you're right your array is too big to fit within ram.

nice project btw :D Alex kid in miracle is a great game (childhood memory :))

Posted: Tue Jan 29, 2013 12:49 pm
by oofwill
Ok i see.

What is maximum size for it?
I will do it in several files :)

Yes, i really like Miracle World and want to play it sometimes, but don't want to plug in my master system :lol:

Don't sure i made the good choice beetwen plug my old system or reprogram the game :lol:

thanks :)

Posted: Tue Jan 29, 2013 1:45 pm
by djcouchycouch
If your map array is not declared as "const", then it'll be stored in ram. If your array is const, then it'll be stored in rom.

Posted: Tue Jan 29, 2013 1:45 pm
by Pascal
if you count
320 pix = 40 tiles
1728 pix = 216 tiles

40*216 = 8640 tiles * 2 bytes (size of one map entry) = 17280 bytes
almost 1/4 of your memory for a array... + add the memory footprint of the SGDK...

you don't have to do such big array in memory , as in alex kidd , i think you can not go back

Posted: Tue Jan 29, 2013 1:54 pm
by oofwill
Ok i see.

My map is declared as :

Code: Select all

* ---------------------------
.global level1_map
level1_map:
* ---------------------------
* size:47520 bytes

	dc.w 0x0000
	dc.w 0x0000
	dc.w 0x0000
	dc.w 0x0000
	dc.w 0x0000
	dc.w 0x0000
	dc.w 0x0000
	dc.w 0x0000
	dc.w 0x0000
	dc.w 0x0000
	dc.w 0x0000
	dc.w 0x0000
	dc.w 0x0000
	dc.w 0x0000
	dc.w 0x0000
	dc.w 0x0000
	dc.w 0x0000
How can i declare it as "const"?

I use to write:

Code: Select all

extern u16 level1_map[];
But i if write "extern const level1_map[];", this won't work since sgdk tell me it's declared as int...

And pascal, you're right, no use to go back in alex kidd, but as i'm new in coding, i try to build a correct scroll engine, in all direction, wich will be usefull for another game :)

EDIT: if i write extern const u16 level1_map[];
map will be stored in rom and not ram?

Posted: Tue Jan 29, 2013 2:10 pm
by djcouchycouch
Oh right, you're working in assembly. I was talking about doing it in C. I don't know what the syntax is in assembly.

Posted: Tue Jan 29, 2013 2:14 pm
by oofwill
I'm using assembly only for map. i think i'm complicating things :lol:

Posted: Tue Jan 29, 2013 2:45 pm
by Pascal
genitile can generate h file (btw good choice of tools :D)