.model medium
.stack 20h
.386

EXTRN gsclipx1:WORD
EXTRN gsclipx2:WORD
EXTRN gsclipy1:WORD
EXTRN gsclipy2:WORD

.code
public gsvline
gsvline proc
;stack:
;bp+14  x
;bp+12  y1
;bp+10  y2
;bp+8	seg
;bp+6	ofs
;bp+4	col
;bp+2	retseg
;bp	retofs
mov si, bp
mov bp, sp

push es
mov bx, [bp+14]

cmp bx, gsclipx1
jl endofline

cmp bx, gsclipx2
jg endofline

mov ax, [bp+12]
mov cx, [bp+10]

cmp ax, cx
jg swapy

afterswapy:
cmp ax, gsclipy2
jg endofline

cmp cx, gsclipy1
jl endofline

cmp ax, gsclipy1
jl clipy1

afterclipy1:
cmp cx, gsclipy2
jg clipy2

afterclipy2:
sub cx, ax
mov di, [bp+6]

shl ax, 6
add di, bx

add di, ax
mov es, [bp+8]

shl ax, 2
inc cx

add di, ax
mov bx, [bp+4]

theloop:
mov es:[di], bl
add di, 320

loop theloop

endofline:
pop es
mov bp, si
ret 12

swapy:
xchg ax, cx
jmp afterswapy

clipy1:
mov ax, gsclipy1
jmp afterclipy1

clipy2:
mov cx, gsclipy2
jmp afterclipy2

gsvline endp
end
