/*
      One Shot Test
*/

/*                 */
/* Include headers */
/*                 */
#include <shinobi.h>
#include <sg_sd.h>
#include "sndutls.h"

/* Defines */
#define NUMBER_OF_SHOT 7

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

/*                 */
/* Function Define */
/*                 */
void UserVBlankIn() {
  /* Call Sound Server */
  sdSysServer();
}

void SoundInit() {
  SoundInitialize( "MANATEE.DRV", "ONESHOT.MLT" );
}

void SoundMain( PDS_PERIPHERAL *pad ) {
  SDSHOT        oneshot_handle;
  SDE_ERR       err;
  static Uint16 number = 0;
  static Uint16 fx = 0;
  char *msg[] = { "FX Off", "FX On" };

  if ( pad->press & PDD_DGT_ST ) {
    /* Oneshot play */
    sdShotOpenPort( &oneshot_handle );
    sdShotPlay( oneshot_handle, 0, number, 0  );
    sdShotClosePort( oneshot_handle );
  } else if ( pad->press & PDD_DGT_KD ) {
     if ( ++number > NUMBER_OF_SHOT ) number = NUMBER_OF_SHOT;
  } else if ( pad->press & PDD_DGT_KU ) {
    if ( number == 0 ) number = 0;
    else --number;
  }

  njPrintC( NJM_LOCATION( 5, 8 ), "Music No is:" );
  njPrintH( NJM_LOCATION( 18, 8 ), number, 2 );
}

void main(void)
{
  static Sint32  i = 0;
  PDS_PERIPHERAL *pad;

  /* 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
  njInitVertexBuffer( 20000, 0, 20000, 0, 0 );
  njInitPrint( NULL, 0, NJD_TEXFMT_ARGB_1555 );
  njSetBackColor( 0x00000000, 0x00000000, 0x000000FF );

  SoundInit();
  njSetVSyncFunction( UserVBlankIn );

  while ( 1 ) {
    pad = pdGetPeripheral( PDD_PORT_A0 );
    njPrintC( NJM_LOCATION( 5, 3 ), "-- Oneshot Test Sample --" );
    njPrintC( NJM_LOCATION( 5, 4 ), "Up/Down:Select Music" );
    njPrintC( NJM_LOCATION( 5, 5 ), "START  :Play One Shot" );
    SoundLibVer( 5, 10 );
    SoundDrvVer( 5, 11 );
    SoundDrvStat( 5, 12 );

    SoundMain( pad );

    njWaitVSync();
  }
}

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