main.c B:B/ϯiRmain.c"GI?l@TEXTCWIE@ :/ϯiR#include #include "pad.h" //Header file containing functions to use the game pad. //******************************** // Simple CD-Player. Shows how to // draw text onto the screen, play // a CD and read from the game pad // using PAD.H //******************************** main() { int track[10]={1,2,3,4,5,6,7,8,9,0}; //First an array of tracks must be set up. //This can be in any order you want them played int track_num=0; //The index of the track array to be played RECT r1,r2; //The rectangles in VRAM to clear the screen ResetGraph(0); //Reset the graphics mode GsInitGraph(320,256,GsOFSGPU,1,0); //Init the graphics mode to 320*256 GsDefDispBuff(0,0,0,256); //Set up the display buffer r1.x=0; //The first rectangle set in the first buffer r1.y=0; r1.h=256; r1.w=320; r2.x=0; //And the second in the second buffer r2.y=256; r2.h=256; r2.w=320; SsSetSerialAttr(SS_CD,SS_MIX,SS_SON); //Turn on the mixer SsSetSerialVol(SS_CD,127,127); //Turn up the volume of the CD-Audio SsSetMVol(127,127); //Turn up the master volume (note:127 is the max // volume) FntLoad(960, 256); //Set up the area of memory that contains the font FntOpen(16, 16, 256, 200, 0, 512); //Set up the window on the screen ClearImage(&r1,0,0,0); //Clear the first screen DrawSync(0); ClearImage(&r2,0,0,0); //Clear the second screen DrawSync(0); FntPrint("Insert Music CD and press START"); //Print a message FntFlush(-1); //Flip the text to the screen GsSwapDispBuff(); //Flip the switch the double buffers PadInit(); //Initialise the pad while(!(PadRead() & PADstart)); //wait until the user presses start CdPlay(1,track,track_num); //Play the first track ClearImage(&r1,0,0,0); //Clear the screen (of text) DrawSync(0); ClearImage(&r2,0,0,0); //And the double buffer DrawSync(0); while(!(PadRead() & PADselect)) { FntPrint("Track playing=%d\n",track[CdPlay(3,track,0)]); //Print out the current track FntPrint("Press SELECT to Quit\n"); FntPrint("Press R1 to Play Next Track\n"); FntPrint("Press L1 to Play Previous Track\n"); FntFlush(-1); //Flip the text to the screen VSync(0); //Syncronise the drawind with the vertical retrace //of the monitor (stops flickering) GsSwapDispBuff(); //Swap the double buffers if(GsGetActiveBuff()==1) //Clear the appropriate double buffer { ClearImage(&r2,0,0,0); DrawSync(0); } else { ClearImage(&r1,0,0,0); DrawSync(0); } if(PadRead()&PADR1&&track_num<9) //If the user presses R1 then go onto the next track { track_num++; CdPlay(0,track,0); CdPlay(1,track,track_num); } else if(PadRead()&PADL1&&track_num>0) //If the user presses L1 then go onto the previous track { track_num--; CdPlay(0,track,0); CdPlay(1,track,track_num); } } ClearImage(&r1,0,0,0); //Clear the screen DrawSync(0); ClearImage(&r2,0,0,0); DrawSync(0); FntPrint("Finished!"); //Say goodbye FntFlush(-1); //Flip the text to the screen GsSwapDispBuff(); CdPlay(0,track,0); //Stop the CD }2main.cmTEXTCWIE2TEXTCWIE/ : !).357<CGQY2D2MWBB