/*
      Sequance play Test
*/

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

#include "sndutls.h"

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

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

void SoundMain( PDS_PERIPHERAL *pad ) {
  static SDMIDI midi_handle;
  static Sint32 status = 0;
  GDFS          fd;
  char *msg[] = { "STOP", "PLAY" };

  if ( pad->press & PDD_DGT_ST ) {
    if ( status == 0 ) {
      /* Sequence play */
      sdMidiOpenPort( &midi_handle );
      sdMidiPlay( midi_handle, 0, 0, 0 );
      status = 1; 
    } else {
      sdMidiStop( midi_handle );
      sdMidiClosePort( midi_handle );
      status = 0; 
    }
  }

  njPrintC( NJM_LOCATION( 5, 7 ), "Play Status:" );
  njPrintC( NJM_LOCATION( 20, 7 ), msg[ status ] );
}
 
void main(void)
{
  Int            y = 0, x = 0;
  static Sint32  i = 0;
  PDS_PERIPHERAL *pad;

#ifdef __GNUC__
	shinobi_workaround();
#endif
  /* Initialize System */
  njSetBorderColor( 0x00000000 );

  sbInitSystem( NJD_RESOLUTION_320x240_NTSCNI, NJD_FRAMEBUFFER_MODE_RGB565, 1 );

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

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

  njSetVSyncFunction( UserVBlankIn );

  while ( 1 ) {
    pad = pdGetPeripheral( PDD_PORT_A0 );
    njPrintC( NJM_LOCATION( 5, 4 ), "-- Sequence Test --" );
    njPrintC( NJM_LOCATION( 5, 5 ), "START     : Play music" );
    SoundLibVer( 5, 10 );
    SoundDrvVer( 5, 11 );
    SoundDrvStat( 5, 12 );

    SoundMain( pad );

    njWaitVSync();
  }
}

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