bond/arch/print.c

63 lines
1.1 KiB
C
Raw Normal View History

2019-06-26 05:47:18 +00:00
#include <kern/cdef.h>
2018-12-16 23:52:33 +00:00
#include <arch/mem.h>
2019-11-28 18:02:52 +00:00
#include <kern/libkern.h>
2018-12-16 23:52:33 +00:00
#define FB_PADDR (0xb8000)
2019-11-28 18:02:52 +00:00
#define FB_ROW (25)
#define FB_COL (80)
#define BYTE_PER_CHAR (2)
#define FB_SZ (FB_ROW * FB_COL * BYTE_PER_CHAR)
#define DEFAULT_COLOR (0x07)
2018-01-25 09:53:35 +00:00
2019-11-28 18:02:52 +00:00
static char *base;
static uint text_pos;
2018-10-01 17:01:00 +00:00
static void
2019-11-28 18:02:52 +00:00
_fb_scroll()
{
2019-11-28 18:02:52 +00:00
memmove(base, base + FB_COL * BYTE_PER_CHAR, FB_SZ - (FB_COL * BYTE_PER_CHAR));
2019-12-07 08:54:18 +00:00
// clear the last line
memset(base + (FB_ROW - 1) * FB_COL * BYTE_PER_CHAR, 0, FB_COL * BYTE_PER_CHAR);
2019-11-28 18:02:52 +00:00
text_pos = FB_SZ - (FB_COL * BYTE_PER_CHAR);
}
2018-10-01 17:01:00 +00:00
static void
2019-11-28 18:02:52 +00:00
_print_newline(void)
{
2019-11-28 18:02:52 +00:00
text_pos += FB_COL * BYTE_PER_CHAR - text_pos % (FB_COL * BYTE_PER_CHAR);
2019-11-28 18:02:52 +00:00
if (text_pos >= FB_SZ) {
_fb_scroll();
2018-10-01 17:01:00 +00:00
}
}
2019-11-28 18:02:52 +00:00
void
arch_print_init(void)
{
2019-11-28 18:02:52 +00:00
// 0 here since it doesn't matter direct mapped
base = arch_pmap_map(FB_PADDR, FB_SZ);
text_pos = 0;
}
2018-10-01 17:01:00 +00:00
void
2019-11-28 18:02:52 +00:00
arch_cls()
{
2019-11-28 18:02:52 +00:00
memset(base, 0, FB_SZ);
}
2019-06-26 05:47:18 +00:00
void
2019-11-28 18:02:52 +00:00
arch_putc(const char c)
{
2019-11-28 18:02:52 +00:00
if (c == '\n') {
_print_newline();
return;
}
2019-11-28 18:02:52 +00:00
if (text_pos >= FB_SZ) {
_fb_scroll();
2018-10-01 17:01:00 +00:00
}
2018-01-25 19:11:22 +00:00
2019-11-28 18:02:52 +00:00
base[text_pos++] = c;
base[text_pos++] = DEFAULT_COLOR;
2019-06-26 05:47:18 +00:00
}