; > Print_Lib   Library of console print subroutines
;
;               Includes PRTH - prints R5 (16 bits) in hex
;                        PRTO - prints R5 (16 bits) in octal
;                        PRTA - prints R5 (8 bits) in ASCII
;                        MSSG - prints the string following the JSR
;                               (terminate with top-bit-set character/byte)
;                        CRLF - prints carriage-return/linefeed
;
;       All subroutines link with R7 except MSSG (link with R5)
;
;
CRLF:   MOV     #13,R5          ; print <CR> and <LF> on console
        JSR     R7,@#PRTA
        MOV     #10,R5
        JSR     R7,@#PRTA
        RTS     R7
;
PRTH:   MOV     R5,-(R6)        ; print R5 in hex
        ASR     R5
        ASR     R5
        ASR     R5
        ASR     R5
        JSR     R7,@#HEX1
        MOV     (R6)+,R5
        BIC     #&F0,R5
HEX1:   BIS     #ASC"0",R5      ; make hex into ASCII and print it
        CMPB    #ASC"9",R5
        BPL     PRTA
        ADD     #7,R5
;
PRTA:   TSTB    @#O177564       ; wait for console XBUFF to be ready
        BPL     PRTA
        MOV     R5,@#O177566
        RTS     R7
;
PRTO:   MOV     R0,-(R6)        ; save R0,R4 on stack
        MOV     R4,-(R6)
        MOV     R5,R4
        MOV     #O30,R5         ; R4 will be 6x after shifts
        ROL     R4              ; rotate 1 bit from R4 to R5
        ROL     R5
        JSR     R7,@#PRTA       ; print - as ASCII since it's 6x
        MOV     #5,R0           ; set to do five octets
CLOOP:  MOV     #6,R5           ; 6>>3 becomes octal 60, ie "0"
        ROL     R4              ; rotate R4>R5: 3 bits of octal number
        ROL     R5              ; could use ASHC R4,#3 if we have EIS
        ROL     R4
        ROL     R5
        ROL     R4
        ROL     R5
        JSR     R7,@#PRTA       ; print a digit
        DEC     R0              ; one less digit to do
        BNE     CLOOP
        MOV     (R6)+,R4        ; restore caller's R4,R0
        MOV     (R6)+,R0
        RTS     R7
;
MSSG:   TSTB    @#O177564       ; prints message at word following call
        BPL     MSSG
        MOVB    (R5),@#O177566  ; print char just past where we were
        TSTB    (R5)+           ; see if it was last, and point to next
        BPL     MSSG            ; top bit set = finished
        INC     R5              ; in case it's not on a word boundary
        BIC     #1,R5           ; in case it was
        RTS     R5
