; > Input_Lib   Library of subroutines to call console for input.
;
;               Includes GETA - gets a single ASCII character in R5
;                        GETV - gets a 16-bit decimal value in R5.
;                        GETO - gets a 16-bit octal value in R5
;                        GETH - gets a 16-bit hex value in R5
;                        GETS - gets a string to the buffer located by R5
;                               Size of buffer must be in R4.
;
;   All routines linked to by R7.
;
GETA:   TSTB    @#O177560       ; wait for character
        BPL     GETA
        MOV     @#O177562,R5
        RTS     R7
;
GETV:   CLR     -(R6)           ; clear a word on the stack
GETV1:  JSR     R7,@#GETA       ; get a character
        CMP     #33,R5
        BMI     DECIN           ; terminate on any control char or space
        JSR     R7,@#CRLF       ; ***** remove if not required *****
        MOV     (R6)+,R5
        RTS     R7
DECIN:  CMP     R5,#ASC"0"      ; check character>="0"
        BMI     GETV1
        CMP     #ASC"9",R5      ; check character<="9"
        BMI     GETV1
        JSR     R7,@#PRTA       ; ***** remove if not required *****
        BIC     #ASC"0",R5      ; ascii-to-decimal
        ASL     (R6)            ; times 2
        ADD     (R6),R5         ; add to the new value
        ASL     (R6)            ; times 4
        ASL     (R6)            ; times 8
        ADD     R5,(R6)         ; times 10, plus new value
        BR      GETV1
;
GETO:   CLR     -(R6)           ; stack space for value
GETO1:  JSR     R7,@#GETA
        CMP     #33,R5          ; terminate on any control char or space
        BMI     OCTIN
        JSR     R7,@#CRLF       ; ***** remove if not required *****
        MOV     (R6)+,R5
        RTS     R7
OCTIN:  CMP     R5,#ASC"0"      ; if not CR, test for numeric
        BMI     GETO1
        CMP     R5,#ASC"8"
        BPL     GETO1
        JSR     R7,@#PRTA       ; ***** remove if not required *****
        BIC     #&F8,R5         ; mask off to make octal
        ASL     (R6)            ; move one octet
        ASL     (R6)
        ASL     (R6)
        ADD     R5,(R6)         ; add this octet
        BR      GETO1
;
GETH:   CLR     -(R6)           ; clear a word on the stack
GETH1:  JSR     R7,@#GETA
        CMP     #33,R5          ; terminate on any control char or space
        BMI     HEXIN
        JSR     R7,@#CRLF       ; ***** remove if not required *****
        MOV     (R6)+,R5
        RTS     R7
HEXIN:  CMP     R5,#ASC"0"
        BMI     GETH1
        CMP     #ASC"F",R5
        BMI     GETH1
        CMP     #ASC"9",R5
        BPL     OKVAL
        CMP     R5,#ASC"A"
        BMI     GETH1
OKVAL:  JSR     R7,@#PRTA       ; ***** remove if not required *****
        CMP     #ASC"9",R5
        BPL     $+6
        SUB     #ASC"A"-ASC"9",R5
        BIC     #ASC"0",R5
        ASL     (R6)
        ASL     (R6)
        ASL     (R6)
        ASL     (R6)
        ADD     R5,(R6)
        BR      GETH1
;
