static int show_options(char *game)
{
	unsigned long ExKey=0;
	int selected_option=0;
	int x_Pos = 41;
	int y_Pos = 43;
	int options_count = 12;
	char text[256];
	FILE *f;
	int i=0;

	while(ExKey=gp2x_joystick_read(0)&0x8c0ff55){
		gp2x_video_flip();
		gp2x_timer_delay(1);
	};

	/* Read game configuration */
	sprintf(text,get_documents_path("frontend/%s_v5.cfg"),game);
	f=fopen(text,"r");
	if (f) {
		fscanf(f,"%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",&m4all_video_aspect,&m4all_video_rotate,&m4all_video_sync,
		&m4all_frameskip,&m4all_sound,&m4all_buttons,&m4all_clock_cpu,&m4all_clock_sound,&i,&m4all_cheat,&m4all_video_depth,&m4all_waysStick,&m4all_cpu_cores);
		fclose(f);
	}

	while(1)
	{
		/* Draw background image */
		load_bmp_8bpp(gp2x_screen8,gp2xmenu_bmp);

		/* Draw the options */
		gp2x_gamelist_text_out(x_Pos,y_Pos,"Selected Game:\0");
		strncpy (text,game_list_description(last_game_selected),33);
		text[32]='\0';
		gp2x_gamelist_text_out(x_Pos,y_Pos+10,text);

		/* (1) Video Aspect */
		switch (m4all_video_aspect)
		{
			case 0: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video Aspect  Original"); break;
			/*
			case 1: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video Aspect  Ratio Not Kept"); break;
			*/
			case 1: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video Aspect  Cropping 4/3"); break;
			case 2: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video Aspect  Cropping 3/4"); break;

			case 3: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video Aspect  Fixed 320x240"); break;
			case 4: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video Aspect  Fixed 240x320"); break;
			case 5: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video Aspect  Fixed 640x480"); break;
			case 6: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video Aspect  Fixed 480x640"); break;
		}

		/* (2) Video Rotation */
		switch (m4all_video_rotate)
		{
			case 0: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+40,"Video Rotate  No"); break;
			case 1: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+40,"Video Rotate  Yes"); break;
			case 2: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+40,"Video Rotate  TATE"); break;
		}
		
		/* (3) Video Depth */
		switch (m4all_video_depth)
		{
			case -1: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+50,"Video Depth   Auto"); break;
			case 8:  gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+50,"Video Depth   8 bit"); break;
			case 16: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+50,"Video Depth   16 bit"); break;
		}

		/* (4) Video Sync */
		switch (m4all_video_sync)
		{
			case 0: gp2x_gamelist_text_out(x_Pos,y_Pos+60, "Video Sync    Normal"); break;
			case 1: gp2x_gamelist_text_out(x_Pos,y_Pos+60, "Video Sync    DblBuf"); break;
			case -1: gp2x_gamelist_text_out(x_Pos,y_Pos+60,"Video Sync    OFF"); break;
		}
		
		/* (5) Frame-Skip */
		if(m4all_frameskip==-1) {
			gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70, "Frame-Skip    Auto");
		}
		else{
			gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Frame-Skip    %d",m4all_frameskip);
		}

		/* (6) Sound */
		switch(m4all_sound)
		{
			case 0: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+80,"Sound         %s","OFF"); break;

			case 1: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+80,"Sound         %s","ON (11 KHz fast)"); break;
			case 2: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+80,"Sound         %s","ON (22 KHz fast)"); break;
			case 3: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+80,"Sound         %s","ON (33 KHz fast)"); break;
			case 4: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+80,"Sound         %s","ON (44 KHz fast)"); break;

			case 5: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+80,"Sound         %s","ON (11 KHz)"); break;
			case 6: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+80,"Sound         %s","ON (22 KHz)"); break;
			case 7: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+80,"Sound         %s","ON (33 KHz)"); break;
			case 8: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+80,"Sound         %s","ON (44 KHz)"); break;

			case 9: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+80,"Sound         %s","ON (11 KHz stereo)"); break;
			case 10: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+80,"Sound         %s","ON (22 KHz stereo)"); break;
			case 11: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+80,"Sound         %s","ON (33 KHz stereo)"); break;
			case 12: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+80,"Sound         %s","ON (44 KHz stereo)"); break;

		}

		/* (7) Landscape Num Buttons */
		switch (m4all_waysStick)
		{
			case 8: gp2x_gamelist_text_out(x_Pos,y_Pos+90, "Stick         8-way"); break;
			case 4: gp2x_gamelist_text_out(x_Pos,y_Pos+90, "Stick         4-way"); break;
			case 2: gp2x_gamelist_text_out(x_Pos,y_Pos+90, "Stick         2-way"); break;
		}

		/* (8) Landscape Num Buttons */
		switch (m4all_buttons)
		{
		    case 0: gp2x_gamelist_text_out(x_Pos,y_Pos+100, "Num Buttons   0 Button"); break;
		    case 1: gp2x_gamelist_text_out(x_Pos,y_Pos+100, "Num Buttons   1 Button"); break;
			case 2: gp2x_gamelist_text_out(x_Pos,y_Pos+100, "Num Buttons   2 Buttons"); break;
			case 3: gp2x_gamelist_text_out(x_Pos,y_Pos+100, "Num Buttons   3 Buttons (A=B+X)"); break;
			case 4: gp2x_gamelist_text_out(x_Pos,y_Pos+100, "Num Buttons   3 Buttons"); break;
			case 5: gp2x_gamelist_text_out(x_Pos,y_Pos+100, "Num Buttons   4 Buttons"); break;
			case 6: gp2x_gamelist_text_out(x_Pos,y_Pos+100, "Num Buttons   All Buttons"); break;
		}

		/* (9) CPU Clock */
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+110,"CPU Clock     %d%%",m4all_clock_cpu);

		/* (10) Audio Clock */
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+120,"Audio Clock   %d%%",m4all_clock_sound);

		/* (11) CPU ASM Cores */

		if(m4all_ASMCores)
		{
			switch (m4all_cpu_cores)
			{
				case 0: gp2x_gamelist_text_out(x_Pos,y_Pos+130, "CPU ASM cores None"); break;
				case 1: gp2x_gamelist_text_out(x_Pos,y_Pos+130, "CPU ASM cores Cyclone"); break;
				case 2: gp2x_gamelist_text_out(x_Pos,y_Pos+130, "CPU ASM cores DrZ80"); break;
				case 3: gp2x_gamelist_text_out(x_Pos,y_Pos+130, "CPU ASM cores Cyclone+DrZ80"); break;
				case 4: gp2x_gamelist_text_out(x_Pos,y_Pos+130, "CPU ASM cores DrZ80(snd)"); break;
				case 5: gp2x_gamelist_text_out(x_Pos,y_Pos+130, "CPU ASM cores Cyclone+DrZ80(snd)"); break;
				case 6: gp2x_gamelist_text_out(x_Pos,y_Pos+130, "CPU ASM cores All"); break;
			}
		}
		else
		{
			gp2x_gamelist_text_out(x_Pos,y_Pos+130, "CPU ASM cores None");
		}

		/* (12) Cheats */
		if (m4all_cheat)
			gp2x_gamelist_text_out(x_Pos,y_Pos+140,"Cheats        ON");
		else
			gp2x_gamelist_text_out(x_Pos,y_Pos+140,"Cheats        OFF");

	
		gp2x_gamelist_text_out(x_Pos,y_Pos+160,"Press B to confirm, X to return\0");

		/* Show currently selected item */
		gp2x_gamelist_text_out(x_Pos-16,y_Pos+(selected_option*10)+30," >");

		gp2x_video_flip();

		gp2x_timer_delay(150);
		ExKey=gp2x_joystick_read(0)&0x8c0ff55;

		if(ExKey & GP2X_DOWN){
			selected_option++;
			selected_option = selected_option % options_count;
		}
		else if(ExKey & GP2X_UP){
			selected_option--;
			if(selected_option<0)
				selected_option = options_count - 1;
		}
		else if(ExKey & GP2X_R || ExKey & GP2X_L || ExKey & GP2X_RIGHT || ExKey & GP2X_LEFT)
		{
			switch(selected_option) {
			case 0:
				if((ExKey & GP2X_R) || (ExKey & GP2X_RIGHT))
				{
					m4all_video_aspect++;
					if (m4all_video_aspect>6)
						m4all_video_aspect=0;
				}
				else
				{

					m4all_video_aspect--;
					if (m4all_video_aspect<0)
						m4all_video_aspect=6;
				}
				break;
			case 1:
				if((ExKey & GP2X_R) || (ExKey & GP2X_RIGHT))
				{
					m4all_video_rotate++;
					if (m4all_video_rotate>2)
						m4all_video_rotate=0;
				}
				else
				{
					m4all_video_rotate--;
					if (m4all_video_rotate<0)
						m4all_video_rotate=2;
				}
				break;
			case 2:
				switch (m4all_video_depth)
				{
					case -1: m4all_video_depth=8; break;
					case 8: m4all_video_depth=16; break;
					case 16: m4all_video_depth=-1; break;
				}
				break;
			case 3:
				m4all_video_sync=m4all_video_sync+1;
				if (m4all_video_sync>1)
					m4all_video_sync=-1;
				break;
			case 4:
				/* "Frame-Skip" */
				if(ExKey & GP2X_R || ExKey & GP2X_RIGHT )
				{
					m4all_frameskip ++;
					if (m4all_frameskip>11)
						m4all_frameskip=-1;
				}
				else
				{
					m4all_frameskip--;
					if (m4all_frameskip<-1)
						m4all_frameskip=11;
				}
				break;
			case 5:
				if(ExKey & GP2X_R || ExKey & GP2X_RIGHT)
				{
					m4all_sound ++;
					if (m4all_sound>12)
						m4all_sound=0;
				}
				else
				{
					m4all_sound--;
					if (m4all_sound<0)
						m4all_sound=12;
				}
				break;
			case 6:
				switch (m4all_waysStick)
				{
					case 8: m4all_waysStick=4; break;
					case 4: m4all_waysStick=2; break;
					case 2: m4all_waysStick=8; break;
				}
				break;
			case 7:
				if(ExKey & GP2X_R || ExKey & GP2X_RIGHT)
				{
					m4all_buttons ++;
					if (m4all_buttons>6)
						m4all_buttons=0;
				}
				else
				{
					m4all_buttons--;
					if (m4all_buttons<0)
						m4all_buttons=6;
				}
				break;
			case 8:
				/* "CPU Clock" */
				if(ExKey & GP2X_R || ExKey & GP2X_RIGHT)
				{
					m4all_clock_cpu += 10; /* Add 10% */
					if (m4all_clock_cpu > 200) /* 200% is the max */
						m4all_clock_cpu = 200;
				}
				else
				{
					m4all_clock_cpu -= 10; /* Subtract 10% */
					if (m4all_clock_cpu < 10) /* 10% is the min */
						m4all_clock_cpu = 10;
				}
				break;
			case 9:
				/* "Audio Clock" */
				if(ExKey & GP2X_R || ExKey & GP2X_RIGHT)
				{
					m4all_clock_sound += 10; /* Add 10% */
					if (m4all_clock_sound > 200) /* 200% is the max */
						m4all_clock_sound = 200;
				}
				else{
					m4all_clock_sound -= 10; /* Subtract 10% */
					if (m4all_clock_sound < 10) /* 10% is the min */
						m4all_clock_sound = 10;
				}
				break;
			case 10:
				m4all_cpu_cores=(m4all_cpu_cores+1)%7;
				break;
			case 11:
				m4all_cheat=!m4all_cheat;
				break;
			}
		}

		if ((ExKey & GP2X_A) || (ExKey & GP2X_B) || (ExKey & GP2X_PUSH) || (ExKey & GP2X_START))
		{
			/* Write game configuration */
			sprintf(text,get_documents_path("frontend/%s_v5.cfg"),game);
			f=fopen(text,"w");
			if (f) {
				fprintf(f,"%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",m4all_video_aspect,m4all_video_rotate,m4all_video_sync,
				m4all_frameskip,m4all_sound,m4all_buttons,m4all_clock_cpu,m4all_clock_sound,i,m4all_cheat,m4all_video_depth,m4all_waysStick,m4all_cpu_cores);
				fclose(f);
				sync();
			}

			/* Selected game will be run */
			return 1;
		}
		else if ((ExKey & GP2X_X) || (ExKey & GP2X_Y) || (ExKey & GP2X_SELECT))
		{
			/* Return To Menu */
			return 0;
		}
	}
}
Exemple #2
0
static void controller_config(void)
{

	unsigned long ExKey=0;
	int selected_option=0;
	int x_Pos = 41;
	int y_Pos = 48;
	int options_count = 18;
	char text[64];
	int i;
	char* options[] = 		{	"FIRE01 Auto    = %s",
						"FIRE02 Auto    = %s",
						"FIRE03 Auto    = %s",
						"FIRE01         = %s",
						"FIRE02         = %s",
						"FIRE03         = %s",
						"FIRE04         = %s",
						"FIRE05         = %s",
						"FIRE06         = %s",
						"FIRE07         = %s",
						"FIRE08         = %s",
						"FIRE09         = %s",
						"FIRE10         = %s",
						"X Sensitivity  = %s",
						"X Reversed     = %s",
						"Y Sensitivity  = %s",
						"Y Reversed     = %s",
						"Back to Default Values"};
	
	while (1)
	{
		/* Draw background image */
		load_bmp_8bpp(gp2x_screen8,gp2xmenu_bmp);
		
		/* Draw the options */
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+0,options[0],key_settings->JOY_FIRE1_AUTO?"ON\0":"OFF\0");
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+8,options[1],key_settings->JOY_FIRE2_AUTO?"ON\0":"OFF\0");
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+16,options[2],key_settings->JOY_FIRE3_AUTO?"ON\0":"OFF\0");
		button_text(key_settings->JOY_FIRE1,text);
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+24,options[3],text);
		button_text(key_settings->JOY_FIRE2,text);
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+32,options[4],text);
		button_text(key_settings->JOY_FIRE3,text);
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+40,options[5],text);
		button_text(key_settings->JOY_FIRE4,text);
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+48,options[6],text);
		button_text(key_settings->JOY_FIRE5,text);
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+56,options[7],text);
		button_text(key_settings->JOY_FIRE6,text);
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+64,options[8],text);
		button_text(key_settings->JOY_FIRE7,text);
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+72,options[9],text);
		button_text(key_settings->JOY_FIRE8,text);
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+80,options[10],text);
		button_text(key_settings->JOY_FIRE9,text);
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+88,options[11],text);
		button_text(key_settings->JOY_FIRE10,text);
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+96,options[12],text);
		if (x_sensitivity!=-1)
			sprintf(text,"%d",x_sensitivity);
		else
			strcpy(text,"DEFAULT");
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+104,options[13],text);
		if (x_reversed)
			strcpy(text,"ON");
		else
			strcpy(text,"OFF");
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+112,options[14],text);
		if (y_sensitivity!=-1)
			sprintf(text,"%d",y_sensitivity);
		else
			strcpy(text,"DEFAULT");
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+120,options[15],text);
		if (y_reversed)
			strcpy(text,"ON");
		else
			strcpy(text,"OFF");
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+128,options[16],text);
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+136,options[17]);

