
                          USER'S GUIDE

                         TopKey for DOS
                          Version 1.40

                   Copyright (c) ETS Ltd., 1994


   ------- continuation, see origin at TK_1_DOS.TXT -----------


   4.5. Program interface with TopKey

   4.5.1 Control using interruptions

   You can call TopKey from your programs. It can be very convenient
   in creating multilingual applications - dictionaries, translators,
   word processors etc. Calling TopKey is performed through the
   interruption 2Fh, Ah= 8Fh, Al= number of the function. TopKey
   processes the following functions:

   Al= 40h - to check the presence of TopKey in memory.
             If present, AX= -1, BL,BH - number of the TopKey version
             will be returned.

   Al= 41h - to unload TopKey from memory.
             To load, the TopKey program must be run which will
             become resident again.

   Al= 42h - to choose a table.
             In calling: AX= 8F42h, BX= ident of the table.
             On calling: AX= ident of the new current table.
             Check AX, if you need to know if a table is loaded in
             TopKey.

   Al= 43h - to get information.
             Returned: ES:BX - pointer to the first table in the
             list; ES:DX - pointer to the current table in the list;
             AX - ident of the current table; CX - size of the buffer
             in TopKey.

   Al= 44h - to turn the driver on/off.
             In calling:
               AX= 8F44h,
               BX= 1    - to turn the driver on,
               BX= -1   - to turn the driver off,
               BX= 0    - setting is not changed.
             On calling:
               AX= 0    - the driver is turned off,
               AX= 1    - the driver is turned on.


   4.5.2 Internal format of keyboard profile files

   Keyboard profile tables are placed in the buffer of the TopKey
   driver continuously one after another. Each such table consists of
   the three integral parts:

   - head of the table;
   - table of keyboard modifications;
   - optional additional data.

   We will describe the format of these integral parts later. Here we
   just have to point out that the first two parts must be present in
   each table, and the third part may be omitted.

   Head of table:

         Ŀ
          word  Number of reassigned keys                    
         Ĵ
          word  Ident of the table                           
         Ĵ
          word  Size of the table, including head, in bytes  
         

   Keyboard profile table contains the list of those keys only
   meanings of which are modified compared to the meanings of the
   hardware driver. The number of such modifications must not be
   zero. The table cannot contain zero number of modifications.

   Ident of a table is an integer number from 0 through  65535, and
   the number 0 is assigned to the base table, the other numbers of
   tables must be unique. The table is chosen in the list by this
   number.

   The size of a table must be indicated in bytes, it cannot be more
   than 65535. This size includes the size of the head (6 bytes).


   Table of keyboard modifications:

   This table consists of records of the length of 4 or 6 bytes. Each
   record defines one key modified. The number of records in the
   table is indicated in the head of the table. The records follow
   each other continuously, 4-byte records are NOT justified by
   6-byte ones. The size of each record it determined by its context.

          Ŀ
           byte  Scan-code of the key reassigned   
          Ĵ
           word  Transformed status of the key     
          Ĵ
           byte  New meaning or number of command  
          ͵
           word  additional data word              
          

   The list of scan-codes of keys is given in Supplement 1. You can
   also refer to User's Guide of your computer, particularly if it is
   different from standard version, Tech Help, Norton Guide, etc. The
   driver reads scan-code from the port 60h.

   For the keys which have their analogues (grey keys), you must
   indicate either their scan-codes - for white keys, or their
   scan-codes increased by 80h (or by the decimal 128) - for grey
   keys. If you want to assign the same meaning to both keys, you
   must assign the meaning to each of them separately. Additionally
   take into account, that the right Ctrl and Alt keys are considered
   as "grey", i.e., their scan-codes must be increased by 80h. (More
   correctly: the keys the scan-code of which must be increased by
   80h are the keys preceded by the code E0h (224)).

   Transformed status of the keyboard determines at which combination
   of the statuses Shift, Ctrl, Alt, CapsLock, ScrollLock and NumLock
   the reassignment of this key is active. This status is placed in a
   single word of the following format:

             Number of bits            Comment
    
      F E DC BA 98 76 54 32 10
               Shift         RL-fag
              Ctrl          RL-flag
             Alt           RL-flag
            Summary Shift UD-flag
           CapsLock      UD-flag
          ScrollLock    UD-flag
         NumLock       UD-flag
        compare       compare flag
       command       command flag


   RL-flag is a 2-bit flag which can have one of the following
   meanings: 00b - any status; 01b - left key only must be pressed;
   10b - right key only must be pressed; 11b - either right or left
   key only must be pressed, i.e., the status must be active.

   Meanings of RL-flags slightly differ depending on the compare
   flag: if the flag is dropped, the meanings of RL-flag are as
   described above, and if the flag is set, the meaning of the 00b
   flag is interpreted as "the status must be dropped", i.e., neither
   of the two keys (left and right) must be pressed. Compare flag
   effects all three RL-statuses, shift, ctrl and alt, at the same
   time. In doing so, the effect on the shift-status depends also on
   the "summary shift" flag (see below). RL is the abbreviation of
   (R)ight  - (L)eft.

   UD-flag is a 2-bit flag which can have one of the following
   meanings: 00b - any flag; 01b - the flag must be active; 10b - the
   flag must be dropped; the meaning 11b is illegal.

   Meanings of UD-flags do not depend on the compare flag or other
   statuses. Meanings of the statuses CapsLock, ScrollLock and
   NumLock are evident by their names.

   The "Summary  Shift" status is the flags Shift and CapsLock taken
   together. This status is considered active, if either of the two
   Shift keys is pressed, or both of them are pressed, or the
   CapsLock key is pressed; and it is considered dropped, if neither
   Shift, nor CapsLock is pressed, or CapsLock and one Shift key or
   both Shift keys are pressed. This status is used for assigning
   keys of main alphabetic keyboard.

   Command flag can be dropped. In this case, this is considered as
   the assignment of a new ASCII-code for this key. New ASCII-code is
   placed in the 4th byte of the record, additional data word is not
   used. A record with the assignment of a new ASCII-code is a 4-byte
   record. This ASCII-code will be placed in the keyboard buffer; in
   doing so, the scan-code placed in the buffer will be set as it was
   written from the port 60h. The code E0h (224) cannot be placed by
   this method. For a symbol with such code, the scan-code must be
   dropped to 0 to imitate ALT-input (see below).

   Command flag can be set to 1; in this case, the 4th byte bears the
   code of the command, and the command can use additional data word.
   The length of the record with a command is 4 or 6 byte depending
   on the command.

   The commands can be as follows:

     FFh - replace the current table, using the address
     FEh - send ASCII-line
     FDh - replace the table, using the address, for the next
           following pressing only
     FCh - assign ASCII/SCAN combination
     FBh - send line of ASCII/SCAN combinations
     FAh - replace the table, using the ident of the table
     F9h - send single ASCII/SCAN combination
     01h - do not send any data on pressing this key
     00h - do not change the hardware assignment

   The commands FFh, FEh, FDh and FBh use the address to indicate the
   beginning of the corresponding object - a table or a line. The
   address is read from the end of the record describing this command
   to the beginning of the corresponding object, i.e., the distance
   to the object is used as the address. These commands have the
   length of the record of 6 byte.

   The table which the commands FFh  FDh point to must be placed in
   the third part of this table, in optional additional data area.
   Any meaning can be assigned in the field "ident" of the head of
   these tables, for this field is not used. In other respects, the
   format of these pages concurs with that described above.
   Replacement of the table for a single pressing is required in many
   languages, e.g., in describing symbols with stress-marks or colons
   above them; in doing so, first the key with the stress-mark is
   pressed, followed by the key with the letter needed.

   Lines sent by the FEh and FBh commands have a similar format. The
   number of symbols sent is indicated in the first byte, followed by
   the list of the symbols. For the FEh command, symbols consist of
   one byte, ASCII-code, and for the FBh command, symbols consist of
   two bytes - the ASCII-code indicated in the first, and the
   SCAN-code (or extended ASCII-code) indicated in the second). Lines
   are sent through the interruption 16h.

   The FCh command is used to place an ASCII/SCAN combination in the
   keyboard buffer. This command is necessary, e.g., for imitation of
   ALT-input of a symbol, when the SCAN-code is set equal to 0.
   ASCII-code is indicated in the junior, and SCAN-code is indicated
   in the senior byte of the word of additional data of the record.
   Using such command, symbols with the code E0h or F0h can be
   printed. The length of the record is 6 byte.

   The FAh command is used to replace tables by their ident. Relative
   addressing (i.e., setting distances) is suitable inside a single
   table, but it is not effective between different tables, as tables
   can move during modification thereof. To make calling tables more
   suitable, the mechanism of access by the ident is used. An
   additional data word containing the number of the table chosen is
   used in the record containing this command. This method is limited
   by tables of the "external" level only. See the picture:


   ĿĿĿ
     Table 1           Table 2            Table 3        
   ĿĿĿ
    Subtable 1-a    Subtable 2-a    Subtable 3-a   
   ٳٳٳ
   ĿٳĿ
    Subtable 1-b                        Subtable 3-b   
   ٳ                    ٳ
                       Ŀ
                                            Subtable 3-c   
                                           ٳ
                                           

   Using the FAh command, tables 1, 2, 3 only (the number of tables
   may be greater or lesser; in this example, 3 tables are drawn) can
   be chosen, and subtables included into the tables 1, 2 and 3 are
   unavailable for this function. E.g., to call the subtable 3-b from
   the table 3, use the FFh command; it is impossible to call
   subtables of the tables 1 and 2 from the table 3, the
   corresponding table must be called first.

   So, a table of the "external" level is a unit of description of
   the keyboard and can correspond to any language. The structure of
   this table can be very complicated, using enclosed subtables and
   assigned lines, which provides for an opportunity to use such
   tables not only for description of a language, but for
   modification of commands or creation of macro sequences working in
   specific applications as well.

   In planning tables, take into account, that EACH TABLE OR
   SUB-TABLE must contain ALL NECESSARY COMMANDS OF TRANSITION to
   needed tables and sub-tables. E.g., for a system of 3 tables
   without any sub-tables, the table 1 must contain commands for
   transition to 2 and 3, the table 2 - to 1 and 3, and the table 3 -
   to the tables 1 and 2.

   In some extent it can be simplified by the fact that the table
   with the ident 0 is always placed first in the list of the pages,
   and, if there is no correspondence found for the key pressed in
   the current table, the first (base) table will be looked over. It
   is useful to include all commands for choosing tables by the ident
   into this table, in this case, these commands may not be included
   into the other tables.

   The commands 01 and 00 do not require any additional data, the
   length of the record with these commands is 4 bytes. There are no
   any special comments on using these commands which are needed very
   rarely.


   The format described relates to the tables placed in memory and
   used by the TopKey package. For tables placed in files this
   description is still valid, but a record of three bytes (not
   included into the size of the table) may be given after the table,
   which assigns the key used for calling this table by default. The
   first byte is the scan-code of the key, and the status word (see
   the description above). One file can describe one table.


   5. About the code pages 866, 900 and 920

   CODEPAGE 866   was made for working with texts including English
                  and Russian. Code page 866 is presented in the
                  Russian version of MS-DOS 4.0. It is compatible
                  with more well-known in Russia "GOST (Federal
                  Standard) alternative coding".

   CODEPAGE 900   was developed in Finland. It is an extention of the
                  code page 866. It is completely compatible with the
                  latter by English and Russian symbols. In addition,
                  it contains some letters of Scandinavian languages,
                  which provide for an opportunity to use it for work
                  with English, Russian, and Finnish texts, as well
                  as with those compatible by alphabet.

   CODEPAGE 920   was developed in Russia. It is a further extension
                  of the code page 900. It is supplemented with
                  symbols providing for an opportunity to use it for
                  editing texts in English, Russian, German, Finnish,
                  Danish, Swedish and Norwegian; in addition, it
                  contains some symbols of phonetic (transcription)
                  alphabet.


   6. How to get the technical support

   Should any problems arise in installation or use of TopKey, please
   consult with your local dealer or directly with experts of ETS
   Ltd.

   ETS Ltd., 13 Podsosenski Per., Moscow 103062, Russia.
   Tel./fax: (+7) (095) 916-37-11
   E-Mail: Vlad@erika.msk.su

   Contact persons:
      Andrey Makarov, tel.: (+7) (095) 972-6956
      Vladimir Butakov, tel.: (+7) (095) 400-6634





                            Supplement 1

         Table of compatibility of keyboards and code pages

   NOTE: some keyboard tables are limited by a set of symbols,
   determined by code pages.

   E.g.:
   Universal keyboard was developed for the code page 850. However,
   it can be used (in reduced version) together with the code pages
   437, 920 and 900 (very limited set of symbols).

 ͻ
   \ Code                                                              
    \page       437         850         866        900         920     
     \       standard    standard    standard   ७multilingual
 Keyboard    English    multilingual Russian    Russian    Russian     
 Ķ
 universal        +           +                      +          +      
                                                                       
 Ķ
 graphics         +           +           +          +          +      
 Ķ
 Russian                                  +          +          +      
 Ķ
 German           +           +                                 +      
 Ķ
 Finnish/         +           +                      +          +      
 Swedish                                                               
 Ķ
 Norwegian        +           +                                 +      
 Ķ
 Phonetic                                                       +      
 ͼ





                            Supplement 2

           Table of key names for the "ASSIGN" command of
                       the TOPKEY.EXE program

 ͻ
  Key    Scan    Key    Scan    Key    Scan     Key    Scan    
 Ķ
  Esc         1  I          23  X           45  F9          67 
  1           2  O          24  C           46  F10         68 
  2           3  P          25  V           47  NumLock     69 
  3           4  [{         26  B           48  ScrollLock  70 
  4           5  ]}         27  N           49  Home        71 
  5           6  Enter      28  M           50  Up Arrow    72 
  6           7  Ctrl       29  ,<          51  PgUp        73 
  7           8  A          30  .>          52  Gray -      74 
  8           9  S          31  /?          53  Left Arrow  75 
  9          10  D          32  Right Shift 54  Numpad [5]  76 
  0          11  F          33  PrintScreen 55  Right Arrow 77 
  -_         12  G          34  Alt         56  Gray +      78 
  =+         13  H          35  Spacebar    57  End         79 
  Backspace  14  J          36  CapsLock    58  Down Arrow  80 
  Tab        15  K          37  F1          59  PgDn        81 
  Q          16  L          38  F2          60  Insert      82 
  W          17  ;:         39  F3          61  Delete      83 
  E          18  '"         40  F4          62  SysReq      84 
  R          19  `~         41  F5          63  ??          85 
  T          20  Left Shift 42  F6          64  Key45(macro)86 
  Y          21  \|         43  F7          65  F11         87 
  U          22  Z          44  F8          66  F12         88 
 ͼ



                            Supplement 3

   Table of most widely used assignments of statuses for keyboard

  Ŀ
   4040h  main alphabetic keyboard, capital letters           
  Ĵ
   4080h  main alphabetic keyboard, small letters             
  Ĵ
   4003h  main alphabetic keyboard, numerical keys with the   
          Shift key pressed, i.e., the symbols !"/$:,.;?%_+   
  

