Home | History | Annotate | Line # | Download | only in common
      1 /*	$NetBSD: hil.c,v 1.15 2023/01/15 06:19:46 tsutsui Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1997 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 /*
     33  * Copyright (c) 1988 University of Utah.
     34  * Copyright (c) 1990, 1993
     35  *	The Regents of the University of California.  All rights reserved.
     36  *
     37  * This code is derived from software contributed to Berkeley by
     38  * the Systems Programming Group of the University of Utah Computer
     39  * Science Department.
     40  *
     41  * Redistribution and use in source and binary forms, with or without
     42  * modification, are permitted provided that the following conditions
     43  * are met:
     44  * 1. Redistributions of source code must retain the above copyright
     45  *    notice, this list of conditions and the following disclaimer.
     46  * 2. Redistributions in binary form must reproduce the above copyright
     47  *    notice, this list of conditions and the following disclaimer in the
     48  *    documentation and/or other materials provided with the distribution.
     49  * 3. Neither the name of the University nor the names of its contributors
     50  *    may be used to endorse or promote products derived from this software
     51  *    without specific prior written permission.
     52  *
     53  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     54  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     55  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     56  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     57  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     58  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     59  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     60  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     61  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     62  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     63  * SUCH DAMAGE.
     64  *
     65  * from: Utah Hdr: hil.c 1.1 89/08/22
     66  *
     67  *	@(#)hil.c	8.1 (Berkeley) 6/10/93
     68  */
     69 
     70 /*
     71  * HIL keyboard routines for the standalone ITE.
     72  */
     73 
     74 #if defined(ITECONSOLE) && defined(HIL_KEYBOARD)
     75 
     76 #include <sys/param.h>
     77 
     78 #include <hp300/stand/common/hilreg.h>
     79 #include <hp300/stand/common/kbdmap.h>
     80 #include <hp300/stand/common/itevar.h>
     81 
     82 #include <hp300/stand/common/samachdep.h>
     83 #include <hp300/stand/common/kbdvar.h>
     84 
     85 #ifndef SMALL
     86 
     87 /*
     88  * HIL cooked keyboard keymaps.
     89  * Supports only unshifted, shifted and control keys.
     90  */
     91 char hil_us_keymap[] = {
     92 	'\0',	'`',	'\\',	ESC,	'\0',	DEL,	'\0',	'\0',
     93 	'\n',	'\t',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',
     94 	'\0',	'\n',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',
     95 	'\0',	'\t',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',
     96 	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',
     97 	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',	'\b',	'\0',
     98 	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',
     99 	ESC,	'\r',	'\0',	'\n',	'0',	'.',	',',	'+',
    100 	'1',	'2',	'3',	'-',	'4',	'5',	'6',	'*',
    101 	'7',	'8',	'9',	'/',	'E',	'(',	')',	'^',
    102 	'1',	'2',	'3',	'4',	'5',	'6',	'7',	'8',
    103 	'9',	'0',	'-',	'=',	'[',	']',	';',	'\'',
    104 	',',	'.',	'/',	'\040',	'o',	'p',	'k',	'l',
    105 	'q',	'w',	'e',	'r',	't',	'y',	'u',	'i',
    106 	'a',	's',	'd',	'f',	'g',	'h',	'j',	'm',
    107 	'z',	'x',	'c',	'v',	'b',	'n',	'\0',	'\0'
    108 };
    109 
    110 char hil_us_shiftmap[] = {
    111 	'\0',	'~',	'|',	DEL,	'\0',	DEL,	'\0',	'\0',
    112 	'\n',	'\t',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',
    113 	'\0',	'\n',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',
    114 	'\0',	'\t',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',
    115 	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',
    116 	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',	DEL,	'\0',
    117 	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',
    118 	ESC,	'\r',	'\0',	'\n',	'0',	'.',	',',	'+',
    119 	'1',	'2',	'3',	'-',	'4',	'5',	'6',	'*',
    120 	'7',	'8',	'9',	'/',	'`',	'|',	'\\',	'~',
    121 	'!',	'@',	'#',	'$',	'%',	'^',	'&',	'*',
    122 	'(',	')',	'_',	'+',	'{',	'}',	':',	'\"',
    123 	'<',	'>',	'?',	'\040',	'O',	'P',	'K',	'L',
    124 	'Q',	'W',	'E',	'R',	'T',	'Y',	'U',	'I',
    125 	'A',	'S',	'D',	'F',	'G',	'H',	'J',	'M',
    126 	'Z',	'X',	'C',	'V',	'B',	'N',	'\0',	'\0'
    127 };
    128 
    129 char hil_us_ctrlmap[] = {
    130 	'\0',	'`',	'\034',	ESC,	'\0',	DEL,	'\0',	'\0',
    131 	'\n',	'\t',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',
    132 	'\0',	'\n',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',
    133 	'\0',	'\t',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',
    134 	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',
    135 	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',	'\b',	'\0',
    136 	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',
    137 	ESC,	'\r',	'\0',	'\n',	'0',	'.',	',',	'+',
    138 	'1',	'2',	'3',	'-',	'4',	'5',	'6',	'*',
    139 	'7',	'8',	'9',	'/',	'E',	'(',	')',	'\036',
    140 	'1',	'2',	'3',	'4',	'5',	'6',	'7',	'8',
    141 	'9',	'0',	'-',	'=',	'\033',	'\035',	';',	'\'',
    142 	',',	'.',	'/',	'\040',	'\017',	'\020',	'\013',	'\014',
    143 	'\021',	'\027',	'\005',	'\022',	'\024',	'\031',	'\025',	'\011',
    144 	'\001',	'\023',	'\004',	'\006',	'\007',	'\010',	'\012',	'\015',
    145 	'\032',	'\030',	'\003',	'\026',	'\002',	'\016',	'\0',	'\0'
    146 };
    147 
    148 #ifdef UK_KEYBOARD
    149 char hil_uk_keymap[] = {
    150 	'\0',	'`',	'<',	ESC,	'\0',	DEL,	'\0',	'\0',
    151 	'\n',	'\t',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',
    152 	'\0',	'\n',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',
    153 	'\0',	'\t',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',
    154 	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',
    155 	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',	'\b',	'\0',
    156 	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',
    157 	ESC,	'\r',	'\0',	'\n',	'0',	'.',	',',	'+',
    158 	'1',	'2',	'3',	'-',	'4',	'5',	'6',	'*',
    159 	'7',	'8',	'9',	'/',	'E',	'(',	')',	'^',
    160 	'1',	'2',	'3',	'4',	'5',	'6',	'7',	'8',
    161 	'9',	'0',	'+',	'\'',	'[',	']',	'*',	'\\',
    162 	',',	'.',	'-',	'\040',	'o',	'p',	'k',	'l',
    163 	'q',	'w',	'e',	'r',	't',	'y',	'u',	'i',
    164 	'a',	's',	'd',	'f',	'g',	'h',	'j',	'm',
    165 	'z',	'x',	'c',	'v',	'b',	'n',	'\0',	'\0'
    166 };
    167 
    168 char hil_uk_shiftmap[] = {
    169 	'\0',	'~',	'>',	DEL,	'\0',	DEL,	'\0',	'\0',
    170 	'\n',	'\t',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',
    171 	'\0',	'\n',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',
    172 	'\0',	'\t',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',
    173 	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',
    174 	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',	DEL,	'\0',
    175 	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',
    176 	ESC,	'\r',	'\0',	'\n',	'0',	'.',	',',	'+',
    177 	'1',	'2',	'3',	'-',	'4',	'5',	'6',	'*',
    178 	'7',	'8',	'9',	'/',	'`',	'|',	'\\',	'~',
    179 	'!',	'\"',	'#',	'$',	'%',	'&',	'^',	'(',
    180 	')',	'=',	'?',	'/',	'{',	'}',	'@',	'|',
    181 	';',	':',	'_',	'\040',	'O',	'P',	'K',	'L',
    182 	'Q',	'W',	'E',	'R',	'T',	'Y',	'U',	'I',
    183 	'A',	'S',	'D',	'F',	'G',	'H',	'J',	'M',
    184 	'Z',	'X',	'C',	'V',	'B',	'N',	'\0',	'\0'
    185 };
    186 
    187 char hil_uk_ctrlmap[] = {
    188 	'\0',	'`',	'<',	ESC,	'\0',	DEL,	'\0',	'\0',
    189 	'\n',	'\t',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',
    190 	'\0',	'\n',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',
    191 	'\0',	'\t',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',
    192 	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',
    193 	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',	'\b',	'\0',
    194 	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',	'\0',
    195 	ESC,	'\r',	'\0',	'\n',	'0',	'.',	',',	'+',
    196 	'1',	'2',	'3',	'-',	'4',	'5',	'6',	'*',
    197 	'7',	'8',	'9',	'/',	'E',	'(',	')',	'\036',
    198 	'1',	'2',	'3',	'4',	'5',	'6',	'7',	'8',
    199 	'9',	'0',	'+',	'\'',	'\033',	'\035',	'*',	'\034',
    200 	',',	'.',	'/',	'\040',	'\017',	'\020',	'\013',	'\014',
    201 	'\021',	'\027',	'\005',	'\022',	'\024',	'\031',	'\025',	'\011',
    202 	'\001',	'\023',	'\004',	'\006',	'\007',	'\010',	'\012',	'\015',
    203 	'\032',	'\030',	'\003',	'\026',	'\002',	'\016',	'\0',	'\0'
    204 };
    205 #endif
    206 
    207 /*
    208  * The keyboard map table.
    209  * Lookup is by hardware returned language code.
    210  */
    211 struct kbdmap hilkbd_map[] = {
    212 	{ KBD_US, "",
    213 	    hil_us_keymap, hil_us_shiftmap, hil_us_ctrlmap, NULL, NULL},
    214 
    215 #ifdef UK_KEYBOARD
    216 	{ KBD_UK, "",
    217 	    hil_uk_keymap, hil_uk_shiftmap, hil_uk_ctrlmap, NULL, NULL},
    218 #endif
    219 
    220 	{ 0, "",
    221 	    NULL, NULL, NULL, NULL, NULL},
    222 };
    223 
    224 char	*hilkbd_keymap = hil_us_keymap;
    225 char	*hilkbd_shiftmap = hil_us_shiftmap;
    226 char	*hilkbd_ctrlmap = hil_us_ctrlmap;
    227 
    228 int
    229 hilkbd_getc(void)
    230 {
    231 	int status, c;
    232 	struct hil_dev *hiladdr = HILADDR;
    233 
    234 	status = hiladdr->hil_stat;
    235 	if ((status & HIL_DATA_RDY) == 0)
    236 		return 0;
    237 	c = hiladdr->hil_data;
    238 	switch ((status>>KBD_SSHIFT) & KBD_SMASK) {
    239 	case KBD_SHIFT:
    240 		c = hilkbd_shiftmap[c & KBD_CHARMASK];
    241 		break;
    242 	case KBD_CTRL:
    243 		c = hilkbd_ctrlmap[c & KBD_CHARMASK];
    244 		break;
    245 	case KBD_KEY:
    246 		c = hilkbd_keymap[c & KBD_CHARMASK];
    247 		break;
    248 	default:
    249 		c = 0;
    250 		break;
    251 	}
    252 	return c;
    253 }
    254 #endif /* SMALL */
    255 
    256 void
    257 hilkbd_nmi(void)
    258 {
    259 	struct hil_dev *hiladdr = HILADDR;
    260 
    261 	HILWAIT(hiladdr);
    262 	hiladdr->hil_cmd = HIL_CNMT;
    263 	HILWAIT(hiladdr);
    264 	hiladdr->hil_cmd = HIL_CNMT;
    265 	HILWAIT(hiladdr);
    266 }
    267 
    268 int
    269 hilkbd_init(void)
    270 {
    271 	struct hil_dev *hiladdr = HILADDR;
    272 	struct kbdmap *km;
    273 	u_char lang;
    274 
    275 	/*
    276 	 * Determine the existence of a HIL keyboard.
    277 	 */
    278 	HILWAIT(hiladdr);
    279 	hiladdr->hil_cmd = HIL_READKBDSADR;
    280 	HILDATAWAIT(hiladdr);
    281 	lang = hiladdr->hil_data;
    282 	if (lang == 0)
    283 		return 0;
    284 
    285 	HILWAIT(hiladdr);
    286 	hiladdr->hil_cmd = HIL_SETARR;
    287 	HILWAIT(hiladdr);
    288 	hiladdr->hil_data = ar_format(KBD_ARR);
    289 	HILWAIT(hiladdr);
    290 	hiladdr->hil_cmd = HIL_READKBDLANG;
    291 	HILDATAWAIT(hiladdr);
    292 	lang = hiladdr->hil_data;
    293 	for (km = hilkbd_map; km->kbd_code; km++) {
    294 		if (km->kbd_code == lang) {
    295 			hilkbd_keymap = km->kbd_keymap;
    296 			hilkbd_shiftmap = km->kbd_shiftmap;
    297 			hilkbd_ctrlmap = km->kbd_ctrlmap;
    298 		}
    299 	}
    300 	HILWAIT(hiladdr);
    301 	hiladdr->hil_cmd = HIL_INTON;
    302 	return 1;
    303 }
    304 #endif /* ITECONSOLE && HIL_KEYBOARD */
    305