home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / mskermit / msuibm.asm < prev    next >
Assembly Source File  |  2020-01-01  |  81KB  |  2,267 lines

  1.     NAME    msuibm
  2. ; File MSUIBM.ASM 
  3.     include mssdef.h
  4. ;    Copyright (C) 1982, 1997, Trustees of Columbia University in the 
  5. ;    City of New York.  The MS-DOS Kermit software may not be, in whole 
  6. ;    or in part, licensed or sold for profit as a software product itself,
  7. ;    nor may it be included in or distributed with commercial products
  8. ;    or otherwise distributed by commercial concerns to their clients 
  9. ;    or customers without written permission of the Office of Kermit 
  10. ;    Development and Distribution, Columbia University.  This copyright 
  11. ;    notice must not be removed, altered, or obscured.
  12. ; Keyboard translator, by Joe R. Doupnik, Dec 1986
  13. ;  with contributions from David L. Knoell.
  14. ; Edit history
  15. ; 12 Jan 1995 version 3.14
  16. ; Last edit
  17. ; 12 Jan 1995
  18.  
  19.     public    keybd, dfkey, shkey, msuinit, kbcodes
  20.     public    kbsusp, kbrest, kbhold        ;** LK250 support for IBM-PCs
  21.     public    saveuoff, saveulen
  22.  
  23. ; some definitions
  24. kbint    equ    16h            ; IBM, Bios keyboard interrupt
  25. shift    equ    200h            ; IBM, synonym for right or left shift
  26. control    equ    400h            ; IBM, synonym for control shift
  27. alt    equ    800h            ; IBM, synonym for alt shift
  28. enhanced equ    1000h            ; IBM, enhanced keyboard code
  29.  
  30. rgt_shift equ    1            ; IBM shift state bits
  31. lft_shift equ    2
  32. ctl_shift equ    4
  33. alt_shift equ    8
  34. numlock      equ    20h
  35.  
  36. maxkeys    equ    350            ; maximum number of key definitions
  37. maxstng    equ    256            ; maximum number of multi-char strings
  38. stbuflen equ    2000            ; length of string buffer (bytes)
  39.  
  40. verb    equ    8000h            ; dirlist flag: use verb action table
  41. strng    equ    4000h            ; dirlist flag: use string action table
  42. scan    equ    100h            ; keycode flag: code is scan not ascii
  43. braceop    equ    7bh            ; opening curly brace
  44. bracecl    equ    7dh            ; closing curly brace
  45.  
  46. data    segment
  47.     extrn taklev:byte, comand:byte, flags:byte, keyboard:word
  48.     extrn shkadr:word, stkadr:word, trans:byte, ttyact:byte
  49.                         ; system dependent references
  50.     extrn vtemu:byte, holdscr:byte        ; emulator data
  51.     extrn vtmacname:word, vtmaclen:word    ; external macro, in msyibm
  52.     extrn isps55:byte    ; [HF]940130 in MSXIBM.ASM
  53.     extrn ps55mod:byte    ; [HF]940206 in MSXIBM.ASM
  54.     extrn domath_ptr:word, domath_cnt:word, termesc_flag:byte
  55. ;;;    System Independent local storage
  56.  
  57. crlf    db    cr,lf,'$'
  58. dfaskky    db    cr,lf,' Push key to be defined: $'
  59. dfaskdf    db    ' Enter new definition: ',0        ; asciiz for prompt
  60. strbad    db    cr,lf,' Not enough space for new string',cr,lf,'$'
  61. keyfull    db    cr,lf,' No more space to define keys',cr,lf,'$'
  62. dfkoops    db    cr,lf,' Oops! That is Kermit',27h,'s Escape Char.'
  63.     db    ' Translation is not permitted.',cr,lf,'$'
  64. shkmsg1    db    cr,lf,'Push key to be shown (? shows all): $'
  65. shkmsg2    db    ' decimal is defined as',cr,lf,'$'
  66. shkmsg3    db    cr,lf,'... more, press a key to continue ...$'
  67. kwarnmsg db    cr,lf,' Notice: this form of Set Key is obsolete$'
  68.  
  69. ascmsg    db    ' Ascii char: $'
  70. scanmsg    db    ' Scan Code $'
  71. strngmsg db    ' String: $'
  72. verbmsg    db    ' Verb: $'
  73. noxmsg    db    ' Self, no translation.$'
  74. fremsg    db    cr,lf,' Free space: $'
  75. kyfrdef    db    ' key and $'
  76. stfrdef db    ' string definitions, $'
  77. stfrspc    db    ' string characters.',cr,lf,'$'
  78.     even
  79.  
  80. saveuoff label    word            ; per session save area start
  81. tranbuf    db    150 dup (?)        ; 150 byte translator work buffer
  82.     db    0            ; guard for overflow by one
  83.                     ; translation tables
  84. keylist    dw    maxkeys dup (0)        ; 16 bit keycodes, paralled by dirlist
  85. dirlist    dw    maxkeys dup (0)        ; director {v+s} + {index | new char}
  86. sptable    dw    maxstng dup (0)        ; list of asciiz string offsets
  87. stbuf    dw    stbuflen dup (0)    ; buffer for strings
  88. strmax    dw    stbuf            ; first free byte in stbuf
  89. stringcnt dw    0            ; qty of string chars to be processed
  90. stringptr dw    0            ; address of next string char
  91. nkeys    dw    0            ; number of actively defined keys
  92. listptr    dw    0            ; item number for keylist and dirlist
  93. keycode    dw    0            ; ascii/scan code for key
  94. kbtemp    dw    0            ; scratch storage for translator
  95. brace    db    0            ; brace detected flag byte
  96. msutake    db    0            ; if being run from take file or not
  97. verblen    dw    0            ; length of user's verb (work temp)
  98. kwcnt    dw    0            ; number of keywords (work temp)
  99. dosflg    db    0
  100. saveulen dw    ($ - saveuoff)        ; save area end
  101.  
  102. oldform    db    0            ; old form Set Key, if non-zero
  103. eleven    dw    11d            ; [HF]940211
  104. twelve    dw    12d
  105. ;;;    End System Independent Data Area
  106.  
  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 dw    (14*scan)+bs        ; Backspace key [hi=scan, lo=ascii]
  114.     dw    (55*scan)+'*'        ; keypad asterisk
  115.     dw    (74*scan)+'-'        ; keypad minus
  116.     dw    (78*scan)+'+'        ; keypad plus
  117.     dw    (71*scan)+'7'        ; keypad numeric area
  118.     dw    (72*scan)+'8'
  119.     dw    (73*scan)+'9'
  120.     dw    (75*scan)+'4'
  121.     dw    (76*scan)+'5'
  122.     dw    (77*scan)+'6'
  123.     dw    (79*scan)+'1'
  124.     dw    (80*scan)+'2'
  125.     dw    (81*scan)+'3'
  126.     dw    (82*scan)+'0'
  127.     dw    (83*scan)+'.'
  128.     dw    (83*scan)+','        ; German keypad had comma vs dot
  129.     dw    (15*scan)+tab
  130.     dw    (28*scan)+cr        ; typewriter Enter key
  131.     dw    (28*scan)+lf        ; typewriter Control-Enter
  132.     dw    (57*scan)+' '        ; space bar
  133.     dw    (01*scan)+1bh        ; Esc key
  134. aliaslen equ    ($-aliaskey) shr 1    ; number of words in aliaskey table
  135.  
  136. ifndef    no_network
  137. kverbs    db    163            ; number of table entries below
  138. else
  139. ifndef    no_tcp
  140. kverbs    db    163 - 3            ; number of table entries below
  141. else
  142. kverbs    db    163 - 4            ; number of table entries below
  143. endif    ; no_tcp
  144. endif    ; no_network
  145.     mkeyw    'uparr',uparrw        ; independent of ordering and case!
  146.     mkeyw    'dnarr',dnarrw        ; mkeyw 'name',procedure entry point
  147.     mkeyw    'lfarr',lfarr
  148.     mkeyw    'rtarr',rtarr
  149.     mkeyw    'Gold',pf1
  150.     mkeyw    'PF1',pf1
  151.     mkeyw    'PF2',pf2
  152.     mkeyw    'PF3',pf3
  153.     mkeyw    'PF4',pf4
  154.     mkeyw    'KP0',kp0
  155.     mkeyw    'KP1',kp1
  156.     mkeyw    'KP2',kp2
  157.     mkeyw    'KP3',kp3
  158.     mkeyw    'KP4',kp4
  159.     mkeyw    'KP5',kp5
  160.     mkeyw    'KP6',kp6
  161.     mkeyw    'KP7',kp7
  162.     mkeyw    'KP8',kp8
  163.     mkeyw    'KP9',kp9
  164.     mkeyw    'kpminus',kpminus
  165.     mkeyw    'kpcoma',kpcoma
  166.     mkeyw    'kpenter',kpenter
  167.     mkeyw    'kpdot',kpdot
  168.     mkeyw    'decF6',decf6
  169.     mkeyw    'decF7',decf7
  170.     mkeyw    'decF8',decf8
  171.     mkeyw    'decF9',decf9
  172.     mkeyw    'decF10',decf10
  173.     mkeyw    'decF11',decf11
  174.     mkeyw    'decF12',decf12
  175.     mkeyw    'decF13',decf13
  176.     mkeyw    'decF14',decf14
  177.     mkeyw    'decHelp',dechelp
  178.     mkeyw    'decDo',decdo
  179.     mkeyw    'decF17',decf17
  180.     mkeyw    'decF18',decf18
  181.     mkeyw    'decF19',decf19
  182.     mkeyw    'decF20',decf20
  183.     mkeyw    'decFind',decfind
  184.     mkeyw    'decInsert',decinsert
  185.     mkeyw    'decRemove',decremove
  186.     mkeyw    'decSelect',decselect
  187.     mkeyw    'decPrev',decprev
  188.     mkeyw    'decNext',decnext
  189.     mkeyw    'udkF6',udkf6
  190.     mkeyw    'udkF7',udkf7
  191.     mkeyw    'udkF8',udkf8
  192.     mkeyw    'udkF9',udkf9
  193.     mkeyw    'udkF10',udkf10
  194.     mkeyw    'udkF11',udkf11
  195.     mkeyw    'udkF12',udkf12
  196.     mkeyw    'udkF13',udkf13
  197.     mkeyw    'udkF14',udkf14
  198.     mkeyw    'udkF15',udkf15
  199.     mkeyw    'udkF16',udkf16
  200.     mkeyw    'udkF17',udkf17
  201.     mkeyw    'udkF18',udkf18
  202.     mkeyw    'udkF19',udkf19
  203.     mkeyw    'udkF20',udkf20
  204.     mkeyw    'Compose',kbdcompose
  205.     mkeyw    'termtype',vtans52
  206.     mkeyw    'reset',vtinit
  207.     mkeyw    'holdscrn',khold
  208.     mkeyw    'dnscn',dnwpg
  209.     mkeyw    'upscn',upwpg
  210.     mkeyw    'endscn',endwnd
  211.     mkeyw    'homscn',homwnd
  212.     mkeyw    'upone',upone
  213.     mkeyw    'dnone',dnone
  214.     mkeyw    'prtscn',trnprs
  215.     mkeyw    'dump',dmpscn
  216.     mkeyw    'modeline',trnmod
  217.     mkeyw    'break',sendbr
  218.     mkeyw    'lbreak',sendbl
  219.     mkeyw    'hangup',chang
  220.     mkeyw    'debug',kdebug
  221. ifndef    no_network
  222.     mkeyw    'nethold',ubhold
  223. endif    ; no_network
  224. ifndef    no_tcp
  225.     mkeyw    'tn_AYT',tn_AYT
  226.     mkeyw    'tn_IP',tn_IP
  227.     mkeyw    'nextsession',nextses
  228.     mkeyw    'session1',ses1
  229.     mkeyw    'session2',ses2
  230.     mkeyw    'session3',ses3
  231.     mkeyw    'session4',ses4
  232.     mkeyw    'session5',ses5
  233.     mkeyw    'session6',ses6
  234. endif    ; no_tcp
  235.     mkeyw    'null',snull
  236.     mkeyw    'logon',klogon
  237.     mkeyw    'logoff',klogof
  238.     mkeyw    'DOS',cdos
  239.     mkeyw    'help',cquery
  240.     mkeyw    'status',cstatus
  241.     mkeyw    'exit',cquit
  242.     mkeyw    'lfpage',lfpage
  243.     mkeyw    'rtpage',rtpage
  244.     mkeyw    'lfone',lfone
  245.     mkeyw    'rtone',rtone
  246.     mkeyw    'dgC1',dgkc1
  247.     mkeyw    'dgC2',dgkc2
  248.     mkeyw    'dgC3',dgkc3
  249.     mkeyw    'dgC4',dgkc4
  250.     mkeyw    'dgF1',dgkf1
  251.     mkeyw    'dgF2',dgkf2
  252.     mkeyw    'dgF3',dgkf3
  253.     mkeyw    'dgF4',dgkf4
  254.     mkeyw    'dgF5',dgkf5
  255.     mkeyw    'dgF6',dgkf6
  256.     mkeyw    'dgF7',dgkf7
  257.     mkeyw    'dgF8',dgkf8
  258.     mkeyw    'dgF9',dgkf9
  259.     mkeyw    'dgF10',dgkf10
  260.     mkeyw    'dgF11',dgkf11
  261.     mkeyw    'dgF12',dgkf12
  262.     mkeyw    'dgF13',dgkf13
  263.     mkeyw    'dgF14',dgkf14
  264.     mkeyw    'dgF15',dgkf15
  265.     mkeyw    'dgSF1',dgkSf1
  266.     mkeyw    'dgSF2',dgkSf2
  267.     mkeyw    'dgSF3',dgkSf3
  268.     mkeyw    'dgSF4',dgkSf4
  269.     mkeyw    'dgSF5',dgkSf5
  270.     mkeyw    'dgSF6',dgkSf6
  271.     mkeyw    'dgSF7',dgkSf7
  272.     mkeyw    'dgSF8',dgkSf8
  273.     mkeyw    'dgSF9',dgkSf9
  274.     mkeyw    'dgSF10',dgkSf10
  275.     mkeyw    'dgSF11',dgkSf11
  276.     mkeyw    'dgSF12',dgkSf12
  277.     mkeyw    'dgSF13',dgkSf13
  278.     mkeyw    'dgSF14',dgkSf14
  279.     mkeyw    'dgSF15',dgkSf15
  280.     mkeyw    'dgspcl',kbdcompose
  281.     mkeyw    'dgpoint',dgpoint
  282.     mkeyw    'dgnc',dgnckey
  283.     mkeyw    'wyseF1',wykf1
  284.     mkeyw    'wyseF2',wykf2
  285.     mkeyw    'wyseF3',wykf3
  286.     mkeyw    'wyseF4',wykf4
  287.     mkeyw    'wyseF5',wykf5
  288.     mkeyw    'wyseF6',wykf6
  289.     mkeyw    'wyseF7',wykf7
  290.     mkeyw    'wyseF8',wykf8
  291.     mkeyw    'wyseF9',wykf9
  292.     mkeyw    'wyseF10',wykf10
  293.     mkeyw    'wyseF11',wykf11
  294.     mkeyw    'wyseF12',wykf12
  295.     mkeyw    'wyseF13',wykf13
  296.     mkeyw    'wyseF14',wykf14
  297.     mkeyw    'wyseF15',wykf15
  298.     mkeyw    'wyseF16',wykf16
  299.     mkeyw    'wyseSF1',wykSf1
  300.     mkeyw    'wyseSF2',wykSf2
  301.     mkeyw    'wyseSF3',wykSf3
  302.     mkeyw    'wyseSF4',wykSf4
  303.     mkeyw    'wyseSF5',wykSf5
  304.     mkeyw    'wyseSF6',wykSf6
  305.     mkeyw    'wyseSF7',wykSf7
  306.     mkeyw    'wyseSF8',wykSf8
  307.     mkeyw    'wyseSF9',wykSf9
  308.     mkeyw    'wyseSF10',wykSf10
  309.     mkeyw    'wyseSF11',wykSf11
  310.     mkeyw    'wyseSF12',wykSf12
  311.     mkeyw    'wyseSF13',wykSf13
  312.     mkeyw    'wyseSF14',wykSf14
  313.     mkeyw    'wyseSF15',wykSf15
  314.     mkeyw    'wyseSF16',wykSf16
  315.     mkeyw    'ignore',ignore_key
  316.                     ; Initialization data.
  317. kbdinlst equ    this byte     ; Kermit IBM initialization time keyboard setup
  318.     mkeyw    '\kgold',scan+59    ; F1    mkeyw 'definition',keycode
  319.     mkeyw    '\kpf2',scan+60        ; F2
  320.     mkeyw    '\kpf3',scan+61        ; F3
  321.     mkeyw    '\kpf4',scan+62        ; F4
  322.     mkeyw    '\kkp0',scan+shift+90    ; VT100 keypad numeric area, SF7
  323.     mkeyw    '\kkp1',scan+shift+86    ; SF3
  324.     mkeyw    '\kkp2',scan+shift+87    ; SF4
  325.     mkeyw    '\kkp3',scan+shift+88    ; SF5
  326.     mkeyw    '\kkp4',scan+67        ; F9
  327.     mkeyw    '\kkp5',scan+68        ; F10
  328.     mkeyw    '\kkp6',scan+shift+84    ; SF1
  329.     mkeyw    '\kkp7',scan+63        ; F5
  330.     mkeyw    '\kkp8',scan+64        ; F6
  331.     mkeyw    '\kkp9',scan+65        ; F7
  332.     mkeyw    '\kkpenter',scan+shift+89 ; SF6
  333.     mkeyw    '\kkpcoma',scan+shift+85  ; SF2
  334.     mkeyw    '\kkpminus',scan+66    ; F8
  335.     mkeyw    '\kkpdot',scan+shift+91    ; SF8
  336.     mkeyw    '\kuparr',scan+72    ; VT100 cursor keys (arrows)
  337.     mkeyw    '\kdnarr',scan+80
  338.     mkeyw    '\klfarr',scan+75
  339.     mkeyw    '\krtarr',scan+77
  340.     mkeyw    '\kupscn',scan+73    ; PgUp  Kermit screen roll back keys
  341.     mkeyw    '\kdnscn',scan+81    ; PgDn
  342.     mkeyw    '\khomscn',scan+71    ; Home
  343.     mkeyw    '\kendscn',scan+79    ; End
  344.     mkeyw    '\kupone',scan+control+132 ; Ctrl PgUp    one line scrolls
  345.     mkeyw    '\kdnone',scan+control+118 ; Ctrl PgDn
  346.     mkeyw    '\kuparr',scan+enhanced+72 ; Enhanced kbd duplicate keys
  347.     mkeyw    '\kdnarr',scan+enhanced+80
  348.     mkeyw    '\klfarr',scan+enhanced+75
  349.     mkeyw    '\krtarr',scan+enhanced+77
  350.     mkeyw    '\kupscn',scan+enhanced+73 ; PgUp Kermit screen roll back keys
  351.     mkeyw    '\kdnscn',scan+enhanced+81 ; PgDn
  352.     mkeyw    '\khomscn',scan+enhanced+71 ; Home
  353.     mkeyw    '\kendscn',scan+enhanced+79    ; End
  354.     mkeyw    '\kupone',scan+control+enhanced+132 ;Ctrl PgUp one line scroll
  355.     mkeyw    '\kdnone',scan+control+enhanced+118 ; Ctrl PgDn
  356.     mkeyw    '\kmodeline',scan+74    ; Kermit toggle mode line  Keypad -
  357.     mkeyw    '\ktermtype',scan+alt+130 ; Kermit toggle terminal type  Alt -
  358.     mkeyw    '\kreset',scan+alt+131    ; Kermit reset terminal  Alt =
  359.     mkeyw    '\kreset',scan+alt+19    ; ALT r for reset too
  360.     mkeyw    '\kdebug',scan+alt+32    ; ALT d for debug
  361.     mkeyw    '\kprtscn',scan+control+114 ; Kermit toggle prn scrn  Ctrl *
  362.     mkeyw    '\kdump',scan+control+117 ; Kermit Dump Screen  Ctrl End
  363.     mkeyw    '*',scan+55        ; keypad asterisk
  364.     mkeyw    '*',scan+enhanced+55    ; Enhanced kbd keypad asterisk
  365.     mkeyw    '+',scan+78        ; keypad plus
  366.     mkeyw    '.',scan+shift+83    ; IBM numeric keypad
  367.     mkeyw    '0',scan+shift+82
  368.     mkeyw    '1',scan+shift+79
  369.     mkeyw    '2',scan+shift+80
  370.     mkeyw    '3',scan+shift+81
  371.     mkeyw    '4',scan+shift+75
  372.     mkeyw    '5',scan+shift+76
  373.     mkeyw    '6',scan+shift+77
  374.     mkeyw    '7',scan+shift+71
  375.     mkeyw    '8',scan+shift+72
  376.     mkeyw    '9',scan+shift+73
  377.     mkeyw    ' ',scan+57        ; space bar yields space
  378.     mkeyw    ' ',scan+shift+57    ; Shift + space bar
  379.     mkeyw    '\0',scan+control+57    ; Control-space bar yields nul
  380.     mkeyw    '\0',scan+control+shift+57; Shift Control-space bar
  381.     mkeyw    tab,scan+15        ; regular Tab key, made special
  382.     mkeyw    cr,scan+28        ; typewriter Enter key
  383.     mkeyw    cr,scan+enhanced+cr    ; Enhanced kbd grey Enter key
  384.     mkeyw    lf,scan+control+28    ; Control-Enter
  385.     mkeyw    lf,scan+enhanced+control+lf ; Enhanced grey Control Enter
  386.     mkeyw    '/',scan+enhanced+'/'    ; Enhanced kbd grey foward slash
  387.     mkeyw    '\0',scan+control+3    ; Control at-sign sends null
  388.     mkeyw    '\0',scan+control+shift+3 ; Control Shift at-sign sends null
  389.     mkeyw    '\x7f',scan+83        ; Del key sends DEL
  390.     mkeyw    '\x7f',scan+enhanced+83 ; Enhanced duplicate DEL sends DEL
  391.     mkeyw    '\x7f',scan+14        ; Backspace key sends DEL
  392.     mkeyw    '\x1b',scan+01        ; Esc key sends ESC
  393.     mkeyw    '\kexit',scan+alt+45    ; Exit connect mode  Alt X
  394.     mkeyw    '\kstatus',scan+alt+31    ; Connect mode status  Alt S
  395.     mkeyw    '\kbreak',scan+alt+48    ; Send a Break  Alt B
  396.     mkeyw    '\kbreak',scan+control+0; Control-Break sends a Break too
  397.     mkeyw    '\khelp',scan+alt+35    ; Connect mode drop down menu  Alt H
  398.     mkeyw    '\kcompose',scan+alt+46    ; ALT C is compose
  399. ifndef    no_tcp
  400.     mkeyw    '\knextsession',scan+alt+49    ; nextses is Alt N
  401.     mkeyw    '\knethold',scan+alt+44    ; ALT Z is nethold
  402. endif    ; no_tcp
  403.     dw    0        ; end of table marker
  404.  
  405.                     ;** LK250 support begin
  406. kb250lst equ    this byte             ; Extensions for DEC LK250 keyboard
  407.     mkeyw    escape,scan+104        ; Compose maps to ESC
  408.         mkeyw   '\x7f',scan+14          ; Backspace key sends DEL
  409.         mkeyw   bs,scan+shift+14        ; Shift-Backspace key sends BS
  410.     mkeyw    cr,scan+28        ; Return key sends CR
  411.     mkeyw    lf,scan+shift+28    ; Shift-Return sends LF
  412.     mkeyw    tab,scan+15        ; Tab sends TAB
  413.                     ; the top-row function keys
  414.     mkeyw    '\kholdscrn',scan+59    ; DEC Hold
  415.     mkeyw    '\kprtscn',scan+60    ; DEC Print Screen
  416. ;;;;    mkeyw    '{\{kstatus}\{kexit}}',scan+61    ; DEC Set-Up
  417.     mkeyw    '\kbreak',scan+63    ; DEC Break
  418.     mkeyw    '\kdecF6',scan+64    ; DEC F6
  419.     mkeyw    '\kdecF7',scan+65    ; DEC F7
  420.     mkeyw    '\kdecF8',scan+66    ; DEC F8
  421.     mkeyw    '\kdecF9',scan+67    ; DEC F9
  422.     mkeyw    '\kdecF10',scan+68    ; DEC F10
  423.     mkeyw    '\kdecF11',scan+95    ; DEC F11
  424.     mkeyw    '\kdecF12',scan+96    ; DEC F12
  425.     mkeyw    '\kdecF13',scan+97    ; DEC F13
  426.     mkeyw    '\kdecF14',scan+98    ; DEC F14
  427.     mkeyw    '\kdecHelp',scan+99    ; DEC Help
  428.     mkeyw    '\kdecDo',scan+100    ; DEC DO
  429.     mkeyw    '\kdecF17',scan+101    ; DEC F17
  430.     mkeyw    '\kdecF18',scan+102    ; DEC F18
  431.     mkeyw    '\kdecF19',scan+103    ; DEC F19
  432.     mkeyw    '\kdecF20',scan+84    ; DEC F20
  433.                     ; the cursor/select cluster
  434.     mkeyw    '\kdecFind',scan+85    ; DEC Find
  435.     mkeyw    '\kdecInsert',scan+86    ; DEC Insert Here
  436.     mkeyw    '\kdecRemove',scan+87    ; DEC Remove
  437.     mkeyw    '\kdecSelect',scan+88    ; DEC Select
  438.     mkeyw    '\kdecPrev',scan+89    ; DEC Prev
  439.     mkeyw    '\kdecNext',scan+90    ; DEC Next
  440.     mkeyw    '\kuparr',scan+91    ; up arrow
  441.     mkeyw    '\klfarr',scan+92    ; left arrow
  442.     mkeyw    '\krtarr',scan+93    ; right arrow
  443.     mkeyw    '\kdnarr',scan+94    ; down arrow
  444.                     ; the DEC editing keypad
  445.     mkeyw    '\kgold',scan+106    ; F1
  446.     mkeyw    '\kpf2',scan+107    ; F2
  447.     mkeyw    '\kpf3',scan+108    ; F3
  448.     mkeyw    '\kpf4',scan+109    ; F4
  449.     mkeyw    '\kkp7',scan+shift+71    ; KP7
  450.     mkeyw    '\kkp8',scan+shift+72    ; KP8
  451.     mkeyw    '\kkp9',scan+shift+73    ; KP9
  452.     mkeyw    '\kkpminus',scan+74    ; KP-
  453.     mkeyw    '\kkp4',scan+shift+75    ; KP4
  454.     mkeyw    '\kkp5',scan+shift+76    ; KP5
  455.     mkeyw    '\kkp6',scan+shift+77    ; KP6
  456.     mkeyw    '\kkpcoma',scan+78    ; KP,
  457.     mkeyw    '\kkp1',scan+shift+79    ; KP1
  458.     mkeyw    '\kkp2',scan+shift+80    ; KP2
  459.     mkeyw    '\kkp3',scan+shift+81    ; KP3
  460.     mkeyw    '\kkpenter',scan+105    ; keypad enter
  461.     mkeyw    '\kkpenter',scan+shift+105 ; keypad enter
  462.     mkeyw    '\kkp0',scan+shift+82    ; KP0
  463.     mkeyw    '\kkpdot',scan+shift+83    ; KP.
  464.                     ; some useful Kermit keys
  465.         mkeyw   '\kupscn',scan+alt+89   ; PgUp  Kermit screen roll back keys
  466.         mkeyw   '\kdnscn',scan+alt+90   ; PgDn
  467.         mkeyw   '\khomscn',scan+alt+85  ; Home
  468.         mkeyw   '\kendscn',scan+alt+88  ; End
  469.         mkeyw   '\kupone',scan+control+89 ; Ctrl PgUp  one line scrolls
  470.         mkeyw   '\kdnone',scan+control+90 ; Ctrl PgDn
  471.         mkeyw   '\kexit',scan+alt+45    ; Exit connect mode  Alt X
  472.         mkeyw   '\kstatus',scan+alt+31  ; Connect mode status  Alt S
  473.         mkeyw   '\kbreak',scan+alt+48   ; Send a Break  Alt B
  474.         mkeyw   '\kbreak',scan+control+108 ; Control-Break sends a Break too
  475.         mkeyw   '\khelp',scan+alt+35    ; Connect mode drop down menu  Alt H
  476.         mkeyw   '\ktermtype',scan+alt+130 ; Kermit toggle terminal type  Alt -
  477.         mkeyw   '\kreset',scan+alt+131  ; Kermit reset terminal  Alt =
  478.         mkeyw   '\kprtscn',scan+control+109 ; Kermit toggle prn scrn  Ctrl *
  479.         mkeyw   '\kdump',scan+control+88 ; Kermit Dump Screen  Ctrl End
  480.     dw    0            ; end of table marker
  481.  
  482. got250    db    0            ;** LK250 present if non-zero
  483. kbd250    db    0            ; enable use of LK250 if non-zero
  484. lk250msg db    cr,lf,'?LK250 keyboard external driver is not active.$'
  485.                     ;** LK250 support end
  486. kbcodes    dw    80h            ; keyboard read codes, 80h=not inited
  487. data    ends
  488.  
  489. data1    segment
  490. dfhelp1    db    cr,lf,' Enter key',27h,'s identification as a character',cr,lf
  491.     db    '  or as its numerical equivalent \{b##} of ascii',cr,lf
  492.     db    '  or as its scan code \{b##}'
  493.     db    cr,lf,'  or as SCAN followed by its scan code',cr,lf
  494.     db    '    where b is O for octal, X for hex, or D for decimal'
  495.     db    ' (default).',cr,lf,'    Braces {} are optional.'
  496.     db    cr,lf,'    Follow the identification with the new definition.'
  497.     db    cr,lf,' or CLEAR to restore initial key settings'
  498.     db    cr,lf,' or ON (default) for Bios i/o or OFF to use DOS i/o'
  499.     db    cr,lf,' or LK to use the DEC LK250 keyboard.$' ;IBM
  500. ;;;    System Dependent Data Area
  501. ;    edit dfhelp2 to include nice list of verbs for this system.
  502. dfhelp2 db    cr,lf,' Enter either  \Kverb  for a Kermit action verb',cr,lf
  503.     db    ' or a replacement string  (single byte binary numbers are'
  504.     db    ' \{b##})',cr,lf,' or push Return to undefine a key, ^C to'
  505.     db    ' retain current definition.'
  506.     db    cr,lf,' Braces {} are optional, and strings maybe enclosed in'
  507.     db    ' them.',cr,lf,' Strings may not begin with the character'
  508.     db    ' combinations of  \k  or  \{k',cr,lf
  509.     db    '    (start with a { brace instead).',cr,lf,lf
  510.     db    ' Verbs are as follows. Keys (arrows and keypad):',cr,lf
  511.     db   '   uparr, dnarr, lfarr, rtarr, kpminus, kpcoma, kpdot, kpenter,'
  512.     db    cr,lf
  513.     db   '   Gold (same as PF1), PF1, PF2, PF3, PF4, kp0, ... kp9'
  514.     db    cr,lf,'   decFind, decInsert, decRemove, decSelect, decPrev,'
  515.     db    ' decNext'
  516.     db    cr,lf,'   decF6, ...decF14, decHelp, decDO, decF17, ...decF20'
  517.     db    cr,lf,'   Compose (same as dgSPCL)'
  518.     db    cr,lf,'   User Definable Keys udkF6, ...udkF20'
  519.     db    cr,lf,'   Data General dgC1..dgC4, dgF1..dgF15, dgSF1..dgSf15,'
  520.     db    cr,lf,'   dgPoint, dgSPCL, dgNC'
  521.     db    cr,lf,'   Wyse-50 function keys wyseF1..wyseF16, wyseSF1..'
  522.     db    'wyseSF16'
  523.     db    cr,lf,' Kermit screen control and actions:',cr,lf
  524.     db   '   upscn, dnscn, homscn, endscn, upone, dnone (vertical '
  525.     db    'scrolling),'
  526.     db    cr,lf
  527.     db   '   lfpage, lfone, rtpage, rtone (horizontal scrolling)'
  528.     db    cr,lf
  529.     db   '   logoff, logon, termtype, reset, holdscrn, modeline, break,'
  530.     db   ' debug,'
  531.     db    cr,lf
  532.     db   '   lbreak, nethold, nextsession, prtscn, dump, hangup, null'
  533.     db   ' (send one),'
  534.     db    cr,lf
  535. ifndef    no_tcp
  536.     db   '   session1, ..session6 (selects Telnet session number 1..6)'
  537.     db    cr,lf
  538. endif    ; no_tcp
  539.     db   '   tn_AYT, tn_IP, DOS, help, ignore, status, exit'
  540.     db    cr,lf,'$'
  541.  
  542. data1    ends
  543. ;            Documentation
  544. ;Translating a key:
  545. ;   The translator is called to obtain keyboard input; it sends characters to
  546. ; the serial port through standard controlled echo procedures or invokes
  547. ; named procedures. It returns carry clear when its operation is completed
  548. ; for normal actions and carry set when Connect mode must be exited. When
  549. ; Connect mode is exited the just read char should be passed in Kbdflg 
  550. ; to msster.asm for invoking actions such as Status, send a break,
  551. ; quit connect mode; system dependent procedure Term is responsible for this. 
  552. ;
  553. ;  Principal procedures are -
  554. ;    msuinit        Initializes keyboard translator in this file when
  555. ;            Kermit first begins. Installs dfkey and shkey as the
  556. ;            procedures used for Set Key and Show Key. Sys Indep.
  557. ;            Called from msx or msy init procs. System Independent.
  558. ;    keybd        Performs the translation, outputs chars to the serial
  559. ;            port or invokes a Kermit action routine. Sys Indep.
  560. ;    dfkey        Defines a key's translation. Reads command line
  561. ;            via Kermit's command parser comnd. System Independent.
  562. ;    shkey        Shows translation of a key. Requests user to push
  563. ;            selected key. System Independent.
  564. ;
  565. ;    kbdinit        optional. Initializes the translation tables when
  566. ;            Kermit starts up. Called by msuinit. System Dependent.
  567. ;    getkey        Performs the keyboard read and returns results in
  568. ;            a standardized system independent format. Sys Depend.
  569. ;    postkey        called by active translator after obtaining a keycode.
  570. ;            Used to provide extra local actions (keyclick) only
  571. ;            in Connect mode (not during Set/Show key commands).
  572. ;            Called by keybd. System dependent.
  573. ; Supporting system independent procedures are -
  574. ; shkfre (show string free space), tstkeyw (finds user's keyword in the verb
  575. ; table), insertst (insert string in buffer), remstr (delete string in buffer).
  576. ;
  577. ;   System dependent procedure Getkey reads a keycode (usually via a Bios
  578. ; call). On IBM compatible machines this yields <ah=scan code, al=ascii>
  579. ; for ordinary keys, or <ah=scan code, al=0> for special keys such as F1,
  580. ; or <ah=0, al=###> when Alt### is used.
  581. ; For any system, the canonical output form is the key's code in Keycode.
  582. ; Place the ascii code (or scan code if none) in byte Keycode and ancillary
  583. ; info (shift states plus marker bit for scan codes) in byte Keycode + 1.
  584. ;   Table Aliaskey is a list of scan code/ascii codes for keys which appear
  585. ; more than once on a keyboard. This list is examined to distinguish such
  586. ; aliased keys (those on an auxillary keypad) from an ordinary ascii key,
  587. ; and the aliased key is then referenced by its scan code rather than by
  588. ; the ordinary ascii code. Aliaskey is machine and keyboard dependent.
  589. ;
  590. ;    Procedure Keybd calls Getkey for the Keycode, checks list of translatable
  591. ; keys Keylist, and then either sends an ascii string (one or more characters)
  592. ; or invokes a Kermit action verb. List Dirlist indicates what kind of 
  593. ; translation to do. Keybd is system independent but may contain system
  594. ; dependent special actions such as echoing keyclicks. Keybd calls system
  595. ; dependent procedure Postkey just after calling getkey so local actions
  596. ; such as keyclicks can be activated only during Connect mode operations.
  597. ;
  598. ;    Keylist is a packed but unordered list of 16 bit keycodes which need
  599. ; translation. The lower order byte holds a key code (ascii char or scan code)
  600. ; while the high byte holds a scan code marker bit (0 if ascii code in low
  601. ; byte) plus any ancillary keyboard information such as Control/Shift/Alt/Meta
  602. ; keys being held down; these are of use in Show Key presentations.
  603. ;    Dirlist parallels Keylist to provide the kind of translation, verb or
  604. ; string, in the two highest bits with the other bits holding either
  605. ; a single new replacement character or the item number in lists of verbs
  606. ; or strings. If neither verb nor strng type bits are set in a dirlist
  607. ; word then the translation is a single new character held in the lower
  608. ; eight bits of that dirlist word.
  609. ;
  610. ;    The number of key translations is assembly constant Maxkeys (def 128).
  611. ;    The maximum number of strings is assembly constant Maxstngs (def 64).
  612. ;    The maximum number of verbs is 256 and is set by building table Kverbs.
  613. ;
  614. ;   For verbs, use the Item number from the Director table Dirlist to select
  615. ; a procedure offset from the structured list Kverbs and jump to that offset.
  616. ; Most verb procedures return carry clear to stay within Connect mode.
  617. ; Verbs requiring exiting Connect mode return carry set and may set byte
  618. ; Kbdflg to a char code which will be read by msster.asm for activating a
  619. ; transient Kermit action such as send a break (Kbdflg = 'b').
  620. ; Kbdflg is stored in msster.asm (as zero initially, meaning ignore it).
  621. ; Action verb procedures are normally located in a system dependent file.
  622. ;
  623. ;   For multi-char strings, use Item number from Director table Dirlist to
  624. ; select a pointer to a string. The list of string pointers is Sptable
  625. ; (string pointer table) which holds the offset in the data segment of the
  626. ; strings stored in buffer Stbuf. In stbuf strings are held as: one byte of
  627. ; length of following text and then the text itself (permits embedded nulls).
  628. ;  Use Chrout to send each string character, and finally return from Keybd
  629. ; with carry clear.
  630. ;
  631. ;   For single character replacements obtain the new character from the lower
  632. ; order byte of Director table Dirlist. If the character is Kermit's present
  633. ; escape character return from Keybd carry set to leave connect mode.
  634. ; Otherwise, send the character via Chrout and return from Keybd carry clear.
  635.  
  636. ; Keylist table format:
  637. ;    7 bits   1 bit   8 bits
  638. ; +----------+----+------------+ scan bit = 1 if key's code is non-ascii
  639. ; | aux info |scan| key's code | aux info = system dependent, used only to
  640. ; +----------+----+------------+            help identify key
  641. ;
  642. ; Dirlist table format          v s    meaning
  643. ;   1   1      14 bits         0 0    copy out one byte translation
  644. ; +---+---+--------------------+  1 0    copy out multi-char string number Item
  645. ; | v | s | item # or new char |  0 1    do action verb number Item
  646. ; +---+---+--------------------+  1 1    (not used)
  647. ;
  648. ; Table kverbs is organized by macro mkeyw as -
  649. ;    kverbs    db    number of table entries
  650. ;    (each entry is in the form below:)
  651. ;        dw    number of bytes in verbname
  652. ;        db    'verbname'        variable length
  653. ;        dw    value            offset of procedure
  654. ;
  655. ;
  656. ;   Dfkey defines a key to be itself (undefines it) or a single replacement
  657. ; character or a character string or a Kermit action verb. Dfkey requires
  658. ; a command line so that it may be invoked by Take files but can be forced
  659. ; to prompt an interactive user to push a key. Syntax is discussed below.
  660. ; Note that redefined keys have their old definitions cleared so that
  661. ; old string space is reclaimed automatically.
  662. ;
  663. ;   Shkey displays a key's definition and the user is asked to push the
  664. ; selected key. The free space for strings is always shown afterward. See
  665. ; below for syntax.
  666. ;
  667. ;   Kbdinit is an optional routine called when Kermit starts up. It fills in
  668. ; the translation tables with desirable default values to save having to
  669. ; use long mskermit.ini files. The default values are stored in a structured
  670. ; table similar to (but not the same as) Dfkey's command lines; the keycode
  671. ; values are preset by hand to 16 bit numbers.
  672.  
  673. ;Defining a key:
  674. ; Command is SET KEY <key ident><whitespace><definition>
  675. ;
  676. ; <key ident> is
  677. ;        a single ordinary ascii char or
  678. ;        the numerical equivalent of an ascii char or
  679. ;        a Scan Code written as a number or
  680. ;        keyword SCAN followed by a number.
  681. ;        ?    Displays help message.
  682. ;    Numbers and Binary codes are of the form
  683. ;        \123    a decimal number
  684. ;        \o456    an octal number        base letters o, d, x can be
  685. ;        \d213    a decimal number    upper or lower case
  686. ;        \x0d    a hex number
  687. ;        \{b###}  braces around above material following slash.
  688. ;
  689. ; <whitespace> is one or more spaces and or tabs.
  690. ;
  691. ; <definition> is
  692. ;    missing altogether which "undefines" a key.
  693. ;    \Kverb        for a Kermit action verb; upper or lower case K is ok
  694. ;    \{Kverb}    ditto. Verb is the name of an action verb.
  695. ;    text        a string with allowed embedded whitespace and embedded
  696. ;            binary chars as above. This kind of string may not
  697. ;            commence with sequences \K or \{K; use braces below.
  698. ;    {text}        string confined to material within but excluding
  699. ;            the braces. Note, where the number of opening braces
  700. ;            exceeds the number of closing braces the end of line
  701. ;            terminates the string: {ab{}{{c}d ==> ab{}{{c}d
  702. ;            but  {ab}{{c}d ==> ab.
  703. ;    ?        Displays help message and lists all action verbs.
  704. ;
  705. ;    If Set Key is given interactively, as opposed to within a Take
  706. ;    file, the system will prompt for inputs if none is on the command
  707. ;    line. The response to Push key to be defined cannot be edited.
  708. ;
  709. ;    Text which reduces to a single replacement character is put into a
  710. ;    table separate from the multi-character strings (maxstng of these).
  711. ;    A key may be translated into any single 8 bit code.
  712. ;    
  713. ;    Comments can follow a Kermit action verb or a braced string; no
  714. ;    semicolon is required since all are stripped out by the Take file
  715. ;    reader before the defining text is seen by SET KEY.
  716. ;
  717. ;    The current Kermit escape character cannot be translated without
  718. ;    subtrafuge.
  719. ;
  720. ;    Examples:
  721. ;        Set Key q z
  722. ;                makes key q send character z
  723. ;        Set Key \7 \27[0m
  724. ;                makes key Control G send the four byte
  725. ;                string  ESC [ 0 m
  726. ;        Set Key q
  727. ;                undefines key q so it sends itself (q) again.
  728. ;        Set Key \2349 \kexit
  729. ;                defines IBM Alt-X to invoke the leave connect
  730. ;                mode verb "exit" (Kermit's escape-char ^] C).
  731. ;        Set Key \x0c Login \{x0d}myname\{x0d}mypass\x0d
  732. ;                defines Control L to send the string
  733. ;                Login <cr>myname<cr>mypass<cr>
  734. ;
  735. ; Alternative Set Key syntax for backward compatibility with previous versions
  736. ;    The same forms as above except the key identification number must
  737. ;    be decimal and must Not have a leading backslash. Example:
  738. ;    Set Key Scan 59 This is the F1 key
  739. ;
  740. ;    If the definition is omitted it may be placed on the following line;
  741. ;    if that line is also empty the key is undefined (defined as Self).
  742. ;    A warning message about obsolete syntax will be given followed by
  743. ;    the key's modern numerical value and new definition. Only "special"
  744. ;    keys (those not producing ascii codes) are compatible with this
  745. ;    translator.
  746. ;
  747. ;Showing a key:
  748. ; Command is SHOW KEY <cr>
  749. ; System prompts user to press a key and shows the definition plus the
  750. ; free space for strings. Query response results in showing all definitions.
  751. ;            End Documentation
  752.  
  753. code1    segment
  754.     extrn    vclick:near, udkclear:near        ; in msyibm
  755.     extrn    xltkey:far                ; in mszibm
  756.     extrn    iseof:far, strlen:far, prtscr:far    ; in mssfil
  757.     extrn    domath:far, decout:far            ; in msster
  758.     assume    cs:code1
  759.  
  760. fudkclear proc    far
  761.     call    udkclear
  762.     ret
  763. fudkclear endp
  764.  
  765. fvclick    proc    far
  766.     call    vclick
  767.     ret
  768. fvclick    endp
  769.  
  770. code1    ends
  771.  
  772. code    segment
  773.         ; system independent external items
  774.     extrn    comnd:near, prompt:near, cnvlin:near    ; in msscmd
  775.         ; system dependent external items
  776.     extrn    beep:near, khold:near
  777.         ; these are system dependent action verbs, in msxibm & msyibm 
  778.     extrn    uparrw:near, dnarrw:near, rtarr:near, lfarr:near
  779.     extrn    pf1:near, pf2:near, pf3:near, pf4:near,    kp0:near, kp1:near
  780.     extrn    kp2:near, kp3:near, kp4:near, kp5:near, kp6:near, kp7:near
  781.     extrn    kp8:near, kp9:near, kpminus:near, kpcoma:near, kpenter:near
  782.     extrn    kpdot:near, decf6:near, decf7:near, decf8:near, decf9:near
  783.     extrn    decf10:near, decf11:near, decf12:near, decf13:near
  784.     extrn    decf14:near, dechelp:near, decdo:near, decf17:near
  785.     extrn    decf18:near, decf19:near, decf20:near
  786.     extrn    decfind:near, decinsert:near, decremove:near
  787.     extrn    decselect:near, decprev:near, decnext:near, ignore_key:near
  788.     extrn    udkf6:near, udkf7:near, udkf8:near, udkf9:near, udkf10:near
  789.     extrn    udkf11:near,udkf12:near,udkf13:near,udkf14:near,udkf15:near
  790.     extrn    udkf16:near,udkf17:near,udkf18:near,udkf19:near,udkf20:near
  791.     extrn    chrout:near, cstatus:near, cquit:near, cquery:near
  792.     extrn    vtans52:near, vtinit:near, dnwpg:near, upwpg:near
  793.     extrn    endwnd:near, homwnd:near, upone:near, dnone:near, trnprs:near
  794.     extrn    trnmod:near, sendbr:near, sendbl:near, dmpscn:near, snull:near
  795.     extrn    chang:near, klogon:near, klogof:near, cdos:near
  796.     extrn    lfpage:near, rtpage:near, lfone:near, rtone:near, kdebug:near
  797.     extrn    extmacro:near
  798.     extrn    dgkc1:near,dgkc2:near,dgkc3:near,dgkc4:near,dgkf1:near
  799.     extrn    dgkf2:near,dgkf3:near,dgkf4:near,dgkf5:near,dgkf6:near
  800.     extrn    dgkf7:near,dgkf8:near,dgkf9:near,dgkf10:near,dgkf11:near
  801.     extrn    dgkf12:near,dgkf13:near,dgkf14:near,dgkf15:near
  802.     extrn    dgkSf1:near,dgkSf2:near,dgkSf3:near,dgkSf4:near,dgkSf5:near
  803.     extrn    dgkSf6:near,dgkSf7:near,dgkSf8:near,dgkSf9:near,dgkSf10:near
  804.     extrn    dgkSf11:near,dgkSf12:near,dgkSf13:near,dgkSf14:near
  805.     extrn    dgkSf15:near,dgpoint:near, dgnckey:near, kbdcompose:near
  806.     extrn    wykf1:near,wykf2:near,wykf3:near,wykf4:near,wykf5:near
  807.     extrn    wykf6:near,wykf7:near,wykf8:near,wykf9:near,wykf10:near
  808.     extrn    wykf11:near,wykf12:near,wykf13:near,wykf14:near,wykf15:near
  809.     extrn    wykf16:near
  810.     extrn    wykSf1:near,wykSf2:near,wykSf3:near,wykSf4:near,wykSf5:near
  811.     extrn    wykSf6:near,wykSf7:near,wykSf8:near,wykSf9:near,wykSf10:near
  812.     extrn    wykSf11:near,wykSf12:near,wykSf13:near,wykSf14:near
  813.     extrn    wykSf15:near, wykSf16:near
  814.     extrn    jpnxltkey:near
  815. ifndef    no_network
  816.     extrn    ubhold:near
  817. ifndef    no_tcp
  818.     extrn    nextses:near, tn_AYT:near, tn_IP:near
  819.     extrn    ses1:near,ses2:near,ses3:near,ses4:near,ses5:near,ses6:near
  820. endif    ; no_tcp
  821. endif    ; no_network
  822.  
  823.     assume    cs:code, ds:data, es:data
  824.  
  825. ; Begin system independent Keyboard Translator code
  826.  
  827. ; MSUINIT performs Kermit startup initialization for this file.
  828. ; Note, shkadr and stkadr are pointers tested by Set/Show Key calls. If they
  829. ; are not initialized here then the older Set/Show Key procedures are called.
  830. MSUINIT    PROC    NEAR            ; call from msx/msy init code
  831.     call    kbdinit            ; optional: init translator tables
  832.     mov    shkadr,offset shkey    ; declare keyboard translator present
  833.     mov    stkadr,offset dfkey    ; via Show and Set Key proc addresses
  834.     ret
  835. MSUINIT    ENDP
  836.  
  837. ; Call Keybd to read a keyboard char (just returns carry clear if none) and
  838. ; 1) send the replacement string (or original char if not translated)
  839. ;    out the serial port, or
  840. ; 2) execute a Kermit action verb.
  841. ; Returns carry set if Connect mode is to be exited, else carry clear.
  842. ; Modifies registers ax and bx. 
  843. KEYBD    PROC    NEAR            ; active translator
  844.     mov    ttyact,1        ; doing single char output
  845.     cmp    stringcnt,0        ; any leftover string chars?
  846.     je    keybd0            ; e = no
  847.     jmp    keyst2            ; yes, finish string
  848. keybd0:    call    getkey            ; read keyboard
  849.     jnc    keybd1            ; nc = data available
  850.     jmp    keybdx            ; else just return carry clear
  851. keybd1:    call    postkey            ; call system dependent post processor
  852.     cmp    nkeys,0            ; is number of keys defined = 0?
  853.     jz    keybd3            ; z = none defined
  854.     push    di            ; search keylist for this keycode
  855.     push    cx            ; save some registers    
  856.     push    es
  857.     mov    di,offset keylist    ; list of defined keycode words
  858.     mov    ax,keycode        ; present keycode
  859.     mov    cx,nkeys        ; number of words to examine
  860.     push    ds
  861.     pop    es            ; make es:di point to data segment
  862.     cld
  863.     repne    scasw            ; find keycode in list
  864.     pop    es            ; restore regs
  865.     pop    cx
  866.     je    keybd1b            ; e = found, work with present di
  867.     pop    di            ; restore original di
  868.     test    keycode,scan        ; is this a scan code?
  869.     jz    keybd3            ; z = no, it's ascii, use al as char
  870.     call    beep            ; say key is a dead one
  871.     clc
  872.     ret                ; and exit with no action
  873.  
  874. keybd1b:sub    di,2            ; correct for auto increment
  875.     sub    di,offset keylist    ; subtract start of list ==> listptr
  876.     mov    ax,dirlist[di]        ; ax = contents of director word
  877.     pop    di            ; restore original di
  878.                     ; dispatch on Director code
  879.     test    ax,verb            ; verb only?
  880.     jnz    keyvb            ; e = yes
  881.     test    ax,strng        ; multi-char string only?
  882.     jnz    keyst            ; e = yes, else single char & no xlat.
  883.                     ;
  884.                     ; do single CHAR output (char in al)
  885. keybd3:    cmp    termesc_flag,0        ; is escaping allowed?
  886.     jne    keybd3c            ; ne = no, skip recognition
  887.     cmp    al,trans.escchr        ; Kermit's escape char?
  888.     je    keybd3a            ; e = yes, handle separately
  889. keybd3c:cmp    isps55,0        ; [HF]940206 Japanese PS/55?
  890.     je    keybd3b            ; [HF]940206 e = no
  891.     call    jpnxltkey        ; [HF]940206 check Jpn.dble byte char
  892.     jnc    keybd3b            ; [HF]940206 nc = no Jpn
  893.     clc                ; [HF]940206 return sccess
  894.     ret                ; [HF]940206
  895. keybd3b:call    xltkey            ; do character set translation
  896.     call    chrout            ; transmit the char
  897.     clc                ; return success
  898.     ret
  899. keybd3a:stc                ; set carry for jump to Quit
  900.     ret
  901.  
  902. keyvb:    and    ax,not(verb+strng)    ; VERB (ax=index, remove type bits)
  903.     mov    bx,offset kverbs    ; start of verb table
  904.     cmp    al,byte ptr [bx]    ; index > number of entries?
  905.     jae    keybdx            ; ae = illegal, indices start at 0
  906.     inc    bx            ; bx points to first entry
  907.     push    cx            ; save reg
  908.     mov    cx,ax            ; save the index in cx
  909.     inc     cx            ; counter, indices start at 0
  910. keyvb1:    mov    ax,[bx]            ; cnt value
  911.     add    ax,4            ; skip text and value word
  912.     add    bx,ax            ; look at next slot
  913.     loop    keyvb1            ; walk to correct slot
  914.     sub    bx,2            ; backup to value field
  915.     pop    cx            ; restore reg
  916.     mov    bx,[bx]            ; get value field of this slot
  917.     or    bx,bx            ; jump address defined?
  918.     jz    keybdx            ; z = no, skip the action
  919.     jmp    bx            ; perform the function
  920.  
  921. keyst:    and    ax,not(verb+strng)    ; STRING (ax=index, remove type bits)
  922.     shl    ax,1            ; convert to word index
  923.     push    si            ; save working reg
  924.     mov    si,ax            ; word subscript in table
  925.     mov    si,sptable[si]        ; memory offset of selected string
  926.     xor    cx,cx            ; init string length to null
  927.     or    si,si            ; is there a string pointer present?
  928.     jz    keyst1            ; z = no, skip operation
  929.     cld                ; scan forward
  930.     mov    cx,[si]            ; get string length
  931.     add    si,2
  932. keyst1:    mov    stringcnt,cx
  933.     mov    stringptr,si
  934.     pop    si
  935.     jcxz    keybdx            ; z = null length
  936.  
  937. keyst2:    push    si
  938.     mov    si,stringptr        ; pointer to next string char
  939.     cld
  940.     lodsb                ; get new string char into al
  941.     pop    si
  942.     dec    stringcnt        ; string chars remaining
  943.     inc    stringptr
  944.     call    keysv            ; scan for embedded verbs
  945.     jc    keyst4            ; c = not found, al has string char
  946.     jmp    bx            ; perform the verb (bx = address)
  947. keyst4:    call    xltkey            ; do character set translation
  948.     cmp    stringcnt,0        ; last character?
  949.     je    keyst5            ; e = yes, stop grouping for nets
  950.     mov    ttyact,0        ; group output for networks
  951. keyst5:    jmp    chrout            ; send out the char in al
  952.  
  953. keybdx:    clc                ; return success (nothing to do)
  954.     ret
  955. KEYBD    ENDP
  956.  
  957. ; Scan for keyboard verbs embedded in outgoing string. If found update
  958. ; string pointer and count to just beyond the verb and return action routine
  959. ; address in bx with carry clear. If failure return carry set and no change.
  960. ; Can invoke external procedure EXTMACRO if the verb is not known here.
  961.  
  962. keysv    proc    near
  963.     push    ax
  964.     push    si
  965.     push    di
  966.     cmp    al,'\'            ; escape?
  967.     jne    keysv7            ; ne = no
  968.     mov    cx,stringcnt        ; chars remaining
  969.     mov    si,stringptr        ; address of next char to read
  970.     mov    brace,0            ; assume not using braces
  971.     cmp    byte ptr [si],braceop    ; starts with \{?
  972.     jne    keysv1            ; ne = no
  973.     inc    si            ; skip the opening brace
  974.     dec    cx
  975.     mov    brace,bracecl        ; expect closing brace
  976. keysv1:    cmp    byte ptr [si],'K'    ; starts with \{K or \K?
  977.     je    keysv2            ; e = yes
  978.     cmp    byte ptr [si],'k'    ; starts as \{k or \k?
  979.     jne    keysv7            ; ne = no, then it's a string
  980. keysv2:    inc    si            ; yes, skip the K too
  981.     dec    cx
  982.     mov    di,offset tranbuf    ; copy verb name to this work buffer
  983.     xor    ax,ax
  984.     mov    [di],ax            ; init the buffer to empty
  985. keysv3:    cld
  986.     jcxz    keysv4            ; z = no more string chars
  987.     lodsb                ; scan til closing brace or w/s or end
  988.     dec    cx
  989.     cmp    al,brace        ; closing brace?
  990.     je    keysv4            ; e = yes
  991.     cmp    al,'\'            ; another item starting?
  992.     jne    keysv3a            ; ne = no
  993.     cmp    brace,0            ; need to end on a brace?
  994.     jne    keysv4            ; ne = yes, backing up done below
  995.     dec    si            ; back up to break position
  996.     inc    cx
  997.     jmp    short keysv4        ; process current substring
  998.  
  999. keysv3a:cmp    al,spc            ; white space or control char?
  1000.     jbe    keysv3            ; be = yes
  1001.     mov    [di],ax            ; copy to tranbuf and terminate
  1002.     inc    di
  1003.     jmp    short keysv3
  1004. keysv4:    push    si            ; save input reading position
  1005.     mov    si,offset tranbuf    ; where verb starts (needs si)
  1006.     call    tstkeyw            ; find keyword, bx = action routine
  1007.     pop    si
  1008.     jnc    keysv4a            ; nc = found the verb
  1009.     call    keysv8            ; invoke EXTMACRO worker for unknown
  1010.     jc    keysv7            ; carry = no verb to operate upon
  1011. keysv4a:cmp    brace,0            ; need to end on a brace?
  1012.     je    keysv6            ; e = no
  1013.     dec    si            ; break position
  1014.     inc    cx
  1015.     cld
  1016. keysv5:    jcxz    keysv6            ; z = no more string characters
  1017.     lodsb                ; read string char
  1018.     dec    cx
  1019.     cmp    al,brace        ; the brace?
  1020.     jne    keysv5            ; ne = no, repeat until it is found
  1021. keysv6:    mov    stringptr,si        ; where we finished+1
  1022.     mov    stringcnt,cx        ; new count of remaining chars
  1023.     pop    di
  1024.     pop    si            ; original si, starting place
  1025.     pop    ax            ; original ax
  1026.     clc
  1027.     ret
  1028. keysv7:    pop    di            ; verb not found
  1029.     pop    si
  1030.     pop    ax
  1031.     stc
  1032.     ret
  1033. ; Worker. Unknown verb name as string {\kverb} or {\k{verb}}. Use EXTMACRO
  1034. ; procedure (in msyibm typically), point to verb name with vtmacname, length
  1035. ; of it in byte vtmaclen, address of EXTMACRO to BX. Upper case the verb.
  1036. ; Enter with tranbuf holding the verb, asciiz, without \K and braces.
  1037. ; Returns BX set to EXTMACRO proc, vtmacname pointing to verb (uppercased)
  1038. ; and vtmaclen holding the length of verb.
  1039. keysv8:    mov    bx,offset extmacro    ; use this external macro pointer
  1040.     mov    vtmacname,offset tranbuf; select extmacro procedure address
  1041.     mov    dx,offset tranbuf    ; point to name for extmacro
  1042.     push    cx
  1043.     call    strlen            ; get its length
  1044.     mov    vtmaclen,cx        ; length for extmacro
  1045.     jcxz    keysv11            ; z = none
  1046.     push    si            ; convert verb name to upper case
  1047.     mov    si,dx            ; verb, without leading \K stuff
  1048.     cld
  1049. keysv9:    lodsb                ; read a name byte
  1050.     cmp    al,'a'            ; before lower case?
  1051.     jb    keysv10            ; e = yes
  1052.     cmp    al,'z'            ; above lower case?
  1053.     ja    keysv10            ; a = yes
  1054.     and    al,not 20h        ; convert to upper case
  1055.     mov    [si-1],al        ; put it back
  1056. keysv10:loop    keysv9            ; do all bytes, asciiz
  1057.     pop    si
  1058.     pop    cx
  1059.     clc                ; carry clear = ready to execute
  1060.     ret
  1061. keysv11:stc                ; carry set = no verb, do nothing
  1062.     pop    cx
  1063.     ret
  1064. keysv    endp
  1065.  
  1066. ; SET KEY - define a key   (procedure dfkey)
  1067. ; SET KEY <key ident><whitespace><new meaning>
  1068. ; Call from Kermit level. Returns carry set if failure.
  1069. ;  
  1070. DFKEY    PROC    NEAR            ; define a key as a verb or a string
  1071.     mov    keycode,0        ; clear keycode
  1072.     mov    oldform,0        ; say no old form Set Key yet
  1073.     or    byte ptr kbcodes,80h    ; say kbcodes not-initiated
  1074.     mov    bx,offset tranbuf    ; our work space
  1075.     mov    word ptr tranbuf,0    ; insert terminator
  1076.     mov    dx,offset dfhelp1    ; first help message
  1077.     mov    ah,cmword        ; parse a word
  1078.     call    comnd            ; get key code or original ascii char
  1079.     jnc    dfkey9
  1080.     ret
  1081. dfkey9:    mov    cl,taklev        ; reading from Take file
  1082.     mov    msutake,cl        ; save here
  1083.     or    ax,ax            ; any text given?
  1084.     jnz    dfkey12            ; nz = yes, so don't consider prompts
  1085.                     ; interactive key request
  1086.     cmp    taklev,0        ; in a Take file?
  1087.     je    dfkey10            ; e = no, prompt for keystroke
  1088.     jmp    dfkey0            ;  else say bad syntax
  1089. dfkey10:mov    ah,prstr
  1090.     mov    dx,offset dfaskky    ; ask for key to be pressed
  1091.     int    dos
  1092. dfkey11:call    getkey            ; read key ident from keyboard
  1093.     jc    dfkey11            ; c = no response, wait for keystroke
  1094.     mov    ah,prstr        ; display cr/lf
  1095.     mov    dx,offset crlf
  1096.     int    dos
  1097.     call    shkey0            ; show current definition (in SHKEY)
  1098.     jmp    dfkey1e            ; prompt for and process definition
  1099.  
  1100. dfkey12:                ; Look for word SCAN and ignore it
  1101.     mov    dx,word ptr tranbuf    ; get first two characters
  1102.     or    dx,2020h        ; map upper to lower case
  1103.     cmp    dx,'cs'            ; first two letters of word "scan"?
  1104.     je    dfkey            ; e = yes, skip the word
  1105.     cmp    dx,'lc'            ; first two letters of word "clear"?
  1106.     je    dfkey15            ; e = yes, reinit keyboard [2.31]
  1107.     cmp    dx,'fo'            ; first two letters of "off"
  1108.     je    dfkey13            ; e = yes, use DOS keyboard calls
  1109.     cmp    dx,'no'            ; first two letters of "on"
  1110.     je    dfkey13            ; e = yes, use standard kbd calls
  1111.     cmp    dx,'kl'            ; first two letters of "lk" (LK250)?
  1112.     je    dfkey13            ; e = yes
  1113.     cmp    ax,1            ; number of characters received
  1114.     jbe    dfkey12a        ; be = stay here
  1115.     jmp    dfkey1            ; a = more than one, decode
  1116. dfkey12a:mov    ah,byte ptr tranbuf    ; get the single char
  1117.     mov    byte ptr keycode,ah    ; store as ascii keycode
  1118.     jmp    dfkey1b            ; go get definition
  1119. dfkey13:push    dx            ; save command letters
  1120.     mov    ah,cmeol        ; get end of line confirmation
  1121.     call    comnd
  1122.     pop    dx
  1123.     jnc    dfkey14            ; nc = success
  1124.     ret
  1125. dfkey14:mov    al,0ffh            ; set DOS keyboard read flag
  1126.     cmp    dx,'fo'            ; first two letters of "off"
  1127.     je    dfkey14a        ; e = yes, use DOS keyboard calls
  1128.     xor    al,al            ; clear DOS keyboard read flag
  1129.     cmp    dx,'no'            ; first two letters of "on"
  1130.     je    dfkey14a        ; e = yes, use standard kbd calls
  1131.     mov    ah,dosflg        ; get current flag
  1132.     mov    dosflg,1        ; engage for chk250 test
  1133.     push    ax
  1134.     call    chk250            ; see if LK250 driver is present
  1135.     pop    ax
  1136.     mov    al,ah            ; recover current setting
  1137.     cmp    got250,0        ; did we find the driver?
  1138.     je    dfkey14a        ; e = no
  1139.     call    kbrest            ; and activiate it if so
  1140.     mov    al,1            ; say LK250
  1141. dfkey14a:mov    dosflg,al        ; store new keyboard flag
  1142.     ret
  1143.  
  1144. dfkey15:mov    ah,cmeol
  1145.     call    comnd            ; confirm request before proceeding
  1146.     jnc    dfkeyc            ; nc = success
  1147.     ret                ; failure
  1148.  
  1149. dfkey0:    push    ds
  1150.     mov    dx,seg dfhelp1        ; in seg data1
  1151.     mov    ds,dx
  1152.     mov    dx,offset dfhelp1    ; say bad definition command
  1153.     mov    ah,prstr
  1154.     int    dos
  1155.     pop    ds
  1156.     stc                ; failure
  1157.     ret
  1158.  
  1159. dfkeyc:                    ; CLEAR key defs, restore startup defs
  1160.     mov    cx,maxkeys        ; size of keycode tables
  1161.     push    es            ; save register
  1162.     push    ds
  1163.     pop    es            ; make es point to data segment
  1164.     xor    ax,ax            ; null, value to be stored
  1165.     mov    di,offset dirlist    ; director table
  1166.     cld
  1167.     rep    stosw            ; clear it
  1168.     mov    cx,maxkeys
  1169.     mov    di,offset keylist    ; keycode table
  1170.     rep    stosw            ; clear it
  1171.     mov    cx,maxstng
  1172.     mov    di,offset sptable    ; string pointer table
  1173.     rep    stosw            ; clear it
  1174.     pop    es            ; recover register
  1175.     mov    strmax,offset stbuf    ; clear string buffer, free space ptr
  1176.     mov    stbuf,0            ; first element of buffer 
  1177.     mov    nkeys,0            ; clear number of defined keys
  1178.     call    msuinit            ; restore startup definitions
  1179.     clc                ; success
  1180.     ret
  1181.                     ; Multi-char key identification
  1182. dfkey1:    mov    si,offset tranbuf    ; point to key ident text
  1183.     cmp    byte ptr [si],'0'    ; is first character numeric?
  1184.     jb    dfkey1a            ; b = no
  1185.     cmp    byte ptr [si],'9'    ; in numbers?
  1186.     ja    dfkey1a            ; a = no
  1187.     mov    keycode,scan        ; setup keycode for scan value
  1188.     mov    dx,si            ; get length of string in cx
  1189.     call    strlen
  1190.     push    ds
  1191.     pop    es            ; make es point to data segment
  1192.     push    si
  1193.     add    si,cx            ; point at string terminator
  1194.     mov    di,si
  1195.     inc    di            ; place to store string (1 byte later)
  1196.     inc    cx            ; include null terminator
  1197.     std                ; work backward
  1198.     rep    movsb            ; move string one place later
  1199.     cld
  1200.     pop    si
  1201.     mov    byte ptr [si],'\'    ; make ascii digits into \nnn form
  1202.     mov    oldform,0ffh        ; set old form flag
  1203.     mov    dx,offset kwarnmsg    ; tell user this is old form
  1204.     mov    ah,prstr
  1205.     int    dos
  1206. dfkey1a:mov    domath_ptr,si        ; string
  1207.     push    dx
  1208.     mov    dx,si
  1209.     call    strlen            ; get its length
  1210.     pop    dx
  1211.     mov    domath_cnt,cx
  1212.     call    domath            ; convert numeric to binary in dx:ax
  1213.     jc    dfkey0            ; c = no number converted
  1214.     or    keycode,ax        ; store in keycode
  1215.  
  1216. dfkey1b:                ; Get Definition proper
  1217.     test    oldform,0ffh        ; old form Set Key active?
  1218.     jz    dfkey1f            ; z = no
  1219.     mov    bx,offset tranbuf    ; get new definition on main cmd line
  1220.     mov    dx,offset dfhelp2    ; help for definition of key
  1221.     mov    comand.cmdonum,1    ; \number conversion allowed
  1222.     mov    ah,cmline        ; read rest of line into tranbuf
  1223.     call    comnd            ; allow null definitions
  1224.     mov    cx,ax            ; carry count in cx
  1225.     or    ax,ax            ; char count zero?
  1226.     jz    dfkey1e            ; z = zero, prompt for definition
  1227.     jmp    dfkey2            ; process definition
  1228.  
  1229. dfkey1e:mov    ah,prstr
  1230.     mov    dx,offset crlf
  1231.     int    dos
  1232.     mov    dx,offset dfaskdf    ; prompt for definition string
  1233.      call    prompt            ; Kermit prompt routine
  1234.     mov    comand.cmcr,1        ; permit bare carriage returns
  1235. dfkey1f:mov    bx,offset tranbuf    ; get new definition
  1236.     mov    dx,offset dfhelp2    ; help for definition of key
  1237.     mov    comand.cmwhite,1    ; allow leading whitespace
  1238.     mov    comand.cmdonum,1    ; \number conversion allowed
  1239.     mov    comand.cmblen,length tranbuf
  1240.     mov    ah,cmline        ; read rest of line into tranbuf
  1241.     call    comnd
  1242.     jc    dfkey1x            ; exit now on ^C from user
  1243.     mov    cx,ax            ; line count
  1244.     cmp    comand.cmcr,0        ; prompting for definition?
  1245.     je    dfkey1g            ; e = no, trim leading whitespace
  1246.     mov    comand.cmcr,0        ; turn off allowance for bare c/r's
  1247.     jmp    dfkey2            ; interactive, allow leading whitespace
  1248. dfkey1x:ret                ; failure exit
  1249.  
  1250. dfkey1g:push    ax            ; save count
  1251.     mov    ah,cmeol        ; get a confirm
  1252.     call    comnd
  1253.     pop    cx            ; string length
  1254.     jc    dfkey1x            ; none so declare parse error
  1255.     
  1256. dfkey2:                    ; Examine translation
  1257.     mov    al,trans.escchr        ; current escape char (port dependent)
  1258.     cmp    al,byte ptr keycode    ; is this Kermit's escape char?
  1259.     jne    dfkey2a            ; ne = no
  1260.     test    keycode,scan        ; see if scan code
  1261.     jnz    dfkey2a            ; nz = scan, so not ascii esc char
  1262.     mov    dx,offset dfkoops    ; Oops! msg
  1263.     mov    ah,prstr        ; complain and don't redefine
  1264.     int    dos
  1265.     stc                ; failure
  1266.     ret
  1267.  
  1268. dfkey2a:push    di            ; get a director code for this key
  1269.     push    cx    
  1270.     mov    di,offset keylist    ; list of keycodes
  1271.     mov    cx,nkeys        ; number currently defined
  1272.     mov    ax,keycode        ; present keycode
  1273.     jcxz    dfkey2b            ; cx = 0 means none defined yet
  1274.     cld
  1275.     push    ds
  1276.     pop    es
  1277.     repne    scasw            ; is current keycode in the list?
  1278.     jne    dfkey2b            ; ne = not in list
  1279.     sub    di,2            ; correct for auto increment
  1280.     sub    di,offset keylist
  1281.     mov    listptr,di        ; list pointer for existing definition
  1282.     pop    cx
  1283.     pop    di
  1284.     jmp    dfkey3            ; go process definition
  1285.  
  1286. dfkey2b:pop    cx            ; key not currently defined so
  1287.     pop    di            ;  make a new director entry for it
  1288.     mov    bx,nkeys        ; number of keys previously defined
  1289.     cmp    bx,maxkeys        ; enough space?
  1290.     jae    dfkey2c            ; ae = no, complain
  1291.     shl    bx,1            ; count words
  1292.     mov    listptr,bx        ; index into word list
  1293.     mov    ax,keycode        ; get key's code
  1294.     mov    keylist[bx],ax        ; store it in list of keycodes
  1295.     mov    dirlist[bx],0        ; clear the new director entry
  1296.     inc    nkeys            ; new number of keys
  1297.     jmp    dfkey3            ; go process definition
  1298.  
  1299. dfkey2c:mov    dx,offset keyfull    ; say key space is full already
  1300.     mov    ah,prstr
  1301.     int    dos
  1302.     stc                ; failure
  1303.     ret
  1304.  
  1305. ; listptr has element number in keylist or dirlist; keycode has key's code.
  1306.  
  1307. ; Parse new definition. First look for Kermit verbs as a line beginning
  1308. ; as \K or \{K. Otherwise, consider the line to be a string.
  1309. ; In any case, update the Director table for the new definition.
  1310.  
  1311. dfkey3:    mov    brace,0            ; assume not using braces
  1312.     mov    si,offset tranbuf    ; start of definition text
  1313.     cmp    byte ptr [si],'\'    ; starts with escape char?
  1314.     jne    dfkey5            ; ne = no, so we have a string
  1315.     inc    si            ; skip the backslash
  1316.     cmp    byte ptr [si],braceop    ; starts with \{?
  1317.     jne    dfkey3a            ; ne = no
  1318.     inc    si            ; skip the opening brace
  1319.     mov    brace,bracecl        ; expect closing brace
  1320. dfkey3a:cmp    byte ptr [si],'K'    ; starts with \{K or \K?
  1321.     je    dfkey3b            ; e = yes
  1322.     cmp    byte ptr [si],'k'    ; starts as \{k or \k?
  1323.     jne    dfkey5            ; ne = no, then it's a string
  1324. dfkey3b:inc    si            ; yes, skip the K too
  1325.                     ; Kermit action VERBS
  1326.     push    si            ; save verb name start address
  1327. dfkey4:    cld
  1328.     lodsb                ; scan til closing brace or w/s or end
  1329.     or    al,al            ; premature end?
  1330.     jz    dfkey4b            ; z = yes, accept without brace
  1331.     cmp    al,braceop        ; another opening brace?
  1332.     jne    dfkey4a            ; ne = no
  1333.     pop    si            ; clean stack
  1334.     jmp    short dfkey5        ; it's a string
  1335. dfkey4a:cmp    al,'\'            ; another object starting up?
  1336.     jne    dfkey4d            ; ne = no
  1337.     pop    si            ; clean stack
  1338.     jmp    short dfkey5        ; it's a string
  1339. dfkey4d:cmp    al,brace        ; closing brace?
  1340.     jne    dfkey4            ; ne = no, not yet
  1341.     cmp    byte ptr [si],0        ; closing brace terminates text?
  1342.     je    dfkey4b            ; e = yes, it's a verb
  1343.     pop    si            ; clean stack
  1344.     jmp    short dfkey5        ; it's a string
  1345. dfkey4b:pop    si            ; recover start address
  1346.     call    tstkeyw            ; find keyword, kw # returned in kbtemp
  1347.     jc    dfkey5            ; c = not found, assume \kmacro.
  1348.     call    remstr            ; clear old string, if string
  1349.     mov    ax,kbtemp        ; save keyword number
  1350.     and    ax,not(verb+strng)    ; clear verb / string field
  1351.     or    ax,verb            ; set verb ident
  1352.     mov    si,listptr
  1353.     mov    dirlist[si],ax        ; store info in Director table
  1354.     jmp    dfkey7            ; show results and return success
  1355.  
  1356. ; Here we are left with the definition string; si points to its start, and
  1357. ; its length is in cx. Null length strings mean define key as Self, one
  1358. ; byte means define as character, else as a string.
  1359.                     ; STRING definitions
  1360. dfkey5:    push    cx            ; cx = length of definition string
  1361.     call    remstr            ; first, clear old string, if any
  1362.     pop    cx
  1363.     mov    si,offset tranbuf    ; provide address of new string
  1364.     mov    di,si
  1365.     call    cnvlin            ; convert numbers, cx gets line length
  1366.     mov    si,offset tranbuf    ; provide address of new string
  1367.     cmp    cx,1            ; just zero or one byte to do?
  1368.     jbe    dfkey6            ; e = yes, do as a char
  1369.     call    insertst        ; insert new string, returns reg cx.
  1370.     jc    dfkey5h            ; c = could not do insert
  1371.     mov    si,listptr        ; cx has type and string number
  1372.     mov    dirlist[si],cx        ; update Director table from insertst
  1373.     jmp    dfkey7            ; show results and return success
  1374.  
  1375. dfkey5h:mov    dx,offset strbad    ; display complaint
  1376.     mov    ah,prstr
  1377.     int    dos
  1378.     stc                ; failure
  1379.     ret
  1380.  
  1381.         ; define SINGLE CHAR replacement or CLEAR a key definition.
  1382.         ; cx has char count 1 (normal) or 0 (to undefine the key).
  1383. dfkey6:    jcxz    dfkey6c            ; z = cx= 0, clear definition
  1384.     mov    al,byte ptr [si]    ; get first byte from definition
  1385.     xor    ah,ah            ; set the type bits to Char
  1386.     mov    si,listptr
  1387.     mov    dirlist[si],ax        ; store type and key's new code
  1388.     jmp    dfkey7            ; return success
  1389.  
  1390. dfkey6c:push    si            ; clear a definition,
  1391.     push    di            ; listptr points to current def
  1392.     mov    si,listptr        ; starting address to clear
  1393.     add    si,offset dirlist
  1394.     mov    di,si            ; destination
  1395.     add    si,2            ; source is next word
  1396.     mov    cx,nkeys        ; current number of keys defined
  1397.     add    cx,cx            ; double for listptr being words
  1398.     sub    cx,listptr        ; cx = number of words to move
  1399.     shr    cx,1            ; convert to actual number of moves
  1400.     jcxz    dfkey6d            ; z = none, just remove last word
  1401.     push    es
  1402.     push    ds
  1403.     pop    es            ; make es:di point to data segment
  1404.     cld
  1405.     push    cx            ; save cx
  1406.     rep    movsw            ; move down higher list items
  1407.     pop    cx
  1408.     mov    si,listptr        ; do keylist too, same way
  1409.     add    si,offset keylist
  1410.     mov    di,si
  1411.     add    si,2
  1412.     rep    movsw
  1413.     pop    es
  1414. dfkey6d:mov    si,nkeys        ; clear old highest list element
  1415.     shl    si,1            ; address words
  1416.     mov    dirlist[si],0        ; null the element
  1417.     mov    keylist[si],0        ; null the element
  1418.     dec    nkeys            ; say one less key defined now
  1419.     pop    di            ; restore saved registers
  1420.     pop    si
  1421.  
  1422. dfkey7:    mov    ah,msutake        ; Finish up. In a Take file?
  1423.     or    ah,taklev        ; or even directly
  1424.     or    ah,ah
  1425.     jz    dfkey7a            ; z = no
  1426.     cmp    flags.takflg,0        ; echo Take commands?
  1427.     je    dfkey7b            ; e = no
  1428. dfkey7a:mov    ah,prstr        ; display cr/lf
  1429.     mov    dx,offset crlf
  1430.     int    dos
  1431.     call    shkey0            ; show new definition (in SHKEY)
  1432.     call    shkfre            ; show free string space
  1433. dfkey7b:clc                ; return success
  1434.     ret
  1435. DFKEY    ENDP
  1436.  
  1437. ; SHOW KEY <cr> command. Call from Kermit level. Vectored here by SHOW
  1438. ; command. Replaces obsolete procedure in msx---.
  1439. ; Prompts for a key and shows that key's (or all if ? entered) keycode,
  1440. ; definition, and the key definition free space remaining.
  1441.  
  1442. SHKEY    PROC    NEAR            ; Show key's definition command
  1443.     mov    ah,cmeol        ; get a confirm
  1444.     call    comnd            ; ignore any additional text
  1445.     push    bx
  1446.     mov    dx,offset shkmsg1    ; ask for original key
  1447.     mov    ah,prstr
  1448.     int    dos
  1449.     or    byte ptr kbcodes,80h    ; say kbcodes not-initiated
  1450. shky0:    call    getkey            ; read keyboard, output to keycode
  1451.     jc    shky0            ; wait for a key (c = nothing there)
  1452.     cmp    byte ptr keycode,'?'    ; query for all keys?
  1453.     jne    shky0a            ; ne = no, not a query
  1454.     test    keycode,scan        ; is this a scan code, vs ascii query?
  1455.     jz    shky0c            ; z = no Scan, so it is a query
  1456.  
  1457. shky0a:    mov    ah,prstr        ; show single key. Setup display
  1458.     mov    dx,offset crlf
  1459.     int    dos
  1460.     call    shkey0            ; show just one key
  1461. shky0b:    call    shkfre            ; show free string space
  1462.     jmp    shkeyx            ; exit
  1463.  
  1464. shky0c:    mov    cx,nkeys        ; Show all keys. nkeys = number defined
  1465.     jcxz    shky0b            ; z = none to show
  1466.     mov    si,offset keylist    ; list of definitions
  1467.     push    si            ; save pointer
  1468. shky1:    pop    si            ; recover pointer
  1469.     cld
  1470.     lodsw                ; get a keycode
  1471.     push    si            ; save pointer
  1472.     push    cx            ; save counter
  1473.     mov    keycode,ax        ; save new keycode
  1474.     mov    ah,prstr
  1475.     mov    dx,offset crlf
  1476.     int    dos
  1477.     call    shkey0            ; show this keycode
  1478.  
  1479.     pop    cx            ; pause between screens, recover cntr
  1480.     push    cx            ; save it again
  1481.     dec    cx            ; number yet to be shown
  1482.     jcxz    shky1b            ; z = have now shown all of them
  1483.     mov    ax,nkeys        ; number of defined keys
  1484.     sub    ax,cx            ; minus number yet to be displayed
  1485.     xor    dx,dx            ; clear extended numerator
  1486.     cmp    isps55,0        ;[HF]940211 Japanese PS/55?
  1487.     je    shky1d            ;[HF]940211 e = no
  1488.     cmp    ps55mod,0        ;[HF]940211 is system modeline active?
  1489.     jne    shky1d            ;[HF]940211 ne = no
  1490.     div    eleven            ;[HF]940211 yes, actvie screen is 23
  1491.     jmp    short shky1e        ;[HF]940211
  1492. shky1d:    div    twelve            ; two lines per definition display
  1493. shky1e:    or    dx,dx            ; remainder zero (12 defs shown)?
  1494.     jnz    shky1b            ; nz = no, not yet so keep going
  1495.     mov    ah,prstr
  1496.     mov    dx,offset shkmsg3    ; "push any key to continue" msg
  1497.     int    dos
  1498. shky1a:    mov    ah,0bh            ; check console, check ^C
  1499.     int    dos
  1500.     cmp    flags.cxzflg,'C'    ; a ^C?
  1501.     je    shky1b            ; e = yes, quit
  1502.     or    al,al
  1503.     jz    shky1a            ; z = nothing
  1504.     call    getkey            ; get any key
  1505.     jc    shky1a            ; c = nothing at keyboard yet, wait
  1506. shky1b:    pop    cx            ; resume loop
  1507.     cmp    flags.cxzflg,'C'    ; a ^C?
  1508.     je    shky1c            ; e = yes, quit
  1509.     loop    shky1
  1510. shky1c:    pop    si            ; clean stack
  1511.     call    shkfre            ; show free string space
  1512.     jmp    shkeyx            ; exit
  1513.  
  1514.         ; show key worker routine, called from above
  1515.                     ; SHKEY0 called by DFKEY just above
  1516. SHKEY0:    test    keycode,scan        ; scan code?
  1517.     jz    shkey1            ; z = no, regular ascii
  1518.  
  1519.                     ; SCAN codes
  1520.     mov    dx,offset scanmsg    ; say Scan Code:
  1521.     mov    ah,prstr
  1522.     int    dos
  1523.     mov    ah,conout
  1524.     mov    dl,'\'            ; add backslash before number
  1525.     int    dos
  1526.     mov    ax,keycode        ; get key's code again
  1527.     call    decout            ; display 16 bit decimal keycode
  1528.     jmp    shkey2            ; go get definition
  1529.  
  1530. shkey1:    mov    dx,offset ascmsg    ; say ASCII CHAR
  1531.     mov    ah,prstr
  1532.     int    dos
  1533.     mov    dl,byte ptr keycode    ; get ascii code (al part of input)
  1534.     mov    ah,conout
  1535.     cmp    dl,spc            ; control code?
  1536.     jae    shkey1a            ; ae = no
  1537.     push    dx            ; save char
  1538.     mov    dl,5eh            ; show caret first
  1539.     int    dos
  1540.     pop    dx
  1541.     add    dl,'A'-1        ; ascii bias
  1542. shkey1a:cmp    dl,del            ; DEL?
  1543.     jne    shkey1b            ; ne = no
  1544.     mov    dl,'D'            ; spell out DEL
  1545.     int    dos
  1546.     mov    dl,'E'
  1547.     int    dos
  1548.     mov    dl,'L'
  1549. shkey1b:int    dos
  1550.     mov    dl,spc            ; add a couple of spaces
  1551.     int    dos
  1552.     int    dos
  1553.     mov    dl,'\'            ; add backslash before number
  1554.     int    dos
  1555.     mov    ax,keycode        ; show 16 bit keycode in decimal
  1556.     call    decout            ; and go get definiton
  1557.  
  1558.                     ; Display defintion
  1559. shkey2:    mov    dx,offset shkmsg2    ; intermediate part of reply
  1560.     mov    ah,prstr        ; " is defined as "
  1561.     int    dos
  1562.     push    di            ; get a director code for this key
  1563.     push    cx    
  1564.     mov    di,offset keylist    ; list of keycodes
  1565.     mov    cx,nkeys        ; number currently defined
  1566.     jcxz    shkey2a            ; z = none
  1567.     mov    ax,keycode        ; present keycode
  1568.     push    ds
  1569.     pop    es            ; use data segment for es:di
  1570.     cld
  1571.     repne    scasw            ; is current keycode in the list?
  1572.     jne    shkey2a            ; ne = not in list
  1573.     sub    di,2            ; correct for auto increment
  1574.     sub    di,offset keylist
  1575.     mov    listptr,di        ; list pointer for existing definition
  1576.     pop    cx
  1577.     pop    di
  1578.     jmp    shkey3            ; go process definition
  1579.  
  1580. shkey2a:pop    cx
  1581.     pop    di
  1582.     mov    dx,offset noxmsg    ; say Self (no translation)
  1583.     mov    ah,prstr
  1584.     int    dos
  1585.     ret                ; return to main show key loop
  1586.  
  1587. shkey3:                    ; translations, get kind of.
  1588.     mov    si,listptr
  1589.     test    dirlist[si],verb    ; defined as verb?
  1590.     jnz    shkey6            ; nz = yes, go do that one
  1591.     test    dirlist[si],strng    ; defined as string?
  1592.     jz    shkey3a            ; z = no
  1593.     jmp    shkey8            ; yes, do string display
  1594. shkey3a:
  1595.     mov    dx,offset ascmsg    ; CHAR. say 'Ascii char:'
  1596.     mov    ah,prstr
  1597.     int    dos
  1598.     mov    ax,dirlist [si]        ; get type and char
  1599.     mov    dl,al            ; put char here for display
  1600.     push    ax            ; save here too
  1601.     mov    ah,conout
  1602.     cmp    dl,spc            ; control code?
  1603.     jae    shkey4            ; ae = no
  1604.     push    dx
  1605.     mov    dl,5eh            ; show caret
  1606.     int    dos
  1607.     pop    dx
  1608.     add    dl,'A'-1        ; add ascii bias
  1609. shkey4:    cmp    dl,del            ; DEL?
  1610.     jne    shkey4a            ; ne = no
  1611.     mov    dl,'D'            ; spell out DEL
  1612.     int    dos
  1613.     mov    dl,'E'
  1614.     int    dos
  1615.     mov    dl,'L'
  1616. shkey4a:int    dos
  1617.     mov    dl,spc            ; add a couple of spaces
  1618.     mov    ah,conout
  1619.     int    dos
  1620.     int    dos
  1621.     mov    dl,'\'            ; add backslash before number
  1622.     int    dos
  1623.     pop    ax            ; recover char
  1624.     xor    ah,ah            ; clear high byte
  1625.     call    decout            ; show decimal value
  1626.     ret                ; return to main show key loop
  1627.  
  1628. shkey6:    mov    ah,prstr        ; VERB
  1629.     mov    dx,offset verbmsg    ; say 'verb'
  1630.     int    dos
  1631.     mov    si,listptr        ; get verb index from director
  1632.     mov    dx,dirlist[si]
  1633.     and    dx,not(verb+strng)    ; remove type bits, leaves verb number
  1634.     mov    bx,offset kverbs    ; table of verbs & actions
  1635.     mov    al,byte ptr [bx]    ; number of keywords
  1636.     xor    ah,ah
  1637.     dec    ax
  1638.     mov    kwcnt,ax        ; save number of last one here
  1639.     cmp    dx,ax            ; asking for more than we have?
  1640.     ja    shkeyx            ; a = yes, exit bad
  1641.     inc    bx            ; point to first slot
  1642.     xor    cx,cx            ; current slot number
  1643. shkey6b:cmp    cx,dx            ; this slot?
  1644.     je    shkey6c            ; e = yes, print the text part
  1645.     ja    shkeyx            ; a = beyond, exit bad
  1646.     mov    ax,[bx]            ; get cnt (keyword length)
  1647.     add    ax,4            ; skip count and two byte value
  1648.     add    bx,ax            ; bx = start of next keyword slot
  1649.     inc    cx            ; current keyword number
  1650.     jmp    short shkey6b        ; try another
  1651. shkey6c:push    cx
  1652.     mov    cx,[bx]            ; length of definition
  1653.     add    bx,2            ; look at text field
  1654.     mov    di,bx            ; offset for printing
  1655.     call    prtscr            ; print counted string
  1656.     mov    ah,conout
  1657.     mov    dl,spc            ; add a couple of spaces
  1658.     int    dos
  1659.     int    dos
  1660.     mov    dl,'\'            ; show verb name as \Kverb
  1661.     int    dos
  1662.     mov    dl,'K'
  1663.     int    dos
  1664.     call    prtscr            ; print counted string, again
  1665.     pop    cx
  1666.     ret                ; return to main show key loop
  1667.  
  1668. shkey8:    mov    ah,prstr        ; STRING
  1669.     mov    dx,offset strngmsg    ; say String:
  1670.     int    dos
  1671.     mov    si,listptr        ; get index from director
  1672.     mov    bx,dirlist[si]
  1673.     and    bx,not(verb+strng)    ; remove type bits
  1674.     shl    bx,1            ; index words
  1675.     mov    si,sptable[bx]        ; table of string offsets
  1676.     mov    cx,word ptr [si]    ; get string length
  1677.     add    si,2            ; point to string text
  1678.     mov    ah,conout
  1679. shkey8a:cld
  1680.     lodsb                ; get a byte
  1681.     cmp    al,127            ; DEL?
  1682.     je    shkey8c            ; e = yes
  1683.     cmp    al,spc            ; control code?
  1684.     jae    shkey8b            ; ae = no
  1685. shkey8c:push    ax
  1686.     mov    dl,5eh            ; show caret first
  1687.     int    dos
  1688.     pop    ax
  1689.     add    al,40h            ; convert to printable for display
  1690.     and    al,7fh
  1691. shkey8b:mov    dl,al
  1692.     int    dos            ; display it
  1693.     loop    shkey8a            ; do another
  1694.     ret                ; return to main show key loop
  1695.     
  1696. shkeyx:    pop    bx            ; restore reg
  1697.     clc                ; return success
  1698.     ret
  1699. SHKEY    ENDP
  1700.  
  1701. ;;;    keyboard translator local support procedures, system independent
  1702.  
  1703. ; Tstkeyw checks text word pointed to by si against table of keywords (pointed
  1704. ; to by kverbs, made by mkeyw macro); returns in bx either action value or 0.
  1705. ; Returns in kbtemp the number of the keyword and carry clear, or if failure
  1706. ; returns kbtemp zero and carry set.
  1707. ; Keyword structure is:         dw    cnt    (length of string 'word')
  1708. ;                 db    'word'    (keyword string)
  1709. ;                 dw    value    (value returned in bx)
  1710. ; Make these with macro mkeyw such as   mkeyw 'test',15   with the list of
  1711. ; such keywords headed by a byte giving the number of keywords in the list.
  1712. tstkeyw    proc    near
  1713.     push    ax
  1714.     push    cx
  1715.     push    si
  1716.     mov    verblen,0        ; verblen will hold verb length
  1717.     push    si            ; save user's verb pointer
  1718. tstkw1:    cld
  1719.     lodsb                ; get a verb character
  1720.     cmp    al,spc            ; verbs are all non-spaces and above
  1721.     jbe    tstkw2            ; be = done (space or control char)
  1722.     cmp    word ptr [si-1],'}'    ; closing brace?
  1723.     je    tstkw2            ; e = yes, exclude as terminator
  1724.     inc    verblen            ; count verb length
  1725.     jmp    short tstkw1        ; printable char, look for more
  1726. tstkw2:    pop    si            ; pointer to verb
  1727.     mov    bx,offset kverbs    ; table of Kermit verb keywords
  1728.     mov    al,byte ptr [bx]    ; number of keywords
  1729.     xor    ah,ah
  1730.     mov    kwcnt,ax        ; save number of keywords here
  1731.     inc    bx            ; point bx to first slot
  1732.     mov    kbtemp,0        ; remember which keyword
  1733.  
  1734. tstkw3:                    ; match table keyword and text word
  1735.     mov    cx,verblen        ; length of user's verb
  1736.     cmp    [bx],cx            ; compare length vs table keyword
  1737.     jne    tstkw4            ; ne = not equal lengths, try another
  1738.     push    si            ; lengths match, how about spelling?
  1739.     push    bx
  1740.     add    bx,2            ; point at start of keyword
  1741. tstkw3a:mov    ah,byte ptr [bx]    ; keyword char
  1742.     mov    al,byte ptr [si]    ; text char
  1743.     cmp    ah,'A'
  1744.     jb    tstkw3b            ; b = control chars
  1745.     cmp    ah,'Z'
  1746.     ja    tstkw3b            ; a = not upper case alpha
  1747.     add    ah,'a'-'A'        ; convert upper case to lower case
  1748. tstkw3b:cmp    al,'A'
  1749.     jb    tstkw3c
  1750.     cmp    al,'Z'
  1751.     ja    tstkw3c
  1752.     add    al,'a'-'A'        ; convert upper case to lower case
  1753. tstkw3c:cmp    al,ah            ; test characters
  1754.     jne    tstkw3d            ; ne = no match
  1755.     inc     si            ; move to next char
  1756.     inc    bx
  1757.     loop    tstkw3a            ; loop through entire length
  1758. tstkw3d:pop    bx
  1759.     pop    si
  1760.     jcxz    tstkw5            ; z: cx = 0, exit with match;
  1761.                     ;  else select next keyword
  1762. tstkw4:    inc    kbtemp            ; number of keyword to test next
  1763.     mov    cx,kbtemp
  1764.     cmp    cx,kwcnt        ; all done? Recall kbtemp starts at 0
  1765.     jae    tstkwx            ;ae = exhausted search, unsuccessfully
  1766.     mov    ax,[bx]            ; cnt (keyword length from macro)
  1767.     add    ax,4            ; skip over count and two byte value
  1768.     add    bx,ax            ; bx = start of next keyword slot
  1769.     jmp    tstkw3            ; do another comparison
  1770.  
  1771. tstkw5:                    ; get action pointer
  1772.     mov    ax,[bx]            ; cnt (keyword length from macro)
  1773.     add    ax,2            ; skip over count
  1774.     add    bx,ax            ; now bx points to dispatch value
  1775.     mov    bx,[bx]            ; bx holds dispatch value
  1776.     clc                ; carry clear for success
  1777.     jmp    short tstkwxx        ; exit
  1778.     ret
  1779. tstkwx:    xor    bx,bx            ; exit when no match
  1780.     mov    kbtemp,bx        ; make verb number be zero too
  1781.     stc                ; carry set for failure
  1782. tstkwxx:pop    si
  1783.     pop    cx
  1784.     pop    ax
  1785.     ret
  1786. tstkeyw    endp
  1787.  
  1788. ; Insert asciiz string pointed to by si into string buffer stbuf.
  1789. ; Reg cx has string length upon entry.
  1790. ; Success: returns offset of first free byte (strmax) in string buffer stbuf,
  1791. ; cx = type and Index of new string, and carry clear.
  1792. ; Failure = carry set.
  1793. insertst proc    near
  1794.     push    bx
  1795.     push    dx
  1796.     push    si
  1797.     push    di
  1798.     push    kbtemp        ; save this variable too
  1799.     mov    dx,cx        ; save length of incoming string in dx
  1800.     mov    bx,offset sptable ; table of string offsets
  1801.     mov    kbtemp,0    ; slot number
  1802.     mov    cx,maxstng    ; number of entries, find an empty slot
  1803. insert1:cmp    word ptr[bx],0    ; slot empty?
  1804.     je    insert2        ; e = yes
  1805.     inc    kbtemp        ; remember slot number
  1806.     add    bx,2        ; look at next slot
  1807.     loop    insert1        ; keep looking
  1808.     jmp    short insert4    ; get here if no empty slots
  1809. insert2:            ; see if stbuf has sufficient space
  1810.     mov    cx,dx        ; length of new string to cx
  1811.     mov    di,strmax    ; offset of first free byte in stbuf
  1812.     add    di,cx        ; di = address where this string would end
  1813.     cmp    di,offset stbuf+stbuflen ; beyond end of buffer?
  1814.     jae    insert4        ; ae = yes, not enough room
  1815.     mov    di,strmax    ; point to first free slot in stbuf
  1816.     mov    [bx],di        ; fill slot with address offset of buffer
  1817.     push    es
  1818.     push    ds
  1819.     pop    es        ; point es:di to data segment
  1820.     cld
  1821.     mov    [di],cx        ; length of text for new string
  1822.     add    di,2        ; move to next storage slot
  1823.     rep    movsb        ; copy string text
  1824.     pop    es
  1825.     mov    strmax,di    ; offset of next free byte
  1826.     mov    cx,kbtemp    ; return new slot number with Director Index
  1827.     and    cx,not(strng+verb) ; clear type bits
  1828.     or    cx,strng    ; say type is multi-char string
  1829.     clc            ; say success
  1830.     jmp    short insertx    ; exit
  1831. insert4:stc            ; say no-can-do
  1832. insertx:pop    kbtemp
  1833.     pop    di
  1834.     pop    si
  1835.     pop    dx
  1836.     pop    bx
  1837.     ret
  1838. insertst endp
  1839.  
  1840. ; Remove (delete) string. Enter with listptr preset for director entry.
  1841. ; Acts only on existing multi-char strings; recovers freed space.
  1842. ; All registers preserved.
  1843. remstr    proc    near        
  1844.     push    si
  1845.     mov    si,listptr        ; list pointer
  1846.     test    dirlist[si],strng    ; multi-char string?
  1847.     pop    si
  1848.     jnz    remst1            ; nz = a multi-char string
  1849.     ret                ; else do nothing
  1850. remst1:    push    ax
  1851.     push    bx
  1852.     push    cx
  1853.     push    dx
  1854.     push    si
  1855.     mov    si,listptr
  1856.     mov    ax,dirlist[si]         ; Director table entry
  1857.     and    ax,not(strng+verb) ; clear type bits, leave string's pointer
  1858.     mov    dirlist[si],0        ; clear Director table entry
  1859.     shl    ax,1            ; index words not bytes
  1860.     mov    si,offset sptable     ; list of string offsets in stbuf
  1861.     add    si,ax            ; plus index = current slot
  1862.     mov    bx,[si]            ; get offset of string to be deleted
  1863.     mov    dx,bx            ; save in dx for later
  1864.     mov    cx,[bx]            ; get length of subject string
  1865.     add    cx,2            ; length word too, cx has whole length
  1866.     sub    strmax,cx    ; count space to be freed (adj end-of-buf ptr)
  1867.     mov    word ptr [si],0    ; clear sptable of subject string address
  1868.     push    cx            ; save length of purged string
  1869.     push    di            ; save di
  1870.     push    si
  1871.     push    es            ; save es
  1872.     push    ds
  1873.     pop    es        ; setup es:di to be ds:offset of string
  1874.     mov    di,dx        ; destination = start address of purged string
  1875.     mov    si,dx        ; source = start address of purged string
  1876.     add    si,cx        ;  plus string length of purged string.
  1877.     mov    cx,offset stbuf+stbuflen ; 1 + address of buffer end
  1878.     sub    cx,si            ; 1 + number of bytes to move
  1879.     dec    cx            ; number of bytes to move
  1880.     jcxz    remst2            ; z = none
  1881.     cld                ; direction is forward
  1882.     rep    movsb            ; move down preserved strings
  1883. remst2:    pop    es            ; restore regs
  1884.     pop    di
  1885.     pop    si
  1886.     pop    ax        ; recover length of purged string (was in cx)
  1887.     mov    bx,offset sptable     ; string pointer table
  1888.     mov    cx,maxstng        ; max mumber of entries
  1889. remst4:    cmp    [bx],dx        ; does this entry occur before purged string?
  1890.     jbe    remst5        ; be = before or equal, so leave it alone
  1891.     sub    [bx],ax        ; recompute address (remove old string space)
  1892. remst5:    add    bx,2            ; look at next list entry
  1893.     loop    remst4            ; do all entries in sptable
  1894.     pop    si
  1895.     pop    dx
  1896.     pop    cx
  1897.     pop    bx
  1898.     pop    ax
  1899.     ret
  1900. remstr    endp
  1901.  
  1902. shkfre    proc    near            ; show free key & string defs & space
  1903.     push    ax            ; preserves all registers.
  1904.     push    bx
  1905.     push    cx
  1906.     push    dx
  1907.     push    kbtemp
  1908.     mov    dx,offset fremsg
  1909.     mov    ah,prstr
  1910.     int    dos
  1911.     mov    ax,maxkeys        ; max number of key defs
  1912.     sub    ax,nkeys        ; number currently used
  1913.     call    decout            ; show the value
  1914.     mov    ah,prstr
  1915.     mov    dx,offset kyfrdef    ; give key defs msg
  1916.     int    dos
  1917.     mov    bx,offset sptable    ; table of string pointers
  1918.     mov    cx,maxstng        ; number of pointers
  1919.     mov    kbtemp,0        ; number free
  1920. shkfr1:    cmp    word ptr [bx],0        ; slot empty?
  1921.     jne    shkfr2            ; ne = no
  1922.     inc    kbtemp            ; count free defs
  1923. shkfr2:    add    bx,2            ; look at next slot
  1924.     loop    shkfr1            ; do all of them
  1925.     mov    ax,kbtemp        ; number of free defs
  1926.     call    decout            ; display
  1927.     mov    dx,offset stfrdef    ; say free string defs
  1928.     mov    ah,prstr
  1929.     int    dos
  1930.     mov    ax,offset stbuf+stbuflen ; 1 + last byte in stbuf
  1931.     sub    ax,strmax        ; offset of last free byte in stbuf
  1932.     call    decout
  1933.     mov    dx,offset stfrspc    ; give free space part of msg
  1934.     mov    ah,prstr
  1935.     int    dos
  1936.     pop    kbtemp
  1937.     pop    dx
  1938.     pop    cx
  1939.     pop    bx
  1940.     pop    ax
  1941.     ret
  1942. shkfre    endp
  1943.  
  1944. ; Initialize the keyboard tables at Kermit startup time. Optional procedure.
  1945. ; Requires kbdinlst to be configured with mkeyw macro in the form
  1946. ;    mkeyw    'definition',keytype*256+keycode
  1947. ; keytype is 0 for scan codes and non-zero for ascii.
  1948. ; Returns normally.
  1949. kbdinit    proc     near            ; read keyword kbdinlst and setup
  1950.     or    byte ptr kbcodes,80h    ; say kbcodes not-initiated
  1951.     push    ds            ;  initial keyboard assignments.
  1952.     pop    es            ; set es:di to data segment
  1953.     inc    taklev            ; pretend that we are in Take file
  1954.     call    chk250            ;** LK250 support begin
  1955.     cmp    got250,1        ;** is it installed?
  1956.     jne    kbdini0            ;** ne = no
  1957.     call    kbrest            ;** else initialize to DEC mode
  1958.     mov    si,offset kb250lst    ;** load extensions
  1959.     jmp    short kbdini1        ;** LK250 support end
  1960. kbdini0:mov     si,offset kbdinlst      ; start of list of definitions
  1961. kbdini1:mov    cx,[si]            ; cnt field (keyword length of macro)
  1962.     jcxz    kbdinix            ; z = null cnt field = end of list
  1963.     add    si,2            ; look at text field
  1964.     mov    di,offset tranbuf    ; where defkey expects text
  1965.     push    cx
  1966.     cld
  1967.     rep    movsb            ; copy cx chars to tranbuf
  1968.     pop    cx
  1969.     mov    byte ptr [di],0        ; insert null terminator
  1970.     mov    ax,word ptr [si]    ; get value field
  1971.     mov    keycode,ax        ; set key ident value
  1972.     push    si
  1973.     call    dfkey2            ; put dfkey to work
  1974.     pop    si
  1975.     add    si,2            ; point to next entry
  1976.     jmp    kbdini1            ; keep working
  1977. kbdinix:dec    taklev            ; reset Take file level
  1978.     call    fudkclear        ; clear User Definable Keys
  1979.     mov    cx,40h            ; segment 40h
  1980.     mov    es,cx
  1981.     mov    cl,byte ptr es:[96h]    ; kbd_flag_3, Enhanced keyboard area
  1982.     test    cl,10h            ; select Enhanced kbd presence bit
  1983.     jz    kbdinx1            ; z = regular (88)
  1984.     mov    keyboard,101        ; 101 = enhanced kbd
  1985. kbdinx1:ret
  1986. kbdinit    endp
  1987. ;;;    End of System Independent Procedures
  1988.  
  1989. ;;;    Begin System Dependent Procedures
  1990.  
  1991. ; Read keyboard. System dependent.
  1992. ; Return carry set if nothing at keyboard.
  1993. ; If char present return carry clear with key's code in Keycode.
  1994. ; If key is ascii put that in the low byte of Keycode and clear bit Scan in
  1995. ; the high byte; otherwise, put the scan code in the lower byte and set bit
  1996. ; Scan in the high byte.
  1997. ; Bit Scan is set if key is not an ascii code.
  1998. ; Two methods are used: Bios reading for Set Key ON, and DOS reading for
  1999. ; Set Key OFF. DOS scan codes are coerced to Bios values as much as possible.
  2000. ; Modifies register ax.
  2001. getkey    proc    near
  2002.     mov    keycode,0        ; clear old keycode
  2003.     cmp    dosflg,0ffh        ; do DOS keyboard reading?
  2004.     je    getky7            ; e = yes, DOS
  2005.     jmp    getky6            ; do full Bios form
  2006.                     ; ;;;;;;;; D O S ;;;;;;;;;;
  2007. getky7:    test    byte ptr kbcodes,80h    ; kbcodes initiated?        [dan]
  2008.     jz    getky5            ; z = yes            [dan]
  2009.     and    byte ptr kbcodes,not 80h ; say kbcodes initiated
  2010. getky5:    call    iseof            ; is stdin at eof?
  2011.     jnc    getky5k            ; nc = not eof, get more
  2012.      mov    al,trans.escchr        ; Kermit's escape char
  2013.     mov    byte ptr keycode,al    ; save ascii char
  2014.     clc                ;  to get out gracefully at EOF
  2015.     ret                ; and exit
  2016.  
  2017. getky5k:mov    dl,0ffh            ; DOS read operation
  2018.     mov    ah,dconio        ; from stdin
  2019.     int    dos
  2020.     jnz    getky5a            ; nz = char available
  2021.     stc                ; carry set = nothing available
  2022.     ret                ; exit on no char
  2023. getky5a:or    al,al            ; scan code precursor?
  2024.     jz    getky5d            ; z = yes
  2025.     cmp    al,16            ; Control P?
  2026.     jne    getky5b            ; ne = no
  2027.     mov    al,114            ; force Control PrtSc scan code
  2028.     jmp    short getky5e        ; process as scan code
  2029. getky5b:cmp    al,BS            ; backspace key?
  2030.     jne    getky5c            ; ne = no
  2031.     mov    al,14            ; force scan code for BS key
  2032.     jmp    short getky5e        ; process as scan code
  2033. getky5c:mov    byte ptr keycode,al    ; save ascii char
  2034.     clc                ; carry clear = got a char
  2035.     ret                ; and exit
  2036.  
  2037. getky5d:mov    dl,0ffh            ; read second byte (actual scan code)
  2038.     mov    ah,dconio        ; read via DOS
  2039.     int    dos
  2040.     jnz    getky5e            ; nz = got a char
  2041.     stc                ; none, declare bad read
  2042.     ret
  2043.                     ; Check and modify to Bios scan codes
  2044. getky5e:mov    byte ptr keycode,al    ; save char code
  2045.     cmp    al,1            ; Alt escape
  2046.     je    getkya            ; set Alt bit
  2047.     cmp    al,16            ; back tab
  2048.     jb    getky5g            ; these remain unchanged
  2049.     cmp    al,50            ; start of meta keys
  2050.     jb    getkya            ; b = set Alt bit
  2051.     cmp    al,84            ; Shift F1
  2052.     jb    getky5g            ; b = no change
  2053.     cmp    al,94            ; Control F1
  2054.     jb    getkys            ; set Shift bit
  2055.     cmp    al,104            ; Alt F1
  2056.     jb    getkyc            ; set Control bit
  2057.     cmp    al,114            ; Control PrtSc
  2058.     jb    getkya            ; set Alt bit
  2059.     cmp    al,120            ; Alt top rank
  2060.     jb    getkyc            ; set Control bit
  2061.     cmp    al,132            ; Control PgUp
  2062.     jb    getkya            ; set Alt bit
  2063.     je    getkyc            ; set Control bit
  2064.     cmp    al,135            ; Shift F11, for Enhanced keyboard
  2065.     jb    getky5g            ; no change
  2066.     cmp    al,137            ; Control F11
  2067.     jb    getkys            ; set Shift bit
  2068.     cmp    al,139            ; Alt F11
  2069.     jb    getky5c            ; set Control bit
  2070.     cmp    al,141            ; Control Up
  2071.     jb    getkya            ; set Alt bit
  2072.     cmp    al,151            ; Alt Home
  2073.     jb    getkyc            ; set Control bit
  2074.     jmp    short getkya        ; set Alt bit
  2075. getkyc:    or    keycode,control        ; set Control bit
  2076.     jmp    short getky5g
  2077. getkys:    or    keycode,shift        ; set Shift bit
  2078.     jmp    short getky5g
  2079. getkya:    or    keycode,alt        ; set Alt bit
  2080. getky5g:or    keycode,scan        ; ensure scan bit is set
  2081.     clc                ; report we have a scan keycode
  2082.     ret                ; and exit
  2083.  
  2084.                     ; ;;;;;;;;;; B I O S ;;;;;;;;;;;;;
  2085. getky6:                    ; full BIOS keyboard reading
  2086.     test    byte ptr kbcodes,80h    ; kbcodes initiated?        [dan]
  2087.     jz    getky6a            ; z = yes            [dan]
  2088.     mov    kbcodes,0001h        ; low byte = status, high = read char
  2089.     push    cx            ; save registers
  2090.     push    es
  2091.     mov    cx,40h            ; segment 40h
  2092.     mov    es,cx
  2093.     mov    cl,byte ptr es:[96h]    ; kbd_flag_3, Enhanced keyboard area
  2094.     and    cl,10h            ; select Enhanced kbd presence bit
  2095.     mov    ch,cl            ; copy, for both status and read
  2096.     or    kbcodes,cx        ; 0 = regular kbd, 10h = enhanced kbd
  2097.     pop    es
  2098.     pop    cx
  2099.  
  2100. getky6a:mov    ah,byte ptr kbcodes    ; anything at keyboard?
  2101.     xor    al,al
  2102.     int    kbint            ; Bios keyboard interrupt
  2103.     jnz    getky1            ; nz = char available
  2104.     cmp    ax,240            ; Bios "special ascii code" 0f0h?
  2105.     je    getky1            ; e = yes, Bios makes error, is a key
  2106.     stc                ; carry set = nothing available
  2107.     ret                 ; exit on no char available
  2108. getky1:    mov    ah,byte ptr kbcodes+1    ; read, no echo, wait til done
  2109.     int    kbint            ; ==> ah = scan code, al = char value
  2110.     cmp    ah,0            ; keycode entered by ALT ###?
  2111.     je    getky1c            ; e = yes, not enhanced
  2112.     cmp    ah,0e0h            ; Enhanced kbd Enter, fwd slash keys?
  2113.     jne    getky1b            ; ne = no
  2114.     xchg    ah,al            ; interchange scan and ascii fields
  2115. getky1b:cmp    al,0E0h            ; enhanced key hidden code?
  2116.     jne    getky1c            ; ne = no
  2117.     mov    byte ptr keycode,ah    ; retain scan code, surpress 0e0h
  2118.     or    keycode,scan+enhanced    ; set scan and enhanced idents
  2119.     mov    ah,2            ; use regular keyboard op code here
  2120.     int    kbint            ; get current shift state
  2121.     mov    bl,al            ; copy for a moment
  2122.     and    bl,rgt_shift        ; mask out all but right shift
  2123.     shl    bl,1            ; move right shift to left shift pos
  2124.     or    al,bl            ; collapse shift bits
  2125.     and    al,(lft_shift + alt_shift + ctl_shift)
  2126.     or    byte ptr keycode+1,al    ; store in type field of keycode
  2127.     clc                ; say have a keystroke
  2128.     jmp    getkyx            ; Enhanced kbd end. Skip other tests
  2129.  
  2130. getky1c:push    cx
  2131.     mov    cx,aliaslen        ; number of aliased keys
  2132.     or    cx,cx
  2133.     pop    cx
  2134.     jz    getky2            ; z = none
  2135.     push    di            ; check key (ax) for aliases
  2136.     push    cx
  2137.     push    es
  2138.     push    ds
  2139.     pop    es            ; make es:di refer to data segment
  2140.     mov    di,offset aliaskey    ; list of aliased keys
  2141.     mov    cx,aliaslen        ; number of entries
  2142.     cld
  2143.     repne    scasw            ; look for a match
  2144.     pop    es
  2145.     pop    cx
  2146.     pop    di
  2147.     jne    getky2            ; ne = not there
  2148.     xor    al,al            ; force use of scan code (in ah)
  2149. getky2:    or    al,al            ; scan code being returned?
  2150.     jnz    getky3            ; nz = no
  2151.     mov    byte ptr keycode,ah    ; store scan code for gsh
  2152.     push    ax
  2153.     push    bx
  2154.     call    gsh            ; get modified shift state
  2155.     or    byte ptr keycode+1,al    ; store in type field of keycode
  2156.     pop    bx
  2157.     pop    ax
  2158.     xchg    ah,al            ; put scan code in al
  2159.     or    keycode,scan        ; set scan flag (vs ascii)
  2160. getky3:    mov    byte ptr keycode,al    ; return key's code (usually ascii)
  2161.     clc                ; carry clear = got a char
  2162. getkyx:    ret
  2163. getkey    endp
  2164.  
  2165.  
  2166. ; get shift state into al.  We care about only shift, ctl, and alt keys.
  2167. ; right shift is collapsed into left shift. NumLock offsets Shift on keypad
  2168. ; white keys.
  2169. gsh    proc    near
  2170.     mov    ah,2
  2171.     int    kbint            ; get current shift state
  2172.     mov    bl,al            ; copy for a moment
  2173.     and    bl,rgt_shift        ; mask out all but right shift
  2174.     shl    bl,1            ; move right shift to left shift pos
  2175.     or    al,bl            ; collapse shift bits
  2176.     cmp    byte ptr keycode,71    ; below numeric key pad?
  2177.     jb    gsh1            ; b = yes
  2178.     cmp    byte ptr keycode,83    ; above numeric key pad?
  2179.     ja    gsh1            ; a = yes
  2180.     cmp    byte ptr keycode,74    ; grey - key ?
  2181.     je    gsh1            ; e = yes
  2182.     cmp    byte ptr keycode,78    ; grey + key
  2183.     je    gsh1            ; e = yes
  2184.     test    al,numlock        ; numlock set?
  2185.     jz    gsh1            ; z = no
  2186.     xor    al,lft_shift        ; numlock offsets shift and vice versa
  2187. gsh1:    and    al,(lft_shift + alt_shift + ctl_shift)
  2188.     ret
  2189. gsh    endp
  2190.  
  2191.  
  2192. ; Do any local processing after reading a key during active translation
  2193. ; Avoids same actions if a key is being defined or shown.
  2194. postkey    proc    near
  2195.                     ; Key Click code for VT102 emulator
  2196.     cmp    flags.vtflg,0        ; emulating? (0 = no)
  2197.     je    postke1            ; e = extra clicks not available
  2198.     test    vtemu.vtflgst,vskeyclick ; flags from SET TERM
  2199.     jz    postke1            ; z = extra clicks not wanted
  2200.     call    fvclick            ; click, what else?
  2201. postke1:ret
  2202. postkey    endp
  2203.                     ;** start of LK250 stuff
  2204. kbrest    proc    near            ; set LK250 to DEC mode
  2205.     cmp    got250,1        ; LK250 present?
  2206.     jne    kbrest1            ; ne = no
  2207.     push    es            ; save reg
  2208.     mov    ax,40h            ; point to low memory
  2209.     mov    es,ax
  2210.     or    byte ptr es:[17h],20h    ; ensure Num Lock is on
  2211.     and    byte ptr es:[17h],0efh    ;  and Scroll is off
  2212.     pop    es            ; restore our [DS]
  2213.     mov    ax,5001h        ; issue set mode DEC to keyboard
  2214.     int    15h
  2215. kbrest1:ret
  2216. kbrest    endp
  2217.  
  2218. kbsusp    proc    near            ; set LK250 to DOS mode
  2219.     cmp    got250,1        ; LK250 present?
  2220.     jne    kbsusp1            ; ne = no
  2221.     mov    ax,5000h        ; unload extensions
  2222.     int    15h
  2223. kbsusp1:ret
  2224. kbsusp    endp
  2225.  
  2226. kbhold    proc    near
  2227.     cmp    got250,1        ; LK250 present?
  2228.     jne    kbhold1            ; ne = no
  2229.     mov    ax,5002h        ; issue SET LEDS
  2230.     mov    bl,0edh
  2231.     int    15h
  2232.     mov    ax,5002h
  2233.     mov    bl,holdscr        ; get the hold state
  2234.     or    bl,2            ; OR in Num Lock
  2235.     int    15h
  2236. kbhold1:ret
  2237. kbhold    endp                ;** end of LK250 stuff
  2238.  
  2239. code    ends
  2240. code1    segment
  2241.     assume    cs:code1
  2242.                     ; LK250 stuff
  2243. chk250    proc    far            ; presence test for DEC LK250 keyboard
  2244.     mov    got250,0        ; assume no LK250 keyboard
  2245.     cmp    dosflg,1        ; use LK250?
  2246.     jne    chk250x            ; ne = no
  2247.     mov    ax,sp            ; do push sp test for XT vs AT/386
  2248.     push    sp            ; XT pushes sp-2, AT's push old sp
  2249.     pop    cx            ; recover pushed value, clean stack
  2250.     xor    ax,cx            ; same?
  2251.     jne    chk250a            ; ne = no, XT. Don't do Int 15h
  2252.     mov    ax,5000h        ; see if the keyboard is loaded
  2253.     int    15h            ; look for DOS->DEC mode driver
  2254.     cmp    ax,1234h        ; find marker 1234h
  2255.     jne    chk250a            ; ne = marker not present, no driver
  2256.     mov    got250,1        ; else say we have an LK250
  2257.     mov    keyboard,250        ; global Variable
  2258. chk250x:ret
  2259. chk250a:mov    ah,prstr
  2260.     mov    dx,offset lk250msg    ; say driver not active
  2261.     int    dos
  2262.     ret
  2263. chk250    endp
  2264. code1    ends
  2265.     end
  2266.