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

;SUB RELPCOPYGAMMA(BYVAL DESTSEG,BYVAL SRCSEG,BYVAL GAMMAVAL%)
;STACK
;DEST SEG       =8
;SOURCE SEG     =6
;GAMMAVAL       =4
;QB RETURN SEG	=2
;QB RETURN OFF	=0
;DS:SI		=SRC SEG:SRC OFF
;ES:DI		=DEST SEG:DEST OFF

PUBLIC RELPCOPYGAMMA
RELPCOPYGAMMA PROC

MOV AX,DS	;SAVE DS
MOV BX,BP	;SAVE BP
MOV BP,SP	;POINT STACK POINTER TO BP
MOV ES,[BP+8]   ;POINT ADDRESS OF DEST TO ES
MOV DS,[BP+6]   ;POINT ADDRESS OF SRC TO DS
XOR DI,DI	;ZERO OUT DEST OFFSET
XOR SI,SI	;ZERO OUT SRC OFFSET

MOV CH,[BP+4]
LBL_PLOT_PIXEL:
        MOV CL,DS:[SI]          ;CHECK SOURCE PIXEL
        CMP CL,0                ;IS IT ZERO?
        JZ LBL_SKIP_PIXEL       ;YES THEN SKIP
                                ;CALCULATE NEW COLOR FOR GAMMA
           MOV DL,CL            ;SAVE COLOR
           AND CL,15            ;16 COLOR GRAD
           SUB DL,CL            ;LOWER BOUNDS
           ADD CL,CH            ;GAMMA COL
           ADD CL,DL            ;GET COL
        CMP CL,DL
        JA LBL_LIMIT_TOP
                MOV ES:[DI],DL
                JMP LBL_SKIP_PIXEL
        LBL_LIMIT_TOP:
           ADD DL,15            ;UPPER BOUNDS
        CMP CL,DL
        JB LBL_PLOT_GAMMA
                MOV ES:[DI],DL
                JMP LBL_SKIP_PIXEL
        LBL_PLOT_GAMMA:
           MOV ES:[DI],CL       ;PLOT IT
LBL_SKIP_PIXEL:
        INC SI                  ;INCREMENT SOURCE OFFSET
        INC DI                  ;INCREMENT DEST OFFSET
        CMP DI,64000            ;IS DEST OFF < 64000 ?
        JNE  LBL_PLOT_PIXEL

MOV DS,AX	;RESTORE DS
MOV BP,BX	;RESTORE BP
RET 6

RELPCOPYGAMMA ENDP

END

