Try to make TextRenderer work... still failing
I can now safely call try_initialize() in early_init though
This commit is contained in:
parent
86e4fce654
commit
d8bfb76eef
Binary file not shown.
11
kernel/include/psf1.h
Normal file
11
kernel/include/psf1.h
Normal file
@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
extern unsigned char psf1_magic[2];
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned char magic[2];
|
||||
unsigned char mode;
|
||||
unsigned char charsize;
|
||||
unsigned char glyphs[1];
|
||||
} __attribute__((packed)) psf1_t;
|
@ -1,17 +0,0 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
#define PSF_FONT_MAGIC 0x864ab572
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t magic;
|
||||
uint32_t version;
|
||||
uint32_t headersize;
|
||||
uint32_t flags;
|
||||
uint32_t numglyph;
|
||||
uint32_t bytesperglyph;
|
||||
uint32_t height;
|
||||
uint32_t width;
|
||||
uint8_t glyphs;
|
||||
} __attribute__((packed)) psf2_t;
|
@ -38,13 +38,14 @@ void Init::early_init()
|
||||
|
||||
framebuffer0.init((void*)bootboot.fb_ptr, bootboot.fb_type, bootboot.fb_scanline, bootboot.fb_width,
|
||||
bootboot.fb_height);
|
||||
// ASSERT(TextRenderer::try_initialize());
|
||||
|
||||
kernelPMM.init_from_mmap();
|
||||
kernelVMM.init();
|
||||
|
||||
InitRD::init();
|
||||
|
||||
ASSERT(TextRenderer::try_initialize());
|
||||
|
||||
if (strstr(environment, "quiet=1"))
|
||||
{
|
||||
KernelLog::toggle_log_level(LogLevel::DEBUG);
|
||||
|
3
kernel/src/psf1.cpp
Normal file
3
kernel/src/psf1.cpp
Normal file
@ -0,0 +1,3 @@
|
||||
#include "psf1.h"
|
||||
|
||||
unsigned char psf1_magic[2] = {0x36, 0x04};
|
@ -5,19 +5,22 @@
|
||||
#include "init/InitRD.h"
|
||||
#include "io/Serial.h"
|
||||
#include "log/Log.h"
|
||||
#include "psf2.h"
|
||||
#include "psf1.h"
|
||||
#include "render/Framebuffer.h"
|
||||
#include "std/stdio.h"
|
||||
#include "std/string.h"
|
||||
|
||||
extern BOOTBOOT bootboot;
|
||||
|
||||
static psf2_t* font;
|
||||
static psf1_t* font;
|
||||
static Color bgColor = Color::Black;
|
||||
static Color fgColor = Color::White;
|
||||
static uint32_t xpos = 0;
|
||||
static uint32_t ypos = 0;
|
||||
|
||||
#define FONT_HEIGHT font->charsize
|
||||
#define FONT_WIDTH 8
|
||||
|
||||
bool TextRenderer::try_initialize()
|
||||
{
|
||||
InitRD::File font_file = InitRD::open("boot/font.psf");
|
||||
@ -26,12 +29,14 @@ bool TextRenderer::try_initialize()
|
||||
kerrorln("Failed to load boot/font.psf from initrd");
|
||||
return false;
|
||||
}
|
||||
font = (psf2_t*)font_file.addr;
|
||||
if (font->magic != PSF_FONT_MAGIC)
|
||||
font = (psf1_t*)font_file.addr;
|
||||
if (font->magic[0] != psf1_magic[0] || font->magic[1] != psf1_magic[1])
|
||||
{
|
||||
kerrorln("Font magic does not match PSF font magic: %x", font->magic);
|
||||
kerrorln("Font magic does not match PSF font magic: 0x%x 0x%x", font->magic[0], font->magic[1]);
|
||||
return false;
|
||||
}
|
||||
kdbgln("Loaded font %s, height %d, address %lx, mode %d", font_file.name, font->charsize,
|
||||
(uintptr_t)&font->glyphs[0], font->mode);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -40,19 +45,17 @@ bool TextRenderer::is_initialized()
|
||||
return font; // if font is NULL, not initialized, else yes
|
||||
}
|
||||
|
||||
static void putchar_at_offset(char c, int cx, int cy, Color& fg, Color& bg)
|
||||
static void putchar_at_offset(char c, uint32_t cx, uint32_t cy, Color& fg, Color& bg)
|
||||
{
|
||||
uint8_t* glyph =
|
||||
(uint8_t*)font + font->headersize + (c > 0 && (uint32_t)c < font->numglyph ? c : 0) * font->bytesperglyph;
|
||||
int mask;
|
||||
for (uint32_t y = 0; y < font->height; y++)
|
||||
volatile uint8_t* glyph = (uint8_t*)font->glyphs + (c * font->charsize);
|
||||
for (uint32_t y = 0; y < FONT_HEIGHT; y++)
|
||||
{
|
||||
mask = 1 << (font->width - 1);
|
||||
for (uint32_t x = 0; x < font->width; x++)
|
||||
for (uint32_t x = 0; x < FONT_WIDTH; x++)
|
||||
{
|
||||
framebuffer0.set_pixel(cx + x, cy + y, *((uint32_t*)glyph) & mask ? fg : bg);
|
||||
mask >>= 1;
|
||||
if (((*glyph & (0b10000000 >> x)) > 0)) { framebuffer0.set_pixel(cx + x, cy + y, fg); }
|
||||
else { framebuffer0.set_pixel(cx + x, cy + y, bg); }
|
||||
}
|
||||
glyph++;
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,13 +64,13 @@ void TextRenderer::putchar(char chr)
|
||||
switch (chr)
|
||||
{
|
||||
case '\n':
|
||||
ypos += font->height;
|
||||
if ((ypos + font->height) >= bootboot.fb_height)
|
||||
ypos += FONT_HEIGHT;
|
||||
if ((ypos + FONT_HEIGHT) >= bootboot.fb_height)
|
||||
{
|
||||
memcpy((void*)bootboot.fb_ptr, (uint32_t*)bootboot.fb_ptr + (bootboot.fb_scanline * font->height),
|
||||
bootboot.fb_size - (sizeof(uint32_t) * bootboot.fb_scanline * font->height));
|
||||
ypos -= font->height;
|
||||
framebuffer0.paint_rect(0, ypos, bootboot.fb_width, font->height, Color::Black);
|
||||
memcpy((void*)bootboot.fb_ptr, (uint32_t*)bootboot.fb_ptr + (bootboot.fb_scanline * FONT_HEIGHT),
|
||||
bootboot.fb_size - (sizeof(uint32_t) * bootboot.fb_scanline * FONT_HEIGHT));
|
||||
ypos -= FONT_HEIGHT;
|
||||
framebuffer0.paint_rect(0, ypos, bootboot.fb_width, FONT_HEIGHT, Color::Black);
|
||||
}
|
||||
xpos = 0;
|
||||
break;
|
||||
@ -75,23 +78,23 @@ void TextRenderer::putchar(char chr)
|
||||
case '\b':
|
||||
if (xpos != 0)
|
||||
{
|
||||
xpos -= font->width + 1;
|
||||
framebuffer0.paint_rect(xpos, ypos, font->width + 1, font->height, Color::Black);
|
||||
xpos -= FONT_WIDTH;
|
||||
framebuffer0.paint_rect(xpos, ypos, FONT_WIDTH, FONT_HEIGHT, Color::Black);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
putchar_at_offset(chr, xpos, ypos, fgColor, bgColor);
|
||||
xpos += font->width + 1;
|
||||
if ((xpos + font->width + 1) > bootboot.fb_width)
|
||||
xpos += FONT_WIDTH;
|
||||
if ((xpos + FONT_WIDTH) > bootboot.fb_width)
|
||||
{
|
||||
xpos = 0;
|
||||
ypos += font->height;
|
||||
ypos += FONT_HEIGHT;
|
||||
if (ypos > bootboot.fb_height)
|
||||
{
|
||||
memcpy((void*)bootboot.fb_ptr, (uint32_t*)bootboot.fb_ptr + (bootboot.fb_scanline * font->height),
|
||||
bootboot.fb_size - (sizeof(uint32_t) * bootboot.fb_scanline * font->height));
|
||||
ypos -= font->height;
|
||||
framebuffer0.paint_rect(0, ypos, bootboot.fb_width, font->height, Color::Black);
|
||||
memcpy((void*)bootboot.fb_ptr, (uint32_t*)bootboot.fb_ptr + (bootboot.fb_scanline * FONT_HEIGHT),
|
||||
bootboot.fb_size - (sizeof(uint32_t) * bootboot.fb_scanline * FONT_HEIGHT));
|
||||
ypos -= FONT_HEIGHT;
|
||||
framebuffer0.paint_rect(0, ypos, bootboot.fb_width, FONT_HEIGHT, Color::Black);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user