; > RK07boot
;
; RK07 Bootstrap with unit choice 
; (Adapted from RT-11 Ver.4.0 Sysgen Manual Appendix)
; Asks for unit number before booting
;
        ORG     O1000
;
        MOV     #O1000,R6       ; set up stack 
        MOV     #O177440,R1     ; CSR in R1
        JSR     R7,@#crlf
        JSR     R5,@#mssg
        DEFS    "RK07 unit # ? "
        DEFB    0
        ALIGN
        JSR     R7,@#getv       ; Get value 0-7
        MOV     R0,8(R1)        ; Unit number to 177450
        MOV     #O2003,(R1)     ; RK07 pack acknowledge to CSR
test1:  BIT     #O100200,(R1)   ; wait for ready response
        BEQ     test1
        MOV     #O177400,2(R1)  ; two's complemented word count to RKWC
        MOV     #O2021,(R1)     ; read data command (bit 10 set for RK07)
test2:  BIT     #O100200,(R1)   ; wait till done
        BEQ     test2
        CLR     R7              ; jump to locn 0
;
crlf:   MOV     #13,R5          ; print <CR> and <LF> on console
        JSR     R7,@#prta
        MOV     #10,R5          ; make <LF> and fall through to...
;
prta:   TSTB    @#O177564       ; wait for console XBUFF to be ready
        BPL     prta
        MOV     R5,@#O177566
        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
        BNE     mssg            ; string is zero-terminated
        INC     R5              ; in case it's not on a word boundary
        BIC     #1,R5           ; in case it was
        RTS     R5
;
; This subroutine gets value 0-7 in R0 (also uses R5)
;    null input gives value 0
;    routine terminates on any CTRL char
;    user can enter any printable char
;    character will be converted to a single digit
;
getv:   MOV     #O100000,R5     ; set "no char yet" flag
get:    TSTB    @#O177560       ; wait for character at console
        BPL     get
        BIC     #O377,R5        ; use clear/set instead of MOVB
        BISB    @#O177562,R5    ; MOVB extends sign into high byte, so destroys my flag
        CMPB    #O40,R5
        BMI     deltst
        TST     R5              ; is there a char already
        BPL     return
        CLR     R0              ; if no char, make unit #0
        MOV     #O60,R5         ; ascii 0
        JSR     R7,@#prta
return: RTS     R7
deltst: CMPB    #O177,R5        ; delete ?
        BNE     okchar
        TST     R5
        BMI     get             ; if no char on screen, ignore delete
        JSR     R5,@#mssg
        DEFB    8               ; sequence of backsp,space,backsp
        DEFB    32
        DEFB    8
        DEFB    0
        ALIGN
        BR      getv            ; set "no char" and go for next
okchar: MOVB    R5,R0           ; save char, but leave flag for now
        TST     R5
        BMI     doit
        MOV     #8,R5           ; if not 1st char, do backspace
        JSR     R7,@#prta
doit:   BIC     #O177770,R0     ; ensure range is 0-7
        MOV     R0,R5           ; for printing - also now bit 15 clear
        BIS     #O60,R5         ; make ascii
        JSR     R7,@#prta
        BR      get
