 lib environment
 lib inttab
 lib fio
 data
 sttl Device Interrupt Handlers
 pag
 name inthan

 global irqhan,frqhan,swi3han,idle_tsk

BDATA  equ 0 via b side data register offset
IFR    equ 13 via interrupt flag register
IER    equ 14 via interrupt enable register

*
* irqhan
*
* The irg interrupt handler is called after initial
* system setup to process an irq type interrupt.
*

irqhan
 lbsr map_io ##########################################
irqha0
 ldu CDSdev check CDS drive 0
 lda CDSFLG,u is it marksman?
 lbmi cdsint
 ldu CDSdev+2 check CDS drive 1
 lda CDSFLG,u is it marksman?
 lbmi cdsint
 lda W5STAT is it 5" Winchester?
 lbmi w5int
 lda DMF3CCR check for disk dma
 lbmi dmf3int
 lda CAT_C2 check for archive read
 lbmi ATint
 lda CAT_C3 archive write DMA comp?
 lbmi ATint

*   do strange decode on VIA interrupt

 lda VIA+IFR read VIA flags
 bpl not_via
 ldb VIA+BDATA read the DMF3 status lines
 anda VIA+IER
*bita #%00101000 check for archive int
 bita #%00100000 Archive timer 2?
 lbne ATint
*bita #%00010000 check for board int
 bita #%00001000 check for board int (CB2)
 beq via_err
 lda #%00001000 clear the CB2 interrupt
 sta VIA+IFR by stuffing the flag register
 bitb #%00100000 check for archive exception
 lbeq ATint
 bitb #%00000100 look only at 1797 irq line
 lbne dmf3int yea! branch if good disk irq
 jmp w5int must be WD1000 completion interrupt
via_err
 sta VIA+IFR reset spurious int
not_via

* Check for interrupt from IOP

 lbsr map_iop map in IOP
 tst iop_cpuF is there a message from the IOP?
 beq 10f no - get out
 ldy #IOP0 set up IOP control structure
 jsr fio_int yes - go process it
10 lbsr map_io restore map
 rts *** Nothing left to do...


 pag

*
* frqhan
*
* Handle the firq interrupt.  Works like irq.
*

frqhan ldx #fnttab point to table
frqha2 ldb inmask,x get mask
 andb instat,x check status
 beq frqha99
 ldd indev,x
 jmp [inhand,x]
frqha99 leax INTSIZ,x next entry
 cmpx #fntend end of table?
 bne frqha2 loop til done
 rts return

 pag

*
* SWI3 (System call) interrupt handler
*  -- Fetch arguments and place in User Block
*  -- Call system call handler
*  -- Store return parameters on stack
*  -- Return to program (via ROM)
*
swi3han ldx usp get user stack pointer
 leax 10,x point to user pc
 jsr gtuwrd get the pc
 pshs d save it
 tfr d,x point to pc location
 jsr gtubyt get post byte
 stb upostb save in user block
 puls d get pc back
 addd #1 bump past post byte
 std urglst+UPC save in user block
 ldx usp get stack pointer
 leax 10,x point to pc
 jsr ptuwrd set back on stack
*
 jsr syscl process system call
*
 ldx usp point to user stack
 ldb urglst+UCC get c-codes
 jsr ptubyt put on stack
 leax 1,x point to d reg
 ldd urglst+UD get d reg
 jsr ptuwrd put on stack
 leax 3,x point to x reg
 ldd urglst+UX get x reg
 jsr ptuwrd put on stack
 leax 6,x point to pc
 ldd urglst+UPC get user pc
 jsr ptuwrd put on stack
 rts return

 pag

*
* idle_tsk
*
* CPU Idle task
*
idle_tsk pshs d,x,y,u save registers
99 puls d,x,y,u,pc return
