Some graphics tweaks

This commit is contained in:
Thomas Lovén 2022-02-09 14:22:00 +01:00
parent bb80297c1e
commit e1b917e4c2
5 changed files with 43 additions and 21 deletions

View File

@ -12,9 +12,6 @@
"C_Cpp.default.includePath": ["src/kernel/include", "sysroot/usr/include"], "C_Cpp.default.includePath": ["src/kernel/include", "sysroot/usr/include"],
"C_Cpp.default.cStandard": "c17", "C_Cpp.default.cStandard": "c17",
"files.associations": {
"cpu.h": "c"
},
"[c]": { "[c]": {
"editor.tabSize": 2, "editor.tabSize": 2,
}, },

View File

@ -3,6 +3,7 @@
#include <mittos/graphics.h> #include <mittos/graphics.h>
#include <memory.h> #include <memory.h>
#include <cpu.h> #include <cpu.h>
#include <math.h>
extern gfx_context *term_fb; extern gfx_context *term_fb;
extern gfx_context kernel_fb; extern gfx_context kernel_fb;
@ -11,8 +12,10 @@ int *position = (void *)0x20000;
void thread1() { void thread1() {
int a = 1; int a = 1;
double prev = 0;
gfx_context *ctx = gfx_context *ctx =
framebuffer_make_subcontext(&kernel_fb, 700, 300, 100, 100); framebuffer_make_subcontext(&kernel_fb, 700, 300, 100, 100);
__asm__("sti");
while(1) { while(1) {
putCharacter(term_fb, putCharacter(term_fb,
*position, *position, *position, *position,
@ -20,14 +23,19 @@ void thread1() {
'0'+(a++%10) '0'+(a++%10)
); );
int s = (current_cpu->timer_ticks/1000)%10; int s = (current_cpu->timer_ticks/1000)%10;
double cur = (double)(current_cpu->timer_ticks/100);
putCharacter(term_fb, putCharacter(term_fb,
0, 0, 0, 0,
RGB(255,255,0), RGB(0,0,0), RGB(255,255,0), RGB(0,0,0),
'0'+(s%10) '0'+(s%10)
); );
flip(term_fb); 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)); double angle = cur/3.14*2;
draw_line(ctx, 50, 50 + (int)(50*cos(prev)), 50, 50 + (int)(50*sin(prev)), RGB(0,0,0));
draw_line(ctx, 50, 50 + (int)(50*cos(angle)), 50, 50 + (int)(50*sin(angle)), RGB(255,0,0));
prev = angle;
flip(ctx); flip(ctx);
sched_yield(); sched_yield();
} }
@ -35,7 +43,17 @@ void thread1() {
void thread2() { void thread2() {
int a = 0; int a = 0;
gfx_context *ctx =
framebuffer_make_subcontext(&kernel_fb, 800, 400, 100, 100);
__asm__("sti");
while(1) { while(1) {
double pos = (double)(current_cpu->timer_ticks/100);
fill_rect(ctx, 0, 0, 100, 100, 0);
for(int i = 0; i < 10000; i++) {
putpixel(ctx, i/100, 50 + (int)(50.0*sin(pos + ((double)i)/1000.0)), RGB(0,0,255));
putpixel(ctx, i/100, 50 + (int)(50.0*cos(pos + ((double)i)/1000.0)), RGB(255,0,0));
}
flip(ctx);
putCharacter(term_fb, putCharacter(term_fb,
*position, *position, *position, *position,
RGB(0,255,255), RGB(0,0,0), RGB(0,255,255), RGB(0,0,0),

View File

@ -41,8 +41,6 @@ void kmain(uint64_t multiboot_magic, void *multiboot_data) {
cpu_init(); cpu_init();
__asm__("sti");
debug_info("Boot complete\n"); debug_info("Boot complete\n");
@ -50,6 +48,7 @@ void kmain(uint64_t multiboot_magic, void *multiboot_data) {
irq_unmask(IRQ_PS2_KBD); irq_unmask(IRQ_PS2_KBD);
TEMP_test_scheduler(); TEMP_test_scheduler();
__asm__("sti");
start_scheduler(); start_scheduler();

View File

@ -69,6 +69,7 @@ volatile int ctr = 0;
registers *apic_timer_handler(registers *r) { registers *apic_timer_handler(registers *r) {
current_cpu->timer_ticks++; current_cpu->timer_ticks++;
irq_ack(); irq_ack();
// k_sched_yield();
return r; return r;
} }

View File

@ -27,25 +27,32 @@ void draw_line(
uint64_t y0, uint64_t y1, uint64_t y0, uint64_t y1,
uint32_t clr uint32_t clr
) { ) {
// https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
int64_t dx = x1 > x0 ? x1 - x0 : x0 - x1; int64_t dx = x1 > x0 ? x1 - x0 : x0 - x1;
int sx = x0 < x1 ? 1 : -1;
int64_t dy = y1 > y0 ? y1 - y0 : y0 - y1; int64_t dy = y1 > y0 ? y1 - y0 : y0 - y1;
int sx = x1 > x0 ? 1 : -1; dy = -dy;
int sy = y1 > y0 ? 1 : -1; int sy = y0 < y1 ? 1 : -1;
uint64_t x = x0, y = y0; int64_t err = dx + dy;
int64_t diff = dx - dy;
uint32_t *fb = (uint32_t *)ctx->buffer; uint32_t *fb = (uint32_t *)ctx->buffer;
while(1) { while(1) {
if(0 < x && x < ctx->width && if(0 < x0 && x0 < ctx->width &&
0 < y && y < ctx->height) 0 < y0 && y0 < ctx->height)
fb[PXL(ctx, x, y)] = clr; fb[PXL(ctx, x0, y0)] = clr;
if(x == x1 && y == y1) break; if(x0 == x1 && y0 == y1) break;
if((2*diff) > -dy) { int64_t e2 = 2*err;
diff -= dy; if(e2 >= dy) {
x += sx; if(x0 == x1) break;
} else { err += dy;
diff += dx; x0 += sx;
y += sy; }
if(e2 <= dx) {
if(y0 == y1) break;
err += dx;
y0 += sy;
} }
} }
} }