blue_bear_94, I wouldn't assume everyone here knows C. Many new members come here for whom TI-BASIC (or Axe) is their first exposure to a programming language, and even among calculator programmers who start learning to program on a computer, C isn't one of more common languages unless they're planning to make 68K/Nspire/Prizm games.
The other problem is that your pseudocode in C isn't actually doing what the Axe code does. Specifically, lines 8, 9, and 10 are wrong because
value→{pointer} in Axe returns
pointer after the operation, not
value, when
pointer isn't a constant expression. So if you were to translate it to C, you would actually have
*(a) = r1; *(a + 1) = r2; *(a + 2) = r3; *(a + 3) = r4;. (Yeah, yeah, the evils of side-effect programming and all that. But in Axe it's called optimization. And it looks cool.) There's another minor error in line 3 because
L4 should be added, not subtracted.
So here's a complete breakdown of the code from the guy who wrote it
I'll start with routine ASB.
Say that somewhere in the middle of the game, there are two bullets. Both bullets are of the same type that you call type 1, and they're both traveling upwards at 3 pixels per frame. One is at position (13,37) and the other one is at (4,2). In that particular program I organized the array so that each element was composed of four bytes—type, speed, x-position, and y-position, in that order. If I remember correctly I used
L4 as the start of the array that would hold the all the bullets and the variable
Bn (as in
bullet) to keep track of the number of bullets in that array. So at that moment in the game,
B would be 2 and the array at
L4 would look like this:
Now we look at the code.
First, like with any math expression, you start at the innermost parentheses/brackets/braces. That would be this line:
B+1→B returns the new value of
B as a result. (Every single operation in Axe will return some number as a result, which you can use to chain into the next operation to save a few bytes.) In other words, this code is just an optimized version of this:
The first line takes
B, adds one, and stores it back to
B. (This is exactly the same operation as
B++, but the tutorial was written before the
++ command was added, and there's literally no difference between the two, so it doesn't matter.) So now
B is 3, which is the number of bullets we are about to have.
The value of the second line,
B*4+L4-4, is simply
L4+8. The next level up looks like this:
Since we know that the value inside the braces is
L4+8, you can see that now we're storing
r1 to
{L4+8}, and the data at
L4 now looks like this:
| Bullet 1 | Bullet 2 | Bullet 3 (incomplete) |
| | | |
But what about that
+1?
Turns out when you store something to a pointer that isn't constant (since
B*4+L4-4 isn't a constant number), the result it returns is the pointer you stored to—in this case,
L4+8. So the result of that entire line,
r1→{L4+8}+1, is
L4+9.
That gets passed to the next level up:
Again, we already know what the number in the braces is—it's
L4+9! So here's our array at
L4 again:
| Bullet 1 | Bullet 2 | Bullet 3 (incomplete) |
| | | |
We've added two bytes to the array at
L4 already. If you take a look at the code for the rest of ASB, you should be able to see that we're just repeating that last step twice with
r3 and
r4:
r3 ends up in
L4+10 and
r4 ends up in
L4+11. When the routine is done,
L4 looks like this:
| Bullet 1 | Bullet 2 | Bullet 3 |
| | | L4+8 | L4+9 | L4+10 | L4+11 | r1 | r2 | r3 | r4 |
|
Which is what we're trying to do.
Enjoy!
EDIT: Epic post time. Kinda makes me want to finish up those tutorials