APPLICATIONSDIVERS ★ KEY DEFINER ★

Key Def (Practical Compµting)Applications Divers
★ Ce texte vous est présenté dans sa version originale ★ 
 ★ This text is presented to you in its original version ★ 
 ★ Este texto se presenta en su versión original ★ 
 ★ Dieser Text wird in seiner Originalfassung präsentiert ★ 

Dick Ruck's initialisation utility provides a convenient way of adapting the Amstrad soft keyboard to your own preferred applications.

WHEN I FIRST READ Amstrad's User Instructions manual for the CPC-464 I had visions of tailoring the keyboard to perform single-key keyword entry. But my illusions were shattered by two discoveries: there are only 120 characters to do all the things I wish, and I did not fully understand the Key and Key Def commands.

The Amstrad's keyboard is substantially software redefinable: nearly anything can be generated from any key or combination of keys pressed. Because of this the computer must have a means of identifying which key has been pressed other than by the character it generates. This is achieved by giving each physical key a key number which cannot be changed by software.

These numbers are shown on page 16 of Appendix III in the User Instructions, which says, for example, that when you press the key marked with an A you are pressing key number 69- You naturally expect to see the letter A appear on the screen, but this may not always happen, as we shall see.

The Amstrad uses the ASCII standard for its character set. ASCII (American Standard Code for Information Interchange) provides a means of exchanging information between computers and peripherals in a common code which is understood by all devices expecting to receive ASCII-coded information. On page 1 of Appendix III of the User Instructions there is a table of ASCII codes.

When you press the A key with Caps Lock or Shift depressed then ASCII code 65 is generated, corresponding to an upper-case A. Without the Shift key a lower-case a is produced, corresponding to ASCII 97. If the Ctrl key is held down at the same time, ASCII 1 is generated. In other words, pressing the A key, physical key number 69, generates one of three ASCII codes. It is by changing the codes generated by each key that it is possible to redefine the keyboard.

Control codes are a special subset of the first 32 ASCII codes, 0 to 31. They each have a name and perform special commands: Bel, for example, causes the speaker to give a short beep. On the Amstrad there are two ways to use the control codes. The recommended way to beep the bell is to type the number of the control code as the argument to the CHR$() function. Therefore to beep the bell type

PRINT CHR$(7)

or

?CHR$(7)

if you are a lazy typist.

The second method is to type the control code within inverted commas after the Print command PRINT "Ctrl-G" where G appears on the screen as a semicircle with feet. But be warned: using this method actually places control codes in your programs. They may have unexpected results when they are printed, as many printers use control codes to change character sets, line spacing and other functions — including disabling printing. This method is useful, however, to test the effect of a command in direct mode from the keyboard.

The Amstrad has 32 expansion tokens which can be programmed with up to 120 characters in the default condition. To understand exactly what an expansion token is consider the ASCII codes. They range from 0 to 127, and associated with each code is a standard command or character. Each code is stored in a single byte, which can contain values between 0 and 255 The 128 unused codes 128 to 255 are used for displaying special characters, as shown on pages 2 to 1} of Appendix III in the User Instructions.

Expansion tokens are a special subset of these codes in the range 128 to 159- The character associated with them can be printed as normal using the CHR$() function. However, when a key generates a code in the range 128 to 159 the computer detects this as an expansion token and prints the string of characters associated with it, and not the single character of the firmware character set. You can define the string of characters associated with each expansion token, using the Key command.

The format of the command is KEY key number, string To have the word FRED printed on the screen with expansion token 128 you enter the command

KEY 128,"FRED"

You can terminate the string with ASCII code 13 (CR), which will have the same effect as typing the string in from the keyboard then pressing Enter.

It is not possible to use inverted commas within a string in Locomotive basic as the interpreter thinks you have terminated the string. To create a string similar to that found on CTRL-Enter (Run”) you need to add the inverted comma as an ASCII code argument to the CHR$() function. Therefore to assign Run” plus Enter to expansion token 129 enter

