
*
* Terminal I/O and bad interrupt handlers
*

* Report unhandled interrupts

unhand bsr panic
 fcc 'IRQ ',0
unswi bsr panic
 fcc 'SWI ',0
unswi2 bsr panic
 fcc 'SWI2',0
unswi3 bsr panic
 fcc 'SWI3',0
unnmi bsr panic
 fcc 'NMI ',0
unfirq bsr panic
 fcc 'FIRQ',0
 bsr panic
 fcc 'CHPR',0

* Panic processing

panic seti mask ints
 tst scrtrm reset 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 init rom

 pag

* terminal I/O equates

acia equ $e400 base address for acia

* String display routine

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

hexwrd bsr hexbyt
 tfr b,a

* 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

* Get address

getadr bsr getbyt get byte
 sta 0,--s save on stack
 bcs getext
 bsr getbyt get byte
 sta 1,s
getext puls y,pc return

* Get byte

getbyt leas -1,s
 bsr gethex input hex digit
 bcs hexit
 lsla
 lsla
 lsla
 lsla
 sta 0,s
 bsr gethex get hex digit
 bcs hexit
 ora 0,s
hexit leas 1,s clean stack
 rts return

* Get hex digit

gethex jsr inch get character
 cmpa #'0 is it digit?
 blo nothex
 cmpa #'9
 bls idigit
 cmpa #'A
 blo nothex
 cmpa #'F
 bhi nothex
 suba #'A-'0-10
idigit suba #'0
 rts return
nothex sec set carry
 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 'UniFLEX Boot ROM (MPU-1/DMF2/ACIA)',$d,0
prompt fcb $d
 fcc '%',0
sorry fcc '??',0
panicy fcb $d
 fcc 'Panic -> ',0

 pag