#ifdef PSP
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+152,"Press [] or O to confirm");
#else
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+152,"Press A or B to confirm");
#endif
		/* Show currently selected item */
		gp2x_gamelist_text_out(x_Pos-16,y_Pos+(selected_option*8)," >");

		gp2x_video_flip();
		while(gp2x_joystick_read()&0x8c0ff55) { gp2x_timer_delay(150); }
		while(!(ExKey=gp2x_joystick_read()&0x8c0ff55)) { }

		if(ExKey & GP2X_DOWN){
			selected_option++;
			selected_option = selected_option % options_count;
		}
		else if(ExKey & GP2X_UP){
			selected_option--;
			if(selected_option<0)
				selected_option = options_count - 1;
		}
#ifdef GP2X
		else if(ExKey & GP2X_R || ExKey & GP2X_L){
#else
		else if(ExKey & GP2X_RIGHT || ExKey & GP2X_LEFT){
#endif
			switch(selected_option) {
				
				case 0: key_settings->JOY_FIRE1_AUTO=key_settings->JOY_FIRE1_AUTO?0:1; break;
				case 1: key_settings->JOY_FIRE2_AUTO=key_settings->JOY_FIRE2_AUTO?0:1; break;
				case 2: key_settings->JOY_FIRE3_AUTO=key_settings->JOY_FIRE3_AUTO?0:1; break;
				case 3: key_settings->JOY_FIRE1=button_next((key_settings->JOY_FIRE1),(ExKey&GP2X_R)); break;
				case 4: key_settings->JOY_FIRE2=button_next((key_settings->JOY_FIRE2),(ExKey&GP2X_R)); break;
				case 5: key_settings->JOY_FIRE3=button_next((key_settings->JOY_FIRE3),(ExKey&GP2X_R)); break;
				case 6: key_settings->JOY_FIRE4=button_next((key_settings->JOY_FIRE4),(ExKey&GP2X_R)); break;
				case 7: key_settings->JOY_FIRE5=button_next((key_settings->JOY_FIRE5),(ExKey&GP2X_R)); break;
				case 8: key_settings->JOY_FIRE6=button_next((key_settings->JOY_FIRE6),(ExKey&GP2X_R)); break;
				case 9: key_settings->JOY_FIRE7=button_next((key_settings->JOY_FIRE7),(ExKey&GP2X_R)); break;
				case 10: key_settings->JOY_FIRE8=button_next((key_settings->JOY_FIRE8),(ExKey&GP2X_R)); break;
				case 11: key_settings->JOY_FIRE9=button_next((key_settings->JOY_FIRE9),(ExKey&GP2X_R)); break;
				case 12: key_settings->JOY_FIRE10=button_next((key_settings->JOY_FIRE10),(ExKey&GP2X_R)); break;
				case 13:
					/* X Sensitivity */
#ifdef GP2X
					if (ExKey & GP2X_R) {
#else
					if (ExKey & GP2X_RIGHT) {
#endif
						if (x_sensitivity!=-1) {
							x_sensitivity+=5;
							if (x_sensitivity>255) x_sensitivity=-1;
						} else
							x_sensitivity=0;
					} else {
						if (x_sensitivity!=-1) {
							x_sensitivity-=5;
							if (x_sensitivity<0) x_sensitivity=-1;
						} else
							x_sensitivity=255;
					}
					break;
				case 14:
					/* X Reversed */
					x_reversed=!x_reversed;
					break;
				case 15:
					/* Y Sensitivity */
#ifdef GP2X
					if (ExKey & GP2X_R) {
#else
					if (ExKey & GP2X_RIGHT) {
#endif
						if (y_sensitivity!=-1) {
							y_sensitivity+=5;
							if (y_sensitivity>255) y_sensitivity=-1;
						} else
							y_sensitivity=0;
					} else {
						if (y_sensitivity!=-1) {
							y_sensitivity-=5;
							if (y_sensitivity<0) y_sensitivity=-1;
						} else
							y_sensitivity=255;
					}
					break;
				case 16:
					/* Y Reversed */
					y_reversed=!y_reversed;
					break;
				case 17:
					/* Default Values */
					key_settings->JOY_FIRE1=GP2X_B;
					key_settings->JOY_FIRE2=GP2X_X;
					key_settings->JOY_FIRE3=GP2X_A;
					key_settings->JOY_FIRE4=GP2X_Y;
					key_settings->JOY_FIRE5=GP2X_L;
					key_settings->JOY_FIRE6=GP2X_R;
					key_settings->JOY_FIRE7=GP2X_VOL_UP;
					key_settings->JOY_FIRE8=GP2X_VOL_DOWN;
					key_settings->JOY_FIRE9=GP2X_PUSH;
					key_settings->JOY_FIRE10=GP2X_START;
					key_settings->JOY_FIRE1_AUTO=0;
					key_settings->JOY_FIRE2_AUTO=0;
					key_settings->JOY_FIRE3_AUTO=0;
					x_sensitivity=-1;
					y_sensitivity=-1;
					x_reversed=0;
					y_reversed=0;
					break;
			}
		}
		
		if ((ExKey & GP2X_A) || (ExKey & GP2X_PUSH) || (ExKey & GP2X_START)) {
			return;
		}
		else if ((ExKey & GP2X_B) || (ExKey & GP2X_SELECT)){
			return;
		}
	}
}

static void dipswitches_config(void)
{
	struct InputPort *inp=NULL;					/* input ports */
	int i;								/* Index into the input ports */
	int x_Pos;							/* Position X in the screen to print */
	int y_Pos;							/* Position Y in the screen to print */
	int index=0;							/* Index into the dipswitches to modify */
	int num_items;							/* Total number of dipswitches */
	const char *name;						/* Name of the dipswitch */
	unsigned long ExKey=0;						/* Key status */
	unsigned short *value_change;					/* Pointer of the value to be changed */
	int value_count;						/* Number of values */
	unsigned short value_range[32];					/* Different values */
	unsigned short value;						/* Current value*/
	unsigned short value_count_m;					/* Fire values count */

	/* Get input ports of the selected game */
	index=0;
	for (i=0;i<game_num;i++) {
		if (game_avail[i]==1) {
			if(index==last_game_selected) {
				inp=drivers[i]->input_ports;
			}
			index++;
		}
	}
	if (!inp) return;

	i=0;
	index=0;
	while(1)
	{
		/* Draw background image */
		load_bmp_8bpp(gp2x_screen8,gp2xmenu_bmp);
	
		i=0;
		x_Pos=41;
		y_Pos=48;
		num_items=0;

		/* Show currently selected item */
		gp2x_gamelist_text_out(x_Pos-16,y_Pos+(index*8)," >");

		/* Show Dipswitches configuration */	
		while (inp[i].type!= IPT_END)
		{
			/* Dipswitch Name */
			if ( (inp[i].type & ~IPF_MASK) == IPT_DIPSWITCH_NAME && inp[i].name!=0 && (inp[i].type & IPF_UNUSED) == 0 ) {
				name=inp[i].name;
				value=inp[i].default_value;
				if (index==num_items) {
					value_change = &(inp[i].default_value);
					value_count=0;
					value_count_m=1;
				} else
					value_count_m=0;
			}
			/* Cheat Name */
			if ( (inp[i].type & ~IPF_MASK) == (IPT_DIPSWITCH_NAME | IPF_CHEAT) && inp[i].name!=0 && (inp[i].type & IPF_UNUSED) == 0 ) {
				name=inp[i].name;
				value=inp[i].default_value;
				if (index==num_items) {
					value_change = &(inp[i].default_value);
					value_count=0;
					value_count_m=1;
				} else
					value_count_m=0;
			}
			/* Dipswitch Setting */
			if ((inp[i].type & ~IPF_MASK) == IPT_DIPSWITCH_SETTING) {
				if (value_count_m) {
					value_range[value_count]=inp[i].default_value;
					value_count++;
				}
				if (value==inp[i].default_value) {
					/* printf("%s: %s\n",name,inp[i].name); */
					gp2x_gamelist_text_out_fmt(x_Pos,y_Pos,"%s: %s",name,inp[i].name);
					y_Pos+=8;
					num_items++;
				}
			}
			i++;			
		}	

#ifdef PSP
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+8,"Press [] or O to confirm");
#else
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+8,"Press A or B to confirm");
#endif
	
		gp2x_video_flip();

		while(gp2x_joystick_read()&0x8c0ff55) { gp2x_timer_delay(150); }
		while(!(ExKey=gp2x_joystick_read()&0x8c0ff55)) { }
		if(ExKey & GP2X_DOWN){
			index++;
			index = index % num_items;
		}
		else if(ExKey & GP2X_UP){
			index--;
			if(index<0)
				index = num_items - 1;
		}
#ifdef GP2X
		else if(ExKey & GP2X_R || ExKey & GP2X_L){
#else
		else if(ExKey & GP2X_RIGHT || ExKey & GP2X_LEFT){
#endif
			/* Modify dipswitch */
			for(i=0;i<value_count;i++) {
				if (value_range[i]==*value_change) break;	
			}
			if (i==value_count-1)
				*value_change=value_range[0];
			if (i<value_count-1)
				*value_change=value_range[i+1];
		}

		if ((ExKey & GP2X_A) || (ExKey & GP2X_PUSH) || (ExKey & GP2X_START)) {
			return;
		}
		else if ((ExKey & GP2X_B) || (ExKey & GP2X_SELECT)){
			return;
		}
	}
}

