#include "BIOS_IF.asm"

BUF_SIZE    EQU   100

            ORG   8000H

LOOP1       MVI   L, BIOS_GETC      ;Get a character
            RST   2                 ;Returns immediately
            CPI   0                 ;0 = No character ready
            JZ    LOOP1

            MVI   L, BIOS_PUTC      ;Echo the character
            RST   2
            CPI   CHARCR            ;Exit loop on CR
            JNZ   LOOP1

LOOP2       LXI   B, BUFFER
            MVI   L, BIOS_GETS      ;Get a string
            RST   2                 ;Returns on CR

            MVI   E, BUF_SIZE
            LXI   B, BUFFER
            MVI   L, BIOS_PUTS      ;Echo the string
            RST   2

            LDA   BUFFER            ;Load first char in string
            CPI   0                 ;Exit loop on empty string
            JNZ   LOOP2

            RET                     ;Exit

BUFFER      DS    BUF_SIZE
            