Browse Source

Bg colour change, mandelbrot more efficient, looping function added

master
Stephen Downward 1 year ago
parent
commit
96b351f23b
3 changed files with 36 additions and 2 deletions
  1. +26
    -0
      cpu/timer.c
  2. +1
    -0
      cpu/timer.h
  3. +9
    -2
      kernel/kernel.c

+ 26
- 0
cpu/timer.c View File

@@ -2,17 +2,31 @@
#include "isr.h"
#include "ports.h"
#include "../libc/function.h"
#include "../util/terminal.h" //Debugging

u32 tick = 0;
u32 cl_freq = 0;
volatile u8 done = 0;
u32 countdown = 0;

void (*looped_funcs[255])();
u32 func_per[255]; //Function periods
u8 func_index = 0;

static void timer_callback(registers_t regs) {
tick++;
if (!done && countdown) countdown--;
if (countdown == 0) done = 1;
UNUSED(regs);

//Run the functions and whatever
for(int i = 0; i < func_index; i++)
{
if(tick % (cl_freq * func_per[i] / 1000) == 0)
{
looped_funcs[i]();
}
}
}

void init_timer(u32 freq) {
@@ -48,3 +62,15 @@ void delay(u32 ms) {
}
return;
}

u8 register_loop(void (*func)(), u32 per) //Period
{
if (cl_freq == 0) return 1;

looped_funcs[func_index] = func;
func_per[func_index] = per;

func_index++;

return 0;
}

+ 1
- 0
cpu/timer.h View File

@@ -5,5 +5,6 @@

void init_timer(u32 freq);
void delay(u32 ms);
u8 register_loop(void (*func)(), u32 per);

#endif

+ 9
- 2
kernel/kernel.c View File

@@ -11,13 +11,18 @@

void generate_fractal(u16 x, u16 y, u16 w, u16 h);

/*void loop()
{
println("loop just ran");
}*/

void main() {
isr_install();
irq_install();

setup_video();

set_background(0, 100, 100);
set_background(0, 0, 0);
clear_screen();

print_centered(SCN_WIDTH, 8, "_______ _________ _______ _______ _______ _______ ");
@@ -42,6 +47,8 @@ void main() {
print("> ");

register_commands();

/*register_loop(loop, 1000);*/ //Used when debugging loop
}

//Mandelbrot Generator
@@ -63,7 +70,7 @@ void generate_fractal(u16 x, u16 y, u16 w, u16 h) {
Zi = 2 * Zi * Zr + Ci;
Zr = Zrt;
if(Zr * Zr + Zi * Zi > 4 || Zr * Zr + Zi * Zi < -4) //Divergent
if(Zr * Zr + Zi * Zi > 4) //Divergent
{
Color_t p;
p.r = numIterations * 10;


Loading…
Cancel
Save