summaryrefslogtreecommitdiff
path: root/Source/Kernel/Devices/Keyboard/PS2Keyboard.class.cpp
blob: bacfbe9ac7be9cdca37b017a6f5c863e528122d7 (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
53
54
55
56
57
58
59
60
#include "PS2Keyboard.class.h"
#include <DeviceManager/Dev.ns.h>
#include <DeviceManager/Kbd.ns.h>

using namespace Sys;

PS2Keyboard::PS2Keyboard() {
	Dev::requestIRQ(this, 1);

	//Read all waiting characters, so that keyboard buffer is empty
	u8int temp = inb(0x60), temp2 = 0;
	while (temp != temp2) {
		temp2 = temp;
		temp = inb(0x60);
	}

	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);
}