2019-04-24 00:05:30 +02:00
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
// GNU GPL OS/K //
|
|
|
|
// //
|
2019-05-07 18:35:46 +02:00
|
|
|
// Desc: Basic Keyboard Driver //
|
2019-04-24 00:05:30 +02:00
|
|
|
// //
|
|
|
|
// //
|
|
|
|
// Copyright © 2018-2019 The OS/K Team //
|
|
|
|
// //
|
|
|
|
// This file is part of OS/K. //
|
|
|
|
// //
|
|
|
|
// OS/K 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 //
|
|
|
|
// any later version. //
|
|
|
|
// //
|
|
|
|
// OS/K 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 OS/K. If not, see <https://www.gnu.org/licenses/>. //
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
2019-04-24 21:08:44 +02:00
|
|
|
#include <kernel/base.h>
|
2019-04-24 00:05:30 +02:00
|
|
|
#include <kernel/iomisc.h>
|
2019-04-24 22:40:12 +02:00
|
|
|
#include <extras/buf.h>
|
2019-05-08 10:33:17 +02:00
|
|
|
#include <kernel/keyboard.h>
|
2019-04-24 11:40:14 +02:00
|
|
|
|
2019-05-08 10:33:17 +02:00
|
|
|
static char EarlyScanCodes[100] = { 0 };
|
2019-05-08 00:28:42 +02:00
|
|
|
static char Invisible[100] = { 0 };
|
2019-04-24 11:40:14 +02:00
|
|
|
|
2019-05-08 10:33:17 +02:00
|
|
|
char *ScanCodes = 0;
|
|
|
|
|
2019-04-24 22:40:12 +02:00
|
|
|
void KeybPrint(char code)
|
|
|
|
{
|
2019-05-08 00:28:42 +02:00
|
|
|
uchar ch = ScanCodes[(int)code];
|
|
|
|
|
2019-05-08 15:09:16 +02:00
|
|
|
if (ch != 0) {
|
|
|
|
bputc(BStdIn, ch);
|
|
|
|
if (code && Invisible[(int)code] == 0) {
|
|
|
|
bputc(BStdOut, ScanCodes[(int)code]);
|
|
|
|
//bprintf(BStdOut, "%x ", code);
|
|
|
|
BStdOut->flusher(BStdOut);
|
|
|
|
}
|
2019-04-24 22:40:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScanCodesInit(void)
|
|
|
|
{
|
2019-05-08 10:33:17 +02:00
|
|
|
ScanCodes = &EarlyScanCodes[0];
|
|
|
|
|
|
|
|
ScanCodes[0x01] = KEY_ESC;
|
2019-05-08 00:28:42 +02:00
|
|
|
Invisible[0x01] = 1;
|
2019-04-24 22:40:12 +02:00
|
|
|
ScanCodes[0x02] = '1';
|
|
|
|
ScanCodes[0x03] = '2';
|
|
|
|
ScanCodes[0x04] = '3';
|
|
|
|
ScanCodes[0x05] = '4';
|
|
|
|
ScanCodes[0x06] = '5';
|
|
|
|
ScanCodes[0x07] = '6';
|
|
|
|
ScanCodes[0x08] = '7';
|
|
|
|
ScanCodes[0x09] = '8';
|
|
|
|
ScanCodes[0x0A] = '9';
|
|
|
|
ScanCodes[0x0B] = '0';
|
2019-04-29 23:51:25 +02:00
|
|
|
ScanCodes[0x0C] = ' ';
|
|
|
|
ScanCodes[0x0D] = '+';
|
2019-05-07 22:32:17 +02:00
|
|
|
ScanCodes[0x0E] = 0x8;
|
|
|
|
ScanCodes[0x0F] = '\t';
|
2019-04-24 22:40:12 +02:00
|
|
|
|
|
|
|
ScanCodes[0x10] = 'a';
|
|
|
|
ScanCodes[0x11] = 'z';
|
|
|
|
ScanCodes[0x12] = 'e';
|
|
|
|
ScanCodes[0x13] = 'r';
|
|
|
|
ScanCodes[0x14] = 't';
|
|
|
|
ScanCodes[0x15] = 'y';
|
|
|
|
ScanCodes[0x16] = 'u';
|
|
|
|
ScanCodes[0x17] = 'i';
|
|
|
|
ScanCodes[0x18] = 'o';
|
|
|
|
ScanCodes[0x19] = 'p';
|
2019-04-29 23:51:25 +02:00
|
|
|
ScanCodes[0x1A] = '^';
|
|
|
|
ScanCodes[0x1B] = '$';
|
2019-04-24 22:40:12 +02:00
|
|
|
|
|
|
|
ScanCodes[0x1E] = 'q';
|
|
|
|
ScanCodes[0x1F] = 's';
|
|
|
|
ScanCodes[0x20] = 'd';
|
|
|
|
ScanCodes[0x21] = 'f';
|
|
|
|
ScanCodes[0x22] = 'g';
|
|
|
|
ScanCodes[0x23] = 'h';
|
|
|
|
ScanCodes[0x24] = 'j';
|
|
|
|
ScanCodes[0x25] = 'k';
|
|
|
|
ScanCodes[0x26] = 'l';
|
2019-04-29 23:51:25 +02:00
|
|
|
ScanCodes[0x27] = 'm';
|
|
|
|
ScanCodes[0x28] = 'u';
|
|
|
|
ScanCodes[0x29] = '*';
|
2019-04-24 22:40:12 +02:00
|
|
|
|
|
|
|
ScanCodes[0x2C] = 'w';
|
|
|
|
ScanCodes[0x2D] = 'x';
|
|
|
|
ScanCodes[0x2E] = 'c';
|
|
|
|
ScanCodes[0x2F] = 'v';
|
|
|
|
ScanCodes[0x30] = 'b';
|
|
|
|
ScanCodes[0x31] = 'n';
|
2019-04-29 23:51:25 +02:00
|
|
|
ScanCodes[0x32] = ',';
|
|
|
|
ScanCodes[0x33] = ';';
|
|
|
|
ScanCodes[0x34] = ':';
|
|
|
|
ScanCodes[0x35] = '!';
|
2019-04-24 11:55:15 +02:00
|
|
|
|
2019-04-24 22:40:12 +02:00
|
|
|
ScanCodes[0x1C] = '\n';
|
|
|
|
ScanCodes[0x39] = ' ';
|
2019-05-08 10:33:17 +02:00
|
|
|
|
|
|
|
ScanCodes[0x40] = KEY_BEL;
|
2019-05-08 00:28:42 +02:00
|
|
|
Invisible[0x40] = 1;
|
2019-05-08 10:33:17 +02:00
|
|
|
|
2019-05-08 00:00:45 +02:00
|
|
|
// Numpad
|
2019-05-08 10:33:17 +02:00
|
|
|
ScanCodes[0x48] = KEY_DC1; // DC1, will serve as Arrow Up
|
|
|
|
ScanCodes[0x50] = KEY_DC2; // DC2, will serve as Arrow Down
|
|
|
|
ScanCodes[0x4B] = KEY_DC3; // DC3, will serve as Arrow Left
|
|
|
|
ScanCodes[0x4D] = KEY_DC4; // DC4, will serve as Arrow Right
|
2019-05-08 00:28:42 +02:00
|
|
|
Invisible[0x48] = 1;
|
|
|
|
Invisible[0x50] = 1;
|
|
|
|
Invisible[0x4B] = 1;
|
|
|
|
Invisible[0x4D] = 1;
|
2019-04-24 22:40:12 +02:00
|
|
|
}
|
|
|
|
|
2019-04-27 00:04:27 +02:00
|
|
|
void KeybHandler(ISRFrame_t *regs)
|
2019-04-24 11:55:15 +02:00
|
|
|
{
|
2019-04-24 21:08:44 +02:00
|
|
|
char status;
|
|
|
|
char code = 0;
|
2019-04-24 11:55:15 +02:00
|
|
|
|
|
|
|
// write EOI
|
2019-04-24 18:14:23 +02:00
|
|
|
IoWriteByteOnPort(0x20, 0x20);
|
2019-04-24 11:55:15 +02:00
|
|
|
|
2019-04-24 21:08:44 +02:00
|
|
|
status = IoReadByteFromPort(0x64);
|
2019-04-24 11:55:15 +02:00
|
|
|
|
|
|
|
if (status & 0x01) {
|
2019-04-24 21:08:44 +02:00
|
|
|
code = IoReadByteFromPort(0x60);
|
2019-04-24 11:55:15 +02:00
|
|
|
|
2019-04-24 21:08:44 +02:00
|
|
|
if(code < 0) code = 0;
|
2019-04-24 11:55:15 +02:00
|
|
|
}
|
2019-04-24 22:40:12 +02:00
|
|
|
KeybPrint((int)code);
|
2019-04-24 23:00:12 +02:00
|
|
|
IoSendEOItoPIC(0x21);
|
2019-04-24 11:55:15 +02:00
|
|
|
}
|
2019-04-27 00:04:27 +02:00
|
|
|
|
2019-05-07 22:32:17 +02:00
|
|
|
void IoCreateInputBuffer(void)
|
|
|
|
{
|
|
|
|
error_t rc;
|
|
|
|
|
|
|
|
rc = BOpenPureBuf(&BStdIn, BS_RDWR, 4 * KB);
|
2019-05-08 10:33:17 +02:00
|
|
|
|
|
|
|
if (rc) KeStartPanic("[Keyb] Couldn't create BStdIn");
|
2019-05-07 22:32:17 +02:00
|
|
|
|
2019-05-08 15:09:16 +02:00
|
|
|
//BEnableLineBuffering(BStdIn);
|
|
|
|
BStdIn->flusher = bemptybuf;
|
2019-05-07 22:32:17 +02:00
|
|
|
}
|
|
|
|
|
2019-04-27 00:04:27 +02:00
|
|
|
void IoEnableKeyb(void)
|
|
|
|
{
|
|
|
|
ulong flags = KePauseIRQs();
|
2019-05-07 22:32:17 +02:00
|
|
|
|
2019-05-06 22:04:22 +02:00
|
|
|
IdtRegisterIsr(KeybHandler, 0x21);
|
2019-04-27 00:04:27 +02:00
|
|
|
char readedInterruptConfig = IoReadByteFromPort(0x21);
|
|
|
|
IoWriteByteOnPort(0x21, 0xFD & readedInterruptConfig);
|
2019-05-07 22:32:17 +02:00
|
|
|
|
2019-04-27 00:04:27 +02:00
|
|
|
KeRestoreIRQs(flags);
|
2019-05-07 22:32:17 +02:00
|
|
|
|
2019-04-27 00:04:27 +02:00
|
|
|
IoEnableNMI();
|
|
|
|
ScanCodesInit();
|
2019-05-07 22:32:17 +02:00
|
|
|
|
|
|
|
IoCreateInputBuffer();
|
2019-04-27 00:04:27 +02:00
|
|
|
}
|
2019-05-08 10:33:17 +02:00
|
|
|
|
|
|
|
void IoChangeCodePage(char *CodePage)
|
|
|
|
{
|
|
|
|
ScanCodes = &CodePage[0];
|
|
|
|
}
|