TI-Basic Z80 Programming/Hello, World!
To begin coding TI-BASIC on your calculator, you must use the program editor. This allows you to edit, manage, and run your programs. To access it, press the PRGM button, use the → key until the NEW tab is highlighted, then press ENTER. Then, type in a short name for your program. Naming guidelines include:
- Must include only uppercase letters and numbers, where the first character must be a character
- Cannot include any other tokens, such as symbols or math functions
- Maximum length of 8 tokens long
Press ENTER, and an empty program will appear:
To navigate the program editor, use the arrow keys to move the cursor, which is represented by a blinking black box. Press ENTER to move the cursor down a line, or to create a new line if the cursor is at the bottom-most line. To insert a line at any point, move the cursor to the end of the line above. Then press 2ND:INS(DEL):ENTER. To clear a line, press CLEAR. Press DEL on any empty line to delete it.
Always, the first line (
PROGRAM:EXAMPLE) shows the name of the program. Press ENTER. Now, a new line on the program editor is created:
PROGRAM:EXAMPLE : :
A colon signifies a new line of the program.
- Colons are automatically placed by the calculator when creating a new line. These colons cannot be deleted, except by deleting the line itself.
- Manually adding a colon (ALPHA::(.)) also signifies a new line. These colons can be deleted.
To run a program, you need to first exit the program editor. Press 2ND:QUIT(MODE) to return to the home screen. Press PRGM and use the up and down arrows to select your program. Now, press ENTER twice: once to paste it to the home screen and second to execute it.
To stop a program during execution, press the ON key and an error will be thrown, stopping the program.
Now that you have learned how to navigate and perform simple edits on a program, now we will program our first program: the "hello world." This simple program tells the calculator to display the text
HELLO, WORLD! on the screen.
PROGRAM:HLLOWRLD :ClrHome :Disp "HELLO, WORLD!"
Now, let's break down each line of this program and understand how it works.
Every new line in a TI-BASIC program automatically starts with a colon (:). It's how the calculator knows when a line ends and a new line begins. ClrHome (PRGM:I/O:8) is the instruction that clears the home screen, erasing any text or numbers that may have been on it.
:Disp "HELLO, WORLD!"
Disp (PRGM:I/O:3) displays a variable, value, or string to the screen. If the screen is full, it will scroll down a line. If the string is more than 16 characters, Disp will only show the first 15 of them, followed by an ellipse (...). During execution of the program, you will not be able to scroll and see the rest of the line if the 16 character limit is exceeded. Strings are displayed left-justified, and values are displayed right-justified.
In this example, the string
HELLO, WORLD! is printed to the screen.
| If you attempt to recreate the above example and get an output of
Another command offered for printing to the screen is the Output (PRGM:I/O:6) command. This command offers more arguments to specify where on the screen to print.
- Where row is the vertical positioning of the output. A value of 1 prints on the first row, etc.
- Where column is the horizontal positioning of the output. A value of 1 prints on the first column, etc.
- Where "text" or value is the text or value to be displayed to the screen.
Here's how to use this command in the "hello world" program:
:ClrHome :Output(1,1,"HELLO, WORLD!")
This program will result in the same output.
|On some old versions of the Operating System on the TI-83+, the calculator may crash if there are many other programs. You should update the operating system, or (preferably) program on the computer and then transfer to the calculator.|
You try it!
Try these examples to practice the Disp and Output commands.
Use the Disp commands to print a simple poem to the screen. Your poem should be 7 or fewer lines to fit on the screen (if you try to print an 8th line, the first line will move off the screeen).
:ClrHome :Disp "A POEM BY ME" :Disp "ALL BUT CLASSIC" :Disp "MADE TO YOU" :Disp "FOR TI-BASIC"
This example poem will print to the screen:
A POEM BY ME ALL BUT CLASSIC MADE TO YOU FOR TI-BASIC
Using Output, replicate the following output exactly. You will need to use the command more than once.
WELCOME TO THE TI-BASIC Z80 WIKIBOOK
:ClrHome :Output(1,2,"WELCOME TO THE") :Output(2,3,"TI-BASIC Z80") :Output(3,5,"WIKIBOOK")