diff --git a/src/kernel/boot/TEMP-test_scheduler.c b/src/kernel/boot/TEMP-test_scheduler.c index 3a48d42..3cef0c2 100644 --- a/src/kernel/boot/TEMP-test_scheduler.c +++ b/src/kernel/boot/TEMP-test_scheduler.c @@ -3,13 +3,19 @@ #include extern gfx_context *term_fb; +extern gfx_context kernel_fb; void thread1() { - int a = 0; + int a = 1; + gfx_context *ctx = framebuffer_make_subcontext(&kernel_fb, 700, 300, 100, 100); while(1) { putCharacter(term_fb, 0, 0, RGB(255,255,0), RGB(0,0,0), '0'+(a++%10)); flip(term_fb); + draw_line(ctx, 0, 100, 50, ((a-1)%100), RGB(0,0,0)); + draw_line(ctx, 0, 100, 50, (a%100), RGB(255,0,0)); + flip(ctx); + sched_yield(); } } @@ -19,8 +25,10 @@ void thread2() int a = 0; while(1) { putCharacter(term_fb, 10, 10, RGB(0,255,255), RGB(0,0,0), 'A'+(a++%10)); + draw_rect(term_fb, 10, 10, 200, 300, RGB((uint8_t)(a%256), 0, 255-(uint8_t)(a%256))); flip(term_fb); sched_yield(); + } } diff --git a/src/kernel/drivers/terminal/fbterm.c b/src/kernel/drivers/terminal/fbterm.c index 9743705..6adf09c 100644 --- a/src/kernel/drivers/terminal/fbterm.c +++ b/src/kernel/drivers/terminal/fbterm.c @@ -60,4 +60,11 @@ void fbterm_init(struct fbinfo *fbinfo) flip(term_fb); term_fb = framebuffer_make_subcontext(&kernel_fb, 24, 24, 8*VGA_COLS, 16*VGA_ROWS); setup = 1; + + draw_line(&kernel_fb, 750, 850, 120, 120, RGB(255,0,0)); + draw_line(&kernel_fb, 750, 750, 120, 220, RGB(0,255,0)); + draw_line(&kernel_fb, 750, 850, 120, 220, RGB(0,0,255)); + draw_line(&kernel_fb, 750, 800, 120, 220, RGB(255,0,255)); + draw_line(&kernel_fb, 750, 850, 120, 170, RGB(255,255,0)); + flip(&kernel_fb); } \ No newline at end of file diff --git a/src/libmittos/graphics/framebuffer.c b/src/libmittos/graphics/graphics.c similarity index 63% rename from src/libmittos/graphics/framebuffer.c rename to src/libmittos/graphics/graphics.c index d501978..911a40f 100644 --- a/src/libmittos/graphics/framebuffer.c +++ b/src/libmittos/graphics/graphics.c @@ -17,6 +17,43 @@ void putpixel(gfx_context *ctx, uint64_t x, uint64_t y, uint32_t clr) *fb = clr; } +void draw_line(gfx_context *ctx, uint64_t x0, uint64_t x1, uint64_t y0, uint64_t y1, uint32_t clr) +{ + int64_t dx = x1 > x0 ? x1 - x0 : x0 - x1; + int64_t dy = y1 > y0 ? y1 - y0 : y0 - y1; + int sx = x1 > x0 ? 1 : -1; + int sy = y1 > y0 ? 1 : -1; + uint64_t x = x0, y = y0; + int64_t diff = dx - dy; + while(1) + { + putpixel(ctx, x, y, clr); + if(x == x1 && y == y1) break; + + if((2*diff) > -dy) { + diff -= dy; + x += sx; + } else { + diff += dx; + y += sy; + } + } +} + +void draw_rect(gfx_context *ctx, uint64_t x, uint64_t y, uint64_t width, uint64_t height, uint32_t clr) +{ + for(uint64_t _x = x; _x <= x+width; _x++) + { + putpixel(ctx, _x, y, clr); + putpixel(ctx, _x, y+height, clr); + } + for(uint64_t _y = y; _y <= y+height; _y++) + { + putpixel(ctx, x, _y, clr); + putpixel(ctx, x+width, _y, clr); + } +} + void putCharacter(gfx_context *ctx, uint64_t x, uint64_t y, uint32_t clr_fg, uint32_t clr_bg, char c) { diff --git a/src/libmittos/include/graphics.h b/src/libmittos/include/graphics.h index c6c2c88..7087874 100644 --- a/src/libmittos/include/graphics.h +++ b/src/libmittos/include/graphics.h @@ -14,6 +14,8 @@ typedef struct { #define RGB(r, g, b) (((uint32_t) (r<<16) + (g<<8) + (b))) void putpixel(gfx_context *ctx, uint64_t x, uint64_t y, uint32_t clr); +void draw_line(gfx_context *ctx, uint64_t x0, uint64_t x1, uint64_t y0, uint64_t y1, uint32_t clr); +void draw_rect(gfx_context *ctx, uint64_t x, uint64_t y, uint64_t width, uint64_t height, uint32_t clr); void putCharacter(gfx_context *ctx, uint64_t x, uint64_t y, uint32_t clr_fg, uint32_t clr_bg, char c); void flip(gfx_context *ctx); gfx_context *framebuffer_make_subcontext(gfx_context *ctx, uint64_t x, uint64_t y, uint64_t width, uint64_t height); \ No newline at end of file