mirror of
https://github.com/subhobhai943/SUB-OS.git
synced 2026-10-25 16:52:29 +00:00
Pressing Esc left the desktop and started the shell, but nothing appeared in the
emulator window -- the session was only visible on the host terminal. Once the
VBE adapter is switched into graphics mode the VGA text buffer at 0xB8000 stops
being scanned out, so every printk after that point reached serial and the
dmesg ring but never the display.
Disabling the DISPI interface does not bring the text console back; QEMU keeps
presenting the last framebuffer surface. So rather than clawing the adapter back
to text mode, the console is now rendered into the framebuffer:
drivers/video/fbcon.c draws the console with the shared 8x8 font and carries a
VT100 subset -- SGR colours, cursor addressing, relative moves, erase-display,
erase-line and save/restore. It presents a fixed 80x25 grid, because that is
the geometry the userland assumes (nano pads its bars with %-80s, the shell
wraps at TTY_WIDTH), with the glyph cell scaled to fill the active resolution.
The TTY driver became the console dispatcher: tty_write, tty_clear and
tty_set_cursor route to fbcon while it owns the display. That last one is what
makes nano work -- it positions with tty_set_cursor() rather than escapes, so
its full-screen repaint was landing as an append-only stream.
Also in this change:
- `video=WIDTHxHEIGHT` on the kernel command line selects the display mode,
defaulting to 1280x720 so a 16:9 host panel is filled rather than pillarboxed
when QEMU goes fullscreen. Rejects modes the heap cannot back.
- `make run-fullscreen`, plus zoom-to-fit on the windowed target, so scaling
preserves the guest aspect ratio instead of stretching it.
- QEMU targets raise vgamem_mb, since a 1280x720 32-bit surface exceeds the
default VGA memory.
- bochs_vbe_disable()/fb_set_active() let the framebuffer be marked dormant so
drawing routines no-op after a mode teardown.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01L5yKJT4Wo2cV3rfPrwY5MP
88 lines
2.5 KiB
C
88 lines
2.5 KiB
C
#include <drivers/fb.h>
|
|
#include <lib/font8x8.h>
|
|
#include <lib/string.h>
|
|
#include <kernel/printk.h>
|
|
|
|
static fb_info_t fb_info;
|
|
static uint32_t fb_mock_buffer[320 * 200];
|
|
|
|
void fb_init(void) {
|
|
memset(&fb_info, 0, sizeof(fb_info));
|
|
fb_info.width = 320;
|
|
fb_info.height = 200;
|
|
fb_info.pitch = 320 * 4;
|
|
fb_info.bpp = 32;
|
|
fb_info.address = fb_mock_buffer;
|
|
fb_info.active = true;
|
|
|
|
printk(KERN_INFO "FB: Linear Framebuffer initialized (%ux%ux%d bpp)\n",
|
|
fb_info.width, fb_info.height, fb_info.bpp);
|
|
}
|
|
|
|
const fb_info_t* fb_get_info(void) {
|
|
return &fb_info;
|
|
}
|
|
|
|
void fb_set_active(bool active) {
|
|
fb_info.active = active;
|
|
}
|
|
|
|
void fb_set_hardware_lfb(uint32_t* lfb_addr, uint32_t width, uint32_t height, uint8_t bpp) {
|
|
if (lfb_addr) {
|
|
fb_info.address = lfb_addr;
|
|
fb_info.width = width;
|
|
fb_info.height = height;
|
|
fb_info.pitch = width * (bpp / 8);
|
|
fb_info.bpp = bpp;
|
|
fb_info.active = true;
|
|
}
|
|
}
|
|
|
|
void fb_put_pixel(uint32_t x, uint32_t y, uint32_t color) {
|
|
if (fb_info.address && x < fb_info.width && y < fb_info.height) {
|
|
fb_info.address[y * fb_info.width + x] = color;
|
|
}
|
|
}
|
|
|
|
void fb_draw_rect(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t color) {
|
|
if (!fb_info.address) return;
|
|
for (uint32_t j = y; j < y + h && j < fb_info.height; j++) {
|
|
for (uint32_t i = x; i < x + w && i < fb_info.width; i++) {
|
|
fb_info.address[j * fb_info.width + i] = color;
|
|
}
|
|
}
|
|
}
|
|
|
|
void fb_clear(uint32_t color) {
|
|
fb_draw_rect(0, 0, fb_info.width, fb_info.height, color);
|
|
}
|
|
|
|
void fb_draw_char(uint32_t x, uint32_t y, char c, uint32_t fg, uint32_t bg) {
|
|
const uint8_t* glyph = font8x8_glyph(c);
|
|
|
|
// A background of 0 means "leave what is already there", which lets the
|
|
// boot splash draw status text straight over its gradient.
|
|
bool opaque = (bg != 0);
|
|
|
|
for (uint32_t row = 0; row < FONT8X8_HEIGHT; row++) {
|
|
uint8_t bits = glyph[row];
|
|
for (uint32_t col = 0; col < FONT8X8_WIDTH; col++) {
|
|
if (bits & (0x80u >> col)) {
|
|
fb_put_pixel(x + col, y + row, fg);
|
|
} else if (opaque) {
|
|
fb_put_pixel(x + col, y + row, bg);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void fb_draw_string(uint32_t x, uint32_t y, const char* str, uint32_t fg, uint32_t bg) {
|
|
if (!str) return;
|
|
uint32_t cur_x = x;
|
|
while (*str) {
|
|
fb_draw_char(cur_x, y, *str, fg, bg);
|
|
cur_x += 8;
|
|
str++;
|
|
}
|
|
}
|