Omnimaga
Calculator Community => TI Calculators => Axe => Topic started by: souvik1997 on October 22, 2010, 09:45:26 am
-
I have 2 questions:
How would I copy an arbitrary number of programs to one giant program?
How would I read from a BASIC string variable?
Thanks in advance
-
I have 2 questions:
How would I copy an arbitrary number of programs to one giant program?
How would I read from a BASIC string variable?
Thanks in advance
Regarding your first question: are these compiled assembly programs? And would all the names already be listed somewhere in memory, or would program names be called one by one? Also, would all these programs be in RAM, or might some/all be archived?
As for BASIC strings, reading from them is much like reading from strings inside of Axe, except that Axe strings are strings of ASCII characters (http://tibasicdev.wikidot.com/83lgfont) and BASIC string variables are strings of tokens (http://tibasicdev.wikidot.com/tokens). To find the pointer to a string variable, you would do something like the following:
GetCalc("Str1")→P
And then you can just treat P like you would a pointer to a normal string in Axe, although taking note of the fact that it's a string of tokens and not ASCII characters.
-
All the programs will be in RAM, and the BASIC string will define which programs to copy.
-
Since all program names are in uppercase, you won't have to worry about all that token-to-char mess.
Let's say you have a BASIC string that looks like "ABC PROGRAM TESTPROGMARIO WHATISIT?" that contains all the program names, padded to eight chars each and ending with a "?" character. In the Axe program, you first find the string with
:GetCalc("Str1")→P
The pointer to the start of the string would be at P.
Then you would copy the chars in the string individually to someplace (so that you can get rid of the spaces):
:[]→GDB0
:.Name of program
:"prgm"
:[]→GDB1
:.Start of characters in name of program
:det(9)
:0→N
:.N is the Nth program name in the string, starting with 0
:0→C
:Repeat {N*8+P+C}-175
:.175 is the token code for "?"
:If {N*8+P+C}-20
:.20 is the token code for " "
:{N*8+P+C}→{GDB1+C}
:End
:C+1→C
:End
:0→{GDB1+C}
Then you find the actual program with
:GetCalc(GDB0)→Q
And now you can play with the data at Q (the program that the string points to) all you want. This is only for the first program in the list, though. To access the others, just change N.
I haven't actually tried it, and there are definitely a lot of optimizations you could do, but see if you can understand how it works.
-
Enjoy. :) All the information should be in the source file. I slaved over this for many an hour. ;)
Tell me if it works fine for you. I tested it and it seems to work. If you need the input style changed I can change it for you.
..AXE LIBRARY: MERGE
.<DESCRIPTION>
.This routine will merge multiple BASIC programs listed in an OS string into one program
.Author: Runer112
.Date: 10/24/10
.Insert style: Inline
.Parser version designed for: 0.4.5
.Size as of version 0.4.5: 342 bytes
.<INPUTS>
.Str0M1: Name of OS string containing program names
.Example format of data in OS string: "prgmPRGMNAMEprgmAprgmTEST"
.Str0M2: Output program name
.<OUTPUTS>
.Returns: 0 if failed, non-0 otherwise
.A program, the name of which is determined by Str0M2
.<DESTROYS>
.Last 24 bytes of saveSScreen (last 24 bytes of L₁ as of 10/24/10)
.<ROUTINE>
.Temporary program name storage (last 10 bytes of saveSScreen)
ᴇ05→{ᴇ89EC-10}r
Fill(ᴇ89EC-9,8)
.{ᴇ89EC-12}r = merge loop iteration/pointer to merged program, {ᴇ89EC-14}r = total length of merged program in first iteration, current position in merged program in second iteration
0→{ᴇ89EC-12}r→{ᴇ89EC-14}r
.Merge loop
Lbl 0ML
.Check that OS string exists, {ᴇ89EC-16}r = pointer to string, {ᴇ89EC-18}r = current position in string
If GetCalc(Str0M1)→{ᴇ89EC-16}r→{ᴇ89EC-18}r
.Repeat while position is not outside of string
While sub(0MC)
.{ᴇ89EC-20}r = current offset in temporary program name
0→{ᴇ89EC-20}r
.Repeat until current token = prgm (0x5F)
While {{{ᴇ89EC-18}r+1→{ᴇ89EC-18}r}→{{ᴇ89EC-20}r+1→{ᴇ89EC-20}r+ᴇ89EC-10}}-ᴇ5F
.If position is outside of string
!If sub(0MC)
.Break
Goto 0MD
End
End
.Done copying name
Lbl 0MD
.Replace last byte with 0
0→{{ᴇ89EC-20}r+ᴇ89EC-10}r
.Check that program to copy exists, {ᴇ89EC-20}r = pointer to program, {ᴇ89EC-22}r = length of program
If {GetCalc(ᴇ89EC-10)→{ᴇ89EC-20}r-2}r→{ᴇ89EC-22}r
.If second iteration
If {ᴇ89EC-12}r
.Copy program to merged program
conj({ᴇ89EC-20}r,{ᴇ89EC-14}r,{ᴇ89EC-22}r)
.If not last program to copy, {ᴇ89EC-24}r = backup of length of merged program
If {ᴇ89EC-12}r+{ᴇ89EC-24}r-sub(0MM)
.Append new line token
ᴇ3F→{sub(0MM)-1}
End
End
.Add length of current program (plus 1 for a new line token) to length of merged program
sub(0MM)→{ᴇ89EC-14}r
End
End
.If first iteration
!If {ᴇ89EC-12}r
.Attempt to create merged program and increase iteration count
!If GetCalc(Str0M2,{ᴇ89EC-14}r→{ᴇ89EC-24}r-1)→{ᴇ89EC-12}r→{ᴇ89EC-14}r→{ᴇ89EC-12}r
.Program creation failed, go to end
Goto 0ME
End
Goto 0ML
End
End
.Go to end
Goto 0ME
.Merge position check
Lbl 0MC
{{ᴇ89EC-16}r-2}r+{ᴇ89EC-16}r-{ᴇ89EC-18}r
Return
.Merge math
Lbl 0MM
{ᴇ89EC-14}r+{ᴇ89EC-22}r+1
Return
.Merge end
Lbl 0ME
-
Mhmm nice routine, I assume the code of the 2nd program just appear below the 1st and just the end of the first program and the header of the 2nd program are removed to make it one, right?
-
This is designed to combine multiple non-assembly programs into one. The reason I say non-assembly is because it should work for any programs that can be edited in the program editor, such as BASIC programs or Axe source code. It copies all the lines in the specified programs into one large program, adding new lines between the end and start of programs as necessary.
-
Ah ok :D
For asm I guess it migth be a bit hard since the data has to be at the bottom and the rest at the top, right?
-
And addresses would be all messed up. So no Axe executables, either :P
-
Thanks Runer, that is exactly what I needed. :)