; $Id: kproct.mac 830 2016-12-26 20:25:49Z mueller $
; Copyright 2013- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
; License disclaimer see License.txt in $RETROBASE directory
;
; synchronous (polling) console print: print octal number
; Call:
;   jsr  pc, kproct
; Arguments:
;   r0: number to print
; 
; r1-r5 registers preserved
;  

kproct: mov     r1,-(sp)        ; save r1,..,r3
        mov     r2,-(sp)
        mov     r3,-(sp)
        mov     #101$,r1        ; r1 points behind end of buffer
        clrb    -(r1)           ; ensure 0-termination
        mov     #6,r2           ; loop over 6 digits
1$:     mov     r0,r3           ; get reminder
        bic     #177770,r3      ; mask 3 lsb
        add     #'0,r3          ; add ascii 0 code
        movb    r3,-(r1)        ; write (backwards) to buffer
        clc                     ; unsigned divide by 8
        ror     r0
        asr     r0
        asr     r0
        sob     r2,1$           ; go for next digit
        mov     r1,r0           ; r1 now points to convered string
        jsr     pc,kprstr       ; print it
        mov     (sp)+,r3        ; restore r1,..,r3
        mov     (sp)+,r2
        mov     (sp)+,r1
        rts     pc

100$:   .blkb   7.              ; buffer
101$:                           ; end-of-buffer
        .even
