diff --git a/.vscode/settings.json b/.vscode/settings.json index 5a08ad4..9067971 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -12,9 +12,6 @@ "C_Cpp.default.includePath": ["src/kernel/include", "sysroot/usr/include"], "C_Cpp.default.cStandard": "c17", - "files.associations": { - "cpu.h": "c" - }, "[c]": { "editor.tabSize": 2, }, diff --git a/src/kernel/boot/TEMP-test_scheduler.c b/src/kernel/boot/TEMP-test_scheduler.c index 15d1606..4d9dacb 100644 --- a/src/kernel/boot/TEMP-test_scheduler.c +++ b/src/kernel/boot/TEMP-test_scheduler.c @@ -3,6 +3,7 @@ #include #include #include +#include extern gfx_context *term_fb; extern gfx_context kernel_fb; @@ -11,8 +12,10 @@ int *position = (void *)0x20000; void thread1() { int a = 1; + double prev = 0; gfx_context *ctx = framebuffer_make_subcontext(&kernel_fb, 700, 300, 100, 100); + __asm__("sti"); while(1) { putCharacter(term_fb, *position, *position, @@ -20,14 +23,19 @@ void thread1() { '0'+(a++%10) ); int s = (current_cpu->timer_ticks/1000)%10; + double cur = (double)(current_cpu->timer_ticks/100); putCharacter(term_fb, 0, 0, RGB(255,255,0), RGB(0,0,0), '0'+(s%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)); + + 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); sched_yield(); } @@ -35,7 +43,17 @@ void thread1() { void thread2() { int a = 0; + gfx_context *ctx = + framebuffer_make_subcontext(&kernel_fb, 800, 400, 100, 100); + __asm__("sti"); 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, *position, *position, RGB(0,255,255), RGB(0,0,0), diff --git a/src/kernel/boot/kmain.c b/src/kernel/boot/kmain.c index 11cdd37..74faf9e 100644 --- a/src/kernel/boot/kmain.c +++ b/src/kernel/boot/kmain.c @@ -41,8 +41,6 @@ void kmain(uint64_t multiboot_magic, void *multiboot_data) { cpu_init(); - __asm__("sti"); - debug_info("Boot complete\n"); @@ -50,6 +48,7 @@ void kmain(uint64_t multiboot_magic, void *multiboot_data) { irq_unmask(IRQ_PS2_KBD); TEMP_test_scheduler(); + __asm__("sti"); start_scheduler(); diff --git a/src/kernel/cpu/timer.c b/src/kernel/cpu/timer.c index 7f5fa31..b4b461d 100644 --- a/src/kernel/cpu/timer.c +++ b/src/kernel/cpu/timer.c @@ -69,6 +69,7 @@ volatile int ctr = 0; registers *apic_timer_handler(registers *r) { current_cpu->timer_ticks++; irq_ack(); + // k_sched_yield(); return r; } diff --git a/src/libmittos/graphics/graphics.c b/src/libmittos/graphics/graphics.c index fc43bcb..9c6f56a 100644 --- a/src/libmittos/graphics/graphics.c +++ b/src/libmittos/graphics/graphics.c @@ -27,25 +27,32 @@ void draw_line( uint64_t y0, uint64_t y1, uint32_t clr ) { + // https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm + int64_t dx = x1 > x0 ? x1 - x0 : x0 - x1; + int sx = x0 < x1 ? 1 : -1; 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; + dy = -dy; + int sy = y0 < y1 ? 1 : -1; + int64_t err = dx + dy; + uint32_t *fb = (uint32_t *)ctx->buffer; while(1) { - if(0 < x && x < ctx->width && - 0 < y && y < ctx->height) - fb[PXL(ctx, x, y)] = clr; - if(x == x1 && y == y1) break; + if(0 < x0 && x0 < ctx->width && + 0 < y0 && y0 < ctx->height) + fb[PXL(ctx, x0, y0)] = clr; + if(x0 == x1 && y0 == y1) break; - if((2*diff) > -dy) { - diff -= dy; - x += sx; - } else { - diff += dx; - y += sy; + int64_t e2 = 2*err; + if(e2 >= dy) { + if(x0 == x1) break; + err += dy; + x0 += sx; + } + if(e2 <= dx) { + if(y0 == y1) break; + err += dx; + y0 += sy; } } }