home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume41 / pcvt / part02 < prev    next >
Encoding:
Internet Message Format  |  1994-03-02  |  88.5 KB

  1. From: hm@hcshh.hcs.de (Hellmuth Michaelis)
  2. Newsgroups: comp.sources.misc
  3. Subject: v41i141:  pcvt - Video Driver for 386BSD/NetBSD/FreeBSD, v3.00, Part02/13
  4. Date: 1 Mar 1994 16:58:55 -0600
  5. Organization: Sterling Software
  6. Sender: root@news.sterling.com
  7. Approved: kent@sparky.sterling.com
  8. Message-ID: <2l0hbf$4v0@sparky.sterling.com>
  9. X-Md4-Signature: 27373af1352100af2bee350ed2456bf3
  10.  
  11. Submitted-by: hm@hcshh.hcs.de (Hellmuth Michaelis)
  12. Posting-number: Volume 41, Issue 141
  13. Archive-name: pcvt/part02
  14. Environment: 386BSD, NETBSD, FREEBSD
  15.  
  16. #! /bin/sh
  17. # This is a shell archive.  Remove anything before this line, then feed it
  18. # into a shell via "sh file" or similar.  To overwrite existing files,
  19. # type "sh file -c".
  20. # Contents:  pcvt/pcvt_kbd.c
  21. # Wrapped by kent@sparky on Tue Mar  1 16:46:17 1994
  22. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
  23. echo If this archive is complete, you will see the following message:
  24. echo '          "shar: End of archive 2 (of 13)."'
  25. if test -f 'pcvt/pcvt_kbd.c' -a "${1}" != "-c" ; then 
  26.   echo shar: Will not clobber existing file \"'pcvt/pcvt_kbd.c'\"
  27. else
  28.   echo shar: Extracting \"'pcvt/pcvt_kbd.c'\" \(85774 characters\)
  29.   sed "s/^X//" >'pcvt/pcvt_kbd.c' <<'END_OF_FILE'
  30. X/*
  31. X * Copyright (c) 1992,1993,1994 Hellmuth Michaelis, Brian Dunford-Shore,
  32. X *                              Joerg Wunsch and Holger Veit.
  33. X *
  34. X * All rights reserved.
  35. X *
  36. X * This code is derived from software contributed to Berkeley by
  37. X * William Jolitz and Don Ahn.
  38. X *
  39. X * This code is derived from software contributed to 386BSD by
  40. X * Holger Veit.
  41. X *
  42. X * Redistribution and use in source and binary forms, with or without
  43. X * modification, are permitted provided that the following conditions
  44. X * are met:
  45. X * 1. Redistributions of source code must retain the above copyright
  46. X *    notice, this list of conditions and the following disclaimer.
  47. X * 2. Redistributions in binary form must reproduce the above copyright
  48. X *    notice, this list of conditions and the following disclaimer in the
  49. X *    documentation and/or other materials provided with the distribution.
  50. X * 3. All advertising materials mentioning features or use of this software
  51. X *    must display the following acknowledgement:
  52. X *    This product includes software developed by Hellmuth Michaelis,
  53. X *    Brian Dunford-Shore and Joerg Wunsch.
  54. X * 4. The name authors may not be used to endorse or promote products
  55. X *    derived from this software without specific prior written permission.
  56. X *
  57. X * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
  58. X * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  59. X * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  60. X * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  61. X * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  62. X * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  63. X * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  64. X * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  65. X * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  66. X * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  67. X *
  68. X *
  69. X * @(#)pcvt_kbd.c, 3.00, Last Edit-Date: [Sun Feb 27 17:04:53 1994]
  70. X *
  71. X */
  72. X
  73. X/*---------------------------------------------------------------------------*
  74. X *
  75. X *    pcvt_kbd.c    VT220 Driver Keyboard Interface Code
  76. X *    ----------------------------------------------------
  77. X *    -jw    include rather primitive X stuff
  78. X *    -hm    patch from Gordon L. Burditt to fix repeat of CAPS LOCK etc.
  79. X *    -hm    netbsd: no file ddb.h available
  80. X *    -hm    new keyboard routines from netbsd-current
  81. X *    -hm    re-introduced keyboard id detection
  82. X *    -hm    keyboard id debugging, hp sends special id ...
  83. X *    -jw    keyboard overlay table now malloc'ed, SCROLL_SLEEP
  84. X *    -hm    keyboard initialization for ddb activists ...
  85. X *    -hm    keyboard security no longer ignored
  86. X *    -hm    reset cursor when soft reset fkey
  87. X *    -jw    USL VT compatibility
  88. X *    -hm    CTRL-ALT-Fx switches to virtual terminal x
  89. X *    -hm    added totalscreen checking, removed bug in vt220-like kbd part
  90. X *    -hm    SCROLL_SLEEPing works
  91. X *    -hm    kbd scancode sets 1 and 2 (patch from Onno van der Linden)
  92. X *    -hm    printscreen key fix
  93. X *    -jw    mouse emulation mode
  94. X *    -jw/hm    all ifdef's converted to if's 
  95. X *    -jw    cleaned up the key prefix recognition
  96. X *    -jw    included PCVT_META_ESC
  97. X *    -hm    removed typo in cfkey11() (pillhuhns have good eyes ..)
  98. X *    -hm    Debugger("kbd") patch from Joerg for FreeBSD
  99. X *    -hm    bugfix, ALT-F12 steps over screen 0
  100. X *    -hm    vgapage() -> do_vgapage(), checks if in scrolling
  101. X *    -hm    ------------ Release 3.00 --------------
  102. X *
  103. X *---------------------------------------------------------------------------*/
  104. X
  105. X#include "vt.h"
  106. X#if NVT > 0
  107. X
  108. X#include "pcvt_hdr.h"        /* global include */
  109. X
  110. Xstatic void fkey1(void), fkey2(void),  fkey3(void),  fkey4(void);
  111. Xstatic void fkey5(void), fkey6(void),  fkey7(void),  fkey8(void);
  112. Xstatic void fkey9(void), fkey10(void), fkey11(void), fkey12(void);
  113. X
  114. Xstatic void sfkey1(void), sfkey2(void),  sfkey3(void),  sfkey4(void);
  115. Xstatic void sfkey5(void), sfkey6(void),  sfkey7(void),  sfkey8(void);
  116. Xstatic void sfkey9(void), sfkey10(void), sfkey11(void), sfkey12(void);
  117. X
  118. Xstatic void cfkey1(void), cfkey2(void),  cfkey3(void),  cfkey4(void);
  119. Xstatic void cfkey5(void), cfkey6(void),  cfkey7(void),  cfkey8(void);
  120. Xstatic void cfkey9(void), cfkey10(void), cfkey11(void), cfkey12(void);
  121. X
  122. Xstatic void    doreset ( void );
  123. Xstatic void    ovlinit ( int force );
  124. Xstatic void     settpmrate ( int rate );
  125. Xstatic void    setlockkeys ( int snc );
  126. Xstatic int    kbc_8042cmd ( int val );
  127. Xstatic int    getokeydef ( unsigned key, struct kbd_ovlkey *thisdef );
  128. Xstatic int     getckeydef ( unsigned key, struct kbd_ovlkey *thisdef );
  129. Xstatic int    rmkeydef ( int key );
  130. Xstatic int    setkeydef ( struct kbd_ovlkey *data );
  131. Xstatic u_char *    xlatkey2ascii( U_short key );
  132. X
  133. Xstatic int    ledstate  = 0;    /* keyboard led's */
  134. Xstatic int    tpmrate   = KBD_TPD500|KBD_TPM100;
  135. Xstatic u_char    altkpflag = 0;
  136. Xstatic u_short    altkpval  = 0;
  137. X
  138. X#if PCVT_SHOWKEYS
  139. Xu_char rawkeybuf[80];    
  140. X#endif    /* PCVT_SHOWKEYS */
  141. X
  142. X/*---------------------------------------------------------------------------*
  143. X *    function bound to control function key 12
  144. X *---------------------------------------------------------------------------*/
  145. Xstatic void
  146. Xdo_vgapage(int page)
  147. X{
  148. X    if(critical_scroll)
  149. X        switch_page = page;
  150. X    else
  151. X        vgapage(page);
  152. X}
  153. X
  154. X/*---------------------------------------------------------------------------*
  155. X *    this is one sub-entry for the table. the type can be either
  156. X *    "pointer to a string" or "pointer to a function"
  157. X *---------------------------------------------------------------------------*/
  158. Xtypedef struct
  159. X{
  160. X    u_char subtype;            /* subtype, string or function */
  161. X    union what
  162. X    {
  163. X        u_char *string;        /* ptr to string, null terminated */
  164. X        void (*func)();        /* ptr to function */
  165. X    } what;
  166. X} entry;
  167. X
  168. X/*---------------------------------------------------------------------------*
  169. X *    this is the "outer" table 
  170. X *---------------------------------------------------------------------------*/
  171. Xtypedef struct
  172. X{
  173. X    u_short    type;            /* type of key */
  174. X    u_short    ovlindex;        /* -hv- index into overload table */
  175. X    entry     unshift;        /* normal default codes/funcs */
  176. X    entry    shift;            /* shifted default codes/funcs */
  177. X    entry     ctrl;            /* control default codes/funcs */
  178. X} Keycap_def;
  179. X
  180. X#define IDX0        0    /* default indexvalue into ovl table */
  181. X
  182. X#define STR        KBD_SUBT_STR    /* subtype = ptr to string */
  183. X#define FNC        KBD_SUBT_FNC    /* subtype = ptr to function */
  184. X
  185. X#define CODE_SIZE    5
  186. X
  187. X/*---------------------------------------------------------------------------*
  188. X * the overlaytable table is a static fixed size scratchpad where all the
  189. X * overloaded definitions are stored.
  190. X * an entry consists of a short (holding the new type attribute) and
  191. X * four entries for a new keydefinition.
  192. X *---------------------------------------------------------------------------*/
  193. X
  194. X#define OVLTBL_SIZE    64        /* 64 keys can be overloaded */
  195. X
  196. X#define Ovl_tbl struct kbd_ovlkey
  197. X
  198. Xstatic Ovl_tbl *ovltbl;            /* the table itself */
  199. X
  200. Xstatic ovlinitflag = 0;            /* the init flag for the table */
  201. X
  202. X/*
  203. X * key codes >= 128 denote "virtual" shift/control
  204. X * They are resolved before any keymapping is handled
  205. X */
  206. X
  207. X#if PCVT_SCANSET == 2
  208. Xstatic u_char scantokey[] = {
  209. X/*      -0- -1- -2- -3- -4- -5- -6- -7-    This layout is valid for US only */
  210. X/*00*/   0,120,  0,116,114,112,113,123,  /* ??  F9  ??  F5  F3  F1  F2  F12 */
  211. X/*08*/   0,121,119,117,115, 16,  1,  0,  /* ??  F10 F8  F6  F4  TAB `   ??  */
  212. X/*10*/   0, 60, 44,  0, 58, 17,  2,  0,  /* ??  ALl SHl ??  CTl Q   1   ??  */
  213. X/*18*/   0,  0, 46, 32, 31, 18,  3,  0,  /* ??  Z   S   A   W   2   ??  ??  */
  214. X/*20*/   0, 48, 47, 33, 19,  5,  4,  0,  /* ??  C   X   D   E   4   3   ??  */
  215. X/*28*/   0, 61, 49, 34, 21, 20,  6,  0,  /* ??  SP  V   F   T   R   5   ??  */
  216. X/*30*/   0, 51, 50, 36, 35, 22,  7,  0,  /* ??  N   B   H   G   Y   6   ??  */
  217. X/*38*/   0,  0, 52, 37, 23,  8,  9,  0,  /* ??  ??  M   J   U   7   8   ??  */
  218. X/*40*/   0, 53, 38, 24, 25, 11, 10,  0,  /* ??  ,   K   I   O   0   9   ??  */
  219. X/*48*/   0, 54, 55, 39, 40, 26, 12,  0,  /* ??  .   /   L   ;   P   -   ??  */
  220. X/*50*/   0,  0, 41,  0, 27, 13,  0,  0,  /* ??  ??  "   ??  [   =   ??  ??  */
  221. X/*58*/  30, 57, 43, 28,  0, 29,  0,  0,  /* CAP SHr ENT ]   ??  \   ??  ??  */
  222. X/*60*/   0, 45,  0,  0,  0,  0, 15,  0,  /* ??  NL1 ??  ??  ??  ??  BS  ??  */
  223. X/*68*/   0, 93,  0, 92, 91,  0,  0,  0,  /* ??  KP1 ??  KP4 KP7 ??  ??  ??  */
  224. X/*70*/  99,104, 98, 97,102, 96,110, 90,  /* KP0 KP. KP2 KP5 KP6 KP8 ESC NUM */
  225. X/*78*/ 122,106,103,105,100,101,125,  0,  /* F11 KP+ KP3 KP- KP* KP9 LOC ??  */
  226. X/*80*/   0,  0,  0,118,127               /* ??  ??  ??  F7 SyRQ */
  227. X};
  228. X
  229. Xstatic u_char extscantokey[] = {
  230. X/*      -0- -1- -2- -3- -4- -5- -6- -7-    This layout is valid for US only */
  231. X/*00*/   0,120,  0,116,114,112,113,123,  /* ??  F9  ??  F5  F3  F1  F2  F12 */
  232. X/*08*/   0,121,119,117,115, 16,  1,  0,  /* ??  F10 F8  F6  F4  TAB `   ??  */
  233. X/*10*/   0, 62,128,  0, 58, 17,  2,  0,  /* ??  ALr vSh ??  CTr Q   1   ??  */
  234. X/*18*/   0,  0, 46, 32, 31, 18,  3,  0,  /* ??  Z   S   A   W   2   ??  ??  */
  235. X/*20*/   0, 48, 47, 33, 19,  5,  4,  0,  /* ??  C   X   D   E   4   3   ??  */
  236. X/*28*/   0, 61, 49, 34, 21, 20,  6,  0,  /* ??  SP  V   F   T   R   5   ??  */
  237. X/*30*/   0, 51, 50, 36, 35, 22,  7,  0,  /* ??  N   B   H   G   Y   6   ??  */
  238. X/*38*/   0,  0, 52, 37, 23,  8,  9,  0,  /* ??  ??  M   J   U   7   8   ??  */
  239. X/*40*/   0, 53, 38, 24, 25, 11, 10,  0,  /* ??  ,   K   I   O   0   9   ??  */
  240. X/*48*/   0, 54, 95, 39, 40, 26, 12,  0,  /* ??  .   KP/ L   ;   P   -   ??  */
  241. X/*50*/   0,  0, 41,  0, 27, 13,  0,  0,  /* ??  ??  "   ??  [   =   ??  ??  */
  242. X/*58*/  30, 57,108, 28,  0, 29,  0,  0,  /* CAP  SHr KPE ]   ??  \  ??  ??  */
  243. X/*60*/   0, 45,  0,  0,  0,  0, 15,  0,  /* ??  NL1 ??  ??  ??  ??  BS  ??  */
  244. X/*68*/   0, 81,  0, 79, 80,  0,  0,  0,  /* ??  END ??  LA  HOM ??  ??  ??  */
  245. X/*70*/  75, 76, 84, 97, 89, 83,110, 90,  /* INS DEL DA  KP5 RA  UA  ESC NUM */
  246. X/*78*/ 122,106, 86,105,124, 85,126,  0,  /* F11 KP+ PD  KP- PSc PU  Brk ??  */
  247. X/*80*/   0,  0,  0,118,127               /* ??  ??  ??  F7 SysRq */
  248. X};
  249. X
  250. X#else    /* PCVT_SCANSET != 2 */
  251. X
  252. Xstatic u_char scantokey[] = {
  253. X/*       -0- -1- -2- -3- -4- -5- -6- -7-    This layout is valid for US only */
  254. X/*00*/    0,110,  2,  3,  4,  5,  6,  7,  /* ??  ESC 1   2   3   4   5   6   */
  255. X/*08*/    8,  9, 10, 11, 12, 13, 15, 16,  /* 7   8   9   0   -   =   BS  TAB */
  256. X/*10*/   17, 18, 19, 20, 21, 22, 23, 24,  /* Q   W   E   R   T   Y   U   I   */
  257. X/*18*/   25, 26, 27, 28, 43, 58, 31, 32,  /* O   P   [   ]   ENT CTl A   S   */
  258. X/*20*/   33, 34, 35, 36, 37, 38, 39, 40,  /* D   F   G   H   J   K   L   ;   */
  259. X/*28*/   41,  1, 44, 29, 46, 47, 48, 49,  /* '   `   SHl \   Z   X   C   V   */
  260. X/*30*/   50, 51, 52, 53, 54, 55, 57,100,  /* B   N   M   ,   .   /   SHr KP* */
  261. X/*38*/   60, 61, 30,112,113,114,115,116,  /* ALl SP  CAP F1  F2  F3  F4  F5  */
  262. X/*40*/  117,118,119,120,121, 90,125, 91,  /* F6  F7  F8  F9  F10 NUM LOC KP7 */
  263. X/*48*/   96,101,105, 92, 97,102,106, 93,  /* KP8 KP9 KP- KP4 KP5 KP6 KP+ KP1 */
  264. X/*50*/   98,103, 99,104,127,  0, 45,122,  /* KP2 KP3 KP0 KP. SyRq??  NL1 F11 */
  265. X/*58*/  123                               /* F12 */
  266. X};
  267. X
  268. Xstatic u_char extscantokey[] = {
  269. X/*       -0- -1- -2- -3- -4- -5- -6- -7-    This layout is valid for US only */
  270. X/*00*/    0,110,  2,  3,  4,  5,  6,  7,  /* ??  ESC 1   2   3   4   5   6   */
  271. X/*08*/    8,  9, 10, 11, 12, 13, 15, 16,  /* 7   8   9   0   -   =   BS  TAB */
  272. X/*10*/   17, 18, 19, 20, 21, 22, 23, 24,  /* Q   W   E   R   T   Y   U   I   */
  273. X/*18*/   25, 26, 27, 28,108, 58, 31, 32,  /* O   P   [   ]   KPE CTr A   S   */
  274. X/*20*/   33, 34, 35, 36, 37, 38, 39, 40,  /* D   F   G   H   J   K   L   ;   */
  275. X/*28*/   41,  1,128, 29, 46, 47, 48, 49,  /* '   `   vSh \   Z   X   C   V   */
  276. X/*30*/   50, 51, 52, 53, 54, 95, 57,124,  /* B   N   M   ,   .   KP/ SHr KP* */
  277. X/*38*/   62, 61, 30,112,113,114,115,116,  /* ALr SP  CAP F1  F2  F3  F4  F5  */
  278. X/*40*/  117,118,119,120,121, 90,126, 80,  /* F6  F7  F8  F9  F10 NUM Brk HOM */
  279. X/*48*/   83, 85,105, 79, 97, 89,106, 81,  /* UA  PU  KP- LA  KP5 RA  KP+ END */
  280. X/*50*/   84, 86, 75, 76,  0,  0, 45,122,  /* DA  PD  INS DEL ??  ??  NL1 F11 */
  281. X/*58*/  123,                              /* F12 */
  282. X};
  283. X#endif    /* PCVT_SCANSET == 2 */
  284. X
  285. Xstatic Keycap_def    key2ascii[] =
  286. X{
  287. X
  288. X/* define some shorthands to make the table (almost) fit into 80 columns */
  289. X#define C (u_char *)
  290. X#define V (void *)
  291. X#define S STR
  292. X#define F FNC
  293. X#define I IDX0
  294. X
  295. X/* DONT EVER OVERLOAD KEY 0, THIS IS A KEY THAT MUSTN'T EXIST */
  296. X
  297. X/*      type   index   unshift        shift           ctrl         */
  298. X/*      ---------------------------------------------------------- */
  299. X/*  0*/ KBD_NONE,  I, {S,C "df"},    {S,C ""},      {S,C ""},
  300. X/*  1*/ KBD_ASCII, I, {S,C "`"},     {S,C "~"},     {S,C "`"},
  301. X/*  2*/ KBD_ASCII, I, {S,C "1"},     {S,C "!"},     {S,C "1"},
  302. X/*  3*/ KBD_ASCII, I, {S,C "2"},     {S,C "@"},     {S,C "\000"},   
  303. X/*  4*/ KBD_ASCII, I, {S,C "3"},     {S,C "#"},     {S,C "3"},      
  304. X/*  5*/ KBD_ASCII, I, {S,C "4"},     {S,C "$"},     {S,C "4"},
  305. X/*  6*/ KBD_ASCII, I, {S,C "5"},     {S,C "%"},     {S,C "5"},
  306. X/*  7*/ KBD_ASCII, I, {S,C "6"},     {S,C "^"},     {S,C "\036"},
  307. X/*  8*/ KBD_ASCII, I, {S,C "7"},     {S,C "&"},     {S,C "7"},
  308. X/*  9*/ KBD_ASCII, I, {S,C "8"},     {S,C "*"},     {S,C "9"},
  309. X/* 10*/ KBD_ASCII, I, {S,C "9"},     {S,C "("},     {S,C "9"},
  310. X/* 11*/ KBD_ASCII, I, {S,C "0"},     {S,C ")"},     {S,C "0"},
  311. X/* 12*/ KBD_ASCII, I, {S,C "-"},     {S,C "_"},     {S,C "\037"},
  312. X/* 13*/ KBD_ASCII, I, {S,C "="},     {S,C "+"},     {S,C "="},
  313. X/* 14*/ KBD_NONE,  I, {S,C ""},      {S,C ""},      {S,C ""},
  314. X/* 15*/ KBD_ASCII, I, {S,C "\177"},  {S,C "\010"},  {S,C "\177"}, /* BS */
  315. X/* 16*/ KBD_ASCII, I, {S,C "\t"},    {S,C "\t"},    {S,C "\t"},   /* TAB */
  316. X/* 17*/ KBD_ASCII, I, {S,C "q"},     {S,C "Q"},     {S,C "\021"},
  317. X/* 18*/ KBD_ASCII, I, {S,C "w"},     {S,C "W"},     {S,C "\027"},
  318. X/* 19*/ KBD_ASCII, I, {S,C "e"},     {S,C "E"},     {S,C "\005"},
  319. X/* 20*/ KBD_ASCII, I, {S,C "r"},     {S,C "R"},     {S,C "\022"},
  320. X/* 21*/ KBD_ASCII, I, {S,C "t"},     {S,C "T"},     {S,C "\024"},
  321. X/* 22*/ KBD_ASCII, I, {S,C "y"},     {S,C "Y"},     {S,C "\031"},
  322. X/* 23*/ KBD_ASCII, I, {S,C "u"},     {S,C "U"},     {S,C "\025"},
  323. X/* 24*/ KBD_ASCII, I, {S,C "i"},     {S,C "I"},     {S,C "\011"},
  324. X/* 25*/ KBD_ASCII, I, {S,C "o"},     {S,C "O"},     {S,C "\017"},
  325. X/* 26*/ KBD_ASCII, I, {S,C "p"},     {S,C "P"},     {S,C "\020"},
  326. X/* 27*/ KBD_ASCII, I, {S,C "["},     {S,C "{"},     {S,C "\033"},
  327. X/* 28*/ KBD_ASCII, I, {S,C "]"},     {S,C "}"},     {S,C "\035"},
  328. X/* 29*/ KBD_ASCII, I, {S,C "\\"},    {S,C "|"},     {S,C "\034"},
  329. X/* 30*/ KBD_CAPS,  I, {S,C ""},      {S,C ""},      {S,C ""},
  330. X/* 31*/ KBD_ASCII, I, {S,C "a"},     {S,C "A"},     {S,C "\001"},
  331. X/* 32*/ KBD_ASCII, I, {S,C "s"},     {S,C "S"},     {S,C "\023"},
  332. X/* 33*/ KBD_ASCII, I, {S,C "d"},     {S,C "D"},     {S,C "\004"},
  333. X/* 34*/ KBD_ASCII, I, {S,C "f"},     {S,C "F"},     {S,C "\006"},
  334. X/* 35*/ KBD_ASCII, I, {S,C "g"},     {S,C "G"},     {S,C "\007"},
  335. X/* 36*/ KBD_ASCII, I, {S,C "h"},     {S,C "H"},     {S,C "\010"},
  336. X/* 37*/ KBD_ASCII, I, {S,C "j"},     {S,C "J"},     {S,C "\n"},
  337. X/* 38*/ KBD_ASCII, I, {S,C "k"},     {S,C "K"},     {S,C "\013"},
  338. X/* 39*/ KBD_ASCII, I, {S,C "l"},     {S,C "L"},     {S,C "\014"},
  339. X/* 40*/ KBD_ASCII, I, {S,C ";"},     {S,C ":"},     {S,C ";"},
  340. X/* 41*/ KBD_ASCII, I, {S,C "'"},     {S,C "\""},    {S,C "'"},
  341. X/* 42*/ KBD_ASCII, I, {S,C "\\"},    {S,C "|"},     {S,C "\034"}, /* special */
  342. X/* 43*/ KBD_RETURN,I, {S,C "\r"},    {S,C "\r"},    {S,C "\r"},    /* RETURN */
  343. X/* 44*/ KBD_SHIFT, I, {S,C ""},      {S,C ""},      {S,C ""},  /* SHIFT left */
  344. X/* 45*/ KBD_ASCII, I, {S,C "<"},     {S,C ">"},     {S,C ""},
  345. X/* 46*/ KBD_ASCII, I, {S,C "z"},     {S,C "Z"},     {S,C "\032"},
  346. X/* 47*/ KBD_ASCII, I, {S,C "x"},     {S,C "X"},     {S,C "\030"},
  347. X/* 48*/ KBD_ASCII, I, {S,C "c"},     {S,C "C"},     {S,C "\003"},
  348. X/* 49*/ KBD_ASCII, I, {S,C "v"},     {S,C "V"},     {S,C "\026"},
  349. X/* 50*/ KBD_ASCII, I, {S,C "b"},     {S,C "B"},     {S,C "\002"},
  350. X/* 51*/ KBD_ASCII, I, {S,C "n"},     {S,C "N"},     {S,C "\016"},
  351. X/* 52*/ KBD_ASCII, I, {S,C "m"},     {S,C "M"},     {S,C "\r"},
  352. X/* 53*/ KBD_ASCII, I, {S,C ","},     {S,C "<"},     {S,C ","},
  353. X/* 54*/ KBD_ASCII, I, {S,C "."},     {S,C ">"},     {S,C "."},
  354. X/* 55*/ KBD_ASCII, I, {S,C "/"},     {S,C "?"},     {S,C "/"},
  355. X/* 56*/ KBD_NONE,  I, {S,C ""},      {S,C ""},      {S,C ""},
  356. X/* 57*/ KBD_SHIFT, I, {S,C ""},      {S,C ""},      {S,C ""}, /* SHIFT right */
  357. X/* 58*/ KBD_CTL,   I, {S,C ""},      {S,C ""},      {S,C ""},    /* CTL left */
  358. X/* 59*/ KBD_ASCII, I, {S,C ""},      {S,C ""},      {S,C ""}, 
  359. X/* 60*/ KBD_META,  I, {S,C ""},      {S,C ""},      {S,C ""},    /* ALT left */
  360. X#if !PCVT_NULLCHARS                          
  361. X/* 61*/ KBD_ASCII, I, {S,C " "},     {S,C " "},     {S,C " "},      /* SPACE */
  362. X#else
  363. X/* 61*/ KBD_ASCII, I,   {S,C " "},   {S,C " "},     {S,C "\000"},   /* SPACE */
  364. X#endif /* PCVT_NULLCHARS */
  365. X/* 62*/ KBD_META,  I, {S,C ""},      {S,C ""},      {S,C ""},   /* ALT right */
  366. X/* 63*/ KBD_ASCII, I, {S,C ""},      {S,C ""},      {S,C ""},
  367. X/* 64*/ KBD_CTL,   I, {S,C ""},      {S,C ""},      {S,C ""},   /* CTL right */
  368. X/* 65*/ KBD_NONE,  I, {S,C ""},      {S,C ""},      {S,C ""},
  369. X/* 66*/ KBD_NONE,  I, {S,C ""},      {S,C ""},      {S,C ""},
  370. X/* 67*/ KBD_NONE,  I, {S,C ""},      {S,C ""},      {S,C ""},
  371. X/* 68*/ KBD_NONE,  I, {S,C ""},      {S,C ""},      {S,C ""},
  372. X/* 69*/ KBD_NONE,  I, {S,C ""},      {S,C ""},      {S,C ""},
  373. X/* 70*/ KBD_NONE,  I, {S,C ""},      {S,C ""},      {S,C ""},
  374. X/* 71*/ KBD_NONE,  I, {S,C ""},      {S,C ""},      {S,C ""},
  375. X/* 72*/ KBD_NONE,  I, {S,C ""},      {S,C ""},      {S,C ""},
  376. X/* 73*/ KBD_NONE,  I, {S,C ""},      {S,C ""},      {S,C ""},
  377. X/* 74*/ KBD_NONE,  I, {S,C ""},      {S,C ""},      {S,C ""},
  378. X/* 75*/ KBD_FUNC,  I, {S,C "\033[2~"},{S,C "\033[2~"},{S,C "\033[2~"},/* INS */
  379. X/* 76*/ KBD_FUNC,  I, {S,C "\033[3~"},{S,C "\033[3~"},{S,C "\033[3~"},/* DEL */
  380. X/* 77*/ KBD_NONE,  I, {S,C ""},      {S,C ""},      {S,C ""},
  381. X/* 78*/ KBD_NONE,  I, {S,C ""},      {S,C ""},      {S,C ""},
  382. X/* 79*/ KBD_CURSOR,I, {S,C "\033[D"},{S,C "\033OD"},{S,C "\033[D"}, /* CU <- */
  383. X/* 80*/ KBD_FUNC,  I, {S,C "\033[1~"},{S,C "\033[1~"},{S,C "\033[1~"},/* HOME = FIND*/
  384. X/* 81*/ KBD_FUNC,  I, {S,C "\033[4~"},{S,C "\033[4~"},{S,C "\033[4~"},/* END = SELECT */
  385. X/* 82*/ KBD_NONE,  I, {S,C ""},      {S,C ""},      {S,C ""},
  386. X/* 83*/ KBD_CURSOR,I, {S,C "\033[A"},{S,C "\033OA"},{S,C "\033[A"}, /* CU ^ */
  387. X/* 84*/ KBD_CURSOR,I, {S,C "\033[B"},{S,C "\033OB"},{S,C "\033[B"}, /* CU v */
  388. X/* 85*/ KBD_FUNC,  I, {S,C "\033[5~"},{S,C "\033[5~"},{S,C "\033[5~"},/*PG UP*/
  389. X/* 86*/ KBD_FUNC,  I, {S,C "\033[6~"},{S,C "\033[6~"},{S,C "\033[6~"},/*PG DN*/
  390. X/* 87*/ KBD_NONE,  I, {S,C ""},      {S,C ""},      {S,C ""},
  391. X/* 88*/ KBD_NONE,  I, {S,C ""},      {S,C ""},      {S,C ""},
  392. X/* 89*/ KBD_CURSOR,I, {S,C "\033[C"},{S,C "\033OC"},{S,C "\033[C"}, /* CU -> */
  393. X/* 90*/ KBD_NUM,   I, {S,C ""},      {S,C ""},      {S,C ""},
  394. X/* 91*/ KBD_KP,    I, {S,C "7"},     {S,C "\033Ow"},{S,C "7"},
  395. X/* 92*/ KBD_KP,    I, {S,C "4"},     {S,C "\033Ot"},{S,C "4"},
  396. X/* 93*/ KBD_KP,    I, {S,C "1"},     {S,C "\033Oq"},{S,C "1"},
  397. X/* 94*/ KBD_NONE,  I, {S,C ""},      {S,C ""},      {S,C ""},
  398. X/* 95*/ KBD_KP,    I, {S,C "/"},     {S,C "/"},     {S,C "/"},
  399. X/* 96*/ KBD_KP,    I, {S,C "8"},     {S,C "\033Ox"},{S,C "8"},
  400. X/* 97*/ KBD_KP,    I, {S,C "5"},     {S,C "\033Ou"},{S,C "5"},
  401. X/* 98*/ KBD_KP,    I, {S,C "2"},     {S,C "\033Or"},{S,C "2"},
  402. X/* 99*/ KBD_KP,    I, {S,C "0"},     {S,C "\033Op"},{S,C "0"},
  403. X/*100*/ KBD_KP,    I, {S,C "*"},     {S,C "*"},     {S,C "*"},
  404. X/*101*/ KBD_KP,    I, {S,C "9"},     {S,C "\033Oy"},{S,C "9"},
  405. X/*102*/ KBD_KP,    I, {S,C "6"},     {S,C "\033Ov"},{S,C "6"},
  406. X/*103*/ KBD_KP,    I, {S,C "3"},     {S,C "\033Os"},{S,C "3"},
  407. X/*104*/ KBD_KP,    I, {S,C "."},     {S,C "\033On"},{S,C "."},
  408. X/*105*/ KBD_KP,    I, {S,C "-"},     {S,C "\033Om"},{S,C "-"},
  409. X/*106*/ KBD_KP,    I, {S,C "+"},     {S,C "+"},     {S,C "+"},
  410. X/*107*/ KBD_NONE,  I, {S,C ""},      {S,C ""},      {S,C ""},
  411. X/*108*/ KBD_RETURN,I, {S,C "\r"},    {S,C "\033OM"},{S,C "\r"},  /* KP ENTER */
  412. X/*109*/ KBD_NONE,  I, {S,C ""},      {S,C ""},      {S,C ""},       
  413. X/*110*/ KBD_ASCII, I, {S,C "\033"},  {S,C "\033"},  {S,C "\033"},
  414. X/*111*/ KBD_NONE,  I, {S,C ""},      {S,C ""},      {S,C ""},
  415. X/*112*/ KBD_FUNC,  I, {F,V fkey1},   {F,V sfkey1},  {F,V cfkey1},  /* F1 */
  416. X/*113*/ KBD_FUNC,  I, {F,V fkey2},   {F,V sfkey2},  {F,V cfkey2},  /* F2 */
  417. X/*114*/ KBD_FUNC,  I, {F,V fkey3},   {F,V sfkey3},  {F,V cfkey3},  /* F3 */
  418. X/*115*/ KBD_FUNC,  I, {F,V fkey4},   {F,V sfkey4},  {F,V cfkey4},  /* F4 */
  419. X/*116*/ KBD_FUNC,  I, {F,V fkey5},   {F,V sfkey5},  {F,V cfkey5},  /* F5 */
  420. X/*117*/ KBD_FUNC,  I, {F,V fkey6},   {F,V sfkey6},  {F,V cfkey6},  /* F6 */
  421. X/*118*/ KBD_FUNC,  I, {F,V fkey7},   {F,V sfkey7},  {F,V cfkey7},  /* F7 */
  422. X/*119*/ KBD_FUNC,  I, {F,V fkey8},   {F,V sfkey8},  {F,V cfkey8},  /* F8 */
  423. X/*120*/ KBD_FUNC,  I, {F,V fkey9},   {F,V sfkey9},  {F,V cfkey9},  /* F9 */
  424. X/*121*/ KBD_FUNC,  I, {F,V fkey10},  {F,V sfkey10}, {F,V cfkey10}, /* F10 */
  425. X/*122*/ KBD_FUNC,  I, {F,V fkey11},  {F,V sfkey11}, {F,V cfkey11}, /* F11 */
  426. X/*123*/ KBD_FUNC,  I, {F,V fkey12},  {F,V sfkey12}, {F,V cfkey12}, /* F12 */
  427. X/*124*/ KBD_KP,    I, {S,C ""},      {S,C ""},      {S,C ""},
  428. X/*125*/ KBD_SCROLL,I, {S,C ""},      {S,C ""},      {S,C ""},
  429. X/*126*/ KBD_BREAK, I, {S,C ""},      {S,C ""},      {S,C ""},
  430. X/*127*/ KBD_FUNC,  I, {S,C ""},      {S,C ""},      {S,C ""},      /* SysRq */
  431. X
  432. X#undef C
  433. X#undef V
  434. X#undef S
  435. X#undef F
  436. X#undef I
  437. X};
  438. Xstatic short    keypad2num[] = {
  439. X    7, 4, 1, -1, -1, 8, 5, 2, 0, -1, 9, 6, 3, -1, -1, -1, -1
  440. X};
  441. X
  442. X#if PCVT_USL_VT_COMPAT
  443. X
  444. X#define N_KEYNUMS 128
  445. X
  446. X/*
  447. X * this is the reverse mapping from keynumbers to scanset 1 codes
  448. X * it is used to emulate the SysV-style GIO_KEYMAP ioctl cmd
  449. X */
  450. X
  451. Xstatic u_char key2scan1[N_KEYNUMS] = {
  452. X       0,0x29,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09, /*   0 */
  453. X    0x0a,0x0b,0x0c,0x0d,   0,0x0e,0x0f,0x10,0x11,0x12, /*  10 */
  454. X    0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x2b, /*  20 */
  455. X    0x3a,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26, /*  30 */
  456. X    0x27,0x28,   0,0x1c,0x2a,0x56,0x2c,0x2d,0x2e,0x2f, /*  40 */
  457. X    0x30,0x31,0x32,0x33,0x34,0x35,0x56,0x36,0x1d,   0, /*  50 */
  458. X    0x38,0x39,   0,   0,   0,   0,   0,   0,   0,   0, /*  60 */
  459. X       0,   0,   0,   0,   0,   0,   0,   0,   0,   0, /*  70 */
  460. X       0,   0,   0,   0,   0,   0,   0,   0,   0,   0, /*  80 */
  461. X    0x45,0x47,0x4b,0x4f,   0,   0,0x48,0x4c,0x50,0x52, /*  90 */
  462. X    0x37,0x49,0x4d,0x51,0x53,0x4a,0x4e,   0,   0,   0, /* 100 */
  463. X    0x01,   0,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x42, /* 110 */
  464. X    0x43,0x44,0x57,0x58,   0,0x46,   0,0x54           /* 120 */
  465. X};
  466. X
  467. X/*
  468. X * SysV is brain-dead enough to stick on the IBM code page 437. So we
  469. X * have to translate our keymapping into IBM 437 (possibly losing keys),
  470. X * in order to have the X server convert it back into ISO8859.1
  471. X */
  472. X
  473. X/* NB: this table only contains the mapping for codes >= 128 */
  474. X
  475. Xstatic u_char iso2ibm437[] =
  476. X{
  477. X       0,     0,     0,     0,     0,     0,     0,     0,
  478. X       0,     0,     0,     0,     0,     0,     0,     0,
  479. X       0,     0,     0,     0,     0,     0,     0,     0,
  480. X       0,     0,     0,     0,     0,     0,     0,     0,
  481. X    0xff,  0xad,  0x9b,  0x9c,     0,  0x9d,     0,  0x40,
  482. X    0x6f,  0x63,  0x61,  0xae,     0,     0,     0,     0,
  483. X    0xf8,  0xf1,  0xfd,  0x33,     0,  0xe6,     0,  0xfa,
  484. X       0,  0x31,  0x6f,  0xaf,  0xac,  0xab,     0,  0xa8,
  485. X    0x41,  0x41,  0x41,  0x41,  0x8e,  0x8f,  0x92,  0x80,
  486. X    0x45,  0x90,  0x45,  0x45,  0x49,  0x49,  0x49,  0x49,
  487. X    0x81,  0xa5,  0x4f,  0x4f,  0x4f,  0x4f,  0x99,  0x4f,
  488. X    0x4f,  0x55,  0x55,  0x55,  0x9a,  0x59,     0,  0xe1,
  489. X    0x85,  0xa0,  0x83,  0x61,  0x84,  0x86,  0x91,  0x87,
  490. X    0x8a,  0x82,  0x88,  0x89,  0x8d,  0xa1,  0x8c,  0x8b,
  491. X       0,  0xa4,  0x95,  0xa2,  0x93,  0x6f,  0x94,  0x6f,
  492. X    0x6f,  0x97,  0xa3,  0x96,  0x81,  0x98,     0,     0
  493. X};
  494. X
  495. X#endif /* PCVT_USL_VT_COMPAT */
  496. X
  497. X
  498. X/*---------------------------------------------------------------------------*
  499. X *    update keyboard led's    
  500. X *---------------------------------------------------------------------------*/
  501. Xvoid
  502. Xupdate_led(void)
  503. X{
  504. X    ledstate = ((vsp->scroll_lock) |
  505. X            (vsp->num_lock * 2) |
  506. X            (vsp->caps_lock * 4));
  507. X            
  508. X    if(kbd_cmd(KEYB_C_LEDS) != 0)
  509. X        printf("Keyboard LED command timeout\n");
  510. X    else if(kbd_cmd(ledstate) != 0)
  511. X        printf("Keyboard LED data timeout\n");    
  512. X}
  513. X
  514. X/*---------------------------------------------------------------------------*
  515. X *    set typamatic rate
  516. X *---------------------------------------------------------------------------*/
  517. Xstatic void
  518. Xsettpmrate(int rate)
  519. X{
  520. X    tpmrate = rate & 0x7f;
  521. X    if(kbd_cmd(KEYB_C_TYPEM) != 0)
  522. X        printf("Keyboard TYPEMATIC command timeout\n");
  523. X    else if(kbd_cmd(tpmrate) != 0)
  524. X        printf("Keyboard TYPEMATIC data timeout\n");    
  525. X}
  526. X/*---------------------------------------------------------------------------*
  527. X *    Pass command to keyboard controller (8042)
  528. X *---------------------------------------------------------------------------*/
  529. Xstatic int
  530. Xkbc_8042cmd(int val)
  531. X{
  532. X    unsigned timeo;
  533. X
  534. X    timeo = 100000;     /* > 100 msec */
  535. X    while (inb(CONTROLLER_CTRL) & STATUS_INPBF)
  536. X        if (--timeo == 0)
  537. X            return (-1);
  538. X    outb(CONTROLLER_CTRL, val);
  539. X    return (0);
  540. X}
  541. X
  542. X/*---------------------------------------------------------------------------*
  543. X *    Pass command to keyboard itself
  544. X *---------------------------------------------------------------------------*/
  545. Xint
  546. Xkbd_cmd(int val)
  547. X{
  548. X    unsigned timeo;
  549. X
  550. X    timeo = 100000;     /* > 100 msec */
  551. X    while (inb(CONTROLLER_CTRL) & STATUS_INPBF)
  552. X        if (--timeo == 0)
  553. X            return (-1);
  554. X    outb(CONTROLLER_DATA, val);
  555. X    return (0);
  556. X}
  557. X
  558. X/*---------------------------------------------------------------------------*
  559. X *    Read response from keyboard
  560. X *---------------------------------------------------------------------------*/
  561. Xint
  562. Xkbd_response(void)
  563. X{
  564. X    unsigned timeo;
  565. X
  566. X    timeo = 500000;     /* > 500 msec (KEYB_R_SELFOK requires 87) */
  567. X    while (!(inb(CONTROLLER_CTRL) & STATUS_OUTPBF))
  568. X        if (--timeo == 0)
  569. X            return (-1);
  570. X    return ((u_char) inb(CONTROLLER_DATA));
  571. X}
  572. X
  573. X/*---------------------------------------------------------------------------*
  574. X *    try to force keyboard into a known state ..
  575. X *---------------------------------------------------------------------------*/
  576. Xstatic
  577. Xvoid doreset(void)
  578. X{
  579. X    int again = 0;
  580. X    int response;
  581. X
  582. X    /* Enable interrupts and keyboard, etc. */
  583. X    if (kbc_8042cmd(CONTR_WRITE) != 0)
  584. X        printf("Timeout specifying load of keyboard command byte\n");
  585. X
  586. X#if PCVT_USEKBDSEC        /* security enabled */
  587. X
  588. X#  if PCVT_SCANSET == 2
  589. X#    define KBDINITCMD COMMAND_SYSFLG|COMMAND_IRQEN
  590. X#  else /* PCVT_SCANSET != 2 */
  591. X#    define KBDINITCMD COMMAND_PCSCAN|COMMAND_SYSFLG|COMMAND_IRQEN
  592. X#  endif /* PCVT_SCANSET == 2 */
  593. X
  594. X#else /* ! PCVT_USEKBDSEC */    /* security disabled */
  595. X
  596. X#  if PCVT_SCANSET == 2
  597. X#    define KBDINITCMD COMMAND_INHOVR|COMMAND_SYSFLG|COMMAND_IRQEN
  598. X#  else /* PCVT_SCANSET != 2 */
  599. X#    define KBDINITCMD COMMAND_PCSCAN|COMMAND_INHOVR|COMMAND_SYSFLG\
  600. X    |COMMAND_IRQEN
  601. X#  endif /* PCVT_SCANSET == 2 */
  602. X
  603. X#endif /* PCVT_USEKBDSEC */
  604. X
  605. X    if (kbd_cmd(KBDINITCMD) != 0)
  606. X        printf("Timeout writing keyboard command byte\n");
  607. X    
  608. X    /*
  609. X     * Discard any stale keyboard activity.  The 0.1 boot code isn't
  610. X     * very careful and sometimes leaves a KEYB_R_RESEND.
  611. X     */
  612. X    while (inb(CONTROLLER_CTRL) & STATUS_OUTPBF)
  613. X        kbd_response();
  614. X
  615. X    /* Start keyboard reset */
  616. X    if (kbd_cmd(KEYB_C_RESET) != 0)
  617. X        printf("Timeout for keyboard reset command\n");
  618. X
  619. X    /* Wait for the first response to reset and handle retries */
  620. X    while ((response = kbd_response()) != KEYB_R_ACK) {
  621. X        if (response < 0) {
  622. X            printf("Timeout for keyboard reset ack byte #1\n");
  623. X            response = KEYB_R_RESEND;
  624. X        }
  625. X        if (response == KEYB_R_RESEND) {
  626. X            if (!again) {
  627. X                printf("KEYBOARD disconnected: RECONNECT\n");
  628. X                again = 1;
  629. X            }
  630. X            if (kbd_cmd(KEYB_C_RESET) != 0)
  631. X                printf("Timeout for keyboard reset command\n");
  632. X        }
  633. X        /*
  634. X         * Other responses are harmless.  They may occur for new
  635. X         * keystrokes.
  636. X         */
  637. X    }
  638. X
  639. X    /* Wait for the second response to reset */
  640. X    while ((response = kbd_response()) != KEYB_R_SELFOK) {
  641. X        if (response < 0) {
  642. X            printf("Timeout for keyboard reset ack byte #2\n");
  643. X            /*
  644. X             * If KEYB_R_SELFOK never arrives, the loop will
  645. X             * finish here unless the keyboard babbles or
  646. X             * STATUS_OUTPBF gets stuck.
  647. X             */
  648. X            break;
  649. X        }
  650. X    }
  651. X
  652. X#if PCVT_KEYBDID
  653. X
  654. X    if(kbd_cmd(KEYB_C_ID) != 0)
  655. X    {
  656. X        printf("Timeout for keyboard ID command\n");
  657. X        keyboard_type = KB_UNKNOWN;
  658. X    }
  659. X    else
  660. X    {
  661. X
  662. Xr_entry:
  663. X
  664. X        if((response = kbd_response()) == KEYB_R_MF2ID1)
  665. X        {
  666. X            if((response = kbd_response()) == KEYB_R_MF2ID2)
  667. X            {
  668. X                keyboard_type = KB_MFII;
  669. X            }
  670. X            else if(response == KEYB_R_MF2ID2HP)
  671. X            {
  672. X                keyboard_type = KB_MFII;
  673. X            }                
  674. X            else
  675. X            {
  676. X                printf("\nkbdid, response 2 = [%d]\n",
  677. X                       response);
  678. X                keyboard_type = KB_UNKNOWN;
  679. X            }
  680. X        }    
  681. X        else if (response == KEYB_R_ACK)
  682. X        {
  683. X            goto r_entry;
  684. X        }
  685. X        else if (response == -1)        
  686. X        {
  687. X            keyboard_type = KB_AT;
  688. X        }            
  689. X        else
  690. X        {
  691. X            printf("\nkbdid, response 1 = [%d]\n", response);
  692. X        }
  693. X    }
  694. X
  695. X#else /* PCVT_KEYBDID */
  696. X
  697. X    keyboard_type = KB_MFII;    /* force it .. */
  698. X
  699. X#endif /* PCVT_KEYBDID */
  700. X
  701. X}
  702. X
  703. X/*---------------------------------------------------------------------------*
  704. X *    init keyboard code
  705. X *---------------------------------------------------------------------------*/
  706. Xvoid
  707. Xkbd_code_init(void)
  708. X{
  709. X    doreset();
  710. X    ovlinit(0);
  711. X    keyboard_is_initialized = 1;
  712. X}
  713. X
  714. X/*---------------------------------------------------------------------------*
  715. X *    init keyboard code, this initializes the keyboard subsystem
  716. X *    just "a bit" so the very very first ddb session is able to
  717. X *    get proper keystrokes, in other words, it's a hack ....
  718. X *---------------------------------------------------------------------------*/
  719. Xvoid
  720. Xkbd_code_init1(void)
  721. X{
  722. X    doreset();
  723. X    keyboard_is_initialized = 1;
  724. X}
  725. X
  726. X/*---------------------------------------------------------------------------*
  727. X *    init keyboard overlay table    
  728. X *---------------------------------------------------------------------------*/
  729. Xstatic
  730. Xvoid ovlinit(int force) 
  731. X{
  732. X    register i;
  733. X    
  734. X    if(force || ovlinitflag==0)
  735. X    {
  736. X        if(ovlinitflag == 0 &&
  737. X           (ovltbl = (Ovl_tbl *)malloc(sizeof(Ovl_tbl) * OVLTBL_SIZE,
  738. X                           M_DEVBUF, M_WAITOK)) == NULL)
  739. X            panic("pcvt_kbd: malloc of Ovl_tbl failed");
  740. X
  741. X        for(i=0; i<OVLTBL_SIZE; i++)
  742. X        {
  743. X            ovltbl[i].keynum = 
  744. X            ovltbl[i].type = 0;
  745. X            ovltbl[i].unshift[0] =
  746. X            ovltbl[i].shift[0] = 
  747. X            ovltbl[i].ctrl[0] =
  748. X            ovltbl[i].altgr[0] = 0;
  749. X            ovltbl[i].subu =
  750. X            ovltbl[i].subs =
  751. X            ovltbl[i].subc =
  752. X            ovltbl[i].suba = KBD_SUBT_STR;    /* just strings .. */
  753. X        }
  754. X        for(i=0; i<=MAXKEYNUM; i++)
  755. X            key2ascii[i].type &= KBD_MASK;
  756. X        ovlinitflag = 1;
  757. X    }
  758. X}
  759. X
  760. X/*---------------------------------------------------------------------------*
  761. X *    get original key definition
  762. X *---------------------------------------------------------------------------*/
  763. Xstatic int
  764. Xgetokeydef(unsigned key, Ovl_tbl *thisdef)
  765. X{
  766. X    if(key == 0 || key > MAXKEYNUM)
  767. X        return EINVAL;
  768. X    
  769. X    thisdef->keynum = key;
  770. X    thisdef->type = key2ascii[key].type;
  771. X
  772. X    if(key2ascii[key].unshift.subtype == STR)
  773. X    {
  774. X        bcopyb((u_char *)(key2ascii[key].unshift.what.string),
  775. X               thisdef->unshift, CODE_SIZE);
  776. X        thisdef->subu = KBD_SUBT_STR;
  777. X    }
  778. X    else
  779. X    {
  780. X        bcopyb("", thisdef->unshift, CODE_SIZE);
  781. X        thisdef->subu = KBD_SUBT_FNC;
  782. X    }
  783. X
  784. X    if(key2ascii[key].shift.subtype == STR)
  785. X    {
  786. X        bcopyb((u_char *)(key2ascii[key].shift.what.string),
  787. X               thisdef->shift, CODE_SIZE);
  788. X        thisdef->subs = KBD_SUBT_STR;
  789. X    }
  790. X    else
  791. X    {
  792. X        bcopyb("",thisdef->shift,CODE_SIZE);
  793. X        thisdef->subs = KBD_SUBT_FNC;
  794. X    }        
  795. X    
  796. X    if(key2ascii[key].ctrl.subtype == STR)
  797. X    {
  798. X        bcopyb((u_char *)(key2ascii[key].ctrl.what.string),
  799. X               thisdef->ctrl, CODE_SIZE);
  800. X        thisdef->subc = KBD_SUBT_STR;
  801. X    }
  802. X    else
  803. X    {
  804. X        bcopyb("",thisdef->ctrl,CODE_SIZE);    
  805. X        thisdef->subc = KBD_SUBT_FNC;
  806. X    }
  807. X    
  808. X    /* deliver at least anything for ALTGR settings ... */        
  809. X
  810. X    if(key2ascii[key].unshift.subtype == STR)
  811. X    {
  812. X        bcopyb((u_char *)(key2ascii[key].unshift.what.string),
  813. X               thisdef->altgr, CODE_SIZE);
  814. X        thisdef->suba = KBD_SUBT_STR;
  815. X    }
  816. X    else
  817. X    {
  818. X        bcopyb("",thisdef->altgr, CODE_SIZE);
  819. X        thisdef->suba = KBD_SUBT_FNC;
  820. X    }
  821. X    return 0;
  822. X}
  823. X
  824. X/*---------------------------------------------------------------------------*
  825. X *    get current key definition
  826. X *---------------------------------------------------------------------------*/
  827. Xstatic int
  828. Xgetckeydef(unsigned key, Ovl_tbl *thisdef) 
  829. X{
  830. X    u_short type = key2ascii[key].type;
  831. X
  832. X    if(key>MAXKEYNUM) 
  833. X        return EINVAL;
  834. X
  835. X    if(type & KBD_OVERLOAD)
  836. X        *thisdef = ovltbl[key2ascii[key].ovlindex];
  837. X    else
  838. X        getokeydef(key,thisdef);
  839. X
  840. X    return 0;
  841. X}
  842. X
  843. X/*---------------------------------------------------------------------------*
  844. X *    translate keynumber and returns ptr to associated ascii string
  845. X *    if key is bound to a function, executes it, and ret empty ptr
  846. X *---------------------------------------------------------------------------*/
  847. Xstatic u_char *
  848. Xxlatkey2ascii(U_short key)
  849. X{
  850. X    static u_char    capchar[2] = {0, 0};
  851. X#if PCVT_META_ESC
  852. X    static u_char    metachar[3] = {0x1b, 0, 0};
  853. X#else
  854. X    static u_char    metachar[2] = {0, 0};
  855. X#endif
  856. X    static Ovl_tbl    thisdef;
  857. X    int        n;
  858. X    void        (*fnc)();
  859. X    
  860. X    if(key==0)            /* ignore the NON-KEY */
  861. X        return 0;
  862. X    
  863. X    getckeydef(key&0x7F, &thisdef);    /* get the current ASCII value */
  864. X
  865. X    thisdef.type &= KBD_MASK;
  866. X
  867. X    if(key&0x80)            /* special handling of ALT-KEYPAD */
  868. X    {
  869. X        /* is the ALT Key released? */
  870. X        if(thisdef.type==KBD_META || thisdef.type==KBD_ALTGR)
  871. X        {
  872. X            if(altkpflag)    /* have we been in altkp mode? */
  873. X            {
  874. X                capchar[0] = altkpval;
  875. X                altkpflag = 0;
  876. X                altkpval = 0;
  877. X                return capchar;
  878. X            }
  879. X        }
  880. X        return 0;
  881. X    }
  882. X
  883. X    switch(thisdef.type)        /* convert the keys */
  884. X    {
  885. X        case KBD_BREAK:
  886. X        case KBD_ASCII:
  887. X        case KBD_FUNC:
  888. X            fnc = NULL;
  889. X            more_chars = NULL;
  890. X            
  891. X            if(altgr_down)
  892. X                more_chars = (u_char *)thisdef.altgr;
  893. X    
  894. X            else if(shift_down || vsp->shift_lock)
  895. X            {
  896. X                if(key2ascii[key].shift.subtype == STR)
  897. X                    more_chars = (u_char *)thisdef.shift;
  898. X                else
  899. X                    fnc = key2ascii[key].shift.what.func;
  900. X            }
  901. X                
  902. X            else if(ctrl_down)
  903. X            {
  904. X                if(key2ascii[key].ctrl.subtype == STR)
  905. X                    more_chars = (u_char *)thisdef.ctrl;
  906. X                else
  907. X                    fnc = key2ascii[key].ctrl.what.func;
  908. X            }
  909. X    
  910. X            else
  911. X            {
  912. X                if(key2ascii[key].unshift.subtype == STR)
  913. X                    more_chars = (u_char *)thisdef.unshift;
  914. X                else
  915. X                    fnc = key2ascii[key].unshift.what.func;
  916. X            }
  917. X    
  918. X            if(fnc)
  919. X                (*fnc)();    /* execute function */
  920. X                    
  921. X            if((more_chars != NULL) && (more_chars[1] == 0))
  922. X            {
  923. X                if(vsp->caps_lock && more_chars[0] >= 'a'
  924. X                   && more_chars[0] <= 'z')
  925. X                {
  926. X                    capchar[0] = *more_chars - ('a'-'A');
  927. X                    more_chars = capchar;
  928. X                }
  929. X                if(meta_down)
  930. X                {
  931. X#if PCVT_META_ESC
  932. X                    metachar[1] = *more_chars;
  933. X#else
  934. X                    metachar[0] = *more_chars | 0x80;
  935. X#endif
  936. X                    more_chars = metachar;
  937. X                }
  938. X            }
  939. X            return(more_chars);
  940. X
  941. X        case KBD_KP:
  942. X            fnc = NULL;
  943. X            more_chars = NULL;
  944. X    
  945. X            if(meta_down)
  946. X            {
  947. X                switch(key)
  948. X                {
  949. X                    case 95:    /* / */
  950. X                        altkpflag = 0;
  951. X                        more_chars =
  952. X                         (u_char *)"\033OQ";
  953. X                        return(more_chars);
  954. X                        
  955. X                    case 100:    /* * */
  956. X                        altkpflag = 0;
  957. X                        more_chars =
  958. X                         (u_char *)"\033OR";
  959. X                        return(more_chars);
  960. X                        
  961. X                    case 105:    /* - */
  962. X                        altkpflag = 0;
  963. X                        more_chars =
  964. X                         (u_char *)"\033OS";
  965. X                        return(more_chars);
  966. X                }
  967. X            }
  968. X
  969. X            if(meta_down || altgr_down)                
  970. X            {
  971. X                if((n = keypad2num[key-91]) >= 0)
  972. X                {
  973. X                    if(!altkpflag)
  974. X                    {
  975. X                        /* start ALT-KP mode */
  976. X                        altkpflag = 1;
  977. X                        altkpval = 0;
  978. X                    }
  979. X                    altkpval *= 10;
  980. X                    altkpval += n;
  981. X                }
  982. X                else
  983. X                    altkpflag = 0;
  984. X                return 0;
  985. X            } 
  986. X    
  987. X            if(!(vsp->num_lock))
  988. X            {
  989. X                if(key2ascii[key].shift.subtype == STR)
  990. X                    more_chars = (u_char *)thisdef.shift;
  991. X                else
  992. X                    fnc = key2ascii[key].shift.what.func;
  993. X            }
  994. X            else
  995. X            {
  996. X                if(key2ascii[key].unshift.subtype == STR)
  997. X                    more_chars = (u_char *)thisdef.unshift;
  998. X                else
  999. X                    fnc = key2ascii[key].unshift.what.func;
  1000. X            }
  1001. X    
  1002. X            if(fnc)
  1003. X                (*fnc)();    /* execute function */
  1004. X            return(more_chars);
  1005. X    
  1006. X        case KBD_CURSOR:
  1007. X            fnc = NULL;
  1008. X            more_chars = NULL;
  1009. X    
  1010. X            if(vsp->ckm)
  1011. X            {
  1012. X                if(key2ascii[key].shift.subtype == STR)
  1013. X                    more_chars = (u_char *)thisdef.shift;
  1014. X                else
  1015. X                    fnc = key2ascii[key].shift.what.func;
  1016. X            }
  1017. X            else
  1018. X            {
  1019. X                if(key2ascii[key].unshift.subtype == STR)
  1020. X                    more_chars = (u_char *)thisdef.unshift;
  1021. X                else
  1022. X                    fnc = key2ascii[key].unshift.what.func;
  1023. X            }
  1024. X    
  1025. X            if(fnc)
  1026. X                (*fnc)();    /* execute function */
  1027. X            return(more_chars);
  1028. X
  1029. X        case KBD_NUM:        /*  special kp-num handling */
  1030. X            more_chars = NULL;
  1031. X            
  1032. X            if(meta_down)
  1033. X            {
  1034. X                more_chars = (u_char *)"\033OP"; /* PF1 */
  1035. X            }
  1036. X            else
  1037. X            {
  1038. X                vsp->num_lock ^= 1;
  1039. X                update_led();
  1040. X            }
  1041. X            return(more_chars);
  1042. X
  1043. X        case KBD_RETURN:
  1044. X            more_chars = NULL;
  1045. X
  1046. X            if(!(vsp->num_lock))
  1047. X            {
  1048. X                more_chars = (u_char *)thisdef.shift;
  1049. X            }
  1050. X            else
  1051. X            {
  1052. X                more_chars = (u_char *)thisdef.unshift;
  1053. X            }
  1054. X            if(vsp->lnm && (*more_chars == '\r'))
  1055. X            {
  1056. X                more_chars = (u_char *)"\r\n"; /* CR LF */
  1057. X            }
  1058. X            return(more_chars);
  1059. X            
  1060. X        case KBD_META:        /* these keys are    */
  1061. X        case KBD_ALTGR:        /*  handled directly    */
  1062. X        case KBD_SCROLL:    /*  by the keyboard    */
  1063. X        case KBD_CAPS:        /*  handler - they are    */
  1064. X        case KBD_SHFTLOCK:    /*  ignored here    */
  1065. X        case KBD_CTL:
  1066. X        case KBD_NONE:
  1067. X        default:
  1068. X            return 0;
  1069. X    }
  1070. X}
  1071. X
  1072. X/*---------------------------------------------------------------------------*
  1073. X *    get keystrokes from the keyboard.
  1074. X *    if noblock = 0, wait until a key is pressed.
  1075. X *    else return NULL if no characters present.
  1076. X *---------------------------------------------------------------------------*/
  1077. Xu_char *
  1078. Xsgetc(int noblock)
  1079. X{
  1080. X    u_char        *cp;
  1081. X    u_char        dt;
  1082. X    u_char        key;
  1083. X    u_short        type;
  1084. X    
  1085. X    static u_char    kbd_lastkey = 0; /* last keystroke */
  1086. X    static struct
  1087. X    {
  1088. X        u_char extended: 1;    /* extended prefix seen */
  1089. X        u_char ext1: 1;        /* extended prefix 1 seen */
  1090. X        u_char breakseen: 1;    /* break code seen */
  1091. X        u_char vshift: 1;    /* virtual shift pending */
  1092. X        u_char vcontrol: 1;    /* virtual control pending */
  1093. X        u_char sysrq: 1;    /* sysrq pressed */
  1094. X    } kbd_status = {0};
  1095. X
  1096. X#ifdef XSERVER
  1097. X    static char    keybuf[2] = {0}; /* the second 0 is a delimiter! */
  1098. X#endif /* XSERVER */
  1099. X
  1100. Xloop:
  1101. X    /* see if there is something from the keyboard in the input buffer */
  1102. X
  1103. X#ifdef XSERVER
  1104. X    if (inb(CONTROLLER_CTRL) & STATUS_OUTPBF)
  1105. X    {
  1106. X        dt = inb(CONTROLLER_DATA);        /* yes, get it ! */
  1107. X
  1108. X        /*
  1109. X         * If x mode is active, only care for locking keys, then
  1110. X         * return the scan code instead of any key translation.
  1111. X         * Additionally, this prevents us from any attempts to
  1112. X         * execute pcvt internal functions caused by keys (such
  1113. X         * as screen flipping).
  1114. X         * XXX For now, only the default locking key definitions
  1115. X         * are recognized (i.e. if you have overloaded you "A" key
  1116. X         * as NUMLOCK, that wont effect X mode:-)
  1117. X         * Changing this would be nice, but would require modifi-
  1118. X         * cations to the X server. After having this, X will
  1119. X         * deal with the LEDs itself, so we are committed.
  1120. X         */
  1121. X        /*
  1122. X         * Iff PCVT_USL_VT_COMPAT is defined, the behaviour has
  1123. X         * been fixed. We need not care about any keys here, since
  1124. X         * there are ioctls that deal with the lock key / LED stuff.
  1125. X         */
  1126. X        if (pcvt_kbd_raw)
  1127. X        {
  1128. X            keybuf[0] = dt;
  1129. X#if !PCVT_USL_VT_COMPAT
  1130. X            if ((dt & 0x80) == 0)
  1131. X                /* key make */
  1132. X                switch(dt)
  1133. X                {
  1134. X                case 0x45:
  1135. X                    /* XXX on which virt screen? */                    vsp->num_lock ^= 1;
  1136. X                    update_led();
  1137. X                    break;
  1138. X
  1139. X                case 0x3a:
  1140. X                    vsp->caps_lock ^= 1;
  1141. X                    update_led();
  1142. X                    break;
  1143. X
  1144. X                case 0x46:
  1145. X                    vsp->scroll_lock ^= 1;
  1146. X                    update_led();
  1147. X                    break;
  1148. X                }
  1149. X#endif /* !PCVT_USL_VT_COMPAT */
  1150. X
  1151. X#if PCVT_EMU_MOUSE
  1152. X            /*
  1153. X             * The (mouse systems) mouse emulator. The mouse
  1154. X             * device allocates the first device node that is
  1155. X             * not used by a virtual terminal. (E.g., you have
  1156. X             * eight vtys, /dev/ttyv0 thru /dev/ttyv7, so the
  1157. X             * mouse emulator were /dev/ttyv8.)
  1158. X             * Currently the emulator only works if the keyboard
  1159. X             * is in raw (PC scan code) mode. This is the typic-
  1160. X             * al case when running the X server.
  1161. X             * It is activated if the num locks LED is active
  1162. X             * for the current vty, and if the mouse device
  1163. X             * has been opened by at least one process. It
  1164. X             * grabs the numerical keypad events (but only
  1165. X             * the "non-extended", so the separate arrow keys
  1166. X             * continue to work), and three keys for the "mouse
  1167. X             * buttons", preferrably F1 thru F3. Any of the
  1168. X             * eight directions (N, NE, E, SE, S, SW, W, NW)
  1169. X             * is supported, and frequent key presses (less
  1170. X             * than e.g. half a second between key presses)
  1171. X             * cause the emulator to accelerate the pointer
  1172. X             * movement by 6, while single presses result in
  1173. X             * single moves, so each point can be reached.
  1174. X             */
  1175. X            /*
  1176. X             * NB: the following code is spagghetti.
  1177. X             * Only eat it with lotta tomato ketchup and
  1178. X             * Parmesan cheese:-)
  1179. X             */
  1180. X            /*
  1181. X             * look whether we will have to steal the keys
  1182. X             * and cook them into mouse events
  1183. X             */
  1184. X            if(vsp->num_lock && mouse.opened)
  1185. X            {
  1186. X                int button, accel, i;
  1187. X                enum mouse_dir
  1188. X                {
  1189. X                    MOUSE_NW, MOUSE_N, MOUSE_NE,
  1190. X                    MOUSE_W,  MOUSE_0, MOUSE_E,
  1191. X                    MOUSE_SW, MOUSE_S, MOUSE_SE
  1192. X                }
  1193. X                move;
  1194. X                struct timeval now;
  1195. X                /* from sys/kern/kern_time.c */
  1196. X                extern void timevalsub
  1197. X                    (struct timeval *, struct timeval *);
  1198. X                dev_t dummy = makedev(0, mouse.minor);
  1199. X                struct tty *mousetty = get_pccons(dummy);
  1200. X                /*
  1201. X                 * strings to send for each mouse event,
  1202. X                 * indexed by the movement direction and
  1203. X                 * the "accelerator" value (TRUE for frequent
  1204. X                 * key presses); note that the first byte
  1205. X                 * of each string is actually overwritten
  1206. X                 * by the current button value before sending
  1207. X                 * the string
  1208. X                 */
  1209. X                static u_char mousestrings[2][MOUSE_SE+1][5] =
  1210. X                {
  1211. X                {
  1212. X                    /* first, the non-accelerated strings*/
  1213. X                    {0x87,  -1,   1,   0,   0}, /* NW */
  1214. X                    {0x87,   0,   1,   0,   0}, /* N */
  1215. X                    {0x87,   1,   1,   0,   0}, /* NE */
  1216. X                    {0x87,  -1,   0,   0,   0}, /* W */
  1217. X                    {0x87,   0,   0,   0,   0}, /* 0 */
  1218. X                    {0x87,   1,   0,   0,   0}, /* E */
  1219. X                    {0x87,  -1,  -1,   0,   0}, /* SW */
  1220. X                    {0x87,   0,  -1,   0,   0}, /* S */
  1221. X                    {0x87,   1,  -1,   0,   0}  /* SE */
  1222. X                },
  1223. X                {
  1224. X                    /* now, 6 steps at once */
  1225. X                    {0x87,  -4,   4,   0,   0}, /* NW */
  1226. X                    {0x87,   0,   6,   0,   0}, /* N */
  1227. X                    {0x87,   4,   4,   0,   0}, /* NE */
  1228. X                    {0x87,  -6,   0,   0,   0}, /* W */
  1229. X                    {0x87,   0,   0,   0,   0}, /* 0 */
  1230. X                    {0x87,   6,   0,   0,   0}, /* E */
  1231. X                    {0x87,  -4,  -4,   0,   0}, /* SW */
  1232. X                    {0x87,   0,  -6,   0,   0}, /* S */
  1233. X                    {0x87,   4,  -4,   0,   0}  /* SE */
  1234. X                }
  1235. X                };
  1236. X                
  1237. X                if(dt == 0xe0)
  1238. X                {
  1239. X                    /* ignore extended scan codes */
  1240. X                    mouse.extendedseen = 1;
  1241. X                    goto no_mouse_event;
  1242. X                }
  1243. X                if(mouse.extendedseen)
  1244. X                {
  1245. X                    mouse.extendedseen = 0;
  1246. X                    goto no_mouse_event;
  1247. X                }
  1248. X                mouse.extendedseen = 0;
  1249. X
  1250. X                /*
  1251. X                 * Note that we cannot use a switch here
  1252. X                 * since we want to have the keycodes in
  1253. X                 * a variable
  1254. X                 */
  1255. X                if((dt & 0x7f) == mousedef.leftbutton) {
  1256. X                    button = 4;
  1257. X                    goto do_button;
  1258. X                }
  1259. X                else if((dt & 0x7f) == mousedef.middlebutton) {
  1260. X                    button = 2;
  1261. X                    goto do_button;
  1262. X                }
  1263. X                else if((dt & 0x7f) == mousedef.rightbutton) {
  1264. X                    button = 1;
  1265. X                do_button:
  1266. X
  1267. X                    /*
  1268. X                     * i would really like to give
  1269. X                     * some acustical support
  1270. X                     * (pling/plong); i am not sure
  1271. X                     * whether it is safe to call
  1272. X                     * sysbeep from within an intr
  1273. X                     * service, since it calls
  1274. X                     * timeout in turn which mani-
  1275. X                     * pulates the spl mask - jw
  1276. X                     */
  1277. X
  1278. X# define PLING sysbeep(PCVT_SYSBEEPF / 1500, 2)
  1279. X# define PLONG sysbeep(PCVT_SYSBEEPF / 1200, 2)
  1280. X
  1281. X                    if(mousedef.stickybuttons)
  1282. X                    {
  1283. X                        if(dt & 0x80) {
  1284. X                            mouse.breakseen = 1;
  1285. X                            return (u_char *)0;
  1286. X                        }
  1287. X                        else if(mouse.buttons == button
  1288. X                            && !mouse.breakseen) {
  1289. X                            /* ignore repeats */
  1290. X                            return (u_char *)0;
  1291. X                        }
  1292. X                        else
  1293. X                            mouse.breakseen = 0;
  1294. X                        if(mouse.buttons == button) {
  1295. X                            /* release it */
  1296. X                            mouse.buttons = 0;
  1297. X                            PLONG;
  1298. X                        } else {
  1299. X                            /*
  1300. X                             * eventually, release
  1301. X                             * any other button,
  1302. X                             * and stick this one
  1303. X                             */
  1304. X                            mouse.buttons = button;
  1305. X                            PLING;
  1306. X                        }
  1307. X                    }
  1308. X                    else
  1309. X                    {
  1310. X                        if(dt & 0x80) {
  1311. X                            mouse.buttons &=
  1312. X                                ~button;
  1313. X                            PLONG;
  1314. X                        }
  1315. X                        else if((mouse.buttons
  1316. X                            & button) == 0) {
  1317. X                            mouse.buttons |=
  1318. X                                button;
  1319. X                            PLING;
  1320. X                        }
  1321. X                        /*else: ignore same btn press*/
  1322. X                    }
  1323. X                    move = MOUSE_0;
  1324. X                    accel = 0;
  1325. X                }
  1326. X# undef PLING
  1327. X# undef PLONG
  1328. X                else switch(dt & 0x7f)
  1329. X                {
  1330. X                /* the arrow keys - KP 1 thru KP 9 */
  1331. X                case 0x47:    move = MOUSE_NW; goto do_move;
  1332. X                case 0x48:    move = MOUSE_N; goto do_move;
  1333. X                case 0x49:    move = MOUSE_NE; goto do_move;
  1334. X                case 0x4b:    move = MOUSE_W; goto do_move;
  1335. X                case 0x4c:    move = MOUSE_0; goto do_move;
  1336. X                case 0x4d:    move = MOUSE_E; goto do_move;
  1337. X                case 0x4f:    move = MOUSE_SW; goto do_move;
  1338. X                case 0x50:    move = MOUSE_S; goto do_move;
  1339. X                case 0x51:    move = MOUSE_SE;
  1340. X                do_move:
  1341. X                    if(dt & 0x80)
  1342. X                        /*
  1343. X                         * arrow key break events are
  1344. X                         * of no importance for us
  1345. X                         */
  1346. X                        return (u_char *)0;
  1347. X                    /*
  1348. X                     * see whether the last move did
  1349. X                     * happen "recently", i.e. before
  1350. X                     * less than half a second
  1351. X                     */
  1352. X                    now = time;
  1353. X                    timevalsub(&now, &mouse.lastmove);
  1354. X                    mouse.lastmove = time;
  1355. X                    accel = (now.tv_sec == 0
  1356. X                         && now.tv_usec
  1357. X                         < mousedef.acceltime);
  1358. X                    break;
  1359. X                    
  1360. X                default: /* not a mouse-emulating key */
  1361. X                    goto no_mouse_event;
  1362. X                }
  1363. X                mousestrings[accel][move][0] =
  1364. X                    0x80 + (~mouse.buttons & 7);
  1365. X                /* finally, send the string */
  1366. X                for(i = 0; i < 5; i++)
  1367. X                    (*linesw[mousetty->t_line].l_rint)
  1368. X                        (mousestrings[accel][move][i],
  1369. X                         mousetty);
  1370. X                return (u_char *)0; /* not a kbd event */
  1371. X            }
  1372. Xno_mouse_event:
  1373. X
  1374. X#endif /* PCVT_EMU_MOUSE */
  1375. X
  1376. X            return ((u_char *)keybuf);
  1377. X        }
  1378. X    }
  1379. X
  1380. X#else /* !XSERVER */
  1381. X
  1382. X    if(inb(CONTROLLER_CTRL) & STATUS_OUTPBF)
  1383. X        dt = inb(CONTROLLER_DATA);        /* yes, get it ! */
  1384. X
  1385. X#endif /* !XSERVER */
  1386. X
  1387. X    else
  1388. X    {
  1389. X        if(noblock)
  1390. X            return NULL;
  1391. X        else
  1392. X            goto loop;
  1393. X    }
  1394. X
  1395. X#if PCVT_SHOWKEYS
  1396. X    {
  1397. X    int rki;
  1398. X    
  1399. X    
  1400. X    for(rki = 3; rki < 80; rki++)        /* shift left buffer */
  1401. X        rawkeybuf[rki-3] = rawkeybuf[rki];
  1402. X
  1403. X    rawkeybuf[77] = ' ';        /* delimiter */
  1404. X
  1405. X    rki = (dt & 0xf0) >> 4;        /* ms nibble */
  1406. X
  1407. X    if(rki <= 9)
  1408. X        rki = rki + '0';
  1409. X    else
  1410. X        rki = rki - 10 + 'A';
  1411. X
  1412. X    rawkeybuf[78] = rki;
  1413. X        
  1414. X    rki = dt & 0x0f;            /* ls nibble */
  1415. X
  1416. X    if(rki <= 9)
  1417. X        rki = rki + '0';
  1418. X    else
  1419. X        rki = rki - 10 + 'A';
  1420. X
  1421. X    rawkeybuf[79] = rki;
  1422. X    }
  1423. X#endif    /* PCVT_SHOWKEYS */
  1424. X
  1425. X    /* lets look what we got */
  1426. X    switch(dt)
  1427. X    {
  1428. X        case KEYB_R_OVERRUN0:    /* keyboard buffer overflow */
  1429. X
  1430. X#if PCVT_SCANSET == 2
  1431. X        case KEYB_R_SELFOK:    /* keyboard selftest ok */
  1432. X#endif /* PCVT_SCANSET == 2 */
  1433. X
  1434. X        case KEYB_R_ECHO:    /* keyboard response to KEYB_C_ECHO */
  1435. X        case KEYB_R_ACK:    /* acknowledge after command has rx'd*/
  1436. X        case KEYB_R_SELFBAD:    /* keyboard selftest FAILED */
  1437. X        case KEYB_R_DIAGBAD:    /* keyboard self diagnostic failure */
  1438. X        case KEYB_R_RESEND:    /* keyboard wants us to resend cmnd */
  1439. X        case KEYB_R_OVERRUN1:    /* keyboard buffer overflow */
  1440. X            break;
  1441. X
  1442. X        case KEYB_R_EXT1:    /* keyboard extended scancode pfx 2 */
  1443. X            kbd_status.ext1 = 1;
  1444. X            /* FALLTHROUGH */
  1445. X        case KEYB_R_EXT0:    /* keyboard extended scancode pfx 1 */
  1446. X            kbd_status.extended = 1; 
  1447. X            break;
  1448. X
  1449. X#if PCVT_SCANSET == 2
  1450. X        case KEYB_R_BREAKPFX:    /* break code prefix for set 2 and 3 */
  1451. X            kbd_status.breakseen = 1; 
  1452. X            break;
  1453. X#endif /* PCVT_SCANSET == 2 */
  1454. X
  1455. X        default:
  1456. X            goto regular;    /* regular key */
  1457. X    }
  1458. X
  1459. X    if(noblock)
  1460. X        return NULL;
  1461. X    else
  1462. X        goto loop;
  1463. X
  1464. X    /* got a normal scan key */
  1465. Xregular:
  1466. X
  1467. X#if PCVT_SCANSET == 1
  1468. X    kbd_status.breakseen = dt & 0x80 ? 1 : 0;
  1469. X    dt &= 0x7f;
  1470. X#endif    /* PCVT_SCANSET == 1 */
  1471. X
  1472. X    /*   make a keycode from scan code    */
  1473. X    if(dt >= sizeof scantokey / sizeof(u_char))
  1474. X        key = 0;
  1475. X    else
  1476. X        key = kbd_status.extended ? extscantokey[dt] : scantokey[dt];
  1477. X    if(kbd_status.ext1 && key == 58)
  1478. X        /* virtual control key */
  1479. X        key = 129;
  1480. X    kbd_status.extended = kbd_status.ext1 = 0;
  1481. X
  1482. X#if PCVT_CTRL_ALT_DEL        /*   Check for cntl-alt-del    */
  1483. X    if((key == 76) && ctrl_down && (meta_down||altgr_down))
  1484. X        cpu_reset();
  1485. X#endif /* PCVT_CTRL_ALT_DEL */
  1486. X        
  1487. X#if !PCVT_NETBSD
  1488. X#include "ddb.h"
  1489. X#endif /* !PCVT_NETBSD */
  1490. X
  1491. X#if NDDB > 0 || defined(DDB)         /*   Check for cntl-alt-esc    */
  1492. X
  1493. X      if((key == 110) && ctrl_down && (meta_down || altgr_down))
  1494. X     {
  1495. X         static u_char in_Debugger;
  1496. X         if(!in_Debugger)
  1497. X         {
  1498. X             in_Debugger = 1;
  1499. X#if PCVT_FREEBSD
  1500. X            /* the string is actually not used... */
  1501. X            Debugger("kbd");
  1502. X#else
  1503. X             Debugger();
  1504. X#endif
  1505. X             in_Debugger = 0;
  1506. X             if(noblock)
  1507. X                 return NULL;
  1508. X             else
  1509. X                 goto loop;
  1510. X         }
  1511. X     }
  1512. X#endif /* NDDB > 0 || defined(DDB) */
  1513. X
  1514. X    /* look for keys with special handling */
  1515. X    if(key == 128)
  1516. X    {
  1517. X        /*
  1518. X         * virtual shift; sent around PrtScr, and around the arrow
  1519. X         * keys if the NumLck LED is on
  1520. X         */
  1521. X        kbd_status.vshift = !kbd_status.breakseen;
  1522. X        key = 0;    /* no key */
  1523. X    }
  1524. X    else if(key == 129)
  1525. X    {
  1526. X        /*
  1527. X         * virtual control - the most ugly thingie at all
  1528. X         * the Pause key sends:
  1529. X         * <virtual control make> <numlock make> <virtual control
  1530. X         * break> <numlock break>
  1531. X         */
  1532. X        if(!kbd_status.breakseen)
  1533. X            kbd_status.vcontrol = 1;
  1534. X        /* else: let the numlock hook clear this */
  1535. X        key = 0;    /* no key */
  1536. X    }
  1537. X    else if(key == 90)
  1538. X    {
  1539. X        /* NumLock, look whether this is rather a Pause */
  1540. X        if(kbd_status.vcontrol)
  1541. X            key = 126;
  1542. X        /*
  1543. X         * if this is the final break code of a Pause key,
  1544. X         * clear the virtual control status, too
  1545. X         */
  1546. X        if(kbd_status.vcontrol && kbd_status.breakseen)
  1547. X            kbd_status.vcontrol = 0;
  1548. X    }
  1549. X    else if(key == 127)
  1550. X    {
  1551. X        /*
  1552. X         * a SysRq; some keyboards are brain-dead enough to
  1553. X         * repeat the SysRq key make code by sending PrtScr
  1554. X         * make codes; other keyboards do not repeat SysRq
  1555. X         * at all. We keep track of the SysRq state here.
  1556. X         */
  1557. X        kbd_status.sysrq = !kbd_status.breakseen;
  1558. X    }
  1559. X    else if(key == 124)
  1560. X    {
  1561. X        /*
  1562. X         * PrtScr; look whether this is really PrtScr or rather
  1563. X         * a silly repeat of a SysRq key
  1564. X         */
  1565. X        if(kbd_status.sysrq)
  1566. X            /* ignore the garbage */
  1567. X            key = 0;
  1568. X    }
  1569. X
  1570. X    /* in NOREPEAT MODE ignore the key if it was the same as before */
  1571. X
  1572. X    if(!kbrepflag && key == kbd_lastkey && !kbd_status.breakseen)
  1573. X    {
  1574. X        if(noblock)
  1575. X            return NULL;
  1576. X        else
  1577. X            goto loop;
  1578. X    }
  1579. X    
  1580. X    type = key2ascii[key].type;
  1581. X
  1582. X    if(type & KBD_OVERLOAD)
  1583. X        type = ovltbl[key2ascii[key].ovlindex].type;
  1584. X
  1585. X    type &= KBD_MASK;
  1586. X
  1587. X    switch(type)
  1588. X    {
  1589. X        case KBD_SHFTLOCK:
  1590. X            if(!kbd_status.breakseen && key != kbd_lastkey)
  1591. X            {
  1592. X                vsp->shift_lock ^= 1;
  1593. X            }
  1594. X            break;
  1595. X            
  1596. X        case KBD_CAPS:
  1597. X            if(!kbd_status.breakseen && key != kbd_lastkey)
  1598. X            {
  1599. X                vsp->caps_lock ^= 1;
  1600. X                update_led();
  1601. X            }
  1602. X            break;
  1603. X            
  1604. X        case KBD_SCROLL:
  1605. X            if(!kbd_status.breakseen && key != kbd_lastkey)
  1606. X            {
  1607. X                vsp->scroll_lock ^= 1;
  1608. X                update_led();
  1609. X
  1610. X                if(!(vsp->scroll_lock))
  1611. X                {
  1612. X                    /* someone may be sleeping */
  1613. X                    wakeup((caddr_t)&(vsp->scroll_lock));
  1614. X                }
  1615. X            }
  1616. X            break;
  1617. X            
  1618. X        case KBD_SHIFT:
  1619. X            shift_down = kbd_status.breakseen ? 0 : 1;
  1620. X            break;
  1621. X
  1622. X        case KBD_META:
  1623. X            meta_down = kbd_status.breakseen ? 0 : 0x80;
  1624. X            break;
  1625. X
  1626. X        case KBD_ALTGR:
  1627. X            altgr_down = kbd_status.breakseen ? 0 : 1;
  1628. X            break;
  1629. X
  1630. X        case KBD_CTL:
  1631. X            ctrl_down = kbd_status.breakseen ? 0 : 1;
  1632. X            break;
  1633. X
  1634. X        case KBD_NONE:
  1635. X        default:
  1636. X            break;            /* deliver a key */
  1637. X    }
  1638. X
  1639. X    if(kbd_status.breakseen)
  1640. X    {
  1641. X        key |= 0x80;
  1642. X        kbd_status.breakseen = 0;
  1643. X        kbd_lastkey = 0; /* -hv- I know this is a bug with */
  1644. X    }             /* N-Key-Rollover, but I ignore that */
  1645. X    else             /* because avoidance is too complicated */
  1646. X        kbd_lastkey = key;
  1647. X    
  1648. X    cp = xlatkey2ascii(key);    /* have a key */
  1649. X    if(cp == NULL && !noblock)
  1650. X        goto loop;
  1651. X    return cp;
  1652. X}
  1653. X
  1654. X/*---------------------------------------------------------------------------*
  1655. X *    reflect status of locking keys & set led's
  1656. X *---------------------------------------------------------------------------*/
  1657. Xstatic void
  1658. Xsetlockkeys(int snc)
  1659. X{
  1660. X    vsp->scroll_lock = snc & 1;
  1661. X    vsp->num_lock     = (snc & 2) ? 1 : 0;
  1662. X    vsp->caps_lock     = (snc & 4) ? 1 : 0;
  1663. X    update_led();
  1664. X}
  1665. X
  1666. X/*---------------------------------------------------------------------------*
  1667. X *    remove a key definition
  1668. X *---------------------------------------------------------------------------*/
  1669. Xstatic int
  1670. Xrmkeydef(int key)
  1671. X{
  1672. X    register Ovl_tbl *ref;
  1673. X    
  1674. X    if(key==0 || key > MAXKEYNUM)
  1675. X        return EINVAL;
  1676. X
  1677. X    if(key2ascii[key].type & KBD_OVERLOAD)
  1678. X    {
  1679. X        ref = &ovltbl[key2ascii[key].ovlindex];        
  1680. X        ref->keynum = 0;
  1681. X        ref->type = 0;
  1682. X        ref->unshift[0] =
  1683. X        ref->shift[0] =
  1684. X        ref->ctrl[0] =
  1685. X        ref->altgr[0] = 0;
  1686. X        key2ascii[key].type &= KBD_MASK;
  1687. X    }
  1688. X    return 0;
  1689. X}    
  1690. X
  1691. X/*---------------------------------------------------------------------------*
  1692. X *    overlay a key
  1693. X *---------------------------------------------------------------------------*/
  1694. Xstatic int
  1695. Xsetkeydef(Ovl_tbl *data)
  1696. X{
  1697. X    register i;
  1698. X
  1699. X    if( data->keynum > MAXKEYNUM         ||
  1700. X        (data->type & KBD_MASK) == KBD_BREAK ||
  1701. X        (data->type & KBD_MASK) > KBD_SHFTLOCK)
  1702. X        return EINVAL;
  1703. X
  1704. X    data->unshift[KBDMAXOVLKEYSIZE] =
  1705. X    data->shift[KBDMAXOVLKEYSIZE] =
  1706. X    data->ctrl[KBDMAXOVLKEYSIZE] =
  1707. X    data->altgr[KBDMAXOVLKEYSIZE] = 0;
  1708. X
  1709. X    data->subu =
  1710. X    data->subs =
  1711. X    data->subc =
  1712. X    data->suba = KBD_SUBT_STR;        /* just strings .. */
  1713. X    
  1714. X    data->type |= KBD_OVERLOAD;        /* mark overloaded */
  1715. X
  1716. X    /* if key already overloaded, use that slot else find free slot */
  1717. X
  1718. X    if(key2ascii[data->keynum].type & KBD_OVERLOAD)
  1719. X    {
  1720. X        i = key2ascii[data->keynum].ovlindex;
  1721. X    }
  1722. X    else
  1723. X    {
  1724. X        for(i=0; i<OVLTBL_SIZE; i++)
  1725. X            if(ovltbl[i].keynum==0)
  1726. X                break;
  1727. X
  1728. X        if(i==OVLTBL_SIZE) 
  1729. X            return ENOSPC;    /* no space, abuse of ENOSPC(!) */
  1730. X    }
  1731. X
  1732. X    ovltbl[i] = *data;        /* copy new data string */
  1733. X
  1734. X    key2ascii[data->keynum].type |= KBD_OVERLOAD;     /* mark key */
  1735. X    key2ascii[data->keynum].ovlindex = i;
  1736. X    
  1737. X    return 0;
  1738. X}
  1739. X
  1740. X/*---------------------------------------------------------------------------*
  1741. X *    keyboard ioctl's entry
  1742. X *---------------------------------------------------------------------------*/
  1743. Xint
  1744. Xkbdioctl(Dev_t dev, int cmd, caddr_t data, int flag)
  1745. X{
  1746. X    int key;
  1747. X
  1748. X    switch(cmd)
  1749. X    {
  1750. X        case KBDRESET:
  1751. X            doreset();
  1752. X            ovlinit(1);
  1753. X            settpmrate(KBD_TPD500|KBD_TPM100);
  1754. X            setlockkeys(0);
  1755. X            break;
  1756. X
  1757. X        case KBDGTPMAT:
  1758. X            *(int *)data = tpmrate;
  1759. X            break;
  1760. X
  1761. X        case KBDSTPMAT:
  1762. X            settpmrate(*(int *)data);
  1763. X            break;
  1764. X
  1765. X        case KBDGREPSW:
  1766. X            *(int *)data = kbrepflag;
  1767. X            break;
  1768. X
  1769. X        case KBDSREPSW:
  1770. X            kbrepflag = (*(int *)data) & 1;
  1771. X            break;
  1772. X
  1773. X        case KBDGLEDS:
  1774. X            *(int *)data = ledstate;
  1775. X            break;
  1776. X
  1777. X        case KBDSLEDS:
  1778. X            update_led();    /* ??? */
  1779. X            break;
  1780. X
  1781. X        case KBDGLOCK:
  1782. X            *(int *)data = ( (vsp->scroll_lock) |
  1783. X                     (vsp->num_lock * 2) |
  1784. X                     (vsp->caps_lock * 4));
  1785. X            break;
  1786. X
  1787. X        case KBDSLOCK:
  1788. X            setlockkeys(*(int *)data);
  1789. X            break;
  1790. X
  1791. X        case KBDGCKEY:
  1792. X            key = ((Ovl_tbl *)data)->keynum;
  1793. X            return getckeydef(key,(Ovl_tbl *)data);        
  1794. X
  1795. X        case KBDSCKEY:
  1796. X            key = ((Ovl_tbl *)data)->keynum;
  1797. X            return setkeydef((Ovl_tbl *)data);
  1798. X
  1799. X        case KBDGOKEY:
  1800. X            key = ((Ovl_tbl *)data)->keynum;
  1801. X            return getokeydef(key,(Ovl_tbl *)data);
  1802. X
  1803. X        case KBDRMKEY:
  1804. X            key = *(int *)data;
  1805. X            return rmkeydef(key);
  1806. X
  1807. X        case KBDDEFAULT:
  1808. X            ovlinit(1);
  1809. X            break;    
  1810. X
  1811. X        default:
  1812. X            /* proceed with vga ioctls */
  1813. X            return -1;
  1814. X    }
  1815. X    return 0;
  1816. X}
  1817. X
  1818. X#if PCVT_EMU_MOUSE
  1819. X/*--------------------------------------------------------------------------*
  1820. X *    mouse emulator ioctl
  1821. X *--------------------------------------------------------------------------*/
  1822. Xint
  1823. Xmouse_ioctl(Dev_t dev, int cmd, caddr_t data)
  1824. X{
  1825. X    struct mousedefs *def = (struct mousedefs *)data;
  1826. X    
  1827. X    switch(cmd)
  1828. X    {
  1829. X        case KBDMOUSEGET:
  1830. X            *def = mousedef;
  1831. X            break;
  1832. X            
  1833. X        case KBDMOUSESET:
  1834. X            mousedef = *def;
  1835. X            break;
  1836. X            
  1837. X        default:
  1838. X            return -1;
  1839. X    }
  1840. X    return 0;
  1841. X}
  1842. X#endif    /* PCVT_EMU_MOUSE */
  1843. X
  1844. X#if PCVT_USL_VT_COMPAT
  1845. X/*---------------------------------------------------------------------------*
  1846. X *    convert ISO-8859 style keycode into IBM 437
  1847. X *---------------------------------------------------------------------------*/
  1848. Xstatic inline u_char
  1849. Xiso2ibm(u_char c)
  1850. X{
  1851. X    if(c < 0x80)
  1852. X        return c;
  1853. X    return iso2ibm437[c - 0x80];
  1854. X}
  1855. X
  1856. X/*---------------------------------------------------------------------------*
  1857. X *    build up a USL style keyboard map
  1858. X *---------------------------------------------------------------------------*/
  1859. Xvoid
  1860. Xget_usl_keymap(keymap_t *map)
  1861. X{
  1862. X    int i;
  1863. X
  1864. X    bzero((caddr_t)map, sizeof(keymap_t));
  1865. X
  1866. X    map->n_keys = 0x59;    /* that many keys we know about */
  1867. X    
  1868. X    for(i = 1; i < N_KEYNUMS; i++)
  1869. X    {
  1870. X        Ovl_tbl kdef;
  1871. X        u_char c;
  1872. X        int j;
  1873. X        int idx = key2scan1[i];
  1874. X        
  1875. X        if(idx == 0 || idx >= map->n_keys)
  1876. X            continue;
  1877. X
  1878. X        getckeydef(i, &kdef);
  1879. X        kdef.type &= KBD_MASK;
  1880. X        switch(kdef.type)
  1881. X        {
  1882. X        case KBD_ASCII:
  1883. X        case KBD_RETURN:
  1884. X            map->key[idx].map[0] = iso2ibm(kdef.unshift[0]);
  1885. X            map->key[idx].map[1] = iso2ibm(kdef.shift[0]);
  1886. X            map->key[idx].map[2] = map->key[idx].map[3] =
  1887. X                iso2ibm(kdef.ctrl[0]);
  1888. X            map->key[idx].map[4] = map->key[idx].map[5] =
  1889. X                iso2ibm(c = kdef.altgr[0]);
  1890. X            /*
  1891. X             * XXX this is a hack
  1892. X             * since we currently do not map strings to AltGr +
  1893. X             * shift, we attempt to use the unshifted AltGr
  1894. X             * definition here and try to toggle the case
  1895. X             * this should at least work for ISO8859 letters,
  1896. X             * but also for (e.g.) russian KOI-8 style
  1897. X             */
  1898. X            if((c & 0x7f) >= 0x40)
  1899. X                map->key[idx].map[5] = iso2ibm(c ^ 0x20);
  1900. X            break;
  1901. X            
  1902. X        case KBD_FUNC:
  1903. X            /* we are only interested in F1 thru F12 here */
  1904. X            if(i >= 112 && i <= 123) {
  1905. X                map->key[idx].map[0] = i - 112 + 27;
  1906. X                map->key[idx].spcl = 0x80;
  1907. X            }
  1908. X            break;
  1909. X
  1910. X        case KBD_SHIFT:
  1911. X            c = i == 44? 2 /* lSh */: 3 /* rSh */; goto special;
  1912. X
  1913. X        case KBD_CAPS:
  1914. X            c = 4; goto special;
  1915. X
  1916. X        case KBD_NUM:
  1917. X            c = 5; goto special;
  1918. X
  1919. X        case KBD_SCROLL:
  1920. X            c = 6; goto special;
  1921. X
  1922. X        case KBD_META:
  1923. X            c = 7; goto special;
  1924. X
  1925. X        case KBD_CTL:
  1926. X            c = 9; goto special;
  1927. X        special:
  1928. X            for(j = 0; j < NUM_STATES; j++)
  1929. X                map->key[idx].map[j] = c;
  1930. X            map->key[idx].spcl = 0xff;
  1931. X            break;
  1932. X            
  1933. X        default:
  1934. X            break;
  1935. X        }
  1936. X    }
  1937. X}        
  1938. X
  1939. X#endif /* PCVT_USL_VT_COMPAT */
  1940. X
  1941. X/*---------------------------------------------------------------------------*
  1942. X *    switch keypad to numeric mode
  1943. X *---------------------------------------------------------------------------*/
  1944. Xvoid
  1945. Xvt_keynum(struct video_state *svsp)
  1946. X{
  1947. X    svsp->num_lock = 1;
  1948. X    update_led();
  1949. X}
  1950. X
  1951. X/*---------------------------------------------------------------------------*
  1952. X *    switch keypad to application mode
  1953. X *---------------------------------------------------------------------------*/
  1954. Xvoid
  1955. Xvt_keyappl(struct video_state *svsp)
  1956. X{
  1957. X    svsp->num_lock = 0;
  1958. X    update_led();
  1959. X}
  1960. X
  1961. X#if PCVT_VT220KEYB
  1962. X
  1963. X/*---------------------------------------------------------------------------*
  1964. X *    function bound to function key 1
  1965. X *---------------------------------------------------------------------------*/
  1966. Xstatic void
  1967. Xfkey1(void)
  1968. X{
  1969. X    if(meta_down)
  1970. X        more_chars = (u_char *)"\033[23~"; /* F11 */
  1971. X    else
  1972. X        do_vgapage(0);
  1973. X}
  1974. X
  1975. X/*---------------------------------------------------------------------------*
  1976. X *    function bound to function key 2
  1977. X *---------------------------------------------------------------------------*/
  1978. Xstatic void
  1979. Xfkey2(void)
  1980. X{
  1981. X    if(meta_down)
  1982. X        more_chars = (u_char *)"\033[24~"; /* F12 */
  1983. X    else
  1984. X        do_vgapage(1);
  1985. X}
  1986. X
  1987. X/*---------------------------------------------------------------------------*
  1988. X *    function bound to function key 3
  1989. X *---------------------------------------------------------------------------*/
  1990. Xstatic void
  1991. Xfkey3(void)
  1992. X{
  1993. X    if(meta_down)
  1994. X        more_chars = (u_char *)"\033[25~"; /* F13 */
  1995. X    else
  1996. X        do_vgapage(2);
  1997. X}
  1998. X
  1999. X/*---------------------------------------------------------------------------*
  2000. X *    function bound to function key 4
  2001. X *---------------------------------------------------------------------------*/
  2002. Xstatic void
  2003. Xfkey4(void)
  2004. X{
  2005. X    if(meta_down)
  2006. X        more_chars = (u_char *)"\033[26~"; /* F14 */
  2007. X    else
  2008. X        do_vgapage(3);
  2009. X}
  2010. X
  2011. X/*---------------------------------------------------------------------------*
  2012. X *    function bound to function key 5
  2013. X *---------------------------------------------------------------------------*/
  2014. Xstatic void
  2015. Xfkey5(void)
  2016. X{
  2017. X    if(meta_down)
  2018. X        more_chars = (u_char *)"\033[28~"; /* Help */
  2019. X    else
  2020. X    {
  2021. X        if((current_video_screen + 1) > totalscreens-1)
  2022. X            do_vgapage(0);
  2023. X        else
  2024. X            do_vgapage(current_video_screen + 1);
  2025. X    }
  2026. X}
  2027. X
  2028. X/*---------------------------------------------------------------------------*
  2029. X *    function bound to function key 6
  2030. X *---------------------------------------------------------------------------*/
  2031. Xstatic void
  2032. Xfkey6(void)
  2033. X{
  2034. X    if(meta_down)    
  2035. X        more_chars = (u_char *)"\033[29~"; /* DO */
  2036. X    else
  2037. X        more_chars = (u_char *)"\033[17~"; /* F6 */
  2038. X}
  2039. X
  2040. X/*---------------------------------------------------------------------------*
  2041. X *    function bound to function key 7
  2042. X *---------------------------------------------------------------------------*/
  2043. Xstatic void
  2044. Xfkey7(void)
  2045. X{
  2046. X    if(meta_down)
  2047. X        more_chars = (u_char *)"\033[31~"; /* F17 */
  2048. X    else
  2049. X        more_chars = (u_char *)"\033[18~"; /* F7 */
  2050. X}
  2051. X
  2052. X/*---------------------------------------------------------------------------*
  2053. X *    function bound to function key 8
  2054. X *---------------------------------------------------------------------------*/
  2055. Xstatic void
  2056. Xfkey8(void)
  2057. X{
  2058. X    if(meta_down)
  2059. X        more_chars = (u_char *)"\033[32~"; /* F18 */
  2060. X    else
  2061. X        more_chars = (u_char *)"\033[19~"; /* F8 */
  2062. X}
  2063. X
  2064. X/*---------------------------------------------------------------------------*
  2065. X *    function bound to function key 9
  2066. X *---------------------------------------------------------------------------*/
  2067. Xstatic void
  2068. Xfkey9(void)
  2069. X{
  2070. X    if(meta_down)
  2071. X        more_chars = (u_char *)"\033[33~"; /* F19 */
  2072. X    else
  2073. X        more_chars = (u_char *)"\033[20~"; /* F9 */
  2074. X}
  2075. X
  2076. X/*---------------------------------------------------------------------------*
  2077. X *    function bound to function key 10
  2078. X *---------------------------------------------------------------------------*/
  2079. Xstatic void
  2080. Xfkey10(void)
  2081. X{
  2082. X    if(meta_down)
  2083. X        more_chars = (u_char *)"\033[34~"; /* F20 */
  2084. X    else
  2085. X        more_chars = (u_char *)"\033[21~"; /* F10 */
  2086. X}
  2087. X
  2088. X/*---------------------------------------------------------------------------*
  2089. X *    function bound to function key 11
  2090. X *---------------------------------------------------------------------------*/
  2091. Xstatic void
  2092. Xfkey11(void)
  2093. X{
  2094. X    if(meta_down)
  2095. X        more_chars = (u_char *)"\0x8FP"; /* PF1 */
  2096. X    else
  2097. X        more_chars = (u_char *)"\033[23~"; /* F11 */
  2098. X}
  2099. X
  2100. X/*---------------------------------------------------------------------------*
  2101. X *    function bound to function key 12
  2102. X *---------------------------------------------------------------------------*/
  2103. Xstatic void
  2104. Xfkey12(void)
  2105. X{
  2106. X    if(meta_down)
  2107. X        more_chars = (u_char *)"\0x8FQ"; /* PF2 */
  2108. X    else
  2109. X        more_chars = (u_char *)"\033[24~"; /* F12 */
  2110. X}
  2111. X
  2112. X/*---------------------------------------------------------------------------*
  2113. X *    function bound to SHIFTED function key 1
  2114. X *---------------------------------------------------------------------------*/
  2115. Xstatic void
  2116. Xsfkey1(void)
  2117. X{
  2118. X    if(meta_down)
  2119. X    {
  2120. X        if(vsp->ukt.length[6])    /* entry available ? */
  2121. X            more_chars = (u_char *)
  2122. X                &(vsp->udkbuf[vsp->ukt.first[6]]);
  2123. X        else
  2124. X            more_chars = (u_char *)"\033[23~"; /* F11 */
  2125. X    }
  2126. X}
  2127. X
  2128. X/*---------------------------------------------------------------------------*
  2129. X *    function bound to SHIFTED function key 2
  2130. X *---------------------------------------------------------------------------*/
  2131. Xstatic void
  2132. Xsfkey2(void)
  2133. X{
  2134. X    if(meta_down)
  2135. X    {
  2136. X        if(vsp->ukt.length[7])    /* entry available ? */
  2137. X            more_chars = (u_char *)
  2138. X                &(vsp->udkbuf[vsp->ukt.first[7]]);
  2139. X        else
  2140. X            more_chars = (u_char *)"\033[24~"; /* F12 */
  2141. X    }
  2142. X}
  2143. X
  2144. X/*---------------------------------------------------------------------------*
  2145. X *    function bound to SHIFTED function key 3
  2146. X *---------------------------------------------------------------------------*/
  2147. Xstatic void
  2148. Xsfkey3(void)
  2149. X{
  2150. X    if(meta_down)
  2151. X    {
  2152. X        if(vsp->ukt.length[8])    /* entry available ? */
  2153. X            more_chars = (u_char *)
  2154. X                &(vsp->udkbuf[vsp->ukt.first[8]]);
  2155. X        else
  2156. X            more_chars = (u_char *)"\033[25~"; /* F13 */
  2157. X    }
  2158. X}
  2159. X
  2160. X/*---------------------------------------------------------------------------*
  2161. X *    function bound to SHIFTED function key 4
  2162. X *---------------------------------------------------------------------------*/
  2163. Xstatic void
  2164. Xsfkey4(void)
  2165. X{
  2166. X    if(meta_down)
  2167. X    {
  2168. X        if(vsp->ukt.length[9])    /* entry available ? */
  2169. X            more_chars = (u_char *)
  2170. X                &(vsp->udkbuf[vsp->ukt.first[9]]);
  2171. X        else
  2172. X            more_chars = (u_char *)"\033[26~"; /* F14 */
  2173. X    }
  2174. X}
  2175. X
  2176. X/*---------------------------------------------------------------------------*
  2177. X *    function bound to SHIFTED function key 5
  2178. X *---------------------------------------------------------------------------*/
  2179. Xstatic void
  2180. Xsfkey5(void)
  2181. X{
  2182. X    if(meta_down)
  2183. X    {
  2184. X        if(vsp->ukt.length[11])    /* entry available ? */
  2185. X            more_chars = (u_char *)
  2186. X                &(vsp->udkbuf[vsp->ukt.first[11]]);
  2187. X        else
  2188. X            more_chars = (u_char *)"\033[28~"; /* Help */
  2189. X    }
  2190. X}
  2191. X
  2192. X/*---------------------------------------------------------------------------*
  2193. X *    function bound to SHIFTED function key 6
  2194. X *---------------------------------------------------------------------------*/
  2195. Xstatic void
  2196. Xsfkey6(void)
  2197. X{
  2198. X    if(!meta_down)
  2199. X    {
  2200. X        if(vsp->ukt.length[0])    /* entry available ? */
  2201. X            more_chars = (u_char *)
  2202. X                &(vsp->udkbuf[vsp->ukt.first[0]]);
  2203. X        else
  2204. X            more_chars = (u_char *)"\033[17~"; /* F6 */
  2205. X    }
  2206. X    else if(vsp->ukt.length[12])    /* entry available ? */
  2207. X            more_chars = (u_char *)
  2208. X                &(vsp->udkbuf[vsp->ukt.first[12]]);
  2209. X         else
  2210. X            more_chars = (u_char *)"\033[29~"; /* DO */
  2211. X}
  2212. X
  2213. X/*---------------------------------------------------------------------------*
  2214. X *    function bound to SHIFTED function key 7
  2215. X *---------------------------------------------------------------------------*/
  2216. Xstatic void
  2217. Xsfkey7(void)
  2218. X{
  2219. X    if(!meta_down)
  2220. X    {
  2221. X        if(vsp->ukt.length[1])    /* entry available ? */
  2222. X            more_chars = (u_char *)
  2223. X                &(vsp->udkbuf[vsp->ukt.first[1]]);
  2224. X        else
  2225. X            more_chars = (u_char *)"\033[18~"; /* F7 */
  2226. X    }
  2227. X    else if(vsp->ukt.length[14])    /* entry available ? */
  2228. X            more_chars = (u_char *)
  2229. X                &(vsp->udkbuf[vsp->ukt.first[14]]);
  2230. X         else
  2231. X            more_chars = (u_char *)"\033[31~"; /* F17 */
  2232. X}
  2233. X
  2234. X/*---------------------------------------------------------------------------*
  2235. X *    function bound to SHIFTED function key 8
  2236. X *---------------------------------------------------------------------------*/
  2237. Xstatic void
  2238. Xsfkey8(void)
  2239. X{
  2240. X    if(!meta_down)
  2241. X    {
  2242. X        if(vsp->ukt.length[2])    /* entry available ? */
  2243. X            more_chars = (u_char *)
  2244. X                &(vsp->udkbuf[vsp->ukt.first[2]]);
  2245. X        else
  2246. X            more_chars = (u_char *)"\033[19~"; /* F8 */
  2247. X    }
  2248. X    else if(vsp->ukt.length[14])    /* entry available ? */
  2249. X            more_chars = (u_char *)
  2250. X                &(vsp->udkbuf[vsp->ukt.first[15]]);
  2251. X         else
  2252. X            more_chars = (u_char *)"\033[32~"; /* F18 */
  2253. X}
  2254. X
  2255. X/*---------------------------------------------------------------------------*
  2256. X *    function bound to SHIFTED function key 9
  2257. X *---------------------------------------------------------------------------*/
  2258. Xstatic void
  2259. Xsfkey9(void)
  2260. X{
  2261. X    if(!meta_down)
  2262. X    {
  2263. X        if(vsp->ukt.length[3])    /* entry available ? */
  2264. X            more_chars = (u_char *)
  2265. X                &(vsp->udkbuf[vsp->ukt.first[3]]);
  2266. X        else
  2267. X            more_chars = (u_char *)"\033[20~"; /* F9 */
  2268. X    }
  2269. X    else if(vsp->ukt.length[16])    /* entry available ? */
  2270. X            more_chars = (u_char *)
  2271. X                &(vsp->udkbuf[vsp->ukt.first[16]]);
  2272. X         else
  2273. X            more_chars = (u_char *)"\033[33~"; /* F19 */
  2274. X}
  2275. X
  2276. X/*---------------------------------------------------------------------------*
  2277. X *    function bound to SHIFTED function key 10
  2278. X *---------------------------------------------------------------------------*/
  2279. Xstatic void
  2280. Xsfkey10(void)
  2281. X{
  2282. X    if(!meta_down)
  2283. X    {
  2284. X        if(vsp->ukt.length[4])    /* entry available ? */
  2285. X            more_chars = (u_char *)
  2286. X                &(vsp->udkbuf[vsp->ukt.first[4]]);
  2287. X        else
  2288. X            more_chars = (u_char *)"\033[21~"; /* F10 */
  2289. X    }
  2290. X    else if(vsp->ukt.length[17])    /* entry available ? */
  2291. X            more_chars = (u_char *)
  2292. X                &(vsp->udkbuf[vsp->ukt.first[17]]);
  2293. X         else
  2294. X            more_chars = (u_char *)"\033[34~"; /* F20 */
  2295. X}
  2296. X
  2297. X/*---------------------------------------------------------------------------*
  2298. X *    function bound to SHIFTED function key 11
  2299. X *---------------------------------------------------------------------------*/
  2300. Xstatic void
  2301. Xsfkey11(void)
  2302. X{
  2303. X    if(!meta_down)
  2304. X    {
  2305. X        if(vsp->ukt.length[6])    /* entry available ? */
  2306. X            more_chars = (u_char *)
  2307. X                &(vsp->udkbuf[vsp->ukt.first[6]]);
  2308. X        else
  2309. X            more_chars = (u_char *)"\033[23~"; /* F11 */
  2310. X    }
  2311. X}
  2312. X
  2313. X/*---------------------------------------------------------------------------*
  2314. X *    function bound to SHIFTED function key 12
  2315. X *---------------------------------------------------------------------------*/
  2316. Xstatic void
  2317. Xsfkey12(void)
  2318. X{
  2319. X    if(!meta_down)
  2320. X    {
  2321. X        if(vsp->ukt.length[7])    /* entry available ? */
  2322. X            more_chars = (u_char *)
  2323. X                &(vsp->udkbuf[vsp->ukt.first[7]]);
  2324. X        else
  2325. X            more_chars = (u_char *)"\033[24~"; /* F12 */
  2326. X    }
  2327. X}
  2328. X
  2329. X/*---------------------------------------------------------------------------*
  2330. X *    function bound to control function key 1
  2331. X *---------------------------------------------------------------------------*/
  2332. Xstatic void
  2333. Xcfkey1(void)
  2334. X{
  2335. X}
  2336. X
  2337. X/*---------------------------------------------------------------------------*
  2338. X *    function bound to control function key 2
  2339. X *---------------------------------------------------------------------------*/
  2340. Xstatic void
  2341. Xcfkey2(void)
  2342. X{
  2343. X}
  2344. X
  2345. X/*---------------------------------------------------------------------------*
  2346. X *    function bound to control function key 3
  2347. X *---------------------------------------------------------------------------*/
  2348. Xstatic void
  2349. Xcfkey3(void)
  2350. X{
  2351. X}
  2352. X
  2353. X/*---------------------------------------------------------------------------*
  2354. X *    function bound to control function key 4
  2355. X *---------------------------------------------------------------------------*/
  2356. Xstatic void
  2357. Xcfkey4(void)
  2358. X{
  2359. X}
  2360. X
  2361. X/*---------------------------------------------------------------------------*
  2362. X *    function bound to control function key 5
  2363. X *---------------------------------------------------------------------------*/
  2364. Xstatic void
  2365. Xcfkey5(void)
  2366. X{
  2367. X    if(vsp->which_fkl == SYS_FKL)
  2368. X        toggl_bell(vsp);
  2369. X}
  2370. X
  2371. X/*---------------------------------------------------------------------------*
  2372. X *    function bound to control function key 6
  2373. X *---------------------------------------------------------------------------*/
  2374. Xstatic void
  2375. Xcfkey6(void)
  2376. X{
  2377. X    if(vsp->which_fkl == SYS_FKL)    
  2378. X        toggl_sevenbit(vsp);
  2379. X}
  2380. X
  2381. X/*---------------------------------------------------------------------------*
  2382. X *    function bound to control function key 7
  2383. X *---------------------------------------------------------------------------*/
  2384. Xstatic void
  2385. Xcfkey7(void)
  2386. X{
  2387. X    if(vsp->which_fkl == SYS_FKL)
  2388. X        toggl_dspf(vsp);
  2389. X}
  2390. X
  2391. X/*---------------------------------------------------------------------------*
  2392. X *    function bound to control function key 8
  2393. X *---------------------------------------------------------------------------*/
  2394. Xstatic void
  2395. Xcfkey8(void)
  2396. X{
  2397. X    if(vsp->which_fkl == SYS_FKL)    
  2398. X        toggl_awm(vsp);
  2399. X}
  2400. X
  2401. X/*---------------------------------------------------------------------------*
  2402. X *    function bound to control function key 9
  2403. X *---------------------------------------------------------------------------*/
  2404. Xstatic void
  2405. Xcfkey9(void)
  2406. X{
  2407. X    if(vsp->labels_on)    /* toggle label display on/off */
  2408. X            fkl_off(vsp);
  2409. X    else
  2410. X            fkl_on(vsp);
  2411. X}
  2412. X
  2413. X/*---------------------------------------------------------------------------*
  2414. X *    function bound to control function key 10
  2415. X *---------------------------------------------------------------------------*/
  2416. Xstatic void
  2417. Xcfkey10(void)
  2418. X{
  2419. X    if(vsp->labels_on)    /* toggle user/system fkey labels */
  2420. X    {
  2421. X        if(vsp->which_fkl == USR_FKL)
  2422. X            sw_sfkl(vsp);
  2423. X        else if(vsp->which_fkl == SYS_FKL)
  2424. X            sw_ufkl(vsp);
  2425. X    }
  2426. X}
  2427. X
  2428. X/*---------------------------------------------------------------------------*
  2429. X *    function bound to control function key 11
  2430. X *---------------------------------------------------------------------------*/
  2431. Xstatic void
  2432. Xcfkey11(void)
  2433. X{
  2434. X    if(vsp->vt_pure_mode == M_PUREVT)
  2435. X            set_emulation_mode(vsp, M_HPVT);
  2436. X    else if(vsp->vt_pure_mode == M_HPVT)
  2437. X            set_emulation_mode(vsp, M_PUREVT);
  2438. X}
  2439. X
  2440. X/*---------------------------------------------------------------------------*
  2441. X *    function bound to control function key 12
  2442. X *---------------------------------------------------------------------------*/
  2443. Xstatic void
  2444. Xcfkey12(void)
  2445. X{
  2446. X}
  2447. X
  2448. X#else    /* !PCVT_VT220KEYB, HP-like Keyboard layout */
  2449. X
  2450. X/*---------------------------------------------------------------------------*
  2451. X *    function bound to function key 1
  2452. X *---------------------------------------------------------------------------*/
  2453. Xstatic void
  2454. Xfkey1(void)
  2455. X{
  2456. X    if(!meta_down)
  2457. X    {
  2458. X        if((vsp->vt_pure_mode == M_HPVT)
  2459. X           && (vsp->which_fkl == SYS_FKL))
  2460. X            toggl_columns(vsp);
  2461. X        else
  2462. X            more_chars = (u_char *)"\033[17~";    /* F6 */
  2463. X    }
  2464. X    else
  2465. X    {
  2466. X        if(vsp->vt_pure_mode == M_PUREVT
  2467. X           || (vsp->which_fkl == USR_FKL))
  2468. X            more_chars = (u_char *)"\033[26~";    /* F14 */
  2469. X    }
  2470. X}
  2471. X
  2472. X/*---------------------------------------------------------------------------*
  2473. X *    function bound to function key 2
  2474. X *---------------------------------------------------------------------------*/
  2475. Xstatic void
  2476. Xfkey2(void)
  2477. X{
  2478. X    if(!meta_down)
  2479. X    {
  2480. X        if((vsp->vt_pure_mode == M_HPVT)
  2481. X           && (vsp->which_fkl == SYS_FKL))
  2482. X            vt_ris(vsp);
  2483. X        else
  2484. X            more_chars = (u_char *)"\033[18~";    /* F7 */
  2485. X    }
  2486. X    else
  2487. X    {
  2488. X        if(vsp->vt_pure_mode == M_PUREVT
  2489. X           || (vsp->which_fkl == USR_FKL))
  2490. X            more_chars = (u_char *)"\033[28~";    /* HELP */
  2491. X    }
  2492. X}
  2493. X
  2494. X/*---------------------------------------------------------------------------*
  2495. X *    function bound to function key 3
  2496. X *---------------------------------------------------------------------------*/
  2497. Xstatic void
  2498. Xfkey3(void)
  2499. X{
  2500. X    if(!meta_down)
  2501. X    {
  2502. X        if((vsp->vt_pure_mode == M_HPVT)
  2503. X           && (vsp->which_fkl == SYS_FKL))
  2504. X            toggl_24l(vsp);
  2505. X        else
  2506. X            more_chars = (u_char *)"\033[19~";    /* F8 */
  2507. X    }
  2508. X    else
  2509. X    {
  2510. X        if(vsp->vt_pure_mode == M_PUREVT
  2511. X           || (vsp->which_fkl == USR_FKL))
  2512. X            more_chars = (u_char *)"\033[29~";    /* DO */
  2513. X    }
  2514. X}
  2515. X
  2516. X/*---------------------------------------------------------------------------*
  2517. X *    function bound to function key 4
  2518. X *---------------------------------------------------------------------------*/
  2519. Xstatic void
  2520. Xfkey4(void)
  2521. X{
  2522. X    if(!meta_down)
  2523. X    {
  2524. X
  2525. X#if PCVT_SHOWKEYS
  2526. X        if((vsp->vt_pure_mode == M_HPVT)
  2527. X           && (vsp->which_fkl == SYS_FKL))
  2528. X            toggl_kbddbg(vsp);
  2529. X        else
  2530. X            more_chars = (u_char *)"\033[20~";    /* F9 */
  2531. X#else
  2532. X        if(vsp->vt_pure_mode == M_PUREVT
  2533. X           || (vsp->which_fkl == USR_FKL))
  2534. X            more_chars = (u_char *)"\033[20~";    /* F9 */
  2535. X#endif /* PCVT_SHOWKEYS */
  2536. X
  2537. X    }
  2538. X    else
  2539. X    {
  2540. X        if(vsp->vt_pure_mode == M_PUREVT
  2541. X           || (vsp->which_fkl == USR_FKL))
  2542. X            more_chars = (u_char *)"\033[31~";    /* F17 */
  2543. X    }
  2544. X}
  2545. X
  2546. X/*---------------------------------------------------------------------------*
  2547. X *    function bound to function key 5
  2548. X *---------------------------------------------------------------------------*/
  2549. Xstatic void
  2550. Xfkey5(void)
  2551. X{
  2552. X    if(!meta_down)
  2553. X    {
  2554. X        if((vsp->vt_pure_mode == M_HPVT)
  2555. X           && (vsp->which_fkl == SYS_FKL))    
  2556. X            toggl_bell(vsp);
  2557. X        else
  2558. X            more_chars = (u_char *)"\033[21~";    /* F10 */
  2559. X    }
  2560. X    else
  2561. X    {
  2562. X        if(vsp->vt_pure_mode == M_PUREVT
  2563. X           || (vsp->which_fkl == USR_FKL))
  2564. X            more_chars = (u_char *)"\033[32~";    /* F18 */
  2565. X    }
  2566. X}
  2567. X
  2568. X/*---------------------------------------------------------------------------*
  2569. X *    function bound to function key 6
  2570. X *---------------------------------------------------------------------------*/
  2571. Xstatic void
  2572. Xfkey6(void)
  2573. X{
  2574. X    if(!meta_down)
  2575. X    {
  2576. X        if((vsp->vt_pure_mode == M_HPVT)
  2577. X           && (vsp->which_fkl == SYS_FKL))    
  2578. X            toggl_sevenbit(vsp);
  2579. X        else
  2580. X            more_chars = (u_char *)"\033[23~";    /* F11 */
  2581. X    }
  2582. X    else
  2583. X    {
  2584. X        if(vsp->vt_pure_mode == M_PUREVT
  2585. X           || (vsp->which_fkl == USR_FKL))
  2586. X            more_chars = (u_char *)"\033[33~";    /* F19 */
  2587. X    }
  2588. X}
  2589. X
  2590. X/*---------------------------------------------------------------------------*
  2591. X *    function bound to function key 7
  2592. X *---------------------------------------------------------------------------*/
  2593. Xstatic void
  2594. Xfkey7(void)
  2595. X{
  2596. X    if(!meta_down)
  2597. X    {
  2598. X        if((vsp->vt_pure_mode == M_HPVT)
  2599. X           && (vsp->which_fkl == SYS_FKL))
  2600. X            toggl_dspf(vsp);
  2601. X        else
  2602. X            more_chars = (u_char *)"\033[24~";    /* F12 */
  2603. X    }
  2604. X    else
  2605. X    {
  2606. X        if(vsp->vt_pure_mode == M_PUREVT
  2607. X           || (vsp->which_fkl == USR_FKL))
  2608. X            more_chars = (u_char *)"\033[34~";    /* F20 */
  2609. X    }
  2610. X}
  2611. X
  2612. X/*---------------------------------------------------------------------------*
  2613. X *    function bound to function key 8
  2614. X *---------------------------------------------------------------------------*/
  2615. Xstatic void
  2616. Xfkey8(void)
  2617. X{
  2618. X    if(!meta_down)
  2619. X    {
  2620. X        if((vsp->vt_pure_mode == M_HPVT)
  2621. X           && (vsp->which_fkl == SYS_FKL))    
  2622. X            toggl_awm(vsp);
  2623. X        else
  2624. X            more_chars = (u_char *)"\033[25~";    /* F13 */
  2625. X    }
  2626. X    else
  2627. X    {
  2628. X        if(vsp->vt_pure_mode == M_PUREVT
  2629. X           || (vsp->which_fkl == USR_FKL))
  2630. X            more_chars = (u_char *)"\033[35~";    /* F21 ??!! */
  2631. X    }
  2632. X}
  2633. X
  2634. X/*---------------------------------------------------------------------------*
  2635. X *    function bound to function key 9
  2636. X *---------------------------------------------------------------------------*/
  2637. Xstatic void
  2638. Xfkey9(void)
  2639. X{
  2640. X    if(meta_down)
  2641. X    {
  2642. X        if(vsp->vt_pure_mode == M_PUREVT)
  2643. X            return;
  2644. X    
  2645. X        if(vsp->labels_on)    /* toggle label display on/off */
  2646. X            fkl_off(vsp);
  2647. X        else
  2648. X            fkl_on(vsp);
  2649. X    }
  2650. X    else
  2651. X    {
  2652. X        do_vgapage(0);
  2653. X    }
  2654. X}
  2655. X
  2656. X/*---------------------------------------------------------------------------*
  2657. X *    function bound to function key 10
  2658. X *---------------------------------------------------------------------------*/
  2659. Xstatic void
  2660. Xfkey10(void)
  2661. X{
  2662. X    if(meta_down)
  2663. X    {
  2664. X        if(vsp->vt_pure_mode != M_PUREVT && vsp->labels_on)
  2665. X        {
  2666. X            if(vsp->which_fkl == USR_FKL)
  2667. X                sw_sfkl(vsp);
  2668. X            else if(vsp->which_fkl == SYS_FKL)
  2669. X                sw_ufkl(vsp);
  2670. X        }
  2671. X    }
  2672. X    else
  2673. X    {
  2674. X        do_vgapage(1);
  2675. X    }
  2676. X}
  2677. X
  2678. X/*---------------------------------------------------------------------------*
  2679. X *    function bound to function key 11
  2680. X *---------------------------------------------------------------------------*/
  2681. Xstatic void
  2682. Xfkey11(void)
  2683. X{
  2684. X    if(meta_down)
  2685. X    {
  2686. X        if(vsp->vt_pure_mode == M_PUREVT)
  2687. X            set_emulation_mode(vsp, M_HPVT);
  2688. X        else if(vsp->vt_pure_mode == M_HPVT)
  2689. X            set_emulation_mode(vsp, M_PUREVT);
  2690. X    }
  2691. X    else
  2692. X    {
  2693. X        do_vgapage(2);
  2694. X    }
  2695. X}
  2696. X
  2697. X/*---------------------------------------------------------------------------*
  2698. X *    function bound to function key 12
  2699. X *---------------------------------------------------------------------------*/
  2700. Xstatic void
  2701. Xfkey12(void)
  2702. X{
  2703. X    if(meta_down)
  2704. X    {
  2705. X        if(current_video_screen + 1 > totalscreens-1)
  2706. X            do_vgapage(0);
  2707. X        else
  2708. X            do_vgapage(current_video_screen + 1);
  2709. X    }
  2710. X    else
  2711. X    {
  2712. X        do_vgapage(3);
  2713. X    }
  2714. X}
  2715. X
  2716. X/*---------------------------------------------------------------------------*
  2717. X *    function bound to SHIFTED function key 1
  2718. X *---------------------------------------------------------------------------*/
  2719. Xstatic void
  2720. Xsfkey1(void)
  2721. X{
  2722. X    if(!meta_down)
  2723. X    {
  2724. X        if(vsp->ukt.length[0])    /* entry available ? */
  2725. X            more_chars = (u_char *)
  2726. X                &(vsp->udkbuf[vsp->ukt.first[0]]);
  2727. X    }
  2728. X    else
  2729. X    {
  2730. X        if(vsp->ukt.length[9])    /* entry available ? */
  2731. X            more_chars = (u_char *)
  2732. X                &(vsp->udkbuf[vsp->ukt.first[9]]);
  2733. X    }
  2734. X}
  2735. X
  2736. X/*---------------------------------------------------------------------------*
  2737. X *    function bound to SHIFTED function key 2
  2738. X *---------------------------------------------------------------------------*/
  2739. Xstatic void
  2740. Xsfkey2(void)
  2741. X{
  2742. X    if(!meta_down)
  2743. X    {
  2744. X        if(vsp->ukt.length[1])    /* entry available ? */
  2745. X            more_chars = (u_char *)
  2746. X                &(vsp->udkbuf[vsp->ukt.first[1]]);
  2747. X    }
  2748. X    else
  2749. X    {
  2750. X        if(vsp->ukt.length[11])    /* entry available ? */
  2751. X            more_chars = (u_char *)
  2752. X                &(vsp->udkbuf[vsp->ukt.first[11]]);
  2753. X    }
  2754. X}
  2755. X
  2756. X/*---------------------------------------------------------------------------*
  2757. X *    function bound to SHIFTED function key 3
  2758. X *---------------------------------------------------------------------------*/
  2759. Xstatic void
  2760. Xsfkey3(void)
  2761. X{
  2762. X    if(!meta_down)
  2763. X    {
  2764. X        if(vsp->ukt.length[2])    /* entry available ? */
  2765. X            more_chars = (u_char *)
  2766. X                &(vsp->udkbuf[vsp->ukt.first[2]]);
  2767. X    }
  2768. X    else
  2769. X    {
  2770. X        if(vsp->ukt.length[12])    /* entry available ? */
  2771. X            more_chars = (u_char *)
  2772. X                &(vsp->udkbuf[vsp->ukt.first[12]]);
  2773. X    }
  2774. X}
  2775. X
  2776. X/*---------------------------------------------------------------------------*
  2777. X *    function bound to SHIFTED function key 4
  2778. X *---------------------------------------------------------------------------*/
  2779. Xstatic void
  2780. Xsfkey4(void)
  2781. X{
  2782. X    if(!meta_down)
  2783. X    {
  2784. X        if(vsp->ukt.length[3])    /* entry available ? */
  2785. X            more_chars = (u_char *)
  2786. X                &(vsp->udkbuf[vsp->ukt.first[3]]);
  2787. X    }
  2788. X    else
  2789. X    {
  2790. X        if(vsp->ukt.length[13])    /* entry available ? */
  2791. X            more_chars = (u_char *)
  2792. X                &(vsp->udkbuf[vsp->ukt.first[13]]);
  2793. X    }
  2794. X}
  2795. X
  2796. X/*---------------------------------------------------------------------------*
  2797. X *    function bound to SHIFTED function key 5
  2798. X *---------------------------------------------------------------------------*/
  2799. Xstatic void
  2800. Xsfkey5(void)
  2801. X{
  2802. X    if(!meta_down)
  2803. X    {
  2804. X        if(vsp->ukt.length[4])    /* entry available ? */
  2805. X            more_chars = (u_char *)
  2806. X                &(vsp->udkbuf[vsp->ukt.first[4]]);
  2807. X    }
  2808. X    else
  2809. X    {
  2810. X        if(vsp->ukt.length[14])    /* entry available ? */
  2811. X            more_chars = (u_char *)
  2812. X                &(vsp->udkbuf[vsp->ukt.first[14]]);
  2813. X    }
  2814. X}
  2815. X
  2816. X/*---------------------------------------------------------------------------*
  2817. X *    function bound to SHIFTED function key 6
  2818. X *---------------------------------------------------------------------------*/
  2819. Xstatic void
  2820. Xsfkey6(void)
  2821. X{
  2822. X    if(!meta_down)
  2823. X    {
  2824. X        if(vsp->ukt.length[6])    /* entry available ? */
  2825. X            more_chars = (u_char *)
  2826. X                &(vsp->udkbuf[vsp->ukt.first[6]]);
  2827. X    }
  2828. X    else
  2829. X    {
  2830. X        if(vsp->ukt.length[15])    /* entry available ? */
  2831. X            more_chars = (u_char *)
  2832. X                &(vsp->udkbuf[vsp->ukt.first[15]]);
  2833. X    }
  2834. X}
  2835. X
  2836. X/*---------------------------------------------------------------------------*
  2837. X *    function bound to SHIFTED function key 7
  2838. X *---------------------------------------------------------------------------*/
  2839. Xstatic void
  2840. Xsfkey7(void)
  2841. X{
  2842. X    if(!meta_down)
  2843. X    {
  2844. X        if(vsp->ukt.length[7])    /* entry available ? */
  2845. X            more_chars = (u_char *)
  2846. X                &(vsp->udkbuf[vsp->ukt.first[7]]);
  2847. X    }
  2848. X    else
  2849. X    {
  2850. X        if(vsp->ukt.length[16])    /* entry available ? */
  2851. X            more_chars = (u_char *)
  2852. X                &(vsp->udkbuf[vsp->ukt.first[16]]);
  2853. X    }
  2854. X}
  2855. X
  2856. X/*---------------------------------------------------------------------------*
  2857. X *    function bound to SHIFTED function key 8
  2858. X *---------------------------------------------------------------------------*/
  2859. Xstatic void
  2860. Xsfkey8(void)
  2861. X{
  2862. X    if(!meta_down)
  2863. X    {
  2864. X        if(vsp->ukt.length[8])    /* entry available ? */
  2865. X            more_chars = (u_char *)
  2866. X                &(vsp->udkbuf[vsp->ukt.first[8]]);
  2867. X    }
  2868. X    else
  2869. X    {
  2870. X        if(vsp->ukt.length[17])    /* entry available ? */
  2871. X            more_chars = (u_char *)
  2872. X                &(vsp->udkbuf[vsp->ukt.first[17]]);
  2873. X    }
  2874. X}
  2875. X/*---------------------------------------------------------------------------*
  2876. X *    function bound to SHIFTED function key 9
  2877. X *---------------------------------------------------------------------------*/
  2878. Xstatic void
  2879. Xsfkey9(void)
  2880. X{
  2881. X}
  2882. X
  2883. X/*---------------------------------------------------------------------------*
  2884. X *    function bound to SHIFTED function key 10
  2885. X *---------------------------------------------------------------------------*/
  2886. Xstatic void
  2887. Xsfkey10(void)
  2888. X{
  2889. X}
  2890. X
  2891. X/*---------------------------------------------------------------------------*
  2892. X *    function bound to SHIFTED function key 11
  2893. X *---------------------------------------------------------------------------*/
  2894. Xstatic void
  2895. Xsfkey11(void)
  2896. X{
  2897. X}
  2898. X
  2899. X/*---------------------------------------------------------------------------*
  2900. X *    function bound to SHIFTED function key 12
  2901. X *---------------------------------------------------------------------------*/
  2902. Xstatic void
  2903. Xsfkey12(void)
  2904. X{
  2905. X}
  2906. X
  2907. X/*---------------------------------------------------------------------------*
  2908. X *    function bound to control function key 1
  2909. X *---------------------------------------------------------------------------*/
  2910. Xstatic void
  2911. Xcfkey1(void)
  2912. X{
  2913. X    if(meta_down)
  2914. X        do_vgapage(0);
  2915. X}
  2916. X
  2917. X/*---------------------------------------------------------------------------*
  2918. X *    function bound to control function key 2
  2919. X *---------------------------------------------------------------------------*/
  2920. Xstatic void
  2921. Xcfkey2(void)
  2922. X{
  2923. X    if(meta_down)
  2924. X        do_vgapage(1);
  2925. X}
  2926. X
  2927. X/*---------------------------------------------------------------------------*
  2928. X *    function bound to control function key 3
  2929. X *---------------------------------------------------------------------------*/
  2930. Xstatic void
  2931. Xcfkey3(void)
  2932. X{
  2933. X    if(meta_down)
  2934. X        do_vgapage(2);
  2935. X}
  2936. X
  2937. X/*---------------------------------------------------------------------------*
  2938. X *    function bound to control function key 4
  2939. X *---------------------------------------------------------------------------*/
  2940. Xstatic void
  2941. Xcfkey4(void)
  2942. X{
  2943. X    if(meta_down)
  2944. X        do_vgapage(3);
  2945. X}
  2946. X
  2947. X/*---------------------------------------------------------------------------*
  2948. X *    function bound to control function key 5
  2949. X *---------------------------------------------------------------------------*/
  2950. Xstatic void
  2951. Xcfkey5(void)
  2952. X{
  2953. X    if(meta_down)
  2954. X        do_vgapage(4);
  2955. X}
  2956. X
  2957. X/*---------------------------------------------------------------------------*
  2958. X *    function bound to control function key 6
  2959. X *---------------------------------------------------------------------------*/
  2960. Xstatic void
  2961. Xcfkey6(void)
  2962. X{
  2963. X    if(meta_down)
  2964. X        do_vgapage(5);
  2965. X}
  2966. X
  2967. X/*---------------------------------------------------------------------------*
  2968. X *    function bound to control function key 7
  2969. X *---------------------------------------------------------------------------*/
  2970. Xstatic void
  2971. Xcfkey7(void)
  2972. X{
  2973. X    if(meta_down)
  2974. X        do_vgapage(6);
  2975. X}
  2976. X
  2977. X/*---------------------------------------------------------------------------*
  2978. X *    function bound to control function key 8
  2979. X *---------------------------------------------------------------------------*/
  2980. Xstatic void
  2981. Xcfkey8(void)
  2982. X{
  2983. X    if(meta_down)
  2984. X        do_vgapage(7);
  2985. X}
  2986. X
  2987. X/*---------------------------------------------------------------------------*
  2988. X *    function bound to control function key 9
  2989. X *---------------------------------------------------------------------------*/
  2990. Xstatic void
  2991. Xcfkey9(void)
  2992. X{
  2993. X    if(meta_down)
  2994. X        do_vgapage(8);
  2995. X}
  2996. X
  2997. X/*---------------------------------------------------------------------------*
  2998. X *    function bound to control function key 10
  2999. X *---------------------------------------------------------------------------*/
  3000. Xstatic void
  3001. Xcfkey10(void)
  3002. X{
  3003. X    if(meta_down)
  3004. X        do_vgapage(9);
  3005. X}
  3006. X
  3007. X/*---------------------------------------------------------------------------*
  3008. X *    function bound to control function key 11
  3009. X *---------------------------------------------------------------------------*/
  3010. Xstatic void
  3011. Xcfkey11(void)
  3012. X{
  3013. X    if(meta_down)
  3014. X        do_vgapage(10);
  3015. X}
  3016. X
  3017. X/*---------------------------------------------------------------------------*
  3018. X *    function bound to control function key 12
  3019. X *---------------------------------------------------------------------------*/
  3020. Xstatic void
  3021. Xcfkey12(void)
  3022. X{
  3023. X    if(meta_down)
  3024. X        do_vgapage(11);
  3025. X}
  3026. X
  3027. X#endif    /* PCVT_VT220KEYB */
  3028. X
  3029. X#endif    /* NVT > 0 */
  3030. X
  3031. X/* ------------------------------- EOF -------------------------------------*/
  3032. END_OF_FILE
  3033.   if test 85774 -ne `wc -c <'pcvt/pcvt_kbd.c'`; then
  3034.     echo shar: \"'pcvt/pcvt_kbd.c'\" unpacked with wrong size!
  3035.   fi
  3036.   # end of 'pcvt/pcvt_kbd.c'
  3037. fi
  3038. echo shar: End of archive 2 \(of 13\).
  3039. cp /dev/null ark2isdone
  3040. MISSING=""
  3041. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 ; do
  3042.     if test ! -f ark${I}isdone ; then
  3043.     MISSING="${MISSING} ${I}"
  3044.     fi
  3045. done
  3046. if test "${MISSING}" = "" ; then
  3047.     echo You have unpacked all 13 archives.
  3048.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  3049. else
  3050.     echo You still must unpack the following archives:
  3051.     echo "        " ${MISSING}
  3052. fi
  3053. exit 0
  3054. exit 0 # Just in case...
  3055.