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

 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 lda #CLKMSK get clock mask
 bita CLKSEL check clock int
 beq irqha0 no - try something else
 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 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 complete?
 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 #%00100000 Archive timer 2?
 lbne ATint
 bita #%00001000 check for board int
 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

*  commence polling the stuff in the interrupt list

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
*
 rts *** Unexpected interrupt - what else to do?? **

 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
