BaseOS
This commit is contained in:
70
src/main.c
Normal file
70
src/main.c
Normal file
@@ -0,0 +1,70 @@
|
||||
#include "renderer.h"
|
||||
#include "color.h"
|
||||
#include "font_pack.h"
|
||||
#include "io.h"
|
||||
|
||||
int kernel_main(void)
|
||||
{
|
||||
uart_io.puts("Initializing renderer...\n");
|
||||
|
||||
Renderer renderer;
|
||||
if (!renderer_init(&renderer))
|
||||
{
|
||||
uart_io.puts("Failed to allocate framebuffer.\n");
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
|
||||
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};
|
||||
RenderObject blue_rect = {100, 100, 100, 100, COLOR_BLUE};
|
||||
|
||||
RenderText text = {
|
||||
.base = {
|
||||
.x = 20,
|
||||
.y = 30,
|
||||
.color = 0xFFFFFFFF},
|
||||
.text = "HELLO MARIO",
|
||||
.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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user