1
0
mirror of https://gitlab.os-k.eu/os-k-team/os-k.git synced 2023-08-25 14:03:10 +02:00
os-k/kaleid/kernel/io/keyb.c
Julian Barathieu 2f1fefe724 up
2020-01-10 21:58:11 +01:00

119 lines
3.9 KiB
C

//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
// Desc: Basic Keyboard Driver //
// //
// //
// 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/>. //
//----------------------------------------------------------------------------//
#include <lib/buf.h>
#include <io/keyb.h>
#include <ke/idt.h>
#include "scan.c"
static bool capsLockActive = 0;
static bool leftAltPressed = 0;
static bool leftShiftPressed = 0;
static bool leftControlPressed = 0;
void KeybPrint(uchar _code)
{
uint code = (uint)_code;
const uint *table =
(leftAltPressed ? LeftAltScanCodes
: (leftShiftPressed ? LeftShiftScanCodes
: (leftControlPressed ? LeftControlScanCodes
: RegularScanCodes)));
if (capsLockActive && !leftShiftPressed &&
!!(table[2 * code + 1] & CAPSLOCK) && !leftAltPressed)
table = LeftShiftScanCodes;
uchar ch = table[2 * code];
if (!ch) {
switch (code) {
case 0x38: leftAltPressed = 1; break;
case 0xB8: leftAltPressed = 0; break;
case 0x36: case 0x2A: leftShiftPressed = 1; break;
case 0xB6: case 0xAA: leftShiftPressed = 0; break;
case 0x1D: leftControlPressed = 1; break;
case 0x9D: leftControlPressed = 0; break;
case 0x3A: capsLockActive = !capsLockActive; break;
}
return;
}
bputc(BStdIn, ch);
if (code && (table[2 * code + 1] & INVISIBLE) == 0) {
bputc(BStdOut, table[2 * code]);
BStdOut->flusher(BStdOut);
}
}
static void KeybHandler(ISRFrame_t *regs)
{
char status;
uchar code = 0;
// write EOI
IoWriteByteOnPort(0x20, 0x20);
status = IoReadByteFromPort(0x64);
if (status & 0x01) {
code = IoReadByteFromPort(0x60);
}
KeybPrint(code);
KeSendEOItoPIC(0x21);
}
void IoCreateInputBuffer(void)
{
error_t rc;
rc = BOpenPureBuf(&BStdIn, BS_RDWR, 4 * KB);
if (rc) KeStartPanic("[Keyb] Couldn't create BStdIn");
//BEnableLineBuffering(BStdIn);
BStdIn->flusher = bemptybuf;
}
void IoEnableKeyb(void)
{
ulong flags = KePauseIRQs();
KeRegisterISR(KeybHandler, 0x21);
char readedInterruptConfig = IoReadByteFromPort(0x21);
IoWriteByteOnPort(0x21, 0xFD & readedInterruptConfig);
KeRestoreIRQs(flags);
KeEnableNMI();
IoCreateInputBuffer();
}