# Tips

Here we will write all tips we know about Fargo programming.

We've just wrote a part of the description of the VAT ! Go and see it !
WARNING: This is for TI92/92 II only . The VAT on TI89/92+ is slightly different. Mail me if you want infos about it.

When we have time, we will talk about:

- How to optimize in size a program
- Many other things..
If you have a tip and you want it to be on that page, mail us!

The VAT(variable alocation table) is a table which lists the variables and folders of your calc.
We will describe it in four parts:

1) The folder table
2) The variables tables
3) Some variables caracteristics
4) Some variable formats

1) The folder table

For all actual Roms, the folder table is associated with handle #$0B.
So when you do moveq.w #$B,d0
tios::DEREF d0,a0

You get in a0 the adress of the folder table:
It has the following format:

0(a0).w = maximum number of folders before handle #$B needs to be resized
2(a0).w = actual number of folders
We always have: 2(a0).w <= 0(a0).w

After this small header, there is the list, composed of the names of the folders, their state, and their associated variables list.
With addq.l #4,a0
You get in a0 the adress of the beginning of the list.
Here is the format:

0(a0) to 7(a0): 8 char name of the folder
8(a0).b : a end of string null character
9(a0).b : the state byte
10(a0).w : the handle of the associated variables list

Here is an example in hexa:

00 0A 00 03 64 6F 63 73 ....docs -> you see: maxfold = $A = 10, nbfold = 3
00 00 00 00 00 80 00 2E ........ -> handle to the 'docs' folder = $002E
67 61 6D 65 73 00 00 00 games...
00 80 00 2F 6D 61 69 6E ....main
00 00 00 00 00 80 00 0C ........

The state byte has the following format:

<76543210>: 7 is always set for a folder
5 is set when the folder is checked in the Var-Link or in Doors
3 is set when the folder is locked

For example, you can have
6D 61 69 6E 00 00 00 00 00 80 00 0C
name= "main" null char state byte handle

Then the name of the folder is main, it is NOT locked and NOT checked, and its handle is #$C (in fact it is always #$C for the 'main' folder)

2) The variables tables

They have nearly the same format than the folder one: they have the same header, and the same list format
The only thing that changes is the state byte format:
7 is never set for a variable

So, you can have, for example
66 69 6C 65 6C 69 62 00 00 00 00 16
name="filelib" null char state byte handle

Then the name of the variable is filelib, it is NOT locked and NOT checked, and its handle is #$16

3) Some variables caracteristics

When you have the handle of a variable in d0,you can do:

tios::DEREF d0,a0

You get the adress of the content of the variable in a0

After that ALL variables have the following format:

0(a0).w = size of the variable WARNING! This is not the real size of the var: you must add #2 to get the real size

Then you can do:
move.w (a0),d1 and you have

1(a0,d1.w) = the type byte of the variable

This type byte can be one of the followings:
$DC -> PRGM or FUNC
$D9 -> MAT or LIST
$E0 -> TEXT
$2D -> STR
$DD -> DATA
$E1 -> FIG
$DF -> PIC
$DE -> GDB
$E2 -> MACR
All other values are EXPR variables

To distinguish the PRGM and FUNC type you have to do:

cmp.b #$19,-5(a0,d1.w)

If -5(a0,d1.w) is not #$19 then the variable has the FUNC type,else it has the PRGM type.

Now you will maybe know how to distinguish Fargo vars and normal PRGM vars.
Let's do the following:

cmp.l #$4150504C,8(a0) ;comp with "APPL"
beq \Fargo II prog
cmp.l #$00503130,2(a0) ;comp with "P10"
beq \Fargo I prog
cmp.l #$444C4C20,8(a0) ;comp with "DLL "
beq \Fargo II library
cmp.l #$004C3130,2(a0) ;comp with "L10"
beq \Fargo I library

And that's all for the PRGM type !

To distinguish the MAT and LIST type you have to do:

cmp.b #$D9,0(a0,d1.w)

If 0(a0,d1.w) is #$D9, then the variable has the MAT type else it has the LIST type

4) Some variables formats

We only know the following variables formats:
TEXT variables
PIC variables
STRING variables

TEXT variables

Suppose you have a TEXT variable handle in d0.
With tios::DEREF d0,a0 you get in a0 the variable adress

From then you have the following format:

(a0).w = size of the variable - 2
2(a0).w = position of the cursor in the TIOS editor or in XeTal
from 4(a0).w to the end = your text.
Text has the following format:
#13 = nextline
#20 = beginning of a line. It is always after a #13 char or a the very beginning of the text
#0 = end of the text
At the end of a TEXT variable, you have a #$E0 char, it tells you that it is a TEXT variable

PIC variables

If a0 is the variable adress, then you have:

(a0).w = size of the variable - 2
2(a0).w = height of the picture
4(a0).w = width of the picture
from 4(a0).w to the end = your picture
If a bit is set, then the pixel is on, else, it is off
At the end of a PIC variable, you have a #$DF char, it tells you that it is a PIC variable

STRING variables

If a0 is the variable adress, then you have:

(a0).w = size of the variable - 2
2(a0).b = a null char (#0)
from 3(a0).b to the end = your string, it ends with a null char (#0)
At the end of a STRING variable, you have a #$2D char, it tells you that it is a STRING variable

If you want to add something about these formats, or you know the formats of other variables types, you can mail us