[TI BASIC] Subroutines and unarchiving in BASIC

Got questions? Got answers? Go here for both.

Moderator: MaxCoderz Staff

CompWiz
Calc King
Posts: 1950
Joined: Thu 13 Oct, 2005 1:54 pm
Location: UB

[TI BASIC] Subroutines and unarchiving in BASIC

Post by CompWiz »

Is there any way to archive/unarchive BASIC programs on the calculator from a BASIC program?
Also, If I want to use subroutines in a program, do I have to make a new program to contain each subroutine?
I am working on adapting an old BASIC adventure game skeleton to TI basic as you can read in the announcing projects forum.

Edit kv83: Added tag.
Last edited by CompWiz on Fri 21 Oct, 2005 2:13 am, edited 1 time in total.
In Memory of the Maxcoderz Trophy Image
User avatar
kalan_vod
Calc King
Posts: 2932
Joined: Sat 18 Dec, 2004 6:46 am
Contact:

Re: Subroutines and unarchiving in BASIC

Post by kalan_vod »

CompWiz wrote:Is there any way to archive/unarchive BASIC programs on the calculator from a BASIC program?
Also, If I want to use subroutines in a program, do I have to make a new program to contain each subroutine?
I am working on adapting an old BASIC adventure game skeleton to TI basic as you can read in the announcing projects forum.
Well there is to ways you can do this
-Use zcopy to copy the program into a new one called ztemp
Or
-Run the program directly from the archive using flash Gordon (which is the best option IMO.

As for the sub routine, you make the sub in a new program and when you want to use it you just call the prgm in the main one.

Code: Select all

Example:
MAIN
:Pause "Hi Where Is Sub?
:prgmSUB
:Pause "There It Is!

SUB
:Pause "I'm Right Here ^.^

So you run prgmMAIN and it displays "Hi Where Is Sub?", then you press enter. It calls prgmSUB and it displays "I'm Right Here ^.^", then you press enter. Now it returns to prgmMAIN, and displays "There It Is!".

Sorry if you understand this already, but if not I hope this makes sense :D.
CompWiz
Calc King
Posts: 1950
Joined: Thu 13 Oct, 2005 1:54 pm
Location: UB

Post by CompWiz »

Yes, I know how to use programs as subroutines, but I was hoping to not have a whole lot of little subroutine programs. Thanks for the help with archiving. :)
Last edited by CompWiz on Fri 21 Oct, 2005 2:17 am, edited 1 time in total.
In Memory of the Maxcoderz Trophy Image
KevinJB
Calc Wizard
Posts: 501
Joined: Sat 28 May, 2005 5:34 am
Location: Chesapeake, Virginia
Contact:

Post by KevinJB »

Trick the basic interpreter into executing code in a for loop and return when it hit's the end. This might leak ram, I dunno. I've done it before. Something like:

Code: Select all

for (a,0,1)
If A
Goto Z
End

...

Code: Select all

Lbl Z
<sub code>
End
Something like that... :roll:
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
KevinJB | RevSoft
User avatar
kalan_vod
Calc King
Posts: 2932
Joined: Sat 18 Dec, 2004 6:46 am
Contact:

Post by kalan_vod »

Yeah it leaks pretty bad, but well just check UTI for that topic.
http://www.unitedti.org/index.php?showtopic=3629
CompWiz
Calc King
Posts: 1950
Joined: Thu 13 Oct, 2005 1:54 pm
Location: UB

Post by CompWiz »

Yeah, I read that post on UTI a few days ago. I don't want my program to grind to a halt after a little while.
Another question, is there any way to package several programs into a group and then have a basic program ungroup them when it is used? Also, is there any way to delete programs in basic?
Last edited by CompWiz on Fri 21 Oct, 2005 2:18 am, edited 1 time in total.
In Memory of the Maxcoderz Trophy Image
KevinJB
Calc Wizard
Posts: 501
Joined: Sat 28 May, 2005 5:34 am
Location: Chesapeake, Virginia
Contact:

