62 lines
1.5 KiB
C
62 lines
1.5 KiB
C
#include "../syscall.h"
|
|
#include "../drivers/vga.h"
|
|
#include <stdint.h>
|
|
|
|
enum {
|
|
FRAME_SIZE = VGA_GRAPHICS_WIDTH * VGA_GRAPHICS_HEIGHT,
|
|
BLOCK_WIDTH = 270,
|
|
BLOCK_HEIGHT = 100,
|
|
BLOCK_X = 10,
|
|
BLOCK_Y = 0,
|
|
};
|
|
|
|
// Non-zero initializer keeps the framebuffer in the program image, which this
|
|
// loader maps more reliably than a large BSS object.
|
|
static uint8_t frame[FRAME_SIZE] = { 1 };
|
|
|
|
static uint32_t time_ms(void) {
|
|
return (uint32_t)syscall(SYS_time_ms, 0);
|
|
}
|
|
|
|
static void clear_frame(uint8_t color) {
|
|
for (uint32_t i = 0; i < FRAME_SIZE; i++) {
|
|
frame[i] = color;
|
|
}
|
|
}
|
|
|
|
static void put_pixel(int x, int y, uint8_t color) {
|
|
if (x < 0 || x >= VGA_GRAPHICS_WIDTH || y < 0 || y >= VGA_GRAPHICS_HEIGHT) {
|
|
return;
|
|
}
|
|
frame[y * VGA_GRAPHICS_WIDTH + x] = color;
|
|
}
|
|
|
|
static void draw_demo(void) {
|
|
clear_frame(0x01);
|
|
|
|
for (int y = 0; y < BLOCK_HEIGHT; y++) {
|
|
for (int x = 0; x < BLOCK_WIDTH; x++) {
|
|
int screen_x = BLOCK_X + x;
|
|
int screen_y = BLOCK_Y + y;
|
|
uint8_t color = (uint8_t)((x + 2 * y) & 0x3f);
|
|
|
|
if (x < 3 || y < 3 || x >= BLOCK_WIDTH - 3 || y >= BLOCK_HEIGHT - 3) {
|
|
color = 0x3f;
|
|
}
|
|
put_pixel(screen_x, screen_y, color);
|
|
}
|
|
}
|
|
}
|
|
|
|
int main(void) {
|
|
syscall(SYS_switch_to_graphics, 0);
|
|
draw_demo();
|
|
syscall(SYS_swap_frame, (uintptr_t)frame);
|
|
|
|
uint32_t start = time_ms();
|
|
while ((uint32_t)(time_ms() - start) < 2000) {
|
|
}
|
|
|
|
return 0;
|
|
}
|