/*
      Stereo/Monaural TEST
*/

/*                 */
/* Include headers */
/*                 */
#include <shinobi.h>

#include "..\include\sndutls.h"

/*                   */
/* Declare Prototype */
/*                   */
void SoundInit( void );
void SoundMain( PDS_PERIPHERAL * );
void main( void );

/*                 */
/* Function Define */
/*                 */

void SoundMain( PDS_PERIPHERAL *pad ) {
  Sint32 st;

  char *mes[] = { "STOP", "PLAY" };

  if ( gdFsGetDrvStat() != GDD_DRVSTAT_PLAY ) {
    st = 0;
  } else {
    st = 1;
  }

  if ( pad->press & PDD_DGT_ST ) {
    if ( st == 0 ) { 
      gdFsDaPlay( 4, 4, 0 );
      sdGddaSetVol( 127, 127 );
    } else {
      gdFsDaStop();
      sdGddaSetVol( 0, 0 );
    }
  }
  njPrint( NJM_LOCATION( 10, 16 ), "%s", mes[ st ] );
}

void main(void)
{
  static Sint32  i = 0;
  PDS_PERIPHERAL *pad;
  Sint32         mode;
  Sint8          *mes[] = { "Stereo", "Monaural" };
  void           *buf;
  GDFS           fs;

  /* Initialize System */
  njSetBorderColor( 0x00000000 );
#ifdef VGA
  sbInitSystem( NJD_RESOLUTION_VGA, NJD_FRAMEBUFFER_MODE_RGB565, 1 );
#else
  sbInitSystem( NJD_RESOLUTION_320x240_NTSCNI, NJD_FRAMEBUFFER_MODE_RGB565, 1 );
#endif
  buf = syMalloc( 16 * 1024 );
  syCfgInit( buf );

  njInitVertexBuffer( 20000, 0, 20000, 0, 0 );
  njInitPrint( NULL, 0, NJD_TEXFMT_ARGB_1555 );
  njSetBackColor( 0x00000000, 0x00000000, 0x000000FF );

  SoundInitialize( "MANATEE.DRV", "STREAM.MLT" );

  syCfgGetSoundMode( &mode );
  if ( mode == SYD_CFG_STEREO ) {
    sdSndSetSpace( SDE_SPACE_STEREO );
  } else {
    sdSndSetSpace( SDE_SPACE_MONO );
  }
  fs = gdFsGetSysHn();

  while ( 1 ) {
    gdFsReqDrvStat();
    while ( gdFsGetStat( fs ) != GDD_STAT_COMPLETE );

    pad = pdGetPeripheral( PDD_PORT_A0 );
    njPrintC( NJM_LOCATION( 10, 3 ), "Stereo/Monaural Test" );
    njPrint( NJM_LOCATION( 5, 5 ), "Boot ROM Setting is %s", mes[ mode ] );
    SoundLibVer( 4, 7 );
    SoundDrvVer( 4, 8 );
    SoundDrvStat( 4, 9 );
    SoundMain( pad );

    sdSysServer();
    njWaitVSync();
  }
}

/******************************* end of file *******************************/
