81 lines
2.4 KiB
C
81 lines
2.4 KiB
C
/*
|
|
Copyright (C) 2012, Aaron Lindsay <aaron@aclindsay.com>
|
|
|
|
This file is part of Aedrix.
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
*/
|
|
|
|
#include <font.h>
|
|
#include <framebuffer.h>
|
|
|
|
#define CONSOLE_BUFFER_SIZE 16384
|
|
char console_buffer[CONSOLE_BUFFER_SIZE];
|
|
char console_output_buffer[CONSOLE_BUFFER_SIZE];
|
|
char *console_buffer_p = console_buffer;
|
|
struct fb *console_framebuffer = 0;
|
|
struct font *console_font = 0;
|
|
unsigned int chars_per_line = 0, lines = 0;
|
|
|
|
void console_char_to_fb(char c, unsigned int x, unsigned int y) {
|
|
unsigned int cx, cy, bit = 0;
|
|
char *font_char = &console_font->data[console_font->bytes_per_char * (c - console_font->ascii_offset)];
|
|
|
|
for (cy = 0; cy < console_font->height; cy++) {
|
|
for (cx = 0; cx < console_font->width; cx++) {
|
|
unsigned char on = font_char[bit / 8] & (1 << (bit % 8));
|
|
if (on)
|
|
fb_write_pixel(console_framebuffer, x + cx, y + cy, 0xff, 0xff, 0xff);
|
|
else
|
|
fb_write_pixel(console_framebuffer, x + cx, y + cy, 0x00, 0x00, 0x00);
|
|
bit++;
|
|
}
|
|
}
|
|
}
|
|
|
|
void console_refresh_fb() {
|
|
if (!console_framebuffer)
|
|
return;
|
|
}
|
|
|
|
void console_clear() {
|
|
int i;
|
|
for (i = 0; i < CONSOLE_BUFFER_SIZE; i++) {
|
|
console_buffer[i] = 0;
|
|
}
|
|
}
|
|
|
|
void console_init(struct fb *f) {
|
|
console_clear();
|
|
console_refresh_fb();
|
|
console_font = font_get();
|
|
console_framebuffer = f;
|
|
chars_per_line = console_framebuffer->width / console_font->width;
|
|
lines = console_framebuffer->height / console_font->height;
|
|
|
|
console_char_to_fb('A', 100, 100);
|
|
console_char_to_fb('E', 111, 100);
|
|
console_char_to_fb('D', 122, 100);
|
|
console_char_to_fb('R', 133, 100);
|
|
console_char_to_fb('I', 144, 100);
|
|
console_char_to_fb('X', 155, 100);
|
|
}
|
|
|
|
void console_putc(char c) {
|
|
*console_buffer_p = c;
|
|
if (++console_buffer_p > console_buffer + CONSOLE_BUFFER_SIZE)
|
|
console_buffer_p = console_buffer;
|
|
}
|