.model medium, basic
.stack 20h
.386
.code
public gscollide ;(,x1,y1,1seg,1ofs,x2,y2,2seg,2ofs) (maybe method, first..)
gscollide proc
;stack:
;;bp+22  method
;bp+20  x1
;bp+18  y1
;bp+16  1seg
;bp+14  1ofs
;bp+12  x2
;bp+10  y2
;bp+8   2seg
;bp+6   2ofs
;bp+4   retseg
;bp+2   retofs
;bp     bp
;bp-2   width1
;bp-4   height1
;bp-6   width2
;bp-8   height2
push bp

mov bp,sp

push es
push fs

mov es,[bp+16]      ;es = seg1
mov fs,[bp+8]       ;fs = seg2

mov si,[bp+14]      ;si = ofs1
mov di,[bp+6]       ;di = ofs2

;

mov ax,es:[si]      ;ax = width1*8
mov bx,fs:[di]      ;bx = width2*8

shr ax,3            ;ax = width1
sub bx,8            ;bx = (width2+1)*8

shr bx,3            ;bx = width2 + 1
mov cx,[bp+20]      ;cx = x1

dec ax              ;ax = width1 + 1
mov dx,[bp+12]      ;dx= x2

add cx,ax           ;cx = x1+width1+1
add di,2

cmp cx,dx           ;if x1+width1+1 < x2 then bah.
jl nocollide

sub cx,ax           ;cx = x1
add dx,bx           ;dx = x2 + width2+1

cmp dx,cx           ;if x2+width2+1 then bah.
jl nocollide

mov ax,es:[si+2]
mov bx,fs:[di]

dec bx
mov cx,[bp+18]

dec ax
mov dx,[bp+10]

add cx,ax

cmp cx,dx
jl nocollide

sub cx,ax
add dx,bx

cmp dx,cx
jl nocollide

mov ax, -1
pop fs
pop es
pop bp
ret 16

nocollide:
mov ax, 0
pop fs
pop es
pop bp
ret 16

gscollide endp
end
