Omnimaga
Calculator Community => TI Calculators => TI-BASIC => Topic started by: Eeems on August 24, 2009, 01:48:31 pm
-
this is a small little piece of code I made that saves RAM/ROM wear by smartly running the prog
det(9 //loads the program list into Ans
if inString(Ans,"<progname> //checks to see if program exists
then
if inString(det(0,"<progname>",7),"A //checks to see if program is archived
then
"<progname> //saves the program name into Ans
real(10,0,1 //creates temp file
If ("BB6D"=det(14,"XTEMP001",0,2)) or ("BB6C"=det(14,"XTEMP001",0,2
Then
Asm(prgmXTEMP001 //runs temp file
Else
prgmXTEMP001
End
real(10,1,1 //deletes temp file
Else
If ("BB6D"=det(14,"XTEMP001",0,2)) or ("BB6C"=det(14,"XTEMP001",0,2
Then
Asm(prgm<progname> //if program is not archived, it will run it directly
Else
prgm<progname>
End
det(0,"<progname>",0 //and then archive it
End
[getkey] //just clears the last keypress and loads it into Ans
End
anything in [ ] is optional
EDIT: I have added Iambian's suggestion, with the Then command :P
hmm, I had also worked out a way to run a program that would run more without using the same temporary program, so you could have a huge tree of programs that would run each other without using the same temp program...of course it wasn't perfect, if you had another program run another, you wouldn't delete the last one you where on...I'll have to post the code when I remember it, so you guys can look at it
-
so I guess this would be useful for those who want to make a BASIC shell or a BASIC game with external levels, right?
-
yeah it would, but of course you have to hard code the program name into this, so yeah...
-
I just made a smart program archive/unarchive which would only try to archive/unarchive the program if it isn't and if it exists
:If θ
:Then
:If inString(det(9),Ans
:Then
:If not(inString(det(0,Ans,7),"A
:Then
:det(0,Ans,0
:End
:"DONE
:Else
:"ERROR
:End
:Else
:If inString(det(9),Ans
:Then
:If not(inString(det(0,Ans,7),"R
:Then
:det(0,Ans,0
:End
:"DONE
:Else
:"ERROR
:End
:End
it will return "ERROR" if the program doesn't exist to the Ans variable, otherwise it will return "DONE"
it uses the theta variable to tell if it should archive or not, 1 means archive, 0 means don't
-
Sorry after your 2nd post I don't know what it's supposed to do anymore. Could you post an example of what it does in a screenshot?
-
well this one will unarchive/archive programs only if they exist, and only if they are not archived/unarchived already. this one just makes it so the program doesn't have to be archived/unarchived at the start for it to work, it will put it into exactly what it wants you want it to be
the first one would run the program from the RAM only if it is on it, otherwise it will run it using a temporary program. this one saves ram wear and tear by a little bit
I'll post a screenshot tomorrow
-
A little side note for the first one, you can automate the selection of whether or not it's a "BASIC" program or an ASM program by making the following test:
If ("BB6D"=det(14,"XTEMP001",0,2)) or ("BB6C"=det(14,"XTEMP001",0,2))
Then
//run code if ASM binary or hex
Else
//run code if "BASIC" program (no ASM header)
End
That bit employs the BINREAD command to check the leading token to determine if it's HexASM/ASM (respectively). If the first two bytes does not contain those tokens, it's probably safe to assume it's a BASIC program. The difference between the runs of code would be the addition of the "Asm(" token, but at least it can be further automated in this fashion.
EDIT: The reason why there's two tests (the or statement) is because it's a slightly different "token" depending on the exact form of the ASM program. Though the user might end up using either one or the other, the run of code I posted helps ensure that there will be no error if that little fact is neglected. Also, I put BASIC in quotes because I'm pretty sure someone (like me) would create a binary data file that lacks a header and would most likely be interpreted as a BASIC program insofar as much as the built-in editor is concerned. Again, I'm pretty sure that's not much of a concern, but I want to make it clear in case someone forgets about that type of possibility too. Unfortunately, I've no way to automate detection of that scenario.
EDIT2: Fixed code to include the forgotten "Then" statement. Gosh, I am SO out of touch with BASIC, it's not even funny.
-
ah, well thanks Iambian :)
hmm I was wondering if you could make a file type detection command for the next version of Celtic III, it would be really handy for this type of thing
hmm, now to write this down and use it :P
EDIT: btw, you missed the then statement :P
-
"Filetype" as in "contents of header" ? If so, you'd want to look into det(9...), which is pretty much an ION-style file detector. In a space-delimited string, you can extract the file names that have that special header and run through the list one by one.
If by "filename", you'd want to look into det(32...)
Am I missing something?
-
I was just thinking of one that makes it easier....like having a command that will return something if the program in the argument is ion, or mirage, or dcs, or basic, or standard asm