Page 1 of 1

Max number of tiles in H40 mode

Posted: Thu Oct 24, 2019 6:06 pm
by cloudstrifer
Hi!

Is 1280 the maximum number of tiles in H40 mode?
I want to show 2 images with several tiles, but after that there is no space to allocate more than 2 or 3 sprites.

Thank you!

PLAN_A
stage_01_01_a.png
stage_01_01_a.png (29.71 KiB) Viewed 5132 times
PLAN_B
stage_01_01_b.png
stage_01_01_b.png (30.92 KiB) Viewed 5132 times

Code: Select all

	*paramInd = TILE_USERINDEX;
	VDP_loadTileSet(stage_01_01_b.tileset, *paramInd, DMA);
	paramMapB = unpackMap(stage_01_01_b.map, NULL);
	SYS_disableInts();
	VDP_setMapEx(PLAN_B, paramMapB, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, *paramInd), PlanXPosInTile, PlanYPosInTile, MapXPosInTile, MapYPosInTile, MapWidthInTile, MapHeightInTile);
	*paramInd += stage_01_01_b.tileset->numTile;
	//*paramInd = TILE_USERINDEX;
	//SYS_enableInts();
	MEM_free(paramMapB);
	
	VDP_loadTileSet(stage_01_01_a.tileset, *paramInd, DMA);
	paramMapA = unpackMap(stage_01_01_a.map, NULL);
	//SYS_disableInts();
	VDP_setMapEx(PLAN_A, paramMapA, TILE_ATTR_FULL(PAL1, FALSE, FALSE, FALSE, *paramInd), PlanXPosInTile, PlanYPosInTile, MapXPosInTile, MapYPosInTile, MapWidthInTile, MapHeightInTile);
	*paramInd += stage_01_01_a.tileset->numTile;
	SYS_enableInts();
	MEM_free(paramMapA);

Re: Max number of tiles in H40 mode

Posted: Fri Oct 25, 2019 2:51 am
by hotrodx
Hi. I'll try to answer to the best of my understanding.

Afaik, the maximum number of unique PLAN tiles is arbitrary. It depends on how you configure the VRAM layout.

However, by default, SGDK would upload the PLAN tiles at offset 0x0, while the sprites start at offset 0x03A0 (928th index). So if your unique PLAN tiles go over 927, it is already encroaching Sprite VRAM space.

You could make the VRAM sprite space smaller with SPR_initEx so that it can accommodate all your unique PLAN tiles. By default, 512 tiles are allocated for all sprites.

Also, make sure to optimize your tilemaps so it can reuse tiles by flipping and having duplicates.

Then, when allocating sprites, use SPR_addSpriteSafe so it can defrag the VRAM sprite memory to maximize the available tile space.