 sttl IO Command Handler
 pag

*
* IO_han - I/O Command Handler
*   This routine comprises the main processing loop
* for each task in the system.  Whenever an I/O command
* is detected (via the message interrupt), a task will
* be scheduled to process it.  This is that task.
*   The command is saved in the "tscmd" field of the
* task control block.
*

 if DBG_CMD&DEBUG_CONTROL
00 fcc $d,'Task $',0
01 fcc ', Command $',0
02 fcc "/",0
 endif

IO_han clri allow interrupts
 ldx utask get task control block address
 lda tscmd,x get I/O command
 if DBG_CMD&DEBUG_CONTROL
 jsr DB_msg
 fdb DBG_CMD,10f
 pshs d,x
 ldx #00b
 jsr DB_pdata
 ldd 2,s
 jsr DB_phex2
 ldx #01b
 jsr DB_pdata
 lda 0,s
 jsr DB_phex
 ldx #02b
 jsr DB_pdata
 ldx utask
 lda tsseq,x
 ldb tstval,x
 jsr DB_phex2
 puls d,x
 endif
10 lsra isolate command
 lsra
 lsra
 lsra
 ldb tsdev,x get device #
 cmpb #MAX_DEV check for legal device #
 bne 10f jump if OK
 ldb #E_BADDEV return illegal device error
 bra 20f exit
10 lsla -- word index on command
 ldx #dev_tab
 pshs d
 lda #DEV_SIZE
 mul
 leax d,x
 ldx dev_type,x get handler table address
 puls d
 ldy a,x get processor address
 clra
10 ldx #IO_end interrupt handler address
 pshs x
 ldx utask
 sts umark1,x
 jsr 0,y perform operation & return status
 leas 2,s clean up stack
20 jsr fio_response
IO_end seti mask interrupts
 ldx utask restore task control block address
 sta tstval,x remember transaction value sent
 stb tscmd,x and command response
 lda #TFREE mark task "terminated & free"
 sta tsstat,x
 lda #$FF disassociate from any terminal
 sta tsdev,x
 clr tssgnl,x no waiting signals
 jsr rsched run other tasks
 lbra IO_han

*
* Illegal command
*
bad_cmd
 ldb #E_BADCMD error code
 rts
