User:Xizes/TI-BASIC

Because Allynfolksjr won't let me keep the good version of TI-BASIC on the article, I'm putting it here.

TI-83 Plus Series Code
If Then Else For( While Repeat End Pause Lbl Goto IS>( DS<( Menu( prgm Return Stop DelVar GraphStyle( AxesOff AxesOn Input Prompt Disp DispGraph DispTable Output( getkey ClrHome ClrTable GetCalc( Get( Send(

Input and Output
PROGRAM:INPUT :ClrHome :Input "Type a number:",A :ClrHome:Disp A :Pause PROGRAM:OUTPUT :ClrHome :Input "Type a number",A :ClrHome :Output(1,1,A) :Pause

Disp
PROGRAM:DISP :ClrHome :Disp "HELLO, MY NAME","IS SAM!" ,"" :Pause ________________ |HELLO, MY NAME | |IS SAM! | |              | |               | |               | |               | |               | |               | -

Examples
These examples are slightly TI-83-series-biased. For example, "ClrHome" would be "ClLCD" on the TI-85 and TI-86.

An entirely different command is required to clear the screen in the TI-89. Since output is generally displayed on the ProgramIO screen, the "ClrIO" command is required to clear the output screen. There exists a "ClrHome" command on the TI-89, and it performs its function - namely, clearing the Home screen. For the purpose of programs, however, this command is essentially useless (yet it is invaluable in the programming of functions).

Hello world
The following program, when run, will clear the standard output and print the phrase :

Z80 Series PROGRAM:HELLOWLD :ClrHome :Disp "HELLO, WORLD!"

68000 Series hellowld :Prgm :ClrIO :Disp "Hello, World!" :EndPrgm

Add integers and display sum
PROGRAM:COUNT :ClrHome :Input "Int.=",I :Input "Start=",S :ClrHome :Output(1,1,S) :While 1 :I+S→S :Output(1,1,S) :End

EnterCounter
This program will count how many times you press enter.

PROGRAM:COUNTER :FnOff :PlotsOff :1→A :ClrDraw:AxesOff :Text(6,12,"Counter v1.1") :Text(46,94/2,"Press [ENTER]") :Pause:ClrDraw :ClrHome:Disp :Output(5,6,"Times") :While 1 :1+A→A :Output(4,7,A) :Pause:End

Await keypress, display keycode
This program will loop indefinitely, waiting for a key to be pressed and informing the user of its keycode. Note that the "On" key will stop execution of a TI-BASIC program, and therefore does not have a keycode. (Some assembly subroutines can be called from a TI-BASIC program to clear this interrupt.)

PROGRAM:KEYCODE :Repeat Ans :getKey :End :Disp Ans

Bouncing 'X'
This code will simply make an 'X' bounce around the screen. You can find 'less than', 'greater than' and ' or ' under 2nd→Test

PROGRAM:BOUNCE :ClrHome :1&rarr;X:1&rarr;Y :1&rarr;S:1&rarr;T :Lbl A :While 1 :ClrHome :Output(Y,X,"X :X+S&rarr;X :Y+T&rarr;Y :If X<2 or X>15 :-S&rarr;S :If Y<2 or Y>7 :-T&rarr;T :For(I,1,50 :End :Goto A

Bouncing 'X' 2
This is another form of the same program. NOTE that the bouncing letter, symbol, or number does not NEED to be an X. It may be anything. Input "",Str1 lets you put in ANY letter, number or symbol. Str1 is found in VARS, String..., choose any string. Lbl (Labels) are found in PRGM as 9, and Goto is 0.

PROGRAM:BOUNCE (version 2) :ClrHome :Input"",Str1 :ClrHome :1&rarr;A :1&rarr;B :8&rarr;C :8&rarr;D :Randint(1,2)&rarr;E :Randint(1,2)&rarr;F :Lbl A :ClrHome :Output(C,D," " :Output(A,B,Str1 :A&rarr;C :B&rarr;D :If A=1 :1&rarr;E :If A=8 :2&rarr;E :If B=1 :1&rarr;F :If B=16 :2&rarr;F :If E=1 :A+1&rarr;A :If E=2 :A-1&rarr;A :If F=1 :B+1&rarr;B :If F=2 :B-1&rarr;B :Goto A

If you want, you may make the bouncing onject more than one letter, number, or symbol long. But, then you will need 2 spaces in ':Output(C,D," "', and 16 woul be substituted with another number in ':If B=16 :2&rarr;F'  a=number of letters in word/whatever / b=number to sub with 16, 17 - a = b.  (17 - 1 = 16.)

Number guessing game
This program is a simple number guessing game.

PROGRAM:GUESSNUM :ClrHome :DelVar T :randInt(1,50&rarr;Y :Disp "START GUESSING! :Lbl 0 :Prompt X :If X!=Y :Then :T+1&rarr;T :If X>Y :Then :Disp "TOO LARGE! :Goto 0 :Else :Disp "TOO SMALL! :Goto 0 :End :Else :ClrHome :Disp "CORRECT!","TRIES: :Output(2,8,T :End

Another Simple Number Guessing Game
This program picks a number between 1 and 10, and makes you guess it. PROGRAM:PICKNUMB :ClrHome :randInt(1,10)→A :Disp  "PICK A NUMBER" :Input "BETWEEN 1 AND 10",B :If B=A :Then :Disp  "YOU WIN!" :Else :Disp  "HAHA! YOU LOSE! :Disp   "NUMBER WAS",A

CASINO83
This game simulates random probability and is extremely addicting. (Updated 2-09-2007 4:50 PST)

PROGRAM:CASINO83 ::"TI-83+ Virtual Casino :Menu("Difficulty","Easy",A,"Normal",B,"Casino",C) :Lbl A :11→D :Goto Θ :Lbl B :10->D :Goto Θ :Lbl C :9->D :Lbl Θ :Menu("Continue?","Continue",3,"New game",7) :Lbl 7 :{0,2000}->LC83 :Lbl 3 :ClrHome :LC83(2)-200->LC83(2) :LC83(1)+200->LC83(1) :Output(1,1,"You have") :Output(2,1,LC83(1)) :Output(3,1,"dollars on hand+") :Output(4,1,LC83(2)) :Output(5,1,"in your bank")sfghjkl; :Input "Number:",N :ClrHome:0->Y :For(A,1,T) :randInt(0,10)->X :If X=N :Then:DB+LC83(1)->LC83(1) :Else:-1B+LC83(1)->LC83(1) :End:End:ClrHome :Output(1,1,"You have") :Output(2,1,LC83(1)) :Output(3,1,"dollars on hand+") :Output(4,1,LC83(2)) :Output(5,1,"in your bank") :Output(8,1,"Press enter") :Pause :If LC83< or =0 :Then :LC83(2)-200->LC83(2) :200->LC83(1) :If LC83< or =0 and LC83(2)< or =0:Goto BR :End :Menu("Continue?","Yes:,2,"Cash out:,5) :Lbl 5 :LC83(1)+LC83(2)->LC83(2) :0->LC83(1) :ClrHome:Stop :Lbl BR :ClrHome :Disp "Bankrupt!"

Move dot using arrow keys
A common feature of TI-BASIC game programming is programming the arrow buttons to move an object on the screen. This program will draw a dot on the screen that will move according to which arrow buttons pressed. The lines up to  set up the graph mode screen for use with pixel-by-pixel movement. PROGRAM:MOVEDOT :ClrDraw :-47&rarr;Xmin :47&rarr;Xmax :-31&rarr;Ymin :31&rarr;Ymax :0&rarr;X:0&rarr;Y :While 1 :Pt-Off(X,Y) :getKey&rarr;C :If C=24:X-1&rarr;X :If C=25:Y+1&rarr;Y :If C=26:X+1&rarr;X :If C=34:Y-1&rarr;Y :Pt-On(X,Y) :End

However, this code is both large and slow. Attempts have been made to optimize TI-Basic. The program below does the same thing as the program above, yet is far smaller, and somewhat faster. Note that the end parentheses for commands such as "Pt-On" (point-on) are not needed; often ending quotes, parentheses, brackets, and braces can be eliminated to save space.

PROGRAM:MOVEDOT :ZStandard :ZInteger :0&rarr;X:0&rarr;Y :While 1 :If K>0: Pt-Off(X,Y :getKey&rarr;K :X+(Ans=26)-(Ans=24&rarr;X :Y+(K=25)-(K=34&rarr;Y :Pt-On(X,Y :End

One thing might occur; if you hold down one of the arrow keys for a long time, it will skip the shading of a few pixels. Someone's gotta fix this. Matt, ARE YOU HERE?

Advanced Menu, Using GetKey
A more advanced example of a menu that can be used instead of the "Menu(" button (As in the 68K Calculators).

PROGRAM:MENU :ClrHome :Output(1,1,"==== MENU ==== :Output(2,1,"CHOICE 1 :Output(3,1,"CHOICE 2   :Output(4,1,"CHOICE 3 :Output(5,1,"CHOICE 4   :Output(6,1,"CHOICE 5 :Output(7,1,"QUIT       :Output(8,1,"==== MENU ==== :2&rarr;Y :Output(Y,4,"[ :Output(Y,13,"] :Lbl GK :DelVar K :Repeat K=25 or K=34 or K=45 or K=105 :getKey&rarr;K :End :If K=105:Goto DC :If K=45:Then :7->Y :Goto DC :End :Output(Y,4," " :Output(Y,13," " :Y+(K=34)-(K=25->Y :If Y>7:2->Y :If Y<2:7->Y :Output(Y,4,"[ :Output(Y,13,"] :Goto GK :Lbl DC :ClrHome :If Y=6:Then :Lbl QT :ClrHome :DelVar YDelVar K :Return :End :Disp "YOU PICKED","CHOICE :Pause Y :Goto QT

Exec: calling OS routines
In addition, some of the more advanced TI graphing calculators have something called "Exec", which gives the user some control of the 68k Motorola microprocessor by calling built-in subroutines in the calculator's operating system. However, because this gives the user full control of the microprocessing unit, a minor mistake could lead to crashes and loss of data.

Example on 68k Series Calculators: scrnoff :Prgm :Exec "4E444E754E750000" :EndPrgm

This is a simple (somewhat pointless) program that turns the calculator off from the home screen.

Checking Battery Power and Memory through a program
Note: This program only works on Omnicalc calculators. To get Omnicalc, you must have a TI-GRAPH LINK cable or TI Connect. You can go to Detached Solutions for the download.

PROGRAM:BATTMEM ::"Battery Status & Memory Usage :FnOff :ClrDraw :AxesOff:PlotsOff :ZStandard :real(33,"EFBF41EFB3502803EFD14A") :X→B :real(33,"EFE542EF9247EF5641EFD14A") :X→R :real(33,"EF4045C9") :Line(-5,2,5,2) :Line(-5,2,-5,-2) :Line(-5,-2,5,-2) :Line(5,-2,5,-1) :Line(5,2,5,1) :Line(5,1,5.5,1) :Line(5.5,1,5.5,-1) :Line(-3,2.5,-3,3) :Text(15,28,"Bad") :Line(4.75,2.5,4.75,3) :Text(15,62,"Good") :If B=0 :Then:4.75→W :Else:3→W :End :For(X,-4.5,W,0.1) :Line(X,-1.25,X,1.25) :End  :-5+(R/24261*10)→W :Line(-5,-5,-5,-9) :Line(-5,-9,5,-9) :Line(-5,-5,5,-5) :Line(5,-5,5,-9) :For(X,-4.75,4.75,.4255319149) :Line(X,-5,X,-4.25) :Line(X,9,X,-9.75) :End :Text(50,10,"RAM") :Text(50,75,"24K") :For(X,-5,X,-9) :Line(X,-5,X,-9) :End :real(33,"EF6F4CF578EF8C47EF6742EF6742F1EF8F47F7EFD14A") :X→O :Text(4,2,"OS v",O :real(33,"EFBA80EF8C47EFD14A") :X→H :Line(-1.75,6,-1.75,9.5) :Line(-1.75,6,9,6) :Line(-1.75,9.5,9,9.5) :Line(9,9.5,9,6) :For(X,-1,75,9,.4255319149) :Line(X,9.5,X,10) :Line(X,6,X,5.5) :End :Text(4,42,"Hardware v"),H :Pause

Mathematical Finance
It is possible to use the symbolic computations capabilities of TI-calculators to implement Mathematical Finance Programming in TI-Basic.

Screensavers
Following are some neat screensaver programs

Pixelate
This program pixelates the screen, which makes it look like it has a virus, but dont worry :).

PROGRAM:PIXELATE ::"Screen Pixelation :AxesOff:FnOff :ClrDraw :While 1 :randInt(0,62)→X :randInt(0,94)→Y :Pxl-Change(X,Y) :End

Amazingly, it can do much things and it takes up less than 100 bytes of mem. If you get rid of the line that says ::"Screen Pixelation, it will take evel less bytes. The line is there so you can access it from MirageOS.

Program:Crosshatch
PROGRAM:CHATCH :FnOff :ClrDraw :AxesOff :While 1 :For(C,1,50) :randInt(-10,10)→X :randInt(-15,15)→Y :Horizontal X :Vertical Y :End :ClrDraw :End

Another great screensaver...
It's SEISMOMETER TIME! This program monitors the shock waves generated by a few factors... not.

PROGRAM:QUAKESIM :Simul:AxesOff :FnOff :ClrDraw :While 1 :FnON 1,2 :"randInt(-10,10)sin(randInt(-10,10)X)"→Y1 :"0"→Y2 :DispGraph :End

C'mon! Try it.

Shootemup
I saw a comment of someone wanting a game, so here is a simple one I made. You have to shoot the alien spacecraft before he shoots you.

PROGRAM:SHOOTIT :ClrHome :8→A :1→F :1→G :-1→F :8→E :Lbl C :If A=E:Output(4,6,"HIT!" :For(D,15,250) :End :1→Z :8→C :0→D :Lbl A :E+F→E :randInt(1,3)→X :If E=1:F*-1→F :If E=1:2→E :If E=15:F*-1→F :If E=16:15→E :If A=0:1→A :If A=17:16→A :ClrHome :Output(1,E,"M" :Output(8,A,"W" :getKey→B :If B=24:A-1→A :If B=26:A+1→A :If B=21:Goto B :If E=A:Goto X :Goto A :Lbl B :C-1→C :If C=0:Goto C :Output(8,A,"W" :For(D,1,12) :Output(C,A,"+" :End :Output(C,A," " :Goto B :Lbl X :Z+1→Z :If Z=9:Goto C :Output(1,E,"M" :Output(8,A,"W" :For(D,1,12) :Output(Z,E,"+" :End :Output(Z,E," " :Goto X

This program could most likely be made better in many ways, but I didn't spend much time on making it.

Shoot 83
COMING SOON!