;  Service Routine for Keyboard Input
;
        .ORIG   x04A0
START   ST      R7,SaveR7       ; Save the linkage back to the program.
        ST      R1,SaveR1       ; Save the values in the registers
        ST      R2,SaveR2       ; that are used so that they
        ST      R3,SaveR3       ; can be restored before RET
;
        LD      R2,Newline
L1      LDI     R3,CRTSR        ; Check CRTDR --  is it free?
        BRzp    L1
        STI     R2,CRTDR        ; Move cursor to new clean line
;
        LEA     R1,Prompt       ; Prompt is starting address 
                                ; of prompt string
Loop    LDR     R0,R1,#0        ; Get next prompt character
        BRz     Input           ; Check for end of prompt string
L2      LDI     R3,CRTSR
        BRzp    L2
        STI     R0,CRTDR        ; Write next character of 
                                ; prompt string
        ADD     R1,R1,#1        ; Increment Prompt pointer
        BRnzp   Loop
;
Input   LDI     R3,KBSR         ; Has a character been typed?
        BRzp    Input
        LDI     R0,KBDR         ; Load it into R0
L3      LDI     R3,CRTSR
        BRzp    L3
        STI     R0,CRTDR        ; Echo input character 
                                ; to the monitor
;
L4      LDI     R3,CRTSR
        BRzp    L4
        STI     R2,CRTDR        ; Move cursor to new clean line

        LD      R1,SaveR1       ; Service routine done, restore
        LD      R2,SaveR2       ; original values in registers.
        LD      R3,SaveR3
        LD      R7,SaveR7       ; Restore linkage back prior to RET
        RET                     ; Return to calling program
;
SaveR7  .FILL   x0000           ; Location set aside for saving R7
SaveR1  .FILL   x0000
SaveR2  .FILL   x0000
SaveR3  .FILL   x0000
CRTSR   .FILL   xF3FC
CRTDR   .FILL   xF3FF
KBSR    .FILL   xF400
KBDR    .FILL   xF401
Newline .FILL   x000A           ; ASCII code for newline 
Prompt  .STRINGZ "Input a character>"
        .END