KEY 129,"RUN" + CHR$(34) + CHR$(13)

The more complex Key Def command allows you to associate three numbers in the range 0 to 255 with each physical key number. These numbers are then generated by a key when it is pressed in normal, shifted or control states. The format is KEY DEF Keynumber, Repeat, Normal, Shift, Control where Keynumber is the number of the physical key you are concerned with; Repeat is set to 1 to enable repeat and 0 to disable it; Normal is the code of the character or expansion token you wish to display when the key is pressed; Shift is the code of the character or expansion token you wish to display when the Shift key is simultaneously pressed; and Control is the code of the character or expansion token you wish to display when the Ctrl key is simultaneously pressed.

For example, to change the A key to display X,Y,Z in repeat mode enter KEY DEF 69,1,88,89,90 To change the ? key to display three expansion tokens numbers 130,140,150 with no repeat enter KEY DEF 30,0,130,140,150 This illustrates how the keypad is set up on switch-on. From the data on page 15 of Appendix III you will see that the 1 key on the numeric keypad has expansion token 129 associated with it. Expansion token 129 has effectively been set up with the command

KEY 129,"1"

And the 1 key, physical key number 13, has effectively been set up with

KEY DEF 13,1,129,129,129

So if you redefined expansion token 129 to List followed by CHR$( 13) you wouId stop having a I generated on the keypad.

The keypad therefore has to be redefined if you use expansion tokens 128 to 140 and wish to keep the use of numeric keys on the numeric keypad. The program Keydef shows one method of doing this.

If you use Keydef I suggest you load it at the start of a programming session and leave it there for the duration. The program moves Himem, expansion-token storage areas and Symbol character storage areas from their normal locations. As a result Keydef may not be compatible with commercially available software. A Call 0 system reset is suggested to clear the Amstrad before running such programs.

The program has been written so that it is easily maintainable, and as a result it is longer than it need be, with some sections of code repeated. You can pick and choose the code you require. Three short machine-code routines call firmware routines. Only one of them is required after the program has been run, and then only if you opt to disable Ctrl-Shift-Esc system resets.

Line 80 removes the existing Symbol character buffer. If Himem is not immediately below the bottom of the Symbol buffer the Amstrad will not allow Symbol After commands to be executed. To overcome this problem the Sybol buffer is restored below buffers created by this program.

Line 140 moves Himem down 1,280 bytes to make room for two permanent buffers: 1,024 bytes are reserved for the Key definitions and a further 256 bytes are reserved for development of short machine-code routines. Only the last five bytes of these 256 are required after the program has been run. All values associated with memory operations in this program have been written in absolute values. This gives a clearer picture of the resulting memory map. You may prefer to give the
program long-term portability by replacing such absolute values with relative values, storing Himem to a variable such as Oldhimem and working from this base value.

The default expansion-token buffer is 120 characters. However, the expansion tokens in the program listing require far more space. This is obtained in lines 190 to 320 by calling KM Exp Buffer to relocate the keyboard buffer to the memory value in registers DE, with registers HL containing the length of the buffer.

FUNCTION KEYS
KeyFunction
1Mode 1
2Mode 2
3Reset favourite screen edit mode
4List
5Real Time
6Himem and Fre in hex, program length in decimal
7Display Amstrad character set
8Load and run a program
9Run the program in memory
0Mode 0
-Display expansion tokens and strings
CLRClear the screen

Lines 360 to 650 associate 20 Basic keywords with expansion tokens 128 to 147. There is an attempt to place a keyword on the key of its initial letter. The exceptions are Goto on the > key, List on the \ key and Symbol on the Y key. The keywords chosen are the common Basic words I use. Change them if you wish but remember the first 20 of your list will be the only ones read without further changes to the program

Lines 690 to 850 set up the top row of keys as function keys. They send a command to the Amstrad; each string is terminated with a CHR$(13). Note line 800 prints the numbei of minutes since switch-on. However, it is later overwritten by a further Key command which prints real-time clock values. The first version is given in case you do not wish to include the Time routines. The functions included are shown in the table.

