61 lines
1.6 KiB
C
61 lines
1.6 KiB
C
|
#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;
|
||
|
}
|