/*----------------------------------------------------------------------------------------
If your an audio programmer, and you wish to somehow help me rip a gsf set for the game
you are working on, Implement the following block of code.

For more information on the GSF format, check out GSF central at
http://www.caitsith2.com/gsf/
----------------------------------------------------------------------------------------*/

//Constants Specific to GSF Playback.  Do not change these.
#define MUSIC_MODE_NORMAL 0
#define MUSIC_MODE_GSF 1

#define GSF_STR_LEN 21
#define GSF_MODE 0+GSF_STR_LEN
#define GSF_SONG 1+GSF_STR_LEN


unsigned char GSF_DRIVER_BLOCK[] = {
    //"PSF DRIVER BLOCK V1.0",
    'G','S','F',' ','D','R','I','V','E','R',' ','B','L','O','C','K',' ','V','1','.','0',
    //Do not modify the above line. My automatic ripper looks for this
                             //to know where to begin modifications, for gsflib purposes.
    MUSIC_MODE_NORMAL,      //Always leave this line MUSIC_MODE_NORMAL.
                            //If you define the line as MUSIC_MODE_GSF, then the final
                            //Compiled rom will only play music, and do nothing else.
                            
    0,                      //Reserved for use by MUSIC_MODE_GSF. Do not change.
    
    
    33,                     //Number of songs to follow in this array.
    
    0 ,1 ,2 ,3 ,            //Music numbers in the order specific for the game.
    4 ,5 ,6 ,7 ,            //If you are including voices/sfxs, always put them at the end
    8 ,9 ,10,11,            //of the array, voices, then sfxs.
    12,13,14,15,
    16,17,18,19,            //Anything you do not wish to have included in the GSF set, do
    20,21,22,23,            //not include here.  If the music library your using requires
    24,25,26,27,            //a pointer to reference to, rather than a number, then make
    28,29,30,31,            //another array that references the required pointers, then
    32                      //Put the song number in reference to the pointer here.
};

//Make 100% sure you compile this module with NO Optimizations.  If you
//Optimize this module, The code inside the IF/End If block will be optimized
//out as dead code, and deleted altogether.
//
//The other way to deal with this problem, is to move the GSF_DRIVER_BLOCK
//array to another code file.  Then, the code will not be optimized as dead
//code, which is importent for this easy to rip gsf driver block to work.


void GSF_PLAY()
{
    if(GSF_DRIVER_BLOCK[GSF_MODE]==MUSIC_MODE_GSF)
    {
        //Put All of the necessary code to initialize/play the music, and nothing else
        //here.  GSF_PLAY must be the very first function called, before anything else.
        //You must set up any of the interrupts that are required and everything.
        //If you wish, you can choose to set up the interrupts required first,
        //Then call this function. (these music playing related interrupts are
        //required anyways, so why not.  Just don't set up anything non
        //essential for music playback, until after this function.

        REG_INTERRUPT = (unsigned int)intr_main;
        REG_IE |= INT_TIMER0;
        REG_TM0CNT = 0xC0;
        REG_TM0D = 0xC800;
        initmusic (GSF_DRIVER_BLOCK[GSF_SONG]);
        REG_IME = 0x01;
        
        while(1)    //Leave in this while loop. It is what keeps the rest of the game
                    //code from executing. Uncomment only one of the lines. depending on
		    //What mode this code is compiled in.  This is what keeps the CPU
		    //usage down in whatever player is playing the GSF.
        {
            asm volatile ("swi 0x020000" ::: "r0", "r1", "r2", "r3");  //For ARM code
	    //asm volatile ("swi 0x02" ::: "r0", "r1", "r2", "r3");    //For Thumb code
        }
        
    }
}

/*----------------------------------------------------------------------------------------
    End of GSF DRIVER BLOCK CODE
----------------------------------------------------------------------------------------*/