.model small
.stack 100h
video equ 0B800h
.data
linepack label word
 x1 dw 159
 y1 dw 99  x2 dw ?
 y2 dw ?
 color db 3
 len dw 0
 skip dw 0

mask_table label word
  db 3fh,0
  db 3fh,40h
  db 3fh,80h
  db 3fh,0c0h

  db 0cfh,0
  db 0cfh,10h
  db 0cfh,20h
  db 0cfh,30h

  db 0f3h,0
  db 0f3h,4
  db 0f3h,8
  db 0f3h,12

  db 0fch,0
  db 0fch,1
  db 0fch,2
  db,0fch,3

short_step dw ?
long _step dw ?
line_start dw ?
line_stop dw ?
 ; x1 equ [word ptr si]
;  y1 equ [word ptr si+2]
;  x2 equ [word ptr si+4]
;  y2 equ [word ptr si+6
 ; color equ [word ptr si+8]
 ; len equ [word ptr si+10]
 ; skip equ [word ptr si+12]
codeseg
;public plotdot
  .386
plotdot proc near
 pusha
 mov di,3
 and di,cx
 shl di,2
 and bx,3
 add di,bx
  ;shl di,1
 mov bx,mask_table[di]

 mov di,dx
 and di,0ffeh
 shl di,3
 mov ax,di
 shl di,2
 add di,ax
 test dx,1
 jz pd1
 add di,2000h
pd1:
    mov ax,cx
 shr ax,2
 add di,ax
 
 and es:[di],bl
 or es:[di],bh
 popa
 ret
plotdot endp
 

plotline proc near
  pusha
 mov long_step,1  mov bp,x2
 sub bp,x1
 jge pl1
 neg long_step
 neg bp
pl1:
 mov short_step,1
 mov ax,y2
 sub ax,y1
 jge pl2
 neg short_step
 neg ax

pl2:
 mov line_start,0
 mov di,skip
 cmp di,0
 je pl3
 mov line_start,di

pl3:
 mov bl,color
 mov cx,x1
 mov dx,y1
 cmp ax,bp
 ja alt_code

 mov line_sto p,di
pl4:
 mov di,bp
 shr di,1
 xor si,si
norm_loop:
    cmp si,line_start
 jl pl5
 call plotdot
pl5:
 add cx,long_step
 add di,ax
 cmp di,bp
 jl pl6
 add dx,short_step
pl6:
 inc si
 cmp si,line_stop
 jbe norm_loop
 jmp pl_exit
alt_code:
 xchg ax,bp
 mov di,long_step
 xchg short_step,di
&nbs p;mov long_step,di

 mov line_stop,bp
 mov di,len
 cmp di,0
 je pl7
 mov line_stop,di
pl7:
 mov di,bp
 shr di,1
 xor si,si
alt_loop:
 cmp si,line_start
 jl pl8
 call plotdot
pl8:
 add dx,long_step
 add di,ax
 cmp di,bp
 jl pl9
 add cx,short_step
pl9:
 inc si
 cmp si,line_stop
 jbe alt_loop
pl_exit:
 popa
 ret
plotline endp

draw proc near
 

 mov ax,@data
 mov ds,ax
 mov ax, video
 mov es,ax
 mov ax,4  ;med res interrupt
 int 10h
 mov si,offset linepack
 mov x2,0
 mov y2,0
top_side:

 call plotline
 inc color
 and color,3
 inc x2
 cmp x2,320
 jb top_side
 dec x2
right_side:

 call plotli ne
 inc color
 and color,3
 inc y2
 cmp y2,200
 jb right_side
 dec y2
bot_side:

 call plotline
 inc color
 and color,3
 dec x2
 cmp x2,0
 jg bot_side
 inc x2
left_side:

 call plotline
 inc color
 and color,3
 dec y2
 cmp y2,0
 jg left_side
 

 mov ah,1
 int 21h
 mov ax,2
 int 10h
dosRET:
 mov ax,4c00h
 int 21h
draw endp
 
 
 
 
 

ends
end draw