📄 keyboard.c,v
字号:
head 1.3;access;symbols;locks root:1.3; strict;comment @ * @;1.3date 2004.06.11.22.42.56; author root; state Exp;branches;next 1.2;1.2date 2004.04.06.12.33.16; author oracle; state Exp;branches;next 1.1;1.1date 2004.03.01.12.37.18; author oracle; state Exp;branches;next ;desc@rewrite keyboard handler in C, ported from int.asm ,remove the counterpart in asm code@1.3log@add new function:moveHead(): advance dequeue pointermoveTail(): advance enqueue pointerkeyEmpty(): if keyborad buffer emtpy then return 1, else return 0getKey() : return asciiKey if called when keyboard buffer is not emptygetScan() : return scancode if called when keyboard buffer is not emptyreadKeybd(char *ascii, char *scan): both function of getKey() and getScan()@text@/* Snixos Project version 1.0, 2003.6 (C) Copyright 2003-2004 Snallie Jockeyson <Snallie@@tom.com> All Rights Reserved. Distributed under the terms of the GNU General Public License. keyboard.c: keyboard interrupt handler in C Author : snallie@@tom.com Time : 2004.3 $Id: keyboard.c,v 1.32 2004/06/07 10:51:32 root Exp $ built : $Date: 2004/06/07 10:51:32 $ $Revision: 1.32 $*/#include "keyboard.h"#include "io.h"#include "stdio.h"unsigned char ascTab[] = { /*0xff */ ' ', 0x1b, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 0x08, 0x09, 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', 0x0a, ' ', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', ' ', ' ', ' ', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', ' ', ' ', ' ', ' '};typedef struct kbuf { char scan; char ascii;} keybuf;keybuf keyBufs[KBSIZE];int keyHead = 0;int keyTail = 0;#define keybdTail (keyBufs+keyTail)#define keybdHead (keyBufs+keyHead)static void moveHead();static void moveTail();/*keyBdHandle()convert scancode to ascii, store scancode/asciicode to buffer queue, adjust enquepointer, then return.*/void keyBdHandle(){ unsigned char scanCode; scanCode = inb(KBDATAPORT); if (scanCode >= 0x80) //released or pressed (bit7=0 means pressed) goto bye; if ((keyTail + 1) % KBSIZE == keyHead) { printf("keyboard buffer full\n"); goto bye; } keybdTail->scan = scanCode; keybdTail->ascii = ascTab[scanCode]; moveTail(); bye: // send reset signal to keyboard scanCode = inb(KBCTRLPORT); scanCode || 0x80; outb(KBCTRLPORT, scanCode); scanCode = inb(KBCTRLPORT); scanCode && 0x7f; outb(KBCTRLPORT, scanCode); // send EOI to 8259 outb(0x20, 0x20); //EOI}static void moveHead(){ keyHead = (keyHead + 1) % KBSIZE;}static void moveTail(){ keyTail = (keyTail + 1) % KBSIZE;}// if keyborad buffer emtpy then return 1, else return 0int keyEmpty(){ return ((keyHead % KBSIZE) == keyTail ? 1 : 0);}char getKey(){ char a; while (1) { if (!keyEmpty()) break; } a = keybdHead->ascii; moveHead(); return a;}char getScan(){ char a; while (1) { if (!keyEmpty()) break; } a = keybdHead->scan; moveHead(); return a;}void readKeybd(char *ascii, char *scan ){ while (1) { if (!keyEmpty()) break; } *ascii = keybdHead->ascii; *scan = keybdHead->scan; moveHead();}@1.2log@correct the syntax error for character constant definition '10' in array char ascTab[]@text@d11 3a13 3 $Id: keyboard.c,v 1.1 2004/03/01 12:37:18 oracle Exp oracle $ built : $Date: 2004/03/01 12:37:18 $ $Revision: 1.1 $d21 6a26 5 /*0xff*/' ', 0x1b, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0','-', '=', 0x08, 0x09, 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', 0x0a, ' ', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', ' ', ' ', ' ', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', ' ', ' ', ' ', ' 'd28 16a43 8/*char keyBufs[KBSIZE];int keyHeads = 0;int keyTails = 0;*/char *keyBuf;int *keyHead;int *keyTail;d58 1a58 1 if ((*keyTail + 2) % KBSIZE == *keyHead) {d63 3a65 4 keyBuf[*keyTail % KBSIZE + 1] = ascTab[scanCode]; keyBuf[*keyTail % KBSIZE + 0] = scanCode; *keyTail = (*keyTail + 2) % KBSIZE;// printf("@@%x(%x)@@",ascTab[scanCode],scanCode);d79 56@1.1log@Initial revision@text@d8 1a8 1 keyboard.c: keyboard handler d11 3a13 3 $Id: kernel.c,v 1.5 2004/02/14 10:39:34 oracle Exp oracle $ built : $Date: 2004/02/14 10:39:34 $ $Revision: 1.5 $d18 1d21 5a25 6 /*0xff */ ' ', 0x1b, '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '-', '=', 0x08, 0x09, 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', 0x0a, ' ', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', ' ', ' ', ' ', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/'d27 14a40 4char keyBuf[KBSIZE];int keyHead = 0;int keyTail = 0;d49 1a49 1 if ((keyTail + 2) % KBSIZE == keyHead) {d54 4a57 3 keyBuf[keyTail % KBSIZE + 1] = ascTab[scanCode]; keyBuf[keyTail % KBSIZE + 0] = scanCode; keyTail = (keyTail + 2) % KBSIZE;d59 1a59 1 bye: d69 1a69 1 outb(0x20, 0x20); //EOI@
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -