
*
* Terminal I/O and bad interrupt handlers
*

* Report unhandled interrupts

unhand bsr panic
 fcc 'IRQ ',0
 bsr panic
 fcc 'SWI ',0
unswi2 bsr panic
 fcc 'SWI2',0
 bsr panic
 fcc 'SWI3',0
 bsr panic
 fcc 'NMI ',0
 bsr panic
 fcc 'FIRQ',0
 bsr panic
 fcc 'CHPR',0

* Panic processing

panic seti mask ints
 ldx #panicy point to string
 bsr pdata print it
 puls x get message
 bsr pdata print it
 lds #romstk set rom stack
 jmp montor goto mon loop

 pag

* terminal I/O equates

acia equ $e000 base address for acia

* String display routine

newlin bsr outch output cr
 lda #$a setup line feed
putch bsr outch output it
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

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

* Output a hex byte

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

* Test for an input character

inchck pshs a save a
 lda acia get status
 lsra check status bit
 puls a,pc return

* Input a character with echo

inch lda acia get status
 lsra check bit
 bcc inch wait for character
 lda acia+1 get character
 anda #$7f mask parity
 beq inch ignore nulls
 cmpa #'a is it lower case?
 blo outch
 cmpa #'z
 bhi outch
 suba #$20 make upper case

* Output character routine

outch pshs a save character
outchw lda acia get status
 bita #2 check status
 beq outchw
 puls a get character
 sta acia+1 output it
 rts return

* Initialize the terminal

tinit pshs d save reg
 lda #$3 reset acia
 sta acia
 lda #$11 set up bits & stuff
 sta acia
 ldd #15000 delay some here
tinit2 subd #1
 bne tinit2
 puls d,pc return

* messages

hello fcb $d
 fcc 'GIMIX UniFLEX Boot ROM (UOS-G1) 05/13/83',$d,0
prompt fcb $d
 fcc '%',0
sorry fcc '??',0
panicy fcb $d
 fcc 'Panic -> ',0

 pag
