Exemple #1
0
int launcher(){;

	char *rom = 0;
	char *dir = rc_getstr("romdir");
	char version_str[80];
    
    snprintf(version_str, sizeof(version_str)-1, "gnuboy %s", VERSION);

	gui_begin();

launcher:
	dialog_begin("OhBoy http://ohboy.googlecode.com/", version_str);
	dialog_text("Load ROM",NULL,FIELD_SELECTABLE);
	dialog_text("Options",NULL,FIELD_SELECTABLE);
	dialog_text("Controls",NULL,FIELD_SELECTABLE);
	dialog_text("About",NULL,FIELD_SELECTABLE);
	dialog_text("Quit","",FIELD_SELECTABLE);

#ifdef DINGOO_NATIVE
	dialog_text(NULL, NULL, 0); /* blank line */
	dialog_text("Menu:", NULL, 0);
	dialog_text(" Slide Power", NULL, 0);
#endif /* DINGOO_NATIVE */

	switch(dialog_end()){
		case 1:
			rom = menu_requestfile(NULL,"Select Rom",dir,"gb;gbc;zip");
			if(!rom) goto launcher;
			break;
		case 2:
			if(!menu_options()) goto launcher;
			break;
		case 3:
			if(!menu_controls()) goto launcher;
			break;
		case 4:
			if(!menu_about()) goto launcher;
			break;
		case 5:
			SDL_QuitSubSystem(SDL_INIT_EVERYTHING);
			SDL_Quit();
			exit(0);
		default:
			goto launcher;
	}

	gui_end();

	return rom;
}
Exemple #2
0
int
main (int argc, char **argv)
{
	char		username[128];
	char		passwd[AUTH_PASS_LEN + 1];
	int 		tries, remaining, c;
	UINT4		client_port;
	void 		(*login_func)(char *);	
	FILE		*fp;
	char 		buf[4096];
	char		tty[1024], *p;
	int		noissue = 0;
	int		maxtries = 0;
	char		*ttyn  = NULL;
	char            *path_radiusclient_conf = RC_CONFIG_FILE;

        extern char *optarg;
        extern int optind;

	pname = (pname = strrchr(argv[0],'/'))?pname+1:argv[0];
	
	rc_openlog(pname);

	while ((c = getopt(argc,argv,"f:m:i:nhV")) > 0)
	{
		switch(c) {
			case 'f':
				path_radiusclient_conf = optarg;
				break;
			case 'i':
				ttyn = optarg;
				break;
			case 'n':
				noissue = 1;
				break;
			case 'm':
				maxtries = atoi(optarg);
				break;
			case 'V':
				version();
				break;
			case 'h':
				usage();
				break;
			default:
				exit(ERROR_RC);
				break;
		}
	}

	if (rc_read_config(path_radiusclient_conf) != 0)
		exit(ERROR_RC);
	
	if (rc_read_dictionary(rc_conf_str("dictionary")) != 0)
		exit (ERROR_RC);

	if (rc_read_mapfile(rc_conf_str("mapfile")) != 0)
		exit (ERROR_RC);

	if (ttyn != NULL)
	{
		client_port = rc_map2id(ttyn);
		
		if ((p = strrchr(ttyn, '/')) == NULL)
			strncpy(tty, ttyn, sizeof(tty));
		else
			strncpy(tty, p+1, sizeof(tty));
	}
	else
	{
		ttyn = ttyname(0);
		if (ttyn)
		{
			if ((p = strrchr(ttyn, '/')) == NULL)
				strncpy(tty, ttyn, sizeof(tty));
			else
				strncpy(tty, p+1, sizeof(tty));

			client_port = rc_map2id(ttyn);
		}
		else 
		{
			*tty = '\0';
			client_port = 0;
		}
	}

#ifdef SETVBUF_REVERSED
	setvbuf(stdout, _IONBF, NULL, 0);
#else
	setvbuf(stdout, NULL, _IONBF, 0);
#endif

	if ((argc - optind) == 1)
	{
		strncpy(username,argv[optind], sizeof(username));
	}
	else
	{
		*username = '******';
		
		if (!noissue) {
			if (rc_conf_str("issue") && ((fp = fopen(rc_conf_str("issue"), "r")) != NULL))
			{
				while (fgets(buf, sizeof(buf), fp) != NULL)
					fputs(subst_placeholders(buf, tty), stdout);

				fflush(stdout);
				fclose(fp);
			} else {
				fputs(subst_placeholders(SC_DEFAULT_ISSUE, tty), stdout);
				fflush(stdout);
			}
		}
	}

	if ((env = rc_new_env(ENV_SIZE)) == NULL)
	{
		rc_log(LOG_CRIT, "rc_new_env: FATAL: out of memory");
		abort();
	}
	
#ifdef SECURITY_DISABLED
	if (rc_import_env(env,environ) < 0)
	{
		rc_log(LOG_CRIT, "rc_import_env: FATAL: not enough space for environment (increase ENV_SIZE)");
		abort();
	}
#else
	rc_add_env(env, "IFS", " ");
	rc_add_env(env, "PATH", RC_SECURE_PATH);
#endif

	signal(SIGALRM, alarm_handler);

	remaining = rc_conf_int("login_timeout");
	
	if (!maxtries)
		maxtries = rc_conf_int("login_tries");
		
	tries = 1;
	while (tries <= maxtries)
	{
	 alarm(remaining);

	 while (!*username) {
	 	p = rc_getstr (SC_LOGIN, 1);
	 	if (p)
	 		strncpy(username, p, sizeof(username));
	 	else
	 		exit (ERROR_RC);
	 }
	 p = rc_getstr(SC_PASSWORD,0);
	 if (p) 
	 	strncpy (passwd, p, sizeof (passwd));		
	 else 
		exit (ERROR_RC);

	 remaining = alarm(0);
	 
	 login_func = NULL;

 	 if (rc_conf_int("auth_order") & AUTH_LOCAL_FST)
 	 {
 	 	login_func = auth_local(username, passwd);
 	 		
 	 	if (!login_func)
 	 		if (rc_conf_int("auth_order") & AUTH_RADIUS_SND)
 	 			login_func = auth_radius(client_port, username, passwd);
 	 }
 	 else
 	 {
		login_func = auth_radius(client_port, username, passwd);
 	 	if (!login_func)
 	 		if (rc_conf_int("auth_order") & AUTH_LOCAL_SND)
 	 			login_func = auth_local(username, passwd);
 	 }

	 memset(passwd, '\0', sizeof(passwd));

	 if (login_func != NULL)
	 	if (login_allowed(tty)) {
	 		(*login_func)(username);
		} else {
			sleep(1);
			exit (ERROR_RC);
		}

	 *username = '******';
	 
	 if ((++tries) <= maxtries) {
		alarm(remaining);
	 	sleep(tries * 2);
	 	remaining = alarm(0);
	 }

	}

	fprintf(stderr, SC_EXCEEDED);
	sleep(1);
	
	exit (ERROR_RC);
}
Exemple #3
0
int menu_options(){

	struct pal_s *palp=0;
	int pal=0, skip=0, ret=0, cfilter=0, sfps=0, upscale=0, speed=0, i=0;
	char *tmp=0, *romdir=0;

	FILE *file;
#ifdef DINGOO_NATIVE
    /*
    **  100Mhz once caused Dingoo A320 MIPS to hang,
    **  when 100Mhz worked BW GB (Adjustris) game was running at 32 fps (versus 60 at 200Mhz).
    **  150Mhz has never worked on my Dingoo A320.
    */
    uintptr_t dingoo_clock_speeds[] = { 200000000, 250000000, 300000000, 336000000, 360000000, 400000000 /* , 430000000 Should not be needed */ };
    /*
    ** under-under clock option is for GB games.
    ** GB games can often be ran under the already
    ** underclocked Dingoo speed of 336Mhz
    */

    bool dingoo_clock_change_result;
	uintptr_t tempCore=336000000; /* default Dingoo A320 clock speed */
	uintptr_t tempMemory=112000000; /* default Dingoo A320 memory speed */
	cpu_clock_get(&tempCore, &tempMemory);
#endif /* DINGOO_NATIVE */

	pal = findpal();
	cfilter = rc_getint("colorfilter");
	if(cfilter && !rc_getint("filterdmg")) cfilter = 2;
	upscale = rc_getint("upscaler");
	skip = rc_getint("frameskip")+1;
	sfps = rc_getint("showfps");
#ifdef DINGOO_NATIVE
	speed = 0;
#else
	speed = rc_getint("cpuspeed")/50 - 4;
#endif /* DINGOO_NATIVE */
	if(speed<0) speed = 0;
	if(speed>11) speed = 11;

	romdir = rc_getstr("romdir");
	romdir = romdir ? strdup(romdir) : strdup(".");

	start:

	dialog_begin("Options",NULL);

	dialog_option("Mono Palette",lpalettes,&pal);               /* 1 */
	dialog_option("Color Filter",lcolorfilter,&cfilter);        /* 2 */
	dialog_option("Upscaler",lupscaler,&upscale);               /* 3 */
	dialog_option("Frameskip",lframeskip,&skip);                /* 4 */
	dialog_option("Show FPS",lsdl_showfps,&sfps);               /* 5 */
#if defined(WIZ) || defined(DINGOO_NATIVE)
	dialog_option("Clock Speed",lclockspeeds,&speed);           /* 6 */
#else
	dialog_text("Clock Speed","Default",0);                     /* 6 */
#endif
	dialog_text("Rom Path",romdir,FIELD_SELECTABLE);            /* 7 */
	#ifdef GNUBOY_HARDWARE_VOLUME
	dialog_option("Volume", volume_levels, &volume_hardware);   /* 8 */ /* this is not the OSD volume.. */
	#else
	dialog_text("Volume", "Default", 0);                        /* 8 */ /* this is not the OSD volume.. */
	#endif /* GNBOY_HARDWARE_VOLUME */
	dialog_text(NULL,NULL,0);                                   /* 9 */
	dialog_text("Apply",NULL,FIELD_SELECTABLE);                 /* 10 */
	dialog_text("Apply & Save",NULL,FIELD_SELECTABLE);          /* 11 */
	dialog_text("Cancel",NULL,FIELD_SELECTABLE);                /* 12 */

	switch(ret=dialog_end()){
		case 7: /* "Rom Path" romdir */
			tmp = menu_requestdir("Select Rom Directory",romdir);
			if(tmp){
				free(romdir);
				romdir = tmp;
			}
			goto start;
		case 12: /* Cancel */
			return ret;
			break;
		case 10: /* Apply */
		case 11: /* Apply & Save */
			#ifdef GNUBOY_HARDWARE_VOLUME
			pcm_volume(volume_hardware * 10);
			#endif /* GNBOY_HARDWARE_VOLUME */
			palp = &gbpal[pal];
			if(speed)
			{
#ifdef DINGOO_NATIVE
                /*
                ** For now do NOT plug in into settings system, current
                ** (Wiz) speed system is focused on multiples of 50Mhz.
                ** Dingoo default clock speed is 336Mhz (CPU certified for
                ** 360, 433MHz is supposed to be possible).
                ** Only set clock speed if changed in options each and
                ** everytime - do not use config file
                */
                --speed;
                /* check menu response is withing the preset array range/size */
                if (speed > (sizeof(dingoo_clock_speeds)/sizeof(uintptr_t) - 1) )
                    speed = 0;
                
                tempCore = dingoo_clock_speeds[speed];
                dingoo_clock_change_result = cpu_clock_set(tempCore);
                
                tempCore=tempMemory=0;
                cpu_clock_get(&tempCore, &tempMemory); /* currently unused */
                /* TODO display clock speed next to on screen FPS indicator */
#endif /* DINGOO_NATIVE */
    
				speed = speed*50 + 200;
			}
			sprintf(config[0],"set dmg_bgp 0x%.6x 0x%.6x 0x%.6x 0x%.6x", palp->dmg_bgp[0], palp->dmg_bgp[1], palp->dmg_bgp[2], palp->dmg_bgp[3]);
			sprintf(config[1],"set dmg_wndp 0x%.6x 0x%.6x 0x%.6x 0x%.6x",palp->dmg_wndp[0],palp->dmg_wndp[1],palp->dmg_wndp[2],palp->dmg_wndp[3]);
			sprintf(config[2],"set dmg_obp0 0x%.6x 0x%.6x 0x%.6x 0x%.6x",palp->dmg_obp0[0],palp->dmg_obp0[1],palp->dmg_obp0[2],palp->dmg_obp0[3]);
			sprintf(config[3],"set dmg_obp1 0x%.6x 0x%.6x 0x%.6x 0x%.6x",palp->dmg_obp1[0],palp->dmg_obp1[1],palp->dmg_obp1[2],palp->dmg_obp1[3]);
			sprintf(config[4],"set colorfilter %i",cfilter!=0);
			sprintf(config[5],"set filterdmg %i",cfilter==1);
			sprintf(config[6],"set upscaler %i",upscale);
			sprintf(config[7],"set frameskip %i",skip-1);
			sprintf(config[8],"set showfps %i",sfps);
			sprintf(config[9],"set cpuspeed %i",speed);
			#ifdef DINGOO_NATIVE /* FIXME Windows too..... if (DIRSEP_CHAR == '\\').... */
			{
				char tmp_path[PATH_MAX];
				char *dest, *src;
				dest = &tmp_path[0];
				src = romdir;
				
				/* escape the path seperator (should escape other things too.) */
				while(*dest = *src++)
				{
					if (*dest == DIRSEP_CHAR)
					{
						dest++;
						*dest = DIRSEP_CHAR;
					}
					dest++;
				}
			
				sprintf(config[10], "set romdir \"%s\"", tmp_path);
				scaler_init(0);
			}
			#else
			sprintf(config[10],"set romdir \"%s\"",romdir);
			scaler_init(0);
			#endif /* DINGOO_NATIVE */

			for(i=0; i<11; i++)
				rc_command(config[i]);

			pal_dirty();

			if (ret == 11){ /* Apply & Save */
				file = fopen("ohboy.rc","w");
				for(i=0; i<11; i++){
					fputs(config[i],file);
					fputs("\n",file);
				}
				fclose(file);
			}

		break;
	}

	free(romdir);

	return ret;
}
Exemple #4
0
int menu_state(int save){

	char **statebody=NULL;
	char* name;

	int i, flags,ret, del=0,l;
#ifndef OHBOY_FILE_STAT_NOT_AVAILABLE
	/* Not all platforms implement stat()/fstat() */
	struct stat fstat;
	time_t time;
	char *tstr;
#endif

	char *savedir;
	char *savename;
	char *saveprefix;
	FILE *f;
	int sizeof_slots=0;
    while (slots[sizeof_slots] != NULL)
        sizeof_slots++;
    statebody = malloc(sizeof_slots * sizeof(char*));  /* FIXME check for NULL return from malloc */

	savedir = rc_getstr("savedir");
	savename = rc_getstr("savename");
	saveprefix = malloc(strlen(savedir) + strlen(savename) + 2);
	sprintf(saveprefix, "%s%s%s", savedir, DIRSEP, savename);

	dialog_begin(save?"Save State":"Load State",rom.name);

	for(i=0; i<sizeof_slots; i++){

		name = malloc(strlen(saveprefix) + 5);
		sprintf(name, "%s.%03d", saveprefix, i);

#ifndef OHBOY_FILE_STAT_NOT_AVAILABLE
		/* if the file exists lookup the timestamp */
		if(!stat(name,&fstat)){
			time = fstat.st_mtime;
			tstr = ctime(&time);

			l = strlen(tstr);
			statebody[i] = malloc(l);
			strcpy(statebody[i],tstr);
			statebody[i][l-1]=0;
#else
		/* check if the file exists */
		if(f=fopen(name,"rb")){
			fclose(f);
			statebody[i] = (char*)not_emptyslot;
#endif /* OHBOY_FILE_STAT_NOT_AVAILABLE */
			flags = FIELD_SELECTABLE;
		} else {
			statebody[i] = (char*)emptyslot;
			flags = save ? FIELD_SELECTABLE : 0;
		}
		dialog_text(slots[i],statebody[i],flags);

		free(name);
	}

	if(ret=dialog_end()){
		name = malloc(strlen(saveprefix) + 5);
		sprintf(name, "%s.%03d", saveprefix, ret-1);
		if(save){
			if(f=fopen(name,"wb")){
				savestate(f);
				fclose(f);
			}
		}else{
			if(f=fopen(name,"rb")){
				loadstate(f);
				fclose(f);
				vram_dirty();
				pal_dirty();
				sound_dirty();
				mem_updatemap();
			}
		}
		free(name);
	}

	for(i=0; i<sizeof_slots; i++)
		if(statebody[i] != emptyslot && statebody[i] != not_emptyslot) free(statebody[i]);

	free(saveprefix);
	return ret;
}

#define GBPAL_COUNT 27
struct pal_s{
	char name[16];
	unsigned int dmg_bgp[4];
	unsigned int dmg_wndp[4];
	unsigned int dmg_obp0[4];
	unsigned int dmg_obp1[4];
}gbpal[GBPAL_COUNT] = {
	{
		.name = "Default",
		.dmg_bgp  = {0X98D0E0,0X68A0B0,0X60707C,0X2C3C3C},
		.dmg_wndp = {0X98D0E0,0X68A0B0,0X60707C,0X2C3C3C},
		.dmg_obp0 = {0X98D0E0,0X68A0B0,0X60707C,0X2C3C3C},
		.dmg_obp1 = {0X98D0E0,0X68A0B0,0X60707C,0X2C3C3C}
	},{//Grey Palette
		.name = "Grey",
		.dmg_bgp  = {  0xFFFFFF, 0xAAAAAA, 0x555555, 0x000000 }, //BG
		.dmg_wndp = {  0xFFFFFF, 0xAAAAAA, 0x555555, 0x000000 }, //WIN
		.dmg_obp0 = {  0xFFFFFF, 0xAAAAAA, 0x555555, 0x000000 }, //OB0
		.dmg_obp1 = {  0xFFFFFF, 0xAAAAAA, 0x555555, 0x000000 }  //OB1
	},{//Realistic Palette
		.name = "DMG",
Exemple #5
0
int menu(){

	char *dir;
	int mexit=0;
	static char *loadrom;
	int old_upscale = 0, new_upscale = 0;

	old_upscale = rc_getint("upscaler");
	gui_begin();
	while(!mexit){
		dialog_begin(rom.name,"ohBoy");

		dialog_text("Back to Game",NULL,FIELD_SELECTABLE);
		dialog_text("Load State",NULL,FIELD_SELECTABLE);
		dialog_text("Save State",NULL,FIELD_SELECTABLE);
		dialog_text("Reset Game",NULL,FIELD_SELECTABLE);
		dialog_text(NULL,NULL,0);
		dialog_text("Load ROM",NULL,FIELD_SELECTABLE);
		dialog_text("Options",NULL,FIELD_SELECTABLE);
		dialog_text("Controls",NULL,FIELD_SELECTABLE);
		dialog_text("About",NULL,FIELD_SELECTABLE);
		dialog_text("Quit","",FIELD_SELECTABLE);
		
#ifdef DINGOO_NATIVE
		dialog_text(NULL, NULL, 0); /* blank line */
		dialog_text("Menu:", NULL, 0);
		dialog_text(" Slide Power", NULL, 0);
#endif /* DINGOO_NATIVE */

		switch(dialog_end()){
			case 2:
				if(menu_state(0)) mexit=1;
				break;
			case 3:
				if(menu_state(1)) mexit=1;
				break;
			case 4:
				rc_command("reset");
				mexit=1;
				break;
			case 6:
				dir = rc_getstr("romdir");
				if(loadrom = menu_requestfile(NULL,"Select Rom",dir,"gb;gbc;zip")) {
					loader_unload();
					ohb_loadrom(loadrom);
					mexit=1;
				}
				break;
			case 7:
				if(menu_options()) mexit=1;
				break;
			case 8:
				if(menu_controls()) mexit=1;
				break;
			case 9:
				if(menu_about()) mexit=0;
				break;
			case 10:
				exit(0);
				break;
			default:
				mexit=1;
				break;
		}
	}
	new_upscale = rc_getint("upscaler");
	if (old_upscale != new_upscale)
		scaler_init(new_upscale);
	gui_end();

	return 0;
}