All pastes #1526280 Raw Edit

richard

public text v1 · immutable
#1526280 ·published 2009-08-12 10:20 UTC
rendered paste body
#include "kbd.h"// #include "pipes.h"#include "lowlevel.h"#include "terminal.h"#include "interrupts.h"Keyboard kbd(0x60);const static bool DEBUGKBD=false; static const unsigned char lowercase[] = { NULL, 0x1B, '1', '2', '3', '4', '5', '6', '7', '8', '9',   '0', '-', '=', '\b', '\t', 'q', 'w',   'e', 'r', 't', 'y', 'u', 'i', 'o', 'p',   '[', ']', '\n',   0, 'a',   's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`', 0, '#', 'z', 'x', 'c', 'v', 'b', 'n', 'm',   ',', '.', '/', 0, 0, 0, ' ',   0, KF1,   KF2, KF3, KF4, KF5, KF6, KF7, KF8, KF9,   KF10, 0, 0, KHOME, KUP,   KPGUP,'-', KLFT, '5',   KRT, '+', KEND, KDN, KPGDN, KINS, KDEL, 0, 0, '\\', KF11, KF12 };   // Shifted:   static const unsigned char uppercase[] = { NULL, 0x1B,	   '!', '"', '#', '$', '%', '^', '&', '*', '(',')', '_', '+', '\b',	 '\t', 'Q', 'W','E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P','{', '}', '\n',     0, 'A','S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '@', '~', 0,	 '~', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<','>', '?', 0, 0, 0, ' ',   0, KF1,   KF2, KF3, KF4, KF5, KF6, KF7, KF8, KF9,   KF10, 0, 0, KHOME, KUP,   KPGUP,   '-', KLFT, '5',   KRT, '+', KEND, KDN, KPGDN, KINS, KDEL, 0, 0, '|', KF11, KF12 };void Keyboard::put_byte(u8 b) {	con->putch(b);	if(!output.write_will_block())		output.put_byte(b);	else		con->print("\nKeyboard pipe full, discarding.\n");}void Keyboard::put_csi(char c) {	put_byte(27);	put_byte('[');	put_byte(c);}void Keyboard::do_it(UNUSED registers *regs) {		 u32 new_scan_code = inb(0x60);		if (escaped)			new_scan_code += 256;		switch(new_scan_code) {			case 0x36:			case 0x2a:				if(DEBUGKBD)con->print("SHIFT+");				shift = 1;				break;			case 0xb6:			case 0xaa:				if(DEBUGKBD)con->print("NOSHIFT");				shift = 0;				break;			case 0xe0:				if(DEBUGKBD)con->print("Escape!");				escaped = 1;				break;			default:				if (new_scan_code & 0x80) {					// ignore the break code				} else {					switch(new_scan_code) { 					case 0x14b: //con->print("LEFT Cursor\n");					put_csi('D');					break;					case 0x14d:					put_csi('C');					break;					case 0x148:					put_csi('A');					break;					case 0x150:					put_csi('B');					break;					default://  					if(DEBUGKBD)					con->printf("Got scancode: %X\n",new_scan_code);					put_byte((shift?uppercase:lowercase)[new_scan_code]);					}				escaped=0;				break;		}	}}