keyboard.c revision 50141
130044Ssos/*-
230044Ssos * Copyright (c) 1997 S�ren Schmidt
330044Ssos * All rights reserved.
430044Ssos *
530044Ssos * Redistribution and use in source and binary forms, with or without
630044Ssos * modification, are permitted provided that the following conditions
730044Ssos * are met:
830044Ssos * 1. Redistributions of source code must retain the above copyright
930044Ssos *    notice, this list of conditions and the following disclaimer
1030044Ssos *    in this position and unchanged.
1130044Ssos * 2. Redistributions in binary form must reproduce the above copyright
1230044Ssos *    notice, this list of conditions and the following disclaimer in the
1330044Ssos *    documentation and/or other materials provided with the distribution.
1430044Ssos * 3. The name of the author may not be used to endorse or promote products
1530044Ssos *    derived from this software withough specific prior written permission
1630044Ssos *
1730044Ssos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1830044Ssos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1930044Ssos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2030044Ssos * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2130044Ssos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2230044Ssos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2330044Ssos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2430044Ssos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2530044Ssos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2630044Ssos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2730044Ssos *
2850141Syokota *  $Id: keyboard.c,v 1.1 1997/10/01 20:53:38 sos Exp $
2930044Ssos */
3030044Ssos
3130044Ssos#include <stdio.h>
3230044Ssos#include <sys/types.h>
3330044Ssos#include <sys/ioctl.h>
3430044Ssos#include <termios.h>
3530044Ssos#include <sys/time.h>
3630044Ssos#include <machine/console.h>
3730044Ssos#include "vgl.h"
3830044Ssos
3930044Ssosstatic struct termios VGLKeyboardTty;
4030044Ssosstatic int VGLKeyboardMode = -1;
4130044Ssos
4230044Ssosint
4330044SsosVGLKeyboardInit(int mode)
4430044Ssos{
4530044Ssos  static struct termios term;
4630044Ssos
4730044Ssos  ioctl(0, KDGKBMODE, &VGLKeyboardMode);
4830044Ssos  tcgetattr(0, &VGLKeyboardTty);
4930044Ssos
5030044Ssos  term = VGLKeyboardTty;
5150141Syokota  cfmakeraw(&term);
5230044Ssos  term.c_iflag = IGNPAR | IGNBRK;
5330044Ssos  term.c_oflag = 0;
5430044Ssos  term.c_cflag = CREAD | CS8;
5530044Ssos  term.c_lflag &= ~(ICANON | ECHO | ISIG);
5630044Ssos  term.c_cc[VTIME] = 0;
5730044Ssos  term.c_cc[VMIN] = 0;
5830044Ssos  cfsetispeed(&term, 9600);
5930044Ssos  cfsetospeed(&term, 9600);
6030044Ssos  tcsetattr(0, TCSANOW, &term);
6130044Ssos
6230044Ssos  switch (mode) {
6330044Ssos  case VGL_RAWKEYS:
6430044Ssos    ioctl(0, KDSKBMODE, K_RAW);
6530044Ssos    break;
6630044Ssos  case VGL_CODEKEYS:
6730044Ssos    ioctl(0, KDSKBMODE, K_CODE);
6830044Ssos    break;
6930044Ssos  case VGL_XLATEKEYS:
7030044Ssos    ioctl(0, KDSKBMODE, K_XLATE);
7130044Ssos    break;
7230044Ssos  }
7330044Ssos  return 0;
7430044Ssos}
7530044Ssos
7630044Ssosvoid
7730044SsosVGLKeyboardEnd()
7830044Ssos{
7950141Syokota  if (VGLKeyboardMode != -1) {
8030044Ssos    ioctl(0, KDSKBMODE, VGLKeyboardMode);
8150141Syokota    tcsetattr(0, TCSANOW, &VGLKeyboardTty);
8250141Syokota  }
8330044Ssos}
8430044Ssos
8530044Ssosint
8630044SsosVGLKeyboardGetCh()
8730044Ssos{
8830044Ssos  unsigned char ch = 0;
8930044Ssos
9030044Ssos  read (0, &ch, 1);
9130044Ssos  return (int)ch;
9230044Ssos}
93