.model LARGE ,c
.code
ScreenWidth	dw	80

lineV	proc FAR uses es, x:word,y:word,len:word,color:word
public	lineV
	mov	ax,0a000h
	mov	es,ax

	mov	DX,03C4h        ;color  
	mov	AX,0FF02h
	out	dx,ax


	mov	dx,3ceh     ;режим записи 2
	mov	ax,0205h
	out	dx,ax

	mov	cx,x
	and	cl,0111b
	mov	ah,10000000b
	shr	ah,cl

	mov	al,08h   ;Маска
	out	dx,ax

	mov	cx,y
	mov	ax,cs:ScreenWidth
	mul	cx
	mov	bx,ax
	mov	ax,x
	shr	ax,1  ;/8
	shr	ax,1
	shr	ax,1
	add	bx,ax
	
	mov	ax,color
	cld

	mov	cx,len
do:
	mov	ah,es:[bx]
	mov	es:[bx],al
	add	bx,cs:ScreenWidth
	loop	do

	ret
lineV	endp

lineH	proc FAR uses es, x:word,y:word,len:word,color:word
public	lineH
	mov	ax,0a000h
	mov	es,ax

	mov	DX,03C4h        ;color  
	mov	AX,0FF02h
	out	dx,ax

	mov	dx,3ceh     ;режим записи 2
	mov	ax,0205h
	out	dx,ax

	mov	cx,y
	mov	ax,cs:ScreenWidth
	mul	cx
	mov	bx,ax
	mov	ax,x
	shr	ax,1  ;/8
	shr	ax,1
	shr	ax,1
	add	bx,ax

	cmp	len,8
	jb	malo

	mov	cx,x
	and	cx,0111b
	add	len,cx
	sub	len,8
	mov	ah,11111111b
	shr	ah,cl
	
	mov	dx,3ceh
	mov	al,08h   ;Маска 1
	out	dx,ax

	mov	ax,color
	mov	ah,es:[bx]
	mov	es:[bx],al


	inc	bx
	mov	ax,color
	cld

	mov	cx,len
	shr	cx,1  ;/8
	shr	cx,1
	shr	cx,1

	jz	no_loop	

	mov	ax,0ff08h   ;Маска 2
	out	dx,ax
	mov	ax,color
do1:
	mov	ah,es:[bx]
	mov	es:[bx],al
	inc	bx
	loop	do1
no_loop:

	mov	cx,len
	and	cx,0111b
	mov	ch,cl
	mov	cl,8
	sub	cl,ch
	mov	ah,11111111b
	shl	ah,cl
	mov	al,08h   ;Маска 3
	out	dx,ax

	mov	ax,color
	mov	ah,es:[bx]
	mov	es:[bx],al
	jmp	_end
malo:	
	mov	ah,0ffh
	shr	ah,cl
	xor	ah,0ffh
	mov	al,0
	mov	cx,x
	and	cx,0111b
	shr	ax,cl
	mov	cl,al
	
	mov	dx,3ceh
	mov	al,08h   ;Маска 1
	out	dx,ax

	mov	ax,color
	mov	ah,es:[bx]
	mov	es:[bx],al

	inc	bx
	mov	ah,cl
	mov	al,08h   ;Маска 1
	out	dx,ax

	mov	ax,color
	mov	ah,es:[bx]
	mov	es:[bx],al

_end:	ret
lineH	endp

pixel	proc FAR uses es, x:word,y:word,color:word
public	pixel
	mov	ax,0a000h
	mov	es,ax

	mov	DX,03C4h        ;color  
	mov	AX,0FF02h
	out	dx,ax

	mov	dx,3ceh     ;режим записи 2
	mov	ax,0205h
	out	dx,ax

	mov	cx,x
	and	cl,0111b
	mov	ah,10000000b
	shr	ah,cl

	mov	al,08h   ;Маска
	out	dx,ax

	mov	cx,y
	mov	ax,cs:ScreenWidth
	mul	cx
	mov	bx,ax
	mov	ax,x
	shr	ax,1  ;/8
	shr	ax,1
	shr	ax,1
	add	bx,ax 
	
	mov	ax,color
	mov	ah,es:[bx]
	mov	es:[bx],al
	ret
