mk90.api

Task services

Cooperative task routines for resident workers and the registered pipe consumer.

Routine summary

RoutineInputResult
task_spawnR0 = resident entry; R1 = initial argumentR0 = PID 1/2, or 0 on rejection/full; R1–R5 preserved.
task_yieldNo argumentsR0–R5, SP, PC and supported PSW state restored on resumption.
task_sleepR0 = 0–32767 ticksR0 = 0 after the wait; 1 for an invalid duration or critical-section call. R1–R5 preserved.
task_selfNo argumentsR0 = address of the current task-control block.
task_dataNo argumentsR0 = private data address; R1 = 32. Both zero for PID 0/3.
task_beepNo argumentsR0 = 0 success or 1 I/O error; R1–R5 preserved.
task_exitR0 = final resultTerminates PID 1/2 or restores the parent of PID 3; PID 0 receives error 1.

task_spawn

task_spawn
R0 = resident entry; R1 = initial argument
ContractValue
Entry address0x2236
ReturnsR0 = PID 1/2, or 0 on rejection/full; R1–R5 preserved.

Allocates and initializes a background slot. Entry must be aligned and in the resident range, except the registered, verified pipe consumer while the pipe is active. Starts with R0 set to the argument, R1–R5 zero and interrupts enabled. Clears the slot’s private data; installs a return trampoline. FREE, DONE and FAULT slots may be reused. It is not a native-file loader.

task_yield

task_yield
No arguments
ContractValue
Entry address0x20C2
ReturnsR0–R5, SP, PC and supported PSW state restored on resumption.

Saves the calling context, checks stacks and selects the next READY context. In a busy controller transaction or with masked interrupt priority, returns without switching. The call is cooperative and must not be made from an ISR.

task_sleep

task_sleep
R0 = 0–32767 ticks
ContractValue
Entry address0x21F8
ReturnsR0 = 0 after the wait; 1 for an invalid duration or critical-section call. R1–R5 preserved.

Zero yields. Positive durations set a modular 16-bit deadline and put the caller in SLEEP before yielding. The scheduler makes it READY after the deadline; actual resumption depends on other tasks yielding.

task_self

task_self
No arguments
ContractValue
Entry address0x2326
ReturnsR0 = address of the current task-control block.

Returns a descriptor pointer, not a numeric PID. The descriptor is internal; applications should not rewrite its scheduling fields.

task_data

task_data
No arguments
ContractValue
Entry address0x232C
ReturnsR0 = private data address; R1 = 32. Both zero for PID 0/3.

Returns the fixed private area of a background slot. Its contents survive yields and are zeroed when the slot is reused. There is no heap allocation.

task_beep

task_beep
No arguments
ContractValue
Entry address0x2384
ReturnsR0 = 0 success or 1 I/O error; R1–R5 preserved.

Provides the permitted buzzer path for background workers. It preserves the foreground controller-error state around the guarded tone transaction.

task_exit

task_exit
R0 = final result
ContractValue
Entry address0x22FC
ReturnsTerminates PID 1/2 or restores the parent of PID 3; PID 0 receives error 1.

Closes an owned pipe read endpoint, records the final result and yields permanently for a worker. A normal RTS from a spawned worker reaches a trampoline that calls this routine. For PID 3, foreground cleanup restores the saved shell continuation.

Task-control block

Four 20-byte TCBs begin at 0x0760. Offsets are byte offsets; fields are little-endian words.

OffsetField
0State; see multiprogramming state table.
2Saved stack pointer.
4RTC wake deadline modulo 65536.
6 / 8Stack lower / upper-exclusive bounds.
10Pointer to resident ASCIIZ name.
12Application counter, unsigned 16-bit.
14COUNT/PULSE limit; zero means continuous.
16Final result.
18Scheduler-selection count, unsigned 16-bit with wrap.

Execution, stack and scheduling rules.