Feature: TI-83 ASM Tutorial (Part 2)
Posted by Nick on 12 April 2000, 03:02 GMT
Jeff Chai takes the microphone once again in his second feature here at ticalc.org. Here, he elaborates a little more on some more intermediate TI-83 Plus ASM topics. Tutorial 5 Assembling Asm Programs Overview You will learn the steps to assembling Asm programs using TASM. Background Information TASM stands for Telemark Cross Assembler. The TASM assembler assembles for the Intel 8080 processor. What!? But we're assembling for Zilog's Z80 processor! Don't worry =) When the Z80 was developed by Zilog (A renegade group of Intel engineers), it was highly based off of the Intel 8080. In fact. they are cross compatible! That's why we're using TASM to assemble our programs. Checklist for Assembling - Is the program written in z80 Asm?
- Does the program have a .z80 file extension?
- Have you self checked it for errors?
- Have you had a friend (or me) check it?
- Have you properly installed all the software?
- Have you backed up your calculator?
Once this checklist is completed, continue on. Assembling Programs Now, copy the program you've written from the "MyPrgms" folder to the "TASMassembler" folder. Next, in the "TASMassembler" folder, make sure if you used any include files that they're in the folder along with the written program. In the "TASMassembler" folder, create a new text file called "Start.bat". You may edit this file later by right clicking on it and clicking on edit. In the "start.bat" file type in asm progname. Where progname is the name of the program you've written. Do not include the .z80 extension when typing in the name. Now save it and close the file. Now, to start assembling the program, click on the "start.bat" file. If all goes well, the assembler should have outputted a .hex file. If it did go on. If the assembler gave you an error message, click here to try to debug it. Sending and Running Open the progname.hex file in the "TASMassembler" folder. Select the entire contents of the file and copy it. Then open the TI-Graph Link program and type in AsmPrgm in the new program editing area on the right. Paste the contents of the .hex file there. Give it a name and send it to RAM. Make sure if you're using a Graph Link, that the link is securely connected to one of the computers COM ports. Then, on the calculator, press [2nd] + [Catalog] . Then scroll down to Asm (. Hit enter to paste it to the home screen. Then hit [Prgm] then select your program. Hit Enter. The home screen should look like this: Asm ( prgmprogname Hit enter to execute the command. Your Asm program is now running! What if it Crashes? If you don't have a Graph Link, create a new program on the TI-83 Plus. Paste the AsmPrgm token in the program. Then you'll have to hand copy each charater from the .hex file to the calculator. Compiling To compile your program, paste the AsmComp( token from the catalog. Then paste the program you want to complile to the screen, then hit the , button. Then, from the catalog, paste the Prgm token to the screen. Then type in a name up to 8 characters long. It cannot be the same as the program you are compiling. Your calc screen should look like this: AsmComp(prgmprogname, prgmprogname2 Hit enter and your program has now been compiled. You can run the program the same way as the program before you compiled it. Tutorial 6 Moving the cursor to the next line Overview This is a seemingly worthless but none the less important tutorial on moving the cursor to the next line. The Source Code This code will move the cursor to the new line. #define B_CALL(xxxx) rst 28h \ .dw xxxx #define B_JUMP(xxxx) call 50h \ .dw xxxx _homeup =4558h _newline =452Eh _clrlcdfull =4540h .org 9D95h B_CALL(_clrlcdfull) B_CALL(_homeup) ;Call up the home screen B_CALL(_newline) ;Move cursor to next line ret ;Return home .end END Explanation The screen should look like this after you run the program: As you can see, there is an empty line on the top of the screen followed by a "Done" message and the blinking cursor on the next line. If it weren't for the "Done" message, the cursor would have been on the preceding line. The point is, the cursor isn't on the "First line". But rather on the next "empty" one. New Commands _newline - sets the cursor on the next "empty" line. Related Commands Did you know there is actually a ROM call that displays the "Done" message on the screen? Well that call is _DispDone (_DispDone = 45B5h). Try it out. Tutorial 7 Displaying Text Overview This tutorial will show you how to make a program that will display normal and inverse (white on black) text. Programming The program below will display normal text on the home screen. The program uses the calls we have already learned, and adds some new ones. In a future tutorial, we will make a program that displays small text. #define B_CALL(xxxx) rst 28h \ .dw xxxx #define B_JUMP(xxxx) call 50h \ .dw xxxx _clrlcdfull =4540h ;The calls we will be using are defined here or use an include file _homeup =4558h _puts =450Ah CURCOL =800Dh CURROW =800Ch .org 9D95h B_CALL(_clrlcdfull) ;Clear the screen B_CALL(_homeup) ;Bring on the home screen ld a,0 ;Load "a" register as zero ld (CURCOL),a ;Load zero into the y coordinate ld (CURROW),a ;Load zero into the x coordinate ld hl,txtLabel ;Load text from label below B_CALL(_puts) ;Put text on screen B_CALL(_clrlcdfull) ;Clear screen ret ;Return to OS txtLabel: ;the "Label" can be replaced with any name you want ;as long as you change the one on the top .db "This Program " .db "displays text " .db "on the home " .db "screen. It can " .db "be up to 16 char" .db "long, it can " .db "only be 8 lines " .db "long. ",0 .end END New Commands Used (CURCOL) - the y coordinate of the cursor (CURROW) - the x coordinate of the cursor _puts - Puts the text on the screen. This command will bring the specified text to the screen. _getkey - Detects a key press on the key pad ld - z80 instruction fo loading something. In this program, it loads 0 (zero) to the "a" register. The syntax is - ld (register), (value#) Registers The calculator's memory is where nearly all data is stored. Unfortunately, memory access is relatively slow for the processor. So, when we want the processor to manipulate data, like add two numbers together, we don't want to do it in the memory. Instead, we load the data into special fast memory locations inside the processor itself called registers. In the normal text displaying program (above), the value "0" was saved into the "a" register. The value in the register was then in turn, loaded in to CURCOL and CURROW (the X and Y coordinates of the text). Registers are extremely important! If you don't understand them, I recommend that you read tutorial 4 in Andy S.' tutorials. Inverse Text Jeez, things just keep getting better. Inverse text is normal font text (white) on a black backround. This program will display the text "TI-83 Plus Asm" in inverse text. All you need to know to display inverse text is loading text coordinates and setting textinverse mode. #define bcall(xxxx) rst 28h \ .dw xxxx #define bjump(xxxx) call 50h \ .dw xxxx _clrlcdf =4540h _homeup =4558h _puts =450Ah CURCOL =800Dh CURROW =800Ch textinverse =3 ;See the new commands section for more information textflags =5 .org 9D95h bcall(_clrlcdf) bcall(_homeup) set textInverse,(iy+textflags) ;Sets the textinverse mode ld a,0 ;Load 0 to the "a" register ld (CURCOL),a ;Setting Y coordinates ld a,0 ;Loading 0 to the "a" register ld (CURROW),a ;Setting X coordinates ld hl,txtTIAsm ;Display text from the TIAsm label bcall(_puts) ;Put text on screen res textInverse,(iy+textflags) ;Resets the text inverse ret ;Return to OS txtTIAsm: .db " TI-83 Plus Asm ",0 ;Text to be displayed on screen .end END New Commands Used set - z80 instruction that sets the characteristics of the TI res - z80 instruction which will reset the characteristic textinverse - Inverse text mode of the TI textflags - You don't need to know this yet Tutorial 8 Using Getkey to Detect Key presses Overview This will show you how to use the _getkey ROM call What is _Getkey? _Getkey is a ROM call similar to it's TI-Basic counterpart command, getkey. Getkey waits for a key press from the key pad. Then, depending on what you want to do, getkey can display the key code of the key pressed, execute another command, or act like a program pause. Programming This program will use _getkey as a program pause. #define B_CALL(xxxx) rst 28h \ .dw xxxx #define B_JUMP(xxxx) call 50h \ .dw xxxx _clrlcdfull =4540h ;The ususal constants and defines, look at the ;New Commands section for more information _homeup =4558h _getkey =4972h .org 9D95h B_CALL(_homeup) ;Call up home screen B_CALL(_getkey) ;Pause until next key press B_CALL(_clrlcdfull) ;After key press, clear screen. Or you can use ;any other clear screen command (Tutorial 3) ret ;Return to being a good old calculator .end END New Commands _getkey - Detect key press, store key code if nessasary Programming We will make our own program that displays the Hex key code of the key pressed.The code for the program is here. It looks complicated, but it really isn't. I'll comment the program along the way so you don't get lost. An important concept is the "stack". The stack holds numbers for future use or reference. In this program, it holds the hex code of each key pressed. #define B_CALL(xxxx) rst 28h \ .dw xxxx #define B_JUMP(xxxx) call 50h \ .dw xxxx _clrlcdf =4540h ;The ususal constants and defines, look at the ;New Commands section for more information _homeup =4558h _puts =450Ah _putc =4504h _getkey =4972h _newline =452Eh .org 9D95h B_CALL(_clrlcdf) ; clear screen B_CALL(_homeup) ; home the cursor ld hl,txt1 ; Display the message at the txt1 label B_CALL(_puts) B_CALL(_getkey) ; Detect key press push af ; Save key press in register a B_CALL(_clrlcdf) ; clear screen again B_CALL(_homeup) ; home again ld hl,txt2 ; Display msg2 B_CALL(_puts) ; Display text pop af ; restore reg a call dishex ; Follow commands at label dishex to find hex key code B_CALL(_getkey) ; pause until next key press B_CALL(_newline) ; Move cursor to next line ret ;Return to TI-OS dishex: push af ; keep copy of value and 0F0h ; terminate lower nibble rra ; shift nibble right 4 rra rra rra ld l,a ; Display the Key's hex code in Str1 ld h,0 ld de,hexStr push de ; keep for other nibbler add hl,de ; add offset to hexStr address ld a,(hl) ; find correct ASCII character from string below to ; display hex code of key pressed. bcall(_putc) ; display character pop de pop af and 0Fh ; wipeout upper nibble ld l,a ld h,0 add hl,de ld a,(hl) bcall(_putc) ret ; Return to OS hexStr .db "0123456789ABCDEF" ;These are the characters used to display ;the key's hex code txt1 .db "Push a key.",0 txt2 .db "Key code: ",0 .end END New Commands _putc - Display character and advance cursor push - Pushes a number on to the stack. pop - Takes a number off the stack. call - This looks like the TI-83 macro, and serves almost the same purpose, only for the TI-83 Plus, it jumps the program to a specified label. Conclusion This program wasn't exactly "lightning fast". That's because the _Getkey command was scanning the entire key pad for a key press. Later on, we will make a program like this one, only we'll narrow down the area in which _Getkey looks in for a keypress, making it faster.
|