;*************************
;*** BG effects manager ***
;*************************


;init BG manager
.BG_Init

	xor A
	ld (save_BG_CurrentEffect),A
	ld (save_BG_StopCommand),A
	ld (save_BG_Counter),A
	
	ld A,BG_EffectNull AND 255
	ld (save_BG_Effect_Addr),A
	ld A,BG_EffectNull / 256
	ld (save_BG_Effect_Addr+1),A
	
	;default to no effect
	xor A
	call BG_Effect_Start
	ret

;stop current effect
.BG_Effect_Stop

	ld A,(BG_CurrentEffect)
	
	add A
	ld E,A
	ld D,0
	
	ld HL,BG_Effect_Stop_Table
	add HL,DE
	
	ld E,(HL)
	inc HL
	ld D,(HL)
	push DE
	
	ret
	ret

;Start and effect
; A = effect
.BG_Effect_Start
	
	ld (BG_CurrentEffect),A

	add A
	ld E,A
	ld D,0
	
	ld HL,BG_Effect_Run_Table
	add HL,DE
	
	ld A,(HL)
	inc HL
	ld H,(HL)
	ld L,A
	
	;setup effect run
	ld (BG_Effect_Addr),HL
	
	ld HL,BG_Effect_Start_Table
	add HL,DE
	
	ld E,(HL)
	inc HL
	ld D,(HL)
	
	push DE
	ret	;call effect run
	
	ret
.BG_CurrentEffect
	db 0
.BG_StopCommand 
	db 0
.BG_Counter
	db 0


.BG_Effect_Start_Table
	dw	BG_EffectNull
.BG_LevelEffect0_Init
	dw	BG_EffectNull
.BG_LevelEffect1_Init
	dw	BG_EffectNull
.BG_LevelEffect2_Init
	dw 	BG_EffectNull
	
.BG_Effect_Run_Table
	dw	BG_EffectNull
.BG_LevelEffect0_Run
	dw	BG_EffectNull
.BG_LevelEffect1_Run
	dw	BG_EffectNull
.BG_LevelEffect2_Run
	dw	BG_EffectNull
	
.BG_Effect_Stop_Table
	dw	BG_EffectNull
.BG_LevelEffect0_Stop
	dw	BG_EffectNull
.BG_LevelEffect1_Stop
	dw	BG_EffectNull
.BG_LevelEffect2_Stop
	dw	BG_EffectNull
	
	
.BG_EffectNull
	ret