Newer
Older
Scratch / lockwasher / src / sys / isa / atkbd.c
/**************************************************************************************
 Copyright (c) 2002 The UbixOS Project
 All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

 $Id: atkbd.c,v 1.10 2003/04/27 00:45:15 reddawg Exp $

**************************************************************************************/

#include <isa/atkbd.h>
#include <isa/8259.h>
#include <sys/idt.h>
#include <sys/gdt.h>
#include <sys/io.h>
#include <ubixos/types.h>
#include <ubixos/schedule.h>

unsigned int keyMap = 0;
unsigned int ledStatus = 0;

unsigned int keyboardMap[][8] = {
/*           Ascii,  Shift,   Ctrl,    Alt,    Num,   Caps, Shift Caps, Shift Num */
          {      0,      0,      0,      0,      0,      0,          0,         0},
/* ESC */ {   0x1B,   0x1B,   0x1B,   0x1B,   0x1B,   0x1B,       0x1B,      0x1B},
/* 1,! */ {   0x31,   0x21,      0,      0,   0x31,   0x31,       0x21,      0x21},
/* 2,@ */ {   0x32,   0x40,      0,      0,   0x32,   0x32,       0x40,      0x40},
/* 3,# */ {   0x33,   0x23,      0,      0,   0x33,   0x33,       0x23,      0x23},
/* 4,$ */ {   0x34,   0x24,      0,      0,   0x34,   0x34,       0x24,      0x24},
/* 5,% */ {   0x35,   0x25,      0,      0,   0x35,   0x35,       0x25,      0x25},
/* 6,^ */ {   0x36,   0x5E,      0,      0,   0x36,   0x36,       0x5E,      0x5E},
/* 7,& */ {   0x37,   0x26,      0,      0,   0x37,   0x37,       0x26,      0x26},
/* 8,* */ {   0x38,   0x2A,      0,      0,   0x38,   0x38,       0x2A,      0x2A},
/* 9.( */ {   0x39,   0x28,      0,      0,   0x39,   0x39,       0x28,      0x28},
/* 0,) */ {   0x30,   0x29,      0,      0,   0x30,   0x30,       0x29,      0x29},
/* -,_ */ {   0x2D,   0x5F,      0,      0,   0x2D,   0x2D,       0x5F,      0x5F},
/* =,+ */ {   0x3D,   0x2B,      0,      0,   0x3D,   0x3D,       0x2B,      0x2B},
/*  14 */ {   0x08,   0x08,    0x8,    0x8,   0x08,   0x08,       0x08,      0x08},
/*  15 */ {   0x09,      0,      0,      0,      0,      0,          0,         0},
/*     */ {   0x71,   0x51,      0,      0,      0,      0,          0,         0},
/*     */ {   0x77,   0x57,      0,      0,      0,      0,          0,         0},
/*     */ {   0x65,   0x45,      0,      0,      0,      0,          0,         0},
/*     */ {   0x72,   0x52,      0,      0,      0,      0,          0,         0},
/*     */ {   0x74,   0x54,      0,      0,      0,      0,          0,         0},
/*     */ {   0x79,   0x59,      0,      0,      0,      0,          0,         0},
/*     */ {   0x75,   0x55,      0,      0,      0,      0,          0,         0},
/*     */ {   0x69,   0x49,      0,      0,      0,      0,          0,         0},
/*     */ {   0x6F,   0x4F,      0,      0,      0,      0,          0,         0},
/*     */ {   0x70,   0x50,      0,      0,      0,      0,          0,         0},
/*     */ {   0x5B,   0x7B,      0,      0,      0,      0,          0,         0},
/*     */ {   0x5D,   0x3D,      0,      0,      0,      0,          0,         0},
/*     */ {   0x0A,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/* a,A */ {   0x61,   0x41,   0x41,      0,      0,      0,          0,         0},
/*     */ {   0x73,   0x53,      0,      0,      0,      0,          0,         0},
/*     */ {   0x64,   0x44,      0,      0,      0,      0,          0,         0},
/*     */ {   0x66,   0x46,      0,      0,      0,      0,          0,         0},
/*     */ {   0x67,   0x47,      0,      0,      0,      0,          0,         0},
/*     */ {   0x68,   0x48,      0,      0,      0,      0,          0,         0},
/*     */ {   0x6A,   0x4A,      0,      0,      0,      0,          0,         0},
/*     */ {   0x6B,   0x4B,      0,      0,      0,      0,          0,         0},
/*     */ {   0x6C,   0x4C,      0,      0,      0,      0,          0,         0},
/*     */ {   0x3B,   0x3A,      0,      0,      0,      0,          0,         0},
/*     */ {   0x27,   0x07,      0,      0,      0,      0,          0,         0},
/*     */ {   0x60,   0x40,      0,      0,      0,      0,          0,         0},
/*     */ {   0x2A,    0x0,      0,      0,      0,      0,          0,         0},
/*     */ {   0x5C,   0x3C,      0,      0,      0,      0,          0,         0},
/*     */ {   0x7A,   0x5A,      0,      0,      0,      0,          0,         0},
/*     */ {   0x78,   0x58,      0,      0,      0,      0,          0,         0},
/* c,C */ {   0x63,   0x43,    0x3,      0,      0,      0,          0,         0},
/*     */ {   0x76,   0x56,      0,      0,      0,      0,          0,         0},
/*     */ {   0x62,   0x42,      0,      0,      0,      0,          0,         0},
/*     */ {   0x6E,   0x4E,      0,      0,      0,      0,          0,         0},
/*     */ {   0x6D,   0x4D,      0,      0,      0,      0,          0,         0},
/*     */ {   0x2C,   0x0C,      0,      0,      0,      0,          0,         0},
/*     */ {   0x2E,   0x0E,      0,      0,      0,      0,          0,         0},
/*     */ {   0x2F,   0x0F,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {   0x20,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/* F1  */ { 0x3001,      0,      0,      0,      0,      0,          0,         0},
/*     */ { 0x3C00,      0,      0,      0,      0,      0,          0,         0},
/*     */ { 0x3D00,      0,      0,      0,      0,      0,          0,         0},
/*     */ { 0x3E00,      0,      0,      0,      0,      0,          0,         0},
/*     */ { 0x3F00,      0,      0,      0,      0,      0,          0,         0},
/*     */ { 0x4000,      0,      0,      0,      0,      0,          0,         0},
/*     */ { 0x4100,      0,      0,      0,      0,      0,          0,         0},
/*     */ { 0x4200,      0,      0,      0,      0,      0,          0,         0},
/*     */ { 0x4300,      0,      0,      0,      0,      0,          0,         0},
/*     */ { 0x4400,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ { 0x4700,      0,      0,      0,      0,      0,          0,         0},
/*     */ { 0x4800,      0,      0,      0,      0,      0,          0,         0},
/*     */ { 0x4900,      0,      0,      0,      0,      0,          0,         0},
/*     */ {   0x2D,      0,      0,      0,      0,      0,          0,         0},
/*     */ { 0x4B00,      0,      0,      0,      0,      0,          0,         0},
/*     */ { 0x4C00,      0,      0,      0,      0,      0,          0,         0},
/*     */ { 0x4D00,      0,      0,      0,      0,      0,          0,         0},
/*     */ {   0x2B,      0,      0,      0,      0,      0,          0,         0},
/*     */ { 0x4F00,      0,      0,      0,      0,      0,          0,         0},
/*     */ { 0x5000,      0,      0,      0,      0,      0,          0,         0},
/*     */ { 0x5100,      0,      0,      0,      0,      0,          0,         0},
/*     */ { 0x5200,      0,      0,      0,      0,      0,          0,         0},
/*     */ { 0x5300,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      1,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0},
/*     */ {      0,      0,      0,      0,      0,      0,          0,         0}
  };
void initKeyboard() {
  setVector(keyboardIsr, mVec+1, dPresent + dInt + dDpl3); /* IRQ1 Handler */
  setLeds();
  outportByte(mPic, eoi);
  enableIrq(1);
  outportByte(mPic, eoi);
  }

asm(
  ".globl keyboardIsr     \n"
  "keyboardIsr:           \n"
  "  pusha                \n" /* Save all registers           */
//  "  pushw %ds            \n" /* Set up the data segment      */
//  "  pushw %es            \n"
//  "  pushw %ss            \n" /* Note that ss is always valid */
//  "  pushw %ss            \n"
//  "  popw %ds             \n"
//  "  popw %es             \n"
  "  call keyboardHandler \n"
//  "  popw %es             \n"
//  "  popw %ds             \n" /* Restore registers            */
  "  popa                 \n"
  "  iret                 \n" /* Exit interrupt               */
  );

void keyboardHandler() {
  unsigned int key = inportByte(0x60);
  kTask_t *tmpTask = 0x0;

  tmpTask = getTask(0);
  
  if (tmpTask->oInfo.stdin == 0x0) {
    tmpTask->oInfo.stdin = (char *)kmalloc(256,tmpTask->id);
    }
  /* Control Key */
  if (key == 0x1D && !(tmpTask->oInfo.controlKeys & controlKey)) {
    tmpTask->oInfo.controlKeys |= controlKey;
    }
  if (key == 0x80 + 0x1D) {
    tmpTask->oInfo.controlKeys &= (0xFF - controlKey);
    }
  /* ALT Key */
  if (key == 0x38 && !(tmpTask->oInfo.controlKeys & altKey)) {
    tmpTask->oInfo.controlKeys |= altKey;
    }
  if (key == 0x80 + 0x38) {
    tmpTask->oInfo.controlKeys &= (0xFF - altKey);
    }
  /* Shift Key */
  if ((key == 0x2A || key == 0x36) && !(tmpTask->oInfo.controlKeys & shiftKey)) {
    tmpTask->oInfo.controlKeys |= shiftKey;
    }
  if ((key == 0x80 + 0x2A) || (key == 0x80 + 0x36)) {
    tmpTask->oInfo.controlKeys &= (0xFF - shiftKey);
    }
  /* Caps Lock */
  if (key == 0x3A) {
    ledStatus ^= ledCapslock;
    setLeds();
    }
  /* Num Lock */
  if (key == 0x45) {
    ledStatus ^= ledNumlock;
    setLeds();
    }
  /* Scroll Lock */
  if (key == 0x46) {
    ledStatus ^= ledScrolllock;
    setLeds();
    }
  /* Pick Which Key Map */
  if (tmpTask->oInfo.controlKeys == 0) { keyMap = 0; }
  else if (tmpTask->oInfo.controlKeys == 1) { keyMap = 1; }
  else if (tmpTask->oInfo.controlKeys == 2) { keyMap = 2; }
  else if (tmpTask->oInfo.controlKeys == 4) { keyMap = 3; }
  else {
     //kprintf("controlKeys: [%i]\n",controlKeys);
     }
  //If Key Is Not Null Add It To Handler
  if (((uInt)(keyboardMap[key][keyMap]) > 0) && ((uInt32)(keyboardMap[key][keyMap]) < 0xFF)) {
    switch ((uInt32)keyboardMap[key][keyMap]) {
      case 8:
        //kprintf("BackSpace\n");
        backSpace();
        tmpTask->oInfo.stdin[tmpTask->oInfo.stdinSize] = keyboardMap[key][keyMap];
        tmpTask->oInfo.stdinSize++;
        //kprintf("[0x%X]\n",tmpTask->oInfo.stdinSize);
        //keystrokeBuffer[keystrokeBuffersize] = 0x0;
        break;
      case 0x3:
        kprintf("End Task\n");
        //endTask(tmpTask->id);
        break;
      default:
        tmpTask->oInfo.stdin[tmpTask->oInfo.stdinSize] = keyboardMap[key][keyMap];
        tmpTask->oInfo.stdinSize++;
        break;
      }
    }
  else {
    //kprintf("Key: [%i], KeyMap: [%i],Key Char: [%i]\n",key,keyMap,keyboardMap[key][keyMap]);
    }
  outportByte(mPic, eoi);
  //Return
  return;
  }

void setLeds() {
  outportByte(0x60, 0xED);
  while(inportByte(0x64) & 2);
  outportByte(0x60, ledStatus);
  while(inportByte(0x64) & 2);
  }

//Temp
unsigned char getch() {
  uInt8   retKey   = 0x0;
  uInt32  i        = 0x0;
  kTask_t *tmpTask = 0x0;

  tmpTask = getTask(0);

  while (tmpTask->oInfo.stdinSize == 0) {
    sched_yield();
    }
  retKey = tmpTask->oInfo.stdin[0];
  tmpTask->oInfo.stdinSize--;

  for (i=0x0;i<tmpTask->oInfo.stdinSize;i++) {
    tmpTask->oInfo.stdin[i] = tmpTask->oInfo.stdin[i+0x1];
    }
  return(retKey);
  }