           lib     environment
           lib     hardware
           lib     macdefs
           sttl    System console Code - 8274
           pag
           name    sys8274
           global  systpc,sysrtt,sysbrg

*
* These are non-interrupt output routines for the system
* console.
*

USE_ROM set 1

 global INIT_TTY
INIT_TTY fcb 0
*
OUTCH equ $F80C
TINIT equ $F80E

*
* systpc
*
* Output the character in A.  X points to the port.  All
* registers should be preserved.
*

systpc
 if USE_ROM
 pshs cc,d,x,y,u
 seti -- no interrupts!
 tst INIT_TTY need to re-initialize terminal?
 bne 00f no - continue
 bsr sysrtt
00 jsr [OUTCH] let the ROM do it
 puls cc,d,x,y,u,pc

 else
           pshs    d,x                 save a reg
           pshs    a
           clrb
           asla                        move D7 to Carry
           rolb
           asla
           rolb
           orb     #$80                make no device control
outchw     lda     IFR08               get IFR
           bita    #$10                check for output busy
           beq     outchw
           stb     ORB08               write data to B side
outchlo    lda     IFR08
           bita    #$10
           beq     outchlo
           puls    a
           anda    #%00111111          strip off control bits
           sta     ORB08               put low byte on via
           puls    d,x
 cmpa #$0a
 bne systp9
 pshs d
 ldd #$3000
systp7 subd #1
 bne systp7
 puls d
systp9
           rts
 endif


*
* sysrtt
*
* Reset the console port.  X points to port.  Preserve all but A reg.
*

sysrtt
 if USE_ROM
 pshs d,x,y,u
 jsr [TINIT] call ROM routine
 inc INIT_TTY remember TTY initialized
 puls d,x,y,u,pc return
 else
*
     pshs    d
           ldd     #0                  merely delay a while
syslop     pshs    d,x
           puls    d,x
           subd    #1
           bne     syslop
           puls    d,pc
 endif


*
* sysbrg
*
* Setup baud rates.  Y points to receive baud rate, U points to xmit.
* A has configuration byte.  Preserve all regs but A.
*

sysbrg     rts
