;GSboxf, puts a filled box on the screen...

;for comments of most of the code, look at GSsprite.asm

.model medium, basic
.stack 20h
.386

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

.code

;SUB gsboxf (varseg(screen),varptr(screen),x1,y1,x2,y2,color) [all byvals]
;stack:
;bp+18  screenseg
;bp+16  screenofs
;bp+14  x1 
;bp+12  y1        
;bp+10  x2       
;bp+8   y2    
;bp+6   col   
;bp+4 	returnseg
;bp+2   returnofs
;bp     bp
;bp-2   num of leftover bytes

;es:di = screenseg:screenofset

public gsboxf    
gsboxf proc

push bp
mov bp, sp

push es
mov ax,[bp+14]

mov es, [bp+18]
mov cx,[bp+10]

mov di, [bp+16]
cmp ax,cx
jle noswapx
xchg ax,cx
noswapx:
cmp ax,gsclipx2
jg endofbox     
cmp ax,gsclipx1
jge nofixclipleft
mov ax,gsclipx1
nofixclipleft:
add di, ax
cmp cx,gsclipx1
jl endofbox
cmp cx,gsclipx2
jle nofixclipright
mov cx,gsclipx2
nofixclipright:
mov bx,[bp+8]
mov dx,[bp+12]
cmp bx,dx
jge noswapy
xchg bx,dx
noswapy:
cmp bx,gsclipy1
jl endofbox
cmp bx,gsclipy2
jle nofixclipbot
mov bx,gsclipy2
nofixclipbot:
cmp dx, gsclipy2
jg endofbox
cmp dx,gsclipy1
jge nofixcliptop
mov dx, gsclipy1
nofixcliptop:
sub cx,ax
mov ax,320
sub bx,dx
mul dx
add di,ax
mov ax,[bp+6]
add bx,1
mov ah,al
add cx,1
mov dx,ax
shl eax,16
add ax,dx
mov dx,cx

push cx
and cx,3
jz yippee

shr dx,2
jz smalll

push cx
leftoverloop:
rep stosb
mov cx,dx
rep stosd
add di,320
mov cx,[bp-6]
sub di,[bp-4]
dec bx
jnz leftoverloop
pop ecx

jmp endofbox
smalll:
mov dx,cx
smallloop:
rep stosb
add di,320
mov cx,dx
sub di,[bp-4]
dec bx
jnz smallloop
pop cx
jmp endofbox
yippee:
shr dx, 2
yippeeloop:
mov cx,dx
rep stosd
add di,320
sub di,[bp-4]
dec bx
jnz yippeeloop
pop cx
endofbox:
pop es
pop bp
ret 14
gsboxf endp
end

