data segment public
  extrn colors:word
data ends

code segment public
assume cs:code,ds:data
public fade_set,fade_ResetPic


col db 0                        ;Codesegment-Pendant zu Colors


fade_set proc pascal near quelle:dword, start:word, y:word, hoehe:word
  mov ax,colors                 ;Colors in Code-Segment Variable col eintragen
  mov col,al
   push ds
  mov ax,word ptr Quelle + 2    ;Quellzeiger nach ds:si
  mov ds,ax
  mov si,word ptr Quelle

  mov ax,320                    ;Startadresse innerhalb des Quellbilds dazu
  mul start
  add si,ax

  mov ax,0a000h                 ;Zielzeiger 0a000:0 nach es:di
  mov es,ax
  mov ax,320                    ;Startadresse innerhalb des Zielbilds dazu
  mul y
  mov di,ax

  mov ax,320                    ;Hoehe in Anzahl Bytes umrechnen
  imul hoehe
  mov cx,ax

lp:                             ;Hauptschleife
  lodsb                         ;Zielwert in al
  mul col                       ;neuen Farbwert berechnen
  add al,es:[di]                ;aktueller Wert in draufaddieren
  add al,col
  stosb                         ;und zurckschreiben

  dec cx                        ;alle Punkte kopiert ?
  jne lp

  pop ds
  ret
fade_set endp

fade_ResetPic proc pascal far y:word, hoehe:word
  mov ax,0a000h                 ;VGA-Adresse 0a000:0 nach es:di
  mov es,ax

  mov ax,320                    ;Zeile y bercksichtigen
  mul y
  mov di,ax

  mov ax,320                    ;Anzahl zu bearbeitender Bytes berechnen
  mul hoehe
  mov cx,ax
res_lp:
  mov al,es:[di]                ;Wert holen
  xor ah,ah                     ;ah bei Division lschen !
  div byte ptr colors           ;Blocknummer berechnen
  dec al                        ;Reset-Block rausnehmen
  stosb                         ;zurckschreiben

  dec cx                        ;alle Punkte fertig ?
  jne res_lp                    ;nein, dann weiter

  ret
fade_ResetPic endp

code ends
end
