.model medium,basic
.stack 20h
.386
.code

public gsscroll
gsscroll proc
;stack:
;bp+16  fromseg
;bp+14  fromofs
;bp+12  toseg
;bp+10  toofs
;bp+8   x
;bp+6   y
;bp+4   retofs
;bp+2   retseg
;bp     bp
push bp
mov bp,sp
push ds
push es
xor ecx,ecx
mov dx, [bp+6]     ;dx = y
mov ds, [bp+16]  ;ds = segment
shl dx,2           ;dx = 4*y
mov es,[bp+12]   ;es = segment
add dx,[bp+6]      ;dx = 5*y
mov di,[bp+10]   ;di = offset
shl dx, 6          ;dx = 320*y
mov si,[bp+14]
add dx,[bp+8]      ;dx = x+320*y
cmp dx, 0
jg goright       ;if dx > 0 then goto goright
jz same          ;if dx = 0 then goto same

goleft:
neg dx
mov bx,dx         ;bx = 320*y + x
add si, dx       ;si = offset+abs(dx)
mov cx, 16000
shr dx,2
sub cx,dx
rep movsd
and bx,3          ;bx = (x and 3)
jz theend         ;if (x and 3) = 0 then goto niceleft
mov cx,bx
rep movsb
jmp theend

goright:
add di, 63996
mov bx,dx
add si, 63996
mov cx, 16000
sub si, dx
add dx, 3
shr dx, 2
sub cx, dx
std
rep movsd
and bx, 3
jz goodright
mov cx, bx
rep movsb
goodright:
cld
jmp theend
same:
mov ax, [bp+16]
cmp ax, [bp+12]
jz theend
mov si, [bp+14]
mov di, [bp+10]
mov cx, 16000
rep movsd
theend:
pop es
pop ds
pop bp
ret 12
gsscroll endp
end
