Axe doesn't natively support any data structures, but that doesn't mean you can't use any in your Axe programs. Because Axe allows you to manipulate the bytes and bits of your calculator all you want, you can make your structures, made in whatever way best suits you. Axe is a versatile tool.
One of the most useful data structures (by far) is the array. An array is just a list of data elements, which could be anything—bullets, enemies, lobsters, etc. In fact, if you think about it, a tilemap is a type of array (a two-dimensional one).
So how do you make an array in Axe? Well, first you need to decide where to put it. Any safe RAM area (L1
, L2
, etc.) will do. Just make sure it's reasonably big enough. Arrays can take a lot of memory.
Now decide how each element is going to be stored. What are you representing with each element? Just for the sake of example, let's say you're making a program to keep track of some squares floating around the screen but always going in one direction. You'd need to keep track of its X and Y values, as well as how fast it's moving horizontally and vertically. That would be four bytes per element. (You could probably cut it down to three or even two if you desparately needed to, but I'll keep things simple.) The array could look like this:
Element 0 | Element 1 | ... | ||||||
---|---|---|---|---|---|---|---|---|
XVal0 | YVal0 | XSpeed0 | YSpeed0 | XVal1 | YVal1 | XSpeed1 | YSpeed1 | ... |
Like with everything in Axe, we start counting from 0 because it makes our lives much, much easier.
To start working on our example, make a program called ASQUARE
as follows:
This will be our main program. It should be pretty simple to understand: it first initializes some data (the code for which we're going ot put in a subprogram called ASQUI
), then goes in a loop where it draws the squares until you quit. prgmASQUR
will hold our subroutines.
For program ASQUI
, just put this in:
That's it. L
will hold the current size (length, number of elements) of the array. It'll get updated whenever we modify the array (in the subroutine itself).