★ APPLICATIONS ★ PROGRAMMATION ★ KEY FACTS (PERSONAL COMPUTING TODAY) ★![]() |
| Key Facts (Personal Computing Today) | Applications Programmation |
If you're finding that the manual is a little difficult to follow in the area of key redefinition, read on for a full explanation and program. By David Ellis. The keyboard of the Amstrad CPC64 must be one of the most versatile ever produced on a micro — it is entirely 'soft'. All of the keys, including the joystick, can be programmed to produce any character with any key, in both shifted and unshifted modes, and also when the 'CTRL' key is used. Any key can be programmed to auto repeat or not, when held down, and the initial delay and repeat speed can also be set. Commands are available to test not only which key is pressed — as is usual on most micros — but whichever combination of keys is pressed. You could specify that four keys (or even more) have to be pressed simultaneously, before a certain operation is performed. Add to this the Now that last statement may be a little confusing to those of you who are familiar with the CPC464. Perhaps you thought that only the numeric pad could be used for funtion keys, and everyone knows that the maximum number of characters allowed is 1 20 in total. On the first point, the manual is not very clear. You can indeed use any key as a function key. On the second point — well it is possible very easily by using a machine code routine just 9 bytes in length. Key definition Before showing how this is done let's look at the basic operation of defining keys, and please don't confuse this with redefining of the ASCII characters themselves — this is done with the SYMBOL AFTER command and does not concern us here. Each of the keys on the keyboard (including the joystick) is given a number between 0 and 79. There is an apparent logical sequence for the way in which the keys are numbered. Appendix III page 16 in the user manual shows all the various numbers for the keys. The KEY DEF command is used to determine which characters appear on the screen when that particular key is pressed, and whether or not the key will auto repeat. Five parameters are required by this command:
For example, the 'A' key could be redefined to print the letter 'B' when unshifted, 'C' when shifted, and 'E' with the CTRL key, and auto repeat by the following line: KEY DEF 69,1,66,67 ,6969 is the key number for 'A'. Auto repeat is indicated by '1'B', 'C' and 'E' by 66, 67, and 69 respectively. Any number in the range 0 to 255 could be used for the last three parameters. However, the numbers from 128 to 159 are set aside for the 'expansion characters'. I shall refer to these as the keyboard functions.These are merely a string of characters which will be printed out when the appropriate key is pressed. The CHR$ function can be used at the beginning or at the end of the string if required. The function is set up by the keyword KEY. This is simply KEY, followed by a number between 1 28 and 159, followed by the character string. For example: KEY 128,"CLS" + CHR$ (13)When the key that uses this function is pressed, CLS will be printed on the screen, and the CHR$(13) will cause a carriage return to be issued — thus the screen will clear. All that needs doing is to assign this function to whatever key you wish by using the KEY DEF command. To put this function on the CLR key (number 16) the following could be used:KEY DEF 16,1,16,16,128The operation of the CLR key will remain the same in the unshifted and shifted states but with the CTRL key pressed, it will call the key function assigned to 128 — ie it will clear the screen.Key assignations It is now a simple matter to define whatever string function you require for the remaining function codes 129 and 159 and then assign these to whichever keys you desire. In most cases it will be better to use the CTRL key, but for some of the keys you could use the function in the shifted state — the RETURN key, SPACE BAR, and the keys on the NUMERIC PAD for instance, which are not normally used with the shift key. The only problem now, is that once the 1 20 characters are used up for the function strings, the BASIC interpreter will return an error condition and will not accept any more KEY functions. It is possible through the 'JUMPBLOCK' though, to set the starting address and the size of the buffer that is to hold the function characters. Line 10 in Listing 1 sets the 'Top of BASIC' to &9000 (36846 ), which is also the start of the 9 byte machine code program held in line 40. The start address for the buffer is held in the second and third bytes of the program, and this starts immediately after the machine code program at &900A (36874). Bytes 5 and 6 hold the length of the buffer (LSB/MSB), in this instance set to 0 and 4 (4 * 256 + 10 =1024), which is 1 K.
For most cases this amount will be ample. To set aside more buffer space, then the top of BASIC address, the LOCATION address, and the start of the buffer address should all be lowered by the same amount in bytes 5 and 6 of the machine code program. The rest of the program sets up the various functions and assigns them to the keys as shown in Table 1 . The first 20 function stings will return the string shown, whilst the last 12 function strings (Table 2) are used with the carriage return to perform some useful operations. You can change any of the strings to whatever you like. The ones presented here are the ones that I find are most useful for myself. You may prefer your layout to be different from mine.
Remember to SAVE the program before RUNning it for the first time as the program NEWs itself in line 100. You have been warned! Hopefully your friends with other micros will be green with envy when they see the functions that you can call up at the touch of one key — well two to be exact . Look — single key entry — a la SPECTRUM!!
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||