Author Topic: How to rename an appvar (without copying into new and deleting old)  (Read 4713 times)

0 Members and 1 Guest are viewing this topic.

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Say I have to edit an appvar.

I can do that:
Unarchive it.
Edit it.
Archive it.


The problem with that is that I can lose all my progress if a RAM Clear occurs for some reason (like battery dead).

So I would like to do that:
Copy appvar to temporary one.
Edit temporary appvar.
Delete original.
Rename temporary with original name.

Archive renamed appvar.

So how do I rename an appvar (that is in RAM if that helps) ?
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: How to rename an appvar (without copying into new and deleting old)
« Reply #1 on: January 29, 2014, 03:04:20 pm »
It's a very painful process, and it requires ASM. Theorically, you have to find the address of the VAT header of your appvar (let's say you stored it in P), put the new name length into {P-6}, use _insertMem or _delMem at P-7 depending on whether the new name is longer or smaller than the previous one, and then write your new name from P-7 to P-7-{P-6}+1.
« Last Edit: January 29, 2014, 03:05:17 pm by Matrefeytontias »

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: How to rename an appvar (without copying into new and deleting old)
« Reply #2 on: January 29, 2014, 03:09:33 pm »
It's a very painful process, and it requires ASM. Theorically, you have to find the address of the VAT header of your appvar (let's say you stored it in P), put the new name length into {P-6}, use _insertMem or _delMem at P-7 depending on whether the new name is longer or smaller than the previous one, and then write your new name from P-7 to P-7-{P-6}+1.
Thanks. And if I smartly chose the name of the temporary appvar so that it has the same length as the original one, length is not an issue.
Now how do I get to the VAT header of the appvar (I have its name to find it but that's pretty much all) ? Is there another way than going through the VAT and Equ►String-ing everything ?
« Last Edit: January 29, 2014, 03:10:43 pm by Hayleia »
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline merthsoft

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 241
  • Rating: +63/-1
    • View Profile
Re: How to rename an appvar (without copying into new and deleting old)
« Reply #3 on: January 29, 2014, 03:28:22 pm »
Do you absolutely need to do it in Axe? You should be able to do it with ReadLine and WriteLine in the Celtic III libraries if you don't mind doing it in BASIC.
Shaun

Offline Juju

  • Incredibly sexy mare
  • Coder Of Tomorrow
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 5730
  • Rating: +500/-19
  • Weird programmer
    • View Profile
    • juju2143's shed
Re: How to rename an appvar (without copying into new and deleting old)
« Reply #4 on: January 29, 2014, 03:34:17 pm »
I did that a lot with Calcsys and its hex editor, provided it's the same length. Or else Doors CS might have a rename function I dunno.
« Last Edit: January 29, 2014, 03:35:10 pm by Juju »

Remember the day the walrus started to fly...

I finally cleared my sig after 4 years you're happy now?
THEGAME
This signature is ridiculously large you've been warned.

The cute mare that used to be in my avatar is Yuki Kagayaki, you can follow her on Facebook and Tumblr.

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: How to rename an appvar (without copying into new and deleting old)
« Reply #5 on: January 29, 2014, 04:10:54 pm »
I plan on including this in a standalone app/program (AudaciTI in fact) so Axe and ASM are fine, but Basic and Hybrid won't do.
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: How to rename an appvar (without copying into new and deleting old)
« Reply #6 on: January 29, 2014, 04:38:58 pm »
Okay so my investigations led me to something interesting : you can retrieve the pointer to the VAT header of a variable given its name with GetCalc(name [,size])Asm(EB)->P. I'm trying to write the actual code you need.

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: How to rename an appvar (without copying into new and deleting old)
« Reply #7 on: January 29, 2014, 10:52:10 pm »
Learn asm in 28 days actually has a page on the VAT. Using that info and matrefeytontias's trick you should be able to rename it.

Basically take the VAT pointer, subtract 7, and then write the name backwards. Make sure the program is in RAM though, otherwise when you unarchive it, bad things happen. (I don't remember specifically what, but I remember you don't want it to happen.)
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: How to rename an appvar (without copying into new and deleting old)
« Reply #8 on: January 30, 2014, 12:18:15 am »
Learn asm in 28 days actually has a page on the VAT. Using that info and matrefeytontias's trick you should be able to rename it.

Basically take the VAT pointer, subtract 7, and then write the name backwards. Make sure the program is in RAM though, otherwise when you unarchive it, bad things happen. (I don't remember specifically what, but I remember you don't want it to happen.)

It's actually not a problem with unarchiving, but having a disconnect between the real VAT entry and the copy in archive when a Garbage Collect occurs. Unarchiving afterward actually prevents problems in this case, because the incorrect entry in archive is then marked for deletion. The garbage collector takes the name from the archive copy and ChkFindSym's it to update the VAT entry in RAM, but if the name doesn't match, the entry never gets updated and it points to an invalid spot in archive, showing crazy sizes or error in the memory menu. In addition, the OS doesn't check whether it exists or not after searching, so it writes the new pointer to a particularly volatile spot in RAM that causes a crash the next time you get an OS error. Really bad stuff.
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: How to rename an appvar (without copying into new and deleting old)
« Reply #9 on: January 30, 2014, 12:47:06 am »
Since you two know your ways around the VAT, I have code working for renaming an appvar with a name of the same length as the original name or smaller. I do that by overwriting the name or shrinking the VAT then overwriting the name. But how do I enlarge the VAT to have a longer name than the original one ? I tried translating everything from the name address to $982E the corresponding numbers of bytes before its original location, and translating everything from $9830 to the name address, but that only leads to VAT corrupt and memory crash. What must I do ?

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: How to rename an appvar (without copying into new and deleting old)
« Reply #10 on: January 30, 2014, 05:38:55 am »
I have a problem, even with fixed length. Here is what I try to do for now:

Get size of archived appvar to edit works
Create temp appvar and keep the pointer to its VAT entry works
Copy content of original in temp works
Edit temp works
Delete original works
Rename temp using the pointer I kept doesn't work
Archive temp doesn't work (of course, I try to archive with the wrong name)


I think that the "Delete original" part changes the pointer to the VAT entry of the temp appvar so the one I kept is wrong, and the following "Rename" part renames nothing. Is that true ? How do I fix it ?

edit seems like (after some disassembly) using MEMKIT to look for the appvar knowing its name, then using "Print" and "ex hl,de" returns the pointer to the last letter of the name of the appvar... I'll try that this afternoon.
edit2 seems to work :D
« Last Edit: January 30, 2014, 06:02:53 am by Hayleia »
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s