1 /*-
2 * Copyright (c) 1999, 2000 Hellmuth Michaelis
3 *
4 * Copyright (c) 1992, 1995 Hellmuth Michaelis and Joerg Wunsch.
5 *
6 * Copyright (c) 1992, 1993 Brian Dunford-Shore and Holger Veit.
7 *
8 * All rights reserved.
9 *
10 * This code is derived from software contributed to Berkeley by
11 * William Jolitz and Don Ahn.
12 *
13 * This code is derived from software contributed to 386BSD by
14 * Holger Veit.
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 * 3. All advertising materials mentioning features or use of this software
25 * must display the following acknowledgement:
26 * This product includes software developed by Hellmuth Michaelis,
27 * Brian Dunford-Shore and Joerg Wunsch.
28 * 4. The name authors may not be used to endorse or promote products
29 * derived from this software without specific prior written permission.
30 *
31 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
32 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
33 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
34 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
35 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
36 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
40 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 */
42
43 /*---------------------------------------------------------------------------*
44 *
45 * pcvt_kbd.c VT220 Driver Keyboard Interface Code
46 * ----------------------------------------------------
47 *
48 * Last Edit-Date: [Wed Apr 5 18:16:52 2000]
49 *
50 * $FreeBSD: releng/5.4/sys/i386/isa/pcvt/pcvt_kbd.c 141090 2005-01-31 23:27:04Z imp $
51 *
52 *---------------------------------------------------------------------------*/
53
54 #include "opt_ddb.h"
55
56 #include <i386/isa/pcvt/pcvt_hdr.h> /* global include */
57
58 #define LEDSTATE_UPDATE_PENDING (1 << 3)
59
60 static void fkey1(void), fkey2(void), fkey3(void), fkey4(void);
61 static void fkey5(void), fkey6(void), fkey7(void), fkey8(void);
62 static void fkey9(void), fkey10(void), fkey11(void), fkey12(void);
63
64 static void sfkey1(void), sfkey2(void), sfkey3(void), sfkey4(void);
65 static void sfkey5(void), sfkey6(void), sfkey7(void), sfkey8(void);
66 static void sfkey9(void), sfkey10(void), sfkey11(void), sfkey12(void);
67
68 static void cfkey1(void), cfkey2(void), cfkey3(void), cfkey4(void);
69 static void cfkey5(void), cfkey6(void), cfkey7(void), cfkey8(void);
70 static void cfkey9(void), cfkey10(void), cfkey11(void), cfkey12(void);
71
72 #include <i386/isa/pcvt/pcvt_kbd.h> /* tables etc */
73
74 static void doreset ( void );
75 static void ovlinit ( int force );
76 static void settpmrate ( int rate );
77 static void setlockkeys ( int snc );
78 static int getokeydef ( unsigned key, struct kbd_ovlkey *thisdef );
79 static int getckeydef ( unsigned key, struct kbd_ovlkey *thisdef );
80 static int rmkeydef ( int key );
81 static void scrollback_save_screen ( void );
82 static void scrollback_restore_screen ( void );
83 static int setkeydef ( struct kbd_ovlkey *data );
84 static u_char *xlatkey2ascii( int key );
85
86 static int ledstate = LEDSTATE_UPDATE_PENDING; /* keyboard led's */
87 static int tpmrate = KBD_TPD500|KBD_TPM100;
88 static u_char altkpflag = 0;
89 static u_short altkpval = 0;
90 static u_short *scrollback_savedscreen = (u_short *)0;
91 static size_t scrnsv_size = (size_t)-1;
92 static int lost_intr_timeout_queued = 0;
93 static struct callout_handle lost_intr_ch =
94 CALLOUT_HANDLE_INITIALIZER(&lost_intr_ch);
95
96 #if PCVT_SHOWKEYS
97 u_char rawkeybuf[80];
98 #endif
99
100 #if PCVT_USEKBDSEC /* security enabled */
101
102 # if PCVT_SCANSET == 2
103 # define KBDINITCMD 0
104 # else /* PCVT_SCANSET != 2 */
105 # define KBDINITCMD KBD_TRANSLATION
106 # endif /* PCVT_SCANSET == 2 */
107
108 #else /* ! PCVT_USEKBDSEC */ /* security disabled */
109
110 # if PCVT_SCANSET == 2
111 # define KBDINITCMD KBD_OVERRIDE_KBD_LOCK
112 # else /* PCVT_SCANSET != 2 */
113 # define KBDINITCMD KBD_TRANSLATION | KBD_OVERRIDE_KBD_LOCK
114 # endif /* PCVT_SCANSET == 2 */
115
116 #endif /* PCVT_USEKBDSEC */
117
118 #if PCVT_SHOWKEYS
119 /*---------------------------------------------------------------------------*
120 * keyboard debugging: put kbd communication char into some buffer
121 *---------------------------------------------------------------------------*/
122 static void showkey (char delim, u_char val)
123 {
124 int rki;
125
126 for(rki = 3; rki < 80; rki++) /* shift left buffer */
127 rawkeybuf[rki-3] = rawkeybuf[rki];
128
129 rawkeybuf[77] = delim; /* delimiter */
130
131 rki = (val & 0xf0) >> 4; /* ms nibble */
132
133 if(rki <= 9)
134 rki = rki + '';
135 else
136 rki = rki - 10 + 'A';
137
138 rawkeybuf[78] = rki;
139
140 rki = val & 0x0f; /* ls nibble */
141
142 if(rki <= 9)
143 rki = rki + '';
144 else
145 rki = rki - 10 + 'A';
146
147 rawkeybuf[79] = rki;
148 }
149 #endif /* PCVT_SHOWKEYS */
150
151 /*---------------------------------------------------------------------------*
152 * function to switch to another virtual screen
153 *---------------------------------------------------------------------------*/
154 static void
155 do_vgapage(int page)
156 {
157 if(critical_scroll) /* executing critical region ? */
158 switch_page = page; /* yes, auto switch later */
159 else
160 vgapage(page); /* no, switch now */
161 }
162
163 /*---------------------------------------------------------------------------*
164 * check for lost keyboard interrupts
165 *---------------------------------------------------------------------------*/
166 static void
167 check_for_lost_intr(void *arg)
168 {
169 int opri;
170
171 lost_intr_timeout_queued = 0;
172
173 if (kbd && (*kbdsw[kbd->kb_index]->lock)(kbd, TRUE))
174 {
175 opri = spltty ();
176 (*kbdsw[kbd->kb_index]->lock)(kbd, FALSE);
177 if ((*kbdsw[kbd->kb_index]->check)(kbd))
178 pcvt_rint(0);
179 splx (opri);
180 }
181
182 lost_intr_ch = timeout(check_for_lost_intr, (void *)NULL, hz);
183 lost_intr_timeout_queued = 1;
184 }
185
186 /*---------------------------------------------------------------------------*
187 * update keyboard led's
188 *---------------------------------------------------------------------------*/
189 void
190 update_led(void)
191 {
192 #if !PCVT_NO_LED_UPDATE
193
194 /* Don't update LED's unless necessary. */
195
196 int opri, new_ledstate;
197
198 opri = spltty();
199
200 new_ledstate = ((vsp->scroll_lock) ? LED_SCR : 0) |
201 ((vsp->num_lock) ? LED_NUM : 0) |
202 ((vsp->caps_lock) ? LED_CAP : 0);
203
204 if (new_ledstate != ledstate)
205 {
206 if (kbd == NULL)
207 {
208 ledstate = new_ledstate;
209 splx(opri);
210 }
211 else
212 {
213 ledstate = LEDSTATE_UPDATE_PENDING;
214 splx(opri);
215 if ((*kbdsw[kbd->kb_index]->ioctl)(kbd, KDSETLED,
216 (caddr_t)&new_ledstate) == 0)
217 ledstate = new_ledstate;
218 }
219 }
220 #endif /* !PCVT_NO_LED_UPDATE */
221 }
222
223 /*---------------------------------------------------------------------------*
224 * set typematic rate
225 *---------------------------------------------------------------------------*/
226 static void
227 settpmrate(int rate)
228 {
229 if (kbd == NULL)
230 return;
231 tpmrate = rate & 0x7f;
232 if ((*kbdsw[kbd->kb_index]->ioctl)(kbd, KDSETRAD, (caddr_t)&tpmrate))
233 printf("pcvt: failed to set keyboard TYPEMATIC.\n");
234 }
235
236 #if PCVT_SCANSET > 1
237 /*---------------------------------------------------------------------------*
238 * switch PC scan code emulation mode
239 *---------------------------------------------------------------------------*/
240 void
241 kbd_emulate_pc(int do_emulation)
242 {
243 set_controller_command_byte(*(KBDC *)kbd->kb_data, KBD_TRANSLATION,
244 (do_emulation) ? KBD_TRANSLATION : 0);
245 }
246 #endif /* PCVT_SCANSET > 1 */
247
248 /*---------------------------------------------------------------------------*
249 * try to force keyboard into a known state ..
250 *---------------------------------------------------------------------------*/
251 static
252 void doreset(void)
253 {
254 int type;
255
256 if (!reset_keyboard) /* no, we are not ready to reset */
257 return;
258
259 if (lost_intr_timeout_queued)
260 {
261 untimeout(check_for_lost_intr, (void *)NULL, lost_intr_ch);
262 lost_intr_timeout_queued = 0;
263 }
264
265 if (kbd == NULL)
266 return; /* shouldn't happen */
267
268 kbd_configure(0);
269
270 ledstate = LEDSTATE_UPDATE_PENDING;
271
272 set_controller_command_byte(*(KBDC *)kbd->kb_data,
273 KBD_OVERRIDE_KBD_LOCK | KBD_TRANSLATION, KBDINITCMD);
274
275 type = KB_101;
276
277 (*kbdsw[kbd->kb_index]->ioctl)(kbd, KDGKBTYPE, (caddr_t)&type);
278
279 switch (type)
280 {
281 case KB_84:
282 keyboard_type = KB_AT;
283 break;
284 case KB_101:
285 keyboard_type = KB_MFII;
286 break;
287 default:
288 keyboard_type = KB_UNKNOWN;
289 break;
290 }
291
292 update_led();
293
294 lost_intr_ch = timeout(check_for_lost_intr, (void *)NULL, hz);
295 lost_intr_timeout_queued = 1;
296 }
297
298 /*---------------------------------------------------------------------------*
299 * init keyboard code
300 *---------------------------------------------------------------------------*/
301 void
302 kbd_code_init(void)
303 {
304 doreset();
305 ovlinit(0);
306 keyboard_is_initialized = 1;
307 }
308
309 /*---------------------------------------------------------------------------*
310 * init keyboard code, this initializes the keyboard subsystem
311 * just "a bit" so the very very first ddb session is able to
312 * get proper keystrokes - in other words, it's a hack ....
313 *---------------------------------------------------------------------------*/
314 void
315 kbd_code_init1(void)
316 {
317 doreset();
318 keyboard_is_initialized = 1;
319 }
320
321 /*---------------------------------------------------------------------------*
322 * init keyboard overlay table
323 *---------------------------------------------------------------------------*/
324 static
325 void ovlinit(int force)
326 {
327 register int i;
328
329 if(force || ovlinitflag==0)
330 {
331 if(ovlinitflag == 0 &&
332 (ovltbl = (Ovl_tbl *)malloc(sizeof(Ovl_tbl) * OVLTBL_SIZE,
333 M_DEVBUF, M_WAITOK)) == NULL)
334 panic("pcvt_kbd: malloc of Ovl_tbl failed");
335
336 for(i=0; i<OVLTBL_SIZE; i++)
337 {
338 ovltbl[i].keynum =
339 ovltbl[i].type = 0;
340 ovltbl[i].unshift[0] =
341 ovltbl[i].shift[0] =
342 ovltbl[i].ctrl[0] =
343 ovltbl[i].altgr[0] = 0;
344 ovltbl[i].subu =
345 ovltbl[i].subs =
346 ovltbl[i].subc =
347 ovltbl[i].suba = KBD_SUBT_STR; /* just strings .. */
348 }
349 for(i=0; i<=MAXKEYNUM; i++)
350 key2ascii[i].type &= KBD_MASK;
351 ovlinitflag = 1;
352 }
353 }
354
355 /*---------------------------------------------------------------------------*
356 * get original key definition
357 *---------------------------------------------------------------------------*/
358 static int
359 getokeydef(unsigned key, Ovl_tbl *thisdef)
360 {
361 if(key == 0 || key > MAXKEYNUM)
362 return EINVAL;
363
364 thisdef->keynum = key;
365 thisdef->type = key2ascii[key].type;
366
367 if(key2ascii[key].unshift.subtype == STR)
368 {
369 bcopy((u_char *)(key2ascii[key].unshift.what.string),
370 thisdef->unshift, CODE_SIZE);
371 thisdef->subu = KBD_SUBT_STR;
372 }
373 else
374 {
375 bcopy("", thisdef->unshift, CODE_SIZE);
376 thisdef->subu = KBD_SUBT_FNC;
377 }
378
379 if(key2ascii[key].shift.subtype == STR)
380 {
381 bcopy((u_char *)(key2ascii[key].shift.what.string),
382 thisdef->shift, CODE_SIZE);
383 thisdef->subs = KBD_SUBT_STR;
384 }
385 else
386 {
387 bcopy("",thisdef->shift,CODE_SIZE);
388 thisdef->subs = KBD_SUBT_FNC;
389 }
390
391 if(key2ascii[key].ctrl.subtype == STR)
392 {
393 bcopy((u_char *)(key2ascii[key].ctrl.what.string),
394 thisdef->ctrl, CODE_SIZE);
395 thisdef->subc = KBD_SUBT_STR;
396 }
397 else
398 {
399 bcopy("",thisdef->ctrl,CODE_SIZE);
400 thisdef->subc = KBD_SUBT_FNC;
401 }
402
403 /* deliver at least anything for ALTGR settings ... */
404
405 if(key2ascii[key].unshift.subtype == STR)
406 {
407 bcopy((u_char *)(key2ascii[key].unshift.what.string),
408 thisdef->altgr, CODE_SIZE);
409 thisdef->suba = KBD_SUBT_STR;
410 }
411 else
412 {
413 bcopy("",thisdef->altgr, CODE_SIZE);
414 thisdef->suba = KBD_SUBT_FNC;
415 }
416 return 0;
417 }
418
419 /*---------------------------------------------------------------------------*
420 * get current key definition
421 *---------------------------------------------------------------------------*/
422 static int
423 getckeydef(unsigned key, Ovl_tbl *thisdef)
424 {
425 u_short type = key2ascii[key].type;
426
427 if(key>MAXKEYNUM)
428 return EINVAL;
429
430 if(type & KBD_OVERLOAD)
431 *thisdef = ovltbl[key2ascii[key].ovlindex];
432 else
433 getokeydef(key,thisdef);
434
435 return 0;
436 }
437
438 /*---------------------------------------------------------------------------*
439 * translate keynumber and returns ptr to associated ascii string
440 * if key is bound to a function, executes it, and ret empty ptr
441 *---------------------------------------------------------------------------*/
442 static u_char *
443 xlatkey2ascii(int key)
444 {
445 static u_char capchar[2] = {0, 0};
446 #if PCVT_META_ESC
447 static u_char metachar[3] = {0x1b, 0, 0};
448 #else
449 static u_char metachar[2] = {0, 0};
450 #endif
451 static Ovl_tbl thisdef;
452 int n;
453 void (*fnc)(void);
454
455 if(key==0) /* ignore the NON-KEY */
456 return 0;
457
458 getckeydef(key&0x7F, &thisdef); /* get the current ASCII value */
459
460 thisdef.type &= KBD_MASK;
461
462 if(key&0x80) /* special handling of ALT-KEYPAD */
463 {
464 /* is the ALT Key released? */
465 if(thisdef.type==KBD_META || thisdef.type==KBD_ALTGR)
466 {
467 if(altkpflag) /* have we been in altkp mode? */
468 {
469 capchar[0] = altkpval;
470 altkpflag = 0;
471 altkpval = 0;
472 return capchar;
473 }
474 }
475 return 0;
476 }
477
478 switch(thisdef.type) /* convert the keys */
479 {
480 case KBD_BREAK:
481 case KBD_ASCII:
482 case KBD_FUNC:
483 fnc = NULL;
484 more_chars = NULL;
485
486 if(altgr_down)
487 {
488 more_chars = (u_char *)thisdef.altgr;
489 }
490 else if(!ctrl_down && (shift_down || vsp->shift_lock))
491 {
492 if(key2ascii[key].shift.subtype == STR)
493 more_chars = (u_char *)thisdef.shift;
494 else
495 fnc = key2ascii[key].shift.what.func;
496 }
497
498 else if(ctrl_down)
499 {
500 if(key2ascii[key].ctrl.subtype == STR)
501 more_chars = (u_char *)thisdef.ctrl;
502 else
503 fnc = key2ascii[key].ctrl.what.func;
504 }
505
506 else
507 {
508 if(key2ascii[key].unshift.subtype == STR)
509 more_chars = (u_char *)thisdef.unshift;
510 else
511 fnc = key2ascii[key].unshift.what.func;
512 }
513
514 if(fnc)
515 (*fnc)(); /* execute function */
516
517 if((more_chars != NULL) && (more_chars[1] == 0))
518 {
519 if(vsp->caps_lock && more_chars[0] >= 'a'
520 && more_chars[0] <= 'z')
521 {
522 capchar[0] = *more_chars - ('a'-'A');
523 more_chars = capchar;
524 }
525 if(meta_down)
526 {
527 #if PCVT_META_ESC
528 metachar[1] = *more_chars;
529 #else
530 metachar[0] = *more_chars | 0x80;
531 #endif
532 more_chars = metachar;
533 }
534 }
535 return(more_chars);
536
537 case KBD_KP:
538 fnc = NULL;
539 more_chars = NULL;
540
541 if(meta_down)
542 {
543 switch(key)
544 {
545 case 95: /* / */
546 altkpflag = 0;
547 more_chars =
548 (u_char *)"\033OQ";
549 return(more_chars);
550
551 case 100: /* * */
552 altkpflag = 0;
553 more_chars =
554 (u_char *)"\033OR";
555 return(more_chars);
556
557 case 105: /* - */
558 altkpflag = 0;
559 more_chars =
560 (u_char *)"\033OS";
561 return(more_chars);
562 }
563 }
564
565 if(meta_down || altgr_down)
566 {
567 if((n = keypad2num[key-91]) >= 0)
568 {
569 if(!altkpflag)
570 {
571 /* start ALT-KP mode */
572 altkpflag = 1;
573 altkpval = 0;
574 }
575 altkpval *= 10;
576 altkpval += n;
577 }
578 else
579 altkpflag = 0;
580 return 0;
581 }
582
583 if(!(vsp->num_lock))
584 {
585 if(key2ascii[key].shift.subtype == STR)
586 more_chars = (u_char *)thisdef.shift;
587 else
588 fnc = key2ascii[key].shift.what.func;
589 }
590 else
591 {
592 if(key2ascii[key].unshift.subtype == STR)
593 more_chars = (u_char *)thisdef.unshift;
594 else
595 fnc = key2ascii[key].unshift.what.func;
596 }
597
598 if(fnc)
599 (*fnc)(); /* execute function */
600 return(more_chars);
601
602 case KBD_CURSOR:
603 fnc = NULL;
604 more_chars = NULL;
605
606 if(vsp->ckm)
607 {
608 if(key2ascii[key].shift.subtype == STR)
609 more_chars = (u_char *)thisdef.shift;
610 else
611 fnc = key2ascii[key].shift.what.func;
612 }
613 else
614 {
615 if(key2ascii[key].unshift.subtype == STR)
616 more_chars = (u_char *)thisdef.unshift;
617 else
618 fnc = key2ascii[key].unshift.what.func;
619 }
620
621 if(fnc)
622 (*fnc)(); /* execute function */
623 return(more_chars);
624
625 case KBD_NUM: /* special kp-num handling */
626 more_chars = NULL;
627
628 if(meta_down)
629 {
630 more_chars = (u_char *)"\033OP"; /* PF1 */
631 }
632 else
633 {
634 vsp->num_lock ^= 1;
635 update_led();
636 }
637 return(more_chars);
638
639 case KBD_RETURN:
640 more_chars = NULL;
641
642 if(!(vsp->num_lock))
643 {
644 more_chars = (u_char *)thisdef.shift;
645 }
646 else
647 {
648 more_chars = (u_char *)thisdef.unshift;
649 }
650 if(vsp->lnm && (*more_chars == '\r'))
651 {
652 more_chars = (u_char *)"\r\n"; /* CR LF */
653 }
654 if(meta_down)
655 {
656 #if PCVT_META_ESC
657 metachar[1] = *more_chars;
658 #else
659 metachar[0] = *more_chars | 0x80;
660 #endif
661 more_chars = metachar;
662 }
663 return(more_chars);
664
665 case KBD_META: /* these keys are */
666 case KBD_ALTGR: /* handled directly */
667 case KBD_SCROLL: /* by the keyboard */
668 case KBD_CAPS: /* handler - they are */
669 case KBD_SHFTLOCK: /* ignored here */
670 case KBD_CTL:
671 case KBD_NONE:
672 default:
673 return 0;
674 }
675 }
676
677 /*---------------------------------------------------------------------------*
678 * get keystrokes from the keyboard.
679 * if noblock = 0, wait until a key is pressed.
680 * else return NULL if no characters present.
681 *---------------------------------------------------------------------------*/
682 u_char *
683 sgetc(int noblock)
684 {
685 u_char *cp;
686 u_char dt = 0;
687 u_char key = 0;
688 u_short type;
689 int c;
690
691 #if PCVT_SLOW_INTERRUPT
692 int s;
693 #endif
694
695 #ifdef XSERVER
696 static char keybuf[2] = {0}; /* the second 0 is a delimiter! */
697 #endif /* XSERVER */
698
699 static u_char kbd_lastkey = 0; /* last keystroke */
700
701 static struct
702 {
703 u_char extended: 1; /* extended prefix seen */
704 u_char ext1: 1; /* extended prefix 1 seen */
705 u_char breakseen: 1; /* break code seen */
706 u_char vshift: 1; /* virtual shift pending */
707 u_char vcontrol: 1; /* virtual control pending */
708 u_char sysrq: 1; /* sysrq pressed */
709 } kbd_status = {0};
710
711 loop:
712
713 if(noblock == SCROLLBACK_COOKIE)
714 {
715 vsp->scrolling = 1;
716 goto scroll_reset;
717 }
718
719 #ifdef XSERVER
720
721 if (pcvt_kbd_count)
722 {
723 dt = pcvt_kbd_fifo[pcvt_kbd_rptr++];
724 PCVT_DISABLE_INTR();
725 pcvt_kbd_count--;
726 PCVT_ENABLE_INTR();
727 if (pcvt_kbd_rptr >= PCVT_KBD_FIFO_SZ)
728 pcvt_kbd_rptr = 0;
729 }
730 else if (!noblock)
731 {
732 while ((c = (*kbdsw[kbd->kb_index]->read)(kbd, TRUE)) == -1)
733 ;
734 dt = c;
735 }
736 else
737 {
738 if ((c = (*kbdsw[kbd->kb_index]->read)(kbd, FALSE)) == -1)
739 return NULL;
740 dt = c;
741 }
742
743 /*
744 * If x mode is active, only care for locking keys, then
745 * return the scan code instead of any key translation.
746 * Additionally, this prevents us from any attempts to
747 * execute pcvt internal functions caused by keys (such
748 * as screen flipping).
749 */
750 if (pcvt_kbd_raw)
751 {
752 keybuf[0] = dt;
753
754 random_harvest(keybuf, sizeof(keybuf), 1, 0, RANDOM_KEYBOARD);
755
756 return ((u_char *)keybuf);
757 }
758
759 #else /* !XSERVER */
760
761 if (pcvt_kbd_count)
762 {
763 dt = pcvt_kbd_fifo[pcvt_kbd_rptr++];
764 PCVT_DISABLE_INTR();
765 pcvt_kbd_count--;
766 PCVT_ENABLE_INTR();
767 if (pcvt_kbd_rptr >= PCVT_KBD_FIFO_SZ)
768 pcvt_kbd_rptr = 0;
769 }
770 else if (!noblock)
771 {
772 while ((c = (*kbdsw[kbd->kb_index]->read)(kbd, TRUE)) == -1)
773 ;
774 dt = c;
775 }
776 else
777 {
778 if ((c = (*kbdsw[kbd->kb_index]->read)(kbd, FALSE)) == -1)
779 return NULL;
780 dt = c;
781 }
782 #endif /* !XSERVER */
783
784 #if PCVT_SHOWKEYS
785 showkey (' ', dt);
786 #endif /* PCVT_SHOWKEYS */
787
788 /* lets look what we got */
789 switch(dt)
790 {
791 case KEYB_R_OVERRUN0: /* keyboard buffer overflow */
792
793 #if PCVT_SCANSET == 2
794 case KEYB_R_SELFOK: /* keyboard selftest ok */
795 #endif /* PCVT_SCANSET == 2 */
796
797 case KEYB_R_ECHO: /* keyboard response to KEYB_C_ECHO */
798 case KEYB_R_ACK: /* acknowledge after command has rx'd*/
799 case KEYB_R_SELFBAD: /* keyboard selftest FAILED */
800 case KEYB_R_DIAGBAD: /* keyboard self diagnostic failure */
801 case KEYB_R_RESEND: /* keyboard wants us to resend cmnd */
802 case KEYB_R_OVERRUN1: /* keyboard buffer overflow */
803 break;
804
805 case KEYB_R_EXT1: /* keyboard extended scancode pfx 2 */
806 kbd_status.ext1 = 1;
807 /* FALLTHROUGH */
808 case KEYB_R_EXT0: /* keyboard extended scancode pfx 1 */
809 kbd_status.extended = 1;
810 break;
811
812 #if PCVT_SCANSET == 2
813 case KEYB_R_BREAKPFX: /* break code prefix for set 2 and 3 */
814 kbd_status.breakseen = 1;
815 break;
816 #endif /* PCVT_SCANSET == 2 */
817
818 default:
819 goto regular; /* regular key */
820 }
821
822 if(noblock)
823 return NULL;
824 else
825 goto loop;
826
827 /* got a normal scan key */
828 regular:
829
830 random_harvest(&dt, sizeof(dt), 1, 0, RANDOM_KEYBOARD);
831
832 #if PCVT_SCANSET == 1
833 kbd_status.breakseen = dt & 0x80 ? 1 : 0;
834 dt &= 0x7f;
835 #endif /* PCVT_SCANSET == 1 */
836
837 /* make a keycode from scan code */
838 if(dt >= sizeof scantokey / sizeof(u_char))
839 key = 0;
840 else
841 key = kbd_status.extended ? extscantokey[dt] : scantokey[dt];
842
843 if(kbd_status.ext1 && key == 64)
844 /* virtual control key */
845 key = 129;
846
847 kbd_status.extended = kbd_status.ext1 = 0;
848
849 if ((key == 85) && shift_down && kbd_lastkey != 85)
850 {
851 if (vsp->scr_offset > (vsp->screen_rows - 1))
852 {
853 if (!vsp->scrolling)
854 {
855 vsp->scrolling += vsp->screen_rows - 2;
856 if (vsp->Scrollback)
857 {
858 scrollback_save_screen();
859 if (vsp->scr_offset == vsp->max_off)
860 {
861 bcopy(vsp->Scrollback +
862 vsp->maxcol,
863 vsp->Scrollback,
864 vsp->maxcol *
865 vsp->max_off * CHR);
866 vsp->scr_offset--;
867 }
868 bcopy(vsp->Crtat + vsp->cur_offset -
869 vsp->col, vsp->Scrollback +
870 ((vsp->scr_offset + 1) *
871 vsp->maxcol), vsp->maxcol * CHR);
872 }
873
874 if (vsp->cursor_on)
875 sw_cursor(0);
876 }
877
878 vsp->scrolling += vsp->screen_rows - 1;
879
880 if (vsp->scrolling > vsp->scr_offset)
881 vsp->scrolling = vsp->scr_offset;
882
883 bcopy(vsp->Scrollback + ((vsp->scr_offset -
884 vsp->scrolling) * vsp->maxcol), vsp->Crtat,
885 vsp->screen_rows * vsp->maxcol * CHR);
886 }
887
888 kbd_lastkey = 85;
889 goto loop;
890 }
891 else if ((key == 86) && shift_down && kbd_lastkey != 86)
892 {
893
894 scroll_reset:
895 if (vsp->scrolling > 0)
896 {
897 vsp->scrolling -= vsp->screen_rows - 1;
898 if (vsp->scrolling < 0)
899 vsp->scrolling = 0;
900
901 if (vsp->scrolling <= vsp->screen_rows)
902 {
903 vsp->scrolling = 0;
904 scrollback_restore_screen();
905 }
906 else
907 {
908 bcopy(vsp->Scrollback + ((vsp->scr_offset -
909 vsp->scrolling) * vsp->maxcol),
910 vsp->Crtat, vsp->screen_rows *
911 vsp->maxcol * CHR);
912 }
913 }
914
915 if (vsp->scrolling == 0)
916 {
917 if (vsp->cursor_on)
918 {
919 sw_cursor(1);
920 }
921 }
922
923 if (noblock == SCROLLBACK_COOKIE)
924 return NULL;
925
926 if (key != 86)
927 {
928 goto regular;
929 }
930 else
931 {
932 kbd_lastkey = 86;
933 goto loop;
934 }
935 }
936 else if (vsp->scrolling && key != 128 && key != 44 && key != 85 &&
937 key != 86)
938 {
939 vsp->scrolling = 1;
940 goto scroll_reset;
941 }
942
943 #if PCVT_CTRL_ALT_DEL /* Check for cntl-alt-del */
944 if((key == 76) && ctrl_down && (meta_down||altgr_down))
945 shutdown_nice(0);
946 #endif /* PCVT_CTRL_ALT_DEL */
947
948 #if defined(KDB) /* Check for cntl-alt-esc */
949
950 if((key == 110) && ctrl_down && (meta_down || altgr_down))
951 {
952 if (!kdb_active)
953 {
954 kdb_enter("kbd");
955 if(noblock)
956 return NULL;
957 else
958 goto loop;
959 }
960 }
961 #endif /* defined(KDB) */
962
963 /* look for keys with special handling */
964 if(key == 128)
965 {
966 /*
967 * virtual shift; sent around PrtScr, and around the arrow
968 * keys if the NumLck LED is on
969 */
970 kbd_status.vshift = !kbd_status.breakseen;
971 key = 0; /* no key */
972 }
973 else if(key == 129)
974 {
975 /*
976 * virtual control - the most ugly thingie at all
977 * the Pause key sends:
978 * <virtual control make> <numlock make> <virtual control
979 * break> <numlock break>
980 */
981 if(!kbd_status.breakseen)
982 kbd_status.vcontrol = 1;
983 /* else: let the numlock hook clear this */
984 key = 0; /* no key */
985 }
986 else if(key == 90)
987 {
988 /* NumLock, look whether this is rather a Pause */
989 if(kbd_status.vcontrol)
990 key = 126;
991 /*
992 * if this is the final break code of a Pause key,
993 * clear the virtual control status, too
994 */
995 if(kbd_status.vcontrol && kbd_status.breakseen)
996 kbd_status.vcontrol = 0;
997 }
998 else if(key == 127)
999 {
1000 /*
1001 * a SysRq; some keyboards are brain-dead enough to
1002 * repeat the SysRq key make code by sending PrtScr
1003 * make codes; other keyboards do not repeat SysRq
1004 * at all. We keep track of the SysRq state here.
1005 */
1006 kbd_status.sysrq = !kbd_status.breakseen;
1007 }
1008 else if(key == 124)
1009 {
1010 /*
1011 * PrtScr; look whether this is really PrtScr or rather
1012 * a silly repeat of a SysRq key
1013 */
1014 if(kbd_status.sysrq)
1015 /* ignore the garbage */
1016 key = 0;
1017 }
1018
1019 /* in NOREPEAT MODE ignore the key if it was the same as before */
1020
1021 if(!kbrepflag && key == kbd_lastkey && !kbd_status.breakseen)
1022 {
1023 if(noblock)
1024 return NULL;
1025 else
1026 goto loop;
1027 }
1028
1029 type = key2ascii[key].type;
1030
1031 if(type & KBD_OVERLOAD)
1032 type = ovltbl[key2ascii[key].ovlindex].type;
1033
1034 type &= KBD_MASK;
1035
1036 switch(type)
1037 {
1038 case KBD_SHFTLOCK:
1039 if(!kbd_status.breakseen && key != kbd_lastkey)
1040 {
1041 vsp->shift_lock ^= 1;
1042 }
1043 break;
1044
1045 case KBD_CAPS:
1046 if(!kbd_status.breakseen && key != kbd_lastkey)
1047 {
1048 vsp->caps_lock ^= 1;
1049 update_led();
1050 }
1051 break;
1052
1053 case KBD_SCROLL:
1054 if(!kbd_status.breakseen && key != kbd_lastkey)
1055 {
1056 vsp->scroll_lock ^= 1;
1057 update_led();
1058
1059 if(!(vsp->scroll_lock))
1060 {
1061 /* someone may be sleeping */
1062 wakeup(&(vsp->scroll_lock));
1063 }
1064 }
1065 break;
1066
1067 case KBD_SHIFT:
1068 shift_down = kbd_status.breakseen ? 0 : 1;
1069 break;
1070
1071 case KBD_META:
1072 meta_down = kbd_status.breakseen ? 0 : 0x80;
1073 break;
1074
1075 case KBD_ALTGR:
1076 altgr_down = kbd_status.breakseen ? 0 : 1;
1077 break;
1078
1079 case KBD_CTL:
1080 ctrl_down = kbd_status.breakseen ? 0 : 1;
1081 break;
1082
1083 case KBD_NONE:
1084 default:
1085 break; /* deliver a key */
1086 }
1087
1088 if(kbd_status.breakseen)
1089 {
1090 key |= 0x80;
1091 kbd_status.breakseen = 0;
1092 kbd_lastkey = 0; /* -hv- I know this is a bug with */
1093 } /* N-Key-Rollover, but I ignore that */
1094 else /* because avoidance is too complicated */
1095 kbd_lastkey = key;
1096
1097 cp = xlatkey2ascii(key); /* have a key */
1098
1099 if(cp == NULL && !noblock)
1100 goto loop;
1101
1102 return cp;
1103 }
1104
1105 /*---------------------------------------------------------------------------*
1106 * reflect status of locking keys & set led's
1107 *---------------------------------------------------------------------------*/
1108 static void
1109 setlockkeys(int snc)
1110 {
1111 vsp->scroll_lock = snc & 1;
1112 vsp->num_lock = (snc & 2) ? 1 : 0;
1113 vsp->caps_lock = (snc & 4) ? 1 : 0;
1114 update_led();
1115 }
1116
1117 /*---------------------------------------------------------------------------*
1118 * remove a key definition
1119 *---------------------------------------------------------------------------*/
1120 static int
1121 rmkeydef(int key)
1122 {
1123 register Ovl_tbl *ref;
1124
1125 if(key==0 || key > MAXKEYNUM)
1126 return EINVAL;
1127
1128 if(key2ascii[key].type & KBD_OVERLOAD)
1129 {
1130 ref = &ovltbl[key2ascii[key].ovlindex];
1131 ref->keynum = 0;
1132 ref->type = 0;
1133 ref->unshift[0] =
1134 ref->shift[0] =
1135 ref->ctrl[0] =
1136 ref->altgr[0] = 0;
1137 key2ascii[key].type &= KBD_MASK;
1138 }
1139 return 0;
1140 }
1141
1142 /*---------------------------------------------------------------------------*
1143 * overlay a key
1144 *---------------------------------------------------------------------------*/
1145 static int
1146 setkeydef(Ovl_tbl *data)
1147 {
1148 register int i;
1149
1150 if( data->keynum > MAXKEYNUM ||
1151 (data->type & KBD_MASK) == KBD_BREAK ||
1152 (data->type & KBD_MASK) > KBD_SHFTLOCK)
1153 return EINVAL;
1154
1155 data->unshift[KBDMAXOVLKEYSIZE] =
1156 data->shift[KBDMAXOVLKEYSIZE] =
1157 data->ctrl[KBDMAXOVLKEYSIZE] =
1158 data->altgr[KBDMAXOVLKEYSIZE] = 0;
1159
1160 data->subu =
1161 data->subs =
1162 data->subc =
1163 data->suba = KBD_SUBT_STR; /* just strings .. */
1164
1165 data->type |= KBD_OVERLOAD; /* mark overloaded */
1166
1167 /* if key already overloaded, use that slot else find free slot */
1168
1169 if(key2ascii[data->keynum].type & KBD_OVERLOAD)
1170 {
1171 i = key2ascii[data->keynum].ovlindex;
1172 }
1173 else
1174 {
1175 for(i=0; i<OVLTBL_SIZE; i++)
1176 if(ovltbl[i].keynum==0)
1177 break;
1178
1179 if(i==OVLTBL_SIZE)
1180 return ENOSPC; /* no space, abuse of ENOSPC(!) */
1181 }
1182
1183 ovltbl[i] = *data; /* copy new data string */
1184
1185 key2ascii[data->keynum].type |= KBD_OVERLOAD; /* mark key */
1186 key2ascii[data->keynum].ovlindex = i;
1187
1188 return 0;
1189 }
1190
1191 /*---------------------------------------------------------------------------*
1192 * keyboard ioctl's entry
1193 *---------------------------------------------------------------------------*/
1194 int
1195 kbdioctl(struct cdev *dev, int cmd, caddr_t data, int flag)
1196 {
1197 int key;
1198
1199 switch(cmd)
1200 {
1201 case KBDRESET:
1202 doreset();
1203 ovlinit(1);
1204 settpmrate(KBD_TPD500|KBD_TPM100);
1205 setlockkeys(0);
1206 break;
1207
1208 case KBDGTPMAT:
1209 *(int *)data = tpmrate;
1210 break;
1211
1212 case KBDSTPMAT:
1213 settpmrate(*(int *)data);
1214 break;
1215
1216 case KBDGREPSW:
1217 *(int *)data = kbrepflag;
1218 break;
1219
1220 case KBDSREPSW:
1221 kbrepflag = (*(int *)data) & 1;
1222 break;
1223
1224 case KBDGLEDS:
1225 *(int *)data = ledstate;
1226 break;
1227
1228 case KBDSLEDS:
1229 update_led(); /* ? */
1230 break;
1231
1232 case KBDGLOCK:
1233 *(int *)data = ( (vsp->scroll_lock) |
1234 (vsp->num_lock * 2) |
1235 (vsp->caps_lock * 4));
1236 break;
1237
1238 case KBDSLOCK:
1239 setlockkeys(*(int *)data);
1240 break;
1241
1242 case KBDGCKEY:
1243 key = ((Ovl_tbl *)data)->keynum;
1244 return getckeydef(key,(Ovl_tbl *)data);
1245
1246 case KBDSCKEY:
1247 key = ((Ovl_tbl *)data)->keynum;
1248 return setkeydef((Ovl_tbl *)data);
1249
1250 case KBDGOKEY:
1251 key = ((Ovl_tbl *)data)->keynum;
1252 return getokeydef(key,(Ovl_tbl *)data);
1253
1254 case KBDRMKEY:
1255 key = *(int *)data;
1256 return rmkeydef(key);
1257
1258 case KBDDEFAULT:
1259 ovlinit(1);
1260 break;
1261
1262 default:
1263 /* proceed with vga ioctls */
1264 return -1;
1265 }
1266 return 0;
1267 }
1268
1269 #ifdef XSERVER
1270 /*---------------------------------------------------------------------------*
1271 * convert ISO-8859 style keycode into IBM 437
1272 *---------------------------------------------------------------------------*/
1273 static __inline u_char
1274 iso2ibm(u_char c)
1275 {
1276 if(c < 0x80)
1277 return c;
1278 return iso2ibm437[c - 0x80];
1279 }
1280
1281 /*---------------------------------------------------------------------------*
1282 * build up a USL style keyboard map
1283 *---------------------------------------------------------------------------*/
1284 void
1285 get_usl_keymap(keymap_t *map)
1286 {
1287 int i;
1288
1289 bzero((caddr_t)map, sizeof(keymap_t));
1290
1291 map->n_keys = 0x59; /* that many keys we know about */
1292
1293 for(i = 1; i < N_KEYNUMS; i++)
1294 {
1295 Ovl_tbl kdef;
1296 u_char c;
1297 int j;
1298 int idx = key2scan1[i];
1299
1300 if(idx == 0 || idx >= map->n_keys)
1301 continue;
1302
1303 getckeydef(i, &kdef);
1304 kdef.type &= KBD_MASK;
1305 switch(kdef.type)
1306 {
1307 case KBD_ASCII:
1308 case KBD_RETURN:
1309 map->key[idx].map[0] = iso2ibm(kdef.unshift[0]);
1310 map->key[idx].map[1] = iso2ibm(kdef.shift[0]);
1311 map->key[idx].map[2] = map->key[idx].map[3] =
1312 iso2ibm(kdef.ctrl[0]);
1313 map->key[idx].map[4] = map->key[idx].map[5] =
1314 iso2ibm(c = kdef.altgr[0]);
1315 /*
1316 * XXX this is a hack
1317 * since we currently do not map strings to AltGr +
1318 * shift, we attempt to use the unshifted AltGr
1319 * definition here and try to toggle the case
1320 * this should at least work for ISO8859 letters,
1321 * but also for (e.g.) russian KOI-8 style
1322 */
1323 if((c & 0x7f) >= 0x40)
1324 map->key[idx].map[5] = iso2ibm(c ^ 0x20);
1325 break;
1326
1327 case KBD_FUNC:
1328 /* we are only interested in F1 thru F12 here */
1329 if(i >= 112 && i <= 123) {
1330 map->key[idx].map[0] = i - 112 + 27;
1331 map->key[idx].spcl = 0x80;
1332 }
1333 break;
1334
1335 case KBD_SHIFT:
1336 c = i == 44? 2 /* lSh */: 3 /* rSh */; goto special;
1337
1338 case KBD_CAPS:
1339 c = 4; goto special;
1340
1341 case KBD_NUM:
1342 c = 5; goto special;
1343
1344 case KBD_SCROLL:
1345 c = 6; goto special;
1346
1347 case KBD_META:
1348 c = 7; goto special;
1349
1350 case KBD_CTL:
1351 c = 9; goto special;
1352 special:
1353 for(j = 0; j < NUM_STATES; j++)
1354 map->key[idx].map[j] = c;
1355 map->key[idx].spcl = 0xff;
1356 break;
1357
1358 default:
1359 break;
1360 }
1361 }
1362 }
1363 #endif /* XSERVER */
1364
1365 /*---------------------------------------------------------------------------*
1366 * switch keypad to numeric mode
1367 *---------------------------------------------------------------------------*/
1368 void
1369 vt_keynum(struct video_state *svsp)
1370 {
1371 svsp->num_lock = 1;
1372 update_led();
1373 }
1374
1375 /*---------------------------------------------------------------------------*
1376 * switch keypad to application mode
1377 *---------------------------------------------------------------------------*/
1378 void
1379 vt_keyappl(struct video_state *svsp)
1380 {
1381 svsp->num_lock = 0;
1382 update_led();
1383 }
1384
1385 #if !PCVT_VT220KEYB /* !PCVT_VT220KEYB, HP-like Keyboard layout */
1386
1387 /*---------------------------------------------------------------------------*
1388 * function bound to function key 1
1389 *---------------------------------------------------------------------------*/
1390 static void
1391 fkey1(void)
1392 {
1393 if(!meta_down)
1394 {
1395 if((vsp->vt_pure_mode == M_HPVT)
1396 && (vsp->which_fkl == SYS_FKL))
1397 toggl_columns(vsp);
1398 else
1399 more_chars = (u_char *)"\033[17~"; /* F6 */
1400 }
1401 else
1402 {
1403 if(vsp->vt_pure_mode == M_PUREVT
1404 || (vsp->which_fkl == USR_FKL))
1405 more_chars = (u_char *)"\033[26~"; /* F14 */
1406 }
1407 }
1408
1409 /*---------------------------------------------------------------------------*
1410 * function bound to function key 2
1411 *---------------------------------------------------------------------------*/
1412 static void
1413 fkey2(void)
1414 {
1415 if(!meta_down)
1416 {
1417 if((vsp->vt_pure_mode == M_HPVT)
1418 && (vsp->which_fkl == SYS_FKL))
1419 vt_ris(vsp);
1420 else
1421 more_chars = (u_char *)"\033[18~"; /* F7 */
1422 }
1423 else
1424 {
1425 if(vsp->vt_pure_mode == M_PUREVT
1426 || (vsp->which_fkl == USR_FKL))
1427 more_chars = (u_char *)"\033[28~"; /* HELP */
1428 }
1429 }
1430
1431 /*---------------------------------------------------------------------------*
1432 * function bound to function key 3
1433 *---------------------------------------------------------------------------*/
1434 static void
1435 fkey3(void)
1436 {
1437 if(!meta_down)
1438 {
1439 if((vsp->vt_pure_mode == M_HPVT)
1440 && (vsp->which_fkl == SYS_FKL))
1441 toggl_24l(vsp);
1442 else
1443 more_chars = (u_char *)"\033[19~"; /* F8 */
1444 }
1445 else
1446 {
1447 if(vsp->vt_pure_mode == M_PUREVT
1448 || (vsp->which_fkl == USR_FKL))
1449 more_chars = (u_char *)"\033[29~"; /* DO */
1450 }
1451 }
1452
1453 /*---------------------------------------------------------------------------*
1454 * function bound to function key 4
1455 *---------------------------------------------------------------------------*/
1456 static void
1457 fkey4(void)
1458 {
1459 if(!meta_down)
1460 {
1461
1462 #if PCVT_SHOWKEYS
1463 if((vsp->vt_pure_mode == M_HPVT)
1464 && (vsp->which_fkl == SYS_FKL))
1465 toggl_kbddbg(vsp);
1466 else
1467 more_chars = (u_char *)"\033[20~"; /* F9 */
1468 #else
1469 if(vsp->vt_pure_mode == M_PUREVT
1470 || (vsp->which_fkl == USR_FKL))
1471 more_chars = (u_char *)"\033[20~"; /* F9 */
1472 #endif /* PCVT_SHOWKEYS */
1473
1474 }
1475 else
1476 {
1477 if(vsp->vt_pure_mode == M_PUREVT
1478 || (vsp->which_fkl == USR_FKL))
1479 more_chars = (u_char *)"\033[31~"; /* F17 */
1480 }
1481 }
1482
1483 /*---------------------------------------------------------------------------*
1484 * function bound to function key 5
1485 *---------------------------------------------------------------------------*/
1486 static void
1487 fkey5(void)
1488 {
1489 if(!meta_down)
1490 {
1491 if((vsp->vt_pure_mode == M_HPVT)
1492 && (vsp->which_fkl == SYS_FKL))
1493 toggl_bell(vsp);
1494 else
1495 more_chars = (u_char *)"\033[21~"; /* F10 */
1496 }
1497 else
1498 {
1499 if(vsp->vt_pure_mode == M_PUREVT
1500 || (vsp->which_fkl == USR_FKL))
1501 more_chars = (u_char *)"\033[32~"; /* F18 */
1502 }
1503 }
1504
1505 /*---------------------------------------------------------------------------*
1506 * function bound to function key 6
1507 *---------------------------------------------------------------------------*/
1508 static void
1509 fkey6(void)
1510 {
1511 if(!meta_down)
1512 {
1513 if((vsp->vt_pure_mode == M_HPVT)
1514 && (vsp->which_fkl == SYS_FKL))
1515 toggl_sevenbit(vsp);
1516 else
1517 more_chars = (u_char *)"\033[23~"; /* F11 */
1518 }
1519 else
1520 {
1521 if(vsp->vt_pure_mode == M_PUREVT
1522 || (vsp->which_fkl == USR_FKL))
1523 more_chars = (u_char *)"\033[33~"; /* F19 */
1524 }
1525 }
1526
1527 /*---------------------------------------------------------------------------*
1528 * function bound to function key 7
1529 *---------------------------------------------------------------------------*/
1530 static void
1531 fkey7(void)
1532 {
1533 if(!meta_down)
1534 {
1535 if((vsp->vt_pure_mode == M_HPVT)
1536 && (vsp->which_fkl == SYS_FKL))
1537 toggl_dspf(vsp);
1538 else
1539 more_chars = (u_char *)"\033[24~"; /* F12 */
1540 }
1541 else
1542 {
1543 if(vsp->vt_pure_mode == M_PUREVT
1544 || (vsp->which_fkl == USR_FKL))
1545 more_chars = (u_char *)"\033[34~"; /* F20 */
1546 }
1547 }
1548
1549 /*---------------------------------------------------------------------------*
1550 * function bound to function key 8
1551 *---------------------------------------------------------------------------*/
1552 static void
1553 fkey8(void)
1554 {
1555 if(!meta_down)
1556 {
1557 if((vsp->vt_pure_mode == M_HPVT)
1558 && (vsp->which_fkl == SYS_FKL))
1559 toggl_awm(vsp);
1560 else
1561 more_chars = (u_char *)"\033[25~"; /* F13 */
1562 }
1563 else
1564 {
1565 if(vsp->vt_pure_mode == M_PUREVT
1566 || (vsp->which_fkl == USR_FKL))
1567 more_chars = (u_char *)"\033[35~"; /* F21 ? !! */
1568 }
1569 }
1570
1571 /*---------------------------------------------------------------------------*
1572 * function bound to function key 9
1573 *---------------------------------------------------------------------------*/
1574 static void
1575 fkey9(void)
1576 {
1577 if(meta_down)
1578 {
1579 if(vsp->vt_pure_mode == M_PUREVT)
1580 return;
1581
1582 if(vsp->labels_on) /* toggle label display on/off */
1583 fkl_off(vsp);
1584 else
1585 fkl_on(vsp);
1586 }
1587 else
1588 {
1589 do_vgapage(0);
1590 }
1591 }
1592
1593 /*---------------------------------------------------------------------------*
1594 * function bound to function key 10
1595 *---------------------------------------------------------------------------*/
1596 static void
1597 fkey10(void)
1598 {
1599 if(meta_down)
1600 {
1601 if(vsp->vt_pure_mode != M_PUREVT && vsp->labels_on)
1602 {
1603 if(vsp->which_fkl == USR_FKL)
1604 sw_sfkl(vsp);
1605 else if(vsp->which_fkl == SYS_FKL)
1606 sw_ufkl(vsp);
1607 }
1608 }
1609 else
1610 {
1611 do_vgapage(1);
1612 }
1613 }
1614
1615 /*---------------------------------------------------------------------------*
1616 * function bound to function key 11
1617 *---------------------------------------------------------------------------*/
1618 static void
1619 fkey11(void)
1620 {
1621 if(meta_down)
1622 {
1623 if(vsp->vt_pure_mode == M_PUREVT)
1624 set_emulation_mode(vsp, M_HPVT);
1625 else if(vsp->vt_pure_mode == M_HPVT)
1626 set_emulation_mode(vsp, M_PUREVT);
1627 }
1628 else
1629 {
1630 do_vgapage(2);
1631 }
1632 }
1633
1634 /*---------------------------------------------------------------------------*
1635 * function bound to function key 12
1636 *---------------------------------------------------------------------------*/
1637 static void
1638 fkey12(void)
1639 {
1640 if(meta_down)
1641 {
1642 if(current_video_screen + 1 > totalscreens-1)
1643 do_vgapage(0);
1644 else
1645 do_vgapage(current_video_screen + 1);
1646 }
1647 else
1648 {
1649 do_vgapage(3);
1650 }
1651 }
1652
1653 /*---------------------------------------------------------------------------*
1654 * function bound to SHIFTED function key 1
1655 *---------------------------------------------------------------------------*/
1656 static void
1657 sfkey1(void)
1658 {
1659 if(!meta_down)
1660 {
1661 if(vsp->ukt.length[0]) /* entry available ? */
1662 more_chars = (u_char *)
1663 &(vsp->udkbuf[vsp->ukt.first[0]]);
1664 }
1665 else
1666 {
1667 if(vsp->ukt.length[9]) /* entry available ? */
1668 more_chars = (u_char *)
1669 &(vsp->udkbuf[vsp->ukt.first[9]]);
1670 }
1671 }
1672
1673 /*---------------------------------------------------------------------------*
1674 * function bound to SHIFTED function key 2
1675 *---------------------------------------------------------------------------*/
1676 static void
1677 sfkey2(void)
1678 {
1679 if(!meta_down)
1680 {
1681 if(vsp->ukt.length[1]) /* entry available ? */
1682 more_chars = (u_char *)
1683 &(vsp->udkbuf[vsp->ukt.first[1]]);
1684 }
1685 else
1686 {
1687 if(vsp->ukt.length[11]) /* entry available ? */
1688 more_chars = (u_char *)
1689 &(vsp->udkbuf[vsp->ukt.first[11]]);
1690 }
1691 }
1692
1693 /*---------------------------------------------------------------------------*
1694 * function bound to SHIFTED function key 3
1695 *---------------------------------------------------------------------------*/
1696 static void
1697 sfkey3(void)
1698 {
1699 if(!meta_down)
1700 {
1701 if(vsp->ukt.length[2]) /* entry available ? */
1702 more_chars = (u_char *)
1703 &(vsp->udkbuf[vsp->ukt.first[2]]);
1704 }
1705 else
1706 {
1707 if(vsp->ukt.length[12]) /* entry available ? */
1708 more_chars = (u_char *)
1709 &(vsp->udkbuf[vsp->ukt.first[12]]);
1710 }
1711 }
1712
1713 /*---------------------------------------------------------------------------*
1714 * function bound to SHIFTED function key 4
1715 *---------------------------------------------------------------------------*/
1716 static void
1717 sfkey4(void)
1718 {
1719 if(!meta_down)
1720 {
1721 if(vsp->ukt.length[3]) /* entry available ? */
1722 more_chars = (u_char *)
1723 &(vsp->udkbuf[vsp->ukt.first[3]]);
1724 }
1725 else
1726 {
1727 if(vsp->ukt.length[13]) /* entry available ? */
1728 more_chars = (u_char *)
1729 &(vsp->udkbuf[vsp->ukt.first[13]]);
1730 }
1731 }
1732
1733 /*---------------------------------------------------------------------------*
1734 * function bound to SHIFTED function key 5
1735 *---------------------------------------------------------------------------*/
1736 static void
1737 sfkey5(void)
1738 {
1739 if(!meta_down)
1740 {
1741 if(vsp->ukt.length[4]) /* entry available ? */
1742 more_chars = (u_char *)
1743 &(vsp->udkbuf[vsp->ukt.first[4]]);
1744 }
1745 else
1746 {
1747 if(vsp->ukt.length[14]) /* entry available ? */
1748 more_chars = (u_char *)
1749 &(vsp->udkbuf[vsp->ukt.first[14]]);
1750 }
1751 }
1752
1753 /*---------------------------------------------------------------------------*
1754 * function bound to SHIFTED function key 6
1755 *---------------------------------------------------------------------------*/
1756 static void
1757 sfkey6(void)
1758 {
1759 if(!meta_down)
1760 {
1761 if(vsp->ukt.length[6]) /* entry available ? */
1762 more_chars = (u_char *)
1763 &(vsp->udkbuf[vsp->ukt.first[6]]);
1764 }
1765 else
1766 {
1767 if(vsp->ukt.length[15]) /* entry available ? */
1768 more_chars = (u_char *)
1769 &(vsp->udkbuf[vsp->ukt.first[15]]);
1770 }
1771 }
1772
1773 /*---------------------------------------------------------------------------*
1774 * function bound to SHIFTED function key 7
1775 *---------------------------------------------------------------------------*/
1776 static void
1777 sfkey7(void)
1778 {
1779 if(!meta_down)
1780 {
1781 if(vsp->ukt.length[7]) /* entry available ? */
1782 more_chars = (u_char *)
1783 &(vsp->udkbuf[vsp->ukt.first[7]]);
1784 }
1785 else
1786 {
1787 if(vsp->ukt.length[16]) /* entry available ? */
1788 more_chars = (u_char *)
1789 &(vsp->udkbuf[vsp->ukt.first[16]]);
1790 }
1791 }
1792
1793 /*---------------------------------------------------------------------------*
1794 * function bound to SHIFTED function key 8
1795 *---------------------------------------------------------------------------*/
1796 static void
1797 sfkey8(void)
1798 {
1799 if(!meta_down)
1800 {
1801 if(vsp->ukt.length[8]) /* entry available ? */
1802 more_chars = (u_char *)
1803 &(vsp->udkbuf[vsp->ukt.first[8]]);
1804 }
1805 else
1806 {
1807 if(vsp->ukt.length[17]) /* entry available ? */
1808 more_chars = (u_char *)
1809 &(vsp->udkbuf[vsp->ukt.first[17]]);
1810 }
1811 }
1812 /*---------------------------------------------------------------------------*
1813 * function bound to SHIFTED function key 9
1814 *---------------------------------------------------------------------------*/
1815 static void
1816 sfkey9(void)
1817 {
1818 }
1819
1820 /*---------------------------------------------------------------------------*
1821 * function bound to SHIFTED function key 10
1822 *---------------------------------------------------------------------------*/
1823 static void
1824 sfkey10(void)
1825 {
1826 }
1827
1828 /*---------------------------------------------------------------------------*
1829 * function bound to SHIFTED function key 11
1830 *---------------------------------------------------------------------------*/
1831 static void
1832 sfkey11(void)
1833 {
1834 }
1835
1836 /*---------------------------------------------------------------------------*
1837 * function bound to SHIFTED function key 12
1838 *---------------------------------------------------------------------------*/
1839 static void
1840 sfkey12(void)
1841 {
1842 }
1843
1844 /*---------------------------------------------------------------------------*
1845 * function bound to control function key 1
1846 *---------------------------------------------------------------------------*/
1847 static void
1848 cfkey1(void)
1849 {
1850 if(meta_down)
1851 do_vgapage(0);
1852 }
1853
1854 /*---------------------------------------------------------------------------*
1855 * function bound to control function key 2
1856 *---------------------------------------------------------------------------*/
1857 static void
1858 cfkey2(void)
1859 {
1860 if(meta_down)
1861 do_vgapage(1);
1862 }
1863
1864 /*---------------------------------------------------------------------------*
1865 * function bound to control function key 3
1866 *---------------------------------------------------------------------------*/
1867 static void
1868 cfkey3(void)
1869 {
1870 if(meta_down)
1871 do_vgapage(2);
1872 }
1873
1874 /*---------------------------------------------------------------------------*
1875 * function bound to control function key 4
1876 *---------------------------------------------------------------------------*/
1877 static void
1878 cfkey4(void)
1879 {
1880 if(meta_down)
1881 do_vgapage(3);
1882 }
1883
1884 /*---------------------------------------------------------------------------*
1885 * function bound to control function key 5
1886 *---------------------------------------------------------------------------*/
1887 static void
1888 cfkey5(void)
1889 {
1890 if(meta_down)
1891 do_vgapage(4);
1892 }
1893
1894 /*---------------------------------------------------------------------------*
1895 * function bound to control function key 6
1896 *---------------------------------------------------------------------------*/
1897 static void
1898 cfkey6(void)
1899 {
1900 if(meta_down)
1901 do_vgapage(5);
1902 }
1903
1904 /*---------------------------------------------------------------------------*
1905 * function bound to control function key 7
1906 *---------------------------------------------------------------------------*/
1907 static void
1908 cfkey7(void)
1909 {
1910 if(meta_down)
1911 do_vgapage(6);
1912 }
1913
1914 /*---------------------------------------------------------------------------*
1915 * function bound to control function key 8
1916 *---------------------------------------------------------------------------*/
1917 static void
1918 cfkey8(void)
1919 {
1920 if(meta_down)
1921 do_vgapage(7);
1922 }
1923
1924 /*---------------------------------------------------------------------------*
1925 * function bound to control function key 9
1926 *---------------------------------------------------------------------------*/
1927 static void
1928 cfkey9(void)
1929 {
1930 if(meta_down)
1931 do_vgapage(8);
1932 }
1933
1934 /*---------------------------------------------------------------------------*
1935 * function bound to control function key 10
1936 *---------------------------------------------------------------------------*/
1937 static void
1938 cfkey10(void)
1939 {
1940 if(meta_down)
1941 do_vgapage(9);
1942 }
1943
1944 /*---------------------------------------------------------------------------*
1945 * function bound to control function key 11
1946 *---------------------------------------------------------------------------*/
1947 static void
1948 cfkey11(void)
1949 {
1950 if(meta_down)
1951 do_vgapage(10);
1952 }
1953
1954 /*---------------------------------------------------------------------------*
1955 * function bound to control function key 12
1956 *---------------------------------------------------------------------------*/
1957 static void
1958 cfkey12(void)
1959 {
1960 if(meta_down)
1961 do_vgapage(11);
1962 }
1963
1964 #else /* PCVT_VT220 - VT220-like Keyboard layout */
1965
1966 /*---------------------------------------------------------------------------*
1967 * function bound to function key 1
1968 *---------------------------------------------------------------------------*/
1969 static void
1970 fkey1(void)
1971 {
1972 if(meta_down)
1973 more_chars = (u_char *)"\033[23~"; /* F11 */
1974 else
1975 do_vgapage(0);
1976 }
1977
1978 /*---------------------------------------------------------------------------*
1979 * function bound to function key 2
1980 *---------------------------------------------------------------------------*/
1981 static void
1982 fkey2(void)
1983 {
1984 if(meta_down)
1985 more_chars = (u_char *)"\033[24~"; /* F12 */
1986 else
1987 do_vgapage(1);
1988 }
1989
1990 /*---------------------------------------------------------------------------*
1991 * function bound to function key 3
1992 *---------------------------------------------------------------------------*/
1993 static void
1994 fkey3(void)
1995 {
1996 if(meta_down)
1997 more_chars = (u_char *)"\033[25~"; /* F13 */
1998 else
1999 do_vgapage(2);
2000 }
2001
2002 /*---------------------------------------------------------------------------*
2003 * function bound to function key 4
2004 *---------------------------------------------------------------------------*/
2005 static void
2006 fkey4(void)
2007 {
2008 if(meta_down)
2009 more_chars = (u_char *)"\033[26~"; /* F14 */
2010 else
2011 do_vgapage(3);
2012 }
2013
2014 /*---------------------------------------------------------------------------*
2015 * function bound to function key 5
2016 *---------------------------------------------------------------------------*/
2017 static void
2018 fkey5(void)
2019 {
2020 if(meta_down)
2021 more_chars = (u_char *)"\033[28~"; /* Help */
2022 else
2023 {
2024 if((current_video_screen + 1) > totalscreens-1)
2025 do_vgapage(0);
2026 else
2027 do_vgapage(current_video_screen + 1);
2028 }
2029 }
2030
2031 /*---------------------------------------------------------------------------*
2032 * function bound to function key 6
2033 *---------------------------------------------------------------------------*/
2034 static void
2035 fkey6(void)
2036 {
2037 if(meta_down)
2038 more_chars = (u_char *)"\033[29~"; /* DO */
2039 else
2040 more_chars = (u_char *)"\033[17~"; /* F6 */
2041 }
2042
2043 /*---------------------------------------------------------------------------*
2044 * function bound to function key 7
2045 *---------------------------------------------------------------------------*/
2046 static void
2047 fkey7(void)
2048 {
2049 if(meta_down)
2050 more_chars = (u_char *)"\033[31~"; /* F17 */
2051 else
2052 more_chars = (u_char *)"\033[18~"; /* F7 */
2053 }
2054
2055 /*---------------------------------------------------------------------------*
2056 * function bound to function key 8
2057 *---------------------------------------------------------------------------*/
2058 static void
2059 fkey8(void)
2060 {
2061 if(meta_down)
2062 more_chars = (u_char *)"\033[32~"; /* F18 */
2063 else
2064 more_chars = (u_char *)"\033[19~"; /* F8 */
2065 }
2066
2067 /*---------------------------------------------------------------------------*
2068 * function bound to function key 9
2069 *---------------------------------------------------------------------------*/
2070 static void
2071 fkey9(void)
2072 {
2073 if(meta_down)
2074 more_chars = (u_char *)"\033[33~"; /* F19 */
2075 else
2076 more_chars = (u_char *)"\033[20~"; /* F9 */
2077 }
2078
2079 /*---------------------------------------------------------------------------*
2080 * function bound to function key 10
2081 *---------------------------------------------------------------------------*/
2082 static void
2083 fkey10(void)
2084 {
2085 if(meta_down)
2086 more_chars = (u_char *)"\033[34~"; /* F20 */
2087 else
2088 more_chars = (u_char *)"\033[21~"; /* F10 */
2089 }
2090
2091 /*---------------------------------------------------------------------------*
2092 * function bound to function key 11
2093 *---------------------------------------------------------------------------*/
2094 static void
2095 fkey11(void)
2096 {
2097 if(meta_down)
2098 more_chars = (u_char *)"\0x8FP"; /* PF1 */
2099 else
2100 more_chars = (u_char *)"\033[23~"; /* F11 */
2101 }
2102
2103 /*---------------------------------------------------------------------------*
2104 * function bound to function key 12
2105 *---------------------------------------------------------------------------*/
2106 static void
2107 fkey12(void)
2108 {
2109 if(meta_down)
2110 more_chars = (u_char *)"\0x8FQ"; /* PF2 */
2111 else
2112 more_chars = (u_char *)"\033[24~"; /* F12 */
2113 }
2114
2115 /*---------------------------------------------------------------------------*
2116 * function bound to SHIFTED function key 1
2117 *---------------------------------------------------------------------------*/
2118 static void
2119 sfkey1(void)
2120 {
2121 if(meta_down)
2122 {
2123 if(vsp->ukt.length[6]) /* entry available ? */
2124 more_chars = (u_char *)
2125 &(vsp->udkbuf[vsp->ukt.first[6]]);
2126 else
2127 more_chars = (u_char *)"\033[23~"; /* F11 */
2128 }
2129 else
2130 {
2131 do_vgapage(4);
2132 }
2133 }
2134
2135 /*---------------------------------------------------------------------------*
2136 * function bound to SHIFTED function key 2
2137 *---------------------------------------------------------------------------*/
2138 static void
2139 sfkey2(void)
2140 {
2141 if(meta_down)
2142 {
2143 if(vsp->ukt.length[7]) /* entry available ? */
2144 more_chars = (u_char *)
2145 &(vsp->udkbuf[vsp->ukt.first[7]]);
2146 else
2147 more_chars = (u_char *)"\033[24~"; /* F12 */
2148 }
2149 else
2150 {
2151 do_vgapage(5);
2152 }
2153 }
2154
2155 /*---------------------------------------------------------------------------*
2156 * function bound to SHIFTED function key 3
2157 *---------------------------------------------------------------------------*/
2158 static void
2159 sfkey3(void)
2160 {
2161 if(meta_down)
2162 {
2163 if(vsp->ukt.length[8]) /* entry available ? */
2164 more_chars = (u_char *)
2165 &(vsp->udkbuf[vsp->ukt.first[8]]);
2166 else
2167 more_chars = (u_char *)"\033[25~"; /* F13 */
2168 }
2169 else
2170 {
2171 do_vgapage(6);
2172 }
2173 }
2174
2175 /*---------------------------------------------------------------------------*
2176 * function bound to SHIFTED function key 4
2177 *---------------------------------------------------------------------------*/
2178 static void
2179 sfkey4(void)
2180 {
2181 if(meta_down)
2182 {
2183 if(vsp->ukt.length[9]) /* entry available ? */
2184 more_chars = (u_char *)
2185 &(vsp->udkbuf[vsp->ukt.first[9]]);
2186 else
2187 more_chars = (u_char *)"\033[26~"; /* F14 */
2188 }
2189 else
2190 {
2191 do_vgapage(7);
2192 }
2193 }
2194
2195 /*---------------------------------------------------------------------------*
2196 * function bound to SHIFTED function key 5
2197 *---------------------------------------------------------------------------*/
2198 static void
2199 sfkey5(void)
2200 {
2201 if(meta_down)
2202 {
2203 if(vsp->ukt.length[11]) /* entry available ? */
2204 more_chars = (u_char *)
2205 &(vsp->udkbuf[vsp->ukt.first[11]]);
2206 else
2207 more_chars = (u_char *)"\033[28~"; /* Help */
2208 }
2209 else
2210 {
2211 if(current_video_screen <= 0)
2212 do_vgapage(totalscreens-1);
2213 else
2214 do_vgapage(current_video_screen - 1);
2215 }
2216 }
2217
2218 /*---------------------------------------------------------------------------*
2219 * function bound to SHIFTED function key 6
2220 *---------------------------------------------------------------------------*/
2221 static void
2222 sfkey6(void)
2223 {
2224 if(!meta_down)
2225 {
2226 if(vsp->ukt.length[0]) /* entry available ? */
2227 more_chars = (u_char *)
2228 &(vsp->udkbuf[vsp->ukt.first[0]]);
2229 else
2230 more_chars = (u_char *)"\033[17~"; /* F6 */
2231 }
2232 else if(vsp->ukt.length[12]) /* entry available ? */
2233 more_chars = (u_char *)
2234 &(vsp->udkbuf[vsp->ukt.first[12]]);
2235 else
2236 more_chars = (u_char *)"\033[29~"; /* DO */
2237 }
2238
2239 /*---------------------------------------------------------------------------*
2240 * function bound to SHIFTED function key 7
2241 *---------------------------------------------------------------------------*/
2242 static void
2243 sfkey7(void)
2244 {
2245 if(!meta_down)
2246 {
2247 if(vsp->ukt.length[1]) /* entry available ? */
2248 more_chars = (u_char *)
2249 &(vsp->udkbuf[vsp->ukt.first[1]]);
2250 else
2251 more_chars = (u_char *)"\033[18~"; /* F7 */
2252 }
2253 else if(vsp->ukt.length[14]) /* entry available ? */
2254 more_chars = (u_char *)
2255 &(vsp->udkbuf[vsp->ukt.first[14]]);
2256 else
2257 more_chars = (u_char *)"\033[31~"; /* F17 */
2258 }
2259
2260 /*---------------------------------------------------------------------------*
2261 * function bound to SHIFTED function key 8
2262 *---------------------------------------------------------------------------*/
2263 static void
2264 sfkey8(void)
2265 {
2266 if(!meta_down)
2267 {
2268 if(vsp->ukt.length[2]) /* entry available ? */
2269 more_chars = (u_char *)
2270 &(vsp->udkbuf[vsp->ukt.first[2]]);
2271 else
2272 more_chars = (u_char *)"\033[19~"; /* F8 */
2273 }
2274 else if(vsp->ukt.length[14]) /* entry available ? */
2275 more_chars = (u_char *)
2276 &(vsp->udkbuf[vsp->ukt.first[15]]);
2277 else
2278 more_chars = (u_char *)"\033[32~"; /* F18 */
2279 }
2280
2281 /*---------------------------------------------------------------------------*
2282 * function bound to SHIFTED function key 9
2283 *---------------------------------------------------------------------------*/
2284 static void
2285 sfkey9(void)
2286 {
2287 if(!meta_down)
2288 {
2289 if(vsp->ukt.length[3]) /* entry available ? */
2290 more_chars = (u_char *)
2291 &(vsp->udkbuf[vsp->ukt.first[3]]);
2292 else
2293 more_chars = (u_char *)"\033[20~"; /* F9 */
2294 }
2295 else if(vsp->ukt.length[16]) /* entry available ? */
2296 more_chars = (u_char *)
2297 &(vsp->udkbuf[vsp->ukt.first[16]]);
2298 else
2299 more_chars = (u_char *)"\033[33~"; /* F19 */
2300 }
2301
2302 /*---------------------------------------------------------------------------*
2303 * function bound to SHIFTED function key 10
2304 *---------------------------------------------------------------------------*/
2305 static void
2306 sfkey10(void)
2307 {
2308 if(!meta_down)
2309 {
2310 if(vsp->ukt.length[4]) /* entry available ? */
2311 more_chars = (u_char *)
2312 &(vsp->udkbuf[vsp->ukt.first[4]]);
2313 else
2314 more_chars = (u_char *)"\033[21~"; /* F10 */
2315 }
2316 else if(vsp->ukt.length[17]) /* entry available ? */
2317 more_chars = (u_char *)
2318 &(vsp->udkbuf[vsp->ukt.first[17]]);
2319 else
2320 more_chars = (u_char *)"\033[34~"; /* F20 */
2321 }
2322
2323 /*---------------------------------------------------------------------------*
2324 * function bound to SHIFTED function key 11
2325 *---------------------------------------------------------------------------*/
2326 static void
2327 sfkey11(void)
2328 {
2329 if(!meta_down)
2330 {
2331 if(vsp->ukt.length[6]) /* entry available ? */
2332 more_chars = (u_char *)
2333 &(vsp->udkbuf[vsp->ukt.first[6]]);
2334 else
2335 more_chars = (u_char *)"\033[23~"; /* F11 */
2336 }
2337 }
2338
2339 /*---------------------------------------------------------------------------*
2340 * function bound to SHIFTED function key 12
2341 *---------------------------------------------------------------------------*/
2342 static void
2343 sfkey12(void)
2344 {
2345 if(!meta_down)
2346 {
2347 if(vsp->ukt.length[7]) /* entry available ? */
2348 more_chars = (u_char *)
2349 &(vsp->udkbuf[vsp->ukt.first[7]]);
2350 else
2351 more_chars = (u_char *)"\033[24~"; /* F12 */
2352 }
2353 }
2354
2355 /*---------------------------------------------------------------------------*
2356 * function bound to control function key 1
2357 *---------------------------------------------------------------------------*/
2358 static void
2359 cfkey1(void)
2360 {
2361 if(vsp->which_fkl == SYS_FKL)
2362 toggl_columns(vsp);
2363 }
2364
2365 /*---------------------------------------------------------------------------*
2366 * function bound to control function key 2
2367 *---------------------------------------------------------------------------*/
2368 static void
2369 cfkey2(void)
2370 {
2371 if(vsp->which_fkl == SYS_FKL)
2372 vt_ris(vsp);
2373 }
2374
2375 /*---------------------------------------------------------------------------*
2376 * function bound to control function key 3
2377 *---------------------------------------------------------------------------*/
2378 static void
2379 cfkey3(void)
2380 {
2381 if(vsp->which_fkl == SYS_FKL)
2382 toggl_24l(vsp);
2383 }
2384
2385 /*---------------------------------------------------------------------------*
2386 * function bound to control function key 4
2387 *---------------------------------------------------------------------------*/
2388 static void
2389 cfkey4(void)
2390 {
2391
2392 #if PCVT_SHOWKEYS
2393 if(vsp->which_fkl == SYS_FKL)
2394 toggl_kbddbg(vsp);
2395 #endif /* PCVT_SHOWKEYS */
2396
2397 }
2398
2399 /*---------------------------------------------------------------------------*
2400 * function bound to control function key 5
2401 *---------------------------------------------------------------------------*/
2402 static void
2403 cfkey5(void)
2404 {
2405 if(vsp->which_fkl == SYS_FKL)
2406 toggl_bell(vsp);
2407 }
2408
2409 /*---------------------------------------------------------------------------*
2410 * function bound to control function key 6
2411 *---------------------------------------------------------------------------*/
2412 static void
2413 cfkey6(void)
2414 {
2415 if(vsp->which_fkl == SYS_FKL)
2416 toggl_sevenbit(vsp);
2417 }
2418
2419 /*---------------------------------------------------------------------------*
2420 * function bound to control function key 7
2421 *---------------------------------------------------------------------------*/
2422 static void
2423 cfkey7(void)
2424 {
2425 if(vsp->which_fkl == SYS_FKL)
2426 toggl_dspf(vsp);
2427 }
2428
2429 /*---------------------------------------------------------------------------*
2430 * function bound to control function key 8
2431 *---------------------------------------------------------------------------*/
2432 static void
2433 cfkey8(void)
2434 {
2435 if(vsp->which_fkl == SYS_FKL)
2436 toggl_awm(vsp);
2437 }
2438
2439 /*---------------------------------------------------------------------------*
2440 * function bound to control function key 9
2441 *---------------------------------------------------------------------------*/
2442 static void
2443 cfkey9(void)
2444 {
2445 if(vsp->labels_on) /* toggle label display on/off */
2446 fkl_off(vsp);
2447 else
2448 fkl_on(vsp);
2449 }
2450
2451 /*---------------------------------------------------------------------------*
2452 * function bound to control function key 10
2453 *---------------------------------------------------------------------------*/
2454 static void
2455 cfkey10(void)
2456 {
2457 if(vsp->labels_on) /* toggle user/system fkey labels */
2458 {
2459 if(vsp->which_fkl == USR_FKL)
2460 sw_sfkl(vsp);
2461 else if(vsp->which_fkl == SYS_FKL)
2462 sw_ufkl(vsp);
2463 }
2464 }
2465
2466 /*---------------------------------------------------------------------------*
2467 * function bound to control function key 11
2468 *---------------------------------------------------------------------------*/
2469 static void
2470 cfkey11(void)
2471 {
2472 if(vsp->vt_pure_mode == M_PUREVT)
2473 set_emulation_mode(vsp, M_HPVT);
2474 else if(vsp->vt_pure_mode == M_HPVT)
2475 set_emulation_mode(vsp, M_PUREVT);
2476 }
2477
2478 /*---------------------------------------------------------------------------*
2479 * function bound to control function key 12
2480 *---------------------------------------------------------------------------*/
2481 static void
2482 cfkey12(void)
2483 {
2484 }
2485
2486 #endif /* PCVT_VT220KEYB */
2487
2488 /*---------------------------------------------------------------------------*
2489 *
2490 *---------------------------------------------------------------------------*/
2491 static void
2492 scrollback_save_screen(void)
2493 {
2494 int x = spltty();
2495 register size_t s;
2496
2497 s = sizeof(u_short) * vsp->screen_rowsize * vsp->maxcol;
2498
2499 if (scrollback_savedscreen)
2500 free(scrollback_savedscreen, M_TEMP);
2501
2502 scrnsv_size = s;
2503
2504 if (!(scrollback_savedscreen = (u_short *)malloc(s, M_TEMP, M_NOWAIT)))
2505 {
2506 splx(x);
2507 return;
2508 }
2509 bcopy(vsp->Crtat, scrollback_savedscreen, scrnsv_size);
2510 splx(x);
2511 }
2512
2513 /*---------------------------------------------------------------------------*
2514 *
2515 *---------------------------------------------------------------------------*/
2516 static void
2517 scrollback_restore_screen(void)
2518 {
2519 if (scrollback_savedscreen)
2520 bcopy(scrollback_savedscreen, vsp->Crtat, scrnsv_size);
2521 }
2522
2523 /* ------------------------------- EOF -------------------------------------*/
Cache object: b81697291c6fdb18d19a634f486e8442
|