/* =================================================================================================

  Game / Platform	: Chicken Run - Dreamcast

  File				: sfxtest.c

  Description		: Little menu thingy for testing out the sound FX bank 
					  loading and playing on the Dreamcast

  Author			: James Steele


==================================================================================================== */


#include "global.h"
#include "main.h"
#include "isltex.h"
#include "islfont.h"
#include "islsfx2.h"
#include "loadsnd.h"
#include "menu.h"
#include "islfont.h"


extern psFont * font;

extern SfxBankType	*sampleBanks[6];

void sfxTest_cycle(void);
void sfxTest_draw(void);


SfxBankType * sfxTest_soundBank=NULL;
char sfxTest_menuText[30][64];
int sfxTest_curSel=0;




void sfxTest_start(void)
{
int num, i;

	// ==== Setup the cycle and draw routines....
	cycle_routine = sfxTest_cycle;
	draw_routine = sfxTest_draw;

	// ==== Load the sfx bank and download it to the sound RAM
	num = soundLoadJustBody("TEST");
	sfxTest_soundBank = sampleBanks[num];

	// ==== Setup the menu strings...
	if (sfxTest_soundBank->numSamples > 30)
		num = 30;
	else
		num = sfxTest_soundBank->numSamples;

	i = num;
	for(i=0; i < num; i++)
	{
		sprintf(&sfxTest_menuText[num][0], "Sample %02i", i);
	} // end-while
	
}



void sfxTest_end(void)
{
	sfxUnloadSampleBank(sfxTest_soundBank);
	sfxDestroySampleBank(sfxTest_soundBank);

	menuStart();
}


void sfxTest_cycle(void)
{
	// Play a sample
	if(pReadPad->debounce[0] & PAD_CROSS)
		soundPlaySample(&sfxTest_soundBank->sample[sfxTest_curSel], 255, 0);

	// Previous sample in the bank
	if (pReadPad->debounce[0] & PAD_DOWN || pReadPad->debounce[0] & PAD_RIGHT)
		sfxTest_curSel = (sfxTest_curSel + 1) % sfxTest_soundBank->numSamples;

	// Next sample in the bank
	if (pReadPad->debounce[0] & PAD_UP || pReadPad->debounce[0] & PAD_LEFT)
		sfxTest_curSel = ((sfxTest_curSel - 1) + sfxTest_soundBank->numSamples) % sfxTest_soundBank->numSamples;

}


void sfxTest_draw(void)
{
char selText[30];
int x;

	x = -319 + ((640 - fontExtentW(font, "SoundFX Test")) >> 1);
	fontPrint(font, x, -100, "SoundFX Test", 128, 128, 0);

	//selText = &sfxTest_menuText[sfxTest_curSel][0];

	sprintf(selText, "Sample %i of %i", sfxTest_curSel+1, sfxTest_soundBank->numSamples);
	x = -319 + ((640 - fontExtentW(font, selText)) >> 1);
	fontPrint(font, x, 0, selText, 128, 0, 0);
}


