feat: changed font to 8x16; kfetch

This commit is contained in:
Karina
2025-12-22 00:11:32 +04:00
parent dd4155584a
commit 2c998b53e5
11 changed files with 234 additions and 166 deletions
+5 -5
View File
@@ -10,6 +10,8 @@
#include "gdt.h"
#include "idt.h"
#include "kfetch.h"
void kmain(Bootinfo* info) {
u32 *fb = (u32*)info->framebuffer.base;
if (!fb) return;
@@ -31,12 +33,10 @@ void kmain(Bootinfo* info) {
SG_Point logo_point = {sg_ctx.width-100, 100};
sg_put_img(&sg_ctx, &logo_point, &logo_img);
kprint("Welcome to termOS!!!\n");
kprintf("MemoryMap located at %x; \nMemory map size is %d\n", (u64)info->mem.map, (u64)info->mem.map_size);
kprintf("Welcome to ^ptermOS^0!!!\n");
kprintf("MemoryMap located at ^g%x^0; \nMemory map size is ^g%x^0\n", (u64)info->mem.map, (u64)info->mem.map_size);
int a = 1;
int b = 0;
kprintf("%d", a/b);
kfetch();
while (1) { __asm__("hlt"); }
}
+44 -3
View File
@@ -6,20 +6,29 @@
#include "types.h"
#include <stdarg.h>
#define COLOR_RED 0xFF5555
#define COLOR_GREEN 0x08bf39
#define COLOR_BLUE 0x5555FF
#define COLOR_YELLOW 0xFFFF55
#define COLOR_CYAN 0x55FFFF
#define COLOR_MAGENTA 0xFF55FF
#define COLOR_BLACK 0x000000
#define COLOR_WHITE 0xFFFFFF
#define COLOR_PINK 0xFFA3B1
static SG_Context *ctx_ptr = nullptr;
static SG_Point s_cursor_pos = {0};
static SG_Font s_font = {0};
static u32 s_color = 0xFFFFFF;
static u32 s_color = COLOR_WHITE;
void console_init(SG_Context *ctx) {
ctx_ptr = ctx;
s_cursor_pos.x = 0;
s_cursor_pos.y = 0;
s_font.h = 8;
s_font.h = 16;
s_font.w = 8;
s_font.base = (const unsigned char*)font8x8_basic;
s_font.base = (const unsigned char*)font8x16;
}
void console_clear(u32 color) {
@@ -32,6 +41,17 @@ void console_clear(u32 color) {
s_cursor_pos.y = 0;
}
SG_Context* console_get_context() {
return ctx_ptr;
}
SG_Point console_get_dimensions() {
SG_Point p = {0};
p.x = ctx_ptr->width;
p.y = ctx_ptr->height;
return p;
}
void console_set_cursor_pos(SG_Point *p) {
if (!p) return;
s_cursor_pos.x = p->x;
@@ -44,6 +64,8 @@ static void console_putc(char c) {
if (c == '\n') {
s_cursor_pos.x = 0;
s_cursor_pos.y += s_font.h;
} else if (c == '\t') {
s_cursor_pos.x += s_font.w * 4;
} else {
sg_draw_char_bitmap(ctx_ptr, &s_cursor_pos, c, s_color, &s_font);
s_cursor_pos.x += s_font.w;
@@ -137,6 +159,25 @@ void kprintf(const char *fmt, ...) {
break;
}
}
} else if (fmt[i] == '^') {
i++;
switch (fmt[i]) {
case 'r': console_set_color(COLOR_RED); break;
case 'g': console_set_color(COLOR_GREEN); break;
case 'b': console_set_color(COLOR_BLUE); break;
case 'y': console_set_color(COLOR_YELLOW); break;
case 'c': console_set_color(COLOR_CYAN); break;
case 'm': console_set_color(COLOR_MAGENTA); break;
case 'p': console_set_color(COLOR_PINK); break;
case '0': console_set_color(COLOR_BLACK); break;
case 'w': console_set_color(COLOR_WHITE); break;
case '^': console_putc('^'); break;
default: {
console_putc('^');
console_putc(fmt[i]);
break;
}
}
} else {
console_putc(fmt[i]);
}
+29
View File
@@ -0,0 +1,29 @@
// yes. *fetch in kernel
// WHY FUCKING NOT?? its my OS, my rules
#include "console.h"
const char* ascii_logo[] = {
" /\\___/\\ ",
" | > < | ",
" | w | ",
" |=======|__ ",
" | | | ",
" |TERMOS | | ",
" | |__| ",
" |_______| "
};
void kfetch() {
kprintf("\n\n");
kprintf("^p %s ^0\t\t^g kernel^0@^gtermos\n^0", ascii_logo[0]);
kprintf("^p %s ^0\t\t^0-------------\n^0", ascii_logo[1]);
kprintf("^p %s ^0\t\t^gOS^0: termOS 0.0.1\n^0", ascii_logo[2]);
kprintf("^p %s ^0\t\t^gKernel^0: sucks\n^0", ascii_logo[3]);
kprintf("^p %s ^0\t\t^gUptime^0: 0h 0m\n^0", ascii_logo[4]);
kprintf("^p %s ^0\t\t^gShell^0: termosh\n^0", ascii_logo[5]);
kprintf("^p %s ^p\t\t^gDE^0: shitgui\n^0", ascii_logo[6]);
kprintf("^p %s ^p\t\t^gCPU^0: cool one\n^0", ascii_logo[7]);
kprintf("\n\n");
}
+12 -4
View File
@@ -1,6 +1,7 @@
#include "panic.h"
#include "console.h"
#include "types.h"
#include "shitgui.h"
const char* exception_messages[] = {
@@ -42,17 +43,24 @@ __attribute__((noreturn)) void panic(Registers *regs) {
console_clear(0xFF0000);
console_set_color(0xFFFFFF);
SG_Point p = console_get_dimensions();
p.x /= 2;
p.y /= 2;
p.y -= 200;
console_set_cursor_pos(&p);
kprintf("\n\n");
kprintf("\t\t KERNEL PANIC :( \n");
kprintf("\t\t-------------------\n");
kprintf("\t\t\tKERNEL PANIC :( \n");
kprintf("\t\t-------------------------\n");
kprintf("\t\tCPU EXCEPTION: %d (%s)\n", regs->int_no, exception_messages[regs->int_no]);
kprintf("\t\tError Code: 0x%x\n", regs->err_code);
kprintf("\t\tInstruction Pointer (RIP): 0x%x\n", regs->rip);
kprintf("\t\tCode Segment (CS): 0x%x\n", regs->cs);
kprintf("\t\tFlags (RFLAGS): 0x%x\n", regs->rflags);
kprintf("\t\tStack Pointer (RSP): 0x%x\n", regs->rsp);
kprintf("\t\t-------------------\n");
kprintf(" \tSystem halted.\n");
kprintf("\t\t-------------------------\n");
kprintf("\t\t\tSystem halted.\n");
while (1) {
__asm__ volatile ("cli; hlt");
+1 -1
View File
@@ -59,7 +59,7 @@ void sg_draw_char_bitmap(SG_Context *ctx, SG_Point *p, char c, u32 color, SG_Fon
u8 bitmap_row = font->base[(unsigned char)c * font->h + y];
volatile u32 *row_ptr = &ctx->fb[(start_y + y) * ctx->pitch + start_x];
for (u32 x = 0; x < draw_w; x++) {
if (bitmap_row & (1 << x)) {
if (bitmap_row & (1 << (7 - x))) {
row_ptr[x] = color;
}
}