Snake's Pit of ASM (and Other Stuff)

TSA is SO SCARY like what even IS it? How do I deal with it? What do you MEAN width and height - 1? Flips? What’re those? Ew icky. Why is the palette even bitpacked in there if BgMap_ApplyTsa lets you use different palettes wtf?!?
Yeah that’s how I feel about TSA too. It’s weird and confusing and a pain unless you have…

tmx2tsa

That’s right. You can use Tiled to generate TSA now. This is a long time coming, and I’m excited to release it. It’s really easy; all you need is an image of the tilesheet you’re basing your TSA on and tmx2tsa.exe. It’s that simple.

How to: Make epic custom tile-based UI

Okay so this is an executable with the following command line signature:

tmx2tsa (input.tmx) (ouput.dmp) (optional -p palette ID, default 1 since that seems to be what most UI uses) (optional -c filepath to compress.exe if you want it to be compressed)

After running, just #incbin the dmp!

When opening a new .tmx file to start, be sure that your tile width and height are both 8.

So normally we use Tiled in hacking for chapter maps, right? The "tiles" we use for chapter maps are NOT the same as "tiles" in the general sense.
  • In general for the GBA, a tile is a square of 8x8 pixels that is rendered to tile VRAM and displayed on a BG map by tile ID. TSA is for ordering these tiles.
  • In the chapter map sense, a tile is a square of 2x2 tiles (so 16x16 pixels), so when creating chapters, your settings are 16x16 per tile.

Just be sure that you have 8x8 per tile when using this tool. I hope this clears up confusion.

Anyway, I think the only other setting that matters in here is the Orthogonal setting. Set your width and height accordingly. Each other setting is arbitrary.

Next, I’m going to assume that you have an image of the tile sheet that you want to use. If someone requests it, I can include how I get this image.

Import this tile sheet as a tileset again with 8x8 tiles. From then on, it’s just like making a chapter map! PROTIP: On my Tiled setup at least, press X and Y on your keyboard to horizontally and vertically flip the tile you’re currently placing! Another fun thing is that Tiled updates your tile sheet in real time if you’re making edits to it, so this works well for fancy custom tiles as well. Don’t leave empty space I guess… I think that’s it. Once you’re finished with your tiles, run tmx2tsa on it, and your TSA is good to go!

Wait so what exactly is TSA again?

Someone please correct me if I’m wrong in this section.
I’ve been told that TSA stands for Tile Squaroid Assembly. Weird but whatever everyone calls it TSA. It is a ROM data structure that tells the game what tiles go where. Generally that’s really it.

It seems to often be used for UI, so let’s take that as an example. Say you want to display a UI blue box. First, you would load the tile sheet that you would use in tmx2tsa to tile VRAM and load the palette. (I believe most of the time there’s a single function that does both of these for you.) Your graphics are loaded in the form of tiles, but now you need something that actually renders the tiles. That’s where TSA comes in. I have the C structure signature of TSA as

struct Tile
{
	u16 tileID : 10;
	u16 horizontalFlip : 1;
	u16 verticalFlip : 1;
	u16 paletteID : 4;
};

struct TSA
{
	u8 width, height;
	Tile tiles[];
};

The structure begins with a width byte and a height byte. The structure represents a rectangle on the screen where you want to render the tiles. The X and Y positions are completely irrelevant to the structure itself, but width and height are… but these are actually width-1 and height-1. Don’t ask me why. The rest of the structure is an array of tiles (each tile is a short). The tiles run from left to right and bottom to top. Again don’t ask me why. Each tile is bitpacked where the bottom 10 bits refer to the tile ID, the next bit is for horizontal flip, the next is for vertical flip, then the top 4 bits are for palette ID.

See how this could be a headache to deal with?

You would then call BgMap_ApplyTsa to refer to your TSA and set your tile references to the BG map. (Actually you’d almost certainly set your tile references to the BG map buffer then have to enable BG sync but whatever.)

I’ve most recently made a little bit of custom UI for world map things. If you’d like an example on how I use it, I invite you to check there. Here’s what I was able to whip up for an edit to the world map text box!

Hope to see a bunch of new custom TSA out there! Have a nice day :wave:

15 Likes