What is this wizardry?!
How does it work?
I'll explain the process.
1. Find the first page starting at the end of the archive that is not an app, AND it with $FC and store that.
2. Find a suitable swap sector.
a. First scan the archive for a sector that starts with $FE (swap) or $FF (blank)
b. If that didn't work, look for a sector that doesn't have any valid programs in it
c. If that didn't work, screw it and use page 8.
3. Starting on page 8, and ending at the page found in step 1, begin copying everything to the swap sector.
a. First, search the page for a program that has a valid header (valid meaning not erased, good type, good length, and 0 < (name length) < 9)
b. Copy that program to the swap sector making sure to set the new address and page to where you are copying it
c. When the end of a sector is reached, erase it and continue on to the next one
d. If the swap sector runs out of space, just find a new one. (By this time, page $0C is guarenteed to be open.)
4. Find one last swap sector and copy sector 8 there (program by program because of the valid page thing)
5. Mark sector 8 as the swap sector and clear ram (to rebuild vat)
That's about it. I didn't include any code to try to optimize how the variables are stored in the archive, but, as you make new variables, they'll take up the little spots at the end. This was mostly done to increase speed, and because it would just be annoying to add.
Cool . I've never had issues, but I think I'll keep this topic in mind.
So, the TI-OS will claim another sector from the user sometimes? Interesting.
Ti-OS won't claim another sector, but some program might accidentally. If you write 00 to the first address of any sector, the OS will just stop using it. If it sees that the sector is invalid, rather than deleting it, it just ignores it.
Edit:
Source attached for your enjoyment.