*BSD News Article 9913


Return to BSD News archive

Received: by minnie.vk1xwt.ampr.org with NNTP
	id AA6795 ; Fri, 15 Jan 93 10:34:35 EST
Xref: sserve comp.unix.bsd:9970 alt.sources:4991
Path: sserve!manuel.anu.edu.au!munnari.oz.au!sgiblab!darwin.sura.net!newsserver.jvnc.net!yale.edu!ira.uka.de!Germany.EU.net!hcshh!hm
From: hm@hcshh.hcs.de (Hellmuth Michaelis)
Newsgroups: comp.unix.bsd,alt.sources
Subject: [386BSD] pcvt 2.00 - VT220 console driver (part 09/11)
Summary: 386BSD 0.1 VT220 console device driver source code
Keywords: 386BSD console driver VT220
Message-ID: <1625@hcshh.hcs.de>
Date: 15 Jan 93 13:03:06 GMT
Followup-To: comp.unix.bsd
Organization: HCS GmbH, Hamburg, Europe
Lines: 2525

Submitted-by: hm@hcshh.hcs.de (Hellmuth Michaelis)
Archive-name: pcvt-2.00/part09

---- Cut Here and unpack ----
#!/bin/sh
# This is part 09 of pcvt-2.00
if touch 2>&1 | fgrep '[-amc]' > /dev/null
 then TOUCH=touch
 else TOUCH=true
fi
# ============= pcvt_kbd.c ==============
if test X"$1" != X"-c" -a -f 'pcvt_kbd.c'; then
	echo "File already exists: skipping 'pcvt_kbd.c'"
