summaryrefslogblamecommitdiff
path: root/src/kernel/dev/ps2keyboard.cpp
blob: c7fc32203d90d8f5ad0d293c16f2be3854d0ebad (plain) (tree)






















































                                                               
 
#include "ps2keyboard.h"

#include <core/sys.h>
#include <task/idt.h>

ps2kbd *kbd = 0;

static void kbd_irq(registers*) {
	kbd->kbdIrq();
}

ps2kbd::ps2kbd(node* parent) : keyboard(parent) {
	uint8_t temp = inb(0x60), temp2 = 0;
	while (temp != temp2) {
		temp2 = temp;
		temp = inb(0x60);
	}

	kbd = this;
	idt_handleIrq(1, kbd_irq);

	escaped = false;

	updateLeds();
}

void ps2kbd::updateLeds() {
	uint8_t tmp = 0;
	if (scroll) tmp |= 1;
	if (num) tmp |= 2;
	if (caps) tmp |= 4;
	outb(0x60, tmp);
}

void ps2kbd::kbdIrq() {
	uint8_t scancode = inb(0x60);
	if (scancode == 0xE0) {
		escaped = true;
	} else {
		if (scancode & 0x80) {
			if (escaped) {
				handle(scancode, false);
			} else {
				handle(scancode & 0x7F, false);
			}
		} else {
			if (escaped) {
				handle(scancode | 0x80, true);
			} else {
				handle(scancode, true);
			}
		}
		escaped = false;
	}
}