9 extern uint8_t *mem_top
;
10 extern uint8_t *mem_bottom
;
11 extern uint8_t *mem_task
;
12 extern uint8_t *mem_sds
;
16 void task_register(void)
18 debug("free memory: %lu\n", mem_free());
20 if(mem_task
+sizeof(struct task
) > mem_sds
){
21 die("Out of memory... Not enough to allocate taskstruct");
24 struct task
*t
= (struct task
*)mem_task
;
27 t
->interval
= read16();
28 debug("interval: %d\n", t
->interval
);
31 if(is_interrupt_task(t
)) {
36 t
->tasklength
= read16();
37 debug("task interval: %d, length: %d\n", t
->interval
, t
->tasklength
);
39 if(mem_task
+t
->tasklength
> mem_sds
){
40 die("Out of memory... Not enough to allocate bytes");
43 mem_task
+= sizeof(struct task
);
45 mem_task
+= t
->tasklength
;
48 for(i
= 0; i
<t
->tasklength
; i
++){
49 t
->bc
[i
] = read_byte();
52 //Return the task number for later removal
53 debug("Received a task of length %d", t
->tasklength
);
60 debug("free memory: %lu\n", mem_free());
63 bool is_interrupt_task(struct task
*t
)
65 return t
->interval
& (2 <<14);
68 bool had_interrupt(struct task
* t
)
70 //Not implemented yet...
75 struct task
*task_head(void)
77 return mem_task
== mem_bottom
? NULL
: (struct task
*)mem_bottom
;
80 struct task
*task_next(struct task
*t
)
82 uint8_t *next
= (uint8_t *)t
+ sizeof(struct task
) + t
->tasklength
;
83 return next
>= mem_task
? NULL
: (struct task
*)next
;
86 void task_delete(uint8_t c
)
88 debug("Going to delete task: %i", c
);
89 debug("mem_task: %p", mem_task
);
90 struct task
*t
= task_head();
99 //We found the task, now we move everything from the end of the task up
100 //to the spacepointer right
101 uint8_t *start
= (uint8_t *)t
;
102 uint8_t *end
= start
+ sizeof(struct task
) + t
->tasklength
;
103 debug("Moving %lu bytes\n", mem_task
-end
);
104 for(int i
= 0; i
<mem_task
-end
; i
++){
108 //Decrement the spacepointer
109 mem_task
-= end
-start
;
111 debug("mem_task: %p", mem_task
);