mirror of
https://github.com/subhobhai943/SUB-OS.git
synced 2026-10-25 16:52:29 +00:00
Boot logo (init/bootlogo.c, init/logo_data.c, scripts/mklogo.py): The logo appears in two forms because the framebuffer does not exist for the first third of boot. An ASCII rendition goes to the text console and serial line from the first moments; once the video driver is up at step [5/14] the real bitmap takes over as a graphical splash with a progress bar tied to the actual boot stages. The asset is 4-bit palette indexed, so 160x160 pixels cost 12.5 KB instead of 100 KB, and carries a transparency mask so the mark composites onto the gradient rather than stamping a flat rectangle over it. scripts/mklogo.py regenerates init/logo_data.c from the source PNG. Boot reaches the desktop in well under a second, so the splash is held for a minimum duration and the bar sweeps to 100% during the hold; without that the logo would flash past unseen. `splashtime=<ms>` tunes it and `nosplash`, `nogui` or `text` skip it. Bootloader (boot/stage2.asm): stage2 staged the whole kernel in conventional RAM before copying it to 1 MB, which capped the kernel at roughly 576 KB before the load ran into video memory at 0xA0000. The logo pushed it over that line and the kernel stopped booting. Each 32 KB chunk now goes into one fixed low buffer and is copied straight to its final address, using unreal mode for the 32-bit reach. The ceiling is now the image itself, 1.375 MB. Console font (lib/font8x8.c): fb_draw_char was a stub that ignored its character argument and drew a filled rectangle, which is why the splash rendered its text as solid blocks. It now renders real glyphs, and the table it uses is shared: the framebuffer console, the canvas rasterizer and the desktop compositor had three divergent private copies, two of which still carried the `// \` line-continuation defect. printk console sink (kernel/printk.c): printk output can be redirected to a callback, so a caller can run a subsystem that reports via printk and capture what it printed. Serial and the dmesg ring still see everything, which keeps a captured run debuggable. Shell builtins (userland/lazybox/shell.c): The builtin chain is extracted into shell_execute_builtin(), so the kernel TTY and the desktop terminal accept the same vocabulary instead of the GUI seeing only the applet table. Callers that cannot be suspended pass allow_blocking = false to refuse the animating ones. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01L5yKJT4Wo2cV3rfPrwY5MP
176 lines
6.5 KiB
C
176 lines
6.5 KiB
C
#include <drivers/canvas.h>
|
|
#include <lib/font8x8.h>
|
|
#include <drivers/fb.h>
|
|
#include <mm/kmalloc.h>
|
|
#include <lib/string.h>
|
|
#include <kernel/printk.h>
|
|
|
|
static uint32_t* back_buffer = NULL;
|
|
static uint32_t screen_width = 320;
|
|
static uint32_t screen_height = 200;
|
|
|
|
|
|
void canvas_init(void) {
|
|
const fb_info_t* fb = fb_get_info();
|
|
if (fb && fb->width > 0 && fb->height > 0) {
|
|
screen_width = fb->width;
|
|
screen_height = fb->height;
|
|
}
|
|
back_buffer = (uint32_t*)kzalloc(screen_width * screen_height * sizeof(uint32_t));
|
|
printk(KERN_INFO "CANVAS: 2D Graphics Canvas & Rasterizer online (%ux%u 32bpp)\n",
|
|
screen_width, screen_height);
|
|
}
|
|
|
|
void canvas_clear(uint32_t color) {
|
|
if (!back_buffer) return;
|
|
for (size_t i = 0; i < screen_width * screen_height; i++) {
|
|
back_buffer[i] = color;
|
|
}
|
|
}
|
|
|
|
void canvas_draw_pixel(int x, int y, uint32_t color) {
|
|
if (!back_buffer || x < 0 || x >= (int)screen_width || y < 0 || y >= (int)screen_height) return;
|
|
back_buffer[y * screen_width + x] = color;
|
|
}
|
|
|
|
void canvas_draw_line(int x0, int y0, int x1, int y1, uint32_t color) {
|
|
int dx = (x1 > x0) ? (x1 - x0) : (x0 - x1);
|
|
int dy = (y1 > y0) ? (y1 - y0) : (y0 - y1);
|
|
int sx = (x0 < x1) ? 1 : -1;
|
|
int sy = (y0 < y1) ? 1 : -1;
|
|
int err = (dx > dy ? dx : -dy) / 2;
|
|
|
|
while (1) {
|
|
canvas_draw_pixel(x0, y0, color);
|
|
if (x0 == x1 && y0 == y1) break;
|
|
int e2 = err;
|
|
if (e2 > -dx) { err -= dy; x0 += sx; }
|
|
if (e2 < dy) { err += dx; y0 += sy; }
|
|
}
|
|
}
|
|
|
|
void canvas_draw_rect(int x, int y, int w, int h, uint32_t color, bool filled) {
|
|
if (w <= 0 || h <= 0) return;
|
|
if (filled) {
|
|
for (int j = y; j < y + h; j++) {
|
|
for (int i = x; i < x + w; i++) {
|
|
canvas_draw_pixel(i, j, color);
|
|
}
|
|
}
|
|
} else {
|
|
canvas_draw_line(x, y, x + w - 1, y, color);
|
|
canvas_draw_line(x, y + h - 1, x + w - 1, y + h - 1, color);
|
|
canvas_draw_line(x, y, x, y + h - 1, color);
|
|
canvas_draw_line(x + w - 1, y, x + w - 1, y + h - 1, color);
|
|
}
|
|
}
|
|
|
|
void canvas_draw_circle(int cx, int cy, int r, uint32_t color, bool filled) {
|
|
int x = r;
|
|
int y = 0;
|
|
int err = 0;
|
|
|
|
while (x >= y) {
|
|
if (filled) {
|
|
canvas_draw_line(cx - x, cy + y, cx + x, cy + y, color);
|
|
canvas_draw_line(cx - x, cy - y, cx + x, cy - y, color);
|
|
canvas_draw_line(cx - y, cy + x, cx + y, cy + x, color);
|
|
canvas_draw_line(cx - y, cy - x, cx + y, cy - x, color);
|
|
} else {
|
|
canvas_draw_pixel(cx + x, cy + y, color);
|
|
canvas_draw_pixel(cx + y, cy + x, color);
|
|
canvas_draw_pixel(cx - y, cy + x, color);
|
|
canvas_draw_pixel(cx - x, cy + y, color);
|
|
canvas_draw_pixel(cx - x, cy - y, color);
|
|
canvas_draw_pixel(cx - y, cy - x, color);
|
|
canvas_draw_pixel(cx + y, cy - x, color);
|
|
canvas_draw_pixel(cx + x, cy - y, color);
|
|
}
|
|
if (err <= 0) {
|
|
y += 1;
|
|
err += 2*y + 1;
|
|
}
|
|
if (err > 0) {
|
|
x -= 1;
|
|
err -= 2*x + 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
void canvas_draw_char(int x, int y, char c, uint32_t color, uint32_t bg_color) {
|
|
if (c < 32 || c > 126) c = ' ';
|
|
const uint8_t* glyph = font8x8_glyph(c);
|
|
|
|
for (int row = 0; row < 8; row++) {
|
|
uint8_t line = glyph[row];
|
|
for (int col = 0; col < 8; col++) {
|
|
if (line & (1 << (7 - col))) {
|
|
canvas_draw_pixel(x + col, y + row, color);
|
|
} else if (bg_color != 0) {
|
|
canvas_draw_pixel(x + col, y + row, bg_color);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void canvas_draw_string(int x, int y, const char* str, uint32_t color, uint32_t bg_color) {
|
|
if (!str) return;
|
|
int cur_x = x;
|
|
while (*str) {
|
|
canvas_draw_char(cur_x, y, *str, color, bg_color);
|
|
cur_x += 8;
|
|
str++;
|
|
}
|
|
}
|
|
|
|
void canvas_render_desktop_mockup(void) {
|
|
// 1. Wallpaper (Navy Gradient)
|
|
canvas_clear(COLOR_NAVY);
|
|
|
|
// 2. Top Banner / Desktop Header
|
|
canvas_draw_rect(0, 0, screen_width, 16, COLOR_TITLE_BAR, true);
|
|
canvas_draw_string(8, 4, "SUB-OS Graphical Desktop Environment v0.2.0", COLOR_WHITE, 0);
|
|
canvas_draw_string(screen_width - 80, 4, "13:45 UTC", COLOR_YELLOW, 0);
|
|
|
|
// 3. Floating Terminal Window (Simulated Window Manager)
|
|
int win_x = 24, win_y = 30, win_w = 270, win_h = 135;
|
|
canvas_draw_rect(win_x, win_y, win_w, win_h, COLOR_DARK_GRAY, true);
|
|
canvas_draw_rect(win_x, win_y, win_w, win_h, COLOR_LIGHT_GRAY, false);
|
|
|
|
// Window Title Bar
|
|
canvas_draw_rect(win_x, win_y, win_w, 14, COLOR_ACCENT, true);
|
|
canvas_draw_string(win_x + 6, win_y + 3, "Terminal - root@sub-os:~", COLOR_WHITE, 0);
|
|
canvas_draw_circle(win_x + win_w - 8, win_y + 7, 3, COLOR_RED, true);
|
|
canvas_draw_circle(win_x + win_w - 18, win_y + 7, 3, COLOR_YELLOW, true);
|
|
canvas_draw_circle(win_x + win_w - 28, win_y + 7, 3, COLOR_GREEN, true);
|
|
|
|
// Window Content
|
|
canvas_draw_string(win_x + 8, win_y + 22, "Welcome to SUB-OS Kernel 0.2.0", COLOR_GREEN, 0);
|
|
canvas_draw_string(win_x + 8, win_y + 36, "Tasks: 16 running | Memory: 122MB Free", COLOR_WHITE, 0);
|
|
canvas_draw_string(win_x + 8, win_y + 50, "Services: HTTPD, SSHD, NetFilter active", COLOR_YELLOW, 0);
|
|
canvas_draw_string(win_x + 8, win_y + 68, "sub-os:/> neofetch", COLOR_CYAN, 0);
|
|
canvas_draw_string(win_x + 8, win_y + 82, "OS: SUB-OS (x86_64 Long Mode)", COLOR_WHITE, 0);
|
|
canvas_draw_string(win_x + 8, win_y + 96, "Kernel: 0.2.0-lts Modular Monolithic", COLOR_WHITE, 0);
|
|
canvas_draw_string(win_x + 8, win_y + 112, "sub-os:/> _", COLOR_GREEN, 0);
|
|
|
|
// 4. Bottom Taskbar
|
|
canvas_draw_rect(0, screen_height - 18, screen_width, 18, COLOR_TITLE_BAR, true);
|
|
canvas_draw_rect(4, screen_height - 15, 45, 12, COLOR_ACCENT, true);
|
|
canvas_draw_string(8, screen_height - 13, "Start", COLOR_WHITE, 0);
|
|
canvas_draw_string(60, screen_height - 13, "[Terminal]", COLOR_LIGHT_GRAY, 0);
|
|
canvas_draw_string(140, screen_height - 13, "[Nano]", COLOR_LIGHT_GRAY, 0);
|
|
canvas_draw_string(195, screen_height - 13, "[HTTPD: 80]", COLOR_GREEN, 0);
|
|
canvas_draw_string(screen_width - 45, screen_height - 13, "[OK]", COLOR_YELLOW, 0);
|
|
|
|
canvas_present();
|
|
}
|
|
|
|
void canvas_present(void) {
|
|
if (!back_buffer) return;
|
|
const fb_info_t* fb = fb_get_info();
|
|
if (fb && fb->address != 0) {
|
|
uint32_t* hw_fb = (uint32_t*)fb->address;
|
|
memcpy(hw_fb, back_buffer, screen_width * screen_height * sizeof(uint32_t));
|
|
}
|
|
}
|