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
) {
17 manes::manec::get()->get
<services::interrupt_manager
>("/interrupt_manager")->register_interrupt(0x21, delegate
<void>::method(this, &x86_keybscr::keyboard_received
));
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();
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
;
50 arch::outb(0x3D4, 14);
51 arch::outb(0x3D5, pos
>> 8);
52 arch::outb(0x3D4, 15);
53 arch::outb(0x3D5, pos
);
59 /* Scancode to ASCII translators */
61 const char x86_keybscr::scan_to_ascii
[] = {
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
[] = {
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() {
88 u8 scan_code
= arch::inb(0x60);
90 if (scan_code
== 0x36 || scan_code
== 0x2a)
93 else if (scan_code
== 0xb6 || scan_code
== 0xaa)
96 if (scan_code
> 0x35 && scan_code
!= 0x39) return;
99 received(scan_to_bigascii
[scan_code
]);
101 received(scan_to_ascii
[scan_code
]);