Section 4.2 -- Creating lists, RAM files, and saved games
Section 4.2 -- Creating lists, RAM files, and saved games

Back to home

Creating Lists

Creating lists is fairly easy, but reading from them and using them as files gets very complicated. It's also a good introduction to what you'll be doing A LOT of in assembly. But, first thing's first. Why use lists over matrices, etc.? The nifty thing about lists is that they're the only variable on the calculator that can be modified by a BASIC program that can be named. There are only A-J in matrices, A-Z in variables, etc. But lists can be named LFILE or anything else. The calculator has six built in lists, L1-L6. These should not be modified by a user's program unless the purpose is to specifically import or export data from/to them. It's best to create one's own list. Storing data to a list is much like storing it to a variable. However, one must use {brackets} and commas. To store the numbers one through five to a list (L1, for example), use the following code:
:{1,2,3,4,5}->L1

To access the L1 token, press [2nd][1].


Custom Lists

Now, let's create a custom list! Custom list names can only be 5 letters long, and must have the small "L" in front of them to denote their listiness :). To create a list called LABC, store data, such as {1,2,3} to it. To get the small "L" token, press [2nd][List]{Right}[B]. So your code should look like:
:{1,2,3}->LABC

Make sure you name the lists for your program something unique to your program.


Specific Elements in a list:

It's important to know how to store and read specific elements in a list. This is done with using parentheses after a list variable. For example, to read the 7th number in L1, you would recall L1(7). To store a number to a place in the list, use something like "5->L1(7)". Be warned! that reading or writing to an element that does not exist (for example, trying to store 1 to L1(6) when L1 only has 3 entries) will cause an error.


Reading Elements from a list:

A good way to read lots of elements from a list is using a For loop. To read every element from list 1, use this loop:
:For(I,1,dim(L1),1)
:L1(I)
:End
The dim( function returns the length of the list. It's accessible from [2nd][List]{Right}[3]. This list goes from 1 to the length of the list, and reads every element in the list, but doesn't do anything with it. What if you want to read every 4th entry? Increase the step in the For loop like this:
:For(I,1,dim(L1),4)
:L1(I)
:End:
How will this come in handy? Well, you will see in a minute here.


Files for your programs:

This is where things can get a little complicated and confusing, so I apologize in advance if this is a little less clear. Your programs want to store data, right? What a better place to store it than a list! You can name it whatever you want, you can easy read things from it, and it protects your data from other programs messing it up.
There is no way to tell whether a list exists when you start your program up. You will need to include any lists with the installation package. Let's say you want to store shapes to a file. In this example I will use Argon's file to demonstrate. Before you start writing a large program, you will want to map out the file structure, or what data will be stored where. Argon's file structure is this:
The first ten are information about the file, such as serial numbers, locking, view, etc. Then, the structure repeats itself for each shape:
11: Shape Type
12: Location (X)
13: Location (Y)
14: Location (Z)
15: Radius
16: Direction (For faces and Cylinders)
17: Width (for Cylinders)
18: Empty
19: Empty
20: Empty
The Empty's are to save space, just in case anything else is added. Image having to re-write the entire program and file structure when you realize you forgot something. Adding "Empty" file data makes blocks you can come and use later.
Argon reads shapes from the list like this:
:For(I,11,LARG(5)*10+10,10)
;LARG(I) = Shape Type
;LARG(I+1) = Location (X)
;LARG(I+2) = Location (Y)
and so on.
:End
Starting from the top: The for loop uses the variable I. It goes from 11 (which is where the shape data starts) to a wierd number. What does LARG(5)*10+10 do? Well, LARG(5) stores the number of shapes in the file. Each shape uses 10 elements in the list, so, thus LARG(5)*10. Shapes start at 11, and not 1, so everything's incremented by 10, (thus the +10 on the end). And the For loop counts in steps of 10 because each shape takes up 10 elements in the list. So, basically, this code starts at the first shape, and jumps to every shape to the last one.

Section 4.3 -- Using with Mirage OS and Omnicalc