home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / mskermit / msuv90.asm < prev    next >
Assembly Source File  |  2020-01-01  |  54KB  |  1,527 lines

  1.     NAME    msuv90
  2. ; File MSUV90.ASM
  3.     include mssdef.h
  4. ;       Copyright (C) 1982,1991, Trustees of Columbia University in the
  5. ;       City of New York.  Permission is granted to any individual or
  6. ;       institution to use, copy, or redistribute this software as long as
  7. ;       it is not sold for profit and this copyright notice is retained.
  8. ; Keyboard translator, by Joe R. Doupnik, Dec 1986
  9. ;  with contributions from David L. Knoell.
  10. ; This is the version for GENERIC MS-DOS which has been modified
  11. ;  slightly for use with the Victor 9000
  12. ; edit history:
  13. ; 2 March 1991 version 3.10
  14. ; Last edit: 19 August 1992
  15. ; 27 Feb 1988 Add capability of stdin being a file rather than device. [jrd]
  16.  
  17.     public    keybd, dfkey, shkey, msuinit, kbcodes
  18.  
  19. ; some definitions
  20.  
  21. maxkeys equ    128            ; maximum number of key definitions
  22. maxstng equ    64            ; maximum number of multi-char strings
  23. stbuflen equ    1000            ; length of string buffer (bytes)
  24.  
  25. verb    equ    8000h            ; dirlist flag: use verb action table
  26. strng    equ    4000h            ; dirlist flag: use string action table
  27. scan    equ    100h            ; keycode flag: code is scan not ascii
  28. braceop equ    7bh            ; opening curly brace
  29. bracecl equ    7dh            ; closing curly brace
  30.  
  31. data    segment
  32.     extrn taklev:byte, comand:byte, flags:byte
  33.     extrn shkadr:word, stkadr:word, trans:byte, ttyact:byte
  34.                         ; system dependent references
  35.     extrn vtmacname:word, vtmaclen:word    ; external macro, in msyv90
  36.  
  37. ;;;    System Independent local storage
  38.  
  39. tranbuf db    132 dup (?)        ; 132 byte translator work buffer
  40. crlf    db    cr,lf,'$'
  41. dfhelp1 db    cr,lf,' Enter key',27h,'s identification as a character',cr,lf
  42.     db    '  or as its numerical equivalent \{b##} of ascii',cr,lf
  43.     db    '  or as its scan code \{b##}'
  44.     db    cr,lf,'  or as SCAN followed by the scan code',cr,lf
  45.     db    '    where b is O for octal, X for hex, or D for decimal'
  46.     db    ' (default).',cr,lf,'    Braces {} are optional.'
  47.     db    cr,lf,'    Follow the identification with the new definition.'
  48.     db    cr,lf,' or CLEAR to restore initial key settings.$'
  49. dfaskky db    cr,lf,' Push key to be defined: $'
  50. dfaskdf    db    ' Enter new definition: ',0        ; asciiz for prompt
  51. verbbad db    cr,lf,' No such verb',cr,lf,'$'
  52. strbad    db    cr,lf,' Not enough space for new string',cr,lf,'$'
  53. keyfull db    cr,lf,' No more space to define keys',cr,lf,'$'
  54. dfkoops db    cr,lf,' Oops! That is Kermit',27h,'s Escape Char.'
  55.     db    ' Translation is not permitted.',cr,lf,'$'
  56. shkmsg1 db    cr,lf,'Push key to be shown (? shows all): $'
  57. shkmsg2 db    ' decimal is defined as',cr,lf,'$'
  58. shkmsg3 db    cr,lf,'... more, press a key to continue ...$'
  59. kwarnmsg db    cr,lf,' Notice: this form of Set Key is obsolete$'
  60.  
  61. ascmsg    db    ' Ascii char: $'
  62. scanmsg db    ' Scan Code $'
  63. strngmsg db    ' String: $'
  64. verbmsg db    ' Verb: $'
  65. noxmsg    db    ' Self, no translation.$'
  66. fremsg    db    cr,lf,' Free space: $'
  67. kyfrdef db    ' key and $'
  68. stfrdef db    ' string definitions, $'
  69. stfrspc db    ' string characters.',cr,lf,'$'
  70.                     ; translation tables
  71. keylist dw    maxkeys dup (0)     ; 16 bit keycodes, paralled by dirlist
  72. dirlist dw    maxkeys dup (0)     ; director {v+s} + {index | new char}
  73. sptable dw    maxstng dup (0)     ; list of asciiz string offsets
  74. stbuf    dw    stbuflen dup (0)    ; buffer for strings
  75. strmax    dw    stbuf            ; first free byte in stbuf
  76. listptr dw    ?            ; item number for keylist and dirlist
  77. nkeys    dw    0            ; number of actively defined keys
  78. keycode dw    ?            ; ascii/scan code for key
  79. kbtemp    dw    ?            ; scratch storage for translator
  80. brace    db    ?            ; brace detected flag byte
  81. oldform db    0            ; old form Set Key, if non-zero
  82. verblen dw    ?            ; length of user's verb (work temp)
  83. kwcnt    dw    ?            ; number of keywords (work temp)
  84. msutake db    ?            ; if being run from take file or not
  85. stringcnt dw    0            ; qty of string chars to be processed
  86. stringptr dw    0            ; address of next string char
  87. twelve    dw    12d
  88. dosflg    db    0
  89. ;;;    End System Independent Data Area
  90.  
  91. ;;;    System Dependent Data Area
  92. ;    edit dfhelp2 to include nice list of verbs for this system.
  93. dfhelp2 db    cr,lf,' Enter either \{Kverb}  for a Kermit action verb',cr,lf
  94.     db    ' or a replacement string  (single byte binary numbers are'
  95.     db    ' \{b##})',cr,lf,' or nothing at all to undefine a key.'
  96.     db    cr,lf,' Braces {} are optional, and strings maybe enclosed in'
  97.     db    ' them.',cr,lf,' Strings may not begin with the character'
  98.     db    ' combinations of  \k  or  \{k',cr,lf
  99.     db    '    (start with a { brace instead).',cr,lf,lf
  100.     db    ' Verbs are as follows:',cr,lf
  101.     db    ' Logoff (suspend logging), Logon (resume logging),'
  102.     db    ' DOS (push to), null (send a)',cr,lf
  103.     db    ' break, help, prtscn, status, exit',cr,lf
  104.     db    ' dump, break, lbreak, hangup',cr,lf
  105.     db    ' page, home (Tektronix only)'
  106.     db    cr,lf,'$'
  107.  
  108.     ; Aliaskey: keys having aliases - same ascii code but more than one
  109.     ; scan code, as on auxillary keypads. Use just scan codes with these.
  110.     ; Alternative use: force ascii keys to report out just scan codes.
  111.     ; Table format: high byte = scan code, low byte = ascii code.
  112.     ; Contents are machine dependent.
  113. aliaskey db    0
  114. aliaslen equ    ($-aliaskey) shr 1    ; number of words in aliaskey table
  115.  
  116. kverbs    db    15            ; number of table entries below
  117.     mkeyw    'prtscn',trnprs         ; independent of ordering and case!
  118.     mkeyw    'break',sendbr          ; mkeyw 'name',procedure entry point
  119.     mkeyw    'help',cquery
  120.     mkeyw    'status',cstatus
  121.     mkeyw    'exit',cquit
  122.     mkeyw    'null',snull
  123.     mkeyw    'DOS',kdos
  124.     mkeyw    'Logoff',klogof
  125.     mkeyw    'Logon',klogon
  126.     mkeyw    'dump',dmpscn
  127.     mkeyw    'break',sendbr
  128.     mkeyw    'lbreak',sendbl
  129.     mkeyw    'hangup',chang
  130.     mkeyw    'page',cpage
  131.     mkeyw    'home',chome
  132.  
  133.                 ; Initialization data.
  134. kbdinlst equ    this byte    ; Kermit initialization time keyboard setup
  135.     mkeyw    '\x7f',8        ; Backspace key sends DEL
  136.     mkeyw    '\{Kpage}',0F1H ; function 1 is page
  137.     mkeyw    '\{Khome}',0F2H ; function 2 is home
  138.     mkeyw    '\kexit',0FAh    ; function 10 is exit
  139.     dw    0        ; end of table marker
  140.  
  141. kbcodes    dw    80h        ; keyboard read codes, 80h=not inited
  142. data    ends
  143.  
  144. ;            Documentation
  145. ;Translating a key:
  146. ;   The translator is called to obtain keyboard input; it sends characters to
  147. ; the serial port through standard controlled echo procedures or invokes
  148. ; named procedures. It returns carry clear when its operation is completed
  149. ; for normal actions and carry set when Connect mode must be exited. When
  150. ; Connect mode is exited the just read char should be passed in Kbdflg
  151. ; to msster.asm for invoking actions such as Status, send a break,
  152. ; quit connect mode; system dependent procedure Term is responsible for this.
  153. ;
  154. ;  Principal procedures are -
  155. ;    msuinit     Initializes keyboard translator in this file when
  156. ;            Kermit first begins. Installs dfkey and shkey as the
  157. ;            procedures used for Set Key and Show Key. Sys Indep.
  158. ;            Called from msx or msy init procs. System Independent.
  159. ;    keybd        Performs the translation, outputs chars to the serial
  160. ;            port or invokes a Kermit action routine. Sys Indep.
  161. ;    dfkey        Defines a key's translation. Reads command line
  162. ;            via Kermit's command parser comnd. System Independent.
  163. ;    shkey        Shows translation of a key. Requests user to push
  164. ;            selected key. System Independent.
  165. ;
  166. ;    kbdinit     optional. Initializes the translation tables when
  167. ;            Kermit starts up. Called by msuinit. System Dependent.
  168. ;    getkey        Performs the keyboard read and returns results in
  169. ;            a standardized system independent format. Sys Depend.
  170. ;    postkey     called by active translator after obtaining a keycode.
  171. ;            Used to provide extra local actions (keyclick) only
  172. ;            in Connect mode (not during Set/Show key commands).
  173. ;            Called by keybd. System dependent.
  174. ; Supporting system independent procedures are -
  175. ; shkfre (show string free space), tstkeyw (finds user's keyword in the verb
  176. ; table), insertst (insert string in buffer), remstr (delete string in buffer).
  177. ;
  178. ;   System dependent procedure Getkey reads a keycode (usually via a Bios
  179. ; call). On IBM compatible machines this yields <ah=scan code, al=ascii>
  180. ; for ordinary keys, or <ah=scan code, al=0> for special keys such as F1,
  181. ; or <ah=0, al=###> when Alt### is used.
  182. ; For any system, the canonical output form is the key's code in Keycode.
  183. ; Place the ascii code (or scan code if none) in byte Keycode and ancillary
  184. ; info (shift states plus marker bit for scan codes) in byte Keycode + 1.
  185. ;
  186. ;   Table Aliaskey is a list of scan code/ascii codes for keys which appear
  187. ; more than once on a keyboard. This list is examined to distinguish such
  188. ; aliased keys (those on an auxillary keypad) from an ordinary ascii key,
  189. ; and the aliased key is then referenced by its scan code rather than by
  190. ; the ordinary ascii code. Aliaskey is machine and keyboard dependent.
  191. ;
  192. ;    Procedure Keybd calls Getkey for the Keycode, checks list of translatable
  193. ; keys Keylist, and then either sends an ascii string (one or more characters)
  194. ; or invokes a Kermit action verb. List Dirlist indicates what kind of
  195. ; translation to do. Keybd is system independent but may contain system
  196. ; dependent special actions such as echoing keyclicks. Keybd calls system
  197. ; dependent procedure Postkey just after calling getkey so local actions
  198. ; such as keyclicks can be activated only during Connect mode operations.
  199. ;
  200. ;    Keylist is a packed but unordered list of 16 bit keycodes which need
  201. ; translation. The lower order byte holds a key code (ascii char or scan code)
  202. ; while the high byte holds a scan code marker bit (0 if ascii code in low
  203. ; byte) plus any ancillary keyboard information such as Control/Shift/Alt/Meta
  204. ; keys being held down; these are of use in Show Key presentations.
  205. ;    Dirlist parallels Keylist to provide the kind of translation, verb or
  206. ; string, in the two highest bits with the other bits holding either
  207. ; a single new replacement character or the item number in lists of verbs
  208. ; or strings. If neither verb nor strng type bits are set in a dirlist
  209. ; word then the translation is a single new character held in the lower
  210. ; eight bits of that dirlist word.
  211. ;
  212. ;    The number of key translations is assembly constant Maxkeys (def 128).
  213. ;    The maximum number of strings is assembly constant Maxstngs (def 64).
  214. ;    The maximum number of verbs is 256 and is set by building table Kverbs.
  215. ;
  216. ;   For verbs, use the Item number from the Director table Dirlist to select
  217. ; a procedure offset from the structured list Kverbs and jump to that offset.
  218. ; Most verb procedures return carry clear to stay within Connect mode.
  219. ; Verbs requiring exiting Connect mode return carry set and may set byte
  220. ; Kbdflg to a char code which will be read by msster.asm for activating a
  221. ; transient Kermit action such as send a break (Kbdflg = 'b').
  222. ; Kbdflg is stored in msster.asm (as zero initially, meaning ignore it).
  223. ; Action verb procedures are normally located in a system dependent file.
  224. ;
  225. ;   For multi-char strings, use Item number from Director table Dirlist to
  226. ; select a pointer to a string. The list of string pointers is Sptable
  227. ; (string pointer table) which holds the offset in the data segment of the
  228. ; strings stored in buffer Stbuf. In stbuf strings are held as: one byte of
  229. ; length of following text and then the text itself (permits embedded nulls).
  230. ;  Use Chrout to send each string character, and finally return from Keybd
  231. ; with carry clear.
  232. ;
  233. ;   For single character replacements obtain the new character from the lower
  234. ; order byte of Director table Dirlist. If the character is Kermit's present
  235. ; escape character return from Keybd carry set to leave connect mode.
  236. ; Otherwise, send the character via Chrout and return from Keybd carry clear.
  237.  
  238. ; Keylist table format:
  239. ;    7 bits   1 bit   8 bits
  240. ; +----------+----+------------+ scan bit = 1 if key's code is non-ascii
  241. ; | aux info |scan| key's code | aux info = system dependent, used only to
  242. ; +----------+----+------------+        help identify key
  243. ;
  244. ; Dirlist table format          v s    meaning
  245. ;   1    1      14 bits          0 0    copy out one byte translation
  246. ; +---+---+--------------------+  1 0    copy out multi-char string number Item
  247. ; | v | s | item # or new char |  0 1    do action verb number Item
  248. ; +---+---+--------------------+  1 1    (not used)
  249. ;
  250. ; Table kverbs is organized by macro mkeyw as -
  251. ;    kverbs    db    number of table entries
  252. ;    (each entry is in the form below:)
  253. ;        db    number of bytes in verbname
  254. ;        db    'verbname'              variable length
  255. ;        db    '$'                     for printing
  256. ;        dw    value            offset of procedure
  257. ;
  258. ;
  259. ;   Dfkey defines a key to be itself (undefines it) or a single replacement
  260. ; character or a character string or a Kermit action verb. Dfkey requires
  261. ; a command line so that it may be invoked by Take files but can be forced
  262. ; to prompt an interactive user to push a key. Syntax is discussed below.
  263. ; Note that redefined keys have their old definitions cleared so that
  264. ; old string space is reclaimed automatically.
  265. ;
  266. ;   Shkey displays a key's definition and the user is asked to push the
  267. ; selected key. The free space for strings is always shown afterward. See
  268. ; below for syntax.
  269. ;
  270. ;   Kbdinit is an optional routine called when Kermit starts up. It fills in
  271. ; the translation tables with desirable default values to save having to
  272. ; use long mskermit.ini files. The default values are stored in a structured
  273. ; table similar to (but not the same as) Dfkey's command lines; the keycode
  274. ; values are preset by hand to 16 bit numbers.
  275.  
  276. ;Defining a key:
  277. ; Command is SET KEY <key ident><whitespace><definition>
  278. ;
  279. ; <key ident> is
  280. ;        a single ordinary ascii char or
  281. ;        the numerical equivalent of an ascii char or
  282. ;        a Scan Code written as a number or
  283. ;        keyword SCAN followed by a number.
  284. ;        ?    Displays help message.
  285. ;    Numbers and Binary codes are of the form
  286. ;        \123    a decimal number
  287. ;        \o456    an octal number     base letters o, d, x can be
  288. ;        \d213    a decimal number    upper or lower case
  289. ;        \x0d    a hex number
  290. ;        \{b###}  braces around above material following slash.
  291. ;
  292. ; <whitespace> is one or more spaces and or tabs.
  293. ;
  294. ; <definition> is
  295. ;    missing altogether which "undefines" a key.
  296. ;    \Kverb        for a Kermit action verb; upper or lower case K is ok
  297. ;    \{Kverb}    ditto. Verb is the name of an action verb.
  298. ;    text        a string with allowed embedded whitespace and embedded
  299. ;            binary chars as above. This kind of string may not
  300. ;            commence with sequences \K or \{K; use braces below.
  301. ;    {text}        string confined to material within but excluding
  302. ;            the braces. Note, where the number of opening braces
  303. ;            exceeds the number of closing braces the end of line
  304. ;            terminates the string: {ab{}{{c}d ==> ab{}{{c}d
  305. ;            but  {ab}{{c}d ==> ab.
  306. ;    ?        Displays help message and lists all action verbs.
  307. ;
  308. ;    If Set Key is given interactively, as opposed to within a Take
  309. ;    file, the system will prompt for inputs if none is on the command
  310. ;    line. The response to Push key to be defined cannot be edited.
  311. ;
  312. ;    Text which reduces to a single replacement character is put into a
  313. ;    table separate from the multi-character strings (maxstng of these).
  314. ;    A key may be translated into any single 8 bit code.
  315. ;
  316. ;    Comments can follow a Kermit action verb or a braced string; no
  317. ;    semicolon is required since all are stripped out by the Take file
  318. ;    reader before the defining text is seen by SET KEY.
  319. ;
  320. ;    The current Kermit escape character cannot be translated without
  321. ;    subtrafuge.
  322. ;
  323. ;    Examples:
  324. ;        Set Key q z
  325. ;                makes key q send character z
  326. ;        Set Key \7 \27[0m
  327. ;                makes key Control G send the four byte
  328. ;                string    ESC [ 0 m
  329. ;        Set Key q
  330. ;                undefines key q so it sends itself (q) again.
  331. ;        Set Key \2349 \kexit
  332. ;                defines IBM Alt-X to invoke the leave connect
  333. ;                mode verb "exit" (Kermit's escape-char ^] C).
  334. ;        Set Key \x0c Login \{x0d}myname\{x0d}mypass\x0d
  335. ;                defines Control L to send the string
  336. ;                Login <cr>myname<cr>mypass<cr>
  337. ;
  338. ; Alternative Set Key syntax for backward compatibility with previous versions
  339. ;    The same forms as above except the key identification number must
  340. ;    be decimal and must Not have a leading backslash. Example:
  341. ;    Set Key Scan 59 This is the F1 key
  342. ;
  343. ;    If the definition is omitted it may be placed on the following line;
  344. ;    if that line is also empty the key is undefined (defined as Self).
  345. ;    A warning message about obsolete syntax will be given followed by
  346. ;    the key's modern numerical value and new definition. Only "special"
  347. ;    keys (those not producing ascii codes) are compatible with this
  348. ;    translator.
  349. ;
  350. ;Showing a key:
  351. ; Command is SHOW KEY <cr>
  352. ; System prompts user to press a key and shows the definition plus the
  353. ; free space for strings. Query response results in showing all definitions.
  354. ;            End Documentation
  355.  
  356. code    segment
  357.         ; system independent external items
  358.     extrn    comnd:near, prompt:near, iseof:near    ; in msscmd
  359.     extrn    isfile:near, strlen:near, prtscr:near    ; in mssfil
  360.     extrn    cnvlin:near, katoi:near, decout:near    ; in mssset
  361.         ; system dependent external items
  362.         ; these are system dependent action verbs, in msxgen
  363.     extrn    beep:near, trnprs:near, sendbr:near
  364.     extrn    chrout:near, cstatus:near, cquit:near, cquery:near
  365.     extrn    klogon:near, klogof:near, kdos:near, snull:near
  366.     extrn    dmpscn:near, sendbr:near, sendbl:near, chang:near
  367.     extrn    cpage:near, chome:near
  368.     extrn    extmacro:near
  369.  
  370.     assume    cs:code, ds:data, es:nothing
  371.  
  372. ; Begin system independent Keyboard Translator code
  373.  
  374. ; MSUINIT performs Kermit startup initialization for this file.
  375. ; Note, shkadr and stkadr are pointers tested by Set/Show Key calls. If they
  376. ; are not initialized here then the older Set/Show Key procedures are called.
  377. MSUINIT    PROC    NEAR            ; call from msx/msy init code
  378.     call    kbdinit            ; optional: init translator tables
  379.     mov    shkadr,offset shkey    ; declare keyboard translator present
  380.     mov    stkadr,offset dfkey    ; via Show and Set Key proc addresses
  381.     ret
  382. MSUINIT    ENDP
  383.  
  384. ; Call Keybd to read a keyboard char (just returns carry clear if none) and
  385. ; 1) send the replacement string (or original char if not translated)
  386. ;    out the serial port, or
  387. ; 2) execute a Kermit action verb.
  388. ; Returns carry set if Connect mode is to be exited, else carry clear.
  389. ; Modifies registers ax and bx. 
  390. KEYBD    PROC    NEAR            ; active translator
  391.     mov    ttyact,1        ; doing single char output
  392.     cmp    stringcnt,0        ; any leftover string chars?
  393.     je    keybd0            ; e = no
  394.     jmp    keyst2            ; yes, finish string
  395. keybd0:    call    getkey            ; read keyboard
  396.     jnc    keybd1            ; nc = data available
  397.     jmp    keybdx            ; else just return carry clear
  398. keybd1:    call    postkey            ; call system dependent post processor
  399.     cmp    nkeys,0            ; is number of keys defined = 0?
  400.     jz    keybd3            ; z = none defined
  401.     push    di            ; search keylist for this keycode
  402.     push    cx            ; save some registers    
  403.     push    es
  404.     mov    di,offset keylist    ; list of defined keycode words
  405.     mov    ax,keycode        ; present keycode
  406.     mov    cx,nkeys        ; number of words to examine
  407.     push    ds
  408.     pop    es            ; make es:di point to data segment
  409.     cld
  410.     repne    scasw            ; find keycode in list
  411.     pop    es            ; restore regs
  412.     pop    cx
  413.     je    keybd1b            ; e = found, work with present di
  414.     pop    di            ; restore original di
  415.     test    keycode,scan        ; is this a scan code?
  416.     jz    keybd3            ; z = no, it's ascii, use al as char
  417.     call    beep            ; say key is a dead one
  418.     clc
  419.     ret                ; and exit with no action
  420.  
  421. keybd1b:sub    di,2            ; correct for auto increment
  422.     sub    di,offset keylist    ; subtract start of list ==> listptr
  423.     mov    ax,dirlist[di]        ; ax = contents of director word
  424.     pop    di            ; restore original di
  425.                     ; dispatch on Director code
  426.     test    ax,verb            ; verb only?
  427.     jnz    keyvb            ; e = yes
  428.     test    ax,strng        ; multi-char string only?
  429.     jnz    keyst            ; e = yes, else single char & no xlat.
  430.                     ;
  431.                     ; do single CHAR output (char in al)
  432. keybd3:    cmp    al,trans.escchr        ; Kermit's escape char?
  433.     je    keybd3a            ; e = yes, handle separately
  434.     call    chrout            ; transmit the char
  435.     clc                ; return success
  436.     ret
  437. keybd3a:stc                ; set carry for jump to Quit
  438.     ret
  439.  
  440. keyvb:    and    ax,not(verb+strng)    ; VERB (ax=index, remove type bits)
  441.     mov    bx,offset kverbs    ; start of verb table
  442.     cmp    al,byte ptr [bx]    ; index > number of entries?
  443.     jae    keybdx            ; ae = illegal, indices start at 0
  444.     inc    bx            ; bx points to first entry
  445.     push    cx            ; save reg
  446.     mov    cx,ax            ; save the index in cx
  447.     inc     cx            ; counter, indices start at 0
  448. keyvb1:    mov    ax,[bx]            ; cnt value
  449.     add    ax,4            ; skip text and value word
  450.     add    bx,ax            ; look at next slot
  451.     loop    keyvb1            ; walk to correct slot
  452.     sub    bx,2            ; backup to value field
  453.     pop    cx            ; restore reg
  454.     mov    bx,[bx]            ; get value field of this slot
  455.     or    bx,bx            ; jump address defined?
  456.     jz    keybdx            ; z = no, skip the action
  457.     jmp    bx            ; perform the function
  458.  
  459. keyst:    and    ax,not(verb+strng)    ; STRING (ax=index, remove type bits)
  460.     shl    ax,1            ; convert to word index
  461.     push    si            ; save working reg
  462.     mov    si,ax            ; word subscript in table
  463.     mov    si,sptable[si]        ; memory offset of selected string
  464.     xor    cx,cx            ; init string length to null
  465.     or    si,si            ; is there a string pointer present?
  466.     jz    keyst1            ; z = no, skip operation
  467.     cld                ; scan forward
  468.     mov    cx,[si]            ; get string length
  469.     add    si,2
  470. keyst1:    mov    stringcnt,cx
  471.     mov    stringptr,si
  472.     pop    si
  473.     jcxz    keybdx            ; z = null length
  474.  
  475. keyst2:    push    si
  476.     mov    si,stringptr        ; pointer to next string char
  477.     cld
  478.     lodsb                ; get new string char into al
  479.     pop    si
  480.     dec    stringcnt        ; string chars remaining
  481.     inc    stringptr
  482.     call    keysv            ; scan for embedded verbs
  483.     jc    keyst4            ; c = not found, al has string char
  484.     jmp    bx            ; perform the verb (bx = address)
  485. keyst4:    cmp    stringcnt,0        ; last character?
  486.     je    keyst5            ; e = yes, stop grouping for nets
  487.     mov    ttyact,0        ; group output for networks
  488. keyst5:    jmp    chrout            ; send out the char in al
  489.  
  490. keybdx:    clc                ; return success (nothing to do)
  491.     ret
  492. KEYBD    ENDP
  493.  
  494. ; Scan for keyboard verbs embedded in outgoing string. If found update
  495. ; string pointer and count to just beyond the verb and return action routine
  496. ; address in bx with carry clear. If failure return carry set and no change.
  497. ; Can invoke external procedure EXTMACRO if the verb is not known here.
  498.  
  499. keysv    proc    near
  500.     push    ax
  501.     push    si
  502.     push    di
  503.     cmp    al,'\'            ; escape?
  504.     jne    keysv7            ; ne = no
  505.     mov    cx,stringcnt        ; chars remaining
  506.     mov    si,stringptr        ; address of next char to read
  507.     mov    brace,0            ; assume not using braces
  508.     cmp    byte ptr [si],braceop    ; starts with \{?
  509.     jne    keysv1            ; ne = no
  510.     inc    si            ; skip the opening brace
  511.     dec    cx
  512.     mov    brace,bracecl        ; expect closing brace
  513. keysv1:    cmp    byte ptr [si],'K'    ; starts with \{K or \K?
  514.     je    keysv2            ; e = yes
  515.     cmp    byte ptr [si],'k'    ; starts as \{k or \k?
  516.     jne    keysv7            ; ne = no, then it's a string
  517. keysv2:    inc    si            ; yes, skip the K too
  518.     dec    cx
  519.     mov    di,offset tranbuf    ; copy verb name to this work buffer
  520.     xor    ax,ax
  521.     mov    [di],ax            ; init the buffer to empty
  522. keysv3:    cld
  523.     jcxz    keysv4            ; z = no more string chars
  524.     lodsb                ; scan til closing brace or w/s or end
  525.     dec    cx
  526.     cmp    al,brace        ; closing brace?
  527.     je    keysv4            ; e = yes
  528.     cmp    al,spc            ; white space or control char?
  529.     jbe    keysv3            ; be = yes
  530.     mov    [di],ax            ; copy to tranbuf and terminate
  531.     inc    di
  532.     jmp    short keysv3
  533. keysv4:    push    si            ; save input reading position
  534.     mov    si,offset tranbuf    ; where verb starts (needs si)
  535.     call    tstkeyw            ; find keyword, bx = action routine
  536.     pop    si
  537.     jnc    keysv4a            ; nc = found the verb
  538.     call    keysv8            ; invoke EXTMACRO worker for unknown
  539.     jc    keysv7            ; carry = no verb to operate upon
  540. keysv4a:cmp    brace,0            ; need to end on a brace?
  541.     je    keysv6            ; e = no
  542.     dec    si            ; break position
  543.     inc    cx
  544.     cld
  545. keysv5:    jcxz    keysv6            ; z = no more string characters
  546.     lodsb                ; read string char
  547.     dec    cx
  548.     cmp    al,brace        ; the brace?
  549.     jne    keysv5            ; ne = no, repeat until it is found
  550. keysv6:    mov    stringptr,si        ; where we finished+1
  551.     mov    stringcnt,cx        ; new count of remaining chars
  552.     pop    di
  553.     pop    si            ; original si, starting place
  554.     pop    ax            ; original ax
  555.     clc
  556.     ret
  557. keysv7:    pop    di            ; verb not found
  558.     pop    si
  559.     pop    ax
  560.     stc
  561.     ret
  562. ; Worker. Unknown verb name as string {\kverb} or {\k{verb}}. Use EXTMACRO
  563. ; procedure (in msyibm typically), point to verb name with vtmacname, length
  564. ; of it in byte vtmaclen, address of EXTMACRO to BX. Upper case the verb.
  565. ; Enter with tranbuf holding the verb, asciiz, without \K and braces.
  566. ; Returns BX set to EXTMACRO proc, vtmacname pointing to verb (uppercased)
  567. ; and vtmaclen holding the length of verb.
  568. keysv8:    mov    bx,offset extmacro    ; use this external macro pointer
  569.     mov    vtmacname,offset tranbuf; select extmacro procedure address
  570.     mov    dx,offset tranbuf    ; point to name for extmacro
  571.     push    cx
  572.     call    strlen            ; get its length
  573.     mov    vtmaclen,cx        ; length for extmacro
  574.     jcxz    keysv11            ; z = none
  575.     push    si            ; convert verb name to upper case
  576.     mov    si,dx            ; verb, without leading \K stuff
  577.     cld
  578. keysv9:    lodsb                ; read a name byte
  579.     cmp    al,'a'            ; before lower case?
  580.     jb    keysv10            ; e = yes
  581.     cmp    al,'z'            ; above lower case?
  582.     ja    keysv10            ; a = yes
  583.     and    al,not 20h        ; convert to upper case
  584.     mov    [si-1],al        ; put it back
  585. keysv10:loop    keysv9            ; do all bytes, asciiz
  586.     pop    si
  587.     pop    cx
  588.     clc                ; carry clear = ready to execute
  589.     ret
  590. keysv11:stc                ; carry set = no verb, do nothing
  591.     pop    cx
  592.     ret
  593. keysv    endp
  594.  
  595. ; SET KEY - define a key   (procedure dfkey)
  596. ; SET KEY <key ident><whitespace><new meaning>
  597. ; Call from Kermit level. Returns carry set if failure.
  598. ;  
  599. DFKEY    PROC    NEAR            ; define a key as a verb or a string
  600.     mov    keycode,0        ; clear keycode
  601.     mov    oldform,0        ; say no old form Set Key yet
  602.     or    byte ptr kbcodes,80h    ; say kbcodes not-initiated
  603.     mov    dx,offset tranbuf    ; our work space
  604.     mov    word ptr tranbuf,0    ; insert terminator
  605.     mov    bx,offset dfhelp1    ; first help message
  606.     mov    ah,cmword        ; parse a word
  607.     call    comnd            ; get key code or original ascii char
  608.     mov    cl,taklev        ; reading from Take file
  609.     mov    msutake,cl        ; save here
  610.     or    ax,ax            ; any text given?
  611.     jnz    dfkey12            ; nz = yes, so don't consider prompts
  612.                     ; interactive key request
  613.     cmp    taklev,0        ; in a Take file?
  614.     je    dfkey10            ; e = no, prompt for keystroke
  615.     jmp    dfkey0            ;  else say bad syntax
  616. dfkey10:mov    ah,prstr
  617.     mov    dx,offset dfaskky    ; ask for key to be pressed
  618.     int    dos
  619. dfkey11:call    getkey            ; read key ident from keyboard
  620.     jc    dfkey11            ; c = no response, wait for keystroke
  621.     mov    ah,prstr        ; display cr/lf
  622.     mov    dx,offset crlf
  623.     int    dos
  624.     call    shkey0            ; show current definition (in SHKEY)
  625.     jmp    dfkey1e            ; prompt for and process definition
  626.  
  627. dfkey12:                ; Look for word SCAN and ignore it
  628.     mov    dx,word ptr tranbuf    ; get first two characters
  629.     or    dx,2020h        ; map upper to lower case
  630.     cmp    dx,'cs'            ; first two letters of word "scan"?
  631.     je    dfkey            ; e = yes, skip the word
  632.     cmp    dx,'lc'            ; first two letters of word "clear"?
  633.     je    dfkey15            ; e = yes, reinit keyboard [2.31]
  634.     cmp    dx,'fo'            ; first two letters of "off"
  635.     je    dfkey13            ; e = yes, use DOS keyboard calls
  636.     cmp    dx,'no'            ; first two letters of "on"
  637.     je    dfkey13            ; e = yes, use standard kbd calls
  638.     cmp    ax,1            ; number of characters received
  639.     jbe    dfkey12a        ; be = stay here
  640.     jmp    dfkey1            ; a = more than one, decode
  641. dfkey12a:mov    ah,byte ptr tranbuf    ; get the single char
  642.     mov    byte ptr keycode,ah    ; store as ascii keycode
  643.     jmp    dfkey1b            ; go get definition
  644. dfkey13:push    dx            ; save command letters
  645.     mov    ah,cmeol        ; get end of line confirmation
  646.     call    comnd
  647.     pop    dx
  648.     jnc    dfkey14            ; nc = success
  649.     ret
  650. dfkey14:mov    al,0ffh            ; set DOS keyboard read flag
  651.     cmp    dx,'fo'            ; first two letters of "off"
  652.     je    dfkey14a        ; e = yes, use DOS keyboard calls
  653.     xor    al,al            ; clear DOS keyboard read flag
  654.     cmp    dx,'no'            ; first two letters of "on"
  655.     je    dfkey14a        ; e = yes, use standard kbd calls
  656.     mov    al,dosflg
  657. dfkey14a:mov    dosflg,al        ; store new keyboard flag
  658.     ret
  659.  
  660. dfkey15:mov    ah,cmeol
  661.     call    comnd            ; confirm request before proceeding
  662.     jnc    dfkeyc            ; nc = success
  663.     ret                ; failure
  664.  
  665. dfkey0:    mov    dx,offset dfhelp1    ; say bad definition command
  666.     mov    ah,prstr
  667.     int    dos
  668.     stc                ; failure
  669.     ret
  670.  
  671. dfkeyc:                    ; CLEAR key defs, restore startup defs
  672.     mov    cx,maxkeys        ; size of keycode tables
  673.     push    es            ; save register
  674.     push    ds
  675.     pop    es            ; make es point to data segment
  676.     xor    ax,ax            ; null, value to be stored
  677.     mov    di,offset dirlist    ; director table
  678.     cld
  679.     rep    stosw            ; clear it
  680.     mov    cx,maxkeys
  681.     mov    di,offset keylist    ; keycode table
  682.     rep    stosw            ; clear it
  683.     mov    cx,maxstng
  684.     mov    di,offset sptable    ; string pointer table
  685.     rep    stosw            ; clear it
  686.     pop    es            ; recover register
  687.     mov    strmax,offset stbuf    ; clear string buffer, free space ptr
  688.     mov    stbuf,0            ; first element of buffer 
  689.     mov    nkeys,0            ; clear number of defined keys
  690.     call    msuinit            ; restore startup definitions
  691.     clc                ; success
  692.     ret
  693.                     ; Multi-char key identification
  694. dfkey1:    mov    si,offset tranbuf    ; point to key ident text
  695.     cmp    byte ptr [si],'0'    ; is first character numeric?
  696.     jb    dfkey1a            ; b = no
  697.     cmp    byte ptr [si],'9'    ; in numbers?
  698.     ja    dfkey1a            ; a = no
  699.     mov    keycode,scan        ; setup keycode for scan value
  700.     mov    dx,si            ; get length of string in cx
  701.     call    strlen
  702.     push    ds
  703.     pop    es            ; make es point to data segment
  704.     push    si
  705.     add    si,cx            ; point at string terminator
  706.     mov    di,si
  707.     inc    di            ; place to store string (1 byte later)
  708.     inc    cx            ; include null terminator
  709.     std                ; work backward
  710.     rep    movsb            ; move string one place later
  711.     cld
  712.     pop    si
  713.     mov    byte ptr [si],'\'    ; make ascii digits into \nnn form
  714.     mov    oldform,0ffh        ; set old form flag
  715.     mov    dx,offset kwarnmsg    ; tell user this is old form
  716.     mov    ah,prstr
  717.     int    dos
  718. dfkey1a:call    katoi            ; convert ascii number to binary in ax
  719.     jc    dfkey0            ; c = no number converted
  720.     or    keycode,ax        ; store in keycode
  721.  
  722. dfkey1b:                ; Get Definition proper
  723.     test    oldform,0ffh        ; old form Set Key active?
  724.     jz    dfkey1f            ; z = no
  725.     mov    bx,offset tranbuf    ; get new definition on main cmd line
  726.     mov    word ptr [bx],0        ; insert terminator
  727.     mov    dx,offset dfhelp2    ; help for definition of key
  728.     mov    ah,cmline        ; read rest of line into tranbuf
  729.     call    comnd            ; allow null definitions
  730.     or    ax,ax            ; char count zero?
  731.     jz    dfkey1e            ; z = zero, prompt for definition
  732.     jmp    dfkey1g            ; process definition
  733.  
  734. dfkey1e:mov    ah,prstr
  735.     mov    dx,offset crlf
  736.     int    dos
  737.     mov    dx,offset dfaskdf    ; prompt for definition string
  738.      call    prompt            ; Kermit prompt routine
  739.     mov    comand.cmcr,1        ; permit bare carriage returns
  740.     mov    comand.cmwhite,1    ; allow leading whitespace
  741. dfkey1f:mov    bx,offset tranbuf    ; get new definition
  742.     mov    word ptr [bx],0        ; insert terminator
  743.     mov    dx,offset dfhelp2    ; help for definition of key
  744.     mov    ah,cmline        ; read rest of line into tranbuf
  745.     call    comnd
  746.     jc    dfkey1x            ; exit now on ^C from user
  747.     cmp    comand.cmcr,0        ; prompting for definition?
  748.     je    dfkey1g            ; e = no, trim leading whitespace
  749.     mov    comand.cmcr,0        ; turn off allowance for bare c/r's
  750.     jmp    dfkey2            ; interactive, allow leading whitespace
  751. dfkey1x:ret                ; failure exit
  752.  
  753. dfkey1g:push    ax            ; save count
  754.     mov    ah,cmeol        ; get a confirm
  755.     call    comnd
  756.     pop    cx            ; string length
  757.     jc    dfkey1x            ; none so declare parse error
  758.     
  759. dfkey2:                    ; Examine translation
  760.     mov    al,trans.escchr        ; current escape char (port dependent)
  761.     cmp    al,byte ptr keycode    ; is this Kermit's escape char?
  762.     jne    dfkey2a            ; ne = no
  763.     test    keycode,scan        ; see if scan code
  764.     jnz    dfkey2a            ; nz = scan, so not ascii esc char
  765.     mov    dx,offset dfkoops    ; Oops! msg
  766.     mov    ah,prstr        ; complain and don't redefine
  767.     int    dos
  768.     stc                ; failure
  769.     ret
  770.  
  771. dfkey2a:push    di            ; get a director code for this key
  772.     push    cx    
  773.     mov    di,offset keylist    ; list of keycodes
  774.     mov    cx,nkeys        ; number currently defined
  775.     mov    ax,keycode        ; present keycode
  776.     jcxz    dfkey2b            ; cx = 0 means none defined yet
  777.     cld
  778.     push    ds
  779.     pop    es
  780.     repne    scasw            ; is current keycode in the list?
  781.     jne    dfkey2b            ; ne = not in list
  782.     sub    di,2            ; correct for auto increment
  783.     sub    di,offset keylist
  784.     mov    listptr,di        ; list pointer for existing definition
  785.     pop    cx
  786.     pop    di
  787.     jmp    dfkey3            ; go process definition
  788.  
  789. dfkey2b:pop    cx            ; key not currently defined so
  790.     pop    di            ;  make a new director entry for it
  791.     mov    bx,nkeys        ; number of keys previously defined
  792.     cmp    bx,maxkeys        ; enough space?
  793.     jae    dfkey2c            ; ae = no, complain
  794.     shl    bx,1            ; count words
  795.     mov    listptr,bx        ; index into word list
  796.     mov    ax,keycode        ; get key's code
  797.     mov    keylist[bx],ax        ; store it in list of keycodes
  798.     mov    dirlist[bx],0        ; clear the new director entry
  799.     inc    nkeys            ; new number of keys
  800.     jmp    dfkey3            ; go process definition
  801.  
  802. dfkey2c:mov    dx,offset keyfull    ; say key space is full already
  803.     mov    ah,prstr
  804.     int    dos
  805.     stc                ; failure
  806.     ret
  807.  
  808. ; listptr has element number in keylist or dirlist; keycode has key's code.
  809.  
  810. ; Parse new definition. First look for Kermit verbs as a line beginning
  811. ; as \K or \{K. Otherwise, consider the line to be a string.
  812. ; In any case, update the Director table for the new definition.
  813.  
  814. dfkey3:    mov    brace,0            ; assume not using braces
  815.     mov    si,offset tranbuf    ; start of definition text
  816.     cmp    byte ptr [si],'\'    ; starts with escape char?
  817.     jne    dfkey5            ; ne = no, so we have a string
  818.     inc    si            ; skip the backslash
  819.     cmp    byte ptr [si],braceop    ; starts with \{?
  820.     jne    dfkey3a            ; ne = no
  821.     inc    si            ; skip the opening brace
  822.     mov    brace,bracecl        ; expect closing brace
  823. dfkey3a:cmp    byte ptr [si],'K'    ; starts with \{K or \K?
  824.     je    dfkey3b            ; e = yes
  825.     cmp    byte ptr [si],'k'    ; starts as \{k or \k?
  826.     jne    dfkey5            ; ne = no, then it's a string
  827. dfkey3b:inc    si            ; yes, skip the K too
  828.                     ; Kermit action VERBS
  829.     push    si            ; save verb name start address
  830. dfkey4:    cld
  831.     lodsb                ; scan til closing brace or w/s or end
  832.     or    al,al            ; premature end?
  833.     jz    dfkey4b            ; z = yes, accept without brace
  834.     cmp    al,brace        ; closing brace?
  835.     je    dfkey4b            ; e = yes
  836.     cmp    al,spc            ; white space or control char?
  837.     ja    short dfkey4        ; a = no, so not at end yet
  838. dfkey4b:mov    byte ptr[si-1],0    ; insert null terminator
  839.     pop    si            ; recover start address
  840.     call    tstkeyw            ; find keyword, kw # returned in kbtemp
  841.     jc    dfkey4d            ; c = no keyword found, complain
  842.     call    remstr            ; clear old string, if string
  843.     mov    ax,kbtemp        ; save keyword number
  844.     and    ax,not(verb+strng)    ; clear verb / string field
  845.     or    ax,verb            ; set verb ident
  846.     mov    si,listptr
  847.     mov    dirlist[si],ax        ; store info in Director table
  848.     jmp    dfkey7            ; show results and return success
  849.  
  850. dfkey4d:mov    dx,offset verbbad    ; say no such verb
  851.     mov    ah,prstr
  852.     int    dos
  853.     stc                ; failure
  854.     ret
  855.  
  856. ; Here we are left with the definition string; si points to its start, and
  857. ; kbtemp holds its length (number of bytes). Null termination. If the string
  858. ; begins with an opening brace it terminates on a matching closing brace
  859. ; or the end of line, whichever occurs first. Trailing whitespace removed
  860. ; before examining braces.
  861. ; Null length strings mean define key as Self.
  862.                     ; STRING definitions
  863. dfkey5:    call    remstr            ; first, clear old string, if any
  864.     mov    si,offset tranbuf    ; si=source, di=dest, convert in-place
  865.     mov    di,si
  866.     call    cnvlin            ; convert numbers, cx gets line length
  867.     mov    si,offset tranbuf    ; provide address of new string
  868.     cmp    cx,1            ; just zero or one byte to do?
  869.     jbe    dfkey6            ; e = yes, do as a char
  870.     call    insertst        ; insert new string, returns reg cx.
  871.     jc    dfkey5h            ; c = could not do insert
  872.     mov    si,listptr        ; cx has type and string number
  873.     mov    dirlist[si],cx        ; update Director table from insertst
  874.     jmp    dfkey7            ; show results and return success
  875.  
  876. dfkey5h:mov    dx,offset strbad    ; display complaint
  877.     mov    ah,prstr
  878.     int    dos
  879.     stc                ; failure
  880.     ret
  881.  
  882.         ; define SINGLE CHAR replacement or CLEAR a key definition.
  883.         ; cx has char count 1 (normal) or 0 (to undefine the key).
  884. dfkey6:    jcxz    dfkey6c            ; z = cx= 0, clear definition
  885.     mov    al,byte ptr [si]    ; get first byte from definition
  886.     xor    ah,ah            ; set the type bits to Char
  887.     mov    si,listptr
  888.     mov    dirlist[si],ax        ; store type and key's new code
  889.     jmp    dfkey7            ; return success
  890.  
  891. dfkey6c:push    si            ; clear a definition,
  892.     push    di            ; listptr points to current def
  893.     mov    si,listptr        ; starting address to clear
  894.     add    si,offset dirlist
  895.     mov    di,si            ; destination
  896.     add    si,2            ; source is next word
  897.     mov    cx,nkeys        ; current number of keys defined
  898.     add    cx,cx            ; double for listptr being words
  899.     sub    cx,listptr        ; cx = number of words to move
  900.     shr    cx,1            ; convert to actual number of moves
  901.     jcxz    dfkey6d            ; z = none, just remove last word
  902.     push    es
  903.     push    ds
  904.     pop    es            ; make es:di point to data segment
  905.     cld
  906.     push    cx            ; save cx
  907.     rep    movsw            ; move down higher list items
  908.     pop    cx
  909.     mov    si,listptr        ; do keylist too, same way
  910.     add    si,offset keylist
  911.     mov    di,si
  912.     add    si,2
  913.     rep    movsw
  914.     pop    es
  915. dfkey6d:mov    si,nkeys        ; clear old highest list element
  916.     shl    si,1            ; address words
  917.     mov    dirlist[si],0        ; null the element
  918.     mov    keylist[si],0        ; null the element
  919.     dec    nkeys            ; say one less key defined now
  920.     pop    di            ; restore saved registers
  921.     pop    si
  922.  
  923. dfkey7:    mov    ah,msutake        ; Finish up. In a Take file?
  924.     or    ah,taklev        ; or even directly
  925.     or    ah,ah
  926.     jz    dfkey7a            ; z = no
  927.     cmp    flags.takflg,0        ; echo Take commands?
  928.     je    dfkey7b            ; e = no
  929. dfkey7a:mov    ah,prstr        ; display cr/lf
  930.     mov    dx,offset crlf
  931.     int    dos
  932.     call    shkey0            ; show new definition (in SHKEY)
  933.     call    shkfre            ; show free string space
  934. dfkey7b:clc                ; return success
  935.     ret
  936. DFKEY    ENDP
  937.  
  938. ; SHOW KEY <cr> command. Call from Kermit level. Vectored here by SHOW
  939. ; command. Replaces obsolete procedure in msx---.
  940. ; Prompts for a key and shows that key's (or all if ? entered) keycode,
  941. ; definition, and the key definition free space remaining.
  942.  
  943. SHKEY    PROC    NEAR            ; Show key's definition command
  944.     mov    ah,cmeol        ; get a confirm
  945.     call    comnd            ; ignore any additional text
  946.     push    bx
  947.     mov    dx,offset shkmsg1    ; ask for original key
  948.     mov    ah,prstr
  949.     int    dos
  950.     or    byte ptr kbcodes,80h    ; say kbcodes not-initiated
  951. shky0:    call    getkey            ; read keyboard, output to keycode
  952.     jc    shky0            ; wait for a key (c = nothing there)
  953.     cmp    byte ptr keycode,'?'    ; query for all keys?
  954.     jne    shky0a            ; ne = no, not a query
  955.     test    keycode,scan        ; is this a scan code, vs ascii query?
  956.     jz    shky0c            ; z = no Scan, so it is a query
  957.  
  958. shky0a:    mov    ah,prstr        ; show single key. Setup display
  959.     mov    dx,offset crlf
  960.     int    dos
  961.     call    shkey0            ; show just one key
  962. shky0b:    call    shkfre            ; show free string space
  963.     jmp    shkeyx            ; exit
  964.  
  965. shky0c:    mov    cx,nkeys        ; Show all keys. nkeys = number defined
  966.     jcxz    shky0b            ; z = none to show
  967.     mov    si,offset keylist    ; list of definitions
  968.     push    si            ; save pointer
  969. shky1:    pop    si            ; recover pointer
  970.     cld
  971.     lodsw                ; get a keycode
  972.     push    si            ; save pointer
  973.     push    cx            ; save counter
  974.     mov    keycode,ax        ; save new keycode
  975.     mov    ah,prstr
  976.     mov    dx,offset crlf
  977.     int    dos
  978.     call    shkey0            ; show this keycode
  979.  
  980.     pop    cx            ; pause between screens, recover cntr
  981.     push    cx            ; save it again
  982.     dec    cx            ; number yet to be shown
  983.     jcxz    shky1b            ; z = have now shown all of them
  984.     mov    ax,nkeys        ; number of defined keys
  985.     sub    ax,cx            ; minus number yet to be displayed
  986.     xor    dx,dx            ; clear extended numerator
  987.     div    twelve            ; two lines per definition display
  988.     or    dx,dx            ; remainder zero (12 defs shown)?
  989.     jnz    shky1b            ; nz = no, not yet so keep going
  990.     mov    ah,prstr
  991.     mov    dx,offset shkmsg3    ; "push any key to continue" msg
  992.     int    dos
  993. shky1a:    mov    ah,0bh            ; check console, check ^C
  994.     int    dos
  995.     cmp    flags.cxzflg,'C'    ; a ^C?
  996.     je    shky1b            ; e = yes, quit
  997.     or    al,al
  998.     jz    shky1a            ; z = nothing
  999.     call    getkey            ; get any key
  1000.     jc    shky1a            ; c = nothing at keyboard yet, wait
  1001. shky1b:    pop    cx            ; resume loop
  1002.     cmp    flags.cxzflg,'C'    ; a ^C?
  1003.     je    shky1c            ; e = yes, quit
  1004.     loop    shky1
  1005. shky1c:    pop    si            ; clean stack
  1006.     call    shkfre            ; show free string space
  1007.     jmp    shkeyx            ; exit
  1008.  
  1009.         ; show key worker routine, called from above
  1010.                     ; SHKEY0 called by DFKEY just above
  1011. SHKEY0:    test    keycode,scan        ; scan code?
  1012.     jz    shkey1            ; z = no, regular ascii
  1013.  
  1014.                     ; SCAN codes
  1015.     mov    dx,offset scanmsg    ; say Scan Code:
  1016.     mov    ah,prstr
  1017.     int    dos
  1018.     mov    ah,conout
  1019.     mov    dl,'\'            ; add backslash before number
  1020.     int    dos
  1021.     mov    ax,keycode        ; get key's code again
  1022.     call    decout            ; display 16 bit decimal keycode
  1023.     jmp    shkey2            ; go get definition
  1024.  
  1025. shkey1:    mov    dx,offset ascmsg    ; say ASCII CHAR
  1026.     mov    ah,prstr
  1027.     int    dos
  1028.     mov    dl,byte ptr keycode    ; get ascii code (al part of input)
  1029.     mov    ah,conout
  1030.     cmp    dl,spc            ; control code?
  1031.     jae    shkey1a            ; ae = no
  1032.     push    dx            ; save char
  1033.     mov    dl,5eh            ; show caret first
  1034.     int    dos
  1035.     pop    dx
  1036.     add    dl,'A'-1        ; ascii bias
  1037. shkey1a:cmp    dl,del            ; DEL?
  1038.     jne    shkey1b            ; ne = no
  1039.     mov    dl,'D'            ; spell out DEL
  1040.     int    dos
  1041.     mov    dl,'E'
  1042.     int    dos
  1043.     mov    dl,'L'
  1044. shkey1b:int    dos
  1045.     mov    dl,spc            ; add a couple of spaces
  1046.     int    dos
  1047.     int    dos
  1048.     mov    dl,'\'            ; add backslash before number
  1049.     int    dos
  1050.     mov    ax,keycode        ; show 16 bit keycode in decimal
  1051.     call    decout            ; and go get definiton
  1052.  
  1053.                     ; Display defintion
  1054. shkey2:    mov    dx,offset shkmsg2    ; intermediate part of reply
  1055.     mov    ah,prstr        ; " is defined as "
  1056.     int    dos
  1057.     push    di            ; get a director code for this key
  1058.     push    cx    
  1059.     mov    di,offset keylist    ; list of keycodes
  1060.     mov    cx,nkeys        ; number currently defined
  1061.     jcxz    shkey2a            ; z = none
  1062.     mov    ax,keycode        ; present keycode
  1063.     push    ds
  1064.     pop    es            ; use data segment for es:di
  1065.     cld
  1066.     repne    scasw            ; is current keycode in the list?
  1067.     jne    shkey2a            ; ne = not in list
  1068.     sub    di,2            ; correct for auto increment
  1069.     sub    di,offset keylist
  1070.     mov    listptr,di        ; list pointer for existing definition
  1071.     pop    cx
  1072.     pop    di
  1073.     jmp    shkey3            ; go process definition
  1074.  
  1075. shkey2a:pop    cx
  1076.     pop    di
  1077.     mov    dx,offset noxmsg    ; say Self (no translation)
  1078.     mov    ah,prstr
  1079.     int    dos
  1080.     ret                ; return to main show key loop
  1081.  
  1082. shkey3:                    ; translations, get kind of.
  1083.     mov    si,listptr
  1084.     test    dirlist[si],verb    ; defined as verb?
  1085.     jnz    shkey6            ; nz = yes, go do that one
  1086.     test    dirlist[si],strng    ; defined as string?
  1087.     jz    shkey3a            ; z = no
  1088.     jmp    shkey8            ; yes, do string display
  1089. shkey3a:
  1090.     mov    dx,offset ascmsg    ; CHAR. say 'Ascii char:'
  1091.     mov    ah,prstr
  1092.     int    dos
  1093.     mov    ax,dirlist [si]        ; get type and char
  1094.     mov    dl,al            ; put char here for display
  1095.     push    ax            ; save here too
  1096.     mov    ah,conout
  1097.     cmp    dl,spc            ; control code?
  1098.     jae    shkey4            ; ae = no
  1099.     push    dx
  1100.     mov    dl,5eh            ; show caret
  1101.     int    dos
  1102.     pop    dx
  1103.     add    dl,'A'-1        ; add ascii bias
  1104. shkey4:    cmp    dl,del            ; DEL?
  1105.     jne    shkey4a            ; ne = no
  1106.     mov    dl,'D'            ; spell out DEL
  1107.     int    dos
  1108.     mov    dl,'E'
  1109.     int    dos
  1110.     mov    dl,'L'
  1111. shkey4a:int    dos
  1112.     mov    dl,spc            ; add a couple of spaces
  1113.     mov    ah,conout
  1114.     int    dos
  1115.     int    dos
  1116.     mov    dl,'\'            ; add backslash before number
  1117.     int    dos
  1118.     pop    ax            ; recover char
  1119.     xor    ah,ah            ; clear high byte
  1120.     call    decout            ; show decimal value
  1121.     ret                ; return to main show key loop
  1122.  
  1123. shkey6:    mov    ah,prstr        ; VERB
  1124.     mov    dx,offset verbmsg    ; say 'verb'
  1125.     int    dos
  1126.     mov    si,listptr        ; get verb index from director
  1127.     mov    dx,dirlist[si]
  1128.     and    dx,not(verb+strng)    ; remove type bits, leaves verb number
  1129.     mov    bx,offset kverbs    ; table of verbs & actions
  1130.     mov    al,byte ptr [bx]    ; number of keywords
  1131.     xor    ah,ah
  1132.     dec    ax
  1133.     mov    kwcnt,ax        ; save number of last one here
  1134.     cmp    dx,ax            ; asking for more than we have?
  1135.     ja    shkeyx            ; a = yes, exit bad
  1136.     inc    bx            ; point to first slot
  1137.     xor    cx,cx            ; current slot number
  1138. shkey6b:cmp    cx,dx            ; this slot?
  1139.     je    shkey6c            ; e = yes, print the text part
  1140.     ja    shkeyx            ; a = beyond, exit bad
  1141.     mov    ax,[bx]            ; get cnt (keyword length)
  1142.     add    ax,4            ; skip count and two byte value
  1143.     add    bx,ax            ; bx = start of next keyword slot
  1144.     inc    cx            ; current keyword number
  1145.     jmp    short shkey6b        ; try another
  1146. shkey6c:push    cx
  1147.     mov    cx,[bx]            ; length of definition
  1148.     add    bx,2            ; look at text field
  1149.     mov    di,bx            ; offset for printing
  1150.     call    prtscr            ; print counted string
  1151.     mov    ah,conout
  1152.     mov    dl,spc            ; add a couple of spaces
  1153.     int    dos
  1154.     int    dos
  1155.     mov    dl,'\'            ; show verb name as \Kverb
  1156.     int    dos
  1157.     mov    dl,'K'
  1158.     int    dos
  1159.     call    prtscr            ; print counted string, again
  1160.     pop    cx
  1161.     ret                ; return to main show key loop
  1162.  
  1163. shkey8:    mov    ah,prstr        ; STRING
  1164.     mov    dx,offset strngmsg    ; say String:
  1165.     int    dos
  1166.     mov    si,listptr        ; get index from director
  1167.     mov    bx,dirlist[si]
  1168.     and    bx,not(verb+strng)    ; remove type bits
  1169.     shl    bx,1            ; index words
  1170.     mov    si,sptable[bx]        ; table of string offsets
  1171.     mov    cx,word ptr [si]    ; get string length
  1172.     add    si,2            ; point to string text
  1173.     mov    ah,conout
  1174. shkey8a:cld
  1175.     lodsb                ; get a byte
  1176.     cmp    al,spc            ; control code?
  1177.     jae    shkey8b            ; ae = no
  1178.     push    ax
  1179.     mov    dl,5eh            ; show caret first
  1180.     int    dos
  1181.     pop    ax
  1182.     add    al,40h            ; convert to printable for display
  1183. shkey8b:mov    dl,al
  1184.     int    dos            ; display it
  1185.     loop    shkey8a            ; do another
  1186.     ret                ; return to main show key loop
  1187.     
  1188. shkeyx:    pop    bx            ; restore reg
  1189.     clc                ; return success
  1190.     ret
  1191. SHKEY    ENDP
  1192.  
  1193. ;;;    keyboard translator local support procedures, system independent
  1194.  
  1195. ; Tstkeyw checks text word pointed to by si against table of keywords (pointed
  1196. ; to by kverbs, made by mkeyw macro); returns in bx either action value or 0.
  1197. ; Returns in kbtemp the number of the keyword and carry clear, or if failure
  1198. ; returns kbtemp zero and carry set.
  1199. ; Keyword structure is:         dw    cnt    (length of string 'word')
  1200. ;                 db    'word'    (keyword string)
  1201. ;                 dw    value    (value returned in bx)
  1202. ; Make these with macro mkeyw such as   mkeyw 'test',15   with the list of
  1203. ; such keywords headed by a byte giving the number of keywords in the list.
  1204. tstkeyw    proc    near
  1205.     push    ax
  1206.     push    cx
  1207.     push    si
  1208.     mov    verblen,0        ; verblen will hold verb length
  1209.     push    si            ; save user's verb pointer
  1210. tstkw1:    cld
  1211.     lodsb                ; get a verb character
  1212.     cmp    al,spc            ; verbs are all non-spaces and above
  1213.     jbe    tstkw2            ; be = done (space or control char)
  1214.     inc    verblen            ; count verb length
  1215.     jmp    short tstkw1        ; printable char, look for more
  1216. tstkw2:    pop    si            ; pointer to verb
  1217.     mov    bx,offset kverbs    ; table of Kermit verb keywords
  1218.     mov    al,byte ptr [bx]    ; number of keywords
  1219.     xor    ah,ah
  1220.     mov    kwcnt,ax        ; save number of keywords here
  1221.     inc    bx            ; point bx to first slot
  1222.     mov    kbtemp,0        ; remember which keyword
  1223.  
  1224. tstkw3:                    ; match table keyword and text word
  1225.     mov    cx,verblen        ; length of user's verb
  1226.     cmp    [bx],cx            ; compare length vs table keyword
  1227.     jne    tstkw4            ; ne = not equal lengths, try another
  1228.     push    si            ; lengths match, how about spelling?
  1229.     push    bx
  1230.     add    bx,2            ; point at start of keyword
  1231. tstkw3a:mov    ah,byte ptr [bx]    ; keyword char
  1232.     mov    al,byte ptr [si]    ; text char
  1233.     cmp    ah,'A'
  1234.     jb    tstkw3b            ; b = control chars
  1235.     cmp    ah,'Z'
  1236.     ja    tstkw3b            ; a = not upper case alpha
  1237.     add    ah,'a'-'A'        ; convert upper case to lower case
  1238. tstkw3b:cmp    al,'A'
  1239.     jb    tstkw3c
  1240.     cmp    al,'Z'
  1241.     ja    tstkw3c
  1242.     add    al,'a'-'A'        ; convert upper case to lower case
  1243. tstkw3c:cmp    al,ah            ; test characters
  1244.     jne    tstkw3d            ; ne = no match
  1245.     inc     si            ; move to next char
  1246.     inc    bx
  1247.     loop    tstkw3a            ; loop through entire length
  1248. tstkw3d:pop    bx
  1249.     pop    si
  1250.     jcxz    tstkw5            ; z: cx = 0, exit with match;
  1251.                     ;  else select next keyword
  1252. tstkw4:    inc    kbtemp            ; number of keyword to test next
  1253.     mov    cx,kbtemp
  1254.     cmp    cx,kwcnt        ; all done? Recall kbtemp starts at 0
  1255.     jae    tstkwx            ;ae = exhausted search, unsuccessfully
  1256.     mov    ax,[bx]            ; cnt (keyword length from macro)
  1257.     add    ax,4            ; skip over count and two byte value
  1258.     add    bx,ax            ; bx = start of next keyword slot
  1259.     jmp    tstkw3            ; do another comparison
  1260.  
  1261. tstkw5:                    ; get action pointer
  1262.     mov    ax,[bx]            ; cnt (keyword length from macro)
  1263.     add    ax,2            ; skip over count
  1264.     add    bx,ax            ; now bx points to dispatch value
  1265.     mov    bx,[bx]            ; bx holds dispatch value
  1266.     clc                ; carry clear for success
  1267.     jmp    short tstkwxx        ; exit
  1268.     ret
  1269. tstkwx:    xor    bx,bx            ; exit when no match
  1270.     mov    kbtemp,bx        ; make verb number be zero too
  1271.     stc                ; carry set for failure
  1272. tstkwxx:pop    si
  1273.     pop    cx
  1274.     pop    ax
  1275.     ret
  1276. tstkeyw    endp
  1277.  
  1278. ; Insert asciiz string pointed to by si into string buffer stbuf.
  1279. ; Reg cx has string length upon entry.
  1280. ; Success: returns offset of first free byte (strmax) in string buffer stbuf,
  1281. ; cx = type and Index of new string, and carry clear.
  1282. ; Failure = carry set.
  1283. insertst proc    near
  1284.     push    bx
  1285.     push    dx
  1286.     push    si
  1287.     push    di
  1288.     push    kbtemp        ; save this variable too
  1289.     mov    dx,cx        ; save length of incoming string in dx
  1290.     mov    bx,offset sptable ; table of string offsets
  1291.     mov    kbtemp,0    ; slot number
  1292.     mov    cx,maxstng    ; number of entries, find an empty slot
  1293. insert1:cmp    word ptr[bx],0    ; slot empty?
  1294.     je    insert2        ; e = yes
  1295.     inc    kbtemp        ; remember slot number
  1296.     add    bx,2        ; look at next slot
  1297.     loop    insert1        ; keep looking
  1298.     jmp    short insert4    ; get here if no empty slots
  1299. insert2:            ; see if stbuf has sufficient space
  1300.     mov    cx,dx        ; length of new string to cx
  1301.     mov    di,strmax    ; offset of first free byte in stbuf
  1302.     add    di,cx        ; di = address where this string would end
  1303.     cmp    di,offset stbuf+stbuflen ; beyond end of buffer?
  1304.     jae    insert4        ; ae = yes, not enough room
  1305.     mov    di,strmax    ; point to first free slot in stbuf
  1306.     mov    [bx],di        ; fill slot with address offset of buffer
  1307.     push    es
  1308.     push    ds
  1309.     pop    es        ; point es:di to data segment
  1310.     cld
  1311.     mov    [di],cx     ; length of text for new string
  1312.     add    di,2        ; move to next storage slot
  1313.     rep    movsb        ; copy string text
  1314.     pop    es
  1315.     mov    strmax,di    ; offset of next free byte
  1316.     mov    cx,kbtemp    ; return new slot number with Director Index
  1317.     and    cx,not(strng+verb) ; clear type bits
  1318.     or    cx,strng    ; say type is multi-char string
  1319.     clc            ; say success
  1320.     jmp    short insertx    ; exit
  1321. insert4:stc            ; say no-can-do
  1322. insertx:pop    kbtemp
  1323.     pop    di
  1324.     pop    si
  1325.     pop    dx
  1326.     pop    bx
  1327.     ret
  1328. insertst endp
  1329.  
  1330. ; Remove (delete) string. Enter with listptr preset for director entry.
  1331. ; Acts only on existing multi-char strings; recovers freed space.
  1332. ; All registers preserved.
  1333. remstr    proc    near        
  1334.     push    si
  1335.     mov    si,listptr        ; list pointer
  1336.     test    dirlist[si],strng    ; multi-char string?
  1337.     pop    si
  1338.     jnz    remst1            ; nz = a multi-char string
  1339.     ret                ; else do nothing
  1340. remst1:    push    ax
  1341.     push    bx
  1342.     push    cx
  1343.     push    dx
  1344.     push    si
  1345.     mov    si,listptr
  1346.     mov    ax,dirlist[si]         ; Director table entry
  1347.     and    ax,not(strng+verb) ; clear type bits, leave string's pointer
  1348.     mov    dirlist[si],0        ; clear Director table entry
  1349.     shl    ax,1            ; index words not bytes
  1350.     mov    si,offset sptable     ; list of string offsets in stbuf
  1351.     add    si,ax            ; plus index = current slot
  1352.     mov    bx,[si]            ; get offset of string to be deleted
  1353.     mov    dx,bx            ; save in dx for later
  1354.     mov    cx,[bx]            ; get length of subject string
  1355.     add    cx,2            ; length word too, cx has whole length
  1356.     sub    strmax,cx    ; count space to be freed (adj end-of-buf ptr)
  1357.     mov    word ptr [si],0    ; clear sptable of subject string address
  1358.     push    cx            ; save length of purged string
  1359.     push    di            ; save di
  1360.     push    si
  1361.     push    es            ; save es
  1362.     push    ds
  1363.     pop    es        ; setup es:di to be ds:offset of string
  1364.     mov    di,dx        ; destination = start address of purged string
  1365.     mov    si,dx        ; source = start address of purged string
  1366.     add    si,cx        ;  plus string length of purged string.
  1367.     mov    cx,offset stbuf+stbuflen ; 1 + address of buffer end
  1368.     sub    cx,si            ; 1 + number of bytes to move
  1369.     dec    cx            ; number of bytes to move
  1370.     jcxz    remst2            ; z = none
  1371.     cld                ; direction is forward
  1372.     rep    movsb            ; move down preserved strings
  1373. remst2:    pop    es            ; restore regs
  1374.     pop    di
  1375.     pop    si
  1376.     pop    ax        ; recover length of purged string (was in cx)
  1377.     mov    bx,offset sptable     ; string pointer table
  1378.     mov    cx,maxstng        ; max mumber of entries
  1379. remst4:    cmp    [bx],dx        ; does this entry occur before purged string?
  1380.     jbe    remst5        ; be = before or equal, so leave it alone
  1381.     sub    [bx],ax        ; recompute address (remove old string space)
  1382. remst5:    add    bx,2            ; look at next list entry
  1383.     loop    remst4            ; do all entries in sptable
  1384.     pop    si
  1385.     pop    dx
  1386.     pop    cx
  1387.     pop    bx
  1388.     pop    ax
  1389.     ret
  1390. remstr    endp
  1391.  
  1392. shkfre    proc    near            ; show free key & string defs & space
  1393.     push    ax            ; preserves all registers.
  1394.     push    bx
  1395.     push    cx
  1396.     push    dx
  1397.     push    kbtemp
  1398.     mov    dx,offset fremsg
  1399.     mov    ah,prstr
  1400.     int    dos
  1401.     mov    ax,maxkeys        ; max number of key defs
  1402.     sub    ax,nkeys        ; number currently used
  1403.     call    decout            ; show the value
  1404.     mov    ah,prstr
  1405.     mov    dx,offset kyfrdef    ; give key defs msg
  1406.     int    dos
  1407.     mov    bx,offset sptable    ; table of string pointers
  1408.     mov    cx,maxstng        ; number of pointers
  1409.     mov    kbtemp,0        ; number free
  1410. shkfr1:    cmp    word ptr [bx],0        ; slot empty?
  1411.     jne    shkfr2            ; ne = no
  1412.     inc    kbtemp            ; count free defs
  1413. shkfr2:    add    bx,2            ; look at next slot
  1414.     loop    shkfr1            ; do all of them
  1415.     mov    ax,kbtemp        ; number of free defs
  1416.     call    decout            ; display
  1417.     mov    dx,offset stfrdef    ; say free string defs
  1418.     mov    ah,prstr
  1419.     int    dos
  1420.     mov    ax,offset stbuf+stbuflen+1 ; 1 + last byte in stbuf
  1421.     sub    ax,strmax        ; offset of last free byte in stbuf
  1422.     call    decout
  1423.     mov    dx,offset stfrspc    ; give free space part of msg
  1424.     mov    ah,prstr
  1425.     int    dos
  1426.     pop    kbtemp
  1427.     pop    dx
  1428.     pop    cx
  1429.     pop    bx
  1430.     pop    ax
  1431.     ret
  1432. shkfre    endp
  1433.  
  1434. ; Initialize the keyboard tables at Kermit startup time. Optional procedure.
  1435. ; Requires kbdinlst to be configured with mkeyw macro in the form
  1436. ;    mkeyw    'definition',keytype*256+keycode
  1437. ; keytype is 0 for scan codes and non-zero for ascii.
  1438. ; Returns normally.
  1439. kbdinit    proc     near            ; read keyword kbdinlst and setup
  1440.     or    byte ptr kbcodes,80h    ; say kbcodes not-initiated
  1441.     push    ds            ;  initial keyboard assignments.
  1442.     pop    es            ; set es:di to data segment
  1443.     inc    taklev            ; pretend that we are in Take file
  1444.     mov    si,offset kbdinlst    ; start of list of definitions
  1445. kbdini1:mov    cx,[si]            ; cnt field (keyword length of macro)
  1446.     jcxz    kbdinix            ; z = null cnt field = end of list
  1447.     add    si,2            ; look at text field
  1448.     mov    di,offset tranbuf    ; where defkey expects text
  1449.     cld
  1450.     rep    movsb            ; copy cx chars to tranbuf
  1451.     mov    byte ptr [di],0        ; insert null terminator
  1452.     mov    ax,word ptr [si]    ; get value field
  1453.     mov    keycode,ax        ; set key ident value
  1454.     push    si
  1455.     call    dfkey2            ; put dfkey to work
  1456.     pop    si
  1457.     add    si,2            ; point to next entry
  1458.     jmp    kbdini1            ; keep working
  1459. kbdinix:dec    taklev            ; reset Take file level
  1460. kbdinx1:ret
  1461. kbdinit    endp
  1462. ;;;    End of System Independent Procedures
  1463.  
  1464. ;;;    Begin System Dependent Procedures
  1465.  
  1466. ; Read keyboard. System dependent.
  1467. ; Return carry set if nothing at keyboard.
  1468. ; If char present return carry clear with key's code in Keycode.
  1469. ; If key is ascii put that in the low byte of Keycode and clear bit Scan in
  1470. ; the high byte; otherwise, put the scan code in the lower byte and set bit
  1471. ; Scan in the high byte.
  1472. ; Bit Scan is set if key is not an ascii code.
  1473. ; Modifies register ax.
  1474. getkey    proc    near
  1475.     call    iseof            ; is stdin at eof?
  1476.     jnc    getky5            ; nc = not eof, get more
  1477.      mov    al,trans.escchr        ; Kermit's escape char
  1478.     mov    byte ptr keycode,al    ; save ascii char
  1479.     clc                ;  to get out gracefully at EOF
  1480.     ret                ; and exit
  1481. getky5:    mov    ah,dconio        ; check console
  1482.     mov    dl,0ffh         ; input desired
  1483.     int    dos
  1484.     jnz    getky1            ; nz = char available
  1485.     stc                ; carry set = nothing available
  1486.     jmp    short getkyx        ; exit on no char available
  1487. getky1: mov    keycode,0
  1488.     cmp    al,0            ; scan code being returned?
  1489.     jne    getky1a         ; ne = no
  1490.     mov    ah,dconio        ; read second byte (scan code)
  1491.     mov    dl,0ffh
  1492.     int    dos
  1493.     jz    getkyx            ; z = nothing there
  1494.     mov    ah,al            ; scan code goes here
  1495.     mov    al,0            ; ascii code goes here
  1496. getky1a:
  1497.     push    di            ; check key (ax) for aliases
  1498.     push    cx
  1499.     push    es
  1500.     mov    di,offset aliaskey    ; list of aliased keys
  1501.     mov    cx,aliaslen        ; number of entries
  1502.     jcxz    getky2            ; z = no entries
  1503.     push    ds
  1504.     pop    es            ; make es:di point to data segment
  1505.     cld
  1506.     repne    scasw            ; look for a match
  1507.     jne    getky2            ; ne = not there
  1508.     mov    al,0            ; force use of scan code (in ah)
  1509. getky2: pop    es
  1510.     pop    cx
  1511.     pop    di
  1512.     or    al,al            ; scan code being returned?
  1513.     jnz    getky3            ; nz = no
  1514.     xchg    ah,al            ; put scan code in ident area
  1515.     or    keycode,scan        ; set scan flag (vs ascii)
  1516. getky3: mov    byte ptr keycode,al    ; return key's code (usually ascii)
  1517.     clc                ; carry clear = got a char
  1518. getkyx: ret
  1519. getkey    endp
  1520.  
  1521.  
  1522. postkey proc    near            ; do sys dep action after reading
  1523.     ret                ; key during active translation
  1524. postkey endp
  1525. code    ends
  1526.     end
  1527.