;INCLUIR ESTAS LINEAS EN EL PLAYER

INICIO:		LD	HL,FADE
		BIT	0,[HL]
		CALL	NZ,FADE_OUT
;_____________________________________________________________________________

;FADE_OUT

FADE		EQU	$E474		;BIT 0 FADE OUT ON/OFF
					;BIT 1 FADE IN  ON/OFF
FADE_METER	EQU	$E475		;DB FADE_METER (TIEMPO DE ACTUACION)
DECAY		EQU	$E476		;DB CADENCIA>1
DECAY_TEMP	EQU	$E477		;DB


;FADE_OUT 100% A 0%
;IN [A]:CADENCIA

START_FADE_OUT:	LD	[DECAY],A
		LD	[DECAY_TEMP],A
		XOR	A
		LD	[FADE_METER],A
		LD	HL,FADE
		SET	0,[HL]
		RET
		
FADE_OUT:	LD	HL,DECAY_TEMP
		DEC	[HL]
		JR	NZ,FADEOJP0
		LD	A,[DECAY]
		LD	[HL],A
		LD	A,[FADE_METER]
		CP	$10			;FADE OUT COMPLETO
		JP	Z,FADE_PLAYER_OFF
		INC	A
		LD	[FADE_METER],A
FADEOJP0:	LD	A,[FADE_METER]
		LD	C,A
		LD	HL,PSG_REG+8
		LD	B,3 
FADEOBC0:	LD	A,[HL]
		SUB	C
		JR	NC,@@NO_RESET_VOL
		XOR	A
@@NO_RESET_VOL:	LD	[HL],A
		INC	HL
		DJNZ	FADEOBC0
		RET
