
 lib environment
 sttl System I/O Routines
 pag
 name sysio
 global syspch,sysmsg,blowup,sysdec,syscon

*
* The routines in this file are io routines for
* system diagnostic messages only.
*

*
* syspch
*
* Write one character to the console terminal.
*

syspch pshs cc,a,x save data
 seti mask ints
 ldx scon point to console
 beq syspc4 is it null?
 jsr systpc write character
syspc4 puls cc,a,x,pc return

*
* syscon
*
* Initialize the system console
*

syscon ldx scon get address
 beq sysco2 is it null?
 jsr sysrtt reset port
 lda sconbr pick up baud rate value
 beq sysco2 jump if none
 pshs y,u save registers
 jsr findBRG get baud rate generator addresses
 jsr sysbrg set baud rates
 puls y,u restore registers
sysco2 rts return

*
* sysmsg
*
* Print a message on the system console
*

sysmsg lda 0,x+ get a character
 beq sysco2 end of message?
 bsr syspch send out character
 bra sysmsg repeat


 pag

*
* blowup
*
* Blow up the system after printing the message in X.
*

blowup pshs x
 jsr update update system
 ldx #syscrs get cr & lf
 bsr sysmsg print it
 puls x get message
 bsr sysmsg print it
 bra * blow up !!!!!!

syscrs fcb $d,$a,$d,$a,0


*
* sysdec
*
* Print the decimal number in D on the console.
*

sysdec pshs d save number
 ldd #4 set temps
 pshs d save temps
 ldd 2,s get the number
 ldx #sysct point to constants
sysde4 bsr sysdo output digit
 leax 2,x next constant
 dec 1,s dec the count
 bne sysde4 loop til done
 tfr b,a get last digit
 bsr syshr output it
 leas 2,s clean up stack
 puls d,pc return


 pag

*
* sysdo
*
* Output digit in D.
*

sysdo clr 0,-s clear flag
sysdo2 cmpd 0,x compare to constant
 blo sysdo5
sysdo4 subd 0,x dec number by constant
 inc 0,s bump count
 bra sysdo2 repeat
sysdo5 pshs a save digit
 lda 1,s get count
 bne sysdo6
 tst 4,s output any yet?
 beq sysdo7 if not, exit
sysdo6 inc 4,s set output digit flag
 bsr syshr output the digit
sysdo7 puls a reset number
 leas 1,s clean up stack
 rts return

*
* syshr
*
* Output right hex digit in A.
*

syshr anda #$f mask right half
 adda #$30 add in ASCII bias
 cmpa #'9 greater than 9?
 bls syshr2
 adda #7 add in bias
syshr2 lbra syspch output it


* decimal constants

sysct fdb 10000
 fdb 1000
 fdb 100
 fdb 10


