mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 08:24:32 -08:00
Refactor screen ouput from main console code
This commit is contained in:
3
Makefile
3
Makefile
@@ -51,7 +51,6 @@ WARNFLAGS += -Wno-attributes -Wno-sign-compare -Wno-multichar
|
|||||||
WARNFLAGS += -Wno-div-by-zero -Wno-endif-labels -Wno-pragmas
|
WARNFLAGS += -Wno-div-by-zero -Wno-endif-labels -Wno-pragmas
|
||||||
WARNFLAGS += -Wno-format-extra-args -Wno-unused-result
|
WARNFLAGS += -Wno-format-extra-args -Wno-unused-result
|
||||||
WARNFLAGS += -Wno-deprecated-declarations -Wno-unused-function
|
WARNFLAGS += -Wno-deprecated-declarations -Wno-unused-function
|
||||||
WARNFLAGS += -Wno-unused-but-set-parameter
|
|
||||||
|
|
||||||
ASFLAGS ?=
|
ASFLAGS ?=
|
||||||
ASFLAGS += -p $(BUILD_D)/versions.s
|
ASFLAGS += -p $(BUILD_D)/versions.s
|
||||||
@@ -62,7 +61,7 @@ CFLAGS += -std=c11 -mcmodel=large
|
|||||||
|
|
||||||
CXXFLAGS := $(INCLUDES) $(DEPENDFLAGS) $(BASEFLAGS) $(WARNFLAGS)
|
CXXFLAGS := $(INCLUDES) $(DEPENDFLAGS) $(BASEFLAGS) $(WARNFLAGS)
|
||||||
CXXFLAGS += -DGIT_VERSION="\"$(VERSION)\""
|
CXXFLAGS += -DGIT_VERSION="\"$(VERSION)\""
|
||||||
CXXFLAGS += -std=c++14 -mcmodel=large
|
CXXFLAGS += -std=c++14 -mcmodel=large -fno-rtti
|
||||||
|
|
||||||
BOOT_CFLAGS := $(INCLUDES) $(DEPENDFLAGS) $(BASEFLAGS) $(WARNFLAGS)
|
BOOT_CFLAGS := $(INCLUDES) $(DEPENDFLAGS) $(BASEFLAGS) $(WARNFLAGS)
|
||||||
BOOT_CFLAGS += -std=c11 -I src/boot -fPIC -fshort-wchar
|
BOOT_CFLAGS += -std=c11 -I src/boot -fPIC -fshort-wchar
|
||||||
|
|||||||
@@ -2,10 +2,13 @@
|
|||||||
#include "io.h"
|
#include "io.h"
|
||||||
|
|
||||||
const char digits[] = "0123456789abcdef";
|
const char digits[] = "0123456789abcdef";
|
||||||
|
console g_console;
|
||||||
|
|
||||||
console *console::default_console = nullptr;
|
|
||||||
|
|
||||||
console::console(const font &f, const screen &s, void *scratch, size_t len) :
|
class console_out_screen
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
console_out_screen(const font &f, const screen &s, void *scratch, size_t len) :
|
||||||
m_font(f),
|
m_font(f),
|
||||||
m_screen(s),
|
m_screen(s),
|
||||||
m_size(s.width() / f.width(), s.height() / f.height()),
|
m_size(s.width() / f.width(), s.height() / f.height()),
|
||||||
@@ -16,7 +19,7 @@ console::console(const font &f, const screen &s, void *scratch, size_t len) :
|
|||||||
m_data(nullptr),
|
m_data(nullptr),
|
||||||
m_attrs(nullptr),
|
m_attrs(nullptr),
|
||||||
m_palette(nullptr)
|
m_palette(nullptr)
|
||||||
{
|
{
|
||||||
const unsigned count = m_size.size();
|
const unsigned count = m_size.size();
|
||||||
const size_t palette_size = sizeof(screen::pixel_t) * 256;
|
const size_t palette_size = sizeof(screen::pixel_t) * 256;
|
||||||
const size_t attrs_size = 2 * count;
|
const size_t attrs_size = 2 * count;
|
||||||
@@ -76,40 +79,10 @@ console::console(const font &f, const screen &s, void *scratch, size_t len) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
repaint();
|
repaint();
|
||||||
|
}
|
||||||
|
|
||||||
if (default_console == nullptr)
|
void repaint()
|
||||||
default_console = this;
|
{
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
|
||||||
serial_ready()
|
|
||||||
{
|
|
||||||
return (inb(COM1 + 5) & 0x20) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
serial_write(char c) {
|
|
||||||
while (!serial_ready());
|
|
||||||
outb(COM1, c);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *
|
|
||||||
console::line_pointer(unsigned line)
|
|
||||||
{
|
|
||||||
if (!m_data) return nullptr;
|
|
||||||
return m_data + ((m_first + line) % m_size.y) * m_size.x;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t *
|
|
||||||
console::attr_pointer(unsigned line)
|
|
||||||
{
|
|
||||||
if (!m_attrs) return nullptr;
|
|
||||||
return m_attrs + ((m_first + line) % m_size.y) * m_size.x;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
console::repaint()
|
|
||||||
{
|
|
||||||
m_screen.fill(m_bg);
|
m_screen.fill(m_bg);
|
||||||
if (!m_data) return;
|
if (!m_data) return;
|
||||||
|
|
||||||
@@ -131,21 +104,10 @@ console::repaint()
|
|||||||
y * m_font.height());
|
y * m_font.height());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void scroll(unsigned lines)
|
||||||
console::set_color(uint8_t fg, uint8_t bg)
|
{
|
||||||
{
|
|
||||||
if (!m_palette) return;
|
|
||||||
|
|
||||||
m_bg = m_palette[bg];
|
|
||||||
m_fg = m_palette[fg];
|
|
||||||
m_attr = (bg << 8) | fg;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
console::scroll(unsigned lines)
|
|
||||||
{
|
|
||||||
if (!m_data) {
|
if (!m_data) {
|
||||||
m_pos.x = 0;
|
m_pos.x = 0;
|
||||||
m_pos.y = 0;
|
m_pos.y = 0;
|
||||||
@@ -159,20 +121,22 @@ console::scroll(unsigned lines)
|
|||||||
m_pos.y -= lines;
|
m_pos.y -= lines;
|
||||||
}
|
}
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t
|
void set_color(uint8_t fg, uint8_t bg)
|
||||||
console::puts(const char *message)
|
{
|
||||||
{
|
if (!m_palette) return;
|
||||||
|
|
||||||
|
m_bg = m_palette[bg];
|
||||||
|
m_fg = m_palette[fg];
|
||||||
|
m_attr = (bg << 8) | fg;
|
||||||
|
}
|
||||||
|
|
||||||
|
void putc(char c)
|
||||||
|
{
|
||||||
char *line = line_pointer(m_pos.y);
|
char *line = line_pointer(m_pos.y);
|
||||||
uint16_t *attrs = attr_pointer(m_pos.y);
|
uint16_t *attrs = attr_pointer(m_pos.y);
|
||||||
size_t count = 0;
|
|
||||||
|
|
||||||
while (message && *message) {
|
|
||||||
const unsigned x = m_pos.x * m_font.width();
|
|
||||||
const unsigned y = m_pos.y * m_font.height();
|
|
||||||
const char c = *message++;
|
|
||||||
++count;
|
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case '\t':
|
case '\t':
|
||||||
@@ -184,17 +148,21 @@ console::puts(const char *message)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case '\n':
|
case '\n':
|
||||||
serial_write('\r');
|
|
||||||
m_pos.x = 0;
|
m_pos.x = 0;
|
||||||
m_pos.y++;
|
m_pos.y++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default: {
|
||||||
if (line) line[m_pos.x] = c;
|
if (line) line[m_pos.x] = c;
|
||||||
if (attrs) attrs[m_pos.x] = m_attr;
|
if (attrs) attrs[m_pos.x] = m_attr;
|
||||||
|
|
||||||
|
const unsigned x = m_pos.x * m_font.width();
|
||||||
|
const unsigned y = m_pos.y * m_font.height();
|
||||||
m_font.draw_glyph(m_screen, c, m_fg, m_bg, x, y);
|
m_font.draw_glyph(m_screen, c, m_fg, m_bg, x, y);
|
||||||
|
|
||||||
m_pos.x++;
|
m_pos.x++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (m_pos.x >= m_size.x) {
|
if (m_pos.x >= m_size.x) {
|
||||||
m_pos.x = m_pos.x % m_size.x;
|
m_pos.x = m_pos.x % m_size.x;
|
||||||
@@ -205,10 +173,77 @@ console::puts(const char *message)
|
|||||||
scroll(1);
|
scroll(1);
|
||||||
line = line_pointer(m_pos.y);
|
line = line_pointer(m_pos.y);
|
||||||
}
|
}
|
||||||
serial_write(c);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return count;
|
private:
|
||||||
|
char * line_pointer(unsigned line)
|
||||||
|
{
|
||||||
|
if (!m_data) return nullptr;
|
||||||
|
return m_data + ((m_first + line) % m_size.y) * m_size.x;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t * attr_pointer(unsigned line)
|
||||||
|
{
|
||||||
|
if (!m_attrs) return nullptr;
|
||||||
|
return m_attrs + ((m_first + line) % m_size.y) * m_size.x;
|
||||||
|
}
|
||||||
|
|
||||||
|
font m_font;
|
||||||
|
screen m_screen;
|
||||||
|
|
||||||
|
kutil::coord<unsigned> m_size;
|
||||||
|
kutil::coord<unsigned> m_pos;
|
||||||
|
screen::pixel_t m_fg, m_bg;
|
||||||
|
uint16_t m_attr;
|
||||||
|
|
||||||
|
size_t m_first;
|
||||||
|
size_t m_length;
|
||||||
|
|
||||||
|
char *m_data;
|
||||||
|
uint16_t *m_attrs;
|
||||||
|
screen::pixel_t *m_palette;
|
||||||
|
};
|
||||||
|
|
||||||
|
console_out_screen *
|
||||||
|
console_get_screen_out(const font &f, const screen &s, void *scratch, size_t len)
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
//return new console_out_screen(f, s, scratch, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static bool
|
||||||
|
serial_ready()
|
||||||
|
{
|
||||||
|
return (inb(COM1 + 5) & 0x20) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
serial_write(char c) {
|
||||||
|
while (!serial_ready());
|
||||||
|
outb(COM1, c);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
console::console() :
|
||||||
|
m_screen(nullptr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
console::set_color(uint8_t fg, uint8_t bg)
|
||||||
|
{
|
||||||
|
if (m_screen)
|
||||||
|
m_screen->set_color(fg, bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
console::puts(const char *message)
|
||||||
|
{
|
||||||
|
while (message && *message) {
|
||||||
|
char c = *message++;
|
||||||
|
if (m_screen) m_screen->putc(c);
|
||||||
|
serial_write(c);
|
||||||
|
if (c == '\n') serial_write('\r');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,20 +4,17 @@
|
|||||||
#include "font.h"
|
#include "font.h"
|
||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
|
|
||||||
struct console_data;
|
class console_out_screen;
|
||||||
|
|
||||||
class console
|
class console
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
console(const font &f, const screen &s, void *scratch, size_t len);
|
console();
|
||||||
|
|
||||||
void repaint();
|
|
||||||
void scroll(unsigned lines);
|
|
||||||
|
|
||||||
void set_color(uint8_t fg, uint8_t bg);
|
void set_color(uint8_t fg, uint8_t bg);
|
||||||
|
|
||||||
size_t puts(const char *message);
|
void puts(const char *message);
|
||||||
size_t printf(const char *fmt, ...);
|
void printf(const char *fmt, ...);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void put_hex(T x);
|
void put_hex(T x);
|
||||||
@@ -25,30 +22,20 @@ public:
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
void put_dec(T x);
|
void put_dec(T x);
|
||||||
|
|
||||||
static console * get() { return default_console; }
|
static console * get();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char * line_pointer(unsigned line);
|
console_out_screen *m_screen;
|
||||||
uint16_t * attr_pointer(unsigned line);
|
|
||||||
|
|
||||||
font m_font;
|
|
||||||
screen m_screen;
|
|
||||||
|
|
||||||
kutil::coord<unsigned> m_size;
|
|
||||||
kutil::coord<unsigned> m_pos;
|
|
||||||
screen::pixel_t m_fg, m_bg;
|
|
||||||
uint16_t m_attr;
|
|
||||||
|
|
||||||
size_t m_first;
|
|
||||||
size_t m_length;
|
|
||||||
|
|
||||||
char *m_data;
|
|
||||||
uint16_t *m_attrs;
|
|
||||||
screen::pixel_t *m_palette;
|
|
||||||
|
|
||||||
static console *default_console;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern console g_console;
|
||||||
|
inline console * console::get() { return &g_console; }
|
||||||
|
|
||||||
|
|
||||||
|
console_out_screen * console_get_screen_out(
|
||||||
|
const font &f, const screen &s, void *scratch, size_t len);
|
||||||
|
|
||||||
|
|
||||||
extern const char digits[];
|
extern const char digits[];
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ extern "C" {
|
|||||||
void kernel_main(popcorn_data *header);
|
void kernel_main(popcorn_data *header);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void * operator new (size_t, void *p) throw() { return p; }
|
||||||
|
|
||||||
|
/*
|
||||||
console
|
console
|
||||||
load_console(const popcorn_data *header)
|
load_console(const popcorn_data *header)
|
||||||
{
|
{
|
||||||
@@ -36,11 +39,12 @@ load_console(const popcorn_data *header)
|
|||||||
|
|
||||||
return cons;
|
return cons;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
kernel_main(popcorn_data *header)
|
kernel_main(popcorn_data *header)
|
||||||
{
|
{
|
||||||
console cons = load_console(header);
|
console *cons = new (&g_console) console();
|
||||||
|
|
||||||
memory_initialize_managers(
|
memory_initialize_managers(
|
||||||
header->memory_map,
|
header->memory_map,
|
||||||
@@ -50,13 +54,13 @@ kernel_main(popcorn_data *header)
|
|||||||
interrupts_init();
|
interrupts_init();
|
||||||
interrupts_enable();
|
interrupts_enable();
|
||||||
|
|
||||||
cons.puts("Interrupts initialized.\n");
|
g_console.puts("Interrupts initialized.\n");
|
||||||
|
|
||||||
device_manager devices(header->acpi_table);
|
device_manager devices(header->acpi_table);
|
||||||
|
|
||||||
// int x = 1 / 0;
|
// int x = 1 / 0;
|
||||||
// __asm__ __volatile__("int $15");
|
// __asm__ __volatile__("int $15");
|
||||||
|
|
||||||
cons.puts("boogity!");
|
g_console.puts("boogity!");
|
||||||
do_the_set_registers(header);
|
do_the_set_registers(header);
|
||||||
}
|
}
|
||||||
|
|||||||
3
src/modules/kutil/cpprt.cpp
Normal file
3
src/modules/kutil/cpprt.cpp
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
extern "C" {
|
||||||
|
void __cxa_pure_virtual() { while(1); }
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user