SAVEKEY and LOADKEY For the Commodore 128 Version 2.0 May 23, 1987 Gene Pizzetta Commodore has included a nice program called KEYFIG with C128 CP/M that allows you to assign strings to your function keys (or any other key) or to completely redefine your keyboard. You could easily create a Dvorak keyboard if you wanted. The problem is that it's not so easy to change the key assignments if you'd like to have one set of function keys set up for NewWord or Word Star, another set for SuperCalc, a third for dBase II, and maybe a fourth for general utilities like taking disk directories. You've got to call up KEYFIG and change each key individually before loading your application program, or you've got to have several boot disks--one for each set of function key assignments. No More! SAVEKEY will save the current key assignments at any time to a small 1K file so you never have to recreate that set of assignments again. LOADKEY will load any file of key assignments into your CP/M BIOS within a couple of seconds after you enter a two-word command at the CP/M prompt. USAGE: SAVEKEY {{d:}} will save the currently active key assignments to disk under the given filename () on the given disk drive (d:). If you don't give a drive designation, the key file will be written to the current (default) disk. If you don't enter a filename on the command line, it will be requested by the program. It is not necessary to enter a filetype (extension) and if you do it will be ignored. All key files are created with a .KEY extension. If a file with the same name exists on the destination drive, SAVEKEY will ask if you want to overwrite it and abort if you don't enter "y". LOADKEY {{d:}} will load the key assignments in the given file () on the designated drive (d:) into the CP/M system. As with SAVEKEY, the current drive is assumed and you will be asked for a filename if you don't provide one on the command line. The file must have a nored. If no file by that name is found, LOADKEY will complain and return you to the CCP. CREATING CUSTOM FUNCTION KEYS: KEYFIG is very easy to use. It's self-prompting and includes its own help file, so I won't waste time and space explaining it's operation here. The keyboard can be set up just the way you want it and the new configuration can be saved to your boot disk so it comes up your way every time you boot the system. Custom key configurations for applications programs shouldn't be saved that way, though, because you don't want them in effect except when you're using the program. So, after setting up the keys for a particular program, choose the option to save the key assignments as "current definitions", exit KEYFIG, and save them to a file with SAVEKEY. The four function keys give you 12 possible key assignments as the unshifted, shifted, and control values. The caps-lock value should probably be the same as the unshifted value for your func tion keys or you won't have access to them when you have toggled caps-lock on with the Commodore key. Good candidates for assignment to function keys are application program commands that are used often and require you to enter two or more characters. For NewWord, for instance, you might want to assign such commands as ^P^B for boldface, ^K^B and ^K^K for marking a block, and ^O^G for temporary indent. Then you only have to press one key for those functions. You might even want to make the shifted or control values of your left and right cursor keys issue ^A and ^F to move forward and backward a word at a time. After you get the keys the way you want them, exit KEYFIG (after saving the new assignments as the current defini tions), and type: A>savekey nw to save the key configuration for NewWord on drive A as NW.KEY. Whenever you want to use NewWord, just load the definitions and call the program: A>loadkey nw A>nw sample.doc You can even do it all in one line: A>loadkey nw!nw sample.doc because CP/M Plus allows multiple commands in a single line, separated by an exclamation point. It would be a good idea to keep a copy of your default key defi nitions on each applications program disk along with the special key definitions so you can quickly change back to the normal definitions when you exit the program. If you use a color monitor and you prefer certain colors for particular programs, you can also use KEYFIG to change the logi cal colors for background and characters. The logical color table is saved to the file along with the key definitions. PROGRAM NOTES: Although Commodore's KEYFIG program allows ex tremely flexible use of the keyboard, I never made use of the function keys with applications programs because of the time it took to change them and then change them back when I was through. I dreamed of having a program to save definitions to disk so I could change the function keys quickly. After waiting for a year and a half for one to appear, I decided I was going to have to write it myself. These two utilities are very small: SAVEKEY is 4 records and LOADKEY is 3. That means that they load fast and work fast. SAVEKEY takes a little more time to open and write a file, but LOADKEY can load itself and a keyboard definition in about two seconds. To keep them small there is no error trapping so, if anything goes wrong during the disk read or write, the programs will be aborted by a BDOS error. The BIOS MOVE and XMOVE routines are used to move the key table between banks 0 and 1. The routines are called more or less directly through the BIOS jump table. As a result they are sys tem dependent. They have been tested, however, with the releases of August 1, December 6, and December 8, 1985, and work with all of them. I know of one earlier release (June 1985) but I doubt anyone is still using that warhorse so I haven't tested it. I tried to make these BIOS calls the "right" way by calling them indirectly through BDOS function 50. I couldn't get that method to work properly, so I abandoned the effort after a week of try ing. UPDATE: Version 1 was released February 25, 1987. I haven't been notified of any bugs and I haven't discovered any myself. However, if you have a file with a .KEY filetype that isn't a key definition file saved with SAVEKEY and you tell LOADKEY to load it, LOADKEY will promptly follow your orders and crash your sys tem. Frankly, I knew all along that that was possible, but I didn't believe anybody would be dumb enough to do it. Well, somebody was and did and reported it to me as a bug!! I don't think a small program such as this can possibly check for every possible operator error, so that particular "bug" won't be fixed. Nevertheless, consider yourself warned. Version 2 was released May 23, 1987. The most noticeable change is that my name is no longer displayed in the screen sign-on message. I decided that was an ego trip I should no longer in flict on the rest of you. The most important change in version 2 is for more sophisticated CP/M users. If the .KEY file is not found a failure return code is sent to the BDOS for use during conditional batch jobs. For instance, if you have a .KEY file you use with NewWord, you could issue the following command line: A>loadkey b:nw!:nw sample.doc Notice the colon before the second command. If LOADKEY does not find NW.KEY on drive B, it issues a "File Not Found" message, sends a failure code to the BDOS, and the CCP does not execute the second command to load NewWord. Without the colon NewWord would be loaded anyway. This same procedure will also work with SUBMIT. Lastly, to keep the programs from growing longer I have converted both of them to use Z80 relative jumps, rather than 8080 absolute jumps. It saves a few bytes, but Z80.LIB is now required for re- assembly. (Z80.LIB is included with the additional utilities from Commodore you got by sending in that card in your manual. If you didn't send the card in, you won't have MAC and HEXCOM, so you won't be able to re-assemble it anyway.) If you have any problems with either of these programs please let me know by letter, telephone, or through one of the bulletin boards below. Happy computing! Eugene L. Pizzetta 481 Revere Street Revere, MA 02151 (617) 284-0891 Bar-Ken FOG #29 (617) 288-4667 QuantumLink (GeneP) CompuServe (72060,505)