1 line
13 KiB
Plaintext
1 line
13 KiB
Plaintext
|
\ Forth co-operative multitasker /TASKER ( -- ) initialize multitasker links TCB ( u s r "ccc" ; -- tcb ) create a task control block HIS ( tcb user -- user' ) get a task's user variable address ACTIVATE ( tcb -- ) initialize stacks and run task WAKE ( tcb -- ) resume a task SLEEP ( tcb -- ) suspend a task STOP ( -- ) stop current task, switch to next MULTI ( -- ) enable multitasker SINGLE ( -- ) disable multitasker PAUSE ( -- ) switch to next active task GRAB ( sem -- ) grab resource GET ( sem -- ) pause then grab resource RELEASE ( sem -- ) release resource #FLOAT ( u -- ) per-task f/p stack bytes \ Load screen forth definitions decimal application cr .( loading Multitasker ) 2 #screens 1- thru \ STATUS LINK TOS /TASKER HIS \ Define reserved user variables 0 user TOS \ save top of stack 2 user STATUS status on \ task active flag 4 user LINK \ link to next task's user link value tlink \ topmost LINK \ Initialize multitasker links : /TASKER ( -- ) status tlink ! ; /tasker \ Calculate task local user address : HIS ( tcb user -- user' ) tos - + ; \ (pause) \ Pause current task & switch to next active code (pause) ( -- ) true # al mov \ wake fsp ) push si push bp push \ push FSP IP RP up ) bx mov sp 0 [bx] mov \ save SP to TOS 2 # bx add al 0 [bx] mov \ wake or sleep 1 $: 2 # bx add 0 [bx] bx mov \ find active task false # byte 0 [bx] cmp 1 $ jz false # byte 0 [bx] mov \ sleep 2 # bx sub bx up ) mov \ load UP 0 [bx] sp mov \ restore SP bp pop si pop fsp ) pop \ pop RP IP FSP next end-code
|