vbos/drivers/term/fbcon.c
Michael Shaw 1726663cab fbcon: fix palette issue
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
2026-07-17 21:35:18 -04:00

83 lines
2.1 KiB
C

/* SPDX-License-Identifier: GPL-2.0-only */
#include <kernel/common.h>
#include <kernel/requests.h>
#include <kernel/mem.h>
#include <kernel/page.h>
#include <kernel/tty.h>
#include <lib/stdio.h>
#include "flanterm.h"
#include "fb.h"
static struct flanterm_context *ft_ctx;
static void fbcon_putchar(struct tty *tty, char c)
{
flanterm_write(ft_ctx, &c, 1);
if (c == '\n') {
c = '\r';
flanterm_write(ft_ctx, &c, 1);
}
}
static char fbcon_getchar(struct tty *tty)
{
return 0;
}
static struct tty_serial_ops fbcon_serial_ops = {
.serial_putchar = fbcon_putchar,
.serial_getchar = fbcon_getchar,
};
struct tty *fbcon_init(void)
{
static u32 ansi_colors[] = {0x000000, 0xAA0000, 0x00AA00, 0x00AAAA, 0x0000AA, 0xAA00AA, 0xAAAA00, 0xAAAAAA};
static u32 ansi_bright_colors[] = {0x000000, 0xDD00DD, 0x00DD00, 0x00DDDD, 0x0000DD, 0xDD00DD, 0xDDDD00, 0xDDDDDD};
static u32 default_fg = 0xDDDDDDDD;
static u32 default_bg = 0x00000000;
static u32 default_fg_bright = 0xFFFFFFFF;
static u32 default_bg_bright = 0x00000000;
if (!fb_res || !fb_res->framebuffer_count)
return NULL;
struct limine_framebuffer *fb = fb_res->framebuffers[0];
size_t fb_size = fb->pitch * fb->height;
void *fb_virt = map_mmio_dev((paddr_t)TO_PHYS(fb->address), fb_size);
if (!fb_virt)
return NULL;
ft_ctx = flanterm_fb_init(
NULL, NULL, /* malloc/free override */
fb_virt, /* framebuffer virt pointer */
fb->width, fb->height, fb->pitch, /* screen geometry */
fb->red_mask_size, fb->red_mask_shift, /* red */
fb->green_mask_size, fb->green_mask_shift, /* green */
fb->blue_mask_size, fb->blue_mask_shift, /* blue */
NULL, /* canvas */
ansi_colors, ansi_bright_colors, /* colors */
&default_bg, &default_fg, /* bg colors */
&default_bg_bright, &default_fg_bright, /* bright bg colors */
NULL, 0, 0, 0, /* font ptr, width, height, spacing */
0, 0, /* font scale x, y */
0, /* margin */
FLANTERM_FB_ROTATE_0 /* rotation */
);
if (!ft_ctx)
return NULL;
struct tty *fbtty = tty_create("tty1", NULL);
fbtty->serial_ops = fbcon_serial_ops;
kinfo("fbcon: framebuffer console initialized (%lux%lu)\n", fb->width, fb->height);
return fbtty;
}