MODEL MEDIUM,BASIC
.STACK 20H
.386
.CODE

;SUB RELSPRITEFAST(BYVAL DESTSEG%,BYVAL X%,BYVAL Y%,BYVAL SPRITESEGMENT%,BYVAL SPRITEOFFSET%)
;STACK
;DEST SEG       =16
;X              =14  
;Y              =12
;SPRITESEGMENT  =10
;SPRITOFFSET    =8
;RET SEG        =6
;RET OFF        =4
;BP             =2
;DS             =0
;WIDTH/8        =-2     ;REAL WIDTH
;320-WIDTH      =-4     ;FOR SPEEDIER LOOP NO SUB

;DS:SI          =SPRITE SEG:SPRITE OFF
;ES:DI		=DEST SEG:DEST OFF
;DX=WIDTH
;BX=HEIGHT

PUBLIC RELSPRITEFAST
RELSPRITEFAST PROC
PUSH BP
PUSH DS


MOV BP,SP	;POINT STACK POINTER TO BP
MOV DS,[BP+10]  ;POINT ADDRESS OF SPRITE TO DS
MOV SI,[BP+8]   ;WE ARE NOW ON THE WIDTH OF THE SPRITE W=(ARRAY(0)/8)-1

MOV ES,[BP+16]  ;POINT ADDRESS OF DEST TO ES

MOV DX,[SI]     ;DX= WIDTH * 8
SHR DX,3        ;DIV WIDTH BY 8
MOV BX,[SI+2]   ;BX=HEIGTH
PUSH DX         ;SAVE WIDTH TO STACK
ADD SI,4        ;FIRST WORD 2 COLORS(ARRAY(2))

;LET US NOW CALCULATE  THE OFFSET

MOV CX,[BP+12]  ;Y VALUE

XCHG CH,CL      ;SHIFT LEFT  8 Y VALUE (Y*256)
MOV DI,CX       ;SAVE Y VALUE TO DX
SHR DI,2        ;SHIFT RIGHT TO DIVIDE DI BY 64
ADD DI,CX       ;Y*64+Y*256=Y*320  :)
ADD DI,[BP+14]  ;DEST OFFSET(X,Y)=Y*320+X

MOV DX,[BP-2]   ;REAL WIDTH

MOV AX,320
SUB AX,DX
PUSH AX         ;320-WIDTH


LBL_FAST_SPRITE_LOOP:
        MOV CX,[BP-2]           ;WIDTH
        SHR CX,2                ;DIV BY 4
        REP MOVSD               ;COPY IT
        MOV CX,[BP-2]
        AND CX,3                ;GET REMAINDER
        REP MOVSB               ;STORE ODD PIXELS
        ADD DI,[BP-4]           ;UH.......
        DEC BX                  ;DECREMENT HEIGHT 
JNZ LBL_FAST_SPRITE_LOOP        ;IS HEIGHT=0?


ADD SP,4
POP DS      ;RESTORE DS
POP BP      ;RESTORE BP

RET 10

RELSPRITEFAST ENDP

END

