19bb ; Simple modem communication routine ; ------------------------------------ ; ; Note: this example is setup for COM2 only. ; DATA SEGMENT ORG 02000 pag db ? col db ? row db ? bkflag db ? DATA ENDS jmp main border: db 80*2 dup 020 ;Make border out of spaces b_len equ $-border intro: db ' Simple communications routine. Press ESC to quit',13,10 db ' ------------------------------------------------',13,10 len1 equ $-intro main: mov ah,0fH ;Return Video State int 10H mov pag,bh ;Save Active Page mov ah,05H ;Select Page mov al,pag int 10H push bp mov ah,06H ;Clear screen mov al,0 ;Number of lines blanked 0=Entire window mov bh,1fH ;Attribute mov ch,0 ;row (y) of upper left corner mov cl,0 ;column (x) upper left corner mov dh,24 ;row (y) lower right corner mov dl,79 ;column(x) lower right corner int 10H pop bp mov ah,13H ;Show border mov al,01H mov bh,pag ;Page number mov bl,6eH ;Attribute (foreground & background color) mov cx,b_len ;Length of string mov dh,0 ;Row mov dl,0 ;Column mov bp,border ;Pointer to string int 10H mov ah,13H ;Display string mov al,01H mov bh,pag ;Page number mov bl,6eH ;Attribute (foreground & background color) mov cx,len1 ;Length of string mov dh,0 ;Row mov dl,0 ;Column mov bp,intro ;Pointer to string int 10H mov ah,03H ;Get cursor position mov bh,pag int 10H mov row,dh ;Save current row and column mov col,dl start: mov ah,01H ; Test Keyboard input status int 16H jz modem_inp ; No character, test comm port instead mov ah,00H ; Get next character in keyboard buffer int 16H cmp al,27 ; End if ESC pressed jz quit cmp ah,75 ; Left arrow pressed? jne curr jmp curleft curr: cmp ah,77 ; Right arrow pressed? jne sendch jmp curright sendch: mov dx,1 mov ah,01H ; Send character to serial port int 14H jmp modem_inp quit: mov ah,05H ;Select Page mov al,0 int 10H push bp mov ah,06H ;Clear screen mov al,0 ;Number of lines blanked 0=Entire window mov bh,07H ;Attribute (White on black) mov ch,0 ;row (y) of upper left corner mov cl,0 ;column (x) upper left corner mov dh,24 ;row (y) lower right corner mov dl,79 ;column(x) lower right corner int 10H pop bp mov ax,04C00 ; Exit with no error int 33 ; go back to the operating system modem_inp: mov dx,1 ; (COM2) mov ah,03H ; Get status of serial port int 14H test ah,1 ; Test if Data Ready jz start ; No... mov dx,1 ; Yes! mov ah,02H int 14H ;read character from com2 cmp al,0dH ;If CR, place cursor column 0 jne >l2 jmp carriage l2: cmp al,0aH ;If LF, go down one row jne >l3 jmp incrow l3: cmp al,08H ;If BS, take appropriate action jne write jmp bkspace write: mov ah,0aH ;Write character to screen mov bh,pag ;Page number mov cx,1 ;Number of characters int 10H inc col mov ah,02H ;Set cursor position mov bh,pag mov dl,col ;Inc cursor pos one column mov dh,row int 10H cmp dl,80 ;Cursor at end of line? jne noincrow jmp incrow bkspace: mov bkflag,1 curleft: dec col ;Column -1 cmp col,0 jge setcur inc col ;If column<0 set column=0 jmp setcur curright: inc col cmp col,80 jle setcur dec col setcur: mov ah,02H ;Set cursor mov bh,pag mov dh,row mov dl,col int 10H cmp bkflag,1 je blank jmp start blank: mov ah,0aH ;Blank out character mov al,020H ;With space mov bh,pag ;Page number mov cx,1 ;Number of characters int 10H mov bkflag,0 jmp start incrow: inc row carriage: mov col,0 mov ah,02H ;Yes, inc row mov bh,pag mov dh,row mov dl,col int 10H noincrow: cmp dh,24 ;Cursor at row>24? jg scroll ;Yes, scroll window jmp start scroll: push bp mov ah,06H ;Clear screen mov al,1 ;Number of lines blanked 0=Entire window mov bh,1fH ;Attribute mov ch,2 ;row (y) of upper left corner (save border!) mov cl,0 ;column (x) upper left corner mov dh,24 ;row (y) lower right corner mov dl,79 ;column(x) lower right corner int 10H pop bp mov row,24 ;Put back row to 24 mov col,0 ;And column 0... mov ah,02H ;Set cursor position mov bh,pag mov dh,row mov dl,col int 10H jmp start . 0