.module kernel.c .area text 0000 _get_task_id:: 0000 ; //kernel.c 0000 ; 0000 ; #include "kernel.h" 0000 ; 0000 ; 0000 ; // GLOBAL VARIABLE DEFINITIONS 0000 ; unsigned int current; // current task id number 0000 ; unsigned long int system_tick; 0000 ; 0000 ; 0000 ; // task control block 0000 ; typedef struct task_block { 0000 ; unsigned char id; // ID of task 0000 ; enum task_state state; // State 0000 ; unsigned char priority; // Priority 0000 ; unsigned char *heap_ptr; // heap addr while not current task 0000 ; unsigned int heap_size; // heap size 0000 ; unsigned char *frame_ptr; // CCR pointer 0000 ; }; 0000 ; 0000 ; 0000 ; // resource control block 0000 ; typedef struct resource_block { 0000 ; unsigned char id; // ID of resource 0000 ; enum resource_state state; // State (busy, free...) 0000 ; unsigned char user; // Current resource user/owner 0000 ; signed char queue[4]; // Tasks waiting on resource 0000 ; unsigned char queue_pos; // Next free spot in queue 0000 ; }; 0000 ; 0000 ; 0000 ; struct task_block task[numtasks]; 0000 ; struct resource_block resource[numresources]; 0000 ; 0000 ; 0000 ; 0000 ; // FUNCTIONS 0000 ; 0000 ; unsigned char get_task_id() { 0000 ; return task[current].id; 0000 CC0009 ldd #9 0003 FD002F ldy _current 0006 13 emul 0007 C30010 addd #_task 000A B7C6 xgdy 000C E640 ldab 0,y 000E 87 clra 000F L1: 000F .dbline 0 ; func end 000F 3D rts 0010 ; id -> 3,x 0010 _get_task_state:: 0010 3B pshd 0011 34 pshx 0012 B775 tfr s,x 0014 ; } 0014 ; 0014 ; unsigned char get_task_state(unsigned char id) { 0014 ; return task[id].state; 0014 E603 ldab 3,x 0016 87 clra 0017 B7C6 xgdy 0019 CC0009 ldd #9 001C 1813 emuls 001E C30011 addd #_task+1 0021 B7C6 xgdy 0023 E640 ldab 0,y 0025 87 clra 0026 L2: 0026 B757 tfr x,s 0028 30 pulx 0029 1B82 leas 2,sp 002B .dbline 0 ; func end 002B 3D rts 002C ; id -> 3,x 002C _get_task_priority:: 002C 3B pshd 002D 34 pshx 002E B775 tfr s,x 0030 ; } 0030 ; 0030 ; unsigned char get_task_priority(unsigned char id) { 0030 ; return task[id].priority; 0030 E603 ldab 3,x 0032 87 clra 0033 B7C6 xgdy 0035 CC0009 ldd #9 0038 1813 emuls 003A C30012 addd #_task+2 003D B7C6 xgdy 003F E640 ldab 0,y 0041 87 clra 0042 L4: 0042 B757 tfr x,s 0044 30 pulx 0045 1B82 leas 2,sp 0047 .dbline 0 ; func end 0047 3D rts 0048 ; state -> 7,x 0048 ; id -> 3,x 0048 _set_task_state:: 0048 3B pshd 0049 34 pshx 004A B775 tfr s,x 004C ; } 004C ; 004C ; void set_task_state(unsigned char id, unsigned char state) { 004C ; task[id].state=state; 004C E603 ldab 3,x 004E 87 clra 004F B7C6 xgdy 0051 CC0009 ldd #9 0054 1813 emuls 0056 C30011 addd #_task+1 0059 B7C6 xgdy 005B E607 ldab 7,x 005D 6B40 stab 0,y 005F ; } 005F L6: 005F B757 tfr x,s 0061 30 pulx 0062 1B82 leas 2,sp 0064 .dbline 0 ; func end 0064 3D rts 0065 ; priority -> 7,x 0065 ; id -> 3,x 0065 _set_task_priority:: 0065 3B pshd 0066 34 pshx 0067 B775 tfr s,x 0069 ; 0069 ; void set_task_priority(unsigned char id, unsigned char priority) { 0069 ; 0069 ; if (priority == 0) priority = 1; 0069 E707 tst 7,x 006B 2604 bne L9 006D C601 ldab #1 006F 6B07 stab 7,x 0071 L9: 0071 ; task[id].priority=priority; 0071 E603 ldab 3,x 0073 87 clra 0074 B7C6 xgdy 0076 CC0009 ldd #9 0079 1813 emuls 007B C30012 addd #_task+2 007E B7C6 xgdy 0080 E607 ldab 7,x 0082 6B40 stab 0,y 0084 ; } 0084 L8: 0084 B757 tfr x,s 0086 30 pulx 0087 1B82 leas 2,sp 0089 .dbline 0 ; func end 0089 3D rts .area bss 0000 _resource:: 0000 .blkb 16 0010 _task:: 0010 .blkb 27 002B _system_tick:: 002B .blkb 4 002F _current:: 002F .blkb 2