21aef3e436
Signed-off-by: Chloe M. <chloe@mensia.org>
126 lines
2.3 KiB
C
126 lines
2.3 KiB
C
/*
|
|
* Copyright (c) 2026, Chloe M.
|
|
* Provided under the BSD-3 clause.
|
|
*
|
|
* Description: Bootvid driver
|
|
* Author: Chloe M.
|
|
*/
|
|
|
|
#include <drivers/bootvid/fbio.h>
|
|
#include <ke/bpal.h>
|
|
#include <ex/trace.h>
|
|
#include <stdef.h>
|
|
#include "flanterm.h"
|
|
#include "flanterm_backends/fb.h"
|
|
|
|
#define DTRACE(Fmt, ...) \
|
|
TRACE("[ BOOTVID ]: " Fmt, ##__VA_ARGS__)
|
|
|
|
/* Bootcons attributes */
|
|
#define DEFAULT_BG 0x000000
|
|
#define DEFAULT_FG 0xFFB000
|
|
|
|
static BPAL_FRAMEBUFFER Framebuffer;
|
|
static struct flanterm_context *FtCtx = NULL;
|
|
static BOOLEAN BootConsEnabled = false;
|
|
static BOOTCONS_ATTR DefaultConsAttr = {
|
|
.Foreground = DEFAULT_FG,
|
|
.Background = DEFAULT_BG
|
|
};
|
|
|
|
VOID
|
|
BootVidInitCons(BOOTCONS_ATTR *Attr)
|
|
{
|
|
if (BootConsEnabled) {
|
|
BootVidDeInitCons();
|
|
}
|
|
|
|
if (Attr == NULL) {
|
|
Attr = &DefaultConsAttr;
|
|
}
|
|
|
|
FtCtx = flanterm_fb_init(
|
|
NULL,
|
|
NULL,
|
|
Framebuffer.Address,
|
|
Framebuffer.Width,
|
|
Framebuffer.Height,
|
|
Framebuffer.Pitch,
|
|
Framebuffer.RedMaskSize,
|
|
Framebuffer.RedMaskShift,
|
|
Framebuffer.GreenMaskSize,
|
|
Framebuffer.GreenMaskShift,
|
|
Framebuffer.BlueMaskSize,
|
|
Framebuffer.BlueMaskShift,
|
|
NULL,
|
|
NULL,
|
|
NULL,
|
|
&Attr->Background,
|
|
&Attr->Foreground,
|
|
NULL,
|
|
NULL,
|
|
NULL,
|
|
0, 0, 0,
|
|
0, 0, 0, 0
|
|
);
|
|
|
|
BootConsEnabled = true;
|
|
DTRACE("bootcons enabled\n");
|
|
}
|
|
|
|
VOID
|
|
BootVidInit(VOID)
|
|
{
|
|
BPAL_HANDLE BpalHandle;
|
|
|
|
KeBpalGetHandle(&BpalHandle);
|
|
Framebuffer = BpalHandle.Framebuffer;
|
|
|
|
DTRACE("framebuffer width: %d\n", Framebuffer.Width);
|
|
DTRACE("framebuffer height: %d\n", Framebuffer.Height);
|
|
}
|
|
|
|
VOID
|
|
BootVidConsWrite(const CHAR *String, USIZE Length)
|
|
{
|
|
if (String == NULL || Length == 0) {
|
|
return;
|
|
}
|
|
|
|
if (!BootConsEnabled) {
|
|
return;
|
|
}
|
|
|
|
flanterm_write(FtCtx, String, Length);
|
|
}
|
|
|
|
VOID
|
|
BootVidDeInitCons(VOID)
|
|
{
|
|
if (!BootConsEnabled) {
|
|
return;
|
|
}
|
|
|
|
flanterm_deinit(FtCtx, NULL);
|
|
FtCtx = NULL;
|
|
BootConsEnabled = false;
|
|
}
|
|
|
|
|
|
VOID
|
|
BootVidClear(ULONG Color)
|
|
{
|
|
ULONG *Ptr;
|
|
|
|
Ptr = Framebuffer.Address;
|
|
for (USIZE Idx = 0; Idx < Framebuffer.Height * Framebuffer.Pitch; ++Idx) {
|
|
Ptr[Idx] = Color;
|
|
}
|
|
}
|
|
|
|
BOOLEAN
|
|
BootVidConsEn(VOID)
|
|
{
|
|
return BootConsEnabled;
|
|
}
|