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
|
|
|
// //
|
|
|
|
// //
|
2020-02-06 14:23:26 +01:00
|
|
|
// Copyright © 2018-2020 The OS/K Team //
|
2019-04-24 00:05:30 +02:00
|
|
|
// //
|
|
|
|
// 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/>. //
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
2020-02-19 22:19:58 +01:00
|
|
|
#include <libbuf.h>
|
2019-05-13 23:22:27 +02:00
|
|
|
#include <io/keyb.h>
|
2019-05-14 11:48:07 +02:00
|
|
|
#include <ke/idt.h>
|
2019-04-24 11:40:14 +02:00
|
|
|
|
2020-01-10 21:58:11 +01:00
|
|
|
#include "scan.c"
|
2019-04-24 11:40:14 +02:00
|
|
|
|
2020-01-16 17:44:03 +01:00
|
|
|
#define KEY(code) (table[2*(code)])
|
|
|
|
#define FLAGS(code) (table[2*(code)+1])
|
|
|
|
|
2020-01-10 21:58:11 +01:00
|
|
|
static bool capsLockActive = 0;
|
2020-02-02 13:37:26 +01:00
|
|
|
|
|
|
|
static bool e0received = 0;
|
2020-01-16 17:44:03 +01:00
|
|
|
static bool altPressed = 0;
|
2020-02-02 13:37:26 +01:00
|
|
|
static bool altGrPressed = 0;
|
2020-01-16 17:44:03 +01:00
|
|
|
static bool shiftPressed = 0;
|
|
|
|
static bool controlPressed = 0;
|
2019-05-08 10:33:17 +02:00
|
|
|
|
2020-01-20 20:05:03 +01:00
|
|
|
static void KeybPrint(uchar _code)
|
2020-01-10 21:58:11 +01:00
|
|
|
{
|
|
|
|
uint code = (uint)_code;
|
|
|
|
|
2020-02-02 13:37:26 +01:00
|
|
|
const uint *table;
|
|
|
|
|
|
|
|
if (!e0received) {
|
|
|
|
table = (altPressed ? LeftAltScanCodes
|
|
|
|
: (controlPressed ? LeftControlScanCodes
|
|
|
|
: (shiftPressed ? LeftShiftScanCodes
|
|
|
|
: (altGrPressed ? AltGrScanCodes
|
|
|
|
: RegularScanCodes))));
|
|
|
|
} else {
|
|
|
|
table = E0ScanCodes;
|
|
|
|
e0received = 0;
|
|
|
|
}
|
2020-01-10 21:58:11 +01:00
|
|
|
|
2020-01-20 20:06:26 +01:00
|
|
|
if ((capsLockActive && (FLAGS(code) & CAPSLOCK))
|
|
|
|
&& !(altPressed || controlPressed)) {
|
2020-01-16 17:44:03 +01:00
|
|
|
if (shiftPressed)
|
|
|
|
table = RegularScanCodes;
|
|
|
|
else
|
|
|
|
table = LeftShiftScanCodes;
|
|
|
|
}
|
2020-01-10 21:58:11 +01:00
|
|
|
|
2020-01-16 17:44:03 +01:00
|
|
|
uchar ch = KEY(code);
|
2020-01-10 21:58:11 +01:00
|
|
|
|
|
|
|
if (!ch) {
|
|
|
|
switch (code) {
|
2020-02-02 13:37:26 +01:00
|
|
|
case 0xE0: e0received = 1; break;
|
|
|
|
|
|
|
|
case 0x38: if (table == E0ScanCodes) altGrPressed = 1;
|
|
|
|
else altPressed = 1;
|
|
|
|
break;
|
|
|
|
case 0xB8: if (table == E0ScanCodes) altGrPressed = 0;
|
|
|
|
else altPressed = 0;
|
|
|
|
break;
|
2020-01-10 21:58:11 +01:00
|
|
|
|
2020-01-16 17:44:03 +01:00
|
|
|
case 0x36: case 0x2A: shiftPressed = 1; break;
|
|
|
|
case 0xB6: case 0xAA: shiftPressed = 0; break;
|
2020-01-10 21:58:11 +01:00
|
|
|
|
2020-01-16 17:44:03 +01:00
|
|
|
case 0x1D: controlPressed = 1; break;
|
|
|
|
case 0x9D: controlPressed = 0; break;
|
2020-01-10 21:58:11 +01:00
|
|
|
|
|
|
|
case 0x3A: capsLockActive = !capsLockActive; break;
|
2019-05-08 15:09:16 +02:00
|
|
|
}
|
2020-01-10 21:58:11 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bputc(BStdIn, ch);
|
2019-04-24 22:40:12 +02:00
|
|
|
}
|
|
|
|
|
2019-05-14 11:48:07 +02:00
|
|
|
static void KeybHandler(ISRFrame_t *regs)
|
2019-04-24 11:55:15 +02:00
|
|
|
{
|
2019-04-24 21:08:44 +02:00
|
|
|
char status;
|
2020-01-10 21:58:11 +01:00
|
|
|
uchar 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
|
|
|
}
|
2020-01-10 21:58:11 +01:00
|
|
|
KeybPrint(code);
|
2019-05-14 11:48:07 +02:00
|
|
|
KeSendEOItoPIC(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-14 11:48:07 +02:00
|
|
|
KeRegisterISR(KeybHandler, 0x21);
|
2020-02-06 17:45:44 +01:00
|
|
|
KeUnmaskIRQ(0x1);
|
2019-04-27 00:04:27 +02:00
|
|
|
KeRestoreIRQs(flags);
|
2019-05-07 22:32:17 +02:00
|
|
|
|
2019-05-14 11:48:07 +02:00
|
|
|
KeEnableNMI();
|
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
|
|
|
|