X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=bootcensus;a=blobdiff_plain;f=src%2Fkeyb.c;h=0b6187129b305b010e21efe9fc7b77222a908391;hp=c5a672c840bde879761f38ff589c980b43b36d4b;hb=5e8cc93aaf1173688852acaa0825698c2dc0cb3f;hpb=a2f94f569a4c99204de02814a20098a71527e913 diff --git a/src/keyb.c b/src/keyb.c index c5a672c..0b61871 100644 --- a/src/keyb.c +++ b/src/keyb.c @@ -1,9 +1,27 @@ +/* +pcboot - bootable PC demo/game kernel +Copyright (C) 2018 John Tsiombikas + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY, without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ +#include +#include #include "keyb.h" #include "intr.h" #include "asmops.h" +#include "kbregs.h" -#define KB_IRQ 1 -#define KB_PORT 0x60 /* table with rough translations from set 1 scancodes to ASCII-ish */ static int scantbl[] = { @@ -32,6 +50,10 @@ static unsigned char keystate[256]; void kb_init(void) { + buf_ridx = buf_widx = 0; + num_pressed = 0; + memset(keystate, 0, sizeof keystate); + interrupt(IRQ_TO_INTR(KB_IRQ), kbintr); } @@ -93,12 +115,56 @@ void kb_putback(int key) buffer[buf_ridx] = key; } +int kb_wait_write(void) +{ + int i; + for(i=0; i<32768; i++) { + if(!(inb(KB_STATUS_PORT) & KB_STAT_INBUF_FULL)) { + return 1; + } + iodelay(); + } + /*printf("kb_wait_write timeout\n");*/ + return 0; +} + +int kb_wait_read(void) +{ + int i; + for(i=0; i<32768; i++) { + if((inb(KB_STATUS_PORT) & KB_STAT_OUTBUF_FULL)) { + return 1; + } + iodelay(); + } + /*printf("kb_wait_read timeout\n");*/ + return 0; +} + +void kb_send_cmd(unsigned char cmd) +{ + kb_wait_write(); + outb(cmd, KB_CMD_PORT); +} + +void kb_send_data(unsigned char data) +{ + kb_wait_write(); + outb(data, KB_DATA_PORT); +} + +unsigned char kb_read_data(void) +{ + kb_wait_read(); + return inb(KB_DATA_PORT); +} + static void kbintr() { unsigned char code; int key, press; - code = inb(KB_PORT); + code = inb(KB_DATA_PORT); if(code >= 128) { press = 0;