feat: blinking cursor

minor changes while trying to remember what i even wrote here after month break
This commit is contained in:
Karina
2026-01-24 19:26:12 +04:00
parent 358061cd6c
commit 26c0353554
8 changed files with 70 additions and 9 deletions
+3
View File
@@ -16,3 +16,6 @@ char console_getc();
void kprint(const char *str);
void kprintf(const char *fmt, ...);
void kgets(char* buff, u32 lim);
void cursor_blink();
void cursor_blinker_sched_task();
void console_toggle_cursor_blink();
+1
View File
@@ -33,6 +33,7 @@ typedef struct {
} SG_Window;
void sg_init(SG_Context *ctx);
u32 sg_get_pixel(SG_Context *ctx, SG_Point *p);
void sg_put_img(SG_Context *ctx, SG_Point *p, SG_Image *img);
void sg_draw_rect(SG_Context *ctx, SG_Point *p, u32 w, u32 h, u32 color);
void sg_draw_char_bitmap(SG_Context *ctx, SG_Point *p, char c, u32 color, SG_Font *font);
+19 -5
View File
@@ -101,12 +101,12 @@ void draw_panic_bg() {
console_set_color(0xFFFFFF);
console_set_default_color(0xFFFFFF);
SG_Point p = console_get_dimensions();
p.x /= 2;
p.y /= 2;
p.y -= 200;
// SG_Point p = console_get_dimensions();
// p.x /= 2;
// p.y /= 2;
// p.y -= 200;
console_set_cursor_pos(&p);
// console_set_cursor_pos(&p);
u64 msg_count = sizeof(fun_messages) / sizeof(fun_messages[0]);
u8 rand_num = shitrand() % msg_count;
@@ -128,9 +128,23 @@ __attribute__((noreturn)) void panic_exception(Registers *regs) {
kprintf("\t\t^yFlags^! (^yRFLAGS^!): %X\n", regs->rflags);
kprintf("\t\t^yStack Pointer^! (^yRSP^!): %X\n", regs->rsp);
if (regs->int_no == 14) {
kprintf("\t\t--------------------------------\n");
kprintf("\t\t ^yPage Fault Helper^! \n");
kprintf("\t\t--------------------------------\n");
u64 cr2;
__asm__ volatile("mov %%cr2, %0" : "=r"(cr2));
kprintf("\t\t^yFaulting Address^! (^yCR2^!): %X\n", cr2);
kprintf("\t\t^yERRCode^!: %X\n", regs->err_code);
u64 present = (regs->err_code & (1 << 0)) != 0;
u64 write = (regs->err_code & (1 << 1)) != 0;
u64 user = (regs->err_code & (1 << 2)) != 0;
u64 reserved = (regs->err_code & (1 << 3)) != 0;
u64 instruction = (regs->err_code & (1 << 4)) != 0;
kprintf("\t\t\t[^bP^!] ^yReason^! %s\n", present ? "Page Protection violation" : "Non-present page");
kprintf("\t\t\t[^bW^!] ^yCaused by^! %s\n", write ? "WRITE" : "READ");
kprintf("\t\t\t[^bU^!] ^yRing^! %s\n", user ? "3" : "0");
if (reserved) kprintf("\t\t\t[^bR^!] CPU Wrote 1 to a reserved field in page table entry. ^rCorrupt page table?^!\n");
if (instruction) kprintf("\t\t\t[^bI^!] ^yTried to^! execute ^ycode from^! NX ^ymemory^!\n");
}
kprintf("\t\t--------------------------------\n");
kprintf("\t\t\t\t^yREGISTERS^!\n");
+34 -1
View File
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (c) 2025 0xKarinyash
#include "core/scheduler.h"
#include <drivers/console.h>
#include <drivers/serial.h>
#include <drivers/font.h>
@@ -33,6 +34,9 @@ static SG_Font s_font = {0};
static u32 s_color = COLOR_WHITE;
static u32 s_def_color = COLOR_WHITE;
static u32 s_bg_color = COLOR_BLACK;
static bool s_are_we_blinkin = true;
static bool s_waiting_for_input = false;
static bool s_cursor_visible = false;
void console_init(SG_Context *ctx) {
ctx_ptr = ctx;
@@ -235,11 +239,17 @@ void console_set_default_color(u32 color) {
}
char console_getc() {
while (kb_buf.head == kb_buf.tail) __asm__ volatile ("sti; hlt");
s_waiting_for_input = true;
while (kb_buf.head == kb_buf.tail) { __asm__ volatile ("sti"); yield(1); }
__asm__ volatile ("cli");
s_waiting_for_input = false;
char temp = kb_buf.buffer[kb_buf.tail];
kb_buf.tail = (kb_buf.tail + 1) % KB_BUFF_SIZE;
__asm__ volatile ("sti");
if (s_cursor_visible) {
cursor_blink();
s_cursor_visible = false;
}
return temp;
}
@@ -270,3 +280,26 @@ void kgets(char* buff, u32 lim) {
}
}
}
void cursor_blink() {
sg_draw_rect(ctx_ptr, &s_cursor_pos, s_font.w, s_font.h, sg_get_pixel(ctx_ptr, &s_cursor_pos) ^ 0xFFFFFF);
}
void cursor_blinker_sched_task() {
while (true) {
if (s_are_we_blinkin) {
if (s_waiting_for_input) {
cursor_blink();
s_cursor_visible = !s_cursor_visible;
}
} else if (s_cursor_visible) {
cursor_blink();
s_cursor_visible = !s_cursor_visible;
}
yield(500);
}
}
void console_toggle_cursor_blink() {
s_are_we_blinkin = !s_are_we_blinkin;
}
+5
View File
@@ -18,6 +18,11 @@ void sg_init(SG_Context *ctx) {
main_context = ctx;
}
u32 sg_get_pixel(SG_Context *ctx, SG_Point *p) {
if (!ctx->fb || !p || p->x >= ctx->width || p->y >= ctx->height) return 0;
return ctx->fb[p->y * ctx->pitch + p->x];
}
void sg_put_img(SG_Context *ctx, SG_Point *p, SG_Image *img) {
if (!ctx->fb || !img) return;
+1 -1
View File
@@ -90,7 +90,7 @@ void* realloc(void* ptr, u64 new_size) {
if (curr->next &&
curr->next->is_free &&
(curr->size + sizeof(block_header) + curr->next->size) >= new_size) { // why ts shit so fucking unreadable
(curr->size + sizeof(block_header) + curr->next->size) >= new_size) { // why ts so fucking unreadable
combine_forward(curr);
return ptr;
}
+1 -1
View File
@@ -81,4 +81,4 @@ void cmd_debug() {
u64 status = debug();
kprintf("\nDebug ended with code %d\n", status);
return;
}
}
+6 -1
View File
@@ -7,6 +7,7 @@
#include <drivers/console.h>
#include <drivers/shitgui.h>
#include <core/scheduler.h>
#include <core/string.h>
#include <core/rand.h>
#include <core/splash.h>
@@ -33,7 +34,8 @@ typedef enum {
TOKEN_PANIC_UD2,
TOKEN_PANIC_PF,
TOKEN_CLEAR
TOKEN_CLEAR,
TOKEN_BLINKING
} ksh_token;
typedef struct {
@@ -46,6 +48,7 @@ static const ksh_command_map token_map[] = {
{"cls", TOKEN_CLEAR},
{"clear", TOKEN_CLEAR},
{"blinking", TOKEN_BLINKING},
{"meow", TOKEN_MEOW},
{"nya", TOKEN_MEOW},
@@ -75,6 +78,7 @@ ksh_token char2token(char* token) {
}
void ksh() {
sched_spawn(cursor_blinker_sched_task);
while (true) {
kprintf("ksh_> ");
char cmdbuff[256];
@@ -95,6 +99,7 @@ void ksh() {
case TOKEN_HELP: cmd_help(); break;
case TOKEN_KFETCH: cmd_kfetch(); break;
case TOKEN_MEOW: cmd_meow(); break;
case TOKEN_BLINKING: console_toggle_cursor_blink(); break;
default: kprintf("Unknown command!!\n"); break;
}