Post by KevinJB »

Oops, that should be not(a instead of A (test if it equals zero not one ;)).

Indeed, it leaks tremoundously. I had found away to do it without them- wish I could remember :(.

And yes, I know what leaks are and how they occur.

PS: Want to see a easy example of what leaks can do?

Code: Select all

Lbl 0
For(A,0,1
If not(A
Goto Z
End
Disp "Bye
Goto 0
Lbl Z
Disp "Hi
End
Note the initial speed, then let it run for about two minutes. If you haven't recieved an 'Error! Memory' message by then; you'll at least notice the crawl it has been reduced too :-)
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
KevinJB | RevSoft
threefingeredguy
Calc King
Posts: 2195
Joined: Sun 27 Mar, 2005 4:06 am
Location: sleeping
Contact:

Post by threefingeredguy »

I posted how to use subroutines in your post about your TBA
Image
Gambit
Sir Posts-A-Lot
Posts: 252
Joined: Mon 21 Feb, 2005 5:34 am
Location: Laveen, Arizona

Post by Gambit »

Not sure if this has been brought up due to this topic appearing everywhere on various forums/threads, but I used a technique I found on ticalc.org ('cause I didn't want to think of one myself):

http://www.ticalc.org/archives/files/fi ... 14542.html

Considering its age (Sat Sep 2 19:36:55 2000! :o), it was (or may still be) pretty "advanced" concepts :wink:
"If SOURCE is outlawed, only outlaws will have SOURCE."
CompWiz
Calc King
Posts: 1950
Joined: Thu 13 Oct, 2005 1:54 pm
Location: UB

Post by CompWiz »

That looks like a good document(expecially for me, as I am terrible at optimizing for speed and size). I'm not sure if that method for subroutines will work for what I am doing, but I'll look into it. Thanks for all the help! :D
Last edited by CompWiz on Fri 21 Oct, 2005 2:18 am, edited 1 time in total.
In Memory of the Maxcoderz Trophy Image
DarkerLine
Calc Wizard
Posts: 526
Joined: Tue 08 Mar, 2005 1:37 am
Location: who wants to know?
Contact:

Post by DarkerLine »

A good document, but outdated - there are many more known ways to optimize now. Example:
then wrote:{Ans,0
While Ans(1
{Ans(1)-1,Ans(2)+1/(4Ans(1)-3)-1/(4Ans(1)-1
End
Disp Ans
now wrote:{Ans,0
While Ans(1
Ans-{1,2/(16Ans(1)^2+8Ans(1)-3
End
max(Ans
Last edited by DarkerLine on Fri 21 Oct, 2005 12:44 pm, edited 1 time in total.
just try to be nice to people.
_________________
My TI Blog - http://mpl.unitedti.org/
CompWiz
Calc King
Posts: 1950
Joined: Thu 13 Oct, 2005 1:54 pm
Location: UB

Post by CompWiz »

well once I finish, I'll be sure to upload the source code so you can optimise to your hearts content :lol:
In Memory of the Maxcoderz Trophy Image
User avatar
kv83
Maxcoderz Staff
Posts: 2735
Joined: Wed 15 Dec, 2004 7:26 pm
Location: The Hague, Netherlands
Contact:

Post by kv83 »

Please use the tag.
Image
CompWiz
Calc King
Posts: 1950
Joined: Thu 13 Oct, 2005 1:54 pm
Location: UB

Post by CompWiz »

kv83 wrote:Please use the tag.
sorry, tag? :?: :?
In Memory of the Maxcoderz Trophy Image
KevinJB
Calc Wizard
Posts: 501
Joined: Sat 28 May, 2005 5:34 am
Location: Chesapeake, Virginia
Contact:

Post by KevinJB »

[TI-BASIC]

He edit's it in to the topic title because he's a 'Nice Guy' apparently :). For future reference, you should include it in all your topics in the Programming Help category.
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
KevinJB | RevSoft
Post Reply