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,
|
framebuffer0.init((void*)bootboot.fb_ptr, bootboot.fb_type, bootboot.fb_scanline, bootboot.fb_width,
|
||||||
bootboot.fb_height);
|
bootboot.fb_height);
|
||||||
// ASSERT(TextRenderer::try_initialize());
|
|
||||||
|
|
||||||
kernelPMM.init_from_mmap();
|
kernelPMM.init_from_mmap();
|
||||||
kernelVMM.init();
|
kernelVMM.init();
|
||||||
|
|
||||||
InitRD::init();
|
InitRD::init();
|
||||||
|
|
||||||
|
ASSERT(TextRenderer::try_initialize());
|
||||||
|
|
||||||
if (strstr(environment, "quiet=1"))
|
if (strstr(environment, "quiet=1"))
|
||||||
{
|
{
|
||||||
KernelLog::toggle_log_level(LogLevel::DEBUG);
|
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 "init/InitRD.h"
|
||||||
#include "io/Serial.h"
|
#include "io/Serial.h"
|
||||||
#include "log/Log.h"
|
#include "log/Log.h"
|
||||||
#include "psf2.h"
|
#include "psf1.h"
|
||||||
#include "render/Framebuffer.h"
|
#include "render/Framebuffer.h"
|
||||||
#include "std/stdio.h"
|
#include "std/stdio.h"
|
||||||
#include "std/string.h"
|
#include "std/string.h"
|
||||||
|
|
||||||
extern BOOTBOOT bootboot;
|
extern BOOTBOOT bootboot;
|
||||||
|
|
||||||
static psf2_t* font;
|
static psf1_t* font;
|
||||||
static Color bgColor = Color::Black;
|
static Color bgColor = Color::Black;
|
||||||
static Color fgColor = Color::White;
|
static Color fgColor = Color::White;
|
||||||
static uint32_t xpos = 0;
|
static uint32_t xpos = 0;
|
||||||
static uint32_t ypos = 0;
|
static uint32_t ypos = 0;
|
||||||
|
|
||||||
|
#define FONT_HEIGHT font->charsize
|
||||||
|
#define FONT_WIDTH 8
|
||||||
|
|
||||||
bool TextRenderer::try_initialize()
|
bool TextRenderer::try_initialize()
|
||||||
{
|
{
|
||||||
InitRD::File font_file = InitRD::open("boot/font.psf");
|
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");
|
kerrorln("Failed to load boot/font.psf from initrd");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
font = (psf2_t*)font_file.addr;
|
font = (psf1_t*)font_file.addr;
|
||||||
if (font->magic != PSF_FONT_MAGIC)
|
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;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,19 +45,17 @@ bool TextRenderer::is_initialized()
|
|||||||
return font; // if font is NULL, not initialized, else yes
|
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 =
|
volatile uint8_t* glyph = (uint8_t*)font->glyphs + (c * font->charsize);
|
||||||
(uint8_t*)font + font->headersize + (c > 0 && (uint32_t)c < font->numglyph ? c : 0) * font->bytesperglyph;
|
for (uint32_t y = 0; y < FONT_HEIGHT; y++)
|
||||||
int mask;
|
|
||||||
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);
|
if (((*glyph & (0b10000000 >> x)) > 0)) { framebuffer0.set_pixel(cx + x, cy + y, fg); }
|
||||||
mask >>= 1;
|
else { framebuffer0.set_pixel(cx + x, cy + y, bg); }
|
||||||
}
|
}
|
||||||
|
glyph++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,13 +64,13 @@ void TextRenderer::putchar(char chr)
|
|||||||
switch (chr)
|
switch (chr)
|
||||||
{
|
{
|
||||||
case '\n':
|
case '\n':
|
||||||
ypos += font->height;
|
ypos += FONT_HEIGHT;
|
||||||
if ((ypos + font->height) >= bootboot.fb_height)
|
if ((ypos + FONT_HEIGHT) >= bootboot.fb_height)
|
||||||
{
|
{
|
||||||
memcpy((void*)bootboot.fb_ptr, (uint32_t*)bootboot.fb_ptr + (bootboot.fb_scanline * font->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));
|
bootboot.fb_size - (sizeof(uint32_t) * bootboot.fb_scanline * FONT_HEIGHT));
|
||||||
ypos -= font->height;
|
ypos -= FONT_HEIGHT;
|
||||||
framebuffer0.paint_rect(0, ypos, bootboot.fb_width, font->height, Color::Black);
|
framebuffer0.paint_rect(0, ypos, bootboot.fb_width, FONT_HEIGHT, Color::Black);
|
||||||
}
|
}
|
||||||
xpos = 0;
|
xpos = 0;
|
||||||
break;
|
break;
|
||||||
@ -75,23 +78,23 @@ void TextRenderer::putchar(char chr)
|
|||||||
case '\b':
|
case '\b':
|
||||||
if (xpos != 0)
|
if (xpos != 0)
|
||||||
{
|
{
|
||||||
xpos -= font->width + 1;
|
xpos -= FONT_WIDTH;
|
||||||
framebuffer0.paint_rect(xpos, ypos, font->width + 1, font->height, Color::Black);
|
framebuffer0.paint_rect(xpos, ypos, FONT_WIDTH, FONT_HEIGHT, Color::Black);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
putchar_at_offset(chr, xpos, ypos, fgColor, bgColor);
|
putchar_at_offset(chr, xpos, ypos, fgColor, bgColor);
|
||||||
xpos += font->width + 1;
|
xpos += FONT_WIDTH;
|
||||||
if ((xpos + font->width + 1) > bootboot.fb_width)
|
if ((xpos + FONT_WIDTH) > bootboot.fb_width)
|
||||||
{
|
{
|
||||||
xpos = 0;
|
xpos = 0;
|
||||||
ypos += font->height;
|
ypos += FONT_HEIGHT;
|
||||||
if (ypos > bootboot.fb_height)
|
if (ypos > bootboot.fb_height)
|
||||||
{
|
{
|
||||||
memcpy((void*)bootboot.fb_ptr, (uint32_t*)bootboot.fb_ptr + (bootboot.fb_scanline * font->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));
|
bootboot.fb_size - (sizeof(uint32_t) * bootboot.fb_scanline * FONT_HEIGHT));
|
||||||
ypos -= font->height;
|
ypos -= FONT_HEIGHT;
|
||||||
framebuffer0.paint_rect(0, ypos, bootboot.fb_width, font->height, Color::Black);
|
framebuffer0.paint_rect(0, ypos, bootboot.fb_width, FONT_HEIGHT, Color::Black);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user