 lib environment
 lib inttab
 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
 lda #CLKMSK get clock mask
 bita CLKSEL check clock int
 beq irqha0 no - try something else
 tst FD5cnt floppy disk time-out?
 beq 00f no - jump
 dec FD5cnt time to time-out?
 bne 00f no - jump
 jsr dmfTO yes - time out the disk
00 ldd CLKLAT reset timer interrupt
 jmp clkint go process interrupt
irqha0 lda DMFINT get dma status
 bita #%01000000 check int status
 lbne dmfint go service disk
 lda CMICMD is it CMI Winchester
 lbmi cmiint
 lda W5STAT check for SWTPC Winchester
 lbmi w5int
 lda CAT_C2 check for Archive Read DMA complete
 lbmi AT_int
 lda CAT_C3 check for Archive Write DMA complete
 lbmi AT_int
 lda VIA+IFR read VIA flags
 ldb VIA+BDATA check for Archive exception
 bitb #%00100000
 lbeq AT_int go process Archive exception
 tsta handle VIA interrupt
 bpl not_via
 bita #%00010000 look only at the board irq bit (CB1)
 beq not_via nope, not the disk
 jsr w5int process WD1000 completion interrupt
 rts
not_via
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
*
 jsr w5int process WD1000 completion interrupt
 rts *** Unexpected interrupt - what else to do?? **

 global pdata,hexbyt,hexwrd
 global Pdata,Phex,Pspace


* String display routine

newlin jsr outch output cr
 lda #$a setup line feed
putch jsr outch output it
Pdata
pdata lda 0,x+ get string character
 beq pdata2 end of string?
 cmpa #$d is it cr?
 beq newlin
 bra putch go output char
pdata2 rts return

* Output a space

Pspace
outsp pshs a save a
 lda #$20 setup space
 bsr outch output it
 puls a,pc return

* Output hex word

hexwrd bsr hexbyt
 tfr b,a

* Output a hex byte

Phex
hexbyt pshs a save byte
 lsra shift right 4 bits
 lsra
 lsra
 lsra
 bsr hexdig output it
 puls a restore digit

* Output a digit in hex

hexdig anda #$0f mask low bits
 adda #'0 make ascii digit
 cmpa #'9 is it digit?
 bls outch
 adda #7 add letter bias
 bra outch

* Output character routine

outch pshs a,x save a reg
 ldx #BASACI set up device address
outchw lda 0,x get status
 bita #$02 xmit busy?
 beq outchw
 puls a get character
 sta 1,x output char
 puls x,pc return
 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
