9 extern uint8_t *mem_top
, *mem_bottom
, *mem_task
, *mem_sds
;
13 void task_register(void)
15 debug("free memory: %lu\n", mem_free());
17 if(mem_task
+sizeof(struct task
) > mem_sds
){
18 die("Out of memory... Not enough to allocate taskstruct");
21 struct task
*t
= (struct task
*)mem_task
;
24 t
->interval
= read16();
25 debug("interval: %d\n", t
->interval
);
28 if(is_interrupt_task(t
)) {
33 t
->tasklength
= read16();
34 debug("task interval: %d, length: %d\n", t
->interval
, t
->tasklength
);
36 if(mem_task
+t
->tasklength
> mem_sds
){
37 die("Out of memory... Not enough to allocate bytes");
40 mem_task
+= sizeof(struct task
);
42 mem_task
+= t
->tasklength
;
45 for(i
= 0; i
<t
->tasklength
; i
++){
46 t
->bc
[i
] = read_byte();
49 //Return the task number for later removal
50 debug("Received a task of length %d", t
->tasklength
);
57 debug("free memory: %lu\n", mem_free());
60 bool is_interrupt_task(struct task
*t
)
62 return t
->interval
& (2 <<14);
65 bool had_interrupt(struct task
* t
)
67 //Not implemented yet...
72 struct task
*task_head(void)
74 return mem_task
== mem_bottom
? NULL
: (struct task
*)mem_bottom
;
77 struct task
*task_next(struct task
*t
)
79 uint8_t *next
= (uint8_t *)t
+ sizeof(struct task
) + t
->tasklength
;
80 return next
>= mem_task
? NULL
: (struct task
*)next
;
83 void task_delete(uint8_t c
)
85 debug("Going to delete task: %i", c
);
86 debug("mem_task: %p", mem_task
);
87 struct task
*t
= task_head();
96 //We found the task, now we move everything from the end of the task up
97 //to the spacepointer right
98 uint8_t *start
= (uint8_t *)t
;
99 uint8_t *end
= start
+ sizeof(struct task
) + t
->tasklength
;
100 debug("Moving %lu bytes\n", mem_task
-end
);
101 for(int i
= 0; i
<mem_task
-end
; i
++){
105 //Decrement the spacepointer
106 mem_task
-= end
-start
;
108 debug("mem_task: %p", mem_task
);