Editor's note: The information contained in this article may be outdated and/or inaccurate.
Good day (or evening) once again! Here is the Log which I should have put out a long time ago, but I frankly forgot. I'm very forgetful like that. Here goes the "Key Press" Log. Injoy, and maybe you'll learn something.Key Press
Alright. Key Press is one of the greatest features of the TI calcs. With this ability, menus can be made, games can be played, options can be set, and equations can be solved.
The keyboard of the TI 83 (and, as I believe, with all of the up-right calcs) is located at port (1). Now, in order to activate the keyboard, you need to send some data to (1). What you send to (1) depends on what keys you want to activate. For our purposes, we're going to activate the entire keyboard at onece, and that is done by sending the number (in decimal) 255. 255 is the largest thing you can store in the accumulator. This can be represented by 255d, FFh, or 11111111b. To send this to the port, you need to output it by using the 'out' command. 'out' works with the accumulator, and works like the 'ld' command. Here's what it looks like:
Just store 255d to the accumulator before this command to send it to the keyboard.
ld a,0FFh ;You don't have to put the
out (1),a 0 in there, but I do
Now the entire keyboard is active. You can activate certian rows at a time, if you wish, but I have not found that practical unless you are writing an action game (which, I know, most of you ARE, but you can learn direct input later, or from source). I use the command 'call _GETKEY' to do my Key Presses, just because it takes up less power to run the command, and, if you don't press anything (and don't turn it off), the APD (Automatic Power Down) will kick in after a few minutes. The '_GETKEY' command runs just like BASIC's 'getkey' command, but you can do thing in it like wait for <2nd> or <ALPHA> presses. Let's say for instance I wanted something to happen when I used the MEM key. Well, that's <2nd> <+>, and you can't do that with BASIC without making a complex, memory consuming "If" and "Goto" statements. With ASM, all you have to do is check for the key code that coresponds with MEM, and there you go. '_GETKEY' will recognize the fact that you press <2nd>, so pressing <2nd> <+> is different then just pressing <+>, if you follow me.
How do you use the '_GETKEY' command? Well, every key on the keyboard, including the combonations of <ALPHA> and <2nd>, has a key code. These codes are in hex, so they will all have a 'h' after them. The codes begin at 00h, if the <ON> key was pressed, up to FBh, which is the small <w>, which is a <2nd> function. After you activate the keyboard and use the 'call _GETKEY' command, the calculator halts until a valid key is pressed, meaning that the APD still works (which I have mentioned before). Also, when using the '_GETKEY' command, if you have nothing defined for <2nd> and either <Up> or <Down>, the contrast controls still work. After using the command 'call _GETKEY', the key's code that you press will be stored in the accumulator. So, if the <Enter> key gets pressed, 05h is stored in 'a'. All of the keycodes can be found on TI's website, the URL being www.ti.com/calc/docs/83asmkey.htm. With this information, you can check the key that was pressed and jump to a label in a program. The example below jumps to the label LABELONE when you press the <Enter> key.
You can also put the commands in a list. In this sample, the program will check for the <Enter> first, then it will check for <Alpha> <Math>, or <A>, code 9Ah. If it finds <Enter>, it will go to LABELONE. If it finds <A>, it will go to LABELTWO. Also, in this sample, as all keypress routines should be, this one will loop back to the keypress command if it finds anything else other than <Enter> or <A>. If, like in the above example, there is no jump command to go back to the '_GETKEY', the program will continue past the routine like normal, with the code for the key you just pressed in the accumulator.
Now, you can also define the codes in the begining of your program as named variables. For instance, instead of entering the command 'cp 05h', you could put 'cp kEnter'. The advantage of this is you don't have to remember the code for the key every time you want to use it. The disadvantage is you have to define all the keys you want to use this way in the begining of your code. This is done after the line '#include "ti83asm.inc"' or '#include "whatever.inc"'. The header equating (defining) 05h as kEnter and 9Ah as kA looks something like this:
#define equ .equ
#define EQU .equ
#define end .end
kEnter .equ 05h
kA .equ 9Ah
The previous sample using the two keys would now look something like this:
There is also a command called '_GETKY' which is exactally like it's BASIC counterpart, 'Getkey'. This command outputs the key code as a 2 or 3 digit decimal number in OP2. The codes are the same as those found in the TI-83 manual, page 16-20. The firts 2 digits of the code stored in OP2 is the row of the key just pressed (01-10), and the last digit is the actual key in the row (1-6). This command uses more of the calculator's power than '_GETKEY' because it doesn't halt and use the APD. It's also slightly faster than '_GETKEY', but not enough to make a difference unless you are making a percision action- or puzzle-style game. I never use this command, so I won't get into it at all. It's just nice to know it's there, I suppose, if you ever become an expert 83 ASM programmer.
This might just possibly be my last eddition to the Logs. Sorry I couldn't get around to program detection and the VAT, but school has come, and I'm getting a TI-89 soon. Once TI releases the command protocols, then you might just see the TI-89 Logs. Who knows?
Special thanks goes out to Lindsay. I wish everyone had a friend like her.
To Karen and Crystal, I'm really sorry, and I miss both of you.
And to Jamie, who I never got the chance to talk to very much, and I never will again. I never even had the chance to say "I'm sorry". You were the first, but not the last.
That's it. Now go offline and do your homework. -Phil