.module kernel.c .area data 0200 _main_frame_ptr:: 0200 .blkb 2 .area idata --- 0000 0000 .word 0 .area data 0202 _main_frame_x_ptr:: 0202 .blkb 2 .area idata --- 0002 0000 .word 0 .area data 0204 _temp_task_frame_ptr:: 0204 .blkb 2 .area idata --- 0004 0000 .word 0 .area data 0206 _kdb_trace:: 0206 .blkb 2 .area idata --- 0006 0001 .word 1 .area data 0208 _kdb_trace_cycle:: 0208 .blkb 2 .area idata --- 0008 0000 .word 0 .area data .area text 102A _error_msg:: 102A 756E696D706C696D656E746564206675 .byte 'u,'n,'i,'m,'p,'l,'i,'m,'e,'n,'t,'e,'d,32,'f,'u 103A 6E6374696F6E00 .byte 'n,'c,'t,'i,'o,'n,0 1041 0000 .byte 0,0 1043 73796E746178206572726F7200 .byte 's,'y,'n,'t,'a,'x,32,'e,'r,'r,'o,'r,0 1050 00000000000000000000 .word 0,0,0,0,0 105A 0000 .byte 0,0 105C 696C6C6567616C207461736B20494400 .byte 'i,'l,'l,'e,'g,'a,'l,32,'t,'a,'s,'k,32,'I,'D,0 106C 000000000000000000 .byte 0,0,0,0,0,0,0,0,0 1075 696C6C6567616C207461736B20737461 .byte 'i,'l,'l,'e,'g,'a,'l,32,'t,'a,'s,'k,32,'s,'t,'a 1085 746500 .byte 't,'e,0 1088 000000000000 .byte 0,0,0,0,0,0 108E 696C6C6567616C207461736B20707269 .byte 'i,'l,'l,'e,'g,'a,'l,32,'t,'a,'s,'k,32,'p,'r,'i 109E 6F7269747900 .byte 'o,'r,'i,'t,'y,0 10A4 000000 .byte 0,0,0 10A7 6F7574206F66206D656D6F727900 .byte 'o,'u,'t,32,'o,'f,32,'m,'e,'m,'o,'r,'y,0 10B5 00000000000000000000 .word 0,0,0,0,0 10BF 00 .byte 0 10C0 696C6C6567616C207265736F75726365 .byte 'i,'l,'l,'e,'g,'a,'l,32,'r,'e,'s,'o,'u,'r,'c,'e 10D0 20494400 .byte 32,'I,'D,0 10D4 0000000000 .byte 0,0,0,0,0 10D9 696C6C6567616C207265736F75726365 .byte 'i,'l,'l,'e,'g,'a,'l,32,'r,'e,'s,'o,'u,'r,'c,'e 10E9 20737461746500 .byte 32,'s,'t,'a,'t,'e,0 10F0 0000 .byte 0,0 10F2 63616E6E6F7420637265617465207461 .byte 'c,'a,'n,'n,'o,'t,32,'c,'r,'e,'a,'t,'e,32,'t,'a 1102 736B00 .byte 's,'k,0 1105 000000000000 .byte 0,0,0,0,0,0 110B _error_src:: 110B 6B65726E656C206572726F723A00 .byte 'k,'e,'r,'n,'e,'l,32,'e,'r,'r,'o,'r,58,0 1119 00000000 .byte 0,0,0,0 111D 6B65726E656C2E63206572726F723A00 .byte 'k,'e,'r,'n,'e,'l,46,'c,32,'e,'r,'r,'o,'r,58,0 112D 0000 .byte 0,0 112F 6B65726E656C20525449206572726F72 .byte 'k,'e,'r,'n,'e,'l,32,'R,'T,'I,32,'e,'r,'r,'o,'r 113F 3A00 .byte 58,0 1141 7368656C6C206572726F723A00 .byte 's,'h,'e,'l,'l,32,'e,'r,'r,'o,'r,58,0 114E 0000000000 .byte 0,0,0,0,0 1153 73656D6C69622E63206572726F723A00 .byte 's,'e,'m,'l,'i,'b,46,'c,32,'e,'r,'r,'o,'r,58,0 1163 0000 .byte 0,0 1165 ; lreg1 -> -4,x 1165 ; lreg2 -> -8,x 1165 ; ?temp -> -19,x 1165 ; ?temp -> -19,x 1165 ; ?temp -> -19,x 1165 ; ?temp -> -21,x 1165 ; ?temp -> -19,x 1165 ; id -> -17,x 1165 ; result -> -15,x 1165 ; priority_check -> -13,x 1165 ; deadline -> -12,x 1165 ; i -> -10,x 1165 _main:: 1165 34 pshx 1166 B775 tfr s,x 1168 1BF1EA leas -22,sp 116B ; /* RLPOS: RLPotter Operating System 116B ; 116B ; Version 0.7.1 for the 68HC12D60A microcontroller 116B ; by Ryan Potter 116B ; ryan@rlpotter.com 116B ; 116B ; Compiled with the ImageCraft ICC12 compiler v6.15A 116B ; - 912D60 Single Chip Mode 116B ; - printf option: long 116B ; 116B ; 116B ; v0.7.1 April 27, 2003: 116B ; - implemented the TOF_handler interrupt for use with sysTime. 116B ; brings time resolution from 64 ms to 16 ms. 116B ; - added kernel funct: get_sysTime(), set_sysTime(); shell cmd: time. 116B ; - now tasks are 'int f()', and must return a value to the kernel 116B ; when exiting. kernel doesn't handle it yet, though. 116B ; - in shell, now names of tasks are shell commands (dynamic). 116B ; - put all kernel initialization code into kernel_init(). 116B ; - added kernel funct: remove_task(). 116B ; 116B ; 116B ; v0.7 April 25, 2003: 11174 bytes: 116B ; - combined kernel.c & semlib.c with rlpos.c to make one big kernel.c. 116B ; - changed context switch mechanism to give each task a dedicated 116B ; stack, making the kernel context switches >400% faster. 116B ; - added a basic timer task that will eventually keep system time/date. 116B ; 116B ; v0.6 April 24, 2003: 11042 bytes 116B ; - made the task block and the task control block dynamic, so that 116B ; now tasks can create tasks, and can also start/stop them. 116B ; - implemented the sysInit() task for kicking off a user system. 116B ; - implemented a kernel debug command for tracing code execution. 116B ; - implemented small msg box system in kernel for tasks. 116B ; - implemented COP watchdog reset timer. 116B ; - added system resources to semlib. 116B ; - added skeleton ISR_handler() code for the other interrupts. 116B ; - implemented _HC12Setup.c to initialize/harden the system. 116B ; 116B ; v0.5 April 16, 2003: 116B ; - added priority preemption. 116B ; - finished kernel task state switcher. 116B ; - it is now officially a legitimate 116B ; rate monotonic 116B ; priority preemptive 116B ; multitasking 116B ; Real Time Operating System :) 116B ; - made kernel.c and semlib.c consistent with the 116B ; rest of the kernel. 116B ; - included the early framework for a msg box system. 116B ; 116B ; v0.4 April 13, 2003: 8096 bytes 116B ; - gerneralized the shell command-line input parser: 116B ; cmd (up to 32 chars). 116B ; - added kernel and shell functions. 116B ; 116B ; v0.3 April 12, 2003: 6155 bytes 116B ; - added a beginning shell user interface. 116B ; - added a resource control block and basic semaphore functions. 116B ; - added basic kernel functions. 116B ; 116B ; v0.2 April 9, 2003: 116B ; - able to round-robin with RTI interrupt. 116B ; - bonified/certified multitasking with 3 tasks. :) 116B ; 116B ; v0.1 April 3, 2003: 116B ; - able to round-robin without interrupts. 116B ; - not multitasking, really. 116B ; 116B ; v0.0 started April 1, 2003; 0 bytes 116B ; - no idea where to start. 116B ; - don't want to look at anyone else's work. ;0) 116B ; 116B ; 116B ; 116B ; 116B ; Architecture/C assumptions: 116B ; 1) 'D' register is the accumulator 116B ; 2) 'X' register points to the top of the current stack 116B ; 3) 'Y' register is for general use in indexed operations 116B ; 4) the heap grows upward and mem segments allocated by malloc, 116B ; realloc, and calloc are linear and contiguous. 116B ; 5) the stack grows downwards, and there is no boundary checking. 116B ; 6) chars are one byte 116B ; ints are two bytes 116B ; longs are 4 bytes 116B ; 7) only 1536 (1.5k) of the 2k ram are available 116B ; 8) register base is 0x0000 116B ; 116B ; Potential problem areas: 116B ; 1) 'running' section of the kernel get's compiled using extra 116B ; push and pop instructions 116B ; 2) run out of ram (global + stack + heap) 116B ; 116B ; */ 116B ; 116B ; 116B ; 116B ; #include <912d60.h> 116B ; #include 116B ; #include 116B ; #include 116B ; #include "kernel.h" 116B ; 116B ; 116B ; 116B ; // FUNCTION PROTOTYPES 116B ; void RTI_handler(void); 116B ; int sysInit(void); 116B ; int shell(void); 116B ; int idleTask(void); 116B ; int sysTime(void); 116B ; int (*task_ptr[MAXTASKS])(void); 116B ; 116B ; 116B ; 116B ; 116B ; // GLOBAL VARIABLES 116B ; unsigned char *main_frame_ptr = NULL; // bottom of main() frame 116B ; unsigned char *main_frame_x_ptr = NULL; // top of main() frame (x-reg ptr) 116B ; unsigned char *temp_task_frame_ptr = NULL; // temp CCR pointer for RTI 116B ; 116B ; 116B ; unsigned int current; // current task id number 116B ; unsigned long int system_tick; 116B ; unsigned int cop_cycle; 116B ; 116B ; unsigned long int time_tick; // one tick every x microseconds 116B ; 116B ; 116B ; // task control block 116B ; typedef struct task_block { 116B ; int (*address)(); // Address of the task 116B ; unsigned char id; // ID of task 116B ; char name[9]; // Name 116B ; enum task_state state; // State 116B ; unsigned char priority; // Priority 116B ; unsigned long int period_tick; // for determining if deadline is up 116B ; unsigned int interrupt_msg_box; // flags for pending interrupts 116B ; enum message_box message; // misc flags 116B ; unsigned char message_data[2]; // data for misc_msg_box flags 116B ; unsigned int stack_size; // heap allocated for task stack 116B ; unsigned char *top_of_stack; // top of task stack in the heap 116B ; unsigned char *frame_ptr; // CCR pointer in idle stack 116B ; }; 116B ; 116B ; 116B ; // resource control block 116B ; typedef struct resource_block { 116B ; unsigned char id; // ID of resource 116B ; char name[5]; // Name of resource 116B ; enum resource_state state; // State (busy, free...) 116B ; unsigned char owner; // Current resource owner 116B ; signed char queue[3]; // Tasks waiting on resource 116B ; unsigned char queue_ptr; // Next free spot in queue 116B ; }; 116B ; 116B ; 116B ; struct task_block *task[MAXTASKS]; 116B ; struct resource_block resource[NUMRESOURCES]; 116B ; 116B ; 116B ; int kdb_trace = 1; 116B ; int kdb_trace_cycle = 0; 116B ; 116B ; 116B ; struct time { 116B ; char hours; 116B ; char minutes; 116B ; char seconds; 116B ; int milliseconds; 116B ; }; 116B ; 116B ; int exit_status; 116B ; 116B ; 116B ; 116B ; // global interrupt flags 116B ; //unsigned int interrupt_flags_ADC; 116B ; //unsigned int interrupt_flags_TC; 116B ; 116B ; 116B ; 116B ; 116B ; // error massages 116B ; const char error_msg[][25] = {"unimplimented function", // error 0 116B ; "syntax error", // error 1 116B ; "illegal task ID", // error 2 116B ; "illegal task state", // error 3 116B ; "illegal task priority", // error 4 116B ; "out of memory", // error 5 116B ; "illegal resource ID", // error 6 116B ; "illegal resource state", // error 7 116B ; "cannot create task" // error 8 116B ; }; 116B ; const char error_src[][18] = {"kernel error:", // source 0 116B ; "kernel.c error:", // source 1 116B ; "kernel RTI error:", // source 2 116B ; "shell error:", // source 3 116B ; "semlib.c error:" // source 4 116B ; }; 116B ; 116B ; 116B ; 116B ; 116B ; 116B ; main() { 116B ; 116B ; // LOCAL VARIABLES 116B ; int result, id, i; 116B ; unsigned char priority_check; 116B ; unsigned int deadline; 116B ; 116B ; 116B ; 116B ; // INITIALIZE the kernel 116B ; kernel_init(); 116B 16143F jsr _kernel_init 116E ; 116E ; 116E ; // save SP value for use in the RTI 116E ; asm("TFR s,d"); 116E B774 TFR s,d 1170 1170 ; asm("STD _main_frame_ptr"); 1170 7C0200 STD _main_frame_ptr 1173 1173 ; // save X reg value for use in the RTI 1173 ; asm("TFR x,d"); 1173 B754 TFR x,d 1175 1175 ; asm("STD _main_frame_x_ptr"); 1175 7C0202 STD _main_frame_x_ptr 1178 1178 1820022A lbra L5 117C L4: 117C ; 117C ; 117C ; 117C ; // MULTITASKING KERNEL: Priority Preemptive, Real Time, multitasking 117C ; // KDB_TRACE Section 2 117C ; while(1) { 117C ; 117C ; //------------------------------- 117C ; /* REENTRY POINT after either 117C ; 1) task finishes, or 117C ; 2) RTI 117C ; */ 117C ; //------------------------------- 117C ; 117C ; 117C ; if (kdb_trace_cycle >= KDB_CYCLES) 117C FC0208 ldd _kdb_trace_cycle 117F 8C0004 cpd #4 1182 2D06 blt L7 1184 ; kdb_trace = 0; 1184 CC0000 ldd #0 1187 7C0206 std _kdb_trace 118A L7: 118A ; 118A ; #ifdef KDB_TRACE_LEVEL_1 118A ; if (kdb_trace) puts("kDB2.1"); 118A ; #endif 118A ; 118A ; 118A ; /* No RTI interrupts allowed inside of main(). Only allowed 118A ; inside of non-critical sections of tasks */ 118A ; //INTR_OFF(); 118A ; 118A ; 118A ; // PET THE DOG: cop watchdog reset timer (pet freq = 2x COP freq) 118A ; if (cop_cycle == 4) { 118A FC0258 ldd _cop_cycle 118D 8C0004 cpd #4 1190 2610 bne L9 1192 ; COP_PET(0x55); 1192 C655 ldab #85 1194 7B0017 stab 0x17 1197 ; COP_PET(0xAA); 1197 C6AA ldab #170 1199 7B0017 stab 0x17 119C ; cop_cycle = 0; 119C CC0000 ldd #0 119F 7C0258 std _cop_cycle 11A2 ; //putchar(':'); 11A2 ; } 11A2 L9: 11A2 CC0000 ldd #0 11A5 6C16 std -10,x 11A7 L11: 11A7 ; #ifdef KDB_TRACE_LEVEL_1 11A7 ; if (kdb_trace) puts("kDB2.2-1"); 11A7 ; #endif 11A7 ; 11A7 ; 11A7 ; 11A7 ; // CHANGE STATES ACCORDING TO MESSAGES 11A7 ; // 'waiting' needs to have highest precedence here 11A7 ; for (i=0; imessage && STATE_FLAG) { 11B5 EC16 ldd -10,x 11B7 59 lsld 11B8 C30244 addd #_task 11BB B7C6 xgdy 11BD ED40 ldy 0,y 11BF E7E814 tst 20,y 11C2 2732 beq L17 11C4 ; // set task state to what the message says 11C4 ; task[i]->state = task[i]->message_data[STATE_BOX]; 11C4 EC16 ldd -10,x 11C6 59 lsld 11C7 C30244 addd #_task 11CA B7C6 xgdy 11CC ED40 ldy 0,y 11CE 6DE1ED sty -19,x 11D1 EDE1ED ldy -19,x 11D4 E6E815 ldab 21,y 11D7 EDE1ED ldy -19,x 11DA 6B4C stab 12,y 11DC ; // clear the STATE_FLAG 11DC ; task[i]->message &= ~(STATE_FLAG); 11DC EC16 ldd -10,x 11DE 59 lsld 11DF C30244 addd #_task 11E2 B7C6 xgdy 11E4 EC40 ldd 0,y 11E6 C30014 addd #20 11E9 6CE1EB std -21,x 11EC B746 tfr d,y 11EE 35 pshy ; spill 11EF EDE1EB ldy -21,x 11F2 31 puly ; reload 11F3 0D4001 bclr 0,y,#0x1 11F6 ; #ifdef KDB_TRACE_LEVEL_2 11F6 ; if (kdb_trace) puts("kDB2.3-2a"); 11F6 ; #endif 11F6 ; } 11F6 L17: 11F6 L12: 11F6 EC16 ldd -10,x 11F8 C30001 addd #1 11FB 6C16 std -10,x 11FD EC16 ldd -10,x 11FF 8C0008 cpd #8 1202 2DA3 blt L11 1204 CC0000 ldd #0 1207 6C16 std -10,x 1209 L19: 1209 ; #ifdef KDB_TRACE_LEVEL_2 1209 ; if (kdb_trace) puts("kDB2.3-2b"); 1209 ; #endif 1209 ; } 1209 ; #ifdef KDB_TRACE_LEVEL_1 1209 ; if (kdb_trace) puts("kDB2.3-1"); 1209 ; #endif 1209 ; 1209 ; 1209 ; 1209 ; // RT PRIORITY BLOCK: 1209 ; // set the current task id based on priority and deadline 1209 ; 1209 ; // determine if the deadline is up for idle tasks 1209 ; /* deadline, is equal to period plus an initial time (t0) reference 1209 ; (t0 = system_tick). Period = priority + 1. 1209 ; Changing the state from idle to PENDING occurs here. */ 1209 ; for (i=0; istate == IDLE) { 1209 EC16 ldd -10,x 120B 59 lsld 120C C30244 addd #_task 120F B7C6 xgdy 1211 ED40 ldy 0,y 1213 E74C tst 12,y 1215 2655 bne L23 1217 ; deadline = task[i]->period_tick + (task[i]->priority + 1); 1217 EC16 ldd -10,x 1219 59 lsld 121A C30244 addd #_task 121D B7C6 xgdy 121F ED40 ldy 0,y 1221 6DE1ED sty -19,x 1224 EDE1ED ldy -19,x 1227 E64D ldab 13,y 1229 87 clra 122A C30001 addd #1 122D 163861 jsr __d2lreg2 1230 EDE1ED ldy -19,x 1233 194E leay 14,y 1235 1802401C movw 0,y,-4,x 1239 1802421E movw 2,y,-2,x 123D 1638A9 jsr __ladd 1240 16387C jsr __lreg2d 1243 6C14 std -12,x 1245 ; if (system_tick >= deadline) { 1245 CD025A ldy #_system_tick 1248 1802401C movw 0,y,-4,x 124C 1802421E movw 2,y,-2,x 1250 EC14 ldd -12,x 1252 6C1A std -6,x 1254 1800180000 movw #0,-8,x 1259 163A4A jsr __lcmp 125C 250E blo L25 125E ; task[i]->state = PENDING; // change state at deadline 125E EC16 ldd -10,x 1260 59 lsld 1261 C30244 addd #_task 1264 B7C6 xgdy 1266 ED40 ldy 0,y 1268 C601 ldab #1 126A 6B4C stab 12,y 126C ; #ifdef KDB_TRACE_LEVEL_2 126C ; if (kdb_trace) puts("kDB2.4-2"); 126C ; #endif 126C ; } 126C L25: 126C ; } 126C L23: 126C L20: 126C EC16 ldd -10,x 126E C30001 addd #1 1271 6C16 std -10,x 1273 EC16 ldd -10,x 1275 8C0008 cpd #8 1278 2D8F blt L19 127A ; // if (task[i]->message) {} ??? 127A ; } 127A ; #ifdef KDB_TRACE_LEVEL_1 127A ; if (kdb_trace) puts("kDB2.4-1"); 127A ; #endif 127A ; 127A ; 127A ; // set current = to highest priority pending/running task. 127A ; priority_check = 255; // lowest possible 127A C6FF ldab #255 127C 6B13 stab -13,x 127E CC0000 ldd #0 1281 6C16 std -10,x 1283 L27: 1283 ; 1283 ; for (i=0; istate == PENDING) || (task[i]->state == RUNNING)) { 12AC ; if (task[i]->priority <= priority_check) { 12AC EC16 ldd -10,x 12AE 59 lsld 12AF C30244 addd #_task 12B2 B7C6 xgdy 12B4 ED40 ldy 0,y 12B6 E64D ldab 13,y 12B8 E113 cmpb -13,x 12BA 2213 bhi L36 12BC ; current = i; 12BC EC16 ldd -10,x 12BE 7C025E std _current 12C1 ; priority_check = task[i]->priority; 12C1 EC16 ldd -10,x 12C3 59 lsld 12C4 C30244 addd #_task 12C7 B7C6 xgdy 12C9 ED40 ldy 0,y 12CB E64D ldab 13,y 12CD 6B13 stab -13,x 12CF ; #ifdef KDB_TRACE_LEVEL_2 12CF ; if (kdb_trace) puts("kDB2.5-2"); 12CF ; #endif 12CF ; } 12CF L36: 12CF ; } 12CF L33: 12CF ; } 12CF L31: 12CF L28: 12CF EC16 ldd -10,x 12D1 C30001 addd #1 12D4 6C16 std -10,x 12D6 EC16 ldd -10,x 12D8 8C0008 cpd #8 12DB 2DA6 blt L27 12DD FC025E ldd _current 12E0 59 lsld 12E1 C30244 addd #_task 12E4 B7C6 xgdy 12E6 ED40 ldy 0,y 12E8 E64C ldab 12,y 12EA 87 clra 12EB 6CE1ED std -19,x 12EE 182700B4 lbeq L39 12F2 ECE1ED ldd -19,x 12F5 8C0001 cpd #1 12F8 2722 beq L42 12FA ECE1ED ldd -19,x 12FD 8C0002 cpd #2 1300 1827007F lbeq L43 1304 ECE1ED ldd -19,x 1307 8C0003 cpd #3 130A 18270098 lbeq L39 130E ECE1ED ldd -19,x 1311 8C0004 cpd #4 1314 1827008E lbeq L39 1318 1820007E lbra L38 131C X0: 131C ; } 131C ; #ifdef KDB_TRACE_LEVEL_1 131C ; if (kdb_trace) puts("kDB2.5-1"); 131C ; #endif 131C ; 131C ; 131C ; 131C ; // DISPATCH, or otherwise deal with the current task 131C ; // KDB_TRACE Section 3 131C ; 131C ; #ifdef KDB_TRACE_LEVEL_2 131C ; if (kdb_trace) { 131C ; printf("task[%d]->state = %d\n", current, task[current]->state); 131C ; printf("task[%d]->prior = %d\n", current, task[current]->priority); 131C ; } 131C ; #endif 131C ; 131C ; switch (task[current]->state) { 131C ; case IDLE: // skip task 131C ; #ifdef KDB_TRACE_LEVEL_1 131C ; if (kdb_trace) puts("kDB3.1-1"); 131C ; #endif 131C ; break; 131C L42: 131C ; case PENDING: // ready and waiting to run 131C ; #ifdef KDB_TRACE_LEVEL_1 131C ; if (kdb_trace) puts("kDB3.2-1"); 131C ; #endif 131C ; #ifdef KDB_TRACE_LEVEL_2 131C ; if (kdb_trace) { 131C ; //puts("kDB3.2-2"); 131C ; putchar('S'); 131C ; putchar(current+48); 131C ; putchar('\n'); 131C ; } 131C ; #endif 131C ; task[current]->state = RUNNING; 131C FC025E ldd _current 131F 59 lsld 1320 C30244 addd #_task 1323 B7C6 xgdy 1325 ED40 ldy 0,y 1327 C602 ldab #2 1329 6B4C stab 12,y 132B ; task[current]->period_tick = system_tick; 132B FC025E ldd _current 132E 59 lsld 132F C30244 addd #_task 1332 B7C6 xgdy 1334 ED40 ldy 0,y 1336 194E leay 14,y 1338 35 pshy ; spill 1339 CD025A ldy #_system_tick 133C 1802401C movw 0,y,-4,x 1340 1802421E movw 2,y,-2,x 1344 31 puly ; reload 1345 18021C40 movw -4,x,0,y 1349 18021E42 movw -2,x,2,y 134D ; temp_task_frame_ptr = task[current]->top_of_stack; 134D FC025E ldd _current 1350 59 lsld 1351 C30244 addd #_task 1354 B7C6 xgdy 1356 ED40 ldy 0,y 1358 EDE819 ldy 25,y 135B 7D0204 sty _temp_task_frame_ptr 135E ; asm("LDS _temp_task_frame_ptr"); // set the SP 135E FF0204 LDS _temp_task_frame_ptr 1361 1361 ; exit_status = (*task_ptr[current])(); // start the task 1361 FC025E ldd _current 1364 59 lsld 1365 C30260 addd #_task_ptr 1368 B7C6 xgdy 136A ED40 ldy 0,y 136C 1540 jsr 0,y 136E 7C0212 std _exit_status 1371 ; asm("LDS _main_frame_ptr"); // reset the SP 1371 FF0200 LDS _main_frame_ptr 1374 1374 ; task[current]->state = IDLE; // task finished 1374 FC025E ldd _current 1377 59 lsld 1378 C30244 addd #_task 137B B7C6 xgdy 137D ED40 ldy 0,y 137F 694C clr 12,y 1381 ; #ifdef KDB_TRACE_LEVEL_1 1381 ; if (kdb_trace) puts("kDB3.3-1"); 1381 ; #endif 1381 ; #ifdef KDB_TRACE_LEVEL_2 1381 ; if (kdb_trace) { 1381 ; //puts("kDB3.3-2"); 1381 ; putchar('F'); 1381 ; putchar(current+48); 1381 ; putchar('\n'); 1381 ; } 1381 ; #endif 1381 ; break; 1381 2023 bra L39 1383 L43: 1383 ; case RUNNING: // interrupted. continue running. 1383 ; // restore context and run 1383 ; temp_task_frame_ptr = task[current]->frame_ptr; 1383 FC025E ldd _current 1386 59 lsld 1387 C30244 addd #_task 138A B7C6 xgdy 138C ED40 ldy 0,y 138E EDE81B ldy 27,y 1391 7D0204 sty _temp_task_frame_ptr 1394 ; asm("LDS _temp_task_frame_ptr"); 1394 FF0204 LDS _temp_task_frame_ptr 1397 1397 ; asm("RTI"); 1397 0B RTI 1398 1398 ; break; 1398 200C bra L39 139A X1: 139A ; case WAITING: // waiting on a resource 139A ; #ifdef KDB_TRACE_LEVEL_1 139A ; if (kdb_trace) puts("kDB3.5-1"); 139A ; #endif 139A ; break; 139A ; case STOPPED: // done running until later 139A ; #ifdef KDB_TRACE_LEVEL_1 139A ; if (kdb_trace) puts("kDB3.6-1"); 139A ; #endif 139A ; break; 139A L38: 139A ; default: // shouldn't happen, but, error if so. 139A ; puts("KERNEL: task state error\n"); 139A CC1CE0 ldd #L46 139D 163AE3 jsr _puts 13A0 ; exit(1); 13A0 CC0001 ldd #1 13A3 161028 jsr _exit 13A6 ; } // end switch 13A6 L39: 13A6 L5: 13A6 1820FDD2 lbra L4 13AA X2: 13AA ; 13AA ; 13AA ; 13AA ; // exit_status HANDLER 13AA ; //... 13AA ; 13AA ; 13AA ; 13AA ; } // end while(1) 13AA ; 13AA ; return 0; 13AA CC0000 ldd #0 13AD L3: 13AD B757 tfr x,s 13AF 30 pulx 13B0 .dbline 0 ; func end 13B0 3D rts 13B1 ; lreg1 -> -4,x 13B1 ; lreg2 -> -8,x 13B1 ; local_thp -> -14,x 13B1 ; i -> -12,x 13B1 ; frame_size -> -10,x 13B1 _RTI_handler:: 13B1 34 pshx 13B2 B775 tfr s,x 13B4 1B92 leas -14,sp 13B6 ; 13B6 ; } // end main() 13B6 ; 13B6 ; 13B6 ; 13B6 ; #pragma interrupt_handler RTI_handler() 13B6 ; 13B6 ; void RTI_handler(void) { 13B6 ; 13B6 ; size_t frame_size; 13B6 ; unsigned int i; 13B6 ; unsigned char *local_thp; 13B6 ; 13B6 ; 13B6 ; 13B6 ; //ACKNOWLEDGE THE INTERRUPT 13B6 ; RTIFLG = 0x0080; // acknowledge/clear the interrupt 13B6 C680 ldab #128 13B8 7B0015 stab 0x15 13BB ; 13BB ; 13BB ; #ifdef KDB_TRACE_LEVEL_1 13BB ; if (kdb_trace) putchar('.'); 13BB ; #endif 13BB ; //putchar('.'); 13BB ; 13BB ; 13BB ; // SET THE FRAME POINTER for the interupted task. 13BB ; // should point to the CCR entry on the stack. 13BB ; asm("TFR x,d"); // start of RTI stack 13BB B754 TFR x,d 13BD 13BD ; asm("ADDD #2"); // adjust to CCR stack entry 13BD C30002 ADDD #2 13C0 13C0 ; asm("STD _temp_task_frame_ptr"); // put into task_frame_ptr 13C0 7C0204 STD _temp_task_frame_ptr 13C3 13C3 ; task[current]->frame_ptr = temp_task_frame_ptr; 13C3 FC025E ldd _current 13C6 59 lsld 13C7 C30244 addd #_task 13CA B7C6 xgdy 13CC ED40 ldy 0,y 13CE FC0204 ldd _temp_task_frame_ptr 13D1 6CE81B std 27,y 13D4 ; 13D4 ; 13D4 ; 13D4 ; // update system time base and cop reset counter 13D4 ; system_tick++; 13D4 CD025A ldy #_system_tick 13D7 1802401C movw 0,y,-4,x 13DB 1802421E movw 2,y,-2,x 13DF CD1CDC ldy #L48 13E2 18024018 movw 0,y,-8,x 13E6 1802421A movw 2,y,-6,x 13EA 1638A9 jsr __ladd 13ED CD025A ldy #_system_tick 13F0 18021C40 movw -4,x,0,y 13F4 18021E42 movw -2,x,2,y 13F8 ; cop_cycle++; 13F8 FC0258 ldd _cop_cycle 13FB C30001 addd #1 13FE 7C0258 std _cop_cycle 1401 ; if (time_tick > TIME_TICKS_PER_DAY) { 1401 CD0254 ldy #_time_tick 1404 1802401C movw 0,y,-4,x 1408 1802421E movw 2,y,-2,x 140C CD1CD8 ldy #L51 140F 18024018 movw 0,y,-8,x 1413 1802421A movw 2,y,-6,x 1417 163A4A jsr __lcmp 141A 2316 bls L49 141C ; time_tick = 0; 141C CD1CD4 ldy #L52 141F 1802401C movw 0,y,-4,x 1423 1802421E movw 2,y,-2,x 1427 CD0254 ldy #_time_tick 142A 18021C40 movw -4,x,0,y 142E 18021E42 movw -2,x,2,y 1432 ; } 1432 L49: 1432 ; 1432 ; 1432 ; 1432 ; // RETURN: simulate a RTS instruction 1432 ; // set stack pointer for main() 1432 ; asm("LDS _main_frame_ptr"); 1432 FF0200 LDS _main_frame_ptr 1435 1435 ; asm("LDX _main_frame_x_ptr"); 1435 FE0202 LDX _main_frame_x_ptr 1438 1438 ; /* return to main() at the reentry point 1438 ; and must be adjusted after each kernel mod/compilation!! */ 1438 ; asm("JMP $117C"); 1438 06117C JMP $117C 143B 143B ; 143B ; } 143B L47: 143B B757 tfr x,s 143D 30 pulx 143E .dbline 0 ; func end 143E 0B rti 143F ; lreg1 -> -4,x 143F ; lreg2 -> -8,x 143F ; i -> -10,x 143F _kernel_init:: 143F 34 pshx 1440 B775 tfr s,x 1442 1BF1EE leas -18,sp 1445 ; 1445 ; 1445 ; 1445 ; 1445 ; void kernel_init(void) { 1445 CC0000 ldd #0 1448 6C16 std -10,x 144A L54: 144A CC000C ldd #12 144D ED16 ldy -10,x 144F 1813 emuls 1451 C30214 addd #_resource 1454 B7C6 xgdy 1456 EC16 ldd -10,x 1458 6B40 stab 0,y 145A CC000C ldd #12 145D ED16 ldy -10,x 145F 1813 emuls 1461 C3021A addd #_resource+6 1464 B7C6 xgdy 1466 6940 clr 0,y 1468 CC000C ldd #12 146B ED16 ldy -10,x 146D 1813 emuls 146F C3021B addd #_resource+7 1472 B7C6 xgdy 1474 C6FF ldab #255 1476 6B40 stab 0,y 1478 CC000C ldd #12 147B ED16 ldy -10,x 147D 1813 emuls 147F C3021F addd #_resource+11 1482 B7C6 xgdy 1484 6940 clr 0,y 1486 L55: 1486 ; 1486 ; // LOCAL VARIABLES 1486 ; extern int _bss_end, _textmode; 1486 ; int i; 1486 ; 1486 ; 1486 ; 1486 ; // START/INITIALIZE the os 1486 ; // KDB_TRACE Section 1 1486 ; 1486 ; // initialize the rcb pointer block 1486 ; for (i=0; i 3,x 152B _if_task_exists:: 152B 3B pshd 152C 34 pshx 152D B775 tfr s,x 152F ; 152F ; 152F ; 152F ; // KERNEL FUNCTIONS 152F ; 152F ; int if_task_exists(unsigned char id) { 152F ; 152F ; if (task[id] == NULL) 152F E603 ldab 3,x 1531 87 clra 1532 59 lsld 1533 C30244 addd #_task 1536 B7C6 xgdy 1538 EC40 ldd 0,y 153A 2605 bne L72 153C ; return -1; 153C CCFFFF ldd #-1 153F 200E bra L71 1541 L72: 1541 ; else 1541 ; return task[id]->id; 1541 E603 ldab 3,x 1543 87 clra 1544 59 lsld 1545 C30244 addd #_task 1548 B7C6 xgdy 154A ED40 ldy 0,y 154C E642 ldab 2,y 154E 87 clra 154F L71: 154F B757 tfr x,s 1551 30 pulx 1552 1B82 leas 2,sp 1554 .dbline 0 ; func end 1554 3D rts 1555 ; id -> 3,x 1555 _get_task_address:: 1555 3B pshd 1556 34 pshx 1557 B775 tfr s,x 1559 ; 1559 ; } 1559 ; 1559 ; 1559 ; 1559 ; 1559 ; int get_task_address(unsigned char id) { 1559 ; 1559 ; return (int)task[id]->address; 1559 E603 ldab 3,x 155B 87 clra 155C 59 lsld 155D C30244 addd #_task 1560 B7C6 xgdy 1562 ECEB0000 ldd [0,y] 1566 L74: 1566 B757 tfr x,s 1568 30 pulx 1569 1B82 leas 2,sp 156B .dbline 0 ; func end 156B 3D rts 156C _get_task_id:: 156C ; 156C ; } 156C ; 156C ; 156C ; 156C ; 156C ; char get_task_id() { 156C ; 156C ; return task[current]->id; 156C FC025E ldd _current 156F 59 lsld 1570 C30244 addd #_task 1573 B7C6 xgdy 1575 ED40 ldy 0,y 1577 E642 ldab 2,y 1579 87 clra 157A L75: 157A .dbline 0 ; func end 157A 3D rts 157B ; id -> 3,x 157B _get_task_name:: 157B 3B pshd 157C 34 pshx 157D B775 tfr s,x 157F ; } 157F ; 157F ; 157F ; 157F ; char *get_task_name(unsigned char id) { 157F ; if (task[id] == NULL) 157F E603 ldab 3,x 1581 87 clra 1582 59 lsld 1583 C30244 addd #_task 1586 B7C6 xgdy 1588 EC40 ldd 0,y 158A 2605 bne L77 158C ; return NULL; 158C CC0000 ldd #0 158F 200E bra L76 1591 L77: 1591 ; else 1591 ; return task[id]->name; 1591 E603 ldab 3,x 1593 87 clra 1594 59 lsld 1595 C30244 addd #_task 1598 B7C6 xgdy 159A EC40 ldd 0,y 159C C30003 addd #3 159F L76: 159F B757 tfr x,s 15A1 30 pulx 15A2 1B82 leas 2,sp 15A4 .dbline 0 ; func end 15A4 3D rts 15A5 ; id -> 3,x 15A5 _get_task_state:: 15A5 3B pshd 15A6 34 pshx 15A7 B775 tfr s,x 15A9 ; } 15A9 ; 15A9 ; 15A9 ; 15A9 ; 15A9 ; int get_task_state(unsigned char id) { 15A9 ; 15A9 ; if (task[id] == NULL) 15A9 E603 ldab 3,x 15AB 87 clra 15AC 59 lsld 15AD C30244 addd #_task 15B0 B7C6 xgdy 15B2 EC40 ldd 0,y 15B4 2605 bne L80 15B6 ; return -1; 15B6 CCFFFF ldd #-1 15B9 2019 bra L79 15BB L80: 15BB ; else if (id < MAXTASKS) 15BB E603 ldab 3,x 15BD C108 cmpb #8 15BF 2410 bhs L82 15C1 ; return task[id]->state; 15C1 E603 ldab 3,x 15C3 87 clra 15C4 59 lsld 15C5 C30244 addd #_task 15C8 B7C6 xgdy 15CA ED40 ldy 0,y 15CC E64C ldab 12,y 15CE 87 clra 15CF 2003 bra L79 15D1 L82: 15D1 ; else { 15D1 ; #ifdef KERNEL_ERROR_MSG 15D1 ; puts(error_src[1]); puts(error_msg[3]); 15D1 ; #endif 15D1 ; return -1; 15D1 CCFFFF ldd #-1 15D4 L79: 15D4 B757 tfr x,s 15D6 30 pulx 15D7 1B82 leas 2,sp 15D9 .dbline 0 ; func end 15D9 3D rts 15DA ; id -> 3,x 15DA _get_task_messages:: 15DA 3B pshd 15DB 34 pshx 15DC B775 tfr s,x 15DE ; } 15DE ; 15DE ; } 15DE ; 15DE ; 15DE ; 15DE ; int get_task_messages(unsigned char id) { 15DE ; 15DE ; if (task[id] == NULL) 15DE E603 ldab 3,x 15E0 87 clra 15E1 59 lsld 15E2 C30244 addd #_task 15E5 B7C6 xgdy 15E7 EC40 ldd 0,y 15E9 2605 bne L85 15EB ; return -1; 15EB CCFFFF ldd #-1 15EE 201A bra L84 15F0 L85: 15F0 ; else if (id < MAXTASKS) 15F0 E603 ldab 3,x 15F2 C108 cmpb #8 15F4 2411 bhs L87 15F6 ; return task[id]->message; 15F6 E603 ldab 3,x 15F8 87 clra 15F9 59 lsld 15FA C30244 addd #_task 15FD B7C6 xgdy 15FF ED40 ldy 0,y 1601 E6E814 ldab 20,y 1604 87 clra 1605 2003 bra L84 1607 L87: 1607 ; else { 1607 ; #ifdef KERNEL_ERROR_MSG 1607 ; puts(error_src[1]); puts(error_msg[3]); 1607 ; #endif 1607 ; return -1; 1607 CCFFFF ldd #-1 160A L84: 160A B757 tfr x,s 160C 30 pulx 160D 1B82 leas 2,sp 160F .dbline 0 ; func end 160F 3D rts 1610 ; id -> 3,x 1610 _get_task_priority:: 1610 3B pshd 1611 34 pshx 1612 B775 tfr s,x 1614 ; } 1614 ; 1614 ; } 1614 ; 1614 ; 1614 ; 1614 ; int get_task_priority(unsigned char id) { 1614 ; 1614 ; INTR_OFF(); 1614 1410 sei 1616 1616 ; 1616 ; if (id < MAXTASKS) { 1616 E603 ldab 3,x 1618 C108 cmpb #8 161A 2412 bhs L90 161C ; INTR_ON(); 161C 10EF cli 161E 161E ; return task[id]->priority; 161E E603 ldab 3,x 1620 87 clra 1621 59 lsld 1622 C30244 addd #_task 1625 B7C6 xgdy 1627 ED40 ldy 0,y 1629 E64D ldab 13,y 162B 87 clra 162C 2005 bra L89 162E L90: 162E ; } 162E ; else { 162E ; #ifdef KERNEL_ERROR_MSG 162E ; puts(error_src[1]); puts(error_msg[4]); 162E ; #endif 162E ; INTR_ON(); 162E 10EF cli 1630 1630 ; return -1; 1630 CCFFFF ldd #-1 1633 L89: 1633 B757 tfr x,s 1635 30 pulx 1636 1B82 leas 2,sp 1638 .dbline 0 ; func end 1638 3D rts 1639 ; ?temp -> -4,x 1639 ; ?temp -> -4,x 1639 ; ?temp -> -4,x 1639 ; ?temp -> -4,x 1639 ; ?temp -> -4,x 1639 ; ?temp -> -2,x 1639 ; newstate -> 7,x 1639 ; id -> 3,x 1639 _set_task_state:: 1639 3B pshd 163A 34 pshx 163B B775 tfr s,x 163D 1B9C leas -4,sp 163F ; } 163F ; 163F ; } 163F ; 163F ; 163F ; 163F ; int set_task_state(unsigned char id, unsigned char newstate) { 163F ; 163F ; 163F ; INTR_OFF(); 163F 1410 sei 1641 1641 ; 1641 ; 1641 ; // check id validity 1641 ; if (id < MAXTASKS) { 1641 E603 ldab 3,x 1643 C108 cmpb #8 1645 182401D9 lbhs L93 1649 ; 1649 ; if (task[id] == NULL) { 1649 E603 ldab 3,x 164B 87 clra 164C 59 lsld 164D C30244 addd #_task 1650 B7C6 xgdy 1652 EC40 ldd 0,y 1654 2609 bne L95 1656 ; #ifdef KERNEL_ERROR_MSG 1656 ; puts(error_src[1]); puts(error_msg[2]); 1656 ; #endif 1656 ; INTR_ON(); 1656 10EF cli 1658 1658 ; return -1; 1658 CCFFFF ldd #-1 165B 182001CF lbra L92 165F L95: 165F ; } 165F ; 165F ; 165F ; // check newstate validity 165F ; if ((newstate == RUNNING) || 165F E607 ldab 7,x 1661 C102 cmpb #2 1663 270C beq L100 1665 E607 ldab 7,x 1667 C103 cmpb #3 1669 2706 beq L100 166B E607 ldab 7,x 166D C104 cmpb #4 166F 2309 bls L97 1671 L100: 1671 ; (newstate == WAITING) || 1671 ; (newstate > STOPPED)) { 1671 ; #ifdef KERNEL_ERROR_MSG 1671 ; puts(error_src[1]); puts(error_msg[3]); 1671 ; #endif 1671 ; INTR_ON(); 1671 10EF cli 1673 1673 ; return -1; 1673 CCFFFF ldd #-1 1676 182001B4 lbra L92 167A L97: 167A E603 ldab 3,x 167C 87 clra 167D 59 lsld 167E C30244 addd #_task 1681 B7C6 xgdy 1683 ED40 ldy 0,y 1685 E64C ldab 12,y 1687 87 clra 1688 6C1E std -2,x 168A 271F beq L104 168C EC1E ldd -2,x 168E 8C0001 cpd #1 1691 1827009C lbeq L111 1695 EC1E ldd -2,x 1697 8C0002 cpd #2 169A 182700F0 lbeq L118 169E EC1E ldd -2,x 16A0 8C0004 cpd #4 16A3 18270128 lbeq L121 16A7 18200170 lbra L101 16AB X3: 16AB ; } 16AB ; 16AB ; // referenced to the task's current state: 16AB ; switch (task[id]->state) { 16AB L104: 16AB ; case IDLE: 16AB ; if (newstate == IDLE) { // no change 16AB E707 tst 7,x 16AD 2609 bne L105 16AF ; INTR_ON(); 16AF 10EF cli 16B1 16B1 ; return 0; 16B1 CC0000 ldd #0 16B4 18200176 lbra L92 16B8 L105: 16B8 ; } 16B8 ; else if (newstate == PENDING) { 16B8 E607 ldab 7,x 16BA C101 cmpb #1 16BC 2632 bne L107 16BE ; // pass msg to task[id]->msgbox; 16BE ; task[id]->message |= STATE_FLAG; 16BE E603 ldab 3,x 16C0 87 clra 16C1 59 lsld 16C2 C30244 addd #_task 16C5 B7C6 xgdy 16C7 EC40 ldd 0,y 16C9 C30014 addd #20 16CC 6C1C std -4,x 16CE B746 tfr d,y 16D0 35 pshy ; spill 16D1 ED1C ldy -4,x 16D3 31 puly ; reload 16D4 0C4001 bset 0,y,#1 16D7 ; task[id]->message_data[STATE_BOX] = PENDING; 16D7 E603 ldab 3,x 16D9 87 clra 16DA 59 lsld 16DB C30244 addd #_task 16DE B7C6 xgdy 16E0 ED40 ldy 0,y 16E2 C601 ldab #1 16E4 6BE815 stab 21,y 16E7 ; INTR_ON(); 16E7 10EF cli 16E9 16E9 ; return 0; 16E9 CC0000 ldd #0 16EC 1820013E lbra L92 16F0 L107: 16F0 ; } 16F0 ; else if (newstate == STOPPED) { 16F0 E607 ldab 7,x 16F2 C104 cmpb #4 16F4 2632 bne L109 16F6 ; // pass msg to task[id]->msgbox; 16F6 ; task[id]->message |= STATE_FLAG; 16F6 E603 ldab 3,x 16F8 87 clra 16F9 59 lsld 16FA C30244 addd #_task 16FD B7C6 xgdy 16FF EC40 ldd 0,y 1701 C30014 addd #20 1704 6C1C std -4,x 1706 B746 tfr d,y 1708 35 pshy ; spill 1709 ED1C ldy -4,x 170B 31 puly ; reload 170C 0C4001 bset 0,y,#1 170F ; task[id]->message_data[STATE_BOX] = STOPPED; 170F E603 ldab 3,x 1711 87 clra 1712 59 lsld 1713 C30244 addd #_task 1716 B7C6 xgdy 1718 ED40 ldy 0,y 171A C604 ldab #4 171C 6BE815 stab 21,y 171F ; INTR_ON(); 171F 10EF cli 1721 1721 ; return 0; 1721 CC0000 ldd #0 1724 18200106 lbra L92 1728 L109: 1728 ; } 1728 ; else { // nothing else is legal; 1728 ; #ifdef KERNEL_ERROR_MSG 1728 ; puts(error_src[1]); puts(error_msg[3]); 1728 ; #endif 1728 ; INTR_ON(); 1728 10EF cli 172A 172A ; return -1; 172A CCFFFF ldd #-1 172D 182000FD lbra L92 1731 X4: 1731 ; } 1731 ; break; 1731 L111: 1731 ; case PENDING: 1731 ; if (newstate == PENDING) { // no change 1731 E607 ldab 7,x 1733 C101 cmpb #1 1735 2609 bne L112 1737 ; INTR_ON(); 1737 10EF cli 1739 1739 ; return 0; 1739 CC0000 ldd #0 173C 182000EE lbra L92 1740 L112: 1740 ; } 1740 ; else if (newstate == IDLE) { 1740 E707 tst 7,x 1742 2609 bne L114 1744 ; // pass msg to task[id]->msgbox; 1744 ; #ifdef KERNEL_ERROR_MSG 1744 ; puts(error_src[1]); puts(error_msg[0]); 1744 ; #endif 1744 ; INTR_ON(); 1744 10EF cli 1746 1746 ; return -1; 1746 CCFFFF ldd #-1 1749 182000E1 lbra L92 174D L114: 174D ; } 174D ; else if (newstate == STOPPED) { 174D E607 ldab 7,x 174F C104 cmpb #4 1751 2632 bne L116 1753 ; // pass msg to task[id]->msgbox; 1753 ; task[id]->message |= STATE_FLAG; 1753 E603 ldab 3,x 1755 87 clra 1756 59 lsld 1757 C30244 addd #_task 175A B7C6 xgdy 175C EC40 ldd 0,y 175E C30014 addd #20 1761 6C1C std -4,x 1763 B746 tfr d,y 1765 35 pshy ; spill 1766 ED1C ldy -4,x 1768 31 puly ; reload 1769 0C4001 bset 0,y,#1 176C ; task[id]->message_data[STATE_BOX] = STOPPED; 176C E603 ldab 3,x 176E 87 clra 176F 59 lsld 1770 C30244 addd #_task 1773 B7C6 xgdy 1775 ED40 ldy 0,y 1777 C604 ldab #4 1779 6BE815 stab 21,y 177C ; INTR_ON(); 177C 10EF cli 177E 177E ; return 0; 177E CC0000 ldd #0 1781 182000A9 lbra L92 1785 L116: 1785 ; } 1785 ; else { 1785 ; #ifdef KERNEL_ERROR_MSG 1785 ; puts(error_src[1]); puts(error_msg[3]); 1785 ; #endif 1785 ; INTR_ON(); 1785 10EF cli 1787 1787 ; return -1; 1787 CCFFFF ldd #-1 178A 182000A0 lbra L92 178E X5: 178E ; } 178E ; break; 178E L118: 178E ; case RUNNING: 178E ; if (newstate == STOPPED) { 178E E607 ldab 7,x 1790 C104 cmpb #4 1792 2632 bne L119 1794 ; // pass msg to task[id]->msgbox; 1794 ; task[id]->message |= STATE_FLAG; 1794 E603 ldab 3,x 1796 87 clra 1797 59 lsld 1798 C30244 addd #_task 179B B7C6 xgdy 179D EC40 ldd 0,y 179F C30014 addd #20 17A2 6C1C std -4,x 17A4 B746 tfr d,y 17A6 35 pshy ; spill 17A7 ED1C ldy -4,x 17A9 31 puly ; reload 17AA 0C4001 bset 0,y,#1 17AD ; task[id]->message_data[STATE_BOX] = STOPPED; 17AD E603 ldab 3,x 17AF 87 clra 17B0 59 lsld 17B1 C30244 addd #_task 17B4 B7C6 xgdy 17B6 ED40 ldy 0,y 17B8 C604 ldab #4 17BA 6BE815 stab 21,y 17BD ; 17BD ; INTR_ON(); 17BD 10EF cli 17BF 17BF ; return 0; 17BF CC0000 ldd #0 17C2 18200068 lbra L92 17C6 L119: 17C6 ; } 17C6 ; else { 17C6 ; #ifdef KERNEL_ERROR_MSG 17C6 ; puts(error_src[1]); puts(error_msg[3]); 17C6 ; #endif 17C6 ; INTR_ON(); 17C6 10EF cli 17C8 17C8 ; return -1; 17C8 CCFFFF ldd #-1 17CB 1820005F lbra L92 17CF X6: 17CF ; } 17CF ; break; 17CF L121: 17CF ; case STOPPED: 17CF ; if (newstate == STOPPED) { // no change 17CF E607 ldab 7,x 17D1 C104 cmpb #4 17D3 2609 bne L122 17D5 ; INTR_ON(); 17D5 10EF cli 17D7 17D7 ; return 0; 17D7 CC0000 ldd #0 17DA 18200050 lbra L92 17DE L122: 17DE ; } 17DE ; else if (newstate == PENDING) { 17DE E607 ldab 7,x 17E0 C101 cmpb #1 17E2 2630 bne L124 17E4 ; // pass msg to task[id]->msgbox; 17E4 ; task[id]->message |= STATE_FLAG; 17E4 E603 ldab 3,x 17E6 87 clra 17E7 59 lsld 17E8 C30244 addd #_task 17EB B7C6 xgdy 17ED EC40 ldd 0,y 17EF C30014 addd #20 17F2 6C1C std -4,x 17F4 B746 tfr d,y 17F6 35 pshy ; spill 17F7 ED1C ldy -4,x 17F9 31 puly ; reload 17FA 0C4001 bset 0,y,#1 17FD ; task[id]->message_data[STATE_BOX] = PENDING; 17FD E603 ldab 3,x 17FF 87 clra 1800 59 lsld 1801 C30244 addd #_task 1804 B7C6 xgdy 1806 ED40 ldy 0,y 1808 C601 ldab #1 180A 6BE815 stab 21,y 180D ; INTR_ON(); 180D 10EF cli 180F 180F ; return 0; 180F CC0000 ldd #0 1812 201A bra L92 1814 L124: 1814 ; } 1814 ; else { 1814 ; #ifdef KERNEL_ERROR_MSG 1814 ; puts(error_src[1]); puts(error_msg[3]); 1814 ; #endif 1814 ; INTR_ON(); 1814 10EF cli 1816 1816 ; return -1; 1816 CCFFFF ldd #-1 1819 2013 bra L92 181B X7: 181B ; } 181B ; break; 181B L101: 181B ; default: 181B ; #ifdef KERNEL_ERROR_MSG 181B ; puts(error_src[1]); puts(error_msg[3]); 181B ; #endif 181B ; INTR_ON(); 181B 10EF cli 181D 181D ; return -1; 181D CCFFFF ldd #-1 1820 200C bra L92 1822 X8: 1822 ; break; 1822 L93: 1822 ; 1822 ; } // end switch (task[id]->state) 1822 ; 1822 ; } // if (id < MAXTASKS) 1822 ; 1822 ; else { 1822 ; #ifdef KERNEL_ERROR_MSG 1822 ; puts(error_src[1]); puts(error_msg[2]); 1822 ; #endif 1822 ; INTR_ON(); 1822 10EF cli 1824 1824 ; return -1; 1824 CCFFFF ldd #-1 1827 2005 bra L92 1829 X9: 1829 ; } 1829 ; 1829 ; INTR_ON(); 1829 10EF cli 182B 182B ; return 0; 182B CC0000 ldd #0 182E L92: 182E B757 tfr x,s 1830 30 pulx 1831 1B82 leas 2,sp 1833 .dbline 0 ; func end 1833 3D rts 1834 ; priority -> 7,x 1834 ; id -> 3,x 1834 _set_task_priority:: 1834 3B pshd 1835 34 pshx 1836 B775 tfr s,x 1838 ; 1838 ; } 1838 ; 1838 ; 1838 ; 1838 ; int set_task_priority(unsigned char id, unsigned char priority) { 1838 ; 1838 ; if (priority == 0) // priority 0 is reserved for the shell 1838 E707 tst 7,x 183A 2604 bne L127 183C ; priority = 1; 183C C601 ldab #1 183E 6B07 stab 7,x 1840 L127: 1840 ; 1840 ; if (id >= (MAXTASKS)) { 1840 E603 ldab 3,x 1842 C108 cmpb #8 1844 2505 blo L129 1846 ; #ifdef KERNEL_ERROR_MSG 1846 ; puts(error_src[1]); puts(error_msg[4]); 1846 ; #endif 1846 ; return -1; 1846 CCFFFF ldd #-1 1849 2021 bra L126 184B L129: 184B E607 ldab 7,x 184D C1FF cmpb #255 184F 2204 bhi L133 1851 E707 tst 7,x 1853 2405 bhs L131 1855 L133: 1855 ; } 1855 ; else if ((priority > 255) || (priority < 0)) { 1855 ; #ifdef KERNEL_ERROR_MSG 1855 ; puts(error_src[1]); puts(error_msg[4]); 1855 ; #endif 1855 ; return -1; 1855 CCFFFF ldd #-1 1858 2012 bra L126 185A L131: 185A ; } 185A ; else { 185A ; task[id]->priority = priority; 185A E603 ldab 3,x 185C 87 clra 185D 59 lsld 185E C30244 addd #_task 1861 B7C6 xgdy 1863 ED40 ldy 0,y 1865 E607 ldab 7,x 1867 6B4D stab 13,y 1869 ; return 0; 1869 CC0000 ldd #0 186C L126: 186C B757 tfr x,s 186E 30 pulx 186F 1B82 leas 2,sp 1871 .dbline 0 ; func end 1871 3D rts 1872 ; lreg1 -> -4,x 1872 ; lreg2 -> -8,x 1872 ; ?temp -> -15,x 1872 ; ?temp -> -13,x 1872 ; ?temp -> -11,x 1872 ; id -> -9,x 1872 ; stack_size -> 12,x 1872 ; state -> 10,x 1872 ; priority -> 9,x 1872 ; addr -> 6,x 1872 ; name -> 2,x 1872 _create_task:: 1872 3B pshd 1873 34 pshx 1874 B775 tfr s,x 1876 1BF1EA leas -22,sp 1879 ; } 1879 ; } 1879 ; 1879 ; 1879 ; 1879 ; 1879 ; int create_task(char *name, 1879 ; int (*addr)(), 1879 ; unsigned char priority, 1879 ; int state, 1879 ; int stack_size) { 1879 ; 1879 ; // LOCAL VARIABLES 1879 ; unsigned char id; 1879 ; 1879 ; 1879 ; INTR_OFF(); // critical section 1879 1410 sei 187B 187B 6917 clr -9,x 187D 2015 bra L138 187F L135: 187F E617 ldab -9,x 1881 87 clra 1882 59 lsld 1883 C30260 addd #_task_ptr 1886 B7C6 xgdy 1888 EC40 ldd 0,y 188A 270E beq L137 188C L136: 188C E617 ldab -9,x 188E 87 clra 188F C30001 addd #1 1892 6B17 stab -9,x 1894 L138: 1894 ; 1894 ; 1894 ; //if (get_free_memory() > 64) { 1894 ; 1894 ; // determine lowest free id available to assign to this task 1894 ; for (id=0; idaddress = addr; 18CA E617 ldab -9,x 18CC 87 clra 18CD 59 lsld 18CE C30244 addd #_task 18D1 B7C6 xgdy 18D3 ED40 ldy 0,y 18D5 EC06 ldd 6,x 18D7 6C40 std 0,y 18D9 ; task[id]->id = id; 18D9 E617 ldab -9,x 18DB 87 clra 18DC 59 lsld 18DD C30244 addd #_task 18E0 B7C6 xgdy 18E2 ED40 ldy 0,y 18E4 E617 ldab -9,x 18E6 6B42 stab 2,y 18E8 ; strcpy(task[id]->name, name); 18E8 18020280 movw 2,x,0,sp 18EC E617 ldab -9,x 18EE 87 clra 18EF 59 lsld 18F0 C30244 addd #_task 18F3 B7C6 xgdy 18F5 EC40 ldd 0,y 18F7 C30003 addd #3 18FA 163AD4 jsr _strcpy 18FD ; task[id]->state = state; 18FD E617 ldab -9,x 18FF 87 clra 1900 59 lsld 1901 C30244 addd #_task 1904 B7C6 xgdy 1906 ED40 ldy 0,y 1908 EC0A ldd 10,x 190A 6B4C stab 12,y 190C ; task[id]->priority = priority; 190C E617 ldab -9,x 190E 87 clra 190F 59 lsld 1910 C30244 addd #_task 1913 B7C6 xgdy 1915 ED40 ldy 0,y 1917 E609 ldab 9,x 1919 6B4D stab 13,y 191B ; task[id]->period_tick = 0; 191B E617 ldab -9,x 191D 87 clra 191E 59 lsld 191F C30244 addd #_task 1922 B7C6 xgdy 1924 ED40 ldy 0,y 1926 194E leay 14,y 1928 35 pshy ; spill 1929 CD1CD4 ldy #L52 192C 1802401C movw 0,y,-4,x 1930 1802421E movw 2,y,-2,x 1934 31 puly ; reload 1935 18021C40 movw -4,x,0,y 1939 18021E42 movw -2,x,2,y 193D ; task[id]->interrupt_msg_box = NULL; 193D E617 ldab -9,x 193F 87 clra 1940 59 lsld 1941 C30244 addd #_task 1944 B7C6 xgdy 1946 ED40 ldy 0,y 1948 CC0000 ldd #0 194B 6CE812 std 18,y 194E ; task[id]->message = NULL; 194E E617 ldab -9,x 1950 87 clra 1951 59 lsld 1952 C30244 addd #_task 1955 B7C6 xgdy 1957 ED40 ldy 0,y 1959 69E814 clr 20,y 195C ; task[id]->message_data[0] = NULL; 195C E617 ldab -9,x 195E 87 clra 195F 59 lsld 1960 C30244 addd #_task 1963 B7C6 xgdy 1965 ED40 ldy 0,y 1967 69E815 clr 21,y 196A ; task[id]->message_data[1] = NULL; 196A E617 ldab -9,x 196C 87 clra 196D 59 lsld 196E C30244 addd #_task 1971 B7C6 xgdy 1973 ED40 ldy 0,y 1975 69E816 clr 22,y 1978 ; if (stack_size <= 0) 1978 EC0C ldd 12,x 197A 2E05 bgt L143 197C ; stack_size = DEFAULT_STACK_SIZE; 197C CC0040 ldd #64 197F 6C0C std 12,x 1981 L143: 1981 ; task[id]->stack_size = stack_size; 1981 E617 ldab -9,x 1983 87 clra 1984 59 lsld 1985 C30244 addd #_task 1988 B7C6 xgdy 198A ED40 ldy 0,y 198C EC0C ldd 12,x 198E 6CE817 std 23,y 1991 ; task[id]->top_of_stack = malloc(task[id]->stack_size); 1991 E617 ldab -9,x 1993 87 clra 1994 59 lsld 1995 C30244 addd #_task 1998 B7C6 xgdy 199A ED40 ldy 0,y 199C 6D15 sty -11,x 199E ED15 ldy -11,x 19A0 ECE817 ldd 23,y 19A3 163D42 jsr _malloc 19A6 6CE1EC std -20,x 19A9 ED15 ldy -11,x 19AB ECE1EC ldd -20,x 19AE 6CE819 std 25,y 19B1 ; task[id]->top_of_stack += task[id]->stack_size; 19B1 E617 ldab -9,x 19B3 87 clra 19B4 59 lsld 19B5 C30244 addd #_task 19B8 B7C6 xgdy 19BA ED40 ldy 0,y 19BC 6D13 sty -13,x 19BE EC13 ldd -13,x 19C0 C30019 addd #25 19C3 6C11 std -15,x 19C5 ED13 ldy -13,x 19C7 ECE817 ldd 23,y 19CA E3E3FFF1 addd [-15,x] 19CE ED11 ldy -15,x 19D0 6C40 std 0,y 19D2 ; task[id]->frame_ptr = NULL; 19D2 E617 ldab -9,x 19D4 87 clra 19D5 59 lsld 19D6 C30244 addd #_task 19D9 B7C6 xgdy 19DB ED40 ldy 0,y 19DD CC0000 ldd #0 19E0 6CE81B std 27,y 19E3 ; 19E3 ; } 19E3 ; //} 19E3 ; INTR_ON(); 19E3 10EF cli 19E5 19E5 ; 19E5 ; return id; 19E5 E617 ldab -9,x 19E7 87 clra 19E8 L134: 19E8 B757 tfr x,s 19EA 30 pulx 19EB 1B82 leas 2,sp 19ED .dbline 0 ; func end 19ED 3D rts 19EE ; ?temp -> -2,x 19EE ; id -> 3,x 19EE _remove_task:: 19EE 3B pshd 19EF 34 pshx 19F0 B775 tfr s,x 19F2 1B9E leas -2,sp 19F4 ; 19F4 ; } 19F4 ; 19F4 ; 19F4 ; 19F4 ; int remove_task(unsigned char id) { 19F4 ; 19F4 ; if (task[id] == NULL) 19F4 E603 ldab 3,x 19F6 87 clra 19F7 59 lsld 19F8 C30244 addd #_task 19FB B7C6 xgdy 19FD EC40 ldd 0,y 19FF 2605 bne L146 1A01 ; return -1; 1A01 CCFFFF ldd #-1 1A04 2047 bra L145 1A06 L146: 1A06 ; 1A06 ; 1A06 ; free(task[id]->top_of_stack - task[id]->stack_size); 1A06 E603 ldab 3,x 1A08 87 clra 1A09 59 lsld 1A0A C30244 addd #_task 1A0D B7C6 xgdy 1A0F ED40 ldy 0,y 1A11 6D1E sty -2,x 1A13 ED1E ldy -2,x 1A15 ECE819 ldd 25,y 1A18 ED1E ldy -2,x 1A1A A3E817 subd 23,y 1A1D 163F10 jsr _free 1A20 ; free(task[id]); 1A20 E603 ldab 3,x 1A22 87 clra 1A23 59 lsld 1A24 C30244 addd #_task 1A27 B7C6 xgdy 1A29 EC40 ldd 0,y 1A2B 163F10 jsr _free 1A2E ; task[id] = NULL; 1A2E E603 ldab 3,x 1A30 87 clra 1A31 59 lsld 1A32 C30244 addd #_task 1A35 B7C6 xgdy 1A37 CC0000 ldd #0 1A3A 6C40 std 0,y 1A3C ; task_ptr[id] = NULL; 1A3C E603 ldab 3,x 1A3E 87 clra 1A3F 59 lsld 1A40 C30260 addd #_task_ptr 1A43 B7C6 xgdy 1A45 CC0000 ldd #0 1A48 6C40 std 0,y 1A4A ; 1A4A ; return 0; 1A4A CC0000 ldd #0 1A4D L145: 1A4D B757 tfr x,s 1A4F 30 pulx 1A50 1B82 leas 2,sp 1A52 .dbline 0 ; func end 1A52 3D rts 1A53 ; rid -> 3,x 1A53 _get_resource_state:: 1A53 3B pshd 1A54 34 pshx 1A55 B775 tfr s,x 1A57 ; 1A57 ; } 1A57 ; 1A57 ; 1A57 ; 1A57 ; int get_resource_state(unsigned char rid) { 1A57 ; 1A57 ; if (rid < NUMRESOURCES) { 1A57 E603 ldab 3,x 1A59 C104 cmpb #4 1A5B 2414 bhs L149 1A5D ; return resource[rid].state; 1A5D E603 ldab 3,x 1A5F 87 clra 1A60 B7C6 xgdy 1A62 CC000C ldd #12 1A65 1813 emuls 1A67 C3021A addd #_resource+6 1A6A B7C6 xgdy 1A6C E640 ldab 0,y 1A6E 87 clra 1A6F 2003 bra L148 1A71 L149: 1A71 ; } 1A71 ; else { 1A71 ; #ifdef KERNEL_ERROR_MSG 1A71 ; puts(error_src[1]); puts(error_msg[6]); 1A71 ; #endif 1A71 ; return -1; 1A71 CCFFFF ldd #-1 1A74 L148: 1A74 B757 tfr x,s 1A76 30 pulx 1A77 1B82 leas 2,sp 1A79 .dbline 0 ; func end 1A79 3D rts 1A7A ; rid -> 3,x 1A7A _get_resource_owner:: 1A7A 3B pshd 1A7B 34 pshx 1A7C B775 tfr s,x 1A7E ; } 1A7E ; 1A7E ; } 1A7E ; 1A7E ; 1A7E ; 1A7E ; 1A7E ; 1A7E ; int get_resource_owner(unsigned char rid) { 1A7E ; 1A7E ; if (rid < NUMRESOURCES) { 1A7E E603 ldab 3,x 1A80 C104 cmpb #4 1A82 2414 bhs L153 1A84 ; return resource[rid].owner; 1A84 E603 ldab 3,x 1A86 87 clra 1A87 B7C6 xgdy 1A89 CC000C ldd #12 1A8C 1813 emuls 1A8E C3021B addd #_resource+7 1A91 B7C6 xgdy 1A93 E640 ldab 0,y 1A95 87 clra 1A96 2003 bra L152 1A98 L153: 1A98 ; } 1A98 ; else { 1A98 ; #ifdef KERNEL_ERROR_MSG 1A98 ; puts(error_src[1]); puts(error_msg[6]); 1A98 ; #endif 1A98 ; return -1; 1A98 CCFFFF ldd #-1 1A9B L152: 1A9B B757 tfr x,s 1A9D 30 pulx 1A9E 1B82 leas 2,sp 1AA0 .dbline 0 ; func end 1AA0 3D rts 1AA1 ; rid -> 3,x 1AA1 _get_resource_queuelen:: 1AA1 3B pshd 1AA2 34 pshx 1AA3 B775 tfr s,x 1AA5 ; } 1AA5 ; 1AA5 ; } 1AA5 ; 1AA5 ; 1AA5 ; 1AA5 ; 1AA5 ; int get_resource_queuelen(unsigned char rid) { 1AA5 ; 1AA5 ; if (rid < NUMRESOURCES) { 1AA5 E603 ldab 3,x 1AA7 C104 cmpb #4 1AA9 2414 bhs L157 1AAB ; return resource[rid].queue_ptr; 1AAB E603 ldab 3,x 1AAD 87 clra 1AAE B7C6 xgdy 1AB0 CC000C ldd #12 1AB3 1813 emuls 1AB5 C3021F addd #_resource+11 1AB8 B7C6 xgdy 1ABA E640 ldab 0,y 1ABC 87 clra 1ABD 2003 bra L156 1ABF L157: 1ABF ; } 1ABF ; else { 1ABF ; #ifdef KERNEL_ERROR_MSG 1ABF ; puts(error_src[1]); puts(error_msg[6]); 1ABF ; #endif 1ABF ; return -1; 1ABF CCFFFF ldd #-1 1AC2 L156: 1AC2 B757 tfr x,s 1AC4 30 pulx 1AC5 1B82 leas 2,sp 1AC7 .dbline 0 ; func end 1AC7 3D rts 1AC8 ; last -> -6,x 1AC8 ; memory -> -4,x 1AC8 ; i -> -2,x 1AC8 _get_free_memory:: 1AC8 34 pshx 1AC9 B775 tfr s,x 1ACB 1B98 leas -8,sp 1ACD ; } 1ACD ; 1ACD ; } 1ACD ; 1ACD ; 1ACD ; 1ACD ; 1ACD ; int get_free_memory(void) { 1ACD ; 1ACD ; // LOCAL VARIABLES 1ACD ; char *memory, *last; 1ACD ; int i; 1ACD ; 1ACD ; 1ACD ; INTR_OFF(); 1ACD 1410 sei 1ACF 1ACF CC0000 ldd #0 1AD2 6C1E std -2,x 1AD4 L161: 1AD4 ; // check for largest free memory block 1AD4 ; for (i=0; i -6,x 1B03 ; ?temp -> -4,x 1B03 ; ?temp -> -2,x 1B03 ; rid -> 3,x 1B03 _sem_get:: 1B03 3B pshd 1B04 34 pshx 1B05 B775 tfr s,x 1B07 1B98 leas -8,sp 1B09 ; 1B09 ; } 1B09 ; 1B09 ; 1B09 ; 1B09 ; 1B09 ; int sem_get(char rid) { 1B09 ; 1B09 ; /* Gives a resource to a requesting task. 1B09 ; returns the resource id number (0,1,2,...) if free. 1B09 ; otherwise returns -1. 1B09 ; 1B09 ; At this point, semaphores are a procedural control 1B09 ; that the tasks have to follow to avoid resource contention. 1B09 ; There is no kernel control over resources yet. */ 1B09 ; 1B09 ; 1B09 ; // critical section 1B09 ; INTR_OFF(); 1B09 1410 sei 1B0B 1B0B ; 1B0B ; 1B0B ; 1B0B ; // GET SEMAPHORE 1B0B ; // give semaphore to task 1B0B ; if (resource[rid].state == NOTBUSY) { 1B0B E603 ldab 3,x 1B0D 87 clra 1B0E B7C6 xgdy 1B10 CC000C ldd #12 1B13 1813 emuls 1B15 C3021A addd #_resource+6 1B18 B7C6 xgdy 1B1A E740 tst 0,y 1B1C 2630 bne L168 1B1E ; resource[rid].state = BUSY; 1B1E E603 ldab 3,x 1B20 87 clra 1B21 B7C6 xgdy 1B23 CC000C ldd #12 1B26 1813 emuls 1B28 C3021A addd #_resource+6 1B2B B7C6 xgdy 1B2D C601 ldab #1 1B2F 6B40 stab 0,y 1B31 ; resource[rid].owner = current; 1B31 E603 ldab 3,x 1B33 87 clra 1B34 B7C6 xgdy 1B36 CC000C ldd #12 1B39 1813 emuls 1B3B C3021B addd #_resource+7 1B3E B7C6 xgdy 1B40 FC025E ldd _current 1B43 6B40 stab 0,y 1B45 ; 1B45 ; INTR_ON(); 1B45 10EF cli 1B47 1B47 ; return rid; 1B47 E603 ldab 3,x 1B49 87 clra 1B4A 18200084 lbra L167 1B4E L168: 1B4E ; } 1B4E ; 1B4E ; // resource is taken/busy so make task wait 1B4E ; else { 1B4E ; task[current]->message |= STATE_FLAG; 1B4E FC025E ldd _current 1B51 59 lsld 1B52 C30244 addd #_task 1B55 B7C6 xgdy 1B57 EC40 ldd 0,y 1B59 C30014 addd #20 1B5C 6C1E std -2,x 1B5E B746 tfr d,y 1B60 35 pshy ; spill 1B61 ED1E ldy -2,x 1B63 31 puly ; reload 1B64 0C4001 bset 0,y,#1 1B67 ; task[current]->message_data[STATE_BOX] = WAITING; 1B67 FC025E ldd _current 1B6A 59 lsld 1B6B C30244 addd #_task 1B6E B7C6 xgdy 1B70 ED40 ldy 0,y 1B72 C603 ldab #3 1B74 6BE815 stab 21,y 1B77 ; 1B77 ; // put waiting task into the resources queue if there's space 1B77 ; if (resource[rid].queue_ptr < 3) { 1B77 E603 ldab 3,x 1B79 87 clra 1B7A B7C6 xgdy 1B7C CC000C ldd #12 1B7F 1813 emuls 1B81 C3021F addd #_resource+11 1B84 B7C6 xgdy 1B86 E640 ldab 0,y 1B88 C103 cmpb #3 1B8A 2441 bhs L173 1B8C ; resource[rid].queue[resource[rid].queue_ptr] = current; 1B8C E603 ldab 3,x 1B8E 87 clra 1B8F B7C6 xgdy 1B91 CC000C ldd #12 1B94 1813 emuls 1B96 6C1C std -4,x 1B98 C3021F addd #_resource+11 1B9B B7C6 xgdy 1B9D E640 ldab 0,y 1B9F 87 clra 1BA0 3B pshd ; spill 1BA1 EC1C ldd -4,x 1BA3 C3021C addd #_resource+8 1BA6 6C18 std -8,x 1BA8 3A puld ; reload 1BA9 E318 addd -8,x 1BAB B7C6 xgdy 1BAD F6025F ldab _current+1 1BB0 6B40 stab 0,y 1BB2 ; resource[rid].queue_ptr++; 1BB2 E603 ldab 3,x 1BB4 87 clra 1BB5 B7C6 xgdy 1BB7 CC000C ldd #12 1BBA 1813 emuls 1BBC C3021F addd #_resource+11 1BBF 6C1A std -6,x 1BC1 B746 tfr d,y 1BC3 E640 ldab 0,y 1BC5 87 clra 1BC6 C30001 addd #1 1BC9 ED1A ldy -6,x 1BCB 6B40 stab 0,y 1BCD ; } 1BCD L173: 1BCD ; 1BCD ; INTR_ON(); 1BCD 10EF cli 1BCF 1BCF ; return -1; 1BCF CCFFFF ldd #-1 1BD2 L167: 1BD2 B757 tfr x,s 1BD4 30 pulx 1BD5 1B82 leas 2,sp 1BD7 .dbline 0 ; func end 1BD7 3D rts 1BD8 ; rid -> 3,x 1BD8 _sem_give:: 1BD8 3B pshd 1BD9 34 pshx 1BDA B775 tfr s,x 1BDC ; } 1BDC ; 1BDC ; } 1BDC ; 1BDC ; 1BDC ; 1BDC ; 1BDC ; int sem_give(char rid) { 1BDC ; 1BDC ; /* Takes a resource back from a task. 1BDC ; will (eventually) pass a message to a waiting task. 1BDC ; 1BDC ; At this point, semaphores are a procedural control 1BDC ; that the tasks have to follow to avoid resource contention. 1BDC ; There is no kernel control over resources yet. */ 1BDC ; 1BDC ; 1BDC ; // critical section 1BDC ; INTR_OFF(); 1BDC 1410 sei 1BDE 1BDE ; 1BDE ; 1BDE ; // return the resource 1BDE ; resource[rid].state = NOTBUSY; 1BDE E603 ldab 3,x 1BE0 87 clra 1BE1 B7C6 xgdy 1BE3 CC000C ldd #12 1BE6 1813 emuls 1BE8 C3021A addd #_resource+6 1BEB B7C6 xgdy 1BED 6940 clr 0,y 1BEF ; //resource[rid].owner = NULL; 1BEF ; 1BEF ; INTR_ON(); 1BEF 10EF cli 1BF1 1BF1 ; 1BF1 ; return 0; 1BF1 CC0000 ldd #0 1BF4 L179: 1BF4 B757 tfr x,s 1BF6 30 pulx 1BF7 1B82 leas 2,sp 1BF9 .dbline 0 ; func end 1BF9 3D rts 1BFA ; lreg1 -> -4,x 1BFA ; lreg2 -> -8,x 1BFA ; slop -> -12,x 1BFA _get_sysTime:: 1BFA 34 pshx 1BFB B775 tfr s,x 1BFD 1B94 leas -12,sp 1BFF ; 1BFF ; } 1BFF ; 1BFF ; 1BFF ; 1BFF ; unsigned long int get_sysTime(void) { 1BFF ; 1BFF ; // LOCAL VARIABLES 1BFF ; unsigned long int slop; 1BFF ; 1BFF ; 1BFF ; // returns the number of milliseconds since midnight (time_tick=0); 1BFF ; slop = time_tick / 40; 1BFF CD0254 ldy #_time_tick 1C02 1802401C movw 0,y,-4,x 1C06 1802421E movw 2,y,-2,x 1C0A CD1C95 ldy #L182 1C0D 18024018 movw 0,y,-8,x 1C11 1802421A movw 2,y,-6,x 1C15 16396B jsr __ludiv 1C18 1914 leay -12,x 1C1A 18021C40 movw -4,x,0,y 1C1E 18021E42 movw -2,x,2,y 1C22 ; return (time_tick * ms_PER_TIME_TICK + slop); 1C22 CD1C91 ldy #L183 1C25 1802401C movw 0,y,-4,x 1C29 1802421E movw 2,y,-2,x 1C2D CD0254 ldy #_time_tick 1C30 18024018 movw 0,y,-8,x 1C34 1802421A movw 2,y,-6,x 1C38 1638CB jsr __lmul 1C3B 1914 leay -12,x 1C3D 18024018 movw 0,y,-8,x 1C41 1802421A movw 2,y,-6,x 1C45 1638A9 jsr __ladd 1C48 16387F jsr __lret 1C4B L181: 1C4B B757 tfr x,s 1C4D 30 pulx 1C4E .dbline 0 ; func end 1C4E 3D rts 1C4F ; lreg1 -> -4,x 1C4F ; lreg2 -> -8,x 1C4F ; seconds -> 8,x 1C4F ; minutes -> 6,x 1C4F ; hours -> 2,x 1C4F _set_sysTime:: 1C4F 3B pshd 1C50 34 pshx 1C51 B775 tfr s,x 1C53 1B96 leas -10,sp 1C55 ; 1C55 ; } 1C55 ; 1C55 ; 1C55 ; 1C55 ; void set_sysTime(unsigned int hours, unsigned int minutes, unsigned int seconds) { 1C55 ; 1C55 ; // LOCAL VARIABLES 1C55 ; extern unsigned long int time_tick; 1C55 ; 1C55 ; 1C55 ; time_tick = ((hours*3600)+(minutes*60)+(seconds)) * TIME_TICKS_PER_SECOND; 1C55 CC003C ldd #60 1C58 ED06 ldy 6,x 1C5A 13 emul 1C5B 6C16 std -10,x 1C5D CC0E10 ldd #3600 1C60 ED02 ldy 2,x 1C62 13 emul 1C63 E316 addd -10,x 1C65 E308 addd 8,x 1C67 6C1A std -6,x 1C69 1800180000 movw #0,-8,x 1C6E CD1C8D ldy #L185 1C71 1802401C movw 0,y,-4,x 1C75 1802421E movw 2,y,-2,x 1C79 1638CB jsr __lmul 1C7C CD0254 ldy #_time_tick 1C7F 18021C40 movw -4,x,0,y 1C83 18021E42 movw -2,x,2,y 1C87 ; 1C87 ; } 1C87 L184: 1C87 B757 tfr x,s 1C89 30 pulx 1C8A 1B82 leas 2,sp 1C8C .dbline 0 ; func end 1C8C 3D rts .area bss 0212 _exit_status:: 0212 .blkb 2 0214 _resource:: 0214 .blkb 48 0244 _task:: 0244 .blkb 16 0254 _time_tick:: 0254 .blkb 4 0258 _cop_cycle:: 0258 .blkb 2 025A _system_tick:: 025A .blkb 4 025E _current:: 025E .blkb 2 0260 _task_ptr:: 0260 .blkb 16 .area text --- 0C63 L185: --- 0C63 0000003D .word 0,61 --- 0C67 L183: --- 0C67 00000010 .word 0,16 --- 0C6B L182: --- 0C6B 00000028 .word 0,40 --- 0C6F L70: --- 0C6F 726C704F532076302E372E310A0A00 .byte 'r,'l,'p,'O,'S,32,'v,48,46,55,46,49,10,10,0 --- 0C7E L69: --- 0C7E 737973496E6974206661696C75726500 .byte 's,'y,'s,'I,'n,'i,'t,32,'f,'a,'i,'l,'u,'r,'e,0 --- 0C8E L68: --- 0C8E 737973496E697400 .byte 's,'y,'s,'I,'n,'i,'t,0 --- 0C96 L65: --- 0C96 7368656C6C206661696C75726500 .byte 's,'h,'e,'l,'l,32,'f,'a,'i,'l,'u,'r,'e,0 --- 0CA4 L64: --- 0CA4 7368656C6C00 .byte 's,'h,'e,'l,'l,0 --- 0CAA L52: --- 0CAA 00000000 .word 0,0 --- 0CAE L51: --- 0CAE 00506B80 .word 80,27520 --- 0CB2 L48: --- 0CB2 00000001 .word 0,1 --- 0CB6 L46: --- 0CB6 4B45524E454C3A207461736B20737461 .byte 'K,'E,'R,'N,'E,'L,58,32,'t,'a,'s,'k,32,'s,'t,'a --- 0CC6 7465206572726F720A00 .byte 't,'e,32,'e,'r,'r,'o,'r,10,0 .module shell.c .area text ; ?temp -> -49,x ; ?temp -> -47,x ; cmd_length -> -46,x ; cmd -> -44,x ; argc -> -43,x ; argv -> -41,x ; cursor1 -> -39,x ; j -> -37,x ; cursor2 -> -36,x ; command -> -34,x ; i -> -1,x 1CFA _shell:: 1CFA 34 pshx 1CFB B775 tfr s,x 1CFD 1BF1C0 leas -64,sp 1D00 ; // shell.c 1D00 ; 1D00 ; #include <912d60.h> 1D00 ; #include 1D00 ; #include 1D00 ; #include 1D00 ; #include 1D00 ; #include "kernel.h" 1D00 ; #include "semlib.h" 1D00 ; 1D00 ; 1D00 ; 1D00 ; 1D00 ; // FUNCTION PROTOTYPES 1D00 ; void shellcmd_help(char *argv1); 1D00 ; void shellcmd_tcb(signed char id); 1D00 ; void shellcmd_rcb(signed char id); 1D00 ; void shellcmd_rcbPrint(signed char rid); 1D00 ; void shellcmd_ticks(void); 1D00 ; void shellcmd_startTask(unsigned char id); 1D00 ; void shellcmd_stopTask(unsigned char id); 1D00 ; void shellcmd_time(void); 1D00 ; void shellcmd_freeMemCheck(void); 1D00 ; void shellcmd_kdb(int onoff); 1D00 ; void shellcmd_quitShell(void); 1D00 ; /* 1D00 ; void shellcmd_setTaskPriority(unsigned char id, unsigned char priority); 1D00 ; */ 1D00 ; 1D00 ; 1D00 ; 1D00 ; 1D00 ; // GLOBAL VARIABLES 1D00 ; extern unsigned long int system_tick; 1D00 ; extern unsigned int current; // current task id number 1D00 ; 1D00 ; extern char error_msg[8][25]; 1D00 ; extern char error_src[5][18]; 1D00 ; 1D00 ; extern char kdb_trace; 1D00 ; 1D00 ; 1D00 ; 1D00 ; 1D00 ; int shell(void) { 1D00 ; 1D00 ; // LOCAL CONSTANTS 1D00 ; #define cmd_size (32+1) 1D00 ; 1D00 ; 1D00 ; 1D00 ; // LOCAL ENUMERATIONS 1D00 ; enum command_type { help = 1, 1D00 ; tcb, 1D00 ; rcb, 1D00 ; ticks, 1D00 ; start, 1D00 ; stop, 1D00 ; priority, 1D00 ; time, 1D00 ; freemem, 1D00 ; kdb, 1D00 ; quit, 1D00 ; taskname 1D00 ; }; 1D00 ; 1D00 ; 1D00 ; 1D00 ; // LOCAL VARIABLES 1D00 ; char command[cmd_size], i, j, **argv, *cursor1, *cursor2; 1D00 ; int cmd_length, argc; 1D00 ; enum command_type cmd; 1D00 ; 1D00 ; 1D00 ; 1D00 ; 1D00 ; // INITIALIZE SHELL 1D00 ; sem_get(COM1); // get COM1 semaphore 1D00 CC0003 ldd #3 1D03 161B03 jsr _sem_get 1D06 ; set_task_priority(current, 200); 1D06 CC00C8 ldd #200 1D09 6C80 std 0,sp 1D0B FC025E ldd _current 1D0E 87 clra 1D0F 161834 jsr _set_task_priority 1D12 ; INTR_ON(); // enable interrupts 1D12 10EF cli 1D14 1D14 18200661 lbra L5 1D18 L4: 1D18 ; 1D18 ; 1D18 ; 1D18 ; 1D18 ; 1D18 ; // SHELL COMMAND LINE INTERPRETER 1D18 ; while (1) { 1D18 ; 1D18 ; INTR_ON(); 1D18 10EF cli 1D1A 1D1A ; i = 0; 1D1A 691F clr -1,x 1D1C ; cursor1 = command; 1D1C 19E1DE leay -34,x 1D1F 6DE1D9 sty -39,x 1D22 ; cursor2 = command; 1D22 19E1DE leay -34,x 1D25 6DE1DC sty -36,x 1D28 ; 1D28 ; 1D28 ; // put a PROMPT 1D28 ; putchar('>'); putchar('>'); putchar(' '); 1D28 CC003E ldd #62 1D2B 163558 jsr _putchar 1D2E CC003E ldd #62 1D31 163558 jsr _putchar 1D34 CC0020 ldd #32 1D37 163558 jsr _putchar 1D3A 2056 bra L8 1D3C L7: 1D3C ; 1D3C ; 1D3C ; // GET AND ECHO THE COMMAND on the console 1D3C ; while (((command[i]=getchar()) != 0xD) && (i -- required arguments"); 20AB CC2B0D ldd #L76 20AE 163AE3 jsr _puts 20B1 ; puts("[] -- optional arguments\n"); 20B1 CC2AF3 ldd #L77 20B4 163AE3 jsr _puts 20B7 ; puts("help [cmd] -- help on a specific command"); 20B7 CC2ACA ldd #L78 20BA 163AE3 jsr _puts 20BD ; puts("tcb [task_id] -- prints task control block"); 20BD CC2A9F ldd #L79 20C0 163AE3 jsr _puts 20C3 ; puts("rcb [[task_id] | [-b]] -- prints resource control block"); 20C3 CC2A67 ldd #L80 20C6 163AE3 jsr _puts 20C9 ; puts("ticks -- shows system tick"); 20C9 CC2A4C ldd #L81 20CC 163AE3 jsr _puts 20CF ; puts("start -- start a task"); 20CF CC2A2C ldd #L82 20D2 163AE3 jsr _puts 20D5 ; puts("stop -- stop a task"); 20D5 CC2A0D ldd #L83 20D8 163AE3 jsr _puts 20DB ; puts("priority , -- change prio"); 20DB CC29D9 ldd #L84 20DE 163AE3 jsr _puts 20E1 ; puts("time [ ]-- display/set the current system time"); 20E1 CC2999 ldd #L85 20E4 163AE3 jsr _puts 20E7 ; puts("freemem -- get approximate free RAM space"); 20E7 CC296F ldd #L86 20EA 163AE3 jsr _puts 20ED ; puts("kdb [1|0] -- turn kernel debug on/off"); 20ED CC2949 ldd #L87 20F0 163AE3 jsr _puts 20F3 ; puts("quit -- quit the shell (carefull!)"); 20F3 CC2926 ldd #L88 20F6 163AE3 jsr _puts 20F9 ; putchar('\n'); 20F9 CC000A ldd #10 20FC 163558 jsr _putchar 20FF ; } 20FF 18200248 lbra L70 2103 L73: 2103 ; else if (argc == 2) 2103 ECE1D5 ldd -43,x 2106 8C0002 cpd #2 2109 1826023E lbne L70 210D ; shellcmd_help(argv[1]); 210D EDE1D7 ldy -41,x 2110 EC42 ldd 2,y 2112 16238C jsr _shellcmd_help 2115 ; break; 2115 18200232 lbra L70 2119 L91: 2119 ; case tcb: 2119 ; if (argc == 1) 2119 ECE1D5 ldd -43,x 211C 8C0001 cpd #1 211F 260A bne L92 2121 ; shellcmd_tcb(-1); 2121 CCFFFF ldd #-1 2124 162393 jsr _shellcmd_tcb 2127 18200220 lbra L70 212B L92: 212B ; else if (argc == 2) 212B ECE1D5 ldd -43,x 212E 8C0002 cpd #2 2131 2611 bne L94 2133 ; shellcmd_tcb(atoi(argv[1])); 2133 EDE1D7 ldy -41,x 2136 EC42 ldd 2,y 2138 163F43 jsr _atoi 213B B714 tfr b,d 213D 162393 jsr _shellcmd_tcb 2140 18200207 lbra L70 2144 L94: 2144 ; else if (argc > 2) 2144 ECE1D5 ldd -43,x 2147 8C0002 cpd #2 214A 182F01FD lble L70 214E ; puts(error_msg[1]); 214E CC1043 ldd #_error_msg+25 2151 163AE3 jsr _puts 2154 ; break; 2154 182001F3 lbra L70 2158 L99: 2158 ; case rcb: 2158 ; if (argc == 1) // print entire rcb 2158 ECE1D5 ldd -43,x 215B 8C0001 cpd #1 215E 260A bne L100 2160 ; shellcmd_rcb(-1); 2160 CCFFFF ldd #-1 2163 162454 jsr _shellcmd_rcb 2166 182001E1 lbra L70 216A L100: 216A ; else if (argc == 2) { 216A ECE1D5 ldd -43,x 216D 8C0002 cpd #2 2170 262D bne L102 2172 ; if (!strcmp(argv[1], "-b")) { // print 'busy' only 2172 CC2923 ldd #L106 2175 6C80 std 0,sp 2177 EDE1D7 ldy -41,x 217A EC42 ldd 2,y 217C 163A6A jsr _strcmp 217F 8C0000 cpd #0 2182 260A bne L104 2184 ; shellcmd_rcb(-2); 2184 CCFFFE ldd #-2 2187 162454 jsr _shellcmd_rcb 218A ; } 218A 182001BD lbra L70 218E L104: 218E ; else 218E ; shellcmd_rcb(atoi(argv[1])); // single 218E EDE1D7 ldy -41,x 2191 EC42 ldd 2,y 2193 163F43 jsr _atoi 2196 B714 tfr b,d 2198 162454 jsr _shellcmd_rcb 219B ; } 219B 182001AC lbra L70 219F L102: 219F ; else if (argc > 2) 219F ECE1D5 ldd -43,x 21A2 8C0002 cpd #2 21A5 182F01A2 lble L70 21A9 ; puts(error_msg[1]); 21A9 CC1043 ldd #_error_msg+25 21AC 163AE3 jsr _puts 21AF ; break; 21AF 18200198 lbra L70 21B3 L110: 21B3 ; case ticks: 21B3 ; if (argc > 1) 21B3 ECE1D5 ldd -43,x 21B6 8C0001 cpd #1 21B9 2F0A ble L111 21BB ; puts(error_msg[1]); 21BB CC1043 ldd #_error_msg+25 21BE 163AE3 jsr _puts 21C1 18200186 lbra L70 21C5 L111: 21C5 ; else 21C5 ; shellcmd_ticks(); 21C5 16251C jsr _shellcmd_ticks 21C8 ; break; 21C8 1820017F lbra L70 21CC L114: 21CC ; case start: 21CC ; if ((argc != 2) || 21CC ECE1D5 ldd -43,x 21CF 8C0002 cpd #2 21D2 2610 bne L117 21D4 EDE1D7 ldy -41,x 21D7 ED42 ldy 2,y 21D9 E640 ldab 0,y 21DB 87 clra 21DC 163CE8 jsr _isdigit 21DF 8C0000 cpd #0 21E2 260A bne L115 21E4 L117: 21E4 ; (!isdigit(*argv[1]))) 21E4 ; puts(error_msg[1]); 21E4 CC1043 ldd #_error_msg+25 21E7 163AE3 jsr _puts 21EA 1820015D lbra L70 21EE L115: 21EE ; else 21EE ; shellcmd_startTask(atoi(argv[1])); 21EE EDE1D7 ldy -41,x 21F1 EC42 ldd 2,y 21F3 163F43 jsr _atoi 21F6 87 clra 21F7 162544 jsr _shellcmd_startTask 21FA ; break; 21FA 1820014D lbra L70 21FE L119: 21FE ; case stop: 21FE ; if ((argc != 2) || 21FE ECE1D5 ldd -43,x 2201 8C0002 cpd #2 2204 2610 bne L122 2206 EDE1D7 ldy -41,x 2209 ED42 ldy 2,y 220B E640 ldab 0,y 220D 87 clra 220E 163CE8 jsr _isdigit 2211 8C0000 cpd #0 2214 260A bne L120 2216 L122: 2216 ; (!isdigit(*argv[1]))) 2216 ; puts(error_msg[1]); 2216 CC1043 ldd #_error_msg+25 2219 163AE3 jsr _puts 221C 1820012B lbra L70 2220 L120: 2220 ; else 2220 ; shellcmd_stopTask(atoi(argv[1])); 2220 EDE1D7 ldy -41,x 2223 EC42 ldd 2,y 2225 163F43 jsr _atoi 2228 87 clra 2229 16256F jsr _shellcmd_stopTask 222C ; break; 222C 1820011B lbra L70 2230 L124: 2230 ; case priority: 2230 ; puts(error_msg[0]); 2230 CC102A ldd #_error_msg 2233 163AE3 jsr _puts 2236 ; break; 2236 18200111 lbra L70 223A L125: 223A ECE1D5 ldd -43,x 223D 8C0001 cpd #1 2240 270A beq L128 2242 ECE1D5 ldd -43,x 2245 8C0004 cpd #4 2248 2709 beq L129 224A 2055 bra L126 224C X2: 224C ; case time: 224C ; switch (argc) { 224C L128: 224C ; case 1: 224C ; shellcmd_time(); 224C 162596 jsr _shellcmd_time 224F ; break; 224F 182000F8 lbra L70 2253 L129: 2253 ; case 4: 2253 ; if (argv[1] && argv[2] && argv[3]) 2253 EDE1D7 ldy -41,x 2256 EC42 ldd 2,y 2258 273D beq L130 225A EDE1D7 ldy -41,x 225D EC44 ldd 4,y 225F 2736 beq L130 2261 EDE1D7 ldy -41,x 2264 EC46 ldd 6,y 2266 272F beq L130 2268 ; set_sysTime(atoi(argv[1]), 2268 EDE1D7 ldy -41,x 226B EC42 ldd 2,y 226D 163F43 jsr _atoi 2270 6CE1C8 std -56,x 2273 EDE1D7 ldy -41,x 2276 EC44 ldd 4,y 2278 163F43 jsr _atoi 227B 6CE1C6 std -58,x 227E EDE1D7 ldy -41,x 2281 EC46 ldd 6,y 2283 163F43 jsr _atoi 2286 6C82 std 2,sp 2288 ECE1C6 ldd -58,x 228B 6C80 std 0,sp 228D ECE1C8 ldd -56,x 2290 161C4F jsr _set_sysTime 2293 182000B4 lbra L70 2297 L130: 2297 ; atoi(argv[2]), 2297 ; atoi(argv[3])); 2297 ; else 2297 ; puts(error_msg[1]); 2297 CC1043 ldd #_error_msg+25 229A 163AE3 jsr _puts 229D ; break; 229D 182000AA lbra L70 22A1 L126: 22A1 ; default: 22A1 ; puts(error_msg[1]); 22A1 CC1043 ldd #_error_msg+25 22A4 163AE3 jsr _puts 22A7 ; } 22A7 ; break; 22A7 182000A0 lbra L70 22AB L134: 22AB ; case freemem: 22AB ; shellcmd_freeMemCheck(); 22AB 16269F jsr _shellcmd_freeMemCheck 22AE ; break; 22AE 18200099 lbra L70 22B2 L135: 22B2 ; case kdb: 22B2 ; if (argc < 2) 22B2 ECE1D5 ldd -43,x 22B5 8C0002 cpd #2 22B8 2C0A bge L136 22BA ; puts(error_msg[1]); 22BA CC1043 ldd #_error_msg+25 22BD 163AE3 jsr _puts 22C0 18200087 lbra L70 22C4 L136: 22C4 ; else 22C4 ; shellcmd_kdb(atoi(argv[1])); 22C4 EDE1D7 ldy -41,x 22C7 EC42 ldd 2,y 22C9 163F43 jsr _atoi 22CC 1626B7 jsr _shellcmd_kdb 22CF ; break; 22CF 18200078 lbra L70 22D3 L139: 22D3 ; case quit: 22D3 ; shellcmd_quitShell(); 22D3 1626C6 jsr _shellcmd_quitShell 22D6 ; return 1; 22D6 CC0001 ldd #1 22D9 182000AB lbra L3 22DD L140: 22DD ; case taskname: 22DD ; // start a stopped task that's already created 22DD ; cmd = 0; 22DD 69E1D4 clr -44,x 22E0 691F clr -1,x 22E2 2042 bra L144 22E4 L141: 22E4 ; for (i=0; i 2,x 238C _shellcmd_help:: 238C ; 238C ; } // end shell() 238C ; 238C ; 238C ; 238C ; 238C ; 238C ; void shellcmd_help(char *argv1) { 238C ; 238C ; puts(error_msg[0]); 238C CC102A ldd #_error_msg 238F 163AE3 jsr _puts 2392 ; } 2392 L159: 2392 .dbline 0 ; func end 2392 3D rts 2393 ; start -> -2,x 2393 ; max -> -1,x 2393 ; tid -> 3,x 2393 _shellcmd_tcb:: 2393 3B pshd 2394 34 pshx 2395 B775 tfr s,x 2397 1BF1EA leas -22,sp 239A ; 239A ; 239A ; 239A ; void shellcmd_tcb(signed char tid) { 239A ; 239A ; // Local Variables 239A ; unsigned char max, start; 239A ; 239A ; if (tid >= MAXTASKS) { 239A E603 ldab 3,x 239C C108 cmpb #8 239E 2D0A blt L161 23A0 ; puts(error_msg[2]); 23A0 CC105C ldd #_error_msg+50 23A3 163AE3 jsr _puts 23A6 ; return; 23A6 182000A4 lbra L160 23AA L161: 23AA ; } 23AA ; 23AA ; if (tid < 0) { 23AA E703 tst 3,x 23AC 2C08 bge L164 23AE ; start = 0; 23AE 691E clr -2,x 23B0 ; max = MAXTASKS; 23B0 C608 ldab #8 23B2 6B1F stab -1,x 23B4 ; } 23B4 200F bra L165 23B6 L164: 23B6 ; else { 23B6 ; start = tid; 23B6 E603 ldab 3,x 23B8 B714 tfr b,d 23BA 6B1E stab -2,x 23BC ; max = tid + 1; 23BC E603 ldab 3,x 23BE B714 tfr b,d 23C0 C30001 addd #1 23C3 6B1F stab -1,x 23C5 ; } 23C5 L165: 23C5 ; 23C5 ; puts("\nTask Control Block:"); 23C5 CC290E ldd #L166 23C8 163AE3 jsr _puts 23CB E61E ldab -2,x 23CD 6B03 stab 3,x 23CF 2065 bra L170 23D1 L167: 23D1 ; for (tid=start; tid -1,x 2454 ; option -> 3,x 2454 _shellcmd_rcb:: 2454 3B pshd 2455 34 pshx 2456 B775 tfr s,x 2458 1B9E leas -2,sp 245A ; 245A ; 245A ; 245A ; 245A ; void shellcmd_rcb(signed char option) { 245A ; 245A ; // Local Variables 245A ; unsigned char rid; 245A ; 245A ; 245A ; 245A ; // print all 245A ; if (option == -1) { 245A E603 ldab 3,x 245C C1FF cmpb #-1 245E 261B bne L178 2460 691F clr -1,x 2462 200F bra L183 2464 L180: 2464 E61F ldab -1,x 2466 B714 tfr b,d 2468 1624D4 jsr _shellcmd_rcbPrint 246B L181: 246B E61F ldab -1,x 246D 87 clra 246E C30001 addd #1 2471 6B1F stab -1,x 2473 L183: 2473 ; for (rid=0; rid= NUMRESOURCES) { 24A7 E603 ldab 3,x 24A9 C104 cmpb #4 24AB 2D08 blt L192 24AD ; puts(error_msg[6]); 24AD CC10C0 ldd #_error_msg+150 24B0 163AE3 jsr _puts 24B3 ; return; 24B3 2019 bra L177 24B5 L192: 24B5 ; } 24B5 ; else 24B5 ; shellcmd_rcbPrint(option); 24B5 E603 ldab 3,x 24B7 B714 tfr b,d 24B9 1624D4 jsr _shellcmd_rcbPrint 24BC ; 24BC ; } 24BC L185: 24BC L179: 24BC ; 24BC ; 24BC ; puts ("-----------+----------+------------+------------+"); 24BC CC27CB ldd #L195 24BF 163AE3 jsr _puts 24C2 ; 24C2 ; puts("\nState: 0=notbusy, 1=busy"); 24C2 CC27B1 ldd #L196 24C5 163AE3 jsr _puts 24C8 ; puts("Owner: 0..15=task ID, 255=nobody"); 24C8 CC2790 ldd #L197 24CB 163AE3 jsr _puts 24CE ; 24CE ; } 24CE L177: 24CE B757 tfr x,s 24D0 30 pulx 24D1 1B82 leas 2,sp 24D3 .dbline 0 ; func end 24D3 3D rts 24D4 ; rid -> 3,x 24D4 _shellcmd_rcbPrint:: 24D4 3B pshd 24D5 34 pshx 24D6 B775 tfr s,x 24D8 1B94 leas -12,sp 24DA ; 24DA ; 24DA ; 24DA ; void shellcmd_rcbPrint(signed char rid) { 24DA ; 24DA ; puts ("-----------+----------+------------+------------+"); 24DA CC27CB ldd #L195 24DD 163AE3 jsr _puts 24E0 ; 24E0 ; INTR_OFF(); 24E0 1410 sei 24E2 24E2 ; printf("RsrcID: %2d | State: %x | Owner: %3d | Waiting: %d |\n", 24E2 E603 ldab 3,x 24E4 B714 tfr b,d 24E6 87 clra 24E7 161A53 jsr _get_resource_state 24EA 6C1E std -2,x 24EC E603 ldab 3,x 24EE B714 tfr b,d 24F0 87 clra 24F1 161A7A jsr _get_resource_owner 24F4 6C1C std -4,x 24F6 E603 ldab 3,x 24F8 B714 tfr b,d 24FA 87 clra 24FB 161AA1 jsr _get_resource_queuelen 24FE 6C86 std 6,sp 2500 ED1C ldy -4,x 2502 6D84 sty 4,sp 2504 ED1E ldy -2,x 2506 6D82 sty 2,sp 2508 E603 ldab 3,x 250A B714 tfr b,d 250C 6C80 std 0,sp 250E CC275A ldd #L199 2511 163B1B jsr _printf 2514 ; rid, 2514 ; get_resource_state(rid), 2514 ; get_resource_owner(rid), 2514 ; get_resource_queuelen(rid)); 2514 ; INTR_ON(); 2514 10EF cli 2516 2516 ; 2516 ; } 2516 L198: 2516 B757 tfr x,s 2518 30 pulx 2519 1B82 leas 2,sp 251B .dbline 0 ; func end 251B 3D rts 251C ; lreg1 -> -4,x 251C ; lreg2 -> -8,x 251C _shellcmd_ticks:: 251C 34 pshx 251D B775 tfr s,x 251F 1B94 leas -12,sp 2521 ; 2521 ; 2521 ; 2521 ; void shellcmd_ticks(void) { 2521 ; 2521 ; INTR_OFF(); 2521 1410 sei 2523 2523 ; printf("ticks: %ld\n", system_tick); 2523 CD025A ldy #_system_tick 2526 1802401C movw 0,y,-4,x 252A 1802421E movw 2,y,-2,x 252E 1980 leay 0,sp 2530 18021C40 movw -4,x,0,y 2534 18021E42 movw -2,x,2,y 2538 CC274E ldd #L201 253B 163B1B jsr _printf 253E ; INTR_ON(); 253E 10EF cli 2540 2540 ; } 2540 L200: 2540 B757 tfr x,s 2542 30 pulx 2543 .dbline 0 ; func end 2543 3D rts 2544 ; id -> 3,x 2544 _shellcmd_startTask:: 2544 3B pshd 2545 34 pshx 2546 B775 tfr s,x 2548 1B9E leas -2,sp 254A ; 254A ; 254A ; 254A ; 254A ; void shellcmd_startTask(unsigned char id) { 254A ; 254A ; INTR_OFF(); 254A 1410 sei 254C 254C ; if (set_task_state(id, PENDING) == 0) 254C CC0001 ldd #1 254F 6C80 std 0,sp 2551 E603 ldab 3,x 2553 87 clra 2554 161639 jsr _set_task_state 2557 8C0000 cpd #0 255A 260B bne L203 255C ; printf("task %d started\n", id); 255C E603 ldab 3,x 255E 87 clra 255F 6C80 std 0,sp 2561 CC273D ldd #L205 2564 163B1B jsr _printf 2567 L203: 2567 ; INTR_ON(); 2567 10EF cli 2569 2569 ; } 2569 L202: 2569 B757 tfr x,s 256B 30 pulx 256C 1B82 leas 2,sp 256E .dbline 0 ; func end 256E 3D rts 256F ; id -> 3,x 256F _shellcmd_stopTask:: 256F 3B pshd 2570 34 pshx 2571 B775 tfr s,x 2573 1B9E leas -2,sp 2575 ; 2575 ; 2575 ; 2575 ; 2575 ; void shellcmd_stopTask(unsigned char id) { 2575 ; 2575 ; if ((set_task_state(id, STOPPED)) == 0) 2575 CC0004 ldd #4 2578 6C80 std 0,sp 257A E603 ldab 3,x 257C 87 clra 257D 161639 jsr _set_task_state 2580 8C0000 cpd #0 2583 260B bne L207 2585 ; printf("task %d stopped\n", id); 2585 E603 ldab 3,x 2587 87 clra 2588 6C80 std 0,sp 258A CC272C ldd #L209 258D 163B1B jsr _printf 2590 L207: 2590 ; 2590 ; } 2590 L206: 2590 B757 tfr x,s 2592 30 pulx 2593 1B82 leas 2,sp 2595 .dbline 0 ; func end 2595 3D rts 2596 ; lreg1 -> -4,x 2596 ; lreg2 -> -8,x 2596 ; ?temp -> -29,x 2596 ; milliseconds -> -25,x 2596 ; seconds -> -23,x 2596 ; minutes -> -22,x 2596 ; hours -> -21,x 2596 ; time -> -20,x 2596 ; remainder2 -> -16,x 2596 ; remainder1 -> -12,x 2596 _shellcmd_time:: 2596 34 pshx 2597 B775 tfr s,x 2599 1BF1DA leas -38,sp 259C ; 259C ; 259C ; 259C ; 259C ; void shellcmd_time(void) { 259C ; 259C ; // LOCAL VARIABLES 259C ; unsigned long int remainder1, remainder2, time; 259C ; char hours, minutes, seconds; 259C ; int milliseconds; 259C ; 259C ; 259C ; // get the current time, in milliseconds 259C ; time = get_sysTime(); 259C 161BFA jsr _get_sysTime 259F 19E1E3 leay -29,x 25A2 18021C40 movw -4,x,0,y 25A6 18021E42 movw -2,x,2,y 25AA 19E1E3 leay -29,x 25AD 1802401C movw 0,y,-4,x 25B1 1802421E movw 2,y,-2,x 25B5 19E1EC leay -20,x 25B8 18021C40 movw -4,x,0,y 25BC 18021E42 movw -2,x,2,y 25C0 ; 25C0 ; // convert to hh:mm:ss.ms 25C0 ; hours = time / mS_PER_HOUR; 25C0 19E1EC leay -20,x 25C3 1802401C movw 0,y,-4,x 25C7 1802421E movw 2,y,-2,x 25CB CD2728 ldy #L211 25CE 18024018 movw 0,y,-8,x 25D2 1802421A movw 2,y,-6,x 25D6 16396B jsr __ludiv 25D9 16387C jsr __lreg2d 25DC 6BE1EB stab -21,x 25DF ; remainder1 = time % mS_PER_HOUR; 25DF 19E1EC leay -20,x 25E2 1802401C movw 0,y,-4,x 25E6 1802421E movw 2,y,-2,x 25EA CD2728 ldy #L211 25ED 18024018 movw 0,y,-8,x 25F1 1802421A movw 2,y,-6,x 25F5 163989 jsr __lumod 25F8 1914 leay -12,x 25FA 18021C40 movw -4,x,0,y 25FE 18021E42 movw -2,x,2,y 2602 ; minutes = remainder1 / mS_PER_MINUTE; 2602 1914 leay -12,x 2604 1802401C movw 0,y,-4,x 2608 1802421E movw 2,y,-2,x 260C CD2724 ldy #L212 260F 18024018 movw 0,y,-8,x 2613 1802421A movw 2,y,-6,x 2617 16396B jsr __ludiv 261A 16387C jsr __lreg2d 261D 6BE1EA stab -22,x 2620 ; remainder2 = remainder1 % mS_PER_MINUTE; 2620 1914 leay -12,x 2622 1802401C movw 0,y,-4,x 2626 1802421E movw 2,y,-2,x 262A CD2724 ldy #L212 262D 18024018 movw 0,y,-8,x 2631 1802421A movw 2,y,-6,x 2635 163989 jsr __lumod 2638 1910 leay -16,x 263A 18021C40 movw -4,x,0,y 263E 18021E42 movw -2,x,2,y 2642 ; seconds = remainder2 / mS_PER_SECOND; 2642 1910 leay -16,x 2644 1802401C movw 0,y,-4,x 2648 1802421E movw 2,y,-2,x 264C CD2720 ldy #L213 264F 18024018 movw 0,y,-8,x 2653 1802421A movw 2,y,-6,x 2657 16396B jsr __ludiv 265A 16387C jsr __lreg2d 265D 6BE1E9 stab -23,x 2660 ; milliseconds = remainder2 % mS_PER_SECOND; 2660 1910 leay -16,x 2662 1802401C movw 0,y,-4,x 2666 1802421E movw 2,y,-2,x 266A CD2720 ldy #L213 266D 18024018 movw 0,y,-8,x 2671 1802421A movw 2,y,-6,x 2675 163989 jsr __lumod 2678 16387C jsr __lreg2d 267B 6CE1E7 std -25,x 267E ; 267E ; printf(" %d:%d:%d.%d\n", hours, minutes,seconds, milliseconds); 267E EDE1E7 ldy -25,x 2681 6D86 sty 6,sp 2683 E6E1E9 ldab -23,x 2686 87 clra 2687 6C84 std 4,sp 2689 E6E1EA ldab -22,x 268C 87 clra 268D 6C82 std 2,sp 268F E6E1EB ldab -21,x 2692 87 clra 2693 6C80 std 0,sp 2695 CC2712 ldd #L214 2698 163B1B jsr _printf 269B ; 269B ; } 269B L210: 269B B757 tfr x,s 269D 30 pulx 269E .dbline 0 ; func end 269E 3D rts 269F _shellcmd_freeMemCheck:: 269F 34 pshx 26A0 B775 tfr s,x 26A2 1B9E leas -2,sp 26A4 ; 26A4 ; 26A4 ; 26A4 ; 26A4 ; void shellcmd_freeMemCheck(void) { 26A4 ; 26A4 ; 26A4 ; INTR_OFF(); 26A4 1410 sei 26A6 26A6 ; printf("approximate free heap memory: %d bytes\n", get_free_memory()); 26A6 161AC8 jsr _get_free_memory 26A9 6C80 std 0,sp 26AB CC26EA ldd #L216 26AE 163B1B jsr _printf 26B1 ; INTR_ON(); 26B1 10EF cli 26B3 26B3 ; 26B3 ; } 26B3 L215: 26B3 B757 tfr x,s 26B5 30 pulx 26B6 .dbline 0 ; func end 26B6 3D rts 26B7 ; onoff -> 2,x 26B7 _shellcmd_kdb:: 26B7 3B pshd 26B8 34 pshx 26B9 B775 tfr s,x 26BB ; 26BB ; 26BB ; 26BB ; void shellcmd_kdb(int onoff) { 26BB ; 26BB ; 26BB ; kdb_trace = onoff; 26BB EC02 ldd 2,x 26BD 7B0206 stab _kdb_trace 26C0 ; 26C0 ; } 26C0 L217: 26C0 B757 tfr x,s 26C2 30 pulx 26C3 1B82 leas 2,sp 26C5 .dbline 0 ; func end 26C5 3D rts 26C6 _shellcmd_quitShell:: 26C6 ; 26C6 ; 26C6 ; 26C6 ; 26C6 ; void shellcmd_quitShell(void) { 26C6 ; 26C6 ; puts("exiting shell"); 26C6 CC26DC ldd #L219 26C9 163AE3 jsr _puts 26CC ; puts("\n"); 26CC CC26DA ldd #L220 26CF 163AE3 jsr _puts 26D2 ; shellcmd_stopTask(get_task_id()); 26D2 16156C jsr _get_task_id 26D5 87 clra 26D6 16256F jsr _shellcmd_stopTask 26D9 ; 26D9 ; } 26D9 L218: 26D9 .dbline 0 ; func end 26D9 3D rts 26DA L220: 26DA 0A00 .byte 10,0 26DC L219: 26DC 65786974696E67207368656C6C00 .byte 'e,'x,'i,'t,'i,'n,'g,32,'s,'h,'e,'l,'l,0 26EA L216: 26EA 617070726F78696D6174652066726565 .byte 'a,'p,'p,'r,'o,'x,'i,'m,'a,'t,'e,32,'f,'r,'e,'e 26FA 2068656170206D656D6F72793A202564 .byte 32,'h,'e,'a,'p,32,'m,'e,'m,'o,'r,'y,58,32,37,'d 270A 2062797465730A00 .byte 32,'b,'y,'t,'e,'s,10,0 2712 L214: 2712 2025643A25643A25642E25640A00 .byte 32,37,'d,58,37,'d,58,37,'d,46,37,'d,10,0 2720 L213: 2720 000003E8 .word 0,1000 2724 L212: 2724 0000EA60 .word 0,60000 2728 L211: 2728 0036EE80 .word 54,61056 272C L209: 272C 7461736B2025642073746F707065640A .byte 't,'a,'s,'k,32,37,'d,32,'s,'t,'o,'p,'p,'e,'d,10 273C 00 .byte 0 273D L205: 273D 7461736B20256420737461727465640A .byte 't,'a,'s,'k,32,37,'d,32,'s,'t,'a,'r,'t,'e,'d,10 274D 00 .byte 0 274E L201: 274E 7469636B733A20256C640A00 .byte 't,'i,'c,'k,'s,58,32,37,'l,'d,10,0 275A L199: 275A 5273726349443A20253264207C205374 .byte 'R,'s,'r,'c,'I,'D,58,32,37,50,'d,32,124,32,'S,'t 276A 6174653A202578207C204F776E65723A .byte 'a,'t,'e,58,32,37,'x,32,124,32,'O,'w,'n,'e,'r,58 277A 20253364207C2057616974696E673A20 .byte 32,37,51,'d,32,124,32,'W,'a,'i,'t,'i,'n,'g,58,32 278A 2564207C0A00 .byte 37,'d,32,124,10,0 2790 L197: 2790 4F776E65723A20302E2E31353D746173 .byte 'O,'w,'n,'e,'r,58,32,48,46,46,49,53,61,'t,'a,'s 27A0 6B2049442C203235353D6E6F626F6479 .byte 'k,32,'I,'D,44,32,50,53,53,61,'n,'o,'b,'o,'d,'y 27B0 00 .byte 0 27B1 L196: 27B1 0A53746174653A20303D6E6F74627573 .byte 10,'S,'t,'a,'t,'e,58,32,48,61,'n,'o,'t,'b,'u,'s 27C1 792C20313D6275737900 .byte 'y,44,32,49,61,'b,'u,'s,'y,0 27CB L195: 27CB 2D2D2D2D2D2D2D2D2D2D2D2B2D2D2D2D .byte 45,45,45,45,45,45,45,45,45,45,45,43,45,45,45,45 27DB 2D2D2D2D2D2D2B2D2D2D2D2D2D2D2D2D .byte 45,45,45,45,45,45,43,45,45,45,45,45,45,45,45,45 27EB 2D2D2D2B2D2D2D2D2D2D2D2D2D2D2D2D .byte 45,45,45,43,45,45,45,45,45,45,45,45,45,45,45,45 27FB 2B00 .byte 43,0 27FD L176: 27FD 4D6573736167653A205B206269743720 .byte 'M,'e,'s,'s,'a,'g,'e,58,32,91,32,'b,'i,'t,55,32 280D 7C2062697436207C2062697435207C20 .byte 124,32,'b,'i,'t,54,32,124,32,'b,'i,'t,53,32,124,32 281D 62697434207C2062697433207C206269 .byte 'b,'i,'t,52,32,124,32,'b,'i,'t,51,32,124,32,'b,'i 282D 7432207C207072696F207C2073746174 .byte 't,50,32,124,32,'p,'r,'i,'o,32,124,32,'s,'t,'a,'t 283D 65205D00 .byte 'e,32,93,0 2841 L175: 2841 0A53746174653A20303D69646C652C20 .byte 10,'S,'t,'a,'t,'e,58,32,48,61,'i,'d,'l,'e,44,32 2851 313D70656E64696E672C20323D72756E .byte 49,61,'p,'e,'n,'d,'i,'n,'g,44,32,50,61,'r,'u,'n 2861 6E696E672C20333D77616974696E672C .byte 'n,'i,'n,'g,44,32,51,61,'w,'a,'i,'t,'i,'n,'g,44 2871 20343D73746F7070656400 .byte 32,52,61,'s,'t,'o,'p,'p,'e,'d,0 287C L174: 287C 4E616D653A20253873207C2049443A20 .byte 'N,'a,'m,'e,58,32,37,56,'s,32,124,32,'I,'D,58,32 288C 2564207C2053746174653A202564207C .byte 37,'d,32,124,32,'S,'t,'a,'t,'e,58,32,37,'d,32,124 289C 205072696F3A20253364207C20416464 .byte 32,'P,'r,'i,'o,58,32,37,51,'d,32,124,32,'A,'d,'d 28AC 723A20253478207C204D7367733A2030 .byte 'r,58,32,37,52,'x,32,124,32,'M,'s,'g,'s,58,32,48 28BC 78253278207C0A00 .byte 'x,37,50,'x,32,124,10,0 28C4 L173: 28C4 2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2B .byte 45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,43 28D4 2D2D2D2D2D2D2D2B2D2D2D2D2D2D2D2D .byte 45,45,45,45,45,45,45,43,45,45,45,45,45,45,45,45 28E4 2D2D2B2D2D2D2D2D2D2D2D2D2D2D2B2D .byte 45,45,43,45,45,45,45,45,45,45,45,45,45,45,43,45 28F4 2D2D2D2D2D2D2D2D2D2D2D2B2D2D2D2D .byte 45,45,45,45,45,45,45,45,45,45,45,43,45,45,45,45 2904 2D2D2D2D2D2D2D2D2B00 .byte 45,45,45,45,45,45,45,45,43,0 290E L166: 290E 0A5461736B20436F6E74726F6C20426C .byte 10,'T,'a,'s,'k,32,'C,'o,'n,'t,'r,'o,'l,32,'B,'l 291E 6F636B3A00 .byte 'o,'c,'k,58,0 2923 L106: 2923 2D6200 .byte 45,'b,0 2926 L88: 2926 71756974202D2D207175697420746865 .byte 'q,'u,'i,'t,32,45,45,32,'q,'u,'i,'t,32,'t,'h,'e 2936 207368656C6C20286361726566756C6C .byte 32,'s,'h,'e,'l,'l,32,40,'c,'a,'r,'e,'f,'u,'l,'l 2946 212900 .byte 33,41,0 2949 L87: 2949 6B6462205B317C305D202D2D20747572 .byte 'k,'d,'b,32,91,49,124,48,93,32,45,45,32,'t,'u,'r 2959 6E206B65726E656C206465627567206F .byte 'n,32,'k,'e,'r,'n,'e,'l,32,'d,'e,'b,'u,'g,32,'o 2969 6E2F6F666600 .byte 'n,47,'o,'f,'f,0 296F L86: 296F 667265656D656D202D2D206765742061 .byte 'f,'r,'e,'e,'m,'e,'m,32,45,45,32,'g,'e,'t,32,'a 297F 7070726F78696D617465206672656520 .byte 'p,'p,'r,'o,'x,'i,'m,'a,'t,'e,32,'f,'r,'e,'e,32 298F 52414D20737061636500 .byte 'R,'A,'M,32,'s,'p,'a,'c,'e,0 2999 L85: 2999 74696D65205B3C6872733E203C6D696E .byte 't,'i,'m,'e,32,91,60,'h,'r,'s,62,32,60,'m,'i,'n 29A9 3E203C7365633E205D2D2D2064697370 .byte 62,32,60,'s,'e,'c,62,32,93,45,45,32,'d,'i,'s,'p 29B9 6C61792F736574207468652063757272 .byte 'l,'a,'y,47,'s,'e,'t,32,'t,'h,'e,32,'c,'u,'r,'r 29C9 656E742073797374656D2074696D6500 .byte 'e,'n,'t,32,'s,'y,'s,'t,'e,'m,32,'t,'i,'m,'e,0 29D9 L84: 29D9 7072696F72697479203C7461736B5F69 .byte 'p,'r,'i,'o,'r,'i,'t,'y,32,60,'t,'a,'s,'k,95,'i 29E9 643E2C203C7461736B5F7072696F7269 .byte 'd,62,44,32,60,'t,'a,'s,'k,95,'p,'r,'i,'o,'r,'i 29F9 74793E20202D2D206368616E67652070 .byte 't,'y,62,32,32,45,45,32,'c,'h,'a,'n,'g,'e,32,'p 2A09 72696F00 .byte 'r,'i,'o,0 2A0D L83: 2A0D 73746F70203C7461736B5F69643E2020 .byte 's,'t,'o,'p,32,60,'t,'a,'s,'k,95,'i,'d,62,32,32 2A1D 2D2D2073746F702061207461736B00 .byte 45,45,32,'s,'t,'o,'p,32,'a,32,'t,'a,'s,'k,0 2A2C L82: 2A2C 7374617274203C7461736B5F69643E20 .byte 's,'t,'a,'r,'t,32,60,'t,'a,'s,'k,95,'i,'d,62,32 2A3C 2D2D2073746172742061207461736B00 .byte 45,45,32,'s,'t,'a,'r,'t,32,'a,32,'t,'a,'s,'k,0 2A4C L81: 2A4C 7469636B73202D2D2073686F77732073 .byte 't,'i,'c,'k,'s,32,45,45,32,'s,'h,'o,'w,'s,32,'s 2A5C 797374656D207469636B00 .byte 'y,'s,'t,'e,'m,32,'t,'i,'c,'k,0 2A67 L80: 2A67 726362205B5B7461736B5F69645D207C .byte 'r,'c,'b,32,91,91,'t,'a,'s,'k,95,'i,'d,93,32,124 2A77 205B2D625D5D202D2D207072696E7473 .byte 32,91,45,'b,93,93,32,45,45,32,'p,'r,'i,'n,'t,'s 2A87 207265736F7572636520636F6E74726F .byte 32,'r,'e,'s,'o,'u,'r,'c,'e,32,'c,'o,'n,'t,'r,'o 2A97 6C20626C6F636B00 .byte 'l,32,'b,'l,'o,'c,'k,0 2A9F L79: 2A9F 746362205B7461736B5F69645D202D2D .byte 't,'c,'b,32,91,'t,'a,'s,'k,95,'i,'d,93,32,45,45 2AAF 207072696E7473207461736B20636F6E .byte 32,'p,'r,'i,'n,'t,'s,32,'t,'a,'s,'k,32,'c,'o,'n 2ABF 74726F6C20626C6F636B00 .byte 't,'r,'o,'l,32,'b,'l,'o,'c,'k,0 2ACA L78: 2ACA 68656C70205B636D645D202D2D206865 .byte 'h,'e,'l,'p,32,91,'c,'m,'d,93,32,45,45,32,'h,'e 2ADA 6C70206F6E2061207370656369666963 .byte 'l,'p,32,'o,'n,32,'a,32,'s,'p,'e,'c,'i,'f,'i,'c 2AEA 20636F6D6D616E6400 .byte 32,'c,'o,'m,'m,'a,'n,'d,0 2AF3 L77: 2AF3 5B5D202D2D206F7074696F6E616C2061 .byte 91,93,32,45,45,32,'o,'p,'t,'i,'o,'n,'a,'l,32,'a 2B03 7267756D656E74730A00 .byte 'r,'g,'u,'m,'e,'n,'t,'s,10,0 2B0D L76: 2B0D 3C3E202D2D2072657175697265642061 .byte 60,62,32,45,45,32,'r,'e,'q,'u,'i,'r,'e,'d,32,'a 2B1D 7267756D656E747300 .byte 'r,'g,'u,'m,'e,'n,'t,'s,0 2B26 L75: 2B26 2D2D2D48454C502D2D2D0A00 .byte 45,45,45,'H,'E,'L,'P,45,45,45,10,0 2B32 L66: 2B32 7175697400 .byte 'q,'u,'i,'t,0 2B37 L63: 2B37 6B646200 .byte 'k,'d,'b,0 2B3B L60: 2B3B 667265656D656D00 .byte 'f,'r,'e,'e,'m,'e,'m,0 2B43 L57: 2B43 74696D6500 .byte 't,'i,'m,'e,0 2B48 L54: 2B48 7072696F7269747900 .byte 'p,'r,'i,'o,'r,'i,'t,'y,0 2B51 L51: 2B51 73746F7000 .byte 's,'t,'o,'p,0 2B56 L48: 2B56 737461727400 .byte 's,'t,'a,'r,'t,0 2B5C L45: 2B5C 7469636B7300 .byte 't,'i,'c,'k,'s,0 2B62 L42: 2B62 72636200 .byte 'r,'c,'b,0 2B66 L39: 2B66 74636200 .byte 't,'c,'b,0 2B6A L36: 2B6A 68656C7000 .byte 'h,'e,'l,'p,0 .module sysInit.c .area text ; id -> -2,x 2B6F _sysInit:: 2B6F 34 pshx 2B70 B775 tfr s,x 2B72 1B94 leas -12,sp 2B74 ; // sysInit.c 2B74 ; 2B74 ; #include <912d60.h> 2B74 ; #include 2B74 ; #include "kernel.h" 2B74 ; 2B74 ; 2B74 ; 2B74 ; // TASK PROTOTYPES 2B74 ; int task1(void); 2B74 ; int task2(void); 2B74 ; 2B74 ; 2B74 ; 2B74 ; 2B74 ; int sysInit(void) { 2B74 ; 2B74 ; // LOCAL VARIABLES 2B74 ; int id; 2B74 ; 2B74 ; 2B74 ; /* must create all the tasks without interrupt, because this task 2B74 ; will die when it finishes. */ 2B74 ; INTR_OFF(); 2B74 1410 sei 2B76 2B76 ; 2B76 ; 2B76 ; // set up the serial port 2B76 ; setbaud(BAUD38K); // actually running at 19K baud due to xtal speed 2B76 CC000D ldd #13 2B79 16358A jsr _setbaud 2B7C ; 2B7C ; // any additional user setup goes here 2B7C ; //---------------------------------------- 2B7C ; //| | 2B7C ; //---------------------------------------- 2B7C ; 2B7C ; 2B7C ; 2B7C ; // create task1 2B7C ; if (create_task("dummy", &task1, 18, IDLE, 0) < 0) 2B7C CC0000 ldd #0 2B7F 6C86 std 6,sp 2B81 CC0000 ldd #0 2B84 6C84 std 4,sp 2B86 CC0012 ldd #18 2B89 6C82 std 2,sp 2B8B CC2C12 ldd #_task1 2B8E 6C80 std 0,sp 2B90 CC2C08 ldd #L6 2B93 161872 jsr _create_task 2B96 8C0000 cpd #0 2B99 2C06 bge L4 2B9B ; puts("task1 failure"); 2B9B CC2BFA ldd #L7 2B9E 163AE3 jsr _puts 2BA1 L4: 2BA1 ; 2BA1 ; 2BA1 ; // create task2 2BA1 ; if (create_task("timer", &task2, 0, STOPPED, 255) < 0) 2BA1 CC00FF ldd #255 2BA4 6C86 std 6,sp 2BA6 CC0004 ldd #4 2BA9 6C84 std 4,sp 2BAB CC0000 ldd #0 2BAE 6C82 std 2,sp 2BB0 CC2C6E ldd #_task2 2BB3 6C80 std 0,sp 2BB5 CC2BF4 ldd #L10 2BB8 161872 jsr _create_task 2BBB 8C0000 cpd #0 2BBE 2C06 bge L8 2BC0 ; puts("task2 failure"); 2BC0 CC2BE6 ldd #L11 2BC3 163AE3 jsr _puts 2BC6 L8: 2BC6 ; 2BC6 ; 2BC6 ; 2BC6 ; // remove the sysInit task from memory 2BC6 ; set_task_state(get_task_id(), STOPPED); 2BC6 16156C jsr _get_task_id 2BC9 6C1C std -4,x 2BCB CC0004 ldd #4 2BCE 6C80 std 0,sp 2BD0 EC1C ldd -4,x 2BD2 87 clra 2BD3 161639 jsr _set_task_state 2BD6 ; remove_task(get_task_id()); 2BD6 16156C jsr _get_task_id 2BD9 87 clra 2BDA 1619EE jsr _remove_task 2BDD ; 2BDD ; 2BDD ; INTR_ON(); 2BDD 10EF cli 2BDF 2BDF ; 2BDF ; return 0; 2BDF CC0000 ldd #0 2BE2 L3: 2BE2 B757 tfr x,s 2BE4 30 pulx 2BE5 .dbline 0 ; func end 2BE5 3D rts 2BE6 L11: 2BE6 7461736B32206661696C75726500 .byte 't,'a,'s,'k,50,32,'f,'a,'i,'l,'u,'r,'e,0 2BF4 L10: 2BF4 74696D657200 .byte 't,'i,'m,'e,'r,0 2BFA L7: 2BFA 7461736B31206661696C75726500 .byte 't,'a,'s,'k,49,32,'f,'a,'i,'l,'u,'r,'e,0 2C08 L6: 2C08 64756D6D7900 .byte 'd,'u,'m,'m,'y,0 .module idleTask.c .area text 2C0E _idleTask:: 2C0E ; // idleTask.c 2C0E ; 2C0E ; #include <912D60.h> 2C0E ; #include "kernel.h" 2C0E ; 2C0E ; 2C0E ; 2C0E ; int idleTask(void) { 2C0E ; 2C0E ; // will eventually put cpu into low-power mode 2C0E ; return 0; 2C0E CC0000 ldd #0 2C11 L3: 2C11 .dbline 0 ; func end 2C11 3D rts .module task1.c .area text ; i -> -2,x 2C12 _task1:: 2C12 34 pshx 2C13 B775 tfr s,x 2C15 1B9E leas -2,sp 2C17 ; // task1.c 2C17 ; 2C17 ; #include 2C17 ; #include <912d60.h> 2C17 ; #include "semlib.h" 2C17 ; 2C17 ; 2C17 ; 2C17 ; /* dummy task to eat up time, and to give the kernel 2C17 ; something to multitask with */ 2C17 ; int task1 (void) { 2C17 ; 2C17 ; int i; 2C17 ; 2C17 ; //sem_get(COM1); 2C17 ; INTR_ON(); 2C17 10EF cli 2C19 2C19 CC0000 ldd #0 2C1C 6C1E std -2,x 2C1E L4: 2C1E L5: 2C1E ; 2C1E ; 2C1E ; //puts("T1 Starting"); 2C1E ; for (i=0; i<0x0800; i++); 2C1E EC1E ldd -2,x 2C20 C30001 addd #1 2C23 6C1E std -2,x 2C25 EC1E ldd -2,x 2C27 8C0800 cpd #2048 2C2A 2DF2 blt L4 2C2C CC0000 ldd #0 2C2F 6C1E std -2,x 2C31 L8: 2C31 L9: 2C31 ; //puts("T1.1"); 2C31 ; 2C31 ; for (i=0; i<0x1000; i++); 2C31 EC1E ldd -2,x 2C33 C30001 addd #1 2C36 6C1E std -2,x 2C38 EC1E ldd -2,x 2C3A 8C1000 cpd #4096 2C3D 2DF2 blt L8 2C3F CC0000 ldd #0 2C42 6C1E std -2,x 2C44 L12: 2C44 L13: 2C44 ; //puts("T1.2"); 2C44 ; 2C44 ; for (i=0; i<0x1A00; i++); 2C44 EC1E ldd -2,x 2C46 C30001 addd #1 2C49 6C1E std -2,x 2C4B EC1E ldd -2,x 2C4D 8C1A00 cpd #6656 2C50 2DF2 blt L12 2C52 CC0000 ldd #0 2C55 6C1E std -2,x 2C57 L16: 2C57 L17: 2C57 ; //puts("T1.3"); 2C57 ; 2C57 ; for (i=0; i<0x2000; i++); 2C57 EC1E ldd -2,x 2C59 C30001 addd #1 2C5C 6C1E std -2,x 2C5E EC1E ldd -2,x 2C60 8C2000 cpd #8192 2C63 2DF2 blt L16 2C65 ; //puts("T1 Finished"); 2C65 ; 2C65 ; //puts("-T1-"); 2C65 ; 2C65 ; 2C65 ; INTR_OFF(); 2C65 1410 sei 2C67 2C67 ; //sem_give(COM1); 2C67 ; 2C67 ; return 0; 2C67 CC0000 ldd #0 2C6A L3: 2C6A B757 tfr x,s 2C6C 30 pulx 2C6D .dbline 0 ; func end 2C6D 3D rts .module task2.c .area data --- 0000 L4: --- 0000 .blkb 1 .area idata --- 0000 00 .byte 0 .area data --- 0001 L5: --- 0001 .blkb 1 .area idata --- 0001 00 .byte 0 .area data --- 0002 L6: --- 0002 .blkb 1 .area idata --- 0002 00 .byte 0 .area data --- 0003 L7: --- 0003 .blkb 1 .area idata --- 0003 00 .byte 0 .area data --- 0004 L8: --- 0004 .blkb 1 .area idata --- 0004 00 .byte 0 .area data --- 0005 L9: --- 0005 .blkb 1 .area idata --- 0005 00 .byte 0 .area data --- 0006 L10: --- 0006 .blkb 1 .area idata --- 0006 00 .byte 0 .area data .area bss --- 0000 L11: --- 0000 .blkb 4 .area data --- 0007 L12: --- 0007 .blkb 1 .area idata --- 0007 01 .byte 1 .area data .area text ; lreg1 -> -4,x ; lreg2 -> -8,x ; delta_t -> -15,x ; redraw -> -11,x ; i -> -9,x 2C6E _task2:: 2C6E 34 pshx 2C6F B775 tfr s,x 2C71 1B90 leas -16,sp 2C73 ; // task2.c 2C73 ; 2C73 ; #include 2C73 ; #include <912d60.h> 2C73 ; #include "kernel.h" 2C73 ; 2C73 ; 2C73 ; 2C73 ; /* counts seconds and displays them */ 2C73 ; int task2 (void) { 2C73 ; 2C73 ; 2C73 ; char i; 2C73 ; unsigned long int delta_t; 2C73 ; extern unsigned long int time_tick; 2C73 ; 2C73 ; 2C73 ; static unsigned char hh=0, hm=0, hl=0, mh=0, ml=0, sh=0, sl=0; 2C73 ; static unsigned long int last_mark; 2C73 ; int redraw; 2C73 ; static char startup = 1; 2C73 ; 2C73 ; 2C73 ; INTR_ON(); 2C73 10EF cli 2C75 2C75 ; 2C75 ; 2C75 ; 2C75 ; delta_t = (time_tick - last_mark) * uS_PER_TIME_TICK; 2C75 CD0254 ldy #_time_tick 2C78 1802401C movw 0,y,-4,x 2C7C 1802421E movw 2,y,-2,x 2C80 CD0270 ldy #L11 2C83 18024018 movw 0,y,-8,x 2C87 1802421A movw 2,y,-6,x 2C8B 1638BA jsr __lsub 2C8E 18021E1A movw -2,x,-6,x 2C92 18021C18 movw -4,x,-8,x 2C96 CD2EBD ldy #L13 2C99 1802401C movw 0,y,-4,x 2C9D 1802421E movw 2,y,-2,x 2CA1 1638CB jsr __lmul 2CA4 1911 leay -15,x 2CA6 18021C40 movw -4,x,0,y 2CAA 18021E42 movw -2,x,2,y 2CAE ; 2CAE ; if (delta_t > uS_PER_SECOND) { 2CAE 1911 leay -15,x 2CB0 1802401C movw 0,y,-4,x 2CB4 1802421E movw 2,y,-2,x 2CB8 CD2EB9 ldy #L16 2CBB 18024018 movw 0,y,-8,x 2CBF 1802421A movw 2,y,-6,x 2CC3 163A4A jsr __lcmp 2CC6 182301E6 lbls L14 2CCA ; last_mark = time_tick; 2CCA CD0254 ldy #_time_tick 2CCD 1802401C movw 0,y,-4,x 2CD1 1802421E movw 2,y,-2,x 2CD5 CD0270 ldy #L11 2CD8 18021C40 movw -4,x,0,y 2CDC 18021E42 movw -2,x,2,y 2CE0 ; sl++; 2CE0 F60210 ldab L10 2CE3 87 clra 2CE4 C30001 addd #1 2CE7 7B0210 stab L10 2CEA ; redraw = 1; 2CEA CC0001 ldd #1 2CED 6C15 std -11,x 2CEF ; if (sl > 9) { 2CEF F60210 ldab L10 2CF2 C109 cmpb #9 2CF4 2312 bls L17 2CF6 ; sh++; 2CF6 F6020F ldab L9 2CF9 87 clra 2CFA C30001 addd #1 2CFD 7B020F stab L9 2D00 ; sl = 0; 2D00 790210 clr L10 2D03 ; redraw = 2; 2D03 CC0002 ldd #2 2D06 6C15 std -11,x 2D08 ; } 2D08 L17: 2D08 ; if (sh > 5) { 2D08 F6020F ldab L9 2D0B C105 cmpb #5 2D0D 2312 bls L19 2D0F ; ml++; 2D0F F6020E ldab L8 2D12 87 clra 2D13 C30001 addd #1 2D16 7B020E stab L8 2D19 ; sh = 0; 2D19 79020F clr L9 2D1C ; redraw = 4; 2D1C CC0004 ldd #4 2D1F 6C15 std -11,x 2D21 ; } 2D21 L19: 2D21 ; if (ml > 9) { 2D21 F6020E ldab L8 2D24 C109 cmpb #9 2D26 2312 bls L21 2D28 ; mh++; 2D28 F6020D ldab L7 2D2B 87 clra 2D2C C30001 addd #1 2D2F 7B020D stab L7 2D32 ; ml = 0; 2D32 79020E clr L8 2D35 ; redraw = 5; 2D35 CC0005 ldd #5 2D38 6C15 std -11,x 2D3A ; } 2D3A L21: 2D3A ; if (mh > 5) { 2D3A F6020D ldab L7 2D3D C105 cmpb #5 2D3F 2312 bls L23 2D41 ; hl++; 2D41 F6020C ldab L6 2D44 87 clra 2D45 C30001 addd #1 2D48 7B020C stab L6 2D4B ; mh = 0; 2D4B 79020D clr L7 2D4E ; redraw = 7; 2D4E CC0007 ldd #7 2D51 6C15 std -11,x 2D53 ; } 2D53 L23: 2D53 ; if (hl > 9) { 2D53 F6020C ldab L6 2D56 C109 cmpb #9 2D58 2312 bls L25 2D5A ; hm++; 2D5A F6020B ldab L5 2D5D 87 clra 2D5E C30001 addd #1 2D61 7B020B stab L5 2D64 ; hl = 0; 2D64 79020C clr L6 2D67 ; redraw = 8; 2D67 CC0008 ldd #8 2D6A 6C15 std -11,x 2D6C ; } 2D6C L25: 2D6C ; if (hm > 9) { 2D6C F6020B ldab L5 2D6F C109 cmpb #9 2D71 2312 bls L27 2D73 ; hh++; 2D73 F6020A ldab L4 2D76 87 clra 2D77 C30001 addd #1 2D7A 7B020A stab L4 2D7D ; hm = 0; 2D7D 79020B clr L5 2D80 ; redraw = 9; 2D80 CC0009 ldd #9 2D83 6C15 std -11,x 2D85 ; } 2D85 L27: 2D85 ; if (hh > 9) { 2D85 F6020A ldab L4 2D88 C109 cmpb #9 2D8A 2308 bls L29 2D8C ; hh = 0; 2D8C 79020A clr L4 2D8F ; redraw = 9; 2D8F CC0009 ldd #9 2D92 6C15 std -11,x 2D94 ; } 2D94 L29: 2D94 ; 2D94 ; 2D94 ; // display time 2D94 ; if (startup) { 2D94 F70211 tst L12 2D97 2760 beq L31 2D99 ; putchar(hh+48); 2D99 F6020A ldab L4 2D9C 87 clra 2D9D C30030 addd #48 2DA0 87 clra 2DA1 163558 jsr _putchar 2DA4 ; putchar(hm+48); 2DA4 F6020B ldab L5 2DA7 87 clra 2DA8 C30030 addd #48 2DAB 87 clra 2DAC 163558 jsr _putchar 2DAF ; putchar(hl+48); 2DAF F6020C ldab L6 2DB2 87 clra 2DB3 C30030 addd #48 2DB6 87 clra 2DB7 163558 jsr _putchar 2DBA ; putchar(':'); 2DBA CC003A ldd #58 2DBD 163558 jsr _putchar 2DC0 ; putchar(mh+48); 2DC0 F6020D ldab L7 2DC3 87 clra 2DC4 C30030 addd #48 2DC7 87 clra 2DC8 163558 jsr _putchar 2DCB ; putchar(ml+48); 2DCB F6020E ldab L8 2DCE 87 clra 2DCF C30030 addd #48 2DD2 87 clra 2DD3 163558 jsr _putchar 2DD6 ; putchar(':'); 2DD6 CC003A ldd #58 2DD9 163558 jsr _putchar 2DDC ; putchar(sh+48); 2DDC F6020F ldab L9 2DDF 87 clra 2DE0 C30030 addd #48 2DE3 87 clra 2DE4 163558 jsr _putchar 2DE7 ; putchar(sl+48); 2DE7 F60210 ldab L10 2DEA 87 clra 2DEB C30030 addd #48 2DEE 87 clra 2DEF 163558 jsr _putchar 2DF2 ; 2DF2 ; startup = 0; 2DF2 790211 clr L12 2DF5 ; } 2DF5 182000B7 lbra L32 2DF9 L31: 2DF9 ; else { 2DF9 ; for (i=0; i 2EC1 ; #include <912D60.h> 2EC1 ; #include "kernel.h" 2EC1 ; 2EC1 ; 2EC1 ; 2EC1 ; // FUNCTION PROTOTYPES 2EC1 ; void _start(void); 2EC1 ; 2EC1 ; 2EC1 ; 2EC1 ; /* Example code flow for all of these handlers: 2EC1 ; 2EC1 ; // IF interrupt isn't very time critical: 2EC1 ; figure out who cares, if anyone, then send a msg to the caring task 2EC1 ; 2EC1 ; 2EC1 ; if (resource[ADC].owner != 255) 2EC1 ; task[resource[ADC].owner].message |= ADC_MSG; 2EC1 ; 2EC1 ; 2EC1 ; 2EC1 ; // IF interrupt is time critical: (ie, there's data that needs to be serviced) 2EC1 ; get the data, put it in a buffer, then put the data in the message buffer 2EC1 ; 2EC1 ; task[resource[ADC].owner].message_data[ADC_MSG] = ADC; // ADC = correct port definition? 2EC1 ; */ 2EC1 ; 2EC1 ; 2EC1 ; 2EC1 ; 2EC1 ; 2EC1 ; // GLOBALS 2EC1 ; extern unsigned int interrupt_flags_ADC; 2EC1 ; extern unsigned int interrupt_flags_TC; 2EC1 ; 2EC1 ; 2EC1 ; 2EC1 ; 2EC1 ; 2EC1 ; #pragma interrupt_handler MDCOF_handler() 2EC1 ; 2EC1 ; void MDCOF_handler(void) { 2EC1 ; 2EC1 ; /*// LOCAL VARIABLES 2EC1 ; extern unsigned long int time_tick; 2EC1 ; 2EC1 ; // acknowledge the interrupt, incriment global time_tick 2EC1 ; MCFLG = 0x80; 2EC1 ; time_tick++; 2EC1 ; */ 2EC1 ; 2EC1 ; } 2EC1 L3: 2EC1 .dbline 0 ; func end 2EC1 0B rti 2EC2 _KWU_handler:: 2EC2 ; 2EC2 ; 2EC2 ; 2EC2 ; #pragma interrupt_handler KWU_handler() 2EC2 ; 2EC2 ; void KWU_handler(void) {} 2EC2 L4: 2EC2 .dbline 0 ; func end 2EC2 0B rti 2EC3 _ADC_handler:: 2EC3 ; 2EC3 ; 2EC3 ; 2EC3 ; #pragma interrupt_handler ADC_handler() 2EC3 ; 2EC3 ; void ADC_handler(void) {} 2EC3 L5: 2EC3 .dbline 0 ; func end 2EC3 0B rti 2EC4 _SCI1_handler:: 2EC4 ; 2EC4 ; 2EC4 ; 2EC4 ; /* #pragma interrupt_handler SCI0_handler() 2EC4 ; 2EC4 ; void SCI0_handler(void) { 2EC4 ; 2EC4 ; 2EC4 ; 2EC4 ; } */ 2EC4 ; 2EC4 ; 2EC4 ; 2EC4 ; #pragma interrupt_handler SCI1_handler() 2EC4 ; 2EC4 ; void SCI1_handler(void) {} 2EC4 L6: 2EC4 .dbline 0 ; func end 2EC4 0B rti 2EC5 _SPI_handler:: 2EC5 ; 2EC5 ; 2EC5 ; 2EC5 ; #pragma interrupt_handler SPI_handler() 2EC5 ; 2EC5 ; void SPI_handler(void) {} 2EC5 L7: 2EC5 .dbline 0 ; func end 2EC5 0B rti 2EC6 _PAIE_handler:: 2EC6 ; 2EC6 ; 2EC6 ; 2EC6 ; #pragma interrupt_handler PAIE_handler() 2EC6 ; 2EC6 ; void PAIE_handler(void) {} 2EC6 L8: 2EC6 .dbline 0 ; func end 2EC6 0B rti 2EC7 _PAO_handler:: 2EC7 ; 2EC7 ; 2EC7 ; 2EC7 ; #pragma interrupt_handler PAO_handler() 2EC7 ; 2EC7 ; void PAO_handler(void) {} 2EC7 L9: 2EC7 .dbline 0 ; func end 2EC7 0B rti 2EC8 ; lreg1 -> -4,x 2EC8 ; lreg2 -> -8,x 2EC8 _TOF_handler:: 2EC8 34 pshx 2EC9 B775 tfr s,x 2ECB 1B98 leas -8,sp 2ECD ; 2ECD ; 2ECD ; 2ECD ; #pragma interrupt_handler TOF_handler() 2ECD ; 2ECD ; void TOF_handler(void) { 2ECD ; 2ECD ; // LOCAL VARIABLES 2ECD ; extern unsigned long int time_tick; 2ECD ; 2ECD ; // acknowledge the interrupt, incriment global time_tick 2ECD ; TFLG2 = 0x80; 2ECD C680 ldab #128 2ECF 7B008F stab 0x8f 2ED2 ; time_tick++; 2ED2 CD0254 ldy #_time_tick 2ED5 1802401C movw 0,y,-4,x 2ED9 1802421E movw 2,y,-2,x 2EDD CD2F1B ldy #L11 2EE0 18024018 movw 0,y,-8,x 2EE4 1802421A movw 2,y,-6,x 2EE8 1638A9 jsr __ladd 2EEB CD0254 ldy #_time_tick 2EEE 18021C40 movw -4,x,0,y 2EF2 18021E42 movw -2,x,2,y 2EF6 ; 2EF6 ; } 2EF6 L10: 2EF6 B757 tfr x,s 2EF8 30 pulx 2EF9 .dbline 0 ; func end 2EF9 0B rti 2EFA _TC7_handler:: 2EFA ; 2EFA ; 2EFA ; 2EFA ; #pragma interrupt_handler TC7_handler() 2EFA ; 2EFA ; void TC7_handler(void) {} 2EFA L12: 2EFA .dbline 0 ; func end 2EFA 0B rti 2EFB _TC6_handler:: 2EFB ; 2EFB ; 2EFB ; 2EFB ; #pragma interrupt_handler TC6_handler() 2EFB ; 2EFB ; void TC6_handler(void) {} 2EFB L13: 2EFB .dbline 0 ; func end 2EFB 0B rti 2EFC _TC5_handler:: 2EFC ; 2EFC ; 2EFC ; 2EFC ; #pragma interrupt_handler TC5_handler() 2EFC ; 2EFC ; void TC5_handler(void) {} 2EFC L14: 2EFC .dbline 0 ; func end 2EFC 0B rti 2EFD _TC4_handler:: 2EFD ; 2EFD ; 2EFD ; 2EFD ; #pragma interrupt_handler TC4_handler() 2EFD ; 2EFD ; void TC4_handler(void) {} 2EFD L15: 2EFD .dbline 0 ; func end 2EFD 0B rti 2EFE _TC3_handler:: 2EFE ; 2EFE ; 2EFE ; 2EFE ; #pragma interrupt_handler TC3_handler() 2EFE ; 2EFE ; void TC3_handler(void) {} 2EFE L16: 2EFE .dbline 0 ; func end 2EFE 0B rti 2EFF _TC2_handler:: 2EFF ; 2EFF ; 2EFF ; 2EFF ; #pragma interrupt_handler TC2_handler() 2EFF ; 2EFF ; void TC2_handler(void) {} 2EFF L17: 2EFF .dbline 0 ; func end 2EFF 0B rti 2F00 _TC1_handler:: 2F00 ; 2F00 ; 2F00 ; 2F00 ; #pragma interrupt_handler TC1_handler() 2F00 ; 2F00 ; void TC1_handler(void) {} 2F00 L18: 2F00 .dbline 0 ; func end 2F00 0B rti 2F01 _TC0_handler:: 2F01 ; 2F01 ; 2F01 ; 2F01 ; #pragma interrupt_handler TC0_handler() 2F01 ; 2F01 ; void TC0_handler(void) {} 2F01 L19: 2F01 .dbline 0 ; func end 2F01 0B rti 2F02 _IRQ_handler:: 2F02 ; 2F02 ; 2F02 ; 2F02 ; #pragma interrupt_handler IRQ_handler() 2F02 ; 2F02 ; void IRQ_handler(void) {} 2F02 L20: 2F02 .dbline 0 ; func end 2F02 0B rti 2F03 _XIRQ_handler:: 2F03 ; 2F03 ; 2F03 ; 2F03 ; #pragma interrupt_handler XIRQ_handler() 2F03 ; 2F03 ; void XIRQ_handler(void) {} 2F03 L21: 2F03 .dbline 0 ; func end 2F03 0B rti 2F04 _SWI_handler:: 2F04 ; 2F04 ; 2F04 ; 2F04 ; #pragma interrupt_handler SWI_handler() 2F04 ; 2F04 ; void SWI_handler(void) {} 2F04 L22: 2F04 .dbline 0 ; func end 2F04 0B rti 2F05 _COP_handler:: 2F05 ; 2F05 ; 2F05 ; 2F05 ; #pragma interrupt_handler COP_handler() 2F05 ; 2F05 ; void COP_handler(void) { 2F05 ; 2F05 ; puts("COP RESET!"); 2F05 CC2F10 ldd #L24 2F08 163AE3 jsr _puts 2F0B ; _start(); 2F0B 161000 jsr __start 2F0E ; 2F0E ; } 2F0E L23: 2F0E .dbline 0 ; func end 2F0E 0B rti 2F0F _CLM_handler:: 2F0F ; 2F0F ; 2F0F ; 2F0F ; #pragma interrupt_handler CLM_handler() 2F0F ; 2F0F ; void CLM_handler(void) {} 2F0F L25: 2F0F .dbline 0 ; func end 2F0F 0B rti 2F10 L24: 2F10 434F502052455345542100 .byte 'C,'O,'P,32,'R,'E,'S,'E,'T,33,0 2F1B L11: 2F1B 00000001 .word 0,1 .module _HC12Setup.c .area text 2F1F __HC12Setup:: 2F1F ; // _HC12Setup.c 2F1F ; 2F1F ; #include <912d60.h> 2F1F ; #include "kernel.h" 2F1F ; 2F1F ; 2F1F ; 2F1F ; void _HC12Setup(void) { 2F1F ; 2F1F ; // set the register base 2F1F ; //*(volatile unsigned char *)0x0011 = 0x08; 2F1F ; 2F1F ; // set up the SYSTEM CLOCKS 2F1F ; SLOW = 0x00; // don't slow the RTI/COP clocks down 2F1F 79003E clr 0x3e 2F22 ; 2F22 ; 2F22 ; // set up the RTI INTERRUPT 2F22 ; INTR_OFF(); // disable/mask all maskable interrupts 2F22 1410 sei 2F24 2F24 ; RTICTL = 0x86; // enable RTI at 65.536 miliseconds 2F24 C686 ldab #134 2F26 7B0014 stab 0x14 2F29 ; //RTICTL = 0x85; // enable RTI at 32.768 miliseconds 2F29 ; RTIFLG = 0x80; // clear real time interrupt flag 2F29 C680 ldab #128 2F2B 7B0015 stab 0x15 2F2E ; 2F2E ; 2F2E ; // set up the COP WATCHDOG clock monitor for 524.288 ms 2F2E ; COPCTL = 0xC5; // COP on 2F2E C6C5 ldab #197 2F30 7B0016 stab 0x16 2F33 ; //COPCTL = 0x00; // COP off 2F33 ; 2F33 ; 2F33 ; // set up the TOF interrupt 2F33 ; TMSK2 = 0x80; // set to interrupt at 16.384 miliseconds 2F33 C680 ldab #128 2F35 7B008D stab 0x8d 2F38 ; TSCR = 0x80; // enable the timer 2F38 C680 ldab #128 2F3A 7B0086 stab 0x86 2F3D ; PACTL |= 0x0C; // ensure the timer is clocked from mclock divider 2F3D 1C00A00C bset 0xa0,#12 2F41 ; HPRIO = 0xDE; // elevate the TOF interrupt 2F41 C6DE ldab #222 2F43 7B001F stab 0x1f 2F46 ; 2F46 ; 2F46 ; /*// set up the MDC interrupt for time_tick 2F46 ; HPRIO = 0xCC; // elevate to highest priority 2F46 ; TSCR = 0x00; // setup 2F46 ; MCCNT = 0x0000; // modulus down-count start point 2F46 ; MCCTL = 0xC4; // enable 2F46 ; */ 2F46 ; } 2F46 L3: 2F46 .dbline 0 ; func end 2F46 3D rts