;ISR code

	push AF
	push BC
	push HL
	
;performance counter
perf_counter	EQU $+1
	ld A,0
	inc A
	ld (perf_counter),A

;get if we are on VBL
	ld B,#F5
	in A,(C)
	rra
	jr nc,int_not_VBL

	ld A,#FF
	ld (int_counter),A

;count vbls (seconds*50)
vbl_counter	EQU $+1
	ld HL,0
	inc HL
	ld (vbl_counter),HL
	
.int_not_VBL

int_counter	EQU $+1
	ld A,0
	inc A
	and 7
	ld (int_counter),A

	add A,A
int_table	EQU $+1
	ld HL,int_default_table
	ld C,A
	ld B,0
	add HL,BC
	ld A,(HL)
	inc HL
	ld H,(HL)
	ld L,A

	jp (HL)

.int_done

	pop HL
	pop BC
	pop AF
	ei
	ret
	
;interrupt table - 8 vectors
.int_default_table
dw int_done
dw int_SND_Player
dw int_done
dw int_done
dw int_done
dw int_done
dw int_done
dw int_done

;sound player INT
.int_SND_Player
	ld A,(#4000)
	push AF
	ld BC,#7FC7
	out (C),C
	
	call SND_Run
	
	pop AF
	ld B,#7F
	out (C),A
	jr int_done