#ifdef PSP
#define SAVEDATASTRUCTURE "gp2x_freq=%d;gp2x_frameskip=%d;gp2x_frameskip_auto=%d;gp2x_clock_cpu=%d;gp2x_sound_enable=%d;gp2x_clock_sound=%d;key_setting=%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%d,%d,%d,%d;gp2x_double_buffer=%d;gp2x_rotate=%d;gp2x_vsync=%d;gp2x_autofire=%d,%d,%d;\0"
#else
#define SAVEDATASTRUCTURE "gp2x_freq=%d;gp3x_frameskip=%d;gp2x_frameskip_auto=%d;gp2x_clock_cpu=%d;gp2x_sound_enable=%d;gp2x_clock_sound=%d;key_setting=%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%d,%d,%d,%d;gp2x_double_buffer=%d;gp2x_rotate=%d;gp2x_vsync=%d;gp2x_autofire=%d,%d,%d;\0"
#endif
#define SAVEDATAFILEDEF	"%scfg/mame.cfg\0"
#define SAVEDATAFILECFG "%scfg/%s.cfg\0"
/*static*/ int show_options(char *game)
{
	unsigned long ExKey=0;
	int selected_option=0;
	int x_Pos = 41;
	int y_Pos = 58;
#ifdef PSP
	int options_count = 10;
#else
	int options_count = 9;
#endif
	char text[256];
	FILE *f;

	/* Load Configuration Files */
	gp2x_save_config = 0;
#ifdef PSP
  strcpy(gp2x_path_mame,"");
#endif
	sprintf(text,SAVEDATAFILEDEF, gp2x_path_mame);
	f=fopen(text,"r");
	if (f) {
		fscanf(f,SAVEDATASTRUCTURE,
		&gp2x_freq,&gp2x_frameskip,&gp2x_frameskip_auto,&gp2x_clock_cpu,&gp2x_sound_enable,&gp2x_clock_sound,
		&(key_settings->JOY_FIRE1),&(key_settings->JOY_FIRE2),&(key_settings->JOY_FIRE3),&(key_settings->JOY_FIRE4),
		&(key_settings->JOY_FIRE5),&(key_settings->JOY_FIRE6),&(key_settings->JOY_FIRE7),&(key_settings->JOY_FIRE8),
		&(key_settings->JOY_FIRE9),&(key_settings->JOY_FIRE10),&x_sensitivity,&x_reversed,&y_sensitivity,&y_reversed,
		&gp2x_double_buffer,&gp2x_vsync,&(key_settings->JOY_FIRE1_AUTO),&(key_settings->JOY_FIRE2_AUTO),&(key_settings->JOY_FIRE3_AUTO));
		fclose(f);
	}
	sprintf(text,SAVEDATAFILECFG, gp2x_path_mame, game);
	f=fopen(text,"r");
	if (f) {
		fscanf(f,SAVEDATASTRUCTURE,
		&gp2x_freq,&gp2x_frameskip,&gp2x_frameskip_auto,&gp2x_clock_cpu,&gp2x_sound_enable,&gp2x_clock_sound,
		&(key_settings->JOY_FIRE1),&(key_settings->JOY_FIRE2),&(key_settings->JOY_FIRE3),&(key_settings->JOY_FIRE4),
		&(key_settings->JOY_FIRE5),&(key_settings->JOY_FIRE6),&(key_settings->JOY_FIRE7),&(key_settings->JOY_FIRE8),
		&(key_settings->JOY_FIRE9),&(key_settings->JOY_FIRE10),&x_sensitivity,&x_reversed,&y_sensitivity,&y_reversed,
		&gp2x_double_buffer,&gp2x_vsync,&(key_settings->JOY_FIRE1_AUTO),&(key_settings->JOY_FIRE2_AUTO),&(key_settings->JOY_FIRE3_AUTO));
		fclose(f);
	}


	while(1)
	{
		/* Draw background image */
		load_bmp_8bpp(gp2x_screen8,gp2xmenu_bmp);

		/* Draw the options */
		gp2x_gamelist_text_out(x_Pos,y_Pos,"Selected Game:\0");
		fast_memcpy (text,game_list_description(last_game_selected),33);
		text[32]='\0';
		gp2x_gamelist_text_out(x_Pos,y_Pos+10,text);
		/*gp2x_gamelist_text_out(x_Pos,y_Pos+10,game_list_description(last_game_selected));*/

#ifdef GP2X
		/* GP2X Clock*/
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30, "GP2X Clock    %d MHz", gp2x_freq);
		
		/* Frame-Skip */
		if(gp2x_frameskip_auto && gp2x_frameskip!=0) {
			gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+40,"Frame-Skip    %s %d %s","<=",gp2x_frameskip, "(Auto-skip)");
		}
		else{
			gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+40,"Frame-Skip    %s %d %s","=",gp2x_frameskip,"");
		}
#else
#ifdef PSP
		switch (gp2x_rotate)
		{
			case 0: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video         %s","Fixed"); break;
			case 1: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video         %s","Fixed DIV2"); break;
			case 2: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video         %s","SW Scaled"); break;
			default: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video         %s","SW Streched"); break;
		}
		/* Frame-Skip */
		if(gp2x_frameskip_auto && gp2x_frameskip!=0) {
			gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+40,"Frame-Skip    %s %d %s","<=",gp2x_frameskip, "(Auto-skip)");
		}
		else{
			gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+40,"Frame-Skip    %s %d %s","=",gp2x_frameskip,"");
		}
#else
		switch (gp2x_rotate)
		{
			case 0: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video         %s","Fixed"); break;
			case 1: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video         %s","Fixed DIV2"); break;
			case 2: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video         %s","SW Scaled"); break;
			default: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video         %s","HW Scaled"); break;
		}
		if (gp2x_frameskip_auto)
		{
			gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+40,"Frame-Skip    Auto");
			gp2x_frameskip=-1;
		}
		else
			gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+40,"Frame-Skip    = %d",gp2x_frameskip);
#endif
#endif

		/* Video Clock */
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+50,"Video Clock   %d%%",gp2x_clock_cpu);

		/* Video Sync */
#ifdef GP2X
		if (gp2x_double_buffer && gp2x_vsync==1)
			gp2x_gamelist_text_out(x_Pos,y_Pos+60,"Video Sync    VSync+DblBuf");
		else if (gp2x_double_buffer && gp2x_vsync==0)
			gp2x_gamelist_text_out(x_Pos,y_Pos+60,"Video Sync    DblBuf");
		else if (!gp2x_double_buffer && gp2x_vsync==1)
			gp2x_gamelist_text_out(x_Pos,y_Pos+60,"Video Sync    VSync");
		else if (gp2x_vsync==-1)
			gp2x_gamelist_text_out(x_Pos,y_Pos+60,"Video Sync    Off");
		else
			gp2x_gamelist_text_out(x_Pos,y_Pos+60,"Video Sync    Normal");
#else
		if (gp2x_vsync)
			gp2x_gamelist_text_out(x_Pos,y_Pos+60,"Video Sync    On");
		else
			gp2x_gamelist_text_out(x_Pos,y_Pos+60,"Video Sync    Off");

#endif
		/* Sound */
		switch(gp2x_sound_enable)
		{
			case 0: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","Sound OFF"); break;
#ifdef GP2X
			case 1: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","Sound ON (15 KHz)"); break;
			case 2: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","Sound ON (22 KHz)"); break;
			case 3: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","Sound ON (33 KHz)"); break;
			case 4: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","Sound ON (44 KHz)"); break;
			case 5: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","Sound ON (11 KHz)"); break;
#else
			case 1: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","Sound ON"); break;
			case 2: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","Emulated but OFF"); break;
			case 3: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","Accurate and ON"); break;
#ifdef PSP
			case 4: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","44k 16v"); break;
			case 5: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","44k 8v"); break;
			case 6: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","44k 4v"); break;
			case 7: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","33k 16v"); break;
			case 8: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","33k 8v"); break;
			case 9: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","33k 4v"); break;
#endif
#endif
		}

		/* Audio Clock */
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+80,"Audio Clock   %d%%",gp2x_clock_sound);

		/* Controller Configuration */
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+90,"Controller Configuration");

		/* Controller Configuration */
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+100,"Dipswitches Configuration");

		/* Save Configuration */
		switch(gp2x_save_config) {
			case 0: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+110,"No Save Configuration"); break;
			case 1: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+110,"Save Configuration"); break;
			case 2: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+110,"Save as Default"); break;
		}
#ifdef PSP
		/* PSP Clock*/
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+120, "PSP Clock     %d MHz", gp2x_freq);
		gp2x_gamelist_text_out(x_Pos,y_Pos+130,"Press [] to confirm, X return\0");
#else
		gp2x_gamelist_text_out(x_Pos,y_Pos+130,"Press B to confirm, X to return\0");
#endif

		/* Show currently selected item */
		gp2x_gamelist_text_out(x_Pos-16,y_Pos+(selected_option*10)+30," >");

		gp2x_video_flip();
		while(gp2x_joystick_read()&0x8c0ff55) { gp2x_timer_delay(150); }
		while(!(ExKey=gp2x_joystick_read()&0x8c0ff55)) { }
		if(ExKey & GP2X_DOWN){
			selected_option++;
			selected_option = selected_option % options_count;
		}
		else if(ExKey & GP2X_UP){
			selected_option--;
			if(selected_option<0)
				selected_option = options_count - 1;
		}
