[SGDK] datatype for maps imported by genres?

SGDK only sub forum

Moderator: Stef

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

[SGDK] datatype for maps imported by genres?

Post by djcouchycouch » Thu Feb 23, 2012 3:12 am

How do I get at the data from an genres imported .fmp file?

What does the data type look like?

Thanks!
DJCC.

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

Post by Moon-Watcher » Fri Feb 24, 2012 10:58 am

Althoug the genres samples I found no way to use it directly in SGDK.

In my (very limited) experience, in AbbayeMD, I generated an .asm file from Kaneda's Mappy plugin MDPPY. That works for me.

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

Post by djcouchycouch » Fri Feb 24, 2012 11:29 am

Yeah, I think that's what I'll do. Another advantage being I can customize MDPPY to my liking. I was thinking of modifying it so that it outputs C structs as well since that's how I'd prefer the data to be formatted as.

KanedaFr
Administrateur
Posts: 1139
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Post by KanedaFr » Fri Feb 24, 2012 11:56 am

Code: Select all

struct mappyResource{
	ushort	width;
	ushort	height;
	ushort	*pal;
	ushort	nbTiles;
	ushort	compSize;
	uchar 	*tiles;
	ushort	*map;
};

struct mappyLevel{
	uchar	idxPal;
	ushort	idxTile;
	ushort  fieldAdr;
	ushort	scrollV, scrollH;
	struct mappyResource *data;
};
compSize is related to the coming soon compression method, used by tiles too

mappyResource is the export by GenRes
mappyLevel is a struct I use to draw this map

My (raw) way to use it, be free to fix/update/optimize it
I planned to add it on SGDK but not yet ;)

Code: Select all

void mappy_Load( struct mappyLevel *mLevel)
{
	ushort x, y;
	ushort	*curMap;
	
	Video_SetPal(mLevel->idxPal, mLevel->data->pal);
	
	if ( mLevel->data->compSize )
		unpack( (ushort*) (mLevel->data->tiles), GFX_WRITE_ADDR(mLevel->idxTile*32), mLevel->data->compSize);
	else		
		Video_DoDMA_copy( (uint) mLevel->data->tiles, mLevel->idxTile*32, (32*mLevel->data->nbTiles));
	
	curMap = (ushort *) mLevel->data->map; //s[ mLevel->idxLevel ];
	for(y=0; y < MIN(mLevel->data->height, 30); y++)
	{
		for(x=0; x< MIN(mLevel->data->width, 48); x++)
		{
			Video_Tile(x, y, (mLevel->idxTile+curMap[y*mLevel->data->width + x]) | ( mLevel->idxPal << 13 ), mLevel->fieldAdr);
		}
	}
}

void mappy_ScrollH( struct mappyLevel *mLevel, short value)
{
	if (value<0)
	{
		mLevel->scrollH = MAX( mLevel->scrollH+value, 0);
	}
	else
	{
		mLevel->scrollH = MIN( mLevel->scrollH+value, (mLevel->data->width-32)*8 );
	}
}

void mappy_ScrollV( struct mappyLevel *mLevel, short value)
{
	if (value<0)
	{
		mLevel->scrollV = MAX( mLevel->scrollV+value, 0);
	}
	else
	{
		mLevel->scrollV = MIN( mLevel->scrollV+value, (mLevel->data->height-28)*8 );
	}
}
void mappy_Update( struct mappyLevel *mLevel)
{
	short x, y;
	ushort posx, posy;
	ushort fakeC47, fakeC48;
	ushort fakeL29, fakeL30;
	ushort scrollTileH, scrollTileV;
	ushort	*curMap;
	
	curMap = (ushort *) mLevel->data->map; //s[ mLevel->idxLevel ];
	
	scrollTileH = mLevel->scrollH / 8;
	fakeC47 = (scrollTileH + 47)%64;
	fakeC48 = (scrollTileH + 48)%64;
	
	scrollTileV = mLevel->scrollV / 8;
	fakeL29 = (scrollTileV + 29)%32;
	fakeL30 = (scrollTileV + 30)%32;

	x = MIN(scrollTileH, 16) * -1;
	for (; x<48; x++)
	{
		posx = scrollTileH + x;
		Video_Tile(posx%64, fakeL29, (mLevel->idxTile+curMap[ (scrollTileV+29)*mLevel->data->width + posx]) | ( mLevel->idxPal << 13 ), mLevel->fieldAdr);
		Video_Tile(posx%64, fakeL30, (mLevel->idxTile+curMap[ (scrollTileV-2)*mLevel->data->width + posx]) | ( mLevel->idxPal << 13 ), mLevel->fieldAdr);
	}
	
	y = MIN( 2, scrollTileV) * -1;
	for (; y<30; y++)
	{
		posy = scrollTileV+y;
		Video_Tile(fakeC47, posy%32, (mLevel->idxTile+curMap[ posy*mLevel->data->width + scrollTileH+47]) | ( mLevel->idxPal << 13 ), mLevel->fieldAdr);
		Video_Tile(fakeC48, posy%32, (mLevel->idxTile+curMap[ posy*mLevel->data->width + scrollTileH-16]) | ( mLevel->idxPal << 13 ), mLevel->fieldAdr);
	}
}

Sample (the one you can see on genres test rom)

Code: Select all

extern struct mappyResource pengo;
.....
	pengo_level1.data = &pengo;
	pengo_level1.idxPal = PAL1;
	pengo_level1.idxTile = firstTile;
//	pengo_level1.idxLevel = 0;
	pengo_level1.scrollH = 0;
	pengo_level1.scrollV = 0;
	pengo_level1.fieldAdr = APLAN;
	
	mappy_Load(&pengo_level1);
.......
	mappy_Update(&pengo_level1);

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

Post by Moon-Watcher » Fri Feb 24, 2012 12:27 pm

Very appreciated

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

Post by djcouchycouch » Sat Feb 25, 2012 2:38 pm

awesome, thanks!

Post Reply