		org		#8000
		;;limit		#bfff
IntOn:
        LD      A,0
        AND     A                       ; Driver already installed?
        RET     NZ                      ; If yes, does nothing
        INC     A
        LD      (IntOn+1),A             ; Indicates driver 
        LD      HL,BlocEvent
        LD      DE,InterruptLoop
        LD      BC,#8100
        JP      #BCD7

InterruptLoop:
        call equalizer
        ret

.equalizer
		di
		ld		hl,#cdA0
		ld		e,8       ; First PSG Volume reg

		call		draw_bars
		call		draw_bars

.draw_bars
		push		hl
		call		read_from_psg
		and		&0f
		add		1
		inc		e
		ld		c,a
		or		a
		jr		z,nobars
		ld		b,a

.bars
		call		prev_line
		ld		(hl),#6f
		djnz		bars

.nobars
		ld		a,15
		sub		c
		add		1
		jr		z,noblank
		ld		b,a

.blank
		call		prev_line
		ld		(hl),0
		djnz		blank

.noblank
		pop		hl
		inc		hl
		inc		hl
		ret

.prev_line
		ld		a,h
		sub		16 ;;8 ;; 16
		cp		#c0
		jr		nc,line_ok
		ld		a,l
		sub		#50
		ld		l,a
		ld		a,h
		sbc		&d0 ;;#c8   ;; d0
.line_ok
		ld		h,a
		ei
		ret

.read_from_psg
		ld		b,#f4
		out		(c),e
		ld		bc,#f6c0
		out		(c),c
		xor		a
		out		(c),a
		ld		bc,#f7d2
		out		(c),c
		ld		bc,#f640
		out		(c),c
		ld		b,#f4
		in		a,(c)
		ld		bc,#f7c2
		out		(c),c
		ld		bc,#f600
		out		(c),c
		ret
BlocEvent:
        DS      16