updated version

This commit is contained in:
2026-02-11 14:04:00 -07:00
parent b934f79878
commit d2d0a508ec
8 changed files with 295 additions and 185 deletions

View File

@@ -1,81 +1,65 @@
#include "renderer.h"
#include "String.h"
#include "color.h"
#include "font_pack.h"
#include "io.h"
#include "String.h"
#include "renderer.h"
static void delay_1s(void)
{
volatile unsigned long count = 80000000; // Example for ~1 sec at ~80 MHz CPU
while (count--)
{
__asm__ volatile("nop");
}
static void delay_1s(void) {
volatile unsigned long count = 80000000; // Example for ~1 sec at ~80 MHz CPU
while (count--) {
__asm__ volatile("nop");
}
}
void delay_seconds(unsigned int seconds)
{
for (unsigned int i = 0; i < seconds; i++)
{
delay_1s();
}
void delay_seconds(unsigned int seconds) {
for (unsigned int i = 0; i < seconds; i++) {
delay_1s();
}
}
int kernel_main(void)
{
String str;
cs_init(&str);
cs_set(&str, "HELLO MARIO");
uart_io.puts("Initializing renderer...\n");
int kernel_main(void) {
String str;
cs_init(&str);
cs_set(&str, "HELLO MARIO");
uart_io.puts("Initializing renderer...\n");
Renderer renderer;
if (!renderer_init(&renderer))
{
uart_io.puts("Failed to allocate framebuffer.\n");
while (1)
;
Renderer renderer;
if (!renderer_init(&renderer)) {
uart_io.puts("Failed to allocate framebuffer.\n");
while (1)
;
}
uart_io.puts("Framebuffer allocated.\n");
RenderObject background = {0, 0, renderer.width, renderer.height, COLOR_RED};
while (1) {
// Non-blocking UART input
char c = uart_getc_nonblocking();
if (c >= 32 && c <= 126) { // printable
cs_append_char(&str, c);
} else if (c == '\b' || c == 127) { // backspace
if (str.length > 0) {
str.length--;
str.buffer[str.length] = '\0';
}
}
uart_io.puts("Framebuffer allocated.\n");
uart_io.puts("Width: ");
uart_io.print_int(renderer.width);
uart_io.puts("\nHeight: ");
uart_io.print_int(renderer.height);
uart_io.putc('\n');
RenderObject background = {0, 0, renderer.width, renderer.height, COLOR_RED};
// Create a fresh RenderText each loop
RenderText text = {
.base = {
.x = 20,
.y = 30,
.color = 0xFFFFFFFF},
.base = {.x = 20, .y = 30, .color = 0xFFFFFFFF},
.text = str.buffer,
.font = &basic_font_pack,
};
while (1)
{
renderer.clear_screen(&renderer, background.color);
renderer.draw_text(&renderer, &text);
renderer.clear_screen(&renderer, background.color);
renderer.draw_text(&renderer, &text);
char c = uart_getc();
// uart_puts(str.buffer);
if (c >= 32 && c <= 126) // Printable ASCII
{
cs_append_char(&str, c);
}
else if (c == '\b' || c == 127) // Backspace support
{
if (str.length > 0)
{
str.length--;
str.buffer[str.length] = '\0';
}
}
uart_puts(str.buffer);
renderer.draw_text(&renderer, &text);
delay_seconds(4);
}
// Short delay for smoother typingi
delay_seconds(1);
}
}