usb: getting string descriptors, minor improvements
[quarnos.git] / resources / x86_keybscr.cpp
blob1ab0d1b24b0ac404d634f17582da78237f1b6a7c
1 #include "x86_keybscr.h"
3 #include "arch/low/general.h"
4 #include "arch/low/lowlevel.h"
5 #include "resources/isa.h"
6 #include "manes/manec.h"
7 #include "services/interrupt_manager.h"
8 #include "manes/error.h"
11 using namespace resources;
13 bool x86_keybscr::init_device(p<did> iadr) {
14 shift = false;
16 /* Set IRQ1 */
17 manes::manec::get()->get<services::interrupt_manager>("/interrupt_manager")->register_interrupt(0x21, delegate<void>::method(this, &x86_keybscr::keyboard_received));
19 return true;
22 /* Scroll screen */
23 void x86_keybscr::scr_scroll() {
24 u8 *text_mem = (u8*)0xB8000;
26 for (int i = 0; i < get_width() * get_height() * 2; i++)
27 text_mem[i] = text_mem[i + get_width() * 2];
29 int pos = get_width() * (get_height() - 1);
30 arch::outb(0x3D4, 14);
31 arch::outb(0x3D5, pos >> 8);
32 arch::outb(0x3D4, 15);
33 arch::outb(0x3D5, pos);
36 /* Show a sign of selected colour in certain place */
37 void x86_keybscr::screen_print(char sign, int color, int x, int y) {
38 u8 *text_mem = (u8*)0xB8000;
39 int pos = x + y * get_width();
41 last_x = last_y = 0;
42 assert("console: wrong coordinates", x > 79 || x < 0 || y > 24 || y < 0);
44 /* Put char into graphic card memory */
45 text_mem[pos * 2] = sign;
46 text_mem[pos * 2 + 1] = color;
48 /* Move a cursor */
49 pos++;
50 arch::outb(0x3D4, 14);
51 arch::outb(0x3D5, pos >> 8);
52 arch::outb(0x3D4, 15);
53 arch::outb(0x3D5, pos);
55 last_x = x;
56 last_y = y;
59 /* Scancode to ASCII translators */
61 const char x86_keybscr::scan_to_ascii[] = {
62 ' ',' ',
63 '1','2','3','4','5','6','7',
64 '8','9','0','-','=','\b',' ',
65 'q','w','e','r','t','y','u',
66 'i','o','p','[',']','\n',' ',
67 'a','s','d','f','g','h','j',
68 'k','l',';','\'','\\',' ','\\',
69 'z','x','c','v','b','n','m',
70 ',','.','/',' ',' ',' ',' ',' '
73 const char x86_keybscr::scan_to_bigascii[] = {
74 ' ',' ',
75 '!','@','#','$','%','^','&',
76 '*','(',')','_','+','\b',' ',
77 'Q','W','E','R','T','Y','U',
78 'I','O','P','{','}','\n',' ',
79 'A','S','D','F','G','H','J',
80 'K','L',':','\"','|',' ','|',
81 'Z','X','C','V','B','N','M',
82 '<','>','?',' ',' ',' ',' ',' '
85 void x86_keybscr::keyboard_received() {
86 arch::unlock_irqs(1);
88 u8 scan_code = arch::inb(0x60);
90 if (scan_code == 0x36 || scan_code == 0x2a)
91 shift = true;
93 else if (scan_code == 0xb6 || scan_code == 0xaa)
94 shift = false;
95 else {
96 if (scan_code > 0x35 && scan_code != 0x39) return;
98 if (shift)
99 received(scan_to_bigascii[scan_code]);
100 else
101 received(scan_to_ascii[scan_code]);