Example #1
0
int main()
{
	TME_Init();
	SND_Init();
	usb_init();
	_delay_ms(1000);

	unsigned long endTime;
	SND_Beep(220, 1000);
	endTime = TME_GetAccurateMillis + 1000;
	while(TME_GetAccurateMillis() < endTime)
	{
		SND_Update();
	}
	
	SND_Beep(880, 2000);
	endTime = TME_GetAccurateMillis + 2000;
	while(TME_GetAccurateMillis() < endTime)
	{
		SND_Update();
	}
	
	SND_Beep(110, 3000);
	endTime = TME_GetAccurateMillis + 3000;
	while(TME_GetAccurateMillis() < endTime)
	{
		SND_Update();
	}
	
	
	
	return 0;
}
Example #2
0
void dEngine_Init(void) 
{
	FS_InitFilesystem();
    Log_Printf("dEngine Initialization...\n");
    
	ENT_InitCacheSystem();
	TEXT_InitCacheSystem();
	MAT_InitCacheSystem();

#ifdef GENERATE_VIDEO	
	dEngine_INIT_ScreenshotBuffer();
#endif
	
	engine.sceneId = -1;
	dEngine_RequireSceneId(0);
	
	//engine.recordVideo = 0;
	
	engine.musicFilename[0] = '\0';
	engine.musicStartAt = 0;
	engine.playback.filename[0] = '\0';
	
	engine.soundEnabled = 1;
	engine.musicEnabled = 1;
	engine.gameCenterEnabled = 0;
	
	ENPAR_Init();
	
	

	dEngine_ReadConfig();

	SCR_Init();
	
	
	
	
	MATLIB_LoadLibraries();
	

	
	COLL_InitUnitCube();
	
	
	ENE_Mem_Init();
	
	SND_Init();
	
	
	MENU_Init();
	
	
}
Example #3
0
int main(int argc, char* argv[])
{
	u8 *tex_ptrone=GRRLIB_LoadTexture(handpointerred_png);
	u8 *tex_ptrtwo=GRRLIB_LoadTexture(handpointergreen_png);
	u8 *tex_back=GRRLIB_LoadJPG(bigmenuback_jpg, bigmenuback_jpg_size);
	u8 *tex_fore=GRRLIB_LoadTexture(credits_png);

    fatInitDefault();
    GRRLIB_InitVideo();
	WPAD_Init();

	SYS_SetResetCallback(WiiResetPressed);
	SYS_SetPowerCallback(WiiPowerPressed);
	WPAD_SetPowerButtonCallback(WiimotePowerPressed);
    rmode = VIDEO_GetPreferredMode(NULL);

    SND_Init(INIT_RATE_48000); // Initialize the Sound Lib

	MODPlay_Init(&mod_track);

    SND_Pause(0); // the sound loop is running now

	if (MODPlay_SetMOD (&mod_track, dojo_dan_oriental_mod) < 0 ) // set the MOD song
    {
        MODPlay_Unload (&mod_track);
    }
	else
    {
        // set the music volume to the minimum so we don't hear the music before saved volume is known
        MODPlay_SetVolume( &mod_track, 0,0);
        MODPlay_Start (&mod_track); // Play the MOD
    }

    WPAD_SetDataFormat(WPAD_CHAN_ALL, WPAD_FMT_BTNS_ACC_IR);

	WPAD_SetVRes(WPAD_CHAN_ALL, rmode->fbWidth, rmode->xfbHeight);

    initMain();

	MODPlay_SetVolume( &mod_track, opt_music, opt_music);

	while( HWButton == 0) {
		WPAD_ScanPads();
		u32 wpad_one_down = WPAD_ButtonsDown(0);
		u32 wpad_two_down = WPAD_ButtonsDown(1);

		u32 type;
		WPADData *wd_one, *wd_two;
		WPAD_ReadPending(WPAD_CHAN_ALL, countevs);
		WPAD_Probe(WPAD_CHAN_ALL, &type);

		wd_one = WPAD_Data(0);
		wd_two = WPAD_Data(1);

		switch(main_mode) {
			case STARTUP :
				GRRLIB_FillScreen(0xFF000000);
				GRRLIB_DrawImg(0, 0, 640, 480, tex_back, 0, 1, 1, alpha>255?255:alpha);
				GRRLIB_DrawImg(68,308, 256, 80, tex_fore, 0, 1, 1, alpha>255?255:alpha);
				if(alpha++>394 || wpad_one_down > 0) {
					main_mode=MENU;
					if(tex_back) free(tex_back);
					if(tex_fore) free(tex_fore);
					initMenu();
				}
				break;
			case MENU :
				GRRLIB_FillScreen(0xFF000000);
				int menuopt = menuWiimote(wd_one,wpad_one_down);
				if(menuopt==EXIT) {
					if(tex_ptrone) free(tex_ptrone);
					if(tex_ptrtwo) free(tex_ptrtwo);
				}

				if(menuopt>NOTHING) {
					processMenuOption(menuopt);
					if(main_mode==GAME) {
						MODPlay_Unload (&mod_track);
						if(opt_tileset==SPOOKY)
							MODPlay_SetMOD (&mod_track, graveyard_mod);
						else
						if(opt_tileset==EGYPTIAN)
							MODPlay_SetMOD (&mod_track, egypt_crap_mod);
						else
						if(opt_tileset==SIMPLE)
							MODPlay_SetMOD (&mod_track, childhood_mod);
						else
						if(opt_tileset==SPACE)
							MODPlay_SetMOD (&mod_track, nebulos_mod);
						else
							MODPlay_SetMOD (&mod_track, sushi_mod);
						MODPlay_SetVolume( &mod_track, opt_music, opt_music);
						MODPlay_Start (&mod_track);
					}
					else
						drawMenu(wd_one);
				}
				else
					drawMenu(wd_one);
				break;
			case GAME :
				if(gameWiimote(wd_one,wpad_one_down,wd_two,wpad_two_down)) {
					// we are exiting the game back to the menu
					main_mode=MENU;
					MODPlay_Unload (&mod_track);
					MODPlay_SetMOD (&mod_track, dojo_dan_oriental_mod);
					MODPlay_SetVolume( &mod_track, opt_music, opt_music);
					MODPlay_Start (&mod_track);
					killGame();
					initMenu();
				}
				else {
					drawGame();
				}
				break;
		}

		// alternate which pointer is on top every frame to not give the advantage to player one in two player mode
		static int ticktock=0;

		ticktock++;

		if(wd_two->ir.valid && ticktock%2==0) {
			if(main_mode==GAME && whatGameMode()==ONE_PLAYER_GAME) {
				// don't display second pointer in one player mode
			}
			else
				GRRLIB_DrawColImg(wd_two->ir.x - 9,wd_two->ir.y - 7,68,80,tex_ptrtwo,0,1,1,0xEEFFFFFF);
		}

		if(wd_one->ir.valid) {
			GRRLIB_DrawColImg(wd_one->ir.x - 9,wd_one->ir.y - 7,68,80,tex_ptrone,0,1,1,0xEEFFFFFF);
		}

		if(wd_two->ir.valid && ticktock%2!=0) {
			if(main_mode==GAME && whatGameMode()==ONE_PLAYER_GAME) {
				// don't display second pointer in one player mode
			}
			else
				GRRLIB_DrawColImg(wd_two->ir.x - 9,wd_two->ir.y - 7,68,80,tex_ptrtwo,0,1,1,0xEEFFFFFF);
		}

		if(wd_one->btns_h & WPAD_BUTTON_1) {
			GRRLIB_ScrShot("MahjonggWii_Screen_%y%m%d_%H%M%S.png",time(NULL));
		}

		GRRLIB_Render();
	}

    // we are exiting, free the mallocs
    switch( main_mode)
    {
        case GAME:
            killGame();

    }
    if(tex_ptrone) free(tex_ptrone);
    if(tex_ptrtwo) free(tex_ptrtwo);
    killMenuLanguages();
	MODPlay_Unload (&mod_track);
    WPAD_Shutdown();
    SND_End();
    GRRLIB_Stop();
    saveConfig(FILE_CFG);
    SYS_ResetSystem(HWButton, 0, 0);

	return 0;
}
Example #4
0
void LagTest()
{
	char			msg[60], strings[100];
	int				clicks[10], done = 0, view = 0, speed = 1, change = 1;
	int				x, y, x2, y2, pos = 0, i = 0, vary = 0, variation = 1;
	u16				pressed, audio = 0, rumble = 0;
	ImagePtr		back, spriteA, spriteB, fixed;
	char 			**ControllerButtons = NULL;
	
	
	srand((int)(time(0)));	
	back = LoadImage(WHITEIMG, 1);
	if(!back)
		return;
	
	back->r = 0x00;
	back->g = 0x00;
	back->b = 0x00;
	
	fixed = LoadImage(LAGPERIMG, 0);
	if(!fixed)
		return;
	spriteA = LoadImage(LAGPERIMG, 0);
	if(!spriteA)
	{
		FreeImage(&fixed);
		return;
	}
	spriteB = LoadImage(LAGPERIMG, 0);
	if(!spriteB)
	{
		FreeImage(&spriteA);
		FreeImage(&fixed);
		return;
	}
		
	SND_Init(INIT_RATE_48000); 
    SND_Pause(0); 	

	x = 144;
	y = 60;
	x2 = 108;
	y2 = 96;
		
	fixed->x = 144;
	fixed->y = 96;	

	for(i = 0; i < 10; i++)
		clicks[i] = 0xFF;

	while(!done && !EndProgram) 
	{
		StartScene();

		DrawImage(back);
		DrawImage(fixed);

		if(y > 132 + vary)
		{
			speed = -1;
			change = 1;
			if(variation)
			{
				if(rand() % 2)
					vary = rand() % 7;
				else
					vary = -1 * rand() % 7;
			}
		}

		if(y < 60 + vary)
		{
			speed = 1;
			change = 1;
			if(variation)
			{
				if(rand() % 2)
					vary = rand() % 7;
				else
					vary = -1 * rand() % 7;
			}
		}

		y += speed;
		x2 += speed;

		spriteA->x = x;
		spriteA->y = y;
		spriteB->x = x2;
		spriteB->y = y2;
		
		if(y == 96)
		{			
			if(audio)
				SND_SetVoice(SND_GetFirstUnusedVoice(), VOICE_STEREO_16BIT, 44100, 0, beep_snd, beep_snd_size, speed == -1 ? 0 : 255, speed == -1 ? 255 : 0, NULL);				
				
			if(rumble)
				ControllerRumble(0, 1);
			
			spriteA->r = 0xff;
			spriteA->g = 0x00;
			spriteA->b = 0x00;

			spriteB->r = 0xff;
			spriteB->g = 0x00;
			spriteB->b = 0x00;
		}
		else
		{
			if(rumble)
				ControllerRumble(0, 0);
				
			if(y == 97 || y == 95) // one pixel off
			{
				spriteA->r = 0x00;
				spriteA->g = 0xff;
				spriteA->b = 0x00;

				spriteB->r = 0x00;
				spriteB->g = 0xff;
				spriteB->b = 0x00;
			}

			if(y == 98 || y == 94) // two pixels off
			{
				spriteA->r = 0xff;
				spriteA->g = 0xff;
				spriteA->b = 0xff;

				spriteB->r = 0xff;
				spriteB->g = 0xff;
				spriteB->b = 0xff;
			}
		}			

		if(view == 0 || view == 2)
			DrawImage(spriteA);

		if(view == 1 || view == 2)
			DrawImage(spriteB);

		for(i = 0; i < 10; i++)
		{
			if(clicks[i] != 0xFF)
			{
				int px, py;

				px = 10;
				py = i*fh + 20;
	
				sprintf(msg, "Offset %02d:", i + 1);
				DrawStringS(px, py, 0xff, 0xff, 0xff, msg);
			
				px += (strlen(msg) + 2)*fw;
				if(clicks[i] == 1)
					sprintf(msg, "%2d frame", clicks[i]);
				else
					sprintf(msg, "%2d frames", clicks[i]);

				if(clicks[i] >= 0)
				{
					if(clicks[i] == 0)
						DrawStringS(px, py, 0x00, 0xff, 0x00, msg);
					else
						DrawStringS(px, py, 0xff, 0xff, 0xff, msg);
				}
				else
					DrawStringS(px, py, 0xff, 0x00, 0x00, msg);
			}
		}

		sprintf(msg, "Audio: %s", audio ? "on" : "off");
		DrawStringS(200, 20, 0xff, 0xff, 0xff, msg);
		sprintf(msg, "Timing: %s", variation ? "random" : "rhythmic");
		DrawStringS(200, 20+fh, 0xff, 0xff, 0xff, msg);		
		sprintf(msg, "Rumble: %s", rumble ? "on" : "off");
		DrawStringS(200, 20+2*fh, 0xff, 0xff, 0xff, msg);		

#ifdef WII_VERSION
		if(ControllerType == ControllerWiimote)
			ControllerButtons = ControlNamesWii;
			
		if(ControllerType == ControllerWiiClassic)
		{
			if(Options.SFCClassicController)
				ControllerButtons = ControlNamesWiiSFC_CC;
			else
				ControllerButtons = ControlNamesWiiCC;
		}
			
		if(ControllerType == ControllerGC)
#endif
			ControllerButtons = ControlNamesGC;
			
		sprintf(strings, "Press \"%c\" when the sprite is aligned with the background.", ControllerButtons[ControlButtonA][0]);
		DrawStringS(20, 170, 0x00, 0xff, 0x00, strings);
		
		sprintf(strings, "Negative values mean you pressed \"%c\" before they intersected", ControllerButtons[ControlButtonA][0]);
		DrawStringS(20, 170+fh, 0x00, 0xff, 0x00, strings);
		
		sprintf(strings, "\"%c\" button toggles horizontal and vertical movement.", ControllerButtons[ControlButtonX][0]);
		DrawStringS(20, 170+2*fh, 0x00, 0xff, 0x00, strings);
		
		sprintf(strings, "\"%c\" trigger toggles rhythmic timing.", ControllerButtons[ControlButtonY][0]);
		DrawStringS(20, 170+3*fh, 0x00, 0xff, 0x00, strings);
		
		sprintf(strings, "\"%c\" button toggles audio feedback.", ControllerButtons[ControlButtonR][0]);
		DrawStringS(20, 170+4*fh, 0x00, 0xff, 0x00, strings);
		
		sprintf(strings, "\"%c\" button toggles rumble feedback.", ControllerButtons[ControlButtonL][0]);
		DrawStringS(20, 170+5*fh, 0x00, 0xff, 0x00, strings);

		EndScene();
		
		ControllerScan();
		pressed = Controller_ButtonsDown(0);
		if (pressed & PAD_BUTTON_B)
			done =	1;
			
		if (pressed & PAD_BUTTON_START)		
		{
			DrawMenu = 1;					
			HelpData = MANUALLAG;
		}
			
		if (pressed & PAD_BUTTON_A)
		{
			if(change)
			{
				clicks[pos] = (y - 96) *speed;
	
				sprintf(msg, " Off: %d", clicks[pos]);					
	
				if(clicks[pos] >= 0)
				{
					change = 0;
					pos ++;
				}
		
				if(pos > 9)
					done = 1;
			}
		}

		if (pressed & PAD_TRIGGER_R)
			audio =	!audio;	
			
		if (pressed & PAD_TRIGGER_L)
		{
			rumble = !rumble;	
			if(!rumble)
				ControllerRumble(0, 0);
		}
			
		if (pressed & PAD_BUTTON_X)
		{
			view ++;
			if(view > 2)
				view = 0;
		}
					
    					
		if(pressed & PAD_BUTTON_Y)
		{
			variation = !variation;
			if(!variation)
				vary = 0;
		}
	}
    
	ControllerRumble(0, 0);

	FreeImage(&back);
	FreeImage(&fixed);
	FreeImage(&spriteA);
	FreeImage(&spriteB);	
	
	if(pos > 9)
	{
		int	total = 0;
		double	res = 0, ms = 0;
		ImagePtr wall;
		
		done = 0;
		wall = LoadImage(BACKIMG, 0);
		if(!wall)
			return;
		
		while(!done && !EndProgram) 
		{			
			StartScene();

			DrawImage(wall);

			total = 0;
			for(i = 0; i < 10; i++)
			{
				int px, py;
	
				px = 70;
				py = i*fh + 70;
	
				sprintf(msg, "%2d", clicks[i]);
				if(clicks[i] >= 0)
				{
					if(clicks[i] == 0)
						DrawStringS(px, py, 0, 0xff, 0, msg);
					else
						DrawStringS(px, py, 0xff, 0xff, 0xff, msg);
				}
				else
					DrawStringS(px, py, 0xff, 0, 0, msg);
	
				if(clicks[i] >= 0)
					total += clicks[i];
	
			}

			if(!IsPAL)
			{
				res = (double)total / 10.0;
				ms = (double)(res*(1000.0/60.0));
				sprintf(msg, "%d/10 = %0.2f average frames ~= %0.2f ms", total, res, ms);
				DrawStringS(60, 110, 0xff, 0x00, 0x00, "+");
				DrawStringS(55, 70 + fh*10, 0xff, 0x00, 0x00, "_____");
				DrawStringS(60, 70 + fh*11, 0xff, 0xff, 0xff, msg);
				DrawStringS(30, 70 + fh*12, 0x00, 0xff, 0xff, "Keep in mind that an NTSC frame is around 16.67 ms");
			}
			else
			{
				res = (double)total / 10.0;
				ms = (double)(res*(1000.0/50.0));
				sprintf(msg, "%d/10 = %0.2f average frames ~= %0.2f ms", total, res, ms);
				DrawStringS(60, 110, 0xff, 0x00, 0xff, "+");
				DrawStringS(55, 70 + fh*10, 0xff, 0x00, 0x00, "_____");
				DrawStringS(60, 70 + fh*11, 0xff, 0xff, 0xff, msg);
				DrawStringS(40, 70 + fh*12, 0x00, 0xff, 0xff, "Keep in mind that a PAL frame is around 20 ms");
			}

			if(total && total < 5)
			{
				DrawStringS(100, 120, 0x00, 0xff, 0x00, "EXCELLENT REFLEXES!");
			}
			if(total == 0)
			{
				DrawStringS(100, 120, 0x00, 0xff, 0x00, "INCREDIBLE REFLEXES!!");
			}

			EndScene();
			
			ControllerScan();
		
		    pressed = Controller_ButtonsDown(0);		
			
			if (pressed & PAD_BUTTON_B)
				done =	1;	
	
			if (pressed & PAD_BUTTON_START)		
			{
				DrawMenu = 1;					
				HelpData = MANUALLAG;
			}
		}
		FreeImage(&wall);
	}
	SND_End();
	
	return;
}
Example #5
0
void SoundTest()
{
	int 			done = 0, sel = 1, play = 0, aleft = 0, aright = 0;
	u32			    pressed;		
	ImagePtr		back;	
	
	back = LoadImage(BACKIMG, 0);
	if(!back)
		return;
		
    SND_Init(INIT_RATE_48000); 
    SND_Pause(0);
	while(!done && !EndProgram) 
	{
		StartScene();
		DrawImage(back);

		DrawStringS(130, 60, 0xff, 0xff, 0xff, "Sound Test"); 
		DrawStringS(80, 120, 0xff, sel == 0 ? 0 : 0xff, sel == 0 ? 0 : 0xff, "Left Channel"); 
		DrawStringS(120, 130, 0xff, sel == 1 ? 0 : 0xff, sel == 1 ? 0 : 0xff, "Center Channel");
		DrawStringS(160, 120, 0xff, sel == 2 ? 0 : 0xff, sel == 2 ? 0 : 0xff, "Right Channel");
		EndScene();

		ControllerScan();
		
        pressed = Controller_ButtonsDown(0);		
		if (pressed & PAD_BUTTON_B)
			done =	1;								

		if (pressed & PAD_BUTTON_A)
			play =	1; 								

		if (pressed & PAD_BUTTON_LEFT)
			sel --;

		if (pressed & PAD_BUTTON_RIGHT)
			sel ++;

		if ( pressed & PAD_BUTTON_START ) 		
		{
			DrawMenu = 1;					
			HelpData = SOUNDHELP;
		}																	
		
		if(sel < 0)
			sel = 2;

		if(sel > 2)
			sel = 0;
		
		switch(sel)
		{
			case 0:
				aleft = 0xff;
				aright = 0x00;
				break;
			case 1:
				aleft = 0xff;
				aright = 0xff;
				break;
			case 2:
				aleft = 0x00;
				aright = 0xff;
				break;
		}

		if(play)
		{
			SND_SetVoice(SND_GetFirstUnusedVoice(), VOICE_STEREO_16BIT, 44100, 0, beep_snd, beep_snd_size, aleft, aright, NULL);				
			play = 0;
		}        

	}    
	FreeImage(&back);
	SND_End();
	return;
}
Example #6
0
void dEngine_Init()
{
	ENT_InitCacheSystem();
	TEXT_InitCacheSystem();
	MAT_InitCacheSystem();

#ifdef GENERATE_VIDEO	
	dEngine_INIT_ScreenshotBuffer();
#endif
	
	engine.sceneId = -1;
	dEngine_RequireSceneId(0);
	
	//engine.recordVideo = 0;
	
	engine.musicFilename[0] = '\0';
	engine.musicStartAt = 0;
	engine.playback.filename[0] = '\0';
	
	engine.soundEnabled = 1;
	engine.musicEnabled = 1;
	engine.gameCenterEnabled = 0;
	
	ENPAR_Init();
	
	
	FS_InitFilesystem();

	dEngine_ReadConfig();

	SCR_Init();
	
	
	
	
	MATLIB_LoadLibraries();
	

	
	COLL_InitUnitCube();
	
	
	ENE_Mem_Init();
	
	SND_Init();
	
	
	MENU_Init();
	
	
	
	//TESTS
	/*
	char c = CHAR_MAX;
	unsigned char uc = UCHAR_MAX;
	short s = SHRT_MAX;
	unsigned short us = USHRT_MAX;
	int i = INT_MAX;
	unsigned int ui = UINT_MAX;
	long l = LONG_MAX;
	unsigned long ul = ULONG_MAX;
	
	printf("\n");
	printf("LIMITS: c:%d, uc:%u, s:%d, us:%u\n"
		   "LIMITS: i:%d, ui:%u, l:%ld, ul:%lu\n",
		   c, uc, s, us, i, ui, l, ul);
	
	// promotion 
	printf("\n");
	printf("i = s: %d, \n", i = s);
	printf("i = us: %d, \n", i = us);
	printf("ui = s: %u, \n", ui = s);
	printf("ui = us: %u\n", ui = us);
	
	// narrowing 
	printf("\n");
	printf("c = s: %d, \n", c = s);
	printf("c = us: %d, \n", c = us);
	printf("uc = s: %d, \n", uc = s); //Ln:31
	printf("uc = us: %d\n", uc = us);
	
	printf("\n");
	printf("uc = UCHAR_MAX (%u) + 1: %u, \n",
		   UCHAR_MAX, uc = UCHAR_MAX + 1); // Ln:36 
	printf("uc = -1: %d\n", uc = -1);
	*/
	
}