psg_init.asm
bitfixer_bitfixer/dg/z88dk/libsrc/psg/tiki100/psg_init.asm
;
;	TIKI-100 specific routines
;	by Stefano Bodrato, Fall 2015
;
;	int psg_init();
;
;	Set up the PSG
;
;
;	$Id: psg_init.asm,v 1.1 2015/09/25 14:56:01 stefano Exp $
;

	PUBLIC	psg_init


psg_init:
	

	ld	e,@01010101
	xor a 	; R0: Channel A frequency low bits
	call outpsg

	ld	e,a

	ld d,12
psg_iniloop:
	inc a	; R1-13: set all to 0 but 7 and 11
	cp 7
	jr z,skip
	;cp 11
	;jr z,skip
	call outpsg
skip:
	dec d
	jr	nz,psg_iniloop

	ld	e,@11111000	; R7: Channel setting.  Enable sound channels ABC and input on ports A and B
	ld	a,7
	call outpsg

	ld	e,@00001011	; R11: Envelope
	ld	a,11

outpsg:
    LD	BC,$16
	OUT	(C),a
	LD	C,$17
	OUT	(C),e
	ret

