/*--------------------------------------------------------------------------
   BWPCM8 Demo for WonderWitch
		  Copyright (C) 2001 `nh (http://aoi.i.am/)
----------------------------------------------------------------------------*/
#include <stdio.h>
#include <sys/key.h>
#include <sys/bios.h>
#include <sys/text.h>
#include "bwpcm8.h"

void main(int argc, char **argv)
{
	int		i, n;
	int		loop, key, mode;
	char	buff[80];

	text_set_mode(TEXT_MODE_ANK_SJIS);	/* SJIS[h			*/
	text_screen_init();					/* eLXg[hέθ	*/
	sound_init();
	sound_set_output( OUTPUT_INT_ON | OUTPUT_EXT_ON | OUTPUT_VOL_1 );

	while( key_press_check() );

	n	 = 0;
	mode = 0;
	loop = 1;
	while(loop){
		key = key_press_check();
		switch( key ){
		case KEY_A:
					if( mode!=1 ){
						pcm8_open( PCM_ID_WAV, PCM_FREQ_12K );
						mode = 1;
					}
					if( n<5 ){
						pcm8_start(0, 1, 0);
					}
					sys_wait(20);
					break;
		case KEY_B:
					if( mode!=2 ){
						pcm8_open( PCM_ID_X68, PCM_FREQ_6K );
						mode = 2;
					}
					pcm8_start(1, 2, 0);
					sys_wait(20);
					break;
		case KEY_START:
					loop = 0;
					continue;
					break;
		default:
					break;
		}

		for( i=1, n=0; i<=8; i++ ){
			if( pcm8_read_status(i) ) n++;
		}

		switch( mode ){
		case 1:
				sprintf(buff, "τW@oblC@PQgC@%d@rntmcrD@", n );
				break;
		case 2:
				sprintf(buff, "τS@`coblC@UgD@@@@@@@@@@" );
				break;
		default:
				sprintf(buff, "τavoblW@c@`nh" );
				break;
		}
		text_put_string(0, 17, buff);
		sys_wait(1);
	}
	pcm8_close(0);
	bios_exit();
}