#ifdef GP2X
		else if(ExKey & GP2X_R || ExKey & GP2X_L){
#else
		else if(ExKey & GP2X_RIGHT || ExKey & GP2X_LEFT){
#endif
			switch(selected_option) {
			case 0:
#ifdef GP2X
				/* GP2X Clock */
				if(ExKey & GP2X_R){
					switch (gp2x_freq) {
						case  66: gp2x_freq=75;break;
						case  75: gp2x_freq=80;break;
						case  80: gp2x_freq=100;break;
						case 100: gp2x_freq=120;break;
						case 120: gp2x_freq=133;break;
						case 133: gp2x_freq=150;break;
						case 150: gp2x_freq=166;break;
						case 166: gp2x_freq=180;break;
						case 180: gp2x_freq=200;break;
						case 200: gp2x_freq=225;break;
						case 225: gp2x_freq=233;break;
						case 233: gp2x_freq=245;break;
						case 245: gp2x_freq=250;break;
						case 250: gp2x_freq=255;break;
						case 255: gp2x_freq=260;break;
						case 260: gp2x_freq=265;break;
						case 265: gp2x_freq=266;break;
						case 266: gp2x_freq=270;break;
						case 270: gp2x_freq=275;break;
						case 275: gp2x_freq=280;break;
						case 280: gp2x_freq=285;break;
						case 285: gp2x_freq=290;break;
						case 290: gp2x_freq=295;break;
						case 295: gp2x_freq=300;break;
						case 300: gp2x_freq=66;break;
					}
				} else {
					switch (gp2x_freq) {
						case  66: gp2x_freq=300;break;
						case  75: gp2x_freq=66;break;
						case  80: gp2x_freq=75;break;
						case 100: gp2x_freq=80;break;
						case 120: gp2x_freq=100;break;
						case 133: gp2x_freq=120;break;
						case 150: gp2x_freq=133;break;
						case 166: gp2x_freq=150;break;
						case 180: gp2x_freq=166;break;
						case 200: gp2x_freq=180;break;
						case 225: gp2x_freq=200;break;
						case 233: gp2x_freq=225;break;
						case 245: gp2x_freq=233;break;
						case 250: gp2x_freq=245;break;
						case 255: gp2x_freq=250;break;
						case 260: gp2x_freq=255;break;
						case 265: gp2x_freq=260;break;
						case 266: gp2x_freq=265;break;
						case 270: gp2x_freq=266;break;
						case 275: gp2x_freq=270;break;
						case 280: gp2x_freq=275;break;
						case 285: gp2x_freq=280;break;
						case 290: gp2x_freq=285;break;
						case 295: gp2x_freq=290;break;
						case 300: gp2x_freq=295;break;
					}
				}
#else
				if (ExKey & GP2X_RIGHT)
					gp2x_rotate++;
				else
				if (ExKey & GP2X_LEFT)
					gp2x_rotate--;
				if (gp2x_rotate<0)
					gp2x_rotate=3;
				else if (gp2x_rotate>3)
					gp2x_rotate=0;
#ifdef DREAMCAST
				if (gp2x_rotate==3)
					gp2x_vsync=1;
#endif

#endif
				break;
			case 1:
				/* "Frame-Skip" */
#ifdef GP2X
				if(ExKey & GP2X_R){
#else
				if(ExKey & GP2X_RIGHT){
#endif
					gp2x_frameskip ++;
					if (!gp2x_frameskip)
						gp2x_frameskip_auto=0;
					else
					if (gp2x_frameskip > 5) {
#ifdef GP2X
						gp2x_frameskip = 0;
						gp2x_frameskip_auto=!gp2x_frameskip_auto; 
#else
#ifdef PSP
						gp2x_frameskip = 0;
						gp2x_frameskip_auto=!gp2x_frameskip_auto;
#else
						gp2x_frameskip = -1;
						gp2x_frameskip_auto = 1;
#endif
#endif
					}
				}
				else{
					gp2x_frameskip--;
#ifdef GP2X
					if (gp2x_frameskip < 0){
						gp2x_frameskip = 5;
						gp2x_frameskip_auto=!gp2x_frameskip_auto; 
					}
#else
#ifdef PSP
					if (gp2x_frameskip < 0){
						gp2x_frameskip = 5;
						gp2x_frameskip_auto=!gp2x_frameskip_auto;
					}
#else
					if (gp2x_frameskip==-1)
						gp2x_frameskip_auto=1;
					else if (gp2x_frameskip<-1)
					{
						gp2x_frameskip = 5;
						gp2x_frameskip_auto = 0;
					}
#endif
#endif
				}
				break;
			case 2:
				/* "Video Clock" */
#ifdef GP2X
				if(ExKey & GP2X_R){
#else
				if(ExKey & GP2X_RIGHT){
#endif
					gp2x_clock_cpu += 10; /* Add 10% */
					if (gp2x_clock_cpu > 200) /* 200% is the max */
						gp2x_clock_cpu = 200;
				}
				else{
					gp2x_clock_cpu -= 10; /* Subtract 10% */
					if (gp2x_clock_cpu < 10) /* 10% is the min */
						gp2x_clock_cpu = 10;
				}
				break;
			case 3:
				/* Video Sync */
#ifdef GP2X
				if (!gp2x_double_buffer && gp2x_vsync==0)
				{ gp2x_double_buffer=0; gp2x_vsync=-1; }
				else if (!gp2x_double_buffer && gp2x_vsync==-1)
				{ gp2x_double_buffer=1; gp2x_vsync=0; }
				else if (gp2x_double_buffer && gp2x_vsync==0)
				{ gp2x_double_buffer=0; gp2x_vsync=1; }
				else if (!gp2x_double_buffer && gp2x_vsync==1)				
				{ gp2x_double_buffer=1; gp2x_vsync=1; }	
				else 
				{ gp2x_double_buffer=0; gp2x_vsync=0; }	
#else
				gp2x_vsync=(gp2x_vsync+1)&1;
#endif
				break;

			case 4:
#ifndef NOSOUND
				/* "Sound" */
#ifdef GP2X
				if(ExKey & GP2X_R){
#else
				if(ExKey & GP2X_RIGHT){
#endif
					gp2x_sound_enable++;
#ifdef PSP
					if (gp2x_sound_enable>9)
#else
#ifdef GP2X
					if (gp2x_sound_enable>5)
#else
					if (gp2x_sound_enable>3)
#endif
#endif
						gp2x_sound_enable=0;
				}
				else {
					gp2x_sound_enable--;
					if (gp2x_sound_enable<0)
#ifdef PSP
						gp2x_sound_enable=9;
#else
#ifdef GP2X
						gp2x_sound_enable=5;
#else
						gp2x_sound_enable=3;
#endif
#endif
				}
#endif
				break;
			case 5:
				/* "Audio Clock" */
#ifdef GP2X
				if(ExKey & GP2X_R){
#else
				if(ExKey & GP2X_RIGHT){
#endif
					gp2x_clock_sound += 10; /* Add 10% */
					if (gp2x_clock_sound > 200) /* 200% is the max */
						gp2x_clock_sound = 200;
				}
				else{
					gp2x_clock_sound -= 10; /* Subtract 10% */
					if (gp2x_clock_sound < 10) /* 10% is the min */
						gp2x_clock_sound = 10;
				}
				break;
			case 6:
				/* Controller Configuration */
				controller_config();
				break;
			case 7:
				/* Dipswitches Configuration */
				dipswitches_config();
				break;
			case 8:
				/* Save Configuration */
#ifdef GP2X
				if(ExKey & GP2X_R){
#else
				if(ExKey & GP2X_RIGHT){
#endif
					gp2x_save_config += 1;
					if (gp2x_save_config > 2)
						gp2x_save_config = 0;
				}
				else{
					gp2x_save_config -= 1;
					if (gp2x_save_config < 0)
						gp2x_save_config = 2;
				}
				break;
#ifdef PSP
			case 9:
				/* PSP Clock */
				if(ExKey & GP2X_RIGHT){
					switch (gp2x_freq) {
						case 133: gp2x_freq=166;break;
						case 166: gp2x_freq=200;break;
						case 200: gp2x_freq=222;break;
						case 222: gp2x_freq=266;break;
						case 266: gp2x_freq=300;break;
						case 300: gp2x_freq=333;break;
						case 333: gp2x_freq=133;break;
					}
				} else {
					switch (gp2x_freq) {
						case 133: gp2x_freq=333;break;
						case 166: gp2x_freq=133;break;
						case 200: gp2x_freq=166;break;
						case 222: gp2x_freq=200;break;
						case 266: gp2x_freq=222;break;
						case 300: gp2x_freq=266;break;
						case 333: gp2x_freq=300;break;
					}
				}
				break;
#endif
			}
		}
#ifndef GP2X
		if ((ExKey & GP2X_A) || (ExKey & GP2X_START)) {
#else
		if ((ExKey & GP2X_A) || (ExKey & GP2X_B) || (ExKey & GP2X_PUSH) || (ExKey & GP2X_START)) {
#endif

			/* Save Configuration Files */
			if (gp2x_save_config>1) {
				sprintf(text,SAVEDATAFILEDEF, gp2x_path_mame);
				f=fopen(text,"w");
				if (f) {
					fprintf(f,SAVEDATASTRUCTURE,
					gp2x_freq,gp2x_frameskip,gp2x_frameskip_auto,gp2x_clock_cpu,gp2x_sound_enable,gp2x_clock_sound,
					(key_settings->JOY_FIRE1),(key_settings->JOY_FIRE2),(key_settings->JOY_FIRE3),(key_settings->JOY_FIRE4),
					(key_settings->JOY_FIRE5),(key_settings->JOY_FIRE6),(key_settings->JOY_FIRE7),(key_settings->JOY_FIRE8),
					(key_settings->JOY_FIRE9),(key_settings->JOY_FIRE10),x_sensitivity,x_reversed,y_sensitivity,y_reversed,
					gp2x_double_buffer,gp2x_vsync,(key_settings->JOY_FIRE1_AUTO),(key_settings->JOY_FIRE2_AUTO),(key_settings->JOY_FIRE3_AUTO));
					fclose(f);
#ifdef GP2X
					sync();
#endif
				}
			}
			if (gp2x_save_config>0) {
				sprintf(text,SAVEDATAFILECFG, gp2x_path_mame, game);
				f=fopen(text,"w");
				if (f) {
					fprintf(f,SAVEDATASTRUCTURE,
					gp2x_freq,gp2x_frameskip,gp2x_frameskip_auto,gp2x_clock_cpu,gp2x_sound_enable,gp2x_clock_sound,
					(key_settings->JOY_FIRE1),(key_settings->JOY_FIRE2),(key_settings->JOY_FIRE3),(key_settings->JOY_FIRE4),
					(key_settings->JOY_FIRE5),(key_settings->JOY_FIRE6),(key_settings->JOY_FIRE7),(key_settings->JOY_FIRE8),
					(key_settings->JOY_FIRE9),(key_settings->JOY_FIRE10),x_sensitivity,x_reversed,y_sensitivity,y_reversed,
					gp2x_rotate,gp2x_vsync,(key_settings->JOY_FIRE1_AUTO),(key_settings->JOY_FIRE2_AUTO),(key_settings->JOY_FIRE3_AUTO));
					fclose(f);
#ifdef GP2X
					sync();
#endif
				}
			}

			/* Selected game will be run */
			return 1;
		}
#ifndef GP2X
		else if ((ExKey & GP2X_X) || (ExKey & GP2X_PUSH) || (ExKey & GP2X_SELECT)){
#else
		else if ((ExKey & GP2X_X) || (ExKey & GP2X_Y) || (ExKey & GP2X_SELECT)){
#endif
			/* Return To Menu */
			return 0;
		}
	}
}

void select_game(char *game) {

	unsigned long ExKey;
	int c;

	/* No Selected game */
	strcpy(game,"builtinn");

	/* Clean screen */
	gp2x_video_flip();

	/* enable extra PSP-2000 memory */
#ifdef PSP_2K
	psp2k_mem_init();
#endif
	/* Wait until no key pressed */
	while(gp2x_joystick_read()&0x8c0ff55) 
		gp2x_timer_delay(100);

	/* Available games? */
	if(game_num_avail==0) {
		gp2x_mame_palette();
		gp2x_text_out( 35, 110, "ERROR: NO AVAILABLE GAMES FOUND" );
		gp2x_video_flip();
		while(1) { if (gp2x_joystick_read()&GP2X_A) exit(0);}
	}

#ifdef PSP
	SetGP2XClock(133);
#else
	SetGP2XClock(66);
#endif

	/* Wait until user selects a game */
	while(1) {
		game_list_view(&last_game_selected);
		gp2x_video_flip();

#ifdef GP2X
		if( (gp2x_joystick_read()&0x8c0ff55)) 
			gp2x_timer_delay(100); 
		while(!(ExKey=gp2x_joystick_read()&0x8c0ff55)) { if ((ExKey & GP2X_L) && (ExKey & GP2X_R)) exit(0); }
#else
		if( (gp2x_joystick_read()&0x8c0ff55)) 
			gp2x_timer_delay(100); 
		while(!(ExKey=gp2x_joystick_read()&0x8c0ff55))
			gp2x_timer_delay(100); 
#endif

		if (ExKey & GP2X_UP) last_game_selected--;
		if (ExKey & GP2X_DOWN) last_game_selected++;
		if (ExKey & GP2X_L) last_game_selected-=21;
		if (ExKey & GP2X_R) last_game_selected+=21;
		if ((ExKey & GP2X_L) && (ExKey & GP2X_R)) exit(0);

		/* If Button A is pressed, or a rom name was passed to this application */
#ifndef GP2X
		{
#ifdef DREAMCAST
			static int parasalir=0;
			if (ExKey & GP2X_PUSH)
				parasalir++;
			else
				parasalir=0;
			if (parasalir>8)
				gp2x_deinit();
#else
			if (ExKey & GP2X_PUSH)
				gp2x_deinit();
#endif
		}
		if ((ExKey & GP2X_A) || (ExKey & GP2X_START))
#else
		if ((ExKey & GP2X_A) || (ExKey & GP2X_B) || (ExKey & GP2X_PUSH) || (ExKey & GP2X_START))
#endif
		{
			/* Select the game */
			game_list_select(last_game_selected, game);

			/* Emulation Options */
			if(show_options(game))
			{
				/* break out of the while(1) loop */
				break;
			}
		}
	}
	SetGP2XClock(gp2x_freq);
}
static int show_options(char *game)
{
	unsigned long ExKey=0;
	int selected_option=0;
	int x_Pos = 41;
	int y_Pos = 58;
	int options_count = 11;
	char text[256];
	FILE *f;
	int i=0;

	/* Read game configuration */
	sprintf(text,"frontend/%s.cfg",game);
	f=fopen(text,"r");
	if (f) {
		fscanf(f,"%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",&wiz_freq,&wiz_video_depth,&wiz_video_aspect,&wiz_video_sync,
		&wiz_frameskip,&wiz_sound,&wiz_clock_cpu,&wiz_clock_sound,&wiz_cpu_cores,&wiz_ramtweaks,&i,&wiz_cheat);
		fclose(f);
	}

	while(1)
	{
		/* Draw background image */
		load_bmp_8bpp(fb1_8bit,wizmenu_bmp);

		/* Draw the options */
		wiz_gamelist_text_out(x_Pos,y_Pos,"Selected Game:\0");
		strncpy (text,game_list_description(last_game_selected),33);
		text[32]='\0';
		wiz_gamelist_text_out(x_Pos,y_Pos+10,text);

		/* (0) WIZ Clock */
		wiz_gamelist_text_out_fmt(x_Pos,y_Pos+30, "WIZ Clock     %d MHz", wiz_freq);

		/* (1) Video Depth */
		switch (wiz_video_depth)
		{
			case -1: wiz_gamelist_text_out_fmt(x_Pos,y_Pos+40,"Video Depth   Auto"); break;
			case 8:  wiz_gamelist_text_out_fmt(x_Pos,y_Pos+40,"Video Depth   8 bit"); break;
			case 16: wiz_gamelist_text_out_fmt(x_Pos,y_Pos+40,"Video Depth   16 bit"); break;
			default: wiz_gamelist_text_out_fmt(x_Pos,y_Pos+40,"Video Depth   8 bit"); wiz_video_depth=8; break;
		}

		/* (2) Video Aspect */
		switch (wiz_video_aspect)
		{
			case 0: wiz_gamelist_text_out_fmt(x_Pos,y_Pos+50,"Video Aspect  Normal"); break;
			case 1: wiz_gamelist_text_out_fmt(x_Pos,y_Pos+50,"Video Aspect  Scale"); break;
			case 8: wiz_gamelist_text_out_fmt(x_Pos,y_Pos+50,"Video Aspect  Rotate"); break;
			case 9: wiz_gamelist_text_out_fmt(x_Pos,y_Pos+50,"Video Aspect  Rotate Scale"); break;
			case 24:wiz_gamelist_text_out_fmt(x_Pos,y_Pos+50,"Video Aspect  Diagonal Fix"); break;
			case 25:wiz_gamelist_text_out_fmt(x_Pos,y_Pos+50,"Video Aspect  Rotate DiagonalFix"); break;
			default:wiz_gamelist_text_out_fmt(x_Pos,y_Pos+50,"Video Aspect  Normal"); wiz_video_aspect=0; break; 
		}
		
		/* (3) Video Sync */
		switch (wiz_video_sync)
		{
			case 1: wiz_gamelist_text_out(x_Pos,y_Pos+60, "Video Sync    VSync"); break;
			case 0: wiz_gamelist_text_out(x_Pos,y_Pos+60, "Video Sync    Normal"); break;
			case 2: wiz_gamelist_text_out(x_Pos,y_Pos+60, "Video Sync    DblBuf"); break;
			case -1: wiz_gamelist_text_out(x_Pos,y_Pos+60,"Video Sync    OFF"); break;
		}
		
		/* (4) Frame-Skip */
		if ((wiz_video_sync==-1) && (wiz_frameskip==-1)) wiz_frameskip=0;
		if(wiz_frameskip==-1) {
			wiz_gamelist_text_out_fmt(x_Pos,y_Pos+70, "Frame-Skip    Auto");
		}
		else{
			wiz_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Frame-Skip    %d",wiz_frameskip);
		}

		/* (5) Sound */
		switch(wiz_sound)
		{
			case 0: wiz_gamelist_text_out_fmt(x_Pos,y_Pos+80,"Sound         %s","OFF"); break;
			case 1: wiz_gamelist_text_out_fmt(x_Pos,y_Pos+80,"Sound         %s","ON (15 KHz fast)"); break;
			case 2: wiz_gamelist_text_out_fmt(x_Pos,y_Pos+80,"Sound         %s","ON (22 KHz fast)"); break;
			case 3: wiz_gamelist_text_out_fmt(x_Pos,y_Pos+80,"Sound         %s","ON (33 KHz fast)"); break;
			case 4: wiz_gamelist_text_out_fmt(x_Pos,y_Pos+80,"Sound         %s","ON (44 KHz fast)"); break;
			case 5: wiz_gamelist_text_out_fmt(x_Pos,y_Pos+80,"Sound         %s","ON (11 KHz fast)"); break;
			case 6: wiz_gamelist_text_out_fmt(x_Pos,y_Pos+80,"Sound         %s","ON (15 KHz)"); break;
			case 7: wiz_gamelist_text_out_fmt(x_Pos,y_Pos+80,"Sound         %s","ON (22 KHz)"); break;
			case 8: wiz_gamelist_text_out_fmt(x_Pos,y_Pos+80,"Sound         %s","ON (33 KHz)"); break;
			case 9: wiz_gamelist_text_out_fmt(x_Pos,y_Pos+80,"Sound         %s","ON (44 KHz)"); break;
			case 10: wiz_gamelist_text_out_fmt(x_Pos,y_Pos+80,"Sound         %s","ON (11 KHz)"); break;
			case 11: wiz_gamelist_text_out_fmt(x_Pos,y_Pos+80,"Sound         %s","ON (15 KHz stereo)"); break;
			case 12: wiz_gamelist_text_out_fmt(x_Pos,y_Pos+80,"Sound         %s","ON (22 KHz stereo)"); break;
			case 13: wiz_gamelist_text_out_fmt(x_Pos,y_Pos+80,"Sound         %s","ON (33 KHz stereo)"); break;
			case 14: wiz_gamelist_text_out_fmt(x_Pos,y_Pos+80,"Sound         %s","ON (44 KHz stereo)"); break;
			case 15: wiz_gamelist_text_out_fmt(x_Pos,y_Pos+80,"Sound         %s","ON (11 KHz stereo)"); break;
		}

		/* (6) CPU Clock */
		wiz_gamelist_text_out_fmt(x_Pos,y_Pos+90,"CPU Clock     %d%%",wiz_clock_cpu);

		/* (7) Audio Clock */
		wiz_gamelist_text_out_fmt(x_Pos,y_Pos+100,"Audio Clock   %d%%",wiz_clock_sound);

		/* (8) CPU cores */
		switch (wiz_cpu_cores)
		{
			case 0: wiz_gamelist_text_out(x_Pos,y_Pos+110, "CPU ASM cores None"); break;
			case 1: wiz_gamelist_text_out(x_Pos,y_Pos+110, "CPU ASM cores Cyclone"); break;
			case 2: wiz_gamelist_text_out(x_Pos,y_Pos+110, "CPU ASM cores DrZ80"); break;
			case 3: wiz_gamelist_text_out(x_Pos,y_Pos+110, "CPU ASM cores Cyclone+DrZ80"); break;
		}

		/* (9) RAM Tweaks */
		if (wiz_ramtweaks)
			wiz_gamelist_text_out(x_Pos,y_Pos+120,"RAM Tweaks    ON");
		else
			wiz_gamelist_text_out(x_Pos,y_Pos+120,"RAM Tweaks    OFF");

		/* (10) Cheats */
		if (wiz_cheat)
			wiz_gamelist_text_out(x_Pos,y_Pos+130,"Cheats        ON");
		else
			wiz_gamelist_text_out(x_Pos,y_Pos+130,"Cheats        OFF");
	
		wiz_gamelist_text_out(x_Pos,y_Pos+140,"Press B to confirm, X to return\0");

		/* Show currently selected item */
		wiz_gamelist_text_out(x_Pos-16,y_Pos+(selected_option*10)+30," >");

		wiz_video_flip();
		while(wiz_joystick_read(0)&0xFF0FC0) { wiz_timer_delay(150000); }
		while(!(ExKey=wiz_joystick_read(0)&0xFF0FC0)) { }
		if(ExKey & WIZ_DOWN){
			selected_option++;
			selected_option = selected_option % options_count;
		}
		else if(ExKey & WIZ_UP){
			selected_option--;
			if(selected_option<0)
				selected_option = options_count - 1;
		}
		else if(ExKey & WIZ_R || ExKey & WIZ_L)
		{
			switch(selected_option) {
			case 0:
				/* WIZ Clock */
				if(ExKey & WIZ_R){
					switch (wiz_freq) {
                        case 200: wiz_freq=300;break;
                        case 300: wiz_freq=400;break;
                        case 400: wiz_freq=500;break;
                        case 500: wiz_freq=533;break;
                        case 533: wiz_freq=650;break;
                        case 650: wiz_freq=700;break;
                        case 700: wiz_freq=750;break;
                        case 750: wiz_freq=760;break;
                        case 760: wiz_freq=770;break;
                        case 770: wiz_freq=780;break;
                        case 780: wiz_freq=790;break;
                        case 790: wiz_freq=795;break;
                        case 795: wiz_freq=800;break;
                        case 800: wiz_freq=805;break;
                        case 805: wiz_freq=810;break;
                        case 810: wiz_freq=815;break;
                        case 815: wiz_freq=820;break;
                        case 820: wiz_freq=825;break;
                        case 825: wiz_freq=830;break;
                        case 830: wiz_freq=835;break;
                        case 835: wiz_freq=840;break;
                        case 840: wiz_freq=845;break;
                        case 845: wiz_freq=850;break;
                        case 850: wiz_freq=855;break;
                        case 855: wiz_freq=860;break;
                        case 860: wiz_freq=865;break;
                        case 865: wiz_freq=870;break;
                        case 870: wiz_freq=875;break;
                        case 875: wiz_freq=880;break;
                        case 880: wiz_freq=885;break;
                        case 885: wiz_freq=890;break;
                        case 890: wiz_freq=895;break;
                        case 895: wiz_freq=900;break;
                        case 900: wiz_freq=200;break;
                        default:  wiz_freq=533;break;
					}
				} else {
					switch (wiz_freq) {
                        case 200: wiz_freq=900;break;
                        case 300: wiz_freq=200;break;
                        case 400: wiz_freq=300;break;
                        case 500: wiz_freq=400;break;
                        case 533: wiz_freq=500;break;
                        case 650: wiz_freq=533;break;
                        case 700: wiz_freq=650;break;
                        case 750: wiz_freq=700;break;
                        case 760: wiz_freq=750;break;
                        case 770: wiz_freq=760;break;
                        case 780: wiz_freq=770;break;
                        case 790: wiz_freq=780;break;
                        case 795: wiz_freq=790;break;
                        case 800: wiz_freq=795;break;
                        case 805: wiz_freq=800;break;
                        case 810: wiz_freq=805;break;
                        case 815: wiz_freq=810;break;
                        case 820: wiz_freq=815;break;
                        case 825: wiz_freq=820;break;
                        case 830: wiz_freq=825;break;
                        case 835: wiz_freq=830;break;
                        case 840: wiz_freq=835;break;
                        case 845: wiz_freq=840;break;
                        case 850: wiz_freq=845;break;
                        case 855: wiz_freq=850;break;
                        case 860: wiz_freq=855;break;
                        case 865: wiz_freq=860;break;
                        case 870: wiz_freq=865;break;
                        case 875: wiz_freq=870;break;
                        case 880: wiz_freq=875;break;
                        case 885: wiz_freq=880;break;
                        case 890: wiz_freq=885;break;
                        case 895: wiz_freq=890;break;
                        case 900: wiz_freq=895;break;
                        default:  wiz_freq=533;break;
					}
				}
				break;
			case 1:
				switch (wiz_video_depth)
				{
					case -1: wiz_video_depth=8; break;
					case 8: wiz_video_depth=16; break;
					case 16: wiz_video_depth=-1; break;
				}
				break;
			case 2:
				if(ExKey & WIZ_R)
				{
				    switch (wiz_video_aspect)
				    {
				        case 0: wiz_video_aspect=1; break;
				        case 1: wiz_video_aspect=8; break;
				        case 8: wiz_video_aspect=9; break;
				        case 9: wiz_video_aspect=24;break;
				        case 24:wiz_video_aspect=25;break;
				        case 25:wiz_video_aspect=0; break;
				    }
				}
				else
				{
				    switch (wiz_video_aspect)
				    {
				        case 0: wiz_video_aspect=25;break;
				        case 1: wiz_video_aspect=0; break;
				        case 8: wiz_video_aspect=1; break;
				        case 9: wiz_video_aspect=8; break;
				        case 24:wiz_video_aspect=9; break;
				        case 25:wiz_video_aspect=24;break;
				    }
				}
				break;
			case 3:
				wiz_video_sync=wiz_video_sync+1;
				if (wiz_video_sync>2)
					wiz_video_sync=-1;
				break;
			case 4:
				/* "Frame-Skip" */
				if(ExKey & WIZ_R)
				{
					wiz_frameskip ++;
					if (wiz_frameskip>11)
						wiz_frameskip=-1;
				}
				else
				{
					wiz_frameskip--;
					if (wiz_frameskip<-1)
						wiz_frameskip=11;
				}
				break;
			case 5:
				if(ExKey & WIZ_R)
				{
					wiz_sound ++;
					if (wiz_sound>15)
						wiz_sound=0;
				}
				else
				{
					wiz_sound--;
					if (wiz_sound<0)
						wiz_sound=15;
				}
				break;
			case 6:
				/* "CPU Clock" */
				if(ExKey & WIZ_R)
				{
					wiz_clock_cpu += 10; /* Add 10% */
					if (wiz_clock_cpu > 200) /* 200% is the max */
						wiz_clock_cpu = 200;
				}
				else
				{
					wiz_clock_cpu -= 10; /* Subtract 10% */
					if (wiz_clock_cpu < 10) /* 10% is the min */
						wiz_clock_cpu = 10;
				}
				break;
			case 7:
				/* "Audio Clock" */
				if(ExKey & WIZ_R)
				{
					wiz_clock_sound += 10; /* Add 10% */
					if (wiz_clock_sound > 200) /* 200% is the max */
						wiz_clock_sound = 200;
				}
				else{
					wiz_clock_sound -= 10; /* Subtract 10% */
					if (wiz_clock_sound < 10) /* 10% is the min */
						wiz_clock_sound = 10;
				}
				break;
			case 8:
				wiz_cpu_cores=(wiz_cpu_cores+1)%4;
				break;
			case 9:
				wiz_ramtweaks=!wiz_ramtweaks;
				break;
			case 10:
				wiz_cheat=!wiz_cheat;
				break;
			}
		}

		if ((ExKey & WIZ_A) || (ExKey & WIZ_B) || (ExKey & WIZ_MENU)) 
		{
			/* Write game configuration */
			sprintf(text,"frontend/%s.cfg",game);
			f=fopen(text,"w");
			if (f) {
				fprintf(f,"%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",wiz_freq,wiz_video_depth,wiz_video_aspect,wiz_video_sync,
				wiz_frameskip,wiz_sound,wiz_clock_cpu,wiz_clock_sound,wiz_cpu_cores,wiz_ramtweaks,i,wiz_cheat);
				fclose(f);
				sync();
			}

			/* Selected game will be run */
			return 1;
		}
		else if ((ExKey & WIZ_X) || (ExKey & WIZ_Y) || (ExKey & WIZ_SELECT))
		{
			/* Return To Menu */
			return 0;
		}
	}
}
Exemple #4
0
static int show_options(char *game)
{
	unsigned long ExKey=0;
	int selected_option=0;
	int x_Pos = 41;
	int y_Pos = 58;
	int options_count = 9;
	char text[256];
	FILE *f;
	int i=0;

	if(!safe_render_path)
	  while(ExKey=gp2x_joystick_read(0)&0x8c0ff55){};

	/* Read game configuration */
	sprintf(text,get_documents_path("iOS/%s_v2.cfg"),game);
	f=fopen(text,"r");
	if (f) {
		fscanf(f,"%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",&iOS_video_aspect,&iOS_video_rotate,&iOS_video_sync,
		&iOS_frameskip,&iOS_sound,&iOS_landscape_buttons,&iOS_clock_cpu,&iOS_clock_sound,&i,&iOS_cheat);
		fclose(f);
	}

	if(!safe_render_path)
	{
	   iOS_video_aspect=3;
	}

	while(1)
	{
		/* Draw background image */
		load_bmp_8bpp(gp2x_screen8,gp2xmenu_bmp);

		/* Draw the options */
		gp2x_gamelist_text_out(x_Pos,y_Pos,"Selected Game:\0");
		strncpy (text,game_list_description(last_game_selected),33);
		text[32]='\0';
		gp2x_gamelist_text_out(x_Pos,y_Pos+10,text);

		/* (1) Video Aspect */
		switch (iOS_video_aspect)
		{
			case 0: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video Aspect  Original"); break;
			case 1: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video Aspect  Ratio Not Kept"); break;
			case 2: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video Aspect  With Cropping"); break;
			case 3: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video Aspect  Fixed 320x240"); break;
		}

		/* (2) Video Rotation */
		switch (iOS_video_rotate)
		{
			case 0: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+40,"Video Rotate  No"); break;
			case 1: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+40,"Video Rotate  Yes"); break;
			case 2: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+40,"Video Rotate  TATE"); break;
		}
		
		/* (3) Video Sync */
		switch (iOS_video_sync)
		{
			case 0: gp2x_gamelist_text_out(x_Pos,y_Pos+50, "Video Sync    Normal"); break;
			case 1: gp2x_gamelist_text_out(x_Pos,y_Pos+50, "Video Sync    DblBuf"); break;
			case -1: gp2x_gamelist_text_out(x_Pos,y_Pos+50,"Video Sync    OFF"); break;
		}
		
		/* (4) Frame-Skip */
		if(iOS_frameskip==-1) {
			gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+60, "Frame-Skip    Auto");
		}
		else{
			gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+60,"Frame-Skip    %d",iOS_frameskip);
		}

		/* (5) Sound */
		switch(iOS_sound)
		{
			case 0: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","OFF"); break;

			case 1: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","ON (11 KHz fast)"); break;
			case 2: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","ON (22 KHz fast)"); break;
			case 3: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","ON (33 KHz fast)"); break;
			case 4: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","ON (44 KHz fast)"); break;

			case 5: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","ON (11 KHz)"); break;
			case 6: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","ON (22 KHz)"); break;
			case 7: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","ON (33 KHz)"); break;
			case 8: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","ON (44 KHz)"); break;

			case 9: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","ON (11 KHz stereo)"); break;
			case 10: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","ON (22 KHz stereo)"); break;
			case 11: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","ON (33 KHz stereo)"); break;
			case 12: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"Sound         %s","ON (44 KHz stereo)"); break;

		}

		/* (6) Landscape Num Buttons */
		switch (iOS_landscape_buttons)
		{
			case 1: gp2x_gamelist_text_out(x_Pos,y_Pos+80, "Landscape     1 Button"); break;
			case 2: gp2x_gamelist_text_out(x_Pos,y_Pos+80, "Landscape     2 Buttons"); break;
			case 3: gp2x_gamelist_text_out(x_Pos,y_Pos+80, "Landscape     3 Buttons"); break;
			case 4: gp2x_gamelist_text_out(x_Pos,y_Pos+80, "Landscape     4 Buttons"); break;
		}

		/* (7) CPU Clock */
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+90,"CPU Clock     %d%%",iOS_clock_cpu);

		/* (8) Audio Clock */
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+100,"Audio Clock   %d%%",iOS_clock_sound);


		/* (9) Cheats */
		if (iOS_cheat)
			gp2x_gamelist_text_out(x_Pos,y_Pos+110,"Cheats        ON");
		else
			gp2x_gamelist_text_out(x_Pos,y_Pos+110,"Cheats        OFF");
	
		gp2x_gamelist_text_out(x_Pos,y_Pos+140,"Press B to confirm, X to return\0");

		/* Show currently selected item */
		gp2x_gamelist_text_out(x_Pos-16,y_Pos+(selected_option*10)+30," >");

		gp2x_video_flip();

		if(safe_render_path)
		{
		   while(gp2x_joystick_read(0)&0x8c0ff55) { gp2x_timer_delay(150); }
		   while(!(ExKey=gp2x_joystick_read(0)&0x8c0ff55)) { }
		}
		else
		{
		   //ExKey=gp2x_joystick_read(0);
		   //gp2x_timer_delay(150);
		   gp2x_timer_delay(150);
		   ExKey=gp2x_joystick_read(0)&0x8c0ff55;
		}

		if(ExKey & GP2X_DOWN){
			selected_option++;
			selected_option = selected_option % options_count;
		}
		else if(ExKey & GP2X_UP){
			selected_option--;
			if(selected_option<0)
				selected_option = options_count - 1;
		}
		else if(ExKey & GP2X_R || ExKey & GP2X_L || ExKey & GP2X_RIGHT || ExKey & GP2X_LEFT)
		{
			switch(selected_option) {
			case 0:
				if(!safe_render_path)
				{
					iOS_video_aspect=3;
					break;
				}
				if((ExKey & GP2X_R) || (ExKey & GP2X_RIGHT))
				{
					iOS_video_aspect++;
					if (iOS_video_aspect>3)
						iOS_video_aspect=0;
				}
				else
				{
					iOS_video_aspect--;
					if (iOS_video_aspect<0)
						iOS_video_aspect=3;
				}
				break;
			case 1:
				if((ExKey & GP2X_R) || (ExKey & GP2X_RIGHT))
				{
					iOS_video_rotate++;
					if (iOS_video_rotate>2)
						iOS_video_rotate=0;
				}
				else
				{
					iOS_video_rotate--;
					if (iOS_video_rotate<0)
						iOS_video_rotate=2;
				}
				break;
			case 2:
				iOS_video_sync=iOS_video_sync+1;
				if (iOS_video_sync>1)
					iOS_video_sync=-1;
				break;
			case 3:
				/* "Frame-Skip" */
				if(ExKey & GP2X_R || ExKey & GP2X_RIGHT )
				{
					iOS_frameskip ++;
					if (iOS_frameskip>11)
						iOS_frameskip=-1;
				}
				else
				{
					iOS_frameskip--;
					if (iOS_frameskip<-1)
						iOS_frameskip=11;
				}
				break;
			case 4:
				if(ExKey & GP2X_R || ExKey & GP2X_RIGHT)
				{
					iOS_sound ++;
					if (iOS_sound>12)
						iOS_sound=0;
				}
				else
				{
					iOS_sound--;
					if (iOS_sound<0)
						iOS_sound=12;
				}
				break;
			case 5:
				if(ExKey & GP2X_R || ExKey & GP2X_RIGHT)
				{
					iOS_landscape_buttons ++;
					if (iOS_landscape_buttons>4)
						iOS_landscape_buttons=1;
				}
				else
				{
					iOS_landscape_buttons--;
					if (iOS_landscape_buttons<1)
						iOS_landscape_buttons=4;
				}
				break;
			case 6:
				/* "CPU Clock" */
				if(ExKey & GP2X_R || ExKey & GP2X_RIGHT)
				{
					iOS_clock_cpu += 10; /* Add 10% */
					if (iOS_clock_cpu > 200) /* 200% is the max */
						iOS_clock_cpu = 200;
				}
				else
				{
					iOS_clock_cpu -= 10; /* Subtract 10% */
					if (iOS_clock_cpu < 10) /* 10% is the min */
						iOS_clock_cpu = 10;
				}
				break;
			case 7:
				/* "Audio Clock" */
				if(ExKey & GP2X_R || ExKey & GP2X_RIGHT)
				{
					iOS_clock_sound += 10; /* Add 10% */
					if (iOS_clock_sound > 200) /* 200% is the max */
						iOS_clock_sound = 200;
				}
				else{
					iOS_clock_sound -= 10; /* Subtract 10% */
					if (iOS_clock_sound < 10) /* 10% is the min */
						iOS_clock_sound = 10;
				}
				break;
			case 8:
				iOS_cheat=!iOS_cheat;
				break;
			}
		}

		if ((ExKey & GP2X_A) || (ExKey & GP2X_B) || (ExKey & GP2X_PUSH) || (ExKey & GP2X_START))
		{
			/* Write game configuration */
			sprintf(text,get_documents_path("iOS/%s_v2.cfg"),game);
			f=fopen(text,"w");
			if (f) {
				fprintf(f,"%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",iOS_video_aspect,iOS_video_rotate,iOS_video_sync,
				iOS_frameskip,iOS_sound,iOS_landscape_buttons,iOS_clock_cpu,iOS_clock_sound,i,iOS_cheat);
				fclose(f);
				sync();
			}

			/* Selected game will be run */
			return 1;
		}
		else if ((ExKey & GP2X_X) || (ExKey & GP2X_Y) || (ExKey & GP2X_SELECT))
		{
			/* Return To Menu */
			return 0;
		}
	}
}
static int show_options(char *game)
{
	unsigned long ExKey=0;
	int selected_option=0;
	int x_Pos = 41;
	int y_PosTop = 58;
	int y_Pos = y_PosTop;
	int options_count = 10;
	char text[256];
	FILE *f;
	int i=0;

	/* Read game configuration */
	sprintf(text,"frontend/%s.cfg",game);
	f=fopen(text,"r");
	if (f) {
		fscanf(f,"%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",&pnd_freq,&pnd_video_depth,&pnd_video_aspect,&pnd_video_sync,
		&pnd_frameskip,&pnd_sound,&pnd_clock_cpu,&pnd_clock_sound,&pnd_cpu_cores,&pnd_ramtweaks,&i,&pnd_cheat,&pnd_volume,
		&pnd_video_rotate,&pnd_video_filter);
		fclose(f);
	}

	while(1)
	{
		y_Pos = y_PosTop;
		
		/* Draw background image */
		blit_bmp_8bpp(pnd_screen15,menu_bmp);

		/* Draw the options */
		strncpy (text,game_list_description(last_game_selected),33);
		text[32]='\0';
		pnd_gamelist_text_out(x_Pos,y_Pos-10,text);

		/* Video Aspect */
		y_Pos += 10;
		switch (pnd_video_aspect)
		{
			case 0: pnd_gamelist_text_out_fmt(x_Pos,y_Pos,"Video Aspect    Normal"); break;
			case 1: pnd_gamelist_text_out_fmt(x_Pos,y_Pos,"Video Aspect    Scale"); break;
			case 2: pnd_gamelist_text_out_fmt(x_Pos,y_Pos,"Video Aspect    4:3"); break;
			case 3: pnd_gamelist_text_out_fmt(x_Pos,y_Pos,"Video Aspect    Stretch"); break;
			case 4: pnd_gamelist_text_out_fmt(x_Pos,y_Pos,"Video Aspect    Fit"); break;
		}

		/* Video Rotation */
		y_Pos += 10;
		switch (pnd_video_rotate)
		{
			case 0:  pnd_gamelist_text_out_fmt(x_Pos,y_Pos,"Video Rotation  OFF"); break;
			case 1:  pnd_gamelist_text_out_fmt(x_Pos,y_Pos,"Video Rotation  ON"); break;
		}

		/* Video Filter */
		y_Pos += 10;
		switch (pnd_video_filter)
		{
			case -1: pnd_gamelist_text_out_fmt(x_Pos,y_Pos,"Video Filter    Auto"); break;
			case 0:  pnd_gamelist_text_out_fmt(x_Pos,y_Pos,"Video Filter    None"); break;
			case 1:  pnd_gamelist_text_out_fmt(x_Pos,y_Pos,"Video Filter    Default"); break;
		}
		
		/* Video Sync */
		y_Pos += 10;
		switch (pnd_video_sync)
		{
			case 0: pnd_gamelist_text_out(x_Pos,y_Pos, "Video Sync      Normal"); break;
			case 1: pnd_gamelist_text_out(x_Pos,y_Pos, "Video Sync      VSync"); break;
			case 2: pnd_gamelist_text_out(x_Pos,y_Pos, "Video Sync      DblBuf"); break;
			case -1: pnd_gamelist_text_out(x_Pos,y_Pos,"Video Sync      OFF"); break;
		}
		
		/* Frame-Skip */
		y_Pos += 10;
		if ((pnd_video_sync==-1) && (pnd_frameskip==-1)) pnd_frameskip=0;
		if(pnd_frameskip==-1) {
			pnd_gamelist_text_out_fmt(x_Pos,y_Pos, "Frame-Skip      Auto");
		}
		else{
			pnd_gamelist_text_out_fmt(x_Pos,y_Pos,"Frame-Skip      %d",pnd_frameskip);
		}

		/* Sound */
		y_Pos += 10;
		switch(pnd_sound)
		{
			case 0:  pnd_gamelist_text_out_fmt(x_Pos,y_Pos,"Sound           %s","OFF"); break;
			case 1:  pnd_gamelist_text_out_fmt(x_Pos,y_Pos,"Sound           %s","ON (15 KHz fast)"); break;
			case 2:  pnd_gamelist_text_out_fmt(x_Pos,y_Pos,"Sound           %s","ON (22 KHz fast)"); break;
			case 3:  pnd_gamelist_text_out_fmt(x_Pos,y_Pos,"Sound           %s","ON (33 KHz fast)"); break;
			case 4:  pnd_gamelist_text_out_fmt(x_Pos,y_Pos,"Sound           %s","ON (44 KHz fast)"); break;
			case 5:  pnd_gamelist_text_out_fmt(x_Pos,y_Pos,"Sound           %s","ON (11 KHz fast)"); break;
			case 6:  pnd_gamelist_text_out_fmt(x_Pos,y_Pos,"Sound           %s","ON (15 KHz mono)"); break;
			case 7:  pnd_gamelist_text_out_fmt(x_Pos,y_Pos,"Sound           %s","ON (22 KHz mono)"); break;
			case 8:  pnd_gamelist_text_out_fmt(x_Pos,y_Pos,"Sound           %s","ON (33 KHz mono)"); break;
			case 9:  pnd_gamelist_text_out_fmt(x_Pos,y_Pos,"Sound           %s","ON (44 KHz mono)"); break;
			case 10: pnd_gamelist_text_out_fmt(x_Pos,y_Pos,"Sound           %s","ON (11 KHz mono)"); break;
			case 11: pnd_gamelist_text_out_fmt(x_Pos,y_Pos,"Sound           %s","ON (15 KHz stereo)"); break;
			case 12: pnd_gamelist_text_out_fmt(x_Pos,y_Pos,"Sound           %s","ON (22 KHz stereo)"); break;
			case 13: pnd_gamelist_text_out_fmt(x_Pos,y_Pos,"Sound           %s","ON (33 KHz stereo)"); break;
			case 14: pnd_gamelist_text_out_fmt(x_Pos,y_Pos,"Sound           %s","ON (44 KHz stereo)"); break;
			case 15: pnd_gamelist_text_out_fmt(x_Pos,y_Pos,"Sound           %s","ON (11 KHz stereo)"); break;
		}

		/* CPU Clock */
		y_Pos += 10;
		pnd_gamelist_text_out_fmt(x_Pos,y_Pos,"CPU Clock       %d%%",pnd_clock_cpu);

		/* Audio Clock */
		y_Pos += 10;
		pnd_gamelist_text_out_fmt(x_Pos,y_Pos,"Audio Clock     %d%%",pnd_clock_sound);

		/* CPU cores */
		y_Pos += 10;
		switch (pnd_cpu_cores)
		{
			case 0: pnd_gamelist_text_out(x_Pos,y_Pos, "CPU ASM cores   None"); break;
			case 1: pnd_gamelist_text_out(x_Pos,y_Pos, "CPU ASM cores   Cyclone"); break;
			case 2: pnd_gamelist_text_out(x_Pos,y_Pos, "CPU ASM cores   DrZ80"); break;
			case 3: pnd_gamelist_text_out(x_Pos,y_Pos, "CPU ASM cores   Cyclone+DrZ80"); break;
			case 4: pnd_gamelist_text_out(x_Pos,y_Pos, "CPU ASM cores   DrZ80(snd)"); break;
			case 5: pnd_gamelist_text_out(x_Pos,y_Pos, "CPU ASM cores   Cyclone+DrZ80(snd)"); break;
		}

		/* Cheats */
		y_Pos += 10;
		if (pnd_cheat)
			pnd_gamelist_text_out(x_Pos,y_Pos,"Cheats          ON");
		else
			pnd_gamelist_text_out(x_Pos,y_Pos,"Cheats          OFF");

        /* Volume */
        y_Pos += 10;
        /* Does nothing on Pandora right now...
        if (pnd_sound == 0)
        {
            pnd_gamelist_text_out(x_Pos,y_Pos,"Volume          Disabled");
        }
        else
        {
            switch (pnd_volume)
            {
                case 1: pnd_gamelist_text_out(x_Pos,y_Pos,"Volume          Quiet"); break;
                case 2: pnd_gamelist_text_out(x_Pos,y_Pos,"Volume          Low"); break;
                case 3: pnd_gamelist_text_out(x_Pos,y_Pos,"Volume          Medium"); break;
                case 4: pnd_gamelist_text_out(x_Pos,y_Pos,"Volume          Maximum"); break;
            }
        }
        */
	
		y_Pos += 30;
		pnd_gamelist_text_out(x_Pos,y_Pos,"Press B to confirm, X to return\0");

		/* Show currently selected item */
		pnd_gamelist_text_out(x_Pos-16,y_PosTop+(selected_option*10)+10," >");

		pnd_video_flip();
		while(pnd_joystick_read(0)&0x8c0ff55) { pnd_timer_delay(150); }
		while(!(ExKey=pnd_joystick_read(0)&0x8c0ff55)) { }
		
		/* Map left/right to L/R */
		if(ExKey & PND_LEFT)  ExKey |= PND_L;
		if(ExKey & PND_RIGHT) ExKey |= PND_R;

		if(ExKey & PND_DOWN){
			selected_option++;
			selected_option = selected_option % options_count;
		}
		else if(ExKey & PND_UP){
			selected_option--;
			if(selected_option<0)
				selected_option = options_count - 1;
		}
		else if(ExKey & PND_R || ExKey & PND_L)
		{
			switch(selected_option) {
/*			case 0:
				switch (pnd_video_depth)
				{
					case -1: pnd_video_depth=8; break;
					case 8: pnd_video_depth=16; break;
					case 16: pnd_video_depth=-1; break;
				}
				break; */
			case 0:
				if(ExKey & PND_R)
				{
					pnd_video_aspect++;
					if (pnd_video_aspect>4)
						pnd_video_aspect=0;
				}
				else
				{
					pnd_video_aspect--;
					if (pnd_video_aspect<0)
						pnd_video_aspect=4;
				}
				break;
			case 1:
				if( pnd_video_rotate )
					pnd_video_rotate = 0;
				else
					pnd_video_rotate = 1;
				break;
			case 2:
				if(ExKey & PND_R) {
					pnd_video_filter++;
					if (pnd_video_filter>1)
						pnd_video_filter=-1;
				}
				else
				{
					pnd_video_filter--;
					if (pnd_video_filter<-1)
						pnd_video_filter=1;				
				}
				break;
			case 3:
				if(ExKey & PND_R) {
					pnd_video_sync++;
					if (pnd_video_sync>2)
						pnd_video_sync=-1;
					break;
				}
				else
				{
					pnd_video_sync--;
					if (pnd_video_sync<-1)
						pnd_video_sync=2;
					break;				
				}
			case 4:
				/* "Frame-Skip" */
				if(ExKey & PND_R)
				{
					pnd_frameskip ++;
					if (pnd_frameskip>11)
						pnd_frameskip=-1;
				}
				else
				{
					pnd_frameskip--;
					if (pnd_frameskip<-1)
						pnd_frameskip=11;
				}
				break;
			case 5:
				if(ExKey & PND_R)
				{
					pnd_sound ++;
					if (pnd_sound>15)
						pnd_sound=0;
				}
				else
				{
					pnd_sound--;
					if (pnd_sound<0)
						pnd_sound=15;
				}
				break;
			case 6:
				/* "CPU Clock" */
				if(ExKey & PND_R)
				{
					pnd_clock_cpu += 10; /* Add 10% */
					if (pnd_clock_cpu > 200) /* 200% is the max */
						pnd_clock_cpu = 200;
				}
				else
				{
					pnd_clock_cpu -= 10; /* Subtract 10% */
					if (pnd_clock_cpu < 10) /* 10% is the min */
						pnd_clock_cpu = 10;
				}
				break;
			case 7:
				/* "Audio Clock" */
				if(ExKey & PND_R)
				{
					pnd_clock_sound += 10; /* Add 10% */
					if (pnd_clock_sound > 200) /* 200% is the max */
						pnd_clock_sound = 200;
				}
				else{
					pnd_clock_sound -= 10; /* Subtract 10% */
					if (pnd_clock_sound < 10) /* 10% is the min */
						pnd_clock_sound = 10;
				}
				break;
			case 8:
				pnd_cpu_cores=(pnd_cpu_cores+1)%6;
				break;
			case 9:
				pnd_cheat=!pnd_cheat;
				break;
			/* case 10: */
                /* Volume */
                /*
                if(ExKey & PND_R)
                {
                    pnd_volume++;
                    if (pnd_volume > 4)
                        pnd_volume = 1;
                }
                else {
                    pnd_volume--;
                    if (pnd_volume < 1)
                        pnd_volume = 4;
                }
                break;
                */
			}
		}

		if ((ExKey & PND_A) || (ExKey & PND_B) || (ExKey & PND_START)) 
		{
			/* Write game configuration */
			sprintf(text,"frontend/%s.cfg",game);
			f=fopen(text,"w");
			if (f) {
				fprintf(f,"%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",pnd_freq,pnd_video_depth,pnd_video_aspect,pnd_video_sync,
				pnd_frameskip,pnd_sound,pnd_clock_cpu,pnd_clock_sound,pnd_cpu_cores,pnd_ramtweaks,i,pnd_cheat,pnd_volume,
				pnd_video_rotate,pnd_video_filter);
				fclose(f);
				sync();
			}

			/* Selected game will be run */
			return 1;
		}
		else if ((ExKey & PND_X) || (ExKey & PND_Y) || (ExKey & PND_SELECT))
		{
			/* Return To Menu */
			return 0;
		}
	}
}
static int show_options(char *game)
{
	unsigned long ExKey=0;
	int selected_option=0;
	int x_Pos = 41;
	int y_Pos = 58;
	int options_count = 12;
	char text[256];
	FILE *f;
	int i=0;

	/* Read game configuration */
	sprintf(text,"frontend/%s.cfg",game);
	f=fopen(text,"r");
	if (f) {
		fscanf(f,"%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",&gp2x_freq,&gp2x_video_depth,&gp2x_video_aspect,&gp2x_video_sync,
		&gp2x_frameskip,&gp2x_sound,&gp2x_clock_cpu,&gp2x_clock_sound,&gp2x_cpu_cores,&gp2x_ramtweaks,&i,&gp2x_cheat,&gp2x_volume);
		fclose(f);
	}

	while(1)
	{
		/* Draw background image */
		load_bmp_8bpp(gp2x_screen8,gp2xmenu_bmp);

		/* Draw the options */
		strncpy (text,game_list_description(last_game_selected),33);
		text[32]='\0';
		gp2x_gamelist_text_out(x_Pos,y_Pos-10,text);

		/* (0) GP2X Clock */
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+10, "GP2X Clock    %d MHz", gp2x_freq);

		/* (1) Video Depth */
		switch (gp2x_video_depth)
		{
			case -1: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+20,"Video Depth   Auto"); break;
			case 8:  gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+20,"Video Depth   8 bit"); break;
			case 16: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+20,"Video Depth   16 bit"); break;
		}

		/* (2) Video Aspect */
		switch (gp2x_video_aspect)
		{
			case 0: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video Aspect  Normal"); break;
			case 1: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video Aspect  Scale"); break;
			case 2: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video Aspect  4:3"); break;
			case 3: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video Aspect  Scale 4:3"); break;
			case 4: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video Aspect  Border"); break;
			case 5: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video Aspect  Border Scale"); break;
			case 6: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video Aspect  Border 4:3"); break;
			case 7: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video Aspect  Border Scale 4:3"); break;
			case 8: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video Aspect  Rotate"); break;
			case 9: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video Aspect  Rotate Scale"); break;
			case 10: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video Aspect  Rotate 4:3"); break;
			case 11: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video Aspect  Rotate Scale 4:3"); break;
			case 12: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video Aspect  Rotate Border"); break;
			case 13: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video Aspect  Rotate Border Scale"); break;
			case 14: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video Aspect  Rotate Border 4:3"); break;
			case 15: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video Aspect  Rotate Border S4:3"); break;
			case 16: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video Aspect  TATE"); break;
			case 17: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video Aspect  TATE Scale"); break;
			case 18: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video Aspect  TATE 4:3"); break;
			case 19: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video Aspect  TATE Scale 4:3"); break;
			case 20: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video Aspect  TATE Border"); break;
			case 21: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video Aspect  TATE Border Scale"); break;
			case 22: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video Aspect  TATE Border 4:3"); break;
			case 23: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+30,"Video Aspect  TATE Border S4:3"); break;
		}
		
		/* (3) Video Sync */
		switch (gp2x_video_sync)
		{
			case 1: gp2x_gamelist_text_out(x_Pos,y_Pos+40, "Video Sync    VSync"); break;
			case 0: gp2x_gamelist_text_out(x_Pos,y_Pos+40, "Video Sync    Normal"); break;
			case 2: gp2x_gamelist_text_out(x_Pos,y_Pos+40, "Video Sync    DblBuf"); break;
			case -1: gp2x_gamelist_text_out(x_Pos,y_Pos+40,"Video Sync    OFF"); break;
		}
		
		/* (4) Frame-Skip */
		if ((gp2x_video_sync==-1) && (gp2x_frameskip==-1)) gp2x_frameskip=0;
		if(gp2x_frameskip==-1) {
			gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+50, "Frame-Skip    Auto");
		}
		else{
			gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+50,"Frame-Skip    %d",gp2x_frameskip);
		}

		/* (5) Sound */
		switch(gp2x_sound)
		{
			case 0: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+60,"Sound         %s","OFF"); break;
			case 1: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+60,"Sound         %s","ON (15 KHz fast)"); break;
			case 2: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+60,"Sound         %s","ON (22 KHz fast)"); break;
			case 3: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+60,"Sound         %s","ON (33 KHz fast)"); break;
			case 4: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+60,"Sound         %s","ON (44 KHz fast)"); break;
			case 5: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+60,"Sound         %s","ON (11 KHz fast)"); break;
			case 6: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+60,"Sound         %s","ON (15 KHz)"); break;
			case 7: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+60,"Sound         %s","ON (22 KHz)"); break;
			case 8: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+60,"Sound         %s","ON (33 KHz)"); break;
			case 9: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+60,"Sound         %s","ON (44 KHz)"); break;
			case 10: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+60,"Sound         %s","ON (11 KHz)"); break;
			case 11: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+60,"Sound         %s","ON (15 KHz stereo)"); break;
			case 12: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+60,"Sound         %s","ON (22 KHz stereo)"); break;
			case 13: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+60,"Sound         %s","ON (33 KHz stereo)"); break;
			case 14: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+60,"Sound         %s","ON (44 KHz stereo)"); break;
			case 15: gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+60,"Sound         %s","ON (11 KHz stereo)"); break;
		}

		/* (6) CPU Clock */
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+70,"CPU Clock     %d%%",gp2x_clock_cpu);

		/* (7) Audio Clock */
		gp2x_gamelist_text_out_fmt(x_Pos,y_Pos+80,"Audio Clock   %d%%",gp2x_clock_sound);

		/* (8) CPU cores */
		switch (gp2x_cpu_cores)
		{
			case 0: gp2x_gamelist_text_out(x_Pos,y_Pos+90, "CPU ASM cores None"); break;
			case 1: gp2x_gamelist_text_out(x_Pos,y_Pos+90, "CPU ASM cores Cyclone"); break;
			case 2: gp2x_gamelist_text_out(x_Pos,y_Pos+90, "CPU ASM cores DrZ80"); break;
			case 3: gp2x_gamelist_text_out(x_Pos,y_Pos+90, "CPU ASM cores Cyclone+DrZ80"); break;
			case 4: gp2x_gamelist_text_out(x_Pos,y_Pos+90, "CPU ASM cores DrZ80(snd)"); break;
			case 5: gp2x_gamelist_text_out(x_Pos,y_Pos+90, "CPU ASM cores Cyclone+DrZ80(snd)"); break;
		}

		/* (9) RAM Tweaks */
		if (gp2x_ramtweaks)
			gp2x_gamelist_text_out(x_Pos,y_Pos+100,"RAM Tweaks    ON");
		else
			gp2x_gamelist_text_out(x_Pos,y_Pos+100,"RAM Tweaks    OFF");

		/* (10) Cheats */
		if (gp2x_cheat)
			gp2x_gamelist_text_out(x_Pos,y_Pos+110,"Cheats        ON");
		else
			gp2x_gamelist_text_out(x_Pos,y_Pos+110,"Cheats        OFF");

        /* (11) Volume */
        if (gp2x_sound == 0)
        {
            gp2x_gamelist_text_out(x_Pos,y_Pos+120,"Volume        Disabled");
        }
        else
        {
            switch (gp2x_volume)
            {
                case 1: gp2x_gamelist_text_out(x_Pos,y_Pos+120,"Volume        Quiet"); break;
                case 2: gp2x_gamelist_text_out(x_Pos,y_Pos+120,"Volume        Low"); break;
                case 3: gp2x_gamelist_text_out(x_Pos,y_Pos+120,"Volume        Medium"); break;
                case 4: gp2x_gamelist_text_out(x_Pos,y_Pos+120,"Volume        Maximum"); break;
            }
        }
	
		gp2x_gamelist_text_out(x_Pos,y_Pos+140,"Press B to confirm, X to return\0");

		/* Show currently selected item */
		gp2x_gamelist_text_out(x_Pos-16,y_Pos+(selected_option*10)+10," >");

		gp2x_video_flip();
		while(gp2x_joystick_read(0)&0x8c0ff55) { gp2x_timer_delay(150); }
		while(!(ExKey=gp2x_joystick_read(0)&0x8c0ff55)) { }
		if(ExKey & GP2X_DOWN){
			selected_option++;
			selected_option = selected_option % options_count;
		}
		else if(ExKey & GP2X_UP){
			selected_option--;
			if(selected_option<0)
				selected_option = options_count - 1;
		}
		else if(ExKey & GP2X_R || ExKey & GP2X_L)
		{
			switch(selected_option) {
			case 0:
				/* GP2X Clock */
				if(ExKey & GP2X_R){
					switch (gp2x_freq) {
						case  66: gp2x_freq=75;break;
						case  75: gp2x_freq=80;break;
						case  80: gp2x_freq=100;break;
						case 100: gp2x_freq=120;break;
						case 120: gp2x_freq=133;break;
						case 133: gp2x_freq=150;break;
						case 150: gp2x_freq=166;break;
						case 166: gp2x_freq=180;break;
						case 180: gp2x_freq=200;break;
						case 200: gp2x_freq=225;break;
						case 225: gp2x_freq=233;break;
						case 233: gp2x_freq=245;break;
						case 245: gp2x_freq=250;break;
						case 250: gp2x_freq=255;break;
						case 255: gp2x_freq=260;break;
						case 260: gp2x_freq=265;break;
						case 265: gp2x_freq=266;break;
						case 266: gp2x_freq=270;break;
						case 270: gp2x_freq=275;break;
						case 275: gp2x_freq=280;break;
						case 280: gp2x_freq=285;break;
						case 285: gp2x_freq=290;break;
						case 290: gp2x_freq=295;break;
						case 295: gp2x_freq=300;break;
						case 300: gp2x_freq=66;break;
					}
				} else {
					switch (gp2x_freq) {
						case  66: gp2x_freq=300;break;
						case  75: gp2x_freq=66;break;
						case  80: gp2x_freq=75;break;
						case 100: gp2x_freq=80;break;
						case 120: gp2x_freq=100;break;
						case 133: gp2x_freq=120;break;
						case 150: gp2x_freq=133;break;
						case 166: gp2x_freq=150;break;
						case 180: gp2x_freq=166;break;
						case 200: gp2x_freq=180;break;
						case 225: gp2x_freq=200;break;
						case 233: gp2x_freq=225;break;
						case 245: gp2x_freq=233;break;
						case 250: gp2x_freq=245;break;
						case 255: gp2x_freq=250;break;
						case 260: gp2x_freq=255;break;
						case 265: gp2x_freq=260;break;
						case 266: gp2x_freq=265;break;
						case 270: gp2x_freq=266;break;
						case 275: gp2x_freq=270;break;
						case 280: gp2x_freq=275;break;
						case 285: gp2x_freq=280;break;
						case 290: gp2x_freq=285;break;
						case 295: gp2x_freq=290;break;
						case 300: gp2x_freq=295;break;
					}
				}
				break;
			case 1:
				switch (gp2x_video_depth)
				{
					case -1: gp2x_video_depth=8; break;
					case 8: gp2x_video_depth=16; break;
					case 16: gp2x_video_depth=-1; break;
				}
				break;
			case 2:
				if(ExKey & GP2X_R)
				{
					gp2x_video_aspect++;
					if (gp2x_video_aspect>23)
						gp2x_video_aspect=0;
				}
				else
				{
					gp2x_video_aspect--;
					if (gp2x_video_aspect<0)
						gp2x_video_aspect=23;
				}
				break;
			case 3:
				gp2x_video_sync=gp2x_video_sync+1;
				if (gp2x_video_sync>2)
					gp2x_video_sync=-1;
				break;
			case 4:
				/* "Frame-Skip" */
				if(ExKey & GP2X_R)
				{
					gp2x_frameskip ++;
					if (gp2x_frameskip>11)
						gp2x_frameskip=-1;
				}
				else
				{
					gp2x_frameskip--;
					if (gp2x_frameskip<-1)
						gp2x_frameskip=11;
				}
				break;
			case 5:
				if(ExKey & GP2X_R)
				{
					gp2x_sound ++;
					if (gp2x_sound>15)
						gp2x_sound=0;
				}
				else
				{
					gp2x_sound--;
					if (gp2x_sound<0)
						gp2x_sound=15;
				}
				break;
			case 6:
				/* "CPU Clock" */
				if(ExKey & GP2X_R)
				{
					gp2x_clock_cpu += 10; /* Add 10% */
					if (gp2x_clock_cpu > 200) /* 200% is the max */
						gp2x_clock_cpu = 200;
				}
				else
				{
					gp2x_clock_cpu -= 10; /* Subtract 10% */
					if (gp2x_clock_cpu < 10) /* 10% is the min */
						gp2x_clock_cpu = 10;
				}
				break;
			case 7:
				/* "Audio Clock" */
				if(ExKey & GP2X_R)
				{
					gp2x_clock_sound += 10; /* Add 10% */
					if (gp2x_clock_sound > 200) /* 200% is the max */
						gp2x_clock_sound = 200;
				}
				else{
					gp2x_clock_sound -= 10; /* Subtract 10% */
					if (gp2x_clock_sound < 10) /* 10% is the min */
						gp2x_clock_sound = 10;
				}
				break;
			case 8:
				gp2x_cpu_cores=(gp2x_cpu_cores+1)%6;
				break;
			case 9:
				gp2x_ramtweaks=!gp2x_ramtweaks;
				break;
			case 10:
				gp2x_cheat=!gp2x_cheat;
				break;
            case 11:
                /* Volume */
                if(ExKey & GP2X_R)
                {
                    gp2x_volume++;
                    if (gp2x_volume > 4)
                        gp2x_volume = 1;
                }
                else {
                    gp2x_volume--;
                    if (gp2x_volume < 1)
                        gp2x_volume = 4;
                }
                break;
			}
		}

		if ((ExKey & GP2X_A) || (ExKey & GP2X_B) || (ExKey & GP2X_PUSH) || (ExKey & GP2X_START)) 
		{
			/* Write game configuration */
			sprintf(text,"frontend/%s.cfg",game);
			f=fopen(text,"w");
			if (f) {
				fprintf(f,"%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",gp2x_freq,gp2x_video_depth,gp2x_video_aspect,gp2x_video_sync,
				gp2x_frameskip,gp2x_sound,gp2x_clock_cpu,gp2x_clock_sound,gp2x_cpu_cores,gp2x_ramtweaks,i,gp2x_cheat,gp2x_volume);
				fclose(f);
				sync();
			}

			/* Selected game will be run */
			return 1;
		}
		else if ((ExKey & GP2X_X) || (ExKey & GP2X_Y) || (ExKey & GP2X_SELECT))
		{
			/* Return To Menu */
			return 0;
		}
	}
}