In lines 890 to 990 Key 152 is redefined for the Real Time routine. ProgtS is a one-line program to print the time in hours, minutes, and seconds. Later in the program you are asked for the correct time. This is converted to the number of l/300ths of a second that have elapsed since 00:00:00 hours and used to reset Time. Unfortunately, the internal clock is interrupted while the cassette is in use and this will cause the clock to become inaccurate.

Key 158 is defined as Run" and is later transferred to the small Enter key. Key 159 displays the contents of the keys. Progf$ is a one-line program to perform this function. The string associated with each key is held in consecutive memory locations in the function-key buffer.

Lines 1010 to 1230 redefine the keypad by replacing the expansion tokens associated with each key with the ASCII codes for the numerals, full stop and Carriage Return. Run” is replaced on the small Enter key.

Lines 1280 to 1570 set Time to real time. This uses KL Time Set, which requires the number of 1 / 300ths of a second in registers DEHL, with D containing the most significant byte and L the least significant byte.

Lines 1610 to I860 disable Ctrl-Shift-Break. This uses KM Test Break. Register C is used to pass the state of the Shift and Ctrl keys to KM Test Break, and the short machine-code routine simply resets register C to 0. The five-byte routine remains in memory at locations &7FB to &A7FF. Do not use these memory locations for your routines if this option is in use.

The Symbol character buffer must be directly above Himem to enable it to be changed with the Symbol After command. This is achieved in line 1910 by recovering the buffer after allocating space for machine code and key functions.

Line 1950 sets the baud rate to 2,000 as a permanent pan of the initialisation. White on black in mode 2 is provided for in line 1990.

Line 2030 should be left as a Rem until final program testing has been completed, at which point it may be activated.

Ian STOBLE, Practical Compµting

★ PUBLISHER: Practical Compµting
★ YEAR: 1985
★ CONFIG: 64K + AMSDOS
★ LANGUAGE:
★ LiCENCE: LISTING
★ AUTHOR: Dick Ruck
 



★ AMSTRAD CPC ★ DOWNLOAD ★

Type-in/Listing:
» Key  Def  v2.02    (Practical  Computing)    LISTING    ENGLISHDATE: 2024-12-04
DL: 122
TYPE: PDF
SiZE: 831Ko
NOTE: Supplied by archive.org ; 3 pages/PDFlib v1.6

★ AMSTRAD CPC ★ A voir aussi sur CPCrulez , les sujets suivants pourront vous intéresser...

Lien(s):
» Applications » Iankey : Two Fingers to Touch Typing Conversion Course
» Applications » Swift Software - Keyword
» Applications » Pause Key Routine
» Applications » Keysave
» Applications » Confort-Inkey (Schneider Aktiv)
» Applications » RSX Key-Arrow
Je participe au site:
» Pour ce titre nous ne disposons de fichier executable sur CPC (Dump, Saisie du listing) , alors si vous avez ça dans vos cartons ou vous désirez usé vos petit doigts boudinés sur votre clavier faites le nous savoir.
» Vous avez des infos personnel ?
» Vous avez remarqué une erreur dans ce texte ?
» Aidez-nous à améliorer cette page : en nous contactant via le forum ou par email.

CPCrulez[Content Management System] v8.732-desktop/c
Page créée en 193 millisecondes et consultée 410 fois

L'Amstrad CPC est une machine 8 bits à base d'un Z80 à 4MHz. Le premier de la gamme fut le CPC 464 en 1984, équipé d'un lecteur de cassettes intégré il se plaçait en concurrent  du Commodore C64 beaucoup plus compliqué à utiliser et plus cher. Ce fut un réel succès et sorti cette même années le CPC 664 équipé d'un lecteur de disquettes trois pouces intégré. Sa vie fut de courte durée puisqu'en 1985 il fut remplacé par le CPC 6128 qui était plus compact, plus soigné et surtout qui avait 128Ko de RAM au lieu de 64Ko.