usb: getting string descriptors, minor improvements
[quarnos.git] / resources / keybscr.cpp
blob7dfea7712d74979aeb69e58d68413c2274e0e99e
1 /* Quarn OS
3 * Keyboard and Screen
5 * Copyright (C) 2008-2009 Pawel Dziepak
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "keybscr.h"
24 #include "x86_keybscr.h"
26 #include "manes/manec.h"
27 #include "libs/delegate.h"
28 #include "libs/colors.h"
30 using namespace manes;
31 using namespace resources;
33 keybscr::keybscr() : x(17), y(0) {}
36 void keybscr::read(buffer &data) {
37 for (int i = 0; i < data.get_size(); i++)
38 data[i] = buf.pop();
41 void keybscr::write(const buffer &data) {
42 for (int i = 0; i < data.get_size(); i++) {
44 if (data[i] == '\n') {
45 if (y < get_height() - 1)
46 y++;
47 else
48 scr_scroll();
49 x = 0;
50 } else if (data[i] == '\t') {
51 x = (x/8 + 1) * 8;
52 } else {
53 screen_print(data[i], foreground | (background << 4), x, y);
54 x++;
57 y += x / get_width();
58 if (x / get_width() > 0 && y >= get_height() - 1)
59 scr_scroll();
60 y = y < get_height() ? y : get_height() - 1;
61 x = x % get_width();
66 void keybscr::set_ondatareceived(delegate<void> event) {
67 assert("keybscr: attempt to set null event handler", event.null());
68 on_data_received = event;
71 void keybscr::received(const char key) {
72 buf.push(key);
73 write(buffer::to_mem(key));
75 /* delayed action */
76 on_data_received();
79 void keybscr::register_type() {
80 manec::get()->register_type<arch_keybscr>("keybscr", "console");