Author Topic: VAT tutorial  (Read 7750 times)

0 Members and 1 Guest are viewing this topic.

Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
VAT tutorial
« on: February 20, 2011, 03:19:54 pm »
Let's write another tutorial (I'm just in the mood today) Anyway, this'll talk about the VAT, specifically, the symbol table of the calculator where programs, appvars, and protected programs are found. Ever wonder how Axe displays a list of all the Axe programs on your calculator? Well, read on!

1. What is the VAT? (By VAT, I actually mean program table, even though that's not really what VAT means)
The VAT is a chunk of user RAM that keeps track of every program/prot prog and appvar in your calc. If you notice, when you delete a program in archive, you still free up some RAM; that program's table entry is erased.

Every entry in the VAT is backwards (annoying), and structured in the following manner:
Code: (thanks to Iambian) [Select]
==============================================
| -(n+6)    -6    -5   -4    -3    -2  -1  0 |
==============================================
| VarName  N.Len Page DadrH DadrL Ver  T2  T |
==============================================
Now for an explanation of each part:
T: Sort of important but not really: the first five bits are used to identify which object type the variable is. We'll get into this later.
T2: Completely useless to us. Ignore.
Ver: Tells the OS whether or not it can be sent across certain OSs. Ignore.
DadrL: More important: Tells us the low byte of the address of this object.
DadrH: The high byte
Page: What flash page? If in RAM, it'll equal 0.
N. Len: How long is the name
And from here, we have the name of the object (backwards)

Now, the location of the VAT is always changing. Fortunately the calculator stores it for us at address $9830. The address of the end of the VAT is stored in $982E.

Here's a code example on how to set up a loop that goes through the VAT, one entry at a time...
Code: (the little e is the scientific notation E) [Select]
{e9830}^^r->E     //set up
While E>{e982E}^^r  //While we're in the VAT
For(F,0,14)        //Copy backwards to L1. For some reason I couldn't get Copy()r to work...
{E-F}->{F+L1}
End
...stuff. Now you have your VAT entry sitting in L1...do what you want with it.
E-{L1+6}-7->E    //Increment the pointer "position" appropriately. Every entry is a different length, depending on the name length.
End

Now, you can use the value of {L1+3}r+2 as a pointer to the object without even needing a GetCalc statement. This even works with file pointers as well, storing {L1+3}r+2 to {oY1}r and {L1+5} to {oY1+2} allows you to use Y1 normally as well.

Offline FinaleTI

  • Believe in the pony that believes in you!
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1830
  • Rating: +121/-2
  • Believe in the pony that believes in you!
    • View Profile
    • dmuckerman.tumblr.com
Re: VAT tutorial
« Reply #1 on: February 20, 2011, 03:24:48 pm »
Nice.

One thing I wanted to say was that the T2 byte actually has some use. DoorsCS uses it to determine what folder a program is in.


Spoiler For Projects:

My projects haven't been worked on in a while, so they're all on hiatus for the time being. I do hope to eventually return to them in some form or another...

Spoiler For Pokemon TI:
Axe port of Pokemon Red/Blue to the 83+/84+ family. On hold.

Spoiler For Nostalgia:
My big personal project, an original RPG about dimensional travel and a few heroes tasked with saving the world.
Coding-wise, on hold, but I am re-working the story.

Spoiler For Finale's Super Insane Tunnel Pack of Doom:
I will be combining Blur and Collision Course into a single gamepack. On hold.

Spoiler For Nostalgia Origins: Sky's Story:
Prequel to Nostalgia. On hold, especially while the story is re-worked.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: VAT tutorial
« Reply #2 on: February 21, 2011, 11:52:01 pm »
Nice, should be useful to some people eventually. :D

Offline Michael Pang

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 19
  • Rating: +0/-0
    • View Profile
Re: VAT tutorial
« Reply #3 on: March 15, 2015, 07:26:20 pm »
Sorry for reviving, but can we use the VAT to rename variables? I've always wondered why doors can't rename files bigger than ram...

Offline Sorunome

  • Fox Fox Fox Fox Fox Fox Fox!
  • Support Staff
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 7920
  • Rating: +374/-13
  • Derpy Hooves
    • View Profile
    • My website! (You might lose the game)
Re: VAT tutorial
« Reply #4 on: March 16, 2015, 04:32:11 am »
I don't believe i've seen a function to do that anywhere

THE GAME
Also, check out my website
If OmnomIRC is screwed up, blame me!
Click here to give me an internet!

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: VAT tutorial
« Reply #5 on: March 16, 2015, 10:01:02 am »
While there are no OS functions to rename a variable in RAM, it is possible to do manually with a bit of work. However, it is not possible* to rename a varaible in ROM, since the VAT entry is duplicated in ROM, which cannot be modified.


* Technically possible, but to do correctly would involve a fair amount of manual flash operations essentially equating to a full user archive space defragmentation. There are probably only a couple of assembly programmers who could even pull this off.
« Last Edit: March 16, 2015, 10:19:01 am by Runer112 »

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: VAT tutorial
« Reply #6 on: March 16, 2015, 11:09:57 am »
I made a program for changing a variable's name (in RAM, as @Runer112 pointed out). Essentially, I made a new variable of zero size with the name I wanted. Then I just swapped all the VAT info except the names, and deleted the original.

This is probably the easiest way to do it, though somewhat slow and it requires up to 17 bytes of free RAM available.

Offline Michael Pang

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 19
  • Rating: +0/-0
    • View Profile
Re: VAT tutorial
« Reply #7 on: March 16, 2015, 06:21:24 pm »
@Xeda112358 What if you just changed the name directly?

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: VAT tutorial
« Reply #8 on: March 16, 2015, 06:27:27 pm »
@Michael Pang That's also a viable strategy, but an issue arises if the new name length isn't equal to the old. You'd then need to expand or contract the size of the name field of the entry, which would mean also shifting the rest of the VAT and the operator stack in memory.