; > MemDump dumps memory between given parameters
;   Prints result on console in 8 columns
;
        ORG     O153000
        MOV     #O153000,R6     ; init stack
        JSR     R7,@#CRLF       ; newline
        JSR     R7,@#PROMPT     ; ask for address
        MOV     R2,R1           ; start addr in R1
        JSR     R7,@#PROMPT     ; get end address in R2
        BIC     #3,R1           ; make sure R1 is xxxxx0
        BIS     #3,R2           ; and R2 is xxxxx7
        JSR     R7,@#CRLF       ; blank line
LOOP:   JSR     R7,@#CRLF       ; newline
        CMP     R2,R1           ; finished ?
        BCC     LINE
        HALT
LINE:   MOV     R1,R5
        JSR     R7,@#PRTO       ; print address of line
        JSR     R7,@#PRTCS      ; then do colon and space
VALUE:  MOV     (R1)+,R5        ; R5 is value and pointer increments
        JSR     R7,@#PRTO       ; print value
        JSR     R7,@#PRTS
        BIT     #15,R1          ; see if R1 is MOD 16 (8 words)
        BNE     VALUE
        BR      LOOP
;
PROMPT: JSR     R7,@#CRLF
        JSR     R5,@#PRTA
        DEF     ASC"A"
        DEF     ASC"d"
        DEF     ASC"d"
        DEF     ASC"r"
        DEF     ASC"e"
        DEF     ASC"s"
        DEF     ASC"s"
        DEF     &20
        DEF     ASC"?"
        DEF     &8020
        CLR     R2
CHAR:   TSTB    @#O177560       ; wait for character
        BPL     CHAR
        MOV     @#O177562,R0    ; get character
        CMP     R0,#13          ; carriage-return ?
        BNE     NUMB
        RTS     R7
NUMB:   CMP     R0,#ASC"0"      ; if not CR, test for numeric
        BMI     CHAR
        CMP     R0,#ASC"8"
        BPL     CHAR
        MOV     R0,R4
        JSR     R7,@#PRTN       ; good, so echo it to console
        BIC     #&F8,R0         ; mask off to make octal
        ASL     R2              ; move one octet
        ASL     R2
        ASL     R2
        ADD     R0,R2           ; add this octet
        BR      CHAR
CRLF:   MOV     #13,R4
        JSR     R7,@#PRTN
        MOV     #10,R4
        JSR     R7,@#PRTN
        MOV     #0,R4
        JSR     R7,@#PRTN
        JSR     R7,@#PRTN
        RTS     R7
PRTO:   MOV     #O30,R4         ; R4 will be 6x after shifts
        ROL     R5              ; rotate 1 bit from R5 to R4
        ROL     R4
        JSR     R7,@#PRTN       ; print - as ASCII since it's 6x
        MOV     #5,R0           ; set to do five octets
CLOOP:  MOV     #6,R4           ; 6>>3 becomes octal 60, ie "0"
        ROL     R5              ; rotate R5>R4: 3 bits of octal number
        ROL     R4              ; could use ASHC R4,#3 if we have EIS
        ROL     R5
        ROL     R4
        ROL     R5
        ROL     R4
        JSR     R7,@#PRTN       ; print a digit
        DEC     R0              ; one less digit to do
        BNE     CLOOP
        RTS     R7              ; stop when done
PRTCS:  MOV     #ASC":",R4      ; print colon, then space
        JSR     R7,@#PRTN
PRTS:   MOV     #&20,R4         ; print ascii space
PRTN:   TSTB    @#O177564       ; look for RDY bit in CSR
        BPL     PRTN
        MOV     R4,@#O177566    ; send char to TX buffer
        RTS     R7
PRTA:   MOV     (R5),R4         ; get char just past where we were
        JSR     R7,@#PRTN       ; print it
        TST     (R5)+           ; see if it was last, and point to next
        BPL     PRTA            ; top bit set = finished
        RTS     R5