pixel	endp


drawMode       proc FAR mode:word
public	drawMode

		mov	DX,03CEh
		mov	AX,mode
		mov	AH,AL
		mov	AL,3
		out	dx,ax
		ret
                
drawMode        endp

bar	proc FAR uses es, x:word,y:word,len:word,hi:word,color:word
public	bar
	mov	ax,0a000h
	mov	es,ax

	mov	DX,03C4h        ;color  
	mov	AX,0FF02h
	out	dx,ax

	mov	dx,3ceh     ;режим записи 2
	mov	ax,0205h
	out	dx,ax

	mov	cx,y
	mov	ax,cs:ScreenWidth
	mul	cx
	mov	bx,ax
	mov	ax,x
	shr	ax,1  ;/8
	shr	ax,1
	shr	ax,1
	add	bx,ax

	cmp	len,8

	jnb	mnogo
	jmp	malo_b
mnogo:
	mov	cx,x
	and	cx,0111b
	add	len,cx
	sub	len,8
	mov	ah,11111111b
	shr	ah,cl
	
	mov	dx,3ceh
	mov	al,08h   ;Маска 1
	out	dx,ax

	mov	ax,color
;------------------------------
	mov	cx,hi
	mov	dx,bx
_do1:
	mov	ah,es:[bx]
	mov	es:[bx],al
	add	bx,cs:ScreenWidth
	loop	_do1
	mov	bx,dx
;--------------------------	


	inc	bx
	mov	ax,color
	cld

	mov	cx,len
	shr	cx,1  ;/8
	shr	cx,1
	shr	cx,1

	jz	no_loop_b	

	mov	dx,3ceh
	mov	ax,0ff08h   ;Маска 2
	out	dx,ax
	mov	ax,color
do1_b:
;---------------------------
	push	cx
	mov	dx,bx
	mov	cx,hi
_do2:	
	mov	ah,es:[bx]
	mov	es:[bx],al
	add	bx,cs:ScreenWidth
	loop	_do2
	mov	bx,dx
	pop	cx
;------------------------------
	inc	bx
	loop	do1_b
no_loop_b:

	mov	cx,len
	and	cx,0111b
	mov	ch,cl
	mov	cl,8
	sub	cl,ch
	mov	ah,11111111b
	shl	ah,cl
	mov	al,08h   ;Маска 3
	mov	dx,3ceh
	out	dx,ax

	mov	ax,color
;-------------------------------
	mov	cx,hi
_do3:
	mov	ah,es:[bx]
	mov	es:[bx],al
	add	bx,cs:ScreenWidth
	loop	_do3
;-------------------------------	
	jmp	_end_b
malo_b:	
	mov	ah,0ffh
	shr	ah,cl
	xor	ah,0ffh
	mov	al,0
	mov	cx,x
	and	cx,0111b
	shr	ax,cl
	mov	cl,al
	
	mov	dx,3ceh
	mov	al,08h   ;Маска 1
	out	dx,ax

	mov	ax,color

;-------------------------------
	mov	dx,bx
	mov	cx,hi
_do4:
	mov	ah,es:[bx]
	mov	es:[bx],al
	add	bx,cs:ScreenWidth
	loop	_do4
	mov	bx,dx
;-------------------------------	

	inc	bx
	mov	ah,cl
	mov	al,08h   ;Маска 1
	mov	dx,3ceh
	out	dx,ax

	mov	ax,color
;-------------------------------
	mov	cx,hi
_do5:
	mov	ah,es:[bx]
	mov	es:[bx],al
	add	bx,cs:ScreenWidth
	loop	_do5
;-------------------------------	

_end_b:	ret
bar	endp

setPl	proc FAR pl :word
public	setPl
	mov	ah,1
	mov	cx,pl	
	shl	ah,cl
	mov	dx,3c4h
	mov	al,2
	out	dx,ax
	ret
setPl   endp	

norm	proc far
public	norm
	mov	dx,3ceh     ;режим записи 1
	mov	ax,0005h
	out	dx,ax
	mov	ax,0ff08h   ;Маска 
	out	dx,ax
	ret
norm	endp

	end