else
echo "x - extracting pcvt_kbd.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > pcvt_kbd.c &&
X/*
X * Copyright (c) 1992, 1993 Hellmuth Michaelis, Brian Dunford-Shore,
X * and Holger Veit.
X *
X * All rights reserved.
X *
X * This code is derived from software contributed to Berkeley by
X * William Jolitz and Don Ahn.
X *
X * This driver is contributed to the 386BSD operating system.
X *
X * Redistribution and use in source and binary forms, with or without
X * modification, are permitted provided that the following conditions
X * are met:
X * 1. Redistributions of source code must retain the above copyright
X *    notice, this list of conditions and the following disclaimer.
X * 2. Redistributions in binary form must reproduce the above copyright
X *    notice, this list of conditions and the following disclaimer in the
X *    documentation and/or other materials provided with the distribution.
X * 3. All advertising materials mentioning features or use of this software
X *    must display the following acknowledgement:
X *	This product includes software contributed to 386BSD and developed
X *      by Hellmuth Michaelis, Brian Dunford-Shore and Holger Veit
X * 4. Neither the name of the developers nor the names "386BSD" and "pcvt"
X *    may be used to endorse or promote products derived from this software
X *    without specific prior written permission.
X *
X * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
X * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
X * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
X * IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
X * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
X * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
X * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
X * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
X * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
X * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
X */
X
X/*
X *	@(#)pcvt_kbd.c		2.00		   (contributed to 386BSD)
X *				Last Edit-Date: [Tue Jan 12 13:56:15 1993]
X */
X
X/*---------------------------------------------------------------------------*
X *
X *	pcvt_kbd.c	VT220 Driver Keyboard Interface Code
X *	----------------------------------------------------
X *
X *	written by Hellmuth Michaelis, hm@hcshh.hcs.de
X *	based on code from Holger Veit, veit@du9ds3.uni-duisburg.de
X *	
X *	-hv	23/07/92 use at your own risk! national keyboard support
X *	-hv	25/07/92 split into kbd.c vga.c pccons.c
X *	-hm	integration into vt100 emulator, running under 0.1
X *	-hm	making keys bind to functions, new structure
X *	-hm	same functionality as for 0.0
X *	-hm	kbd_cmd() updated
X *	-hm	fkey changes, cleanups
X *	-hm	keypad numeric mode (num lock) and keypad application mode
X *	-hm	cursor keypad mode
X * 	-hm	pf1 .. pf4
X *	-hm	dec user defined keys
X *	-hm	keyboard layout choices for fkey placements etc.
X *	-hm	changing alt-f9..alt-f12 for hp-keyboard layout
X *	-hm	activating keys for german keyboard ...
X *	-hm	returning key-subtype in keyboard ioctls
X *
X *---------------------------------------------------------------------------*/
X
X#include "pcvt_hdr.h"		/* global include */
X
Xstatic void fkey1 ( void );
Xstatic void fkey2 ( void );
Xstatic void fkey3 ( void );
Xstatic void fkey4 ( void );
Xstatic void fkey5 ( void );
Xstatic void fkey6 ( void );
Xstatic void fkey7 ( void );
Xstatic void fkey8 ( void );
Xstatic void fkey9 ( void );
Xstatic void fkey10 ( void );
Xstatic void fkey11 ( void );
Xstatic void fkey12 ( void );
Xstatic void sfkey1 ( void );
Xstatic void sfkey2 ( void );
Xstatic void sfkey3 ( void );
Xstatic void sfkey4 ( void );
Xstatic void sfkey5 ( void );
Xstatic void sfkey6 ( void );
Xstatic void sfkey7 ( void );
Xstatic void sfkey8 ( void );
X
X#ifdef VT220_KEYBOARDLAYOUT
X
Xstatic void sfkey9 ( void );
Xstatic void sfkey10 ( void );
Xstatic void sfkey11 ( void );
Xstatic void sfkey12 ( void );
Xstatic void cfkey1 ( void );
Xstatic void cfkey2 ( void );
Xstatic void cfkey3 ( void );
Xstatic void cfkey4 ( void );
Xstatic void cfkey5 ( void );
Xstatic void cfkey6 ( void );
Xstatic void cfkey7 ( void );
Xstatic void cfkey8 ( void );
Xstatic void cfkey9 ( void );
Xstatic void cfkey10 ( void );
Xstatic void cfkey11 ( void );
Xstatic void cfkey12 ( void );
X
X#endif
X
Xstatic doreset ( void );
Xstatic ovlinit ( int force );
Xstatic int getokeydef ( unsigned key, struct kbd_ovlkey *thisdef );
Xstatic int getckeydef ( unsigned key, struct kbd_ovlkey *thisdef );
Xstatic u_char *xlatkey2ascii( u_short key );
Xstatic void settpmrate ( int rate );
Xstatic void setlockkeys ( int snc );
Xstatic int rmkeydef ( int key );
Xstatic int setkeydef ( struct kbd_ovlkey *data );
X
Xstatic int ledstate = 0;	/* keyboard led's */
X
Xstatic int tpmrate = KBD_TPD500|KBD_TPM100;
X
Xstatic u_char	altkpflag = 0;
Xstatic u_short	altkpval = 0;
X
X/*---------------------------------------------------------------------------*
X *	this is one sub-entry for the table. the type can be either
X *	"pointer to a string" or "pointer to a function"
X *---------------------------------------------------------------------------*/
Xtypedef struct
X{
X	u_char subtype;			/* subtype, string or function */
X	union what
X	{
X		u_char *string;		/* ptr to string, null terminated */
X		void (*func)();		/* ptr to function */
X	} what;
X} entry;
X
X/*---------------------------------------------------------------------------*
X *	this is the "outer" table 
X *---------------------------------------------------------------------------*/
Xtypedef struct
X{
X	u_short	type;			/* type of key */
X	u_short	ovlindex;		/* -hv- index into overload table */
X	entry 	unshift;		/* normal default codes/funcs */
X	entry	shift;			/* shifted default codes/funcs */
X	entry 	ctrl;			/* control default codes/funcs */
X} Keycap_def;
X
X#define IDX0		0	/* default indexvalue into ovl table */
X
X#define STR		KBD_SUBT_STR	/* subtype = ptr to string */
X#define FNC		KBD_SUBT_FNC	/* subtype = ptr to function */
X
X#define CODE_SIZE	5
X
X/*---------------------------------------------------------------------------*
X * the overlaytable table is a static fixed size scratchpad where all the
X * overloaded definitions are stored.
X * an entry consists of a short (holding the new type attribute) and
X * four entries for a new keydefinition.
X *---------------------------------------------------------------------------*/
X
X#define OVLTBL_SIZE	64		/* 64 keys can be overloaded */
X
X#define Ovl_tbl struct kbd_ovlkey
X
Xstatic Ovl_tbl ovltbl[OVLTBL_SIZE];	/* the table itself */
X
Xstatic ovlinitflag = 0;			/* the init flag for the table */
X
Xstatic char scantokey[] = {
X/*      -0-  -1-  -2-  -3-  -4-  -5-  -6-  -7-    This layout is valid for US only */
X/*00*/   0, 120,   0, 116, 114, 112, 113, 123,  /* ??  F9  ??  F5  F3  F1  F2  F12 */
X/*08*/   0, 121, 119, 117, 115,  16,   1,   0,  /* ??  F10 F8  F6  F4  TAB `   ??  */
X/*10*/   0,  60,  44,   0,  58,  17,   2,   0,  /* ??  ALl SHl ??  CTl Q   1   ??  */
X/*18*/   0,   0,  46,  32,  31,  18,   3,   0,  /* ??  Z   S   A   W   2   ??  ??  */
X/*20*/   0,  48,  47,  33,  19,   5,   4,   0,  /* ??  C   X   D   E   4   3   ??  */
X/*28*/   0,  61,  49,  34,  21,  20,   6,   0,  /* ??  SP  V   F   T   R   5   ??  */
X/*30*/   0,  51,  50,  36,  35,  22,   7,   0,  /* ??  N   B   H   G   Y   6   ??  */
X/*38*/   0,   0,  52,  37,  23,   8,   9,   0,  /* ??  ??  M   J   U   7   8   ??  */
X/*40*/   0,  53,  38,  24,  25,  11,  10,   0,  /* ??  ,   K   I   O   0   9   ??  */
X/*48*/   0,  54,  55,  39,  40,  26,  12,   0,  /* ??  .   /   L   ;   P   -   ??  */
X/*50*/   0,   0,  41,   0,  27,  13,   0,   0,  /* ??  ??  "   ??  [   =   ??  ??  */
X/*58*/  30,  57,  43,  28,   0,  29,   0,   0,  /* CAP SHr ENT ]   ??  \   ??  ??  */
X/*60*/   0,  45,   0,   0,   0,   0,  15,   0,  /* ??  NL1 ??  ??  ??  ??  BS  ??  */
X/*68*/   0,  93,   0,  92,  91,   0,   0,   0,  /* ??  KP1 ??  KP4 KP7 ??  ??  ??  */
X/*70*/  99, 104,  98,  97, 102,  96, 110,  90,  /* KP0 KP. KP2 KP5 KP6 KP8 ESC NUM */
X/*78*/ 122, 106, 103, 105, 100, 101, 125,   0,  /* F11 KP+ KP3 KP- KP* KP9 LOC ??  */
X/*80*/ 126,   0,   0, 118,                      /* BREAK  ??  ??  F7 */
X/*     ^^^
X * -hv- we use 0x80 for a pseudo scan code for the break key
X */
X};
X
Xstatic char extscantokey[] = {
X/*      -0-  -1-  -2-  -3-  -4-  -5-  -6-  -7-     This layout is valid for US only */
X/*00*/   0, 120,   0, 116, 114, 112, 113, 123,  /* ??  F9  ??  F5  F3  F1  F2  F12 */
X/*08*/   0, 121, 119, 117, 115,  16,   1,   0,  /* ??  F10 F8  F6  F4  TAB `   ??  */
X/*10*/   0,  62, 124,   0,  64,  17,   2,   0,  /* ??  ALr PSc ??  CTr Q   1   ??  */
X/*18*/   0,   0,  46,  32,  31,  18,   3,   0,  /* ??  Z   S   A   W   2   ??  ??  */
X/*20*/   0,  48,  47,  33,  19,   5,   4,   0,  /* ??  C   X   D   E   4   3   ??  */
X/*28*/   0,  61,  49,  34,  21,  20,   6,   0,  /* ??  SP  V   F   T   R   5   ??  */
X/*30*/   0,  51,  50,  36,  35,  22,   7,   0,  /* ??  N   B   H   G   Y   6   ??  */
X/*38*/   0,   0,  52,  37,  23,   8,   9,   0,  /* ??  ??  M   J   U   7   8   ??  */
X/*40*/   0,  53,  38,  24,  25,  11,  10,   0,  /* ??  ,   K   I   O   0   9   ??  */
X/*48*/   0,  54,  95,  39,  40,  26,  12,   0,  /* ??  .   KP/ L   ;   P   -   ??  */
X/*50*/   0,   0,  41,   0,  27,  13,   0,   0,  /* ??  ??  "   ??  [   =   ??  ??  */
X/*58*/  30,  57, 108,  28,   0,  29,   0,   0,  /* CAP  SHr KPE ]   ??  \  ??  ??  */
X/*60*/   0,  45,   0,   0,   0,   0,  15,   0,  /* ??  NL1 ??  ??  ??  ??  BS  ??  */
X/*68*/   0,  81,   0,  79,  80,   0,   0,   0,  /* ??  END ??  LA  HOM ??  ??  ??  */
X/*70*/  75,  76,  84,  97,  89,  83, 110,  90,  /* INS DEL DA  KP5 RA  UA  ESC NUM */
X/*78*/ 122, 106,  86, 105, 124,  85, 125,   0,  /* F11 KP+ PD  KP- PSc PU  LOC ??  */
X/*80*/ 126,   0,   0, 118,                      /* BREAK  ??  ??  F7 */
X};
X
Xstatic Keycap_def	key2ascii[] =
X{
X
X/* DONT EVER OVERLOAD KEY 0, THIS IS A KEY THAT MUSTN'T EXIST */
X
X/*	type		index	unshift				shift				ctrl	                        */
X/*      ----------	-----	-----------------------		-----------------------		--------------------------	*/
X/*  0*/	KBD_NONE,	IDX0,	{STR,(u_char*)"df"},		{STR,(u_char*)""},		{STR,(u_char*)""},
X/*  1*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"`"},		{STR,(u_char*)"~"},		{STR,(u_char*)"`"},
X/*  2*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"1"},		{STR,(u_char*)"!"},		{STR,(u_char*)"1"},
X/*  3*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"2"},		{STR,(u_char*)"@"},		{STR,(u_char*)"\000"},	
X/*  4*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"3"},		{STR,(u_char*)"#"},		{STR,(u_char*)"3"},	
X/*  5*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"4"},		{STR,(u_char*)"$"},		{STR,(u_char*)"4"},
X/*  6*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"5"},		{STR,(u_char*)"%"},		{STR,(u_char*)"5"},
X/*  7*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"6"},		{STR,(u_char*)"^"},		{STR,(u_char*)"\036"},
X/*  8*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"7"},		{STR,(u_char*)"&"},		{STR,(u_char*)"7"},
X/*  9*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"8"},		{STR,(u_char*)"*"},		{STR,(u_char*)"9"},
X/* 10*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"9"},		{STR,(u_char*)"("},		{STR,(u_char*)"9"},
X/* 11*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"0"},		{STR,(u_char*)")"},		{STR,(u_char*)"0"},
X/* 12*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"-"},		{STR,(u_char*)"_"},		{STR,(u_char*)"\037"},
X/* 13*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"="},		{STR,(u_char*)"+"},		{STR,(u_char*)"="},
X/* 14*/	KBD_NONE,	IDX0,	{STR,(u_char*)""},		{STR,(u_char*)""},		{STR,(u_char*)""},
X/* 15*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"\177"},		{STR,(u_char*)"\010"},		{STR,(u_char*)"\177"},		/* BS */
X/* 16*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"\t"},		{STR,(u_char*)"\t"},		{STR,(u_char*)"\t"},		/* TAB */
X/* 17*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"q"},		{STR,(u_char*)"Q"},		{STR,(u_char*)"\021"},
X/* 18*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"w"},		{STR,(u_char*)"W"},		{STR,(u_char*)"\027"},
X/* 19*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"e"},		{STR,(u_char*)"E"},		{STR,(u_char*)"\005"},
X/* 20*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"r"},		{STR,(u_char*)"R"},		{STR,(u_char*)"\022"},
X/* 21*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"t"},		{STR,(u_char*)"T"},		{STR,(u_char*)"\024"},
X/* 22*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"y"},		{STR,(u_char*)"Y"},		{STR,(u_char*)"\031"},
X/* 23*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"u"},		{STR,(u_char*)"U"},		{STR,(u_char*)"\025"},
X/* 24*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"i"},		{STR,(u_char*)"I"},		{STR,(u_char*)"\011"},
X/* 25*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"o"},		{STR,(u_char*)"O"},		{STR,(u_char*)"\017"},
X/* 26*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"p"},		{STR,(u_char*)"P"},		{STR,(u_char*)"\020"},
X/* 27*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"["},		{STR,(u_char*)"{"},		{STR,(u_char*)"\033"},
X/* 28*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"]"},		{STR,(u_char*)"}"},		{STR,(u_char*)"\035"},
X/* 29*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"\\"},		{STR,(u_char*)"|"},		{STR,(u_char*)"\034"},
X/* 30*/	KBD_CAPS,	IDX0,	{STR,(u_char*)""},		{STR,(u_char*)""},		{STR,(u_char*)""},
X/* 31*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"a"},		{STR,(u_char*)"A"},		{STR,(u_char*)"\001"},
X/* 32*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"s"},		{STR,(u_char*)"S"},		{STR,(u_char*)"\023"},
X/* 33*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"d"},		{STR,(u_char*)"D"},		{STR,(u_char*)"\004"},
X/* 34*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"f"},		{STR,(u_char*)"F"},		{STR,(u_char*)"\006"},
X/* 35*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"g"},		{STR,(u_char*)"G"},		{STR,(u_char*)"\007"},
X/* 36*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"h"},		{STR,(u_char*)"H"},		{STR,(u_char*)"\010"},
X/* 37*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"j"},		{STR,(u_char*)"J"},		{STR,(u_char*)"\n"},
X/* 38*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"k"},		{STR,(u_char*)"K"},		{STR,(u_char*)"\013"},
X/* 39*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"l"},		{STR,(u_char*)"L"},		{STR,(u_char*)"\014"},
X/* 40*/	KBD_ASCII,	IDX0,	{STR,(u_char*)";"},		{STR,(u_char*)":"},		{STR,(u_char*)";"},
X/* 41*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"'"},		{STR,(u_char*)"\""},		{STR,(u_char*)"'"},
X/* 42*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"\\"},		{STR,(u_char*)"|"},		{STR,(u_char*)"\034"},		/* special */
X/* 43*/	KBD_RETURN,	IDX0,	{STR,(u_char*)"\r"},		{STR,(u_char*)"\r"},		{STR,(u_char*)"\r"},		/* RETURN */
X/* 44*/	KBD_SHIFT,	IDX0,	{STR,(u_char*)""},		{STR,(u_char*)""},		{STR,(u_char*)""},		/* SHIFT left */
X/* 45*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"<"},		{STR,(u_char*)">"},		{STR,(u_char*)""},
X/* 46*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"z"},		{STR,(u_char*)"Z"},		{STR,(u_char*)"\032"},
X/* 47*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"x"},		{STR,(u_char*)"X"},		{STR,(u_char*)"\030"},
X/* 48*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"c"},		{STR,(u_char*)"C"},		{STR,(u_char*)"\003"},
X/* 49*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"v"},		{STR,(u_char*)"V"},		{STR,(u_char*)"\026"},
X/* 50*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"b"},		{STR,(u_char*)"B"},		{STR,(u_char*)"\002"},
X/* 51*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"n"},		{STR,(u_char*)"N"},		{STR,(u_char*)"\016"},
X/* 52*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"m"},		{STR,(u_char*)"M"},		{STR,(u_char*)"\r"},
X/* 53*/	KBD_ASCII,	IDX0,	{STR,(u_char*)","},		{STR,(u_char*)"<"},		{STR,(u_char*)","},
X/* 54*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"."},		{STR,(u_char*)">"},		{STR,(u_char*)"."},
X/* 55*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"/"},		{STR,(u_char*)"?"},		{STR,(u_char*)"/"},
X/* 56*/	KBD_NONE,	IDX0,	{STR,(u_char*)""},		{STR,(u_char*)""},		{STR,(u_char*)""},
X/* 57*/	KBD_SHIFT,	IDX0,	{STR,(u_char*)""},		{STR,(u_char*)""},		{STR,(u_char*)""},		/* SHIFT right */
X/* 58*/	KBD_CTL,	IDX0,	{STR,(u_char*)""},		{STR,(u_char*)""},		{STR,(u_char*)""},		/* CTL left */
X/* 59*/	KBD_ASCII,	IDX0,	{STR,(u_char*)""},		{STR,(u_char*)""},		{STR,(u_char*)""},
X/* 60*/	KBD_META,	IDX0,	{STR,(u_char*)""},		{STR,(u_char*)""},		{STR,(u_char*)""},		/* ALT left */
X#ifndef ENABLE_NULLCHARS
X/* 61*/	KBD_ASCII,	IDX0,	{STR,(u_char*)" "},		{STR,(u_char*)" "},		{STR,(u_char*)" "},		/* SPACE */
X#else
X/* 61*/	KBD_ASCII,	IDX0,	{STR,(u_char*)" "},		{STR,(u_char*)" "},		{STR,(u_char*)"\000"},		/* SPACE */
X#endif /* ENABLE_NULLCHARS */
X/* 62*/	KBD_META,	IDX0,	{STR,(u_char*)""},		{STR,(u_char*)""},		{STR,(u_char*)""},		/* ALT right */
X/* 63*/	KBD_ASCII,	IDX0,	{STR,(u_char*)""},		{STR,(u_char*)""},		{STR,(u_char*)""},
X/* 64*/	KBD_CTL,	IDX0,	{STR,(u_char*)""},		{STR,(u_char*)""},		{STR,(u_char*)""},		/* CTL right */
X/* 65*/	KBD_NONE,	IDX0,	{STR,(u_char*)""},		{STR,(u_char*)""},		{STR,(u_char*)""},
X/* 66*/	KBD_NONE,	IDX0,	{STR,(u_char*)""},		{STR,(u_char*)""},		{STR,(u_char*)""},
X/* 67*/	KBD_NONE,	IDX0,	{STR,(u_char*)""},		{STR,(u_char*)""},		{STR,(u_char*)""},
X/* 68*/	KBD_NONE,	IDX0,	{STR,(u_char*)""},		{STR,(u_char*)""},		{STR,(u_char*)""},
X/* 69*/	KBD_NONE,	IDX0,	{STR,(u_char*)""},		{STR,(u_char*)""},		{STR,(u_char*)""},
X/* 70*/	KBD_NONE,	IDX0,	{STR,(u_char*)""},		{STR,(u_char*)""},		{STR,(u_char*)""},
X/* 71*/	KBD_NONE,	IDX0,	{STR,(u_char*)""},		{STR,(u_char*)""},		{STR,(u_char*)""},
X/* 72*/	KBD_NONE,	IDX0,	{STR,(u_char*)""},		{STR,(u_char*)""},		{STR,(u_char*)""},
X/* 73*/	KBD_NONE,	IDX0,	{STR,(u_char*)""},		{STR,(u_char*)""},		{STR,(u_char*)""},
X/* 74*/	KBD_NONE,	IDX0,	{STR,(u_char*)""},		{STR,(u_char*)""},		{STR,(u_char*)""},
X/* 75*/	KBD_FUNC,	IDX0,	{STR,(u_char*)"\033[2~"},	{STR,(u_char*)"\033[2~"},	{STR,(u_char*)"\033[2~"},	/* INS */
X/* 76*/	KBD_FUNC,	IDX0,	{STR,(u_char*)"\033[3~"},	{STR,(u_char*)"\033[3~"},	{STR,(u_char*)"\033[3~"},	/* DEL */
X/* 77*/	KBD_NONE,	IDX0,	{STR,(u_char*)""},		{STR,(u_char*)""},		{STR,(u_char*)""},
X/* 78*/	KBD_NONE,	IDX0,	{STR,(u_char*)""},		{STR,(u_char*)""},		{STR,(u_char*)""},
X/* 79*/	KBD_CURSOR,	IDX0,	{STR,(u_char*)"\033[D"},	{STR,(u_char*)"\033OD"},	{STR,(u_char*)"\033[D"},	/* CU <- */
X/* 80*/	KBD_FUNC,	IDX0,	{STR,(u_char*)"\033[1~"},	{STR,(u_char*)"\033[1~"},	{STR,(u_char*)"\033[1~"},	/* HOME = FIND*/
X/* 81*/	KBD_FUNC,	IDX0,	{STR,(u_char*)"\033[4~"},	{STR,(u_char*)"\033[4~"},	{STR,(u_char*)"\033[4~"},	/* END = SELECT */
X/* 82*/	KBD_NONE,	IDX0,	{STR,(u_char*)""},		{STR,(u_char*)""},		{STR,(u_char*)""},
X/* 83*/	KBD_CURSOR,	IDX0,	{STR,(u_char*)"\033[A"},	{STR,(u_char*)"\033OA"},	{STR,(u_char*)"\033[A"},	/* CU ^ */
X/* 84*/	KBD_CURSOR,	IDX0,	{STR,(u_char*)"\033[B"},	{STR,(u_char*)"\033OB"},	{STR,(u_char*)"\033[B"},	/* CU v */
X/* 85*/	KBD_FUNC,	IDX0,	{STR,(u_char*)"\033[5~"},	{STR,(u_char*)"\033[5~"},	{STR,(u_char*)"\033[5~"},	/* PG UP */
X/* 86*/	KBD_FUNC,	IDX0,	{STR,(u_char*)"\033[6~"},	{STR,(u_char*)"\033[6~"},	{STR,(u_char*)"\033[6~"},	/* PG DN */
X/* 87*/	KBD_NONE,	IDX0,	{STR,(u_char*)""},		{STR,(u_char*)""},		{STR,(u_char*)""},
X/* 88*/	KBD_NONE,	IDX0,	{STR,(u_char*)""},		{STR,(u_char*)""},		{STR,(u_char*)""},
X/* 89*/	KBD_CURSOR,	IDX0,	{STR,(u_char*)"\033[C"},	{STR,(u_char*)"\033OC"},	{STR,(u_char*)"\033[C"},	/* CU -> */
X/* 90*/	KBD_NUM,	IDX0,	{STR,(u_char*)""},		{STR,(u_char*)""},		{STR,(u_char*)""},
X/* 91*/	KBD_KP,		IDX0,	{STR,(u_char*)"7"},		{STR,(u_char*)"\033Ow"},	{STR,(u_char*)"7"},
X/* 92*/	KBD_KP,		IDX0,	{STR,(u_char*)"4"},		{STR,(u_char*)"\033Ot"},	{STR,(u_char*)"4"},
X/* 93*/	KBD_KP,		IDX0,	{STR,(u_char*)"1"},		{STR,(u_char*)"\033Oq"},	{STR,(u_char*)"1"},
X/* 94*/	KBD_NONE,	IDX0,	{STR,(u_char*)""},		{STR,(u_char*)""},		{STR,(u_char*)""},
X/* 95*/	KBD_KP,		IDX0,	{STR,(u_char*)"/"},		{STR,(u_char*)"/"},		{STR,(u_char*)"/"},
X/* 96*/	KBD_KP,		IDX0,	{STR,(u_char*)"8"},		{STR,(u_char*)"\033Ox"},	{STR,(u_char*)"8"},
X/* 97*/	KBD_KP,		IDX0,	{STR,(u_char*)"5"},		{STR,(u_char*)"\033Ou"},	{STR,(u_char*)"5"},
X/* 98*/	KBD_KP,		IDX0,	{STR,(u_char*)"2"},		{STR,(u_char*)"\033Or"},	{STR,(u_char*)"2"},
X/* 99*/	KBD_KP,		IDX0,	{STR,(u_char*)"0"},		{STR,(u_char*)"\033Op"},	{STR,(u_char*)"0"},
X/*100*/	KBD_KP,		IDX0,	{STR,(u_char*)"*"},		{STR,(u_char*)"*"},		{STR,(u_char*)"*"},
X/*101*/	KBD_KP,		IDX0,	{STR,(u_char*)"9"},		{STR,(u_char*)"\033Oy"},	{STR,(u_char*)"9"},
X/*102*/	KBD_KP,		IDX0,	{STR,(u_char*)"6"},		{STR,(u_char*)"\033Ov"},	{STR,(u_char*)"6"},
X/*103*/	KBD_KP,		IDX0,	{STR,(u_char*)"3"},		{STR,(u_char*)"\033Os"},	{STR,(u_char*)"3"},
X/*104*/	KBD_KP,		IDX0,	{STR,(u_char*)"."},		{STR,(u_char*)"\033On"},	{STR,(u_char*)"."},
X/*105*/	KBD_KP,		IDX0,	{STR,(u_char*)"-"},		{STR,(u_char*)"\033Om"},	{STR,(u_char*)"-"},
X/*106*/	KBD_KP,		IDX0,	{STR,(u_char*)"+"},		{STR,(u_char*)"+"},		{STR,(u_char*)"+"},
X/*107*/	KBD_NONE,	IDX0,	{STR,(u_char*)""},		{STR,(u_char*)""},		{STR,(u_char*)""},
X/*108*/	KBD_RETURN,	IDX0,	{STR,(u_char*)"\r"},		{STR,(u_char*)"\033OM"},	{STR,(u_char*)"\r"},		/* KP ENTER */
X/*109*/	KBD_NONE,	IDX0,	{STR,(u_char*)""},		{STR,(u_char*)""},		{STR,(u_char*)""},	
X/*110*/	KBD_ASCII,	IDX0,	{STR,(u_char*)"\033"},		{STR,(u_char*)"\033"},		{STR,(u_char*)"\033"},
X/*111*/	KBD_NONE,	IDX0,	{STR,(u_char*)""},		{STR,(u_char*)""},		{STR,(u_char*)""},
X
X#ifdef VT220_KEYBOARDLAYOUT
X
X/*112*/	KBD_FUNC,	IDX0,	{FNC,(void*)fkey1},		{FNC,(void*)sfkey1},		{FNC,(void*)cfkey1},		/* F1 */
X/*113*/	KBD_FUNC,	IDX0,	{FNC,(void*)fkey2},		{FNC,(void*)sfkey2},		{FNC,(void*)cfkey2},		/* F2 */
X/*114*/	KBD_FUNC,	IDX0,	{FNC,(void*)fkey3},		{FNC,(void*)sfkey3},		{FNC,(void*)cfkey2},		/* F3 */
X/*115*/	KBD_FUNC,	IDX0,	{FNC,(void*)fkey4},		{FNC,(void*)sfkey4},		{FNC,(void*)cfkey4},		/* F4 */
X/*116*/	KBD_FUNC,	IDX0,	{FNC,(void*)fkey5},		{FNC,(void*)sfkey5},		{FNC,(void*)cfkey5},		/* F5 */
X/*117*/	KBD_FUNC,	IDX0,	{FNC,(void*)fkey6},		{FNC,(void*)sfkey6},		{FNC,(void*)cfkey6},		/* F6 */
X/*118*/	KBD_FUNC,	IDX0,	{FNC,(void*)fkey7},		{FNC,(void*)sfkey7},		{FNC,(void*)cfkey7},		/* F7 */
X/*119*/	KBD_FUNC,	IDX0,	{FNC,(void*)fkey8},		{FNC,(void*)sfkey8},		{FNC,(void*)cfkey8},		/* F8 */
X/*120*/	KBD_FUNC, 	IDX0,	{FNC,(void*)fkey9},		{FNC,(void*)sfkey9},		{FNC,(void*)cfkey9},		/* F9 */
X/*121*/	KBD_FUNC,	IDX0,	{FNC,(void*)fkey10},		{FNC,(void*)sfkey10},		{FNC,(void*)cfkey10},		/* F10 */
X/*122*/	KBD_FUNC,	IDX0,	{FNC,(void*)fkey11},		{FNC,(void*)sfkey11},		{FNC,(void*)cfkey11},		/* F11 */
X/*123*/	KBD_FUNC,	IDX0,	{FNC,(void*)fkey12},		{FNC,(void*)sfkey12},		{FNC,(void*)cfkey12},		/* F12 */
X
X#else	/* VT220_KEYBOARDLAYOUT */
X
X/*112*/	KBD_FUNC,	IDX0,	{FNC,(void*)fkey1},		{FNC,(void*)sfkey1},		{STR,(u_char*)""},		/* F1 */
X/*113*/	KBD_FUNC,	IDX0,	{FNC,(void*)fkey2},		{FNC,(void*)sfkey2},		{STR,(u_char*)""},		/* F2 */
X/*114*/	KBD_FUNC,	IDX0,	{FNC,(void*)fkey3},		{FNC,(void*)sfkey3},		{STR,(u_char*)""},		/* F3 */
X/*115*/	KBD_FUNC,	IDX0,	{FNC,(void*)fkey4},		{FNC,(void*)sfkey4},		{STR,(u_char*)""},		/* F4 */
X/*116*/	KBD_FUNC,	IDX0,	{FNC,(void*)fkey5},		{FNC,(void*)sfkey5},		{STR,(u_char*)""},		/* F5 */
X/*117*/	KBD_FUNC,	IDX0,	{FNC,(void*)fkey6},		{FNC,(void*)sfkey6},		{STR,(u_char*)""},		/* F6 */
X/*118*/	KBD_FUNC,	IDX0,	{FNC,(void*)fkey7},		{FNC,(void*)sfkey7},		{STR,(u_char*)""},		/* F7 */
X/*119*/	KBD_FUNC,	IDX0,	{FNC,(void*)fkey8},		{FNC,(void*)sfkey8},		{STR,(u_char*)""},		/* F8 */
X/*120*/	KBD_FUNC, 	IDX0,	{FNC,(void*)fkey9},		{STR,(u_char*)""},		{STR,(u_char*)""},		/* F9 */
X/*121*/	KBD_FUNC,	IDX0,	{FNC,(void*)fkey10},		{STR,(u_char*)""},		{STR,(u_char*)""},		/* F10 */
X/*122*/	KBD_FUNC,	IDX0,	{FNC,(void*)fkey11},		{STR,(u_char*)""},		{STR,(u_char*)""},		/* F11 */
X/*123*/	KBD_FUNC,	IDX0,	{FNC,(void*)fkey12},		{STR,(u_char*)""},		{STR,(u_char*)""},		/* F12 */
X
X#endif	/* VT220_KEYBOARDLAYOUT */
X
X/*124*/	KBD_KP,		IDX0,	{STR,(u_char*)""},		{STR,(u_char*)""},		{STR,(u_char*)""},
X/*125*/	KBD_SCROLL,	IDX0,	{STR,(u_char*)""},		{STR,(u_char*)""},		{STR,(u_char*)""},
X/*126*/	KBD_BREAK,	IDX0,	{STR,(u_char*)""},		{STR,(u_char*)""},		{STR,(u_char*)""},
X/*127*/	KBD_NONE,	IDX0,	{STR,(u_char*)""},		{STR,(u_char*)""},		{STR,(u_char*)""},
X};
X
Xstatic char	keypad2num[] = {
X	7, 4, 1, -1, -1, 8, 5, 2, 0, -1, 9, 6, 3, -1, -1, -1, -1
X};
X
X#ifdef VT220_KEYBOARDLAYOUT
X
X/*---------------------------------------------------------------------------*
X *	function bound to function key 1
X *---------------------------------------------------------------------------*/
Xstatic void fkey1()
X{
X	if(meta_down)
X		more_chars = (u_char *)"\033[23~"; /* F11 */
X	else
X	{
X		current_video_screen = 0;
X		vgapage(0);
X		return;
X	}
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to function key 2
X *---------------------------------------------------------------------------*/
Xstatic void fkey2()
X{
X	if(meta_down)
X		more_chars = (u_char *)"\033[24~"; /* F12 */
X	else
X	{
X		current_video_screen = 1;
X		vgapage(1);
X		return;
X	}
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to function key 3
X *---------------------------------------------------------------------------*/
Xstatic void fkey3()
X{
X	if(meta_down)
X		more_chars = (u_char *)"\033[25~"; /* F13 */
X	else
X	{
X		current_video_screen = 2;
X		vgapage(2);
X		return;
X	}
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to function key 4
X *---------------------------------------------------------------------------*/
Xstatic void fkey4()
X{
X	if(meta_down)
X		more_chars = (u_char *)"\033[26~"; /* F14 */
X	else
X	{
X		current_video_screen = 3;
X		vgapage(3);
X		return;
X	}
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to function key 5
X *---------------------------------------------------------------------------*/
Xstatic void fkey5()
X{
X	if(meta_down)
X		more_chars = (u_char *)"\033[28~"; /* Help */
X	else
X	if(++current_video_screen > totalscreens-1)
X		current_video_screen = 0;
X	vgapage(current_video_screen);
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to function key 6
X *---------------------------------------------------------------------------*/
Xstatic void fkey6()
X{
X	if(meta_down)	
X		more_chars = (u_char *)"\033[29~"; /* DO */
X	else
X		more_chars = (u_char *)"\033[17~"; /* F6 */
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to function key 7
X *---------------------------------------------------------------------------*/
Xstatic void fkey7()
X{
X	if(meta_down)
X		more_chars = (u_char *)"\033[31~"; /* F17 */
X	else
X		more_chars = (u_char *)"\033[18~"; /* F7 */
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to function key 8
X *---------------------------------------------------------------------------*/
Xstatic void fkey8()
X{
X	if(meta_down)
X		more_chars = (u_char *)"\033[32~"; /* F18 */
X	else
X		more_chars = (u_char *)"\033[19~"; /* F8 */
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to function key 9
X *---------------------------------------------------------------------------*/
Xstatic void fkey9()
X{
X	if(meta_down)
X		more_chars = (u_char *)"\033[33~"; /* F19 */
X	else
X		more_chars = (u_char *)"\033[20~"; /* F9 */
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to function key 10
X *---------------------------------------------------------------------------*/
Xstatic void fkey10()
X{
X	if(meta_down)
X		more_chars = (u_char *)"\033[34~"; /* F20 */
X	else
X		more_chars = (u_char *)"\033[21~"; /* F10 */
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to function key 11
X *---------------------------------------------------------------------------*/
Xstatic void fkey11()
X{
X	if(meta_down)
X		more_chars = (u_char *)"\0x8FP"; /* PF1 */
X	else
X		more_chars = (u_char *)"\033[23~"; /* F11 */
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to function key 12
X *---------------------------------------------------------------------------*/
Xstatic void fkey12()
X{
X	if(meta_down)
X		more_chars = (u_char *)"\0x8FQ"; /* PF2 */
X	else
X		more_chars = (u_char *)"\033[24~"; /* F12 */
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to SHIFTED function key 1
X *---------------------------------------------------------------------------*/
Xstatic void sfkey1()
X{
X	if(meta_down)
X	{
X		if(vsp->ukt.length[6])	/* entry available ? */
X			more_chars = (u_char *)&(vsp->udkbuf[vsp->ukt.first[6]]);
X		else
X			more_chars = (u_char *)"\033[23~"; /* F11 */
X	}
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to SHIFTED function key 2
X *---------------------------------------------------------------------------*/
Xstatic void sfkey2()
X{
X	if(meta_down)
X	{
X		if(vsp->ukt.length[7])	/* entry available ? */
X			more_chars = (u_char *)&(vsp->udkbuf[vsp->ukt.first[7]]);
X		else
X			more_chars = (u_char *)"\033[24~"; /* F12 */
X	}
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to SHIFTED function key 3
X *---------------------------------------------------------------------------*/
Xstatic void sfkey3()
X{
X	if(meta_down)
X	{
X		if(vsp->ukt.length[8])	/* entry available ? */
X			more_chars = (u_char *)&(vsp->udkbuf[vsp->ukt.first[8]]);
X		else
X			more_chars = (u_char *)"\033[25~"; /* F13 */
X	}
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to SHIFTED function key 4
X *---------------------------------------------------------------------------*/
Xstatic void sfkey4()
X{
X	if(meta_down)
X	{
X		if(vsp->ukt.length[9])	/* entry available ? */
X			more_chars = (u_char *)&(vsp->udkbuf[vsp->ukt.first[9]]);
X		else
X			more_chars = (u_char *)"\033[26~"; /* F14 */
X	}
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to SHIFTED function key 5
X *---------------------------------------------------------------------------*/
Xstatic void sfkey5()
X{
X	if(meta_down)
X	{
X		if(vsp->ukt.length[11])	/* entry available ? */
X			more_chars = (u_char *)&(vsp->udkbuf[vsp->ukt.first[11]]);
X		else
X			more_chars = (u_char *)"\033[28~"; /* Help */
X	}
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to SHIFTED function key 6
X *---------------------------------------------------------------------------*/
Xstatic void sfkey6()
X{
X	if(!meta_down)
X	{
X		if(vsp->ukt.length[0])	/* entry available ? */
X			more_chars = (u_char *)&(vsp->udkbuf[vsp->ukt.first[0]]);
X		else
X			more_chars = (u_char *)"\033[17~"; /* F6 */
X	}
X	else if(vsp->ukt.length[12])	/* entry available ? */
X			more_chars = (u_char *)&(vsp->udkbuf[vsp->ukt.first[12]]);
X	     else
X			more_chars = (u_char *)"\033[29~"; /* DO */
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to SHIFTED function key 7
X *---------------------------------------------------------------------------*/
Xstatic void sfkey7()
X{
X	if(!meta_down)
X	{
X		if(vsp->ukt.length[1])	/* entry available ? */
X			more_chars = (u_char *)&(vsp->udkbuf[vsp->ukt.first[1]]);
X		else
X			more_chars = (u_char *)"\033[18~"; /* F7 */
X	}
X	else if(vsp->ukt.length[14])	/* entry available ? */
X			more_chars = (u_char *)&(vsp->udkbuf[vsp->ukt.first[14]]);
X	     else
X			more_chars = (u_char *)"\033[31~"; /* F17 */
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to SHIFTED function key 8
X *---------------------------------------------------------------------------*/
Xstatic void sfkey8()
X{
X	if(!meta_down)
X	{
X		if(vsp->ukt.length[2])	/* entry available ? */
X			more_chars = (u_char *)&(vsp->udkbuf[vsp->ukt.first[2]]);
X		else
X			more_chars = (u_char *)"\033[19~"; /* F8 */
X	}
X	else if(vsp->ukt.length[14])	/* entry available ? */
X			more_chars = (u_char *)&(vsp->udkbuf[vsp->ukt.first[15]]);
X	     else
X			more_chars = (u_char *)"\033[32~"; /* F18 */
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to SHIFTED function key 9
X *---------------------------------------------------------------------------*/
Xstatic void sfkey9()
X{
X	if(!meta_down)
X	{
X		if(vsp->ukt.length[3])	/* entry available ? */
X			more_chars = (u_char *)&(vsp->udkbuf[vsp->ukt.first[3]]);
X		else
X			more_chars = (u_char *)"\033[20~"; /* F9 */
X	}
X	else if(vsp->ukt.length[16])	/* entry available ? */
X			more_chars = (u_char *)&(vsp->udkbuf[vsp->ukt.first[16]]);
X	     else
X			more_chars = (u_char *)"\033[33~"; /* F19 */
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to SHIFTED function key 10
X *---------------------------------------------------------------------------*/
Xstatic void sfkey10()
X{
X	if(!meta_down)
X	{
X		if(vsp->ukt.length[4])	/* entry available ? */
X			more_chars = (u_char *)&(vsp->udkbuf[vsp->ukt.first[4]]);
X		else
X			more_chars = (u_char *)"\033[21~"; /* F10 */
X	}
X	else if(vsp->ukt.length[17])	/* entry available ? */
X			more_chars = (u_char *)&(vsp->udkbuf[vsp->ukt.first[17]]);
X	     else
X			more_chars = (u_char *)"\033[34~"; /* F20 */
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to SHIFTED function key 11
X *---------------------------------------------------------------------------*/
Xstatic void sfkey11()
X{
X	if(!meta_down)
X	{
X		if(vsp->ukt.length[6])	/* entry available ? */
X			more_chars = (u_char *)&(vsp->udkbuf[vsp->ukt.first[6]]);
X		else
X			more_chars = (u_char *)"\033[23~"; /* F11 */
X	}
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to SHIFTED function key 12
X *---------------------------------------------------------------------------*/
Xstatic void sfkey12()
X{
X	if(!meta_down)
X	{
X		if(vsp->ukt.length[7])	/* entry available ? */
X			more_chars = (u_char *)&(vsp->udkbuf[vsp->ukt.first[7]]);
X		else
X			more_chars = (u_char *)"\033[24~"; /* F12 */
X	}
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to control function key 1
X *---------------------------------------------------------------------------*/
Xstatic void cfkey1()
X{
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to control function key 2
X *---------------------------------------------------------------------------*/
Xstatic void cfkey2()
X{
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to control function key 3
X *---------------------------------------------------------------------------*/
Xstatic void cfkey3()
X{
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to control function key 4
X *---------------------------------------------------------------------------*/
Xstatic void cfkey4()
X{
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to control function key 5
X *---------------------------------------------------------------------------*/
Xstatic void cfkey5()
X{
X	if(vsp->which_fkl == SYS_FKL)
X		toggl_bell(vsp);
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to control function key 6
X *---------------------------------------------------------------------------*/
Xstatic void cfkey6()
X{
X	if(vsp->which_fkl == SYS_FKL)	
X		toggl_sevenbit(vsp);
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to control function key 7
X *---------------------------------------------------------------------------*/
Xstatic void cfkey7()
X{
X	if(vsp->which_fkl == SYS_FKL)
X		toggl_dspf(vsp);
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to control function key 8
X *---------------------------------------------------------------------------*/
Xstatic void cfkey8()
X{
X	if(vsp->which_fkl == SYS_FKL)	
X		toggl_awm(vsp);
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to control function key 9
X *---------------------------------------------------------------------------*/
Xstatic void cfkey9()
X{
X	if(vsp->labels_on)	/* toggle label display on/off */
X	        fkl_off(vsp);
X	else
X	        fkl_on(vsp);
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to control function key 10
X *---------------------------------------------------------------------------*/
Xstatic void cfkey10()
X{
X	if(vsp->labels_on)	/* toggle user/system fkey labels */
X	{
X		if(vsp->which_fkl == USR_FKL)
X			sw_sfkl(vsp);
X		else if(vsp->which_fkl == SYS_FKL)
X			sw_ufkl(vsp);
X	}
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to control function key 11
X *---------------------------------------------------------------------------*/
Xstatic void cfkey11()
X{
X	if(vsp->vt_pure_mode == M_PUREVT)
X	        set_emulation_mode(vsp, M_HPVT);
X	else if(vsp->vt_pure_mode == M_HPVT)
X	        set_emulation_mode(vsp, M_PUREVT);
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to control function key 12
X *---------------------------------------------------------------------------*/
Xstatic void cfkey12()
X{
X}
X
X#else	/* VT220_KEYBOARDLAYOUT */
X
X/*---------------------------------------------------------------------------*
X *	function bound to function key 1
X *---------------------------------------------------------------------------*/
Xstatic void fkey1()
X{
X	if(!meta_down)
X	{
X		if(vsp->vt_pure_mode == M_PUREVT || (vsp->which_fkl == USR_FKL))
X			more_chars = (u_char *)"\033[17~";	/* F6 */
X	}
X	else
X	{
X		if(vsp->vt_pure_mode == M_PUREVT || (vsp->which_fkl == USR_FKL))
X			more_chars = (u_char *)"\033[26~";	/* F14 */	
X	}
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to function key 2
X *---------------------------------------------------------------------------*/
Xstatic void fkey2()
X{
X	if(!meta_down)
X	{
X		if(vsp->vt_pure_mode == M_PUREVT || (vsp->which_fkl == USR_FKL))
X			more_chars = (u_char *)"\033[18~";	/* F7 */
X	}
X	else
X	{
X		if(vsp->vt_pure_mode == M_PUREVT || (vsp->which_fkl == USR_FKL))
X			more_chars = (u_char *)"\033[28~";	/* HELP */
X	}
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to function key 3
X *---------------------------------------------------------------------------*/
Xstatic void fkey3()
X{
X	if(!meta_down)
X	{
X		if(vsp->vt_pure_mode == M_PUREVT || (vsp->which_fkl == USR_FKL))
X			more_chars = (u_char *)"\033[19~";	/* F8 */
X	}
X	else
X	{
X		if(vsp->vt_pure_mode == M_PUREVT || (vsp->which_fkl == USR_FKL))
X			more_chars = (u_char *)"\033[29~";	/* DO */
X	}
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to function key 4
X *---------------------------------------------------------------------------*/
Xstatic void fkey4()
X{
X	if(!meta_down)
X	{
X		if(vsp->vt_pure_mode == M_PUREVT || (vsp->which_fkl == USR_FKL))
X			more_chars = (u_char *)"\033[20~";	/* F9 */
X	}
X	else
X	{
X		if(vsp->vt_pure_mode == M_PUREVT || (vsp->which_fkl == USR_FKL))
X			more_chars = (u_char *)"\033[31~";	/* F17 */
X	}
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to function key 5
X *---------------------------------------------------------------------------*/
Xstatic void fkey5()
X{
X	if(!meta_down)
X	{
X		if((vsp->vt_pure_mode == M_HPVT) && (vsp->which_fkl == SYS_FKL))	
X			toggl_bell(vsp);
X		else
X			more_chars = (u_char *)"\033[21~";	/* F10 */
X	}
X	else
X	{
X		if(vsp->vt_pure_mode == M_PUREVT || (vsp->which_fkl == USR_FKL))
X			more_chars = (u_char *)"\033[32~";	/* F18 */
X	}
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to function key 6
X *---------------------------------------------------------------------------*/
Xstatic void fkey6()
X{
X	if(!meta_down)
X	{
X		if((vsp->vt_pure_mode == M_HPVT) && (vsp->which_fkl == SYS_FKL))	
X			toggl_sevenbit(vsp);
X		else
X			more_chars = (u_char *)"\033[23~";	/* F11 */
X	}
X	else
X	{
X		if(vsp->vt_pure_mode == M_PUREVT || (vsp->which_fkl == USR_FKL))
X			more_chars = (u_char *)"\033[33~";	/* F19 */
X	}
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to function key 7
X *---------------------------------------------------------------------------*/
Xstatic void fkey7()
X{
X	if(!meta_down)
X	{
X		if((vsp->vt_pure_mode == M_HPVT) && (vsp->which_fkl == SYS_FKL))
X			toggl_dspf(vsp);
X		else
X			more_chars = (u_char *)"\033[24~";	/* F12 */
X	}
X	else
X	{
X		if(vsp->vt_pure_mode == M_PUREVT || (vsp->which_fkl == USR_FKL))
X			more_chars = (u_char *)"\033[34~";	/* F20 */
X	}
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to function key 8
X *---------------------------------------------------------------------------*/
Xstatic void fkey8()
X{
X	if(!meta_down)
X	{
X		if((vsp->vt_pure_mode == M_HPVT) && (vsp->which_fkl == SYS_FKL))	
X			toggl_awm(vsp);
X		else
X			more_chars = (u_char *)"\033[25~";	/* F13 */
X	}
X	else
X	{
X		if(vsp->vt_pure_mode == M_PUREVT || (vsp->which_fkl == USR_FKL))
X			more_chars = (u_char *)"\033[35~";	/* F21 ??!! */
X	}
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to function key 9
X *---------------------------------------------------------------------------*/
Xstatic void fkey9()
X{
X	if(meta_down)
X	{
X		if(vsp->vt_pure_mode == M_PUREVT)
X			return;
X	
X		if(vsp->labels_on)	/* toggle label display on/off */
X			fkl_off(vsp);
X		else
X			fkl_on(vsp);
X	}
X	else
X	{
X		current_video_screen = 0;
X		vgapage(0);
X	}
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to function key 10
X *---------------------------------------------------------------------------*/
Xstatic void fkey10()
X{
X	if(meta_down)
X	{
X		if(vsp->vt_pure_mode != M_PUREVT && vsp->labels_on)
X		{
X			if(vsp->which_fkl == USR_FKL)
X				sw_sfkl(vsp);
X			else if(vsp->which_fkl == SYS_FKL)
X				sw_ufkl(vsp);
X		}
X	}
X	else
X	{
X		current_video_screen = 1;
X		vgapage(1);
X	}
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to function key 11
X *---------------------------------------------------------------------------*/
Xstatic void fkey11()
X{
X	if(meta_down)
X	{
X		if(vsp->vt_pure_mode == M_PUREVT)
X			set_emulation_mode(vsp, M_HPVT);
X		else if(vsp->vt_pure_mode == M_HPVT)
X			set_emulation_mode(vsp, M_PUREVT);
X	}
X	else
X	{
X		current_video_screen = 2;
X		vgapage(2);
X	}
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to function key 12
X *---------------------------------------------------------------------------*/
Xstatic void fkey12()
X{
X	if(meta_down)
X	{
X		if(++current_video_screen > totalscreens-1)
X			current_video_screen = 0;
X		vgapage(current_video_screen);
X	}
X	else
X	{
X		current_video_screen = 3;
X		vgapage(3);
X	}
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to SHIFTED function key 1
X *---------------------------------------------------------------------------*/
Xstatic void sfkey1()
X{
X	if(!meta_down)
X	{
X		if(vsp->ukt.length[0])	/* entry available ? */
X			more_chars = (u_char *)&(vsp->udkbuf[vsp->ukt.first[0]]);
X	}
X	else
X	{
X		if(vsp->ukt.length[9])	/* entry available ? */
X			more_chars = (u_char *)&(vsp->udkbuf[vsp->ukt.first[9]]);
X	}
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to SHIFTED function key 2
X *---------------------------------------------------------------------------*/
Xstatic void sfkey2()
X{
X	if(!meta_down)
X	{
X		if(vsp->ukt.length[1])	/* entry available ? */
X			more_chars = (u_char *)&(vsp->udkbuf[vsp->ukt.first[1]]);
X	}
X	else
X	{
X		if(vsp->ukt.length[11])	/* entry available ? */
X			more_chars = (u_char *)&(vsp->udkbuf[vsp->ukt.first[11]]);
X	}
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to SHIFTED function key 3
X *---------------------------------------------------------------------------*/
Xstatic void sfkey3()
X{
X	if(!meta_down)
X	{
X		if(vsp->ukt.length[2])	/* entry available ? */
X			more_chars = (u_char *)&(vsp->udkbuf[vsp->ukt.first[2]]);
X	}
X	else
X	{
X		if(vsp->ukt.length[12])	/* entry available ? */
X			more_chars = (u_char *)&(vsp->udkbuf[vsp->ukt.first[12]]);
X	}
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to SHIFTED function key 4
X *---------------------------------------------------------------------------*/
Xstatic void sfkey4()
X{
X	if(!meta_down)
X	{
X		if(vsp->ukt.length[3])	/* entry available ? */
X			more_chars = (u_char *)&(vsp->udkbuf[vsp->ukt.first[3]]);
X	}
X	else
X	{
X		if(vsp->ukt.length[13])	/* entry available ? */
X			more_chars = (u_char *)&(vsp->udkbuf[vsp->ukt.first[13]]);
X	}
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to SHIFTED function key 5
X *---------------------------------------------------------------------------*/
Xstatic void sfkey5()
X{
X	if(!meta_down)
X	{
X		if(vsp->ukt.length[4])	/* entry available ? */
X			more_chars = (u_char *)&(vsp->udkbuf[vsp->ukt.first[4]]);
X	}
X	else
X	{
X		if(vsp->ukt.length[14])	/* entry available ? */
X			more_chars = (u_char *)&(vsp->udkbuf[vsp->ukt.first[14]]);
X	}
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to SHIFTED function key 6
X *---------------------------------------------------------------------------*/
Xstatic void sfkey6()
X{
X	if(!meta_down)
X	{
X		if(vsp->ukt.length[6])	/* entry available ? */
X			more_chars = (u_char *)&(vsp->udkbuf[vsp->ukt.first[6]]);
X	}
X	else
X	{
X		if(vsp->ukt.length[15])	/* entry available ? */
X			more_chars = (u_char *)&(vsp->udkbuf[vsp->ukt.first[15]]);
X	}
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to SHIFTED function key 7
X *---------------------------------------------------------------------------*/
Xstatic void sfkey7()
X{
X	if(!meta_down)
X	{
X		if(vsp->ukt.length[7])	/* entry available ? */
X			more_chars = (u_char *)&(vsp->udkbuf[vsp->ukt.first[7]]);
X	}
X	else
X	{
X		if(vsp->ukt.length[16])	/* entry available ? */
X			more_chars = (u_char *)&(vsp->udkbuf[vsp->ukt.first[16]]);
X	}
X}
X
X/*---------------------------------------------------------------------------*
X *	function bound to SHIFTED function key 8
X *---------------------------------------------------------------------------*/
Xstatic void sfkey8()
X{
X	if(!meta_down)
X	{
X		if(vsp->ukt.length[8])	/* entry available ? */
X			more_chars = (u_char *)&(vsp->udkbuf[vsp->ukt.first[8]]);
X	}
X	else
X	{
X		if(vsp->ukt.length[17])	/* entry available ? */
X			more_chars = (u_char *)&(vsp->udkbuf[vsp->ukt.first[17]]);
X	}
X}
X
X#endif	/* VT220_KEYBOARDLAYOUT */
X
X/*---------------------------------------------------------------------------*
X *	switch keypad to numeric mode
X *---------------------------------------------------------------------------*/
Xvoid vt_keynum(svsp)
Xstruct video_state *svsp;
X{
X	svsp->num = 1;
X	update_led();
X}
X
X/*---------------------------------------------------------------------------*
X *	switch keypad to application mode
X *---------------------------------------------------------------------------*/
Xvoid vt_keyappl(svsp)
Xstruct video_state *svsp;
X{
X	svsp->num = 0;
X	update_led();
X}
X
X#ifdef OLDKEYBOARDSTUFF
X/*---------------------------------------------------------------------------*
X *	pass command to keyboard
X *---------------------------------------------------------------------------*/
Xu_char kbd_cmd(u_char byte)
X{
X	while(inb(CONTROLLER_CTRL) & STATUS_INPBF)
X		;
X	outb(CONTROLLER_DATA, byte);
X	while(inb(CONTROLLER_CTRL) & STATUS_INPBF)
X		;
X	return(inb(CONTROLLER_DATA));
X}
X
X/*---------------------------------------------------------------------------*
X *	reset keyboard
X *---------------------------------------------------------------------------*/
Xstatic doreset() 
X{
X	u_char c;
X	int again = 0;
X
X	/* Enable interrupts and keyboard controller */
X	
X	kbc_8042cmd(CONTR_WRITE); 
X	outb(CONTROLLER_DATA, (COMMAND_INHOVR|COMMAND_SYSFLG|COMMAND_IRQEN));
X
X	/* Start keyboard stuff RESET */
X
X	kbd_cmd(KEYB_C_RESET);
X
X	while((c = inb(CONTROLLER_DATA)) != KEYB_R_ACK)
X	{
X		if ((c == KEYB_R_RESEND) || (c == KEYB_R_OVERRUN1))
X		{
X			if(!again)
X				printf("KEYBOARD disconnected: RECONNECT \n");
X			kbd_cmd(KEYB_C_RESET);
X			again = 1;
X		}
X	}
X
X 	/* wait for selftest ok return code */
X 
X	while(inb(CONTROLLER_DATA) != KEYB_R_SELFOK)
X		;
X
X	keyboard_type = KB_MFII;
X
X/*===========================================================================*
X			ATTENTION LAPTOPS !
X
X	Got this one from one beta-tester for making his laptop play, this
X	is included for reference and to help somebody else with the same
X	problem (-hm)
X
X	Below is that keyboard reset code to defeat A20... this time :-)
X	This is taken directly from the kbdrest() function in
X	/usr/src/sys.386bsd/i386/stand/kbd.c, and is needed for my laptop.
X
X *===========================================================================*/
X
X#ifdef LAPTOP 
X
X        /* While we are here, defeat gatea20 */
X        while (inb(0x64)&2);    /* wait input ready */
X        outb(0x64,0xd1);
X        while (inb(0x64)&2);    /* wait input ready */
X        outb(0x60,0xdf);
X        while (inb(0x64)&2);    /* wait input ready */
X        odt = bdt = 0;
X        inb(0x60);
X
X#endif /* LAPTOP */
X
X/*===========================================================================*
X			END ATTENTION LAPTOPS !
X *===========================================================================*/
X
X}
X
X/*---------------------------------------------------------------------------*
X *	update keyboard led's	
X *---------------------------------------------------------------------------*/
Xvoid update_led()
X{
X	ledstate = kbd_scroll | 2*(vsp->num) | 4*caps;
X	kbd_cmd(KEYB_C_LEDS);
X	outb(CONTROLLER_DATA, ledstate);
X}
X
X/*---------------------------------------------------------------------------*
X *	set typamatic rate
X *---------------------------------------------------------------------------*/
Xstatic void settpmrate(rate)
X{
X	tpmrate = rate & 0x7f;
X	kbd_cmd(KEYB_C_TYPEM);
X	outb(CONTROLLER_DATA, tpmrate);
X}
X 
X#else	/* OLDKEYBOARDSTUFF */
X/*---------------------------------------------------------------------------*
X *	this is the beginning of a keyboard rewrite, highly experimental
X *---------------------------------------------------------------------------*/
X/* debugging ... */
X
X#define KEYB_DEBUG		/* enable keyboard debug printf's */
X#define KEYB_DEBUG_ALL	/* enable runtime keyboard debug printf's */
X#define KEYB_DEBUG_ACK	/* enable reset ack keyboard debug printf's */
X
X#ifdef KEYB_DEBUG
Xstatic int kbd_debug_on = 1;	/* debug flag */
X#endif
X
X/*---------------------------------------------------------------------------*
X *
X *	switch 8042 obf interrupts on or off
X *
X *	onoff = 0 - switch off
X *	onoff = 1 - switch on
X *
X *	returns:
X *		0  - successfull
X *		-1 - timeout error
X *
X *---------------------------------------------------------------------------*/
Xstatic int irq_8042(onoff)
Xint onoff;
X{
X	int timeout = KEYB_TIMEOUT;
X	u_char inbyte;
X	
X	while(timeout--)
X	{
X		if(!(inb(CONTROLLER_CTRL) & STATUS_INPBF))
X		{
X			outb(CONTROLLER_CTRL, CONTR_WRITE);
X
X			timeout = KEYB_TIMEOUT;
X			while(timeout--)
X			{
X				if(!(inb(CONTROLLER_CTRL) & STATUS_INPBF))
X				{
X					inbyte = inb(CONTROLLER_DATA);
X					if(onoff)
X						outb(CONTROLLER_DATA, (COMMAND_INHOVR|COMMAND_SYSFLG|COMMAND_IRQEN));
X					else
X						outb(CONTROLLER_DATA, (COMMAND_INHOVR|COMMAND_SYSFLG));
X					return(0);
X				}
X				DELAY(KEYB_INNERTIMO);
X			}
X			return(-1);
X		}
X		DELAY(KEYB_INNERTIMO);
X	}
X	return(-1);
X}
X
X/*---------------------------------------------------------------------------*
X *
X *	write byte to controller data port
X *
X *	returns:
X *		0  - successfull
X *		-1 - timeout error
X *
X *---------------------------------------------------------------------------*/
Xstatic int contr_wr(u_char byte)
X{
X	int timeout = KEYB_TIMEOUT;
X	
X	while(timeout--)
X	{
X		if(!(inb(CONTROLLER_CTRL) & STATUS_INPBF))
X		{
X			outb(CONTROLLER_DATA, byte);
X			return(0);
X		}
X		DELAY(KEYB_INNERTIMO);
X	}
X	return(-1);
X}
X
X/*---------------------------------------------------------------------------*
X *
X *	read byte from controller data port
X *
X *	this is strange, in that one has to wait for STATUS_INPBF to
X *	become 0 before a byte can be read - waiting for status_outpbf
X *	causes not the desired result......
X *
X *	returns:
X *		0x00 .. 0xff - byte read from port
X *		          -1 - timeout error
X *
X *---------------------------------------------------------------------------*/
Xstatic int contr_rd()
X{
X	int timeout = KEYB_TIMEOUT;
X	
X	while(timeout--)
X	{
X		if(!(inb(CONTROLLER_CTRL) & STATUS_INPBF))
X			return((u_char)inb(CONTROLLER_DATA));
X		DELAY(KEYB_INNERTIMO);
X	}
X	return(-1);
X}
X
X/*---------------------------------------------------------------------------*
X *
X *	read byte from controller data port, waiting for status_outpbf
X *
X *	returns:
X *		0x00 .. 0xff - byte read from port
X *		          -1 - timeout error
X *
X *---------------------------------------------------------------------------*/
Xstatic int contr_rdobf()
X{
X	int timeout = 10000;
X	
X	while(timeout--)
X	{
X		if(inb(CONTROLLER_CTRL) & STATUS_OUTPBF)
X			return((u_char)inb(CONTROLLER_DATA));
X		DELAY(KEYB_INNERTIMO);
X	}
X	return(-1);
X}
X
X/*---------------------------------------------------------------------------*
X *
X *	write byte to controller data port and read status
X *
X *	returns:
X *		0x00 .. 0xff - response from controller
X *		          -1 - timeout error
X *
X *---------------------------------------------------------------------------*/
Xstatic int contr_wrrd(u_char byte)
X{
X	int timeout = KEYB_TIMEOUT;
X	
X	while(timeout--)
X	{
X		if(!(inb(CONTROLLER_CTRL) & STATUS_INPBF))
X		{
X			outb(CONTROLLER_DATA, byte);
X
X			timeout = KEYB_TIMEOUT;
X			
X			while(timeout--)
X			{
X				if(!(inb(CONTROLLER_CTRL) & STATUS_INPBF))
X					return((u_char)inb(CONTROLLER_DATA));
X				DELAY(KEYB_INNERTIMO);
X			}
X			return(-1);
X		}
X		DELAY(KEYB_INNERTIMO);
X	}
X	return(-1);
X}
X
X
X/*---------------------------------------------------------------------------*
X *	pass command to keyboard (via 8042 controller on main board)
X *---------------------------------------------------------------------------*/
Xstatic int keyboard_cmd(int two, u_char byte1, u_char byte2)
X{
X	u_char inbyte;
X	int retries;
X	int x;
X
X	x = spltty();	/* block irqs from 8042 */
X	
X	/* write byte 1 to controller data */
X
X	if(byte1 == KEYB_C_ECHO || byte1 == KEYB_C_RESEND)
X	{
X		/* no ack for echo and resend commands */
X		if((contr_wr(byte1)) == -1)
X		{
X#ifdef KEYB_DEBUG
Xif(kbd_debug_on)
X	printf("keyboard_cmd: timeout writing byte 1 echo/resend, stat 0x%x!\n",inb(CONTROLLER_CTRL));
X#endif	
X			splx(x);
X			return(-1);
X		}
X		splx(x);
X		return(0);
X	}
X
X	retries = 100;
X	
X	while(retries--)
X	{
X		inbyte = contr_wrrd(byte1);
X		
X		switch(inbyte)
X		{
X			case -1:
X#ifdef KEYB_DEBUG
Xif(kbd_debug_on)
X	printf("keyboard_cmd: waitfor ack: timeout error, stat = 0x%x\n",inb(CONTROLLER_CTRL));
X#endif	
X				break;
X	
X			case KEYB_R_ACK:
X#ifdef KEYB_DEBUG
Xif(kbd_debug_on)
X	printf("keyboard_cmd: waitfor ack: got ack !!\n");
X#endif	
X				goto ackout;
X	
X			case KEYB_R_OVERRUN:
X#ifdef KEYB_DEBUG
Xif(kbd_debug_on)
X	printf("keyboard_cmd: waitfor ack: got overrun-00\n");
X#endif	
X				break;
X				
X			case KEYB_R_OVERRUN1:
X#ifdef KEYB_DEBUG
Xif(kbd_debug_on)
X	printf("keyboard_cmd: waitfor ack: got overrun-ff\n");
X#endif	
X				break;
X	
X			case KEYB_R_RESEND:
X#ifdef KEYB_DEBUG
Xif(kbd_debug_on)
X	printf("keyboard_cmd: waitfor ack: got resend\n");
X#endif	
X				break;
X	
X			default:
X#ifdef KEYB_DEBUG
Xif(kbd_debug_on)
X	printf("keyboard_cmd: waitfor ack: got %x, stat = 0x%x!\n",inbyte,inb(CONTROLLER_CTRL));
X#endif	
X				break;
X		}
X	}
X	if(retries <= 0)
X	{
X#ifdef KEYB_DEBUG
Xif(kbd_debug_on)
X	printf("keyboard_cmd: waitfor ack: too much retries, continue ..!\n");
X#endif	
X	}		
X
Xackout:
X
X	/* special handling of keyboard reset */
X
X	if(byte1 == KEYB_C_RESET)
X	{
X		retries = KEYB_TIMEOUT;
X
X		while(retries--)
X		{
X			inbyte = contr_rd();
X	
X			switch(inbyte)
X			{
X				case -1:
X#ifdef KEYB_DEBUG
Xif(kbd_debug_on)
X	printf("keyboard_cmd: reset, selftest response timeout error, stat 0x%x!\n",inb(CONTROLLER_CTRL));
X#endif	
X					break;
X					
X				case KEYB_R_SELFOK:
X#ifdef KEYB_DEBUG
Xif(kbd_debug_on)
X	printf("keyboard_cmd: reset, got selftest ok!\n");
X#endif	
X					splx(x);
X					return(0);
X					
X				case KEYB_R_SELFBAD:
X#ifdef KEYB_DEBUG
Xif(kbd_debug_on)
X	printf("keyboard_cmd: reset, got selftest failed error!\n");
X#endif	
X					break;
X					
X				case KEYB_R_ACK: /* this seems pretty normal */
X#ifdef KEYB_DEBUG
X#ifdef KEYB_DEBUG_ACK
Xif(kbd_debug_on)
X	printf("keyboard_cmd: reset, got ack .... error ??\n");
X#endif
X#endif	
X					break;
X
X				default:
X#ifdef KEYB_DEBUG
Xif(kbd_debug_on)
X	printf("keyboard_cmd: reset, unknown response rx'd, got 0x%x, stat 0x%x!\n",inbyte,inb(CONTROLLER_CTRL));
X#endif	
X					break;
X			}
X			DELAY(10);
X		}
X		if(retries <= 0)
X		{
X#ifdef KEYB_DEBUG
Xif(kbd_debug_on)
X	printf("keyboard_cmd: reset, too much retries error, continue ...\n");
X#endif	
X		}
X	}
X
X	if(!two)
X	{
X		splx(x);
X		return(0);	/* one byte only, exit */
X	}
X
X	/* send 2nd byte */
X
X	inbyte = contr_wrrd(byte2);
X	if(inbyte == -1)
X	{
X#ifdef KEYB_DEBUG
Xif(kbd_debug_on)
X	printf("keyboard_cmd: timeout writing byte 2, stat 0x%x!\n",inb(CONTROLLER_CTRL));
X#endif	
X	}
X	else
X	{
X#ifdef KEYB_DEBUG
Xif(kbd_debug_on)
X	printf("keyboard_cmd: successfull wrote byte 2, inbyte = 0x%x\n",inbyte);
X#endif	
X	}
X	splx(x);
X}
X
X/*---------------------------------------------------------------------------*
X *	reset keyboard
X *---------------------------------------------------------------------------*/
Xstatic doreset() 
X{
X	u_char id = 0;
X	int ismf = 0;
X	int retries = 10;
X	
X#ifdef KEYB_DEBUG
X	kbd_debug_on = 1;
X#endif
X
X#ifdef KEYB_DEBUG
X	printf("doreset() calls keyboard_cmd (reset)!\n");
X#endif
X
X	keyboard_cmd(0, KEYB_C_RESET, 0);
X
X#ifdef KEYB_DEBUG
X	printf("doreset() calls keyboard_cmd (id)!\n");
X#endif
X
X	keyboard_cmd(0, KEYB_C_ID, 0);
X
X	while(retries--)
X	{
X		id = contr_rdobf();
X
X		if(id == -1)
X		{
X#ifdef KEYB_DEBUG
X	printf("doreset(): id got timeout\n");
X#endif
X			break;
X		}
X		else if(id == KEYB_R_MF2ID1)
X		{
X#ifdef KEYB_DEBUG
X	printf("doreset(): id got mf-id 1\n");
X#endif
X			ismf++;
X		}
X		else if(id == KEYB_R_MF2ID2)
X		{
X#ifdef KEYB_DEBUG
X	printf("doreset(): id got mf-id 2\n");
X#endif
X			ismf++;
X			break;
X		}
X		else if(id == KEYB_R_ACK)	/* ??? */
X		{
X#ifdef KEYB_DEBUG
X	printf("doreset(): id, got ack ..\n");
X#endif
X			continue;
X		}
X		else
X		{
X#ifdef KEYB_DEBUG
X	printf("doreset(): id, rx'd 0x%x\n",id);
X#endif
X			break;
X		}
X	}
X	if(retries <= 0)
X	{
X#ifdef KEYB_DEBUG
X	printf("doreset(): id error, too much retries\n");
X#endif
X	}
X
X
X	if(ismf == 2)
X	{
X#ifdef KEYB_DEBUG
X		printf("doreset(): keyboard is mf ii\n");
X#endif
X		keyboard_type = KB_MFII;
X	}
X	else if(ismf == 0)
X	{
X#ifdef KEYB_DEBUG
X		printf("doreset(): keyboard is at\n");
X#endif
X		keyboard_type = KB_AT;
X	}
X	else
X	{
X#ifdef KEYB_DEBUG
X		printf("doreset(): keyboard is of unknown type\n");
X#endif
X		keyboard_type = KB_UNKNOWN;
X	}
X
X#ifdef KEYB_DEBUG
X	printf("doreset() calls irq_8042()!\n");
X#endif
X
X	irq_8042(1);	/* enable 8042 OBF irq's */
X
X#ifdef KEYB_DEBUG
X#ifndef KEYB_DEBUG_ALL
X	kbd_debug_on = 0;
X#endif
X#endif
X}
X
X
X/*---------------------------------------------------------------------------*
X *	update keyboard led's	
X *---------------------------------------------------------------------------*/
Xvoid update_led()
X{
X	ledstate = kbd_scroll | 2*(vsp->num) | 4*caps;
X#ifdef KEYB_DEBUG
Xif(kbd_debug_on)
X	printf("update_led() calls keyboard_cmd!\n");
X#endif
X	keyboard_cmd(1, KEYB_C_LEDS, ledstate);	/* LED Command */
X}
X
X
X/*---------------------------------------------------------------------------*
X *	set typamatic rate
X *---------------------------------------------------------------------------*/
Xstatic void settpmrate(int rate)
X{
X	tpmrate = rate & 0x7f;
X#ifdef KEYB_DEBUG
Xif(kbd_debug_on)
X	printf("settpmrate() calls keyboard_cmd!\n");
X#endif
X
X	printf("settpmrate() calls keyboard_cmd, rate=0x%x, tpmrate=0x%x!\n",rate,tpmrate);
X
X	keyboard_cmd(1, KEYB_C_TYPEM, tpmrate);	/* Typematic Command */
X}
X
X#endif /* OLDKEYBOARDSTUFF */
X
X/*---------------------------------------------------------------------------*
X *	probe for device ( = init keyboard code)
X *---------------------------------------------------------------------------*/
Xpcprobe(struct isa_device *dev)
X{
X	doreset();
X	ovlinit(0);
X	return 1;
X}
X
X/*---------------------------------------------------------------------------*
X *	init keyboard overlay table	
X *---------------------------------------------------------------------------*/
Xstatic ovlinit(force) 
X{
X	register i;
X	
X	if (force || ovlinitflag==0)
X	{
X		for (i=0; i<OVLTBL_SIZE; i++)
X		{
X			ovltbl[i].keynum = 
X			ovltbl[i].type = 0;
X			ovltbl[i].unshift[0] =
X			ovltbl[i].shift[0] = 
X			ovltbl[i].ctrl[0] =
X			ovltbl[i].altgr[0] = 0;
X			ovltbl[i].subu =
X			ovltbl[i].subs =
X			ovltbl[i].subc =
X			ovltbl[i].suba = KBD_SUBT_STR;	/* just strings .. */
X		}
X		for (i=0; i<=MAXKEYNUM; i++)
X			key2ascii[i].type &= KBD_MASK;
X		ovlinitflag = 1;
X	}
X}
X
X/*---------------------------------------------------------------------------*
X *	get original key definition
X *---------------------------------------------------------------------------*/
Xstatic int getokeydef(unsigned key, Ovl_tbl *thisdef)
X{
X	if(key == 0 || key > MAXKEYNUM)
X		return EINVAL;
X	
X	thisdef->keynum = key;
X	thisdef->type = key2ascii[key].type;
X
X	if(key2ascii[key].unshift.subtype == STR)
X	{
X		bcopyb(key2ascii[key].unshift.what, thisdef->unshift, CODE_SIZE);
X		thisdef->subu = KBD_SUBT_STR;
X	}
X	else
X	{
X		bcopyb("", thisdef->unshift, CODE_SIZE);
X		thisdef->subu = KBD_SUBT_FNC;
X	}
X
X	if(key2ascii[key].shift.subtype == STR)
X	{
X		bcopyb(key2ascii[key].shift.what,thisdef->shift, CODE_SIZE);
X		thisdef->subs = KBD_SUBT_STR;
X	}
X	else
X	{
X		bcopyb("",thisdef->shift,CODE_SIZE);
X		thisdef->subs = KBD_SUBT_FNC;
X	}		
X	
X	if(key2ascii[key].ctrl.subtype == STR)
X	{
X		bcopyb(key2ascii[key].ctrl.what,thisdef->ctrl, CODE_SIZE);
X		thisdef->subc = KBD_SUBT_STR;
X	}
X	else
X	{
X		bcopyb("",thisdef->ctrl,CODE_SIZE);	
X		thisdef->subc = KBD_SUBT_FNC;
X	}
X	
X	/* deliver at least anything for ALTGR settings ... */		
X
X	if(key2ascii[key].unshift.subtype == STR)
X	{
X		bcopyb(key2ascii[key].unshift.what,thisdef->altgr, CODE_SIZE);
X		thisdef->suba = KBD_SUBT_STR;
X	}
X	else
X	{
X		bcopyb("",thisdef->altgr, CODE_SIZE);
X		thisdef->suba = KBD_SUBT_FNC;
X	}
X	return 0;
X}
X
X/*---------------------------------------------------------------------------*
X *	get current key definition
X *---------------------------------------------------------------------------*/
Xstatic int getckeydef(unsigned key, Ovl_tbl *thisdef) 
X{
X	u_short type = key2ascii[key].type;
X
X	if (key>MAXKEYNUM) 
X		return EINVAL;
X
X	if (type & KBD_OVERLOAD)
X		*thisdef = ovltbl[key2ascii[key].ovlindex];
X	else
X		getokeydef(key,thisdef);
X
X	return 0;
X}
X
X/*---------------------------------------------------------------------------*
X *	translate keynumber and returns ptr to associated ascii string
X *	if key is bound to a function, executes it, and ret empty ptr
X *---------------------------------------------------------------------------*/
Xstatic u_char *xlatkey2ascii(u_short key)
X{
X	static u_char	capchar[2],metachar[2];
X	static Ovl_tbl	thisdef;
X	u_short		n;
X	void		(*fnc)();
X	
X	if (key==0)			/* ignore the NON-KEY */
X		return 0;
X	
X	getckeydef(key&0x7F, &thisdef);	/* get the current ASCII value */
X
X	thisdef.type &= KBD_MASK;
X
X	if (key&0x80)			/* special handling of ALT-KEYPAD */
X	{
X		/* is the ALT Key released? */
X		if (thisdef.type==KBD_META || thisdef.type==KBD_ALTGR)
X		{
X			if (altkpflag)	/* have we been in altkp mode? */
X			{
X				capchar[0] = altkpval;
X				capchar[1] = 0;
X				altkpflag = 0;
X				altkpval = 0;
X				return capchar;
X			}
X		}
X		return 0;
X	}
X
X	switch (thisdef.type)		/* convert the keys */
X	{
X		case KBD_BREAK:
X		case KBD_ASCII:
X		case KBD_FUNC:
X			fnc = NULL;
X			more_chars = NULL;
X			
X			if (altgr_down)
X				more_chars = (u_char *)thisdef.altgr;
X	
X			else if (shift_down || shiftlock)
X			{
X				if(key2ascii[key].shift.subtype == STR)
X					more_chars = (u_char *)thisdef.shift;
X				else
X					fnc = key2ascii[key].shift.what.func;
X			}
X				
X			else if (ctrl_down)
X			{
X				if(key2ascii[key].ctrl.subtype == STR)
X					more_chars = (u_char *)thisdef.ctrl;
X				else
X					fnc = key2ascii[key].ctrl.what.func;
X			}
X	
X			else
X			{
X				if(key2ascii[key].unshift.subtype == STR)
X					more_chars = (u_char *)thisdef.unshift;
X				else
X					fnc = key2ascii[key].unshift.what.func;
X			}
X	
X			if(fnc)
X				(*fnc)();	/* execute function */
X					
X			if((more_chars != NULL) && (more_chars[1] == 0))
X			{
X				capchar[1] = metachar[1] = 0; /* just in case */
X				if (caps && more_chars[0] >= 'a'
X				   && more_chars[0] <= 'z')
X				{
X					capchar[0] = *more_chars - ('a'-'A');
X					more_chars = capchar;
X				}
X				if (meta_down)
X				{
X					metachar[0] = *more_chars | 0x80;
X					more_chars = metachar;
X				}
X			}
X			return(more_chars);
X
X		case KBD_KP:
X			fnc = NULL;
X			more_chars = NULL;
X	
X			if(meta_down)
X			{
X				switch(key)
X				{
X					case 95:	/* / */
X						altkpflag = 0;
X						more_chars =
X						 (u_char *)"\033OQ";
X						return(more_chars);
X						
X					case 100:	/* * */
X						altkpflag = 0;
X						more_chars =
X						 (u_char *)"\033OR";
X						return(more_chars);
X						
X					case 105:	/* - */
X						altkpflag = 0;
X						more_chars =
X						 (u_char *)"\033OS";
X						return(more_chars);
X				}
X			}
X
X			if(meta_down || altgr_down)				
X			{
X				if((n = keypad2num[key-91]) >= 0)
X				{
X					if (!altkpflag)
X					{
X						/* start ALT-KP mode */
X						altkpflag = 1;
X						altkpval = 0;
X					}
X					altkpval *= 10;
X					altkpval += n;
X				}
X				else
X					altkpflag = 0;
X				return 0;
X			} 
X	
X			if (!(vsp->num) || extended)
X			{
X				if(key2ascii[key].shift.subtype == STR)
X					more_chars = (u_char *)thisdef.shift;
X				else
X					fnc = key2ascii[key].shift.what.func;
X			}
X			else
X			{
X				if(key2ascii[key].unshift.subtype == STR)
X					more_chars = (u_char *)thisdef.unshift;
X				else
X					fnc = key2ascii[key].unshift.what.func;
X			}
X	
X			if(fnc)
X				(*fnc)();	/* execute function */
X			return(more_chars);
X	
X		case KBD_CURSOR:
X			fnc = NULL;
X			more_chars = NULL;
X	
X			if(vsp->ckm)
X			{
X				if(key2ascii[key].shift.subtype == STR)
X					more_chars = (u_char *)thisdef.shift;
X				else
X					fnc = key2ascii[key].shift.what.func;
X			}
X			else
X			{
X				if(key2ascii[key].unshift.subtype == STR)
X					more_chars = (u_char *)thisdef.unshift;
X				else
X					fnc = key2ascii[key].unshift.what.func;
X			}
X	
X			if(fnc)
X				(*fnc)();	/* execute function */
X			return(more_chars);
X
X		case KBD_NUM:		/*  special kp-num handling */
X			more_chars = NULL;
X			
X			if(meta_down)
X			{
X				more_chars = (u_char *)"\033OP"; /* PF1 */
X			}
X			else
X			{
X				vsp->num ^= 1;
X				update_led();
X			}
X			return(more_chars);
X
X		case KBD_RETURN:
X			more_chars = NULL;
X
X			if (!(vsp->num))
X			{
X				more_chars = (u_char *)thisdef.shift;
X			}
X			else
X			{
X				more_chars = (u_char *)thisdef.unshift;
X			}
X			if (vsp->lnm && (*more_chars == '\r'))
X			{
X				more_chars = (u_char *)"\r\n"; /* CR LF */
X			}
X			return(more_chars);
X			
X		case KBD_META:		/* these keys are	*/
X		case KBD_ALTGR:		/*  handled directly	*/
X		case KBD_SCROLL:	/*  by the keyboard	*/
X		case KBD_CAPS:		/*  handler - they are	*/
X		case KBD_SHFTLOCK:	/*  ignored here	*/
X		case KBD_CTL:
X		case KBD_NONE:
X		default:
X			return 0;
X	}
X}
X
X/*---------------------------------------------------------------------------*
X *	get keystrokes from the keyboard.
X *	if noblock = 0, wait until a key is pressed.
X *	else return 0 if no characters present.
X *---------------------------------------------------------------------------*/
Xu_char *sgetc(int noblock)
X{
X	u_char		dt;
X	unsigned	key;
X	u_short		type;
X	
X	static u_char	breakseen = 0;
X	static u_char	breakshit = 0;
X	static char	keybuf[2];
X
Xloop:
X	/* see if there is something from the keyboard in the input buffer */
X	
X	if (inb(CONTROLLER_CTRL) & STATUS_OUTPBF)
X		dt = inb(CONTROLLER_DATA);		/* yes, get it ! */
X	else
X	{
X		if (noblock)
X			return 0;
X		else
X			goto loop;
X	}
X
X	/* lets look what we got */
X	switch (dt)
X	{
X		case 0xFE:
X		case 0xFA:
X		case 0x00:
X		case 0xFD:
X		case 0xAA:
X		case 0xEE:		/* this is junk we do not want to see */
X			break;
X
X		case 0xe0:		/* extended code? */
X			extended = 1; 
X			break;
X
X		case 0xf0:		/* break code? */
X			breakseen = 1; 
X			if (breakshit)		/* =5: wait for 14 */ 
X				breakshit++;	/* =7: wait for 77 */
X			break;
X
X		case 0xe1:		/* -hv- the BREAK key */
X			/* we have to collect a sequence E1 14 77 E1 for make
X			   and F0 14 F0 77 for break */
X
X			breakshit++; /* state=1: wait for 14, state=4: have make */
X
X			if(breakshit == 4)
X			{
X				dt = 0x80;	/* build replacement code */
X				goto regular;
X			}
X			break;
X			
X		case 0x14:
X			if (breakshit) 
X				breakshit++;	/* =2: wait for 77 */ 
X			else			/* =6: needs second break; */
X				goto regular; 
X			break;
X
X		case 0x77:
X			if (breakshit) 
X				breakshit++;	/* =3: wait for E1 */ 
X			else			/* =7: needs second break; */
X				goto regular; 
X
X			if (breakshit==8)
X			{
X				dt = 0x80;	/* build replacement code */
X				breakshit = 0;
X				goto regular;
X			}
X			break;
X			
X		default:
X			goto regular;	/* regular key */
X	}		
X
X	if (noblock)
X		return 0;
X	else
X		goto loop;
X
X	/* got a normal scan key */
Xregular:
X
X	/*   Check for cntl-alt-del	*/
X
X	if ((dt == 0x71) && ctrl_down && (meta_down||altgr_down))
X		cpu_reset();
X
X		
X#include "ddb.h"
X#if NDDB > 0
X
X	 /*   Check for cntl-alt-esc	*/
X
X	if ((dt == 0x76) && ctrl_down && (meta_down||altgr_down))
X		Debugger();
X#endif
X
X	/*   make a keycode from scan code	*/
X
X	key = extended ? extscantokey[dt] : scantokey[dt];
X	extended = 0;
X
X	/* in NOREPEAT MODE ignore the key if it was the same as before */
X
X	if (!kbrepflag && key == kbd_lastkey && !breakseen)
X	{
X		if (noblock)
X			return 0;
X		else
X			goto loop;
X	}
X	
X	type = key2ascii[key].type;
X
X	if (type & KBD_OVERLOAD)
X		type = ovltbl[key2ascii[key].ovlindex].type;
X
X	type &= KBD_MASK;
X
X	switch (type)
X	{
X		case KBD_SHFTLOCK:
X			if(!breakseen)
X				shiftlock ^= 1;
X			goto nullkeys;
X			
X		case KBD_CAPS:
X			if (!breakseen)
X			{
X				caps ^= 1;
X				update_led();
X			}
X			goto nullkeys;
X			
X		case KBD_SCROLL:
X			if (!breakseen)
X			{
X				kbd_scroll ^= 1;
X				update_led();
X			}
X			goto nullkeys;
X			
X		case KBD_SHIFT:
X			shift_down = breakseen ? 0 : 1;
X			goto nullkeys;
X
X		case KBD_META:
X			meta_down = breakseen ? 0 : 0x80;
X			goto nullkeys;
X
X		case KBD_ALTGR:
X			altgr_down = breakseen ? 0 : 1;
X			goto nullkeys;
X
X		case KBD_CTL:
X			ctrl_down = breakseen ? 0 : 1;
X			goto nullkeys;
X
X		case KBD_NONE:
X			goto nullkeys;
X
X		default:
X			break;			/* deliver a key */
X	}
X
Xnullkeys:
X	if (breakseen)
X	{
X		key |= 0x80;
X		breakseen = 0;
X		kbd_lastkey = 0; /* -hv- I know this is a bug with */
X	}			 /* N-Key-Rollover, but I ignore that */
X	else			 /* because avoidance is too complicated */
X		kbd_lastkey = key;
X	
X	return xlatkey2ascii(key);	/* have a key */
X}
X
X/*---------------------------------------------------------------------------*
X *	reflect status of locking keys & set led's
X *---------------------------------------------------------------------------*/
Xstatic void setlockkeys(int snc)
X{
X	kbd_scroll = snc & 1;
X	vsp->num = (snc & 2) ? 1 : 0;
X	caps = (snc & 4) ? 1 : 0;
X	update_led();
X}
X
X/*---------------------------------------------------------------------------*
X *	remove a key definition
X *---------------------------------------------------------------------------*/
Xstatic int rmkeydef(int key)
X{
X	register Ovl_tbl *ref;
X	
X	if (key==0 || key > MAXKEYNUM)
X		return EINVAL;
X
X	if (key2ascii[key].type & KBD_OVERLOAD)
X	{
X		ref = &ovltbl[key2ascii[key].ovlindex];		
X		ref->keynum = 0;
X		ref->type = 0;
X		ref->unshift[0] =
X		ref->shift[0] =
X		ref->ctrl[0] =
X		ref->altgr[0] = 0;
X		key2ascii[key].type &= KBD_MASK;
X	}
X	return 0;
X}	
X
X/*---------------------------------------------------------------------------*
X *	overlay a key
X *---------------------------------------------------------------------------*/
Xstatic int setkeydef(Ovl_tbl *data)
X{
X	register i;
X
X	if( data->keynum > MAXKEYNUM		 ||
X	    (data->type & KBD_MASK) == KBD_BREAK ||
X	    (data->type & KBD_MASK) > KBD_SHFTLOCK)
X		return EINVAL;
X
X	data->unshift[KBDMAXOVLKEYSIZE] =
X	data->shift[KBDMAXOVLKEYSIZE] =
X	data->ctrl[KBDMAXOVLKEYSIZE] =
X	data->altgr[KBDMAXOVLKEYSIZE] = 0;
X
X	data->subu =
X	data->subs =
X	data->subc =
X	data->suba = KBD_SUBT_STR;		/* just strings .. */
X	
X	data->type |= KBD_OVERLOAD;		/* mark overloaded */
X
X	/* if key already overloaded, use that slot else find free slot */
X
X	if (key2ascii[data->keynum].type & KBD_OVERLOAD)
X	{
X		i = key2ascii[data->keynum].ovlindex;
X	}
X	else
X	{
X		for (i=0; i<OVLTBL_SIZE; i++)
X			if (ovltbl[i].keynum==0)
X				break;
X
X		if (i==OVLTBL_SIZE) 
X			return ENOSPC;	/* no space, abuse of ENOSPC(!) */
X	}
X
X	ovltbl[i] = *data;		/* copy new data string */
X
X	key2ascii[data->keynum].type |= KBD_OVERLOAD; 	/* mark key */
X	key2ascii[data->keynum].ovlindex = i;
X	
X	return 0;
X}
X
X/*---------------------------------------------------------------------------*
X *	keyboard ioctl's entry
X *---------------------------------------------------------------------------*/
Xint kbdioctl(dev_t dev, int cmd, caddr_t data, int flag)
X{
X	int key;
X
X	switch (cmd)
X	{
X		case KBDRESET:
X			doreset();
X			ovlinit(1);
X			settpmrate(KBD_TPD500|KBD_TPM100);
X			setlockkeys(0);
X			break;
X
X		case KBDGTPMAT:
X			*(int *)data = tpmrate;
X			break;
X
X		case KBDSTPMAT:
X			settpmrate(*(int *)data);
X			break;
X
X		case KBDGREPSW:
X			*(int *)data = kbrepflag;
X			break;
X
X		case KBDSREPSW:
X			kbrepflag = (*(int *)data) & 1;
X			break;
X
X		case KBDGLEDS:
X			*(int *)data = ledstate;
X			break;
X
X		case KBDSLEDS:
X			update_led();	/* ??? */
X			break;
X
X		case KBDGLOCK:
X			*(int *)data = (kbd_scroll | (vsp->num)*2 | caps*4);
X			break;
X
X		case KBDSLOCK:
X			setlockkeys(*(int *)data);
X			break;
X
X		case KBDGCKEY:
X			key = ((Ovl_tbl *)data)->keynum;
X			return getckeydef(key,(Ovl_tbl *)data);		
X
X		case KBDSCKEY:
X			key = ((Ovl_tbl *)data)->keynum;
X			return setkeydef((Ovl_tbl *)data);
X
X		case KBDGOKEY:
X			key = ((Ovl_tbl *)data)->keynum;
X			return getokeydef(key,(Ovl_tbl *)data);
X
X		case KBDRMKEY:
X			key = *(int *)data;
X			return rmkeydef(key);
X
X		case KBDDEFAULT:
X			ovlinit(1);
X			break;	
X
X		default:
X			/* proceed with vga ioctls */
X			return -1;
X	}
X	return 0;
X}
X
X/* ------------------------------- EOF -------------------------------------*/
SHAR_EOF
$TOUCH -am 0114130693 pcvt_kbd.c &&
chmod 0660 pcvt_kbd.c ||
echo "restore of pcvt_kbd.c failed"
set `wc -c pcvt_kbd.c`;Wc_c=$1
if test "$Wc_c" != "74085"; then
	echo original size 74085, current size $Wc_c
fi
fi
echo "End of part 9, continue with part 10"
exit 0
-- 
hellmuth michaelis    HCS Hanseatischer Computerservice GmbH   hamburg, europe
hm@hcshh.hcs.de              tel: +49/40/55903-170         fax: +49/40/5591486