restrcuct
This commit is contained in:
71
src/main.c
71
src/main.c
@@ -2,9 +2,30 @@
|
||||
#include "color.h"
|
||||
#include "font_pack.h"
|
||||
#include "io.h"
|
||||
#include "String.h"
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
int kernel_main(void)
|
||||
{
|
||||
String str;
|
||||
cs_init(&str);
|
||||
cs_set(&str, "HELLO MARIO");
|
||||
uart_io.puts("Initializing renderer...\n");
|
||||
|
||||
Renderer renderer;
|
||||
@@ -23,48 +44,38 @@ int kernel_main(void)
|
||||
uart_io.putc('\n');
|
||||
|
||||
RenderObject background = {0, 0, renderer.width, renderer.height, COLOR_RED};
|
||||
RenderObject blue_rect = {100, 100, 100, 100, COLOR_BLUE};
|
||||
|
||||
RenderText text = {
|
||||
.base = {
|
||||
.x = 20,
|
||||
.y = 30,
|
||||
.color = 0xFFFFFFFF},
|
||||
.text = "HELLO MARIO",
|
||||
.text = str.buffer,
|
||||
.font = &basic_font_pack,
|
||||
};
|
||||
uart_io.puts("Use WASD keys to move the rectangle.\n");
|
||||
|
||||
// Initial draw
|
||||
renderer.clear_screen(&renderer, background.color);
|
||||
renderer.draw_rect(&renderer, &blue_rect);
|
||||
renderer.draw_text(&renderer, &text);
|
||||
|
||||
while (1)
|
||||
{
|
||||
char c = uart_io.getc();
|
||||
uart_io.putc(c);
|
||||
|
||||
// Movement
|
||||
if ((c == 'w' || c == 'W') && blue_rect.y > 0)
|
||||
blue_rect.y = (blue_rect.y > 10) ? blue_rect.y - 10 : 0;
|
||||
if ((c == 's' || c == 'S') && (blue_rect.y + blue_rect.height) < renderer.height)
|
||||
blue_rect.y += 10;
|
||||
if ((c == 'a' || c == 'A') && blue_rect.x > 0)
|
||||
blue_rect.x = (blue_rect.x > 10) ? blue_rect.x - 10 : 0;
|
||||
if ((c == 'd' || c == 'D') && (blue_rect.x + blue_rect.width) < renderer.width)
|
||||
blue_rect.x += 10;
|
||||
|
||||
// Redraw everything
|
||||
renderer.clear_screen(&renderer, background.color);
|
||||
renderer.draw_rect(&renderer, &blue_rect);
|
||||
renderer.draw_text(&renderer, &text);
|
||||
|
||||
// Print updated position
|
||||
uart_io.puts("\nRect X: ");
|
||||
uart_io.print_int(blue_rect.x);
|
||||
uart_io.puts(" Y: ");
|
||||
uart_io.print_int(blue_rect.y);
|
||||
uart_io.putc('\n');
|
||||
char c = uart_getc();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user