 opt nol
 lib environment
 lib inttab
 opt lis
 sttl Device Interrupt Handlers
 pag
 name inthan
 data

 global irqhan,frqhan,swi3han,idle_tsk

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

irqhan lda #CLKMSK get clock mask
 bita CLKSEL check clock int
 beq irqha0 no - try something else
 lda FD_TO check for Floppy Time-out
 beq 10f jump if not waiting
 deca
 sta FD_TO update counter
 bne 10f
 jsr dmf2to floppy has timed out!
10 ldd CLKLAT reset timer interrupt
 jmp clkint go process interrupt
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 DMF2CCR get dma status
 lbpl dmf2int if so, must be disk!
irqha1 ldx #inttab point to table
 lda 0,x+ get count
irqha2 ldb intype,x check device type
 cmpb #5 special code for 8274
 beq irqha3
 ldb inmask,x get mask
 andb [instat,x] check status
 lbeq irqha99 jump if not interrupt
 ldd indev,x get device number
 jmp [inhand,x] goto routine
*
* Special interrupt handler for 8274 type device
*
irqha3 pshs a save count
 ldu instat,x get device address
 lda #2 poll the device
 sta 3,u
 lda 3,u get response
 ldb 2,u
 bitb inmask,x interrupt pending?
 lbeq 10f no - jump
 leas 1,s yes - clean up stack
 pshs d place device status on stack for handler
 bita #$04 channel B (second device)?
 bne 0f
 leax INTSIZ,x yes - bump pointer
 ldu instat,x
 ldb 2,u get proper status for B side
 stb 1,s place on stack
0 lda 0,s
 anda #!$04
 sta 0,s
 ldd indev,x get device #
 ldu instat,x get device address
 jsr [inhand,x] go process interrupt
 leas 2,s clean up stack (remove device status)
 rts return from interrupt
10 leax INTSIZ,x skip over second device
 puls a restore count
 deca also skip second device
*
irqha99 leax INTSIZ,x get to next entry
 deca dec the count
 lbne irqha2 repeat til done
*
 jmp dmf2int -- assume DMF2 Floppy interrupt

 global Pdata,Phex,Pspace

*
*  These routines map onto ROM routines
*
Pdata jmp [$F800]
Phex jmp [$F802]
Pspace jmp [$F804]

 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
*  -- Just pass on to "syscl" - UniFLEX handler
*
swi3han jmp syscl

 pag

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