Function Keys Robert Young, Chichester, Sussex. The Spectrum does not have a function key facility, and so I have written a machine-code program which allows any number of keys to be programmed very easily. This includes all the legends on the keys, the graphic symbols and the used-defined graphics, so that, for instance, the PRINT token can be programmed separately to the P and TAB. Of course, you will only wish to define keys you are unlikely to use for their normal purpose. The definitions of keys should be put in separate REM statements at the very beginning of the program. You should follow the line number and REM by the symbol you wish to program, a colon, and then the definition. The definition can be any combination of characters, graphics and legends. If you want it to execute automatically then end it with the hash - # - character. If a syntax error is found when the line is executed, the line will be displayed at the bottom of the screen with a question mark as normal. Note that a key whose definition is just a hash will act as an ENTER key. The colon that must be put between the key to be defined and the definition not only conveniently separates the two but also puts the computer into K mode. If, however, you wish to start the definition with a letter of the alphabet which cannot be accessed in this mode, it is necessary to type any token or symbol that puts the computer into L mode, such as a keyword, then to type the character you want, and finally to go back and delete whatever you used. [Or, of course, you can omit the colon at first, and only go back to put it in once you've typed the desired letter.] Rather than search through the whole program for key definitions, the program stops looking as soon as it finds the first proper program line. Therefore, all the defini- tions must be put before the main program. This can be quite useful if you want a key which has been programmed to revert to its normal purpose temporarily. Rather than deleting the definition, all you need to do is change its line number so that it is, for instance, at the end of the program. Then at a later date you can change it back again. Lastly, if a key is defined twice it is the definition nearest the beginning of the program that will be taken. Note that a programmed key will repeat if held down. The machine code is included in the data statements of the Basic program. The ninth figure of each statement is, however, the sum of the first eight and this is used by the program to check for errors in the data. Enter the Basic program, save it just to be on the safe side, and then run it. If an error is found the program will display the message Error In Line, followed by the line in which the error occurred. Note that the Basic program automatically alters the machine code if you have a 48K Spectrum, so that it is located at the top of memory - the actual data given is for the 16K model. The program will then display Prepare To Save and the normal message will appear at the bottom of the screen. You may then save the machine code. After this it will print Prepare To Verify. Rewind the tape to the point where you started saving the code and the program will verify it automatically. If this is completed successfully, the Basic program will NEW itself, leaving the machine code located at address 32348 for 16K machines or 65129 for 48K. In future, to load the machine code, type CLEAR 32347 for the 16K or CLEAR 65128 for the 48K, followed by LOAD ""CODE The program must be turned on before it will work. This is done by RANDOMIZE USR 32479 (16K) or RANDOMIZE USR 65260 (48K) To turn it off type: RANDOMIZE USR 32486 (16K) or RANDOMIZE USR 65267 (48K) Here are a few examples of key definitions: 1 REM !: PAPER 7: INK 0: CLS : BORDER 7# 2 REM .: PRINT 65536-USR 7962# 3 REM NEW: INPUT a$: IF a$="Y" THEN NEW# 4 REM :, REM 1 will reset all the colours - white paper and border, black ink - at a press of symbol shift-1. This is useful if you are developing a program using a strange combination of colours. Often, after stopping such a program, the listing is almost unreadable. REM 2 will print out how much free memory you have left on typing a full stop. REM 3 is a safeguard against NEWing a program acciden- tally. On pressing NEW, you must input a string. If you enter Y the program will NEW. Anything else will mean that the key press is ignored. Enter the NEW after the REM by typing a colon followed by the NEW, then deleting the colon. Finally, REM 4 allows you to type in quantities of data far quicker. It makes the space key act as a comma, avoiding the need for using the shift key.