summaryrefslogtreecommitdiff
path: root/Source/Kernel/Devices/Keyboard/PS2Keyboard.class.cpp
blob: f5216c78afd028dbbaa57fbf39975b31270e35f6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "PS2Keyboard.class.h"
#include <DeviceManager/Dev.ns.h>
#include <DeviceManager/Kbd.ns.h>

using namespace Sys;

PS2Keyboard::PS2Keyboard() {
	Dev::requestIRQ(this, 1);
	m_escaped = false;
}

String PS2Keyboard::getClass() {
	return "keyboard.ps2";
}

String PS2Keyboard::getName() {
	return "Standard PS2 keyboard";
}

void PS2Keyboard::handleIRQ(registers_t regs, int irq) {
	if (irq == 1) {
		u8int scancode = inb(0x60);
		if (scancode == 0xE0) {
			m_escaped = true;
		} else {
			if (scancode & 0x80) {
				if (m_escaped) {
					Kbd::keyRelease(scancode);
				} else {
					Kbd::keyRelease(scancode & 0x7F);
				}
			} else {
				if (m_escaped) {
					Kbd::keyPress(scancode | 0x80);
				} else {
					Kbd::keyPress(scancode);
				}
			}
		}
	}
}

void PS2Keyboard::updateLeds(u32int kbdstatus) {
	u8int temp = 0;
	if (kbdstatus & STATUS_SCRL)
		temp |= 1;
	if (kbdstatus & STATUS_NUM)
		temp |= 2;
	if (kbdstatus & STATUS_CAPS)
		temp |= 4;
	outb(0x60, temp);
}