In preparation for TI-Concours, I picked up my TI-89t and tried to make a few programs with it. Among other things, I made a tilemap engine, so I thought I would share the code and explain the parts.
First, let's take a look at how indirection works. If you have an argument that requires a variable name, you can indirectly refer to it with a string. For example, you can draw a picture on the graph screen named sprite0 like this:
In that example, 'string' had the variable name and we used the indirection symbol '#' to tell the program to use the string as the variable name. This will do the same thing:
If you are familiar with the string() command, then you are probably coming up with all sorts of ideas already. For example, say you had a bunch of sprites named sprite0,sprite1,sprite2,… and you wanted to draw a sprite based on an input number:
Or to optimise this a little:
Now if 'num' holds the sprite number to draw, it will draw the appropriate sprite. Using this, we can make a tilemap engine that uses a matrix to hold the tile numbers and uses 8x8 tiles:
For a,1,8 ;8 tiles tall
For b,1,8 ;8 tiles wide
tilemap[a,b] is used to access each matrix element and shift(a,3) basically multiplies the value of a by 8. A more memory efficient way of storing tilemaps, though, is to use strings. For example, if you start your sprite index at sprite1 instead of sprite0, you can convert your matrix to 1-byte char() strings and then add them all together. So the conversion code:
Then to draw your tilemap, you can use the inverse function of char()— ord():
Or probably better:
Attached is a screenshot taken using CalcCapture. I tested it and unfortunately, the screenshot is about half the speed that it actually runs at, so keep that in mind!
This program is a little different from the code that is posted in that it uses another level of indirection. It takes two inputs for the name of the tileset and the name of the tilemap, so it is meant to be a general tilemap engine.