Browse Source

Bg colour change, mandelbrot more efficient, looping function added

Stephen Downward 10 months 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

@ -2,17 +2,31 @@
2 2
#include "isr.h"
3 3
#include "ports.h"
4 4
#include "../libc/function.h"
5
#include "../util/terminal.h" //Debugging
5 6
6 7
u32 tick = 0;
7 8
u32 cl_freq = 0;
8 9
volatile u8 done = 0;
9 10
u32 countdown = 0;
10 11
12
void (*looped_funcs[255])();
13
u32 func_per[255]; //Function periods
14
u8 func_index = 0;
15
11 16
static void timer_callback(registers_t regs) {
12 17
	tick++;
13 18
	if (!done && countdown) countdown--;
14 19
	if (countdown == 0) done = 1;
15 20
	UNUSED(regs);
21
22
	//Run the functions and whatever
23
	for(int i = 0; i < func_index; i++)
24
	{
25
		if(tick % (cl_freq * func_per[i] / 1000) == 0)
26
		{
27
			looped_funcs[i]();
28
		}
29
	}
16 30
}
17 31
18 32
void init_timer(u32 freq) {
@ -48,3 +62,15 @@ void delay(u32 ms) {
48 62
	}
49 63
	return;
50 64
}
65
66
u8 register_loop(void (*func)(), u32 per) //Period
67
{
68
	if (cl_freq == 0) return 1;
69
70
	looped_funcs[func_index] = func;
71
	func_per[func_index] = per;
72
73
	func_index++;
74
75
	return 0;
76
}

+ 1 - 0
cpu/timer.h

@ -5,5 +5,6 @@
5 5
6 6
void init_timer(u32 freq);
7 7
void delay(u32 ms);
8
u8 register_loop(void (*func)(), u32 per);
8 9
9 10
#endif

+ 9 - 2
kernel/kernel.c

@ -11,13 +11,18 @@
11 11
12 12
void generate_fractal(u16 x, u16 y, u16 w, u16 h);
13 13
14
/*void loop()
15
{
16
	println("loop just ran");
17
	}*/
18
14 19
void main() {
15 20
	isr_install();
16 21
	irq_install();
17 22
18 23
	setup_video();
19 24
20
	set_background(0, 100, 100);
25
	set_background(0, 0, 0);
21 26
	clear_screen();
22 27
23 28
	print_centered(SCN_WIDTH, 8, "_______ _________ _______           _______  _______  _______ ");
@ -42,6 +47,8 @@ void main() {
42 47
	print("> ");
43 48
44 49
	register_commands();
50
51
	/*register_loop(loop, 1000);*/ //Used when debugging loop
45 52
}
46 53
47 54
//Mandelbrot Generator
@ -63,7 +70,7 @@ void generate_fractal(u16 x, u16 y, u16 w, u16 h) {
63 70
				Zi = 2 * Zi * Zr + Ci;
64 71
				Zr = Zrt;
65 72
				
66
				if(Zr * Zr + Zi * Zi > 4 || Zr * Zr + Zi * Zi < -4) //Divergent
73
				if(Zr * Zr + Zi * Zi > 4) //Divergent
67 74
				{
68 75
					Color_t p;
69 76
					p.r = numIterations * 10;