Karma Universe - demuynck.org Lesson 3
TI-82 ASM Corner :: Programming Guide :: Lesson 3 Back | Home | Search
Lesson 3 : Your first program

In this lesson you will write your first program for the TI-82!
Well, you're not going to write it yourself, I'm going to give it for you. The programs in this lesson and all the following lessons are for Ash 3.0 or above, unless otherwise stated. Programming for CrASH isn't much different from ASH programming. Most (or all) of the ASH programs work perfectly on CrASH too. We will spend some time on explaining how to compile a program for CrASH only.

The program | Explanation | Compiling

The Program

#include "TI82.H"
#include "KEYS.INC"

.ORG START_ADDR
.DB "Example program",0

 ROM_CALL(CLEARLCD)
 LD HL,0
 LD (CURSOR_POS),HL
 LD HL,Data
 ROM_CALL(D_ZT_STR)
Pause:
 CALL GET_KEY
 CP G_ENTER
 JR NZ,Pause
 RET
Data:
.DB "My 1st Program!",0

.END
 

Explanation

Explanation
#include "TI82.H" Load the ASH header file (contains definitions and such).
This is a way to make the life of the programmer somewhat easier, because now he doesn't have to look up all the addresses of the functions in the ROM.
#include "KEYS.INC" Load key definitions. This way, you won't need to talk about keys with their number (each key on the keyboard has a unique number assigned to it), but you will be able to use the name of the key instead.
.ORG START_ADDR Let the program start at START_ADDR (all programs will be moved to that address before they are started, this address is $9104)
.DB "Example program",0 Title of the program. This is the title that will appear in the shell menu (Either Ash or CrASH)
Start of actual program
ROM_CALL(CLEARLCD) Clear the LCD
LD HL,0
LD (CURSOR_POS),HL
Put $0000 in the HL register and write the contents of the HL register to the memory location CURSOR_POS. This memory location is used by the system to hold the cursor position. So basically, we are putting the cursor to the left top of the screen (coordinates 0,0)
LD HL,Data Load HL with the address of label Data (see further)
ROM_CALL(D_ZT_STR) Write the string pointed to by HL (HL points to Data) on the screen in normal text (at the current cursor position, this is 0,0)
Pause: just a label
CALL GET_KEY Get the current key pressed
CP G_ENTER Check if it was the enter key
JR NZ,Pause If it was not enter or if no key was pressed, jump back to the Pause label
RET If it was enter, exit the program and go back to the shell
Data:
.DB "My 1st Program!",0
Zero terminated string. This is a string that is closed by a $00 byte. Another type of strings are length indexed strings. These have as a first byte the number of characters, e.g. .DB 5,"ABCDE"
.END Tells the assembler that he can stop processing data

Compiling

If you want to compile your program, you will need some programs to do this. There are two common shells on the TI-82: Ash and CrASH. When compiling a program specifically for a certain shell you will need different files. The examples in these lessons are all written for Ash 3.0.

Ash

Files you need
Name Description
Ash 3.0 The shell for your calculator. This package also contains the PRGM82.EXE, TI82.H, KEYS.INC and ASM.BAT files that you will need
TASM 3.1 The assembler that will translate your sourcecode to Z80 machine language. (TASM runs in DOS. A linux version is available from the TASM home page)

Now that you have all the files, you can compile your program.

Create a directory and put the following files in there : TASM.EXE, TASM80.TAB, ASM.BAT, PRGM82.EXE, TI82.H and KEYS.INC.

Create a new file which you call 1STPROG.ASM for example. In that file, you type (or cut and paste) the program from the top of this page. Don't use Word or any other fancy program to do this. Just use Notepad or EDIT.COM in DOS. Make sure that there is a space in front of each line that is not a label and that does not start with '#' or '.'. If you don't do this, TASM will complain about it or your program won't run as expected. The best programs to make and edit .ASM files are a simple text editor such as MS-DOS EDIT.COM, Windows NOTEPAD.EXE or TextPad

To compile your program, you have to open an MS-DOS prompt (There's a shortcut in the Win-95/98 Start Menu or you could do Run-'command').
Once at the MS-DOS Prompt, go to the directory where your program is and type :

C:\TI82>asm 1stprog (Leave off the .asm extension !)

The asm.bat file will run TASM first and after that, it will create a .82P file out of the output from TASM with PRGM82.EXE. This last program also fixes the checksum of the 82P-file. If TASM encounters errors, they will be listed on your screen. If you copied the source correctly, you should not see any problems.

Ash 3.0 Menu The 1stprog.82p file created by asm.bat can now be sent to the calculator using your Graph Link or Homemade Link (see Linking for more info about this) Make sure that you load Ash on your calculator BEFORE you load 1stprog !

The program! When you start the program on your calculator, the output will look like this !

CrASH 1.6

Compiling a program for CrASH is done in a slightly different way:

Files you need
Name Description
CrASH 1.6 SDK The shell for your calculator. This package also contains the CRPRGM82.EXE, CRASH82.INC and CRASM.BAT files you will need
TASM 3.1 The assembler that will translate your sourcecode to Z80 machine language. (TASM runs in DOS. A linux version is available from the TASM home page)

Now that you have all the files, you can compile your program.

Create a directory and put the following files in there : TASM.EXE, TASM80.TAB, CRASM.BAT, CRPRGM82.EXE, CRASH82.INC and the ASM file you want to compile.

To compile your program, you have to open an MS-DOS prompt (There's a shortcut in the Start Menu or you could do Run-'command').
Once at the MS-DOS Prompt, go to the directory where your program is and type :

C:\TI82>crasm progname (where progname is the name of the .asm file without the extension)

The crasm.bat file will run TASM first and after that, it will create a .82P file out of the output from TASM with CRPRGM82.EXE. If TASM encounters errors, they will be listed on your screen.

Previous lesson | Contents | Next lesson