Skip to content

Instantly share code, notes, and snippets.

@honzabilek4
Last active March 17, 2016 14:49
Show Gist options
  • Save honzabilek4/2f12b01fd6f9c0789c36 to your computer and use it in GitHub Desktop.
Save honzabilek4/2f12b01fd6f9c0789c36 to your computer and use it in GitHub Desktop.
ASM
; Autor: Miroslav Balik
; Source code: EXE 16b DOS
; Directs for assembling and linking:
; nasm odeslani.asm -fobj
; alink odeslani.obj
;********************************Macros***********************************
%macro dosint 1
mov ah,%1
int 21h
%endmacro
%macro vidint 1
mov ah,%1
int 10h
%endmacro
%macro line 5
mov bp,%1
mov dh,%2
mov dl,%3
mov cx,%4
mov bl,%5
mov bh,0
mov al,0
vidint 13h
%endmacro
;*******************************Stack segment******************************
segment stack stack
resb 64
stacktop:
;*******************************Data segment*******************************
segment data
h db "Miroslav Balik, odeslani"
times 6 db 32
db "Serial Communication via RS232 Interface"
times 1 db 32
db "MNAV 2016"
r0 db 186
times 78 db 32
db 186
r1 db 201
times 4 db 205
db " Sended data string: "
times 53 db 205
db 187
r2 db 204
times 4 db 205
db " Received data string: "
times 51 db 205
db 185
r3 db 200
times 78 db 205
db 188
p db " ESC-End "
times 55 db 219
db " COM1 1200bps "
kon db " Are you sure to end this program [y/n]? "
nkon times 41 db 32
vydx dw 0202h
prdx dw 0d02h
;*******************************Code segment*******************************
segment code
..start: mov ax,data
mov ds,ax
mov es,ax
mov ax,stack
mov ss,ax
mov sp,stacktop
call obrazovka
call port_init
smycka: mov dx,3FDh ;link state register
in al, dx
and al,00000001b ;bit masking
cmp al,0 ;if 0 there are no data on input, jump to next
je next
mov dx,3F8h ;else read data into al
in al,dx
mjm1p: cmp al,0dh
jne mjm2p ;if not enter go to mjm2p
call entp ;if enter call enter procedure
jmp smycka
mjm2p: cmp al,08h
jne mjm3p ;if not backspace go to mjm3p
call backspacep
jmp smycka
mjm3p:
call wrcharp
next: dosint 0bh
cmp al,00h
je smycka
dosint 08h
cmp al,1bh
jne mjm1
call dotaz
jmp smycka
mjm1: cmp al,0dh
jne mjm2
call ent
call odesli
jmp smycka
mjm2: cmp al,08h
jne mjm3
call backspace
call odesli
jmp smycka
mjm3: call wrchar
call odesli
jmp smycka ;return to begining
;*********************************Procedures sending part of the window*******************************
wrchar:
mov dx,[vydx]
mov bl,1eh
cmp dl,78
jl jm3
mov dl,2
inc dh
cmp dh,12
jl jm3
call scrol
jm3: vidint 2
mov cx,1
vidint 9
inc dl
vidint 2
mov [vydx],dx
ret
;***************************************************************************
ent:
mov dx,[vydx]
inc dh
mov dl,2
cmp dh,12
jl jm4
call scrol
jm4: vidint 2
mov [vydx],dx
ret
;***************************************************************************
backspace:
mov dx,[vydx]
dec dl
cmp dl,1
jg jm5
dec dh
mov dl,78
jm6: dec dl
cmp dl,2
je jm5
vidint 2
mov bh,0
vidint 8
cmp al,32
je jm6
inc dl
cmp dh,1
jg jm5
mov dx,0202h
jm5: vidint 2
mov cx,1
mov bl,1eh
mov al,32
vidint 9
mov al,08h
mov [vydx],dx
ret
;***************************************************************************
scrol:
push ax
mov ch,2
mov cl,2
mov dh,11
mov dl,77
mov al,1
mov bh,1eh
vidint 6
mov dh,11
mov dl,2
mov bh,0
pop ax
ret
;***************************************************************************
obrazovka:
mov al,2
vidint 0
mov bp,r0
mov dh,1
mov dl,0
mov bh,0
mov bl,1fh
l1: mov cx,80
mov al,0
inc dh
push dx
vidint 13h
pop dx
cmp dh,22
jle l1
line h,0,0,80,0fh
line r1,1,0,80,1fh
line r2,12,0,80,1fh
line r3,23,0,80,1fh
line p,24,1,78,70h
mov dx,[vydx]
vidint 2
ret
;***************************************************************************
dotaz: line kon,24,17,41,70h
l2: dosint 8
cmp al,79h
je jm1
cmp al,59h
je jm1
cmp al,4eh
je jm2
cmp al,6eh
jne l2
jm2: line nkon,24,17,41,0fh
ret
jm1: mov al,2
vidint 0
mov al,0
dosint 4ch
;*******************************Serial interface*****************************
port_init:
mov al,80h
mov dx,3FBh
out dx,al
mov al,96
mov dx,3F8h
out dx,al
mov al,0
mov dx,3F9h
out dx,al
mov al,00000011b
mov dx,3FBh
out dx,al
ret
odesli:
mov dx,3F8h
out dx,al
l3: mov dx,3FDh
in al,dx
and al,00100000b
cmp al,0
je l3
ret
;*********************************Procedures for receive part of the window*******************************
wrcharp:
mov dx,[prdx]
cmp dl,78
jl jm3p
inc dh
mov dl,2
cmp dh,23
jne jm3p
call scrolp
mov dx,0b02h
jm3p: vidint 02h
mov bh,0
mov cx,1
mov bl,1eh
vidint 02h
vidint 09h
inc dl
vidint 02h
mov [prdx],dx
ret
entp:
mov dx,[prdx]
inc dh
cmp dh,23
mov dl,2
jl jm4p
call scrolp
jm4p:
vidint 2
mov [prdx],dx
ret
scrolp:
push ax
mov ch,13
mov cl,2
mov dh,22
mov dl,77
mov bh,1eh
mov al,1
vidint 6
mov dh,22
mov dl,2
mov bh,0
pop ax
ret
backspacep:
mov dx,[prdx]
dec dl
cmp dl,1
jg jm5p
dec dh
mov dl,78
l6p: dec dl ;loop for backward detecting spaces when using backspace
cmp dl,2
je jm5p
vidint 2
mov bh,0
vidint 8 ;read cahracter
cmp al,32 ;is space jump to l6
je l6p
inc dl ;if yes increment column and continue
cmp dh,12 ;check borders
jg jm5p
mov dx,0d02h ;default position
jm5p: vidint 2
mov al,32 ;delete with writing a space 32
mov bh,0
mov cx,1
mov bl,1eh
vidint 9
mov [prdx],dx
ret
dotazp:
line kon,24,16,43,70h
l2p: dosint 08h
cmp al,79h
je jm1p
cmp al,59h
je jm1p
cmp al,4eh
je jm2p
cmp al,6eh
jne l2p
jm2p: line nkon,24,16,43,0fh
ret
jm1p: mov al,2
vidint 0
mov ax,4c00h
int 21h
obrazovkap:
mov al,2
vidint 0
mov bp,r0
mov dh,1
mov dl,0
mov bh,0
mov bl,1fh
l1p: mov cx,80
mov al,0
inc dh
push dx
vidint 13h
pop dx
cmp dh,22
jle l1p
line h,0,0,80,0fh
line r1,1,0,80,1fh
line r2,12,0,80,1fh
line r3,23,0,80,1fh
line p,24,1,78,70h
mov dx,[prdx]
vidint 2
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment