Esempio n. 1
0
static WIDGET* init_game_gui(void) {
    WIDGET *frame,*label,*glist,*button,*pix_frame;
    char *ld_label_str;
    frame=(WIDGET*)gui_frame_create(NULL,2,19,300,203,FRAME_SHADOW_ETCHED_IN,"Load game");

    /* Game list selection */
    glist=(WIDGET*)gui_slist_create(NULL,158,8,140,181);
    gui_container_add(GUI_CONTAINER(frame),glist);
    GUI_SLIST(glist)->sel_double_click=game_list_double_click;
    GUI_SLIST(glist)->sel_change=game_list_sel_change;
#ifdef __QNXNTO__
    GUI_SLIST(glist)->l=create_list_from_dir("shared/misc/gngeo/ROMS/");
    glist->pdata1=strdup("shared/misc/gngeo/ROMS/");
#else
    GUI_SLIST(glist)->l=create_list_from_dir(CF_STR(cf_get_item_by_name("rompath")));
    glist->pdata1=strdup(CF_STR(cf_get_item_by_name("rompath")));
#endif
    GUI_SLIST(glist)->get_label=get_glist_label;
    gui_slist_update(GUI_SLIST(glist));
    

    /* Loading progress bar */
    ld_pbar=(WIDGET*)gui_progressbar_create(NULL,107,191,191,10);
    gui_container_add(GUI_CONTAINER(frame),ld_pbar);
    
    ld_label=(WIDGET*)gui_label_create(NULL,20,193,1,1,"");
    gui_container_add(GUI_CONTAINER(frame),ld_label);

    /* some Check button */
    button=(WIDGET*)gui_check_button_create(NULL,4,179,150,10,"Show only NeoGeo's rom");
    GUI_CHECK_BUTTON(button)->toggle=game_list_show_rom_only_toggle;
    button->pdata1=glist;
    gui_container_add(GUI_CONTAINER(frame),button);
    gui_widget_add_keyfocus(desktop,button);
    /* We want glist after check button in the key focus list  */
    gui_widget_add_keyfocus(desktop,GUI_SLIST(glist)->text);

    /* Game information */
    pix_frame=(WIDGET*)gui_frame_create(NULL,2,8,154,114,FRAME_SHADOW_IN,NULL);
    gui_container_add(GUI_CONTAINER(frame),pix_frame);
    game_pix=(WIDGET*)gui_gpix_create(NULL,1,1,152,112);

    screenshots=NULL;
    gui_gpix_set_pixmap(GUI_GPIX(game_pix),screenshots);
    gui_container_add(GUI_CONTAINER(pix_frame),game_pix);
    
    info_label=(WIDGET*)gui_label_create(NULL,5,125,1,1,"");
    gui_container_add(GUI_CONTAINER(frame),info_label);

    return frame;
}
Esempio n. 2
0
static SDL_bool
load_glproc()
{
    static int init=0;
    CONF_ITEM *cf_libgl=cf_get_item_by_name("libglpath");
    if (init) return SDL_TRUE;
    init=1;
    if (SDL_GL_LoadLibrary(CF_STR(cf_libgl))==-1) {
        printf("Unable to load OpenGL library: %s\n", CF_STR(cf_libgl));
        return SDL_FALSE;
    }
	
    pglClearColor	= SDL_GL_GetProcAddress("glClearColor");
    pglClear		= SDL_GL_GetProcAddress("glClear");
    pglEnable		= SDL_GL_GetProcAddress("glEnable");
    pglViewport		= SDL_GL_GetProcAddress("glViewport");
    pglTexParameteri	= SDL_GL_GetProcAddress("glTexParameteri");
    pglPixelStorei	= SDL_GL_GetProcAddress("glPixelStorei");
    pglTexImage2D	= SDL_GL_GetProcAddress("glTexImage2D");
    pglBegin		= SDL_GL_GetProcAddress("glBegin");
    pglEnd		= SDL_GL_GetProcAddress("glEnd");
    pglTexCoord2f	= SDL_GL_GetProcAddress("glTexCoord2f");
    pglVertex2f		= SDL_GL_GetProcAddress("glVertex2f");
	
    return SDL_TRUE;
}
Esempio n. 3
0
void reset_frame_skip(void)
{
    static Uint8 init=0;
    if (!init) {
        autoframeskip=CF_BOOL(cf_get_item_by_name("autoframeskip"));
        show_fps=CF_BOOL(cf_get_item_by_name("showfps"));
        sleep_idle=CF_BOOL(cf_get_item_by_name("sleepidle"));
        init=1;
    }
    init_tv.tv_usec = 0;
    init_tv.tv_sec = 0;
    skip_next_frame = 0;
    init_frame_skip = 1;
    if (conf.pal)
        CPU_FPS=50;
    F = (uclock_t) ((double) TICKS_PER_SEC / CPU_FPS);
}
Esempio n. 4
0
char *cf_get_string_by_name(const char *name) 
{
CONF_ITEM *Item;

Item=cf_get_item_by_name(name);
if (! Item) return("");

if (Item->data.dt_str.str) return(Item->data.dt_str.str);
return("");
}
Esempio n. 5
0
void cf_set_string_by_name(const char *name, char *value) 
{
CONF_ITEM *Item;

Item=cf_get_item_by_name(name);
if (Item) 
{
Item->data.dt_str.str=rstrcpy(Item->data.dt_str.str, value, 1024);
}
}
Esempio n. 6
0
SDL_bool init_game(char *rom_name) {
    DRIVER *dr;
    char *drconf,*gpath;
    dr=dr_get_by_name(rom_name);
    if (!dr) {
#ifdef USE_GUI
	gui_error_box(20,80,264,60,
		      "Error!","No valid romset found for\n%s\n",
		      file_basename(rom_name));
#else
	printf("No valid romset found for %s\n",rom_name);
#endif
	return SDL_FALSE;
    }

    if (conf.game!=NULL) {
	save_nvram(conf.game);
	if (conf.sound) {
	    close_sdl_audio();
	    YM2610_sh_stop();
	    streams_sh_stop();
	}
	free_game_memory();
    }


    /* open transpack if need */
    trans_pack_open(CF_STR(cf_get_item_by_name("transpack")));

    //open_rom(rom_name);
    if (dr_load_game(dr,rom_name)==SDL_FALSE) {
#ifdef USE_GUI
	gui_error_box(20,80,264,60,
		      "Error!","Couldn't load\n%s\n",
		      file_basename(rom_name));
#else
	printf("Can't load %s\n",rom_name);
#endif
	return SDL_FALSE;
    }
    /* per game config */
    gpath=get_gngeo_dir();
    drconf=alloca(strlen(gpath)+strlen(dr->name)+strlen(".cf")+1);
    sprintf(drconf,"%s%s.cf",gpath,dr->name);
    cf_open_file(drconf);
    open_bios();
    open_nvram(conf.game);
    init_sdl();
    sdl_set_title(conf.game);
    init_neo(conf.game);
    if (conf.sound) 
	init_sdl_audio();
    return SDL_TRUE;
}
Esempio n. 7
0
void calculate_hotkey_bitmasks()
{
    int *p;
    int i, j, mask;
    const char *p1_key_list[] = { "p1hotkey0", "p1hotkey1", "p1hotkey2", "p1hotkey3" };
    const char *p2_key_list[] = { "p2hotkey0", "p2hotkey1", "p2hotkey2", "p2hotkey3" };


    for ( i = 0; i < 4; i++ ) {
	p=CF_ARRAY(cf_get_item_by_name(p1_key_list[i]));
	for ( mask = 0, j = 0; j < 4; j++ ) mask |= p[j];
	conf.p1_hotkey[i] = mask;
    }

    for ( i = 0; i < 4; i++ ) {
	p=CF_ARRAY(cf_get_item_by_name(p2_key_list[i]));
	for ( mask = 0, j = 0; j < 4; j++ ) mask |= p[j];
	conf.p2_hotkey[i] = mask;
    }

}
Esempio n. 8
0
char *get_zip_name(char *name) {
    char *zip;
    char *path = CF_STR(cf_get_item_by_name("rompath"));
    if (file_is_zip(name)) {
        zip=malloc(strlen(name)+1);
        strcpy(zip,name);
    } else {
        int len = strlen(path) + strlen(name) + 6;
        zip = malloc(len);
        sprintf(zip,"%s/%s.zip",path,name);
    }
    return zip;
}
Esempio n. 9
0
bool init_event(void) {
	int i;
    //	printf("sizeof joymap=%d nb_joy=%d\n",sizeof(JOYMAP),conf.nb_joy);
	jmap=calloc(sizeof(JOYMAP),1);
    
#ifdef WII
	conf.nb_joy = 4;
#else	
	conf.nb_joy = SDL_NumJoysticks();
#endif
	if( conf.nb_joy>0) {
		if (conf.joy!=NULL) free(conf.joy);
		conf.joy=calloc(sizeof(SDL_Joystick*),conf.nb_joy);
		
		SDL_JoystickEventState(SDL_ENABLE);
		
		jmap->jbutton=calloc(conf.nb_joy,sizeof(struct BUT_MAP*));
		jmap->jaxe=   calloc(conf.nb_joy,sizeof(struct BUT_MAPJAXIS*));
		jmap->jhat=   calloc(conf.nb_joy,sizeof(struct BUT_MAP*));
		
        
		/* Open all the available joystick */
		for (i=0;i<conf.nb_joy;i++) {
			conf.joy[i]=SDL_JoystickOpen(i);
            /*			printf("joy \"%s\", axe:%d, button:%d\n",
             SDL_JoystickName(i),
             SDL_JoystickNumAxes(conf.joy[i])+ (SDL_JoystickNumHats(conf.joy[i]) * 2),
             SDL_JoystickNumButtons(conf.joy[i]));*/
			jmap->jbutton[i]=calloc(SDL_JoystickNumButtons(conf.joy[i]),sizeof(struct BUT_MAP));
			jmap->jaxe[i]=calloc(SDL_JoystickNumAxes(conf.joy[i]),sizeof(struct BUT_MAPJAXIS));
			jmap->jhat[i]=calloc(SDL_JoystickNumHats(conf.joy[i]),sizeof(struct BUT_MAP));
		}
	}
	create_joymap_from_string(1,CF_STR(cf_get_item_by_name("p1control")));
	create_joymap_from_string(2,CF_STR(cf_get_item_by_name("p2control")));
	return true;
}
Esempio n. 10
0
SDL_bool main_gngeo_gui(void) {
    if (desktop==NULL)
	init_gngeo_gui();
    if (conf.sound) SDL_PauseAudio(1);

    /* disable interpolation */
    interpolation=SDL_FALSE;

    //SDL_ShowCursor(1);
    gui_main_loop(desktop/*,conf.res_x,conf.res_y*/);
    //SDL_ShowCursor(0);

    /* reinit interpolation */
    interpolation=CF_BOOL(cf_get_item_by_name("interpolation"));

    if (conf.sound) SDL_PauseAudio(0);
    reset_frame_skip();
//    printf("Quitemu=%d\n",quit_emu);
    return quit_emu;
}
Esempio n. 11
0
void init_neo(void) {
#ifdef ENABLE_940T
	int z80_overclk = CF_VAL(cf_get_item_by_name("z80clock"));
#endif

	//neogeo_init_save_state();

#ifdef GP2X
	gp2x_ram_ptr_reset();
#endif

	cpu_68k_init();
//	neogeo_reset();
	pd4990a_init();
//	setup_misc_patch(rom_name);

	init_sound();

	neogeo_reset();
}
Esempio n. 12
0
void init_sdl(void /*char *rom_name*/) {
    int surface_type = (CF_BOOL(cf_get_item_by_name("hwsurface"))? SDL_HWSURFACE : SDL_SWSURFACE);


    char *nomouse = getenv("SDL_NOMOUSE");
    SDL_Surface *icon;

    SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_NOPARACHUTE);

#ifdef GP2X
    atexit(gp2x_quit);
#else
    atexit(SDL_Quit);
#endif

    if (screen_init() == SDL_FALSE) {
	printf("Screen initialization failed.\n");
	exit(-1);
    }

    buffer = SDL_CreateRGBSurface(surface_type, 352, 256, 16, 0xF800, 0x7E0,
				  0x1F, 0);
    SDL_FillRect(buffer,NULL,SDL_MapRGB(buffer->format,0xE5,0xE5,0xE5));

    fontbuf = SDL_CreateRGBSurfaceFrom(font_image.pixel_data, font_image.width, font_image.height
				       , 24, font_image.width * 3, 0xFF0000, 0xFF00, 0xFF, 0);
    SDL_SetColorKey(fontbuf,SDL_SRCCOLORKEY,SDL_MapRGB(fontbuf->format,0xFF,0,0xFF));
    fontbuf=SDL_DisplayFormat(fontbuf);
    icon = SDL_CreateRGBSurfaceFrom(gngeo_icon.pixel_data, gngeo_icon.width,
				    gngeo_icon.height, gngeo_icon.bytes_per_pixel*8,
				    gngeo_icon.width * gngeo_icon.bytes_per_pixel,
				    0xFF, 0xFF00, 0xFF0000, 0);
    
    SDL_WM_SetIcon(icon,NULL);

    calculate_hotkey_bitmasks();    
	init_event();

    //if (nomouse == NULL)
	//SDL_ShowCursor(SDL_DISABLE);
}
Esempio n. 13
0
int frame_skip(int init)
{
    static int f2skip;
    static uclock_t sec = 0;
    static uclock_t rfd;
    static uclock_t target;
    static int nbFrame = 0;
    static unsigned int nbFrame_moy = 0;
    static int nbFrame_min = 1000;
    static int nbFrame_max = 0;
    static int skpFrm = 0;
    static int count = 0;
    static int moy=60;

    if (init_frame_skip) {
		init_frame_skip = 0;
		target = get_ticks();
		bench = (CF_BOOL(cf_get_item_by_name("bench")) ? 1/*get_ticks()*/ : 0);

		nbFrame = 0;
		//f2skip=0;
		//skpFrm=0;
		sec = 0;
		return 0;
    }

    target += F;
    if (f2skip > 0 ) {
	f2skip--;
	skpFrm++;
	return 1;
    } else
	skpFrm = 0;
//	printf("%d %d\n",conf.autoframeskip,conf.show_fps);

    rfd = get_ticks();

    if (gTurboMode) {
        target=get_ticks();
        f2skip=MAX_FRAMESKIP;
    } else {
    if (conf.autoframeskip) {
        if (rfd < target && f2skip == 0) {               
            while (get_ticks() < target) {
        #ifndef WIN32
                if (conf.sleep_idle) {
                    usleep(5);
                }
        #endif
            }
        } else {
                f2skip = (rfd - target) / (double) F;
	    if (f2skip > MAX_FRAMESKIP) {
		f2skip = MAX_FRAMESKIP;
		reset_frame_skip();
	    }
	    // printf("Skip %d frame(s) %lu %lu\n",f2skip,target,rfd);
        }
    }
    }
    nbFrame++;
    nbFrame_moy++;

    if (conf.show_fps) {
	    if (get_ticks() - sec >= TICKS_PER_SEC) {
		    //printf("%d\n",nbFrame);
		    if (bench) {

			    if (nbFrame_min>nbFrame) nbFrame_min=nbFrame;
			    if (nbFrame_max<nbFrame) nbFrame_max=nbFrame;
			    count++;
			    moy=nbFrame_moy/(float)count;

			    if (count==30) count=0;
			    sprintf(fps_str, "%d %d %d %d\n", nbFrame-1,nbFrame_min-1,nbFrame_max-1,moy-1);
		    } else {
			    sprintf(fps_str, "%2d", nbFrame-1);
		    }
	    
		    nbFrame = 0;
		    sec = get_ticks();
	    }
    }
    return 0;
}
Esempio n. 14
0
bool cf_open_file(char *filename) 
{
	/* if filename==NULL, we use the default one: $HOME/.gngeo/gngeorc */
	FILE *f;
	int i = 0;
	char *buf=NULL;
	char *name=NULL, *ptr;
	CONF_ITEM *cf;

	f = fopen(filename, "rb");
	if (! f)
	{
		printf("ERROR: Unable to open %s\n",filename);
		return false;
	}

	buf=calloc(8192,sizeof(char));
	while (!feof(f)) {
		i = 0;
		my_fgets(buf, 8190, f);
		if (discard_line(buf))
			continue;
	
		ptr=get_token(buf, " =", &name);

		cf = cf_get_item_by_name(name);
		if (cf && !(cf->flags & CF_SETBYCMD) && (!cf->modified)) {
			switch (cf->type) {
				case CFT_INT:
					CF_VAL(cf) = atoi(ptr);
					break;
				case CFT_BOOLEAN:
					CF_BOOL(cf) = (strcasecmp(ptr, "true") == 0 ? true : false);
					break;
				case CFT_STRING:
					printf("ST: %s\n",ptr);
					CF_STR(cf)=rstrcpy(CF_STR(cf), ptr, 8190);
					break;
				case CFT_ARRAY:
					read_array(CF_ARRAY(cf), ptr, CF_ARRAY_SIZE(cf));
					break;
				case CFT_ACTION:
				case CFT_ACTION_ARG:
					/* action are not available in the conf file */
					break;
				case CFT_STR_ARRAY:
					CF_STR_ARRAY(cf) = read_str_array(ptr, &CF_STR_ARRAY_SIZE(cf));
					break;
			}
		} else {
			/*printf("Unknow option %s\n",name);*/
			/* unknow option...*/
		}
	}

	if (name) free(name);
	if (buf) free(buf);

	cf_cache_conf();
	return true;
}
Esempio n. 15
0
bool cf_save_file(char *filename, int flags) {
	char *conf_file = NULL;
	char *conf_file_dst;
	FILE *f;
	FILE *f_dst;
	int i = 0, j, a;
	char buf[512];
	char *name=NULL, *ptr;
	CONF_ITEM *cf;

	if (! sstrlen(filename)) conf_file=cf_default_path(conf_file, "gngeorc", "");
	else conf_file=rstrcpy(conf_file, filename, 1024);

	conf_file_dst = alloca(strlen(conf_file) + 4);
	sprintf(conf_file_dst, "%s.t", conf_file);

	if ((f_dst = fopen(conf_file_dst, "w")) == 0) {
		//printf("Unable to open %s\n",conf_file);
		if (conf_file) free(conf_file);
		return false;
	}

	if ((f = fopen(conf_file, "rb"))) {

		//printf("Loading current .cf\n");

		while (!feof(f)) {
			i = 0;
			my_fgets(buf, 510, f);
			if (discard_line(buf)) {
				fprintf(f_dst, "%s\n", buf);
				continue;
			}

			//this is an odd approach, seeks to replace existing config
			//items in the order they exist in config file?
			ptr=get_token(buf, " ", &name);

			cf = cf_get_item_by_name(name);
			if (cf) {
				if (cf->modified) {
					cf->modified = 0;
					switch (cf->type) {
						case CFT_INT:
							fprintf(f_dst, "%s %d\n", cf->name, CF_VAL(cf));
							break;
						case CFT_BOOLEAN:
							if (CF_BOOL(cf))
								fprintf(f_dst, "%s true\n", cf->name);
							else
								fprintf(f_dst, "%s false\n", cf->name);
							break;
						case CFT_STRING:
							fprintf(f_dst, "%s %s\n", cf->name, CF_STR(cf));
							break;
						case CFT_ARRAY:
							fprintf(f_dst, "%s ", cf->name);
							for (a = 0; a < CF_ARRAY_SIZE(cf) - 1; a++)
								fprintf(f_dst, "%d,", CF_ARRAY(cf)[a]);
							fprintf(f_dst, "%d\n", CF_ARRAY(cf)[a]);
							break;
						case CFT_ACTION:
						case CFT_ACTION_ARG:
							break;
						case CFT_STR_ARRAY:
							printf("TODO: Save CFT_STR_ARRAY\n");
							break;
					}
				} else
					fprintf(f_dst, "%s\n", buf);
			}
		}
		fclose(f);

	}
	/* Now save options that were not in the previous file */
	for (i = 0; i < 128; i++) {
		for (j = 0; j < cf_hash[i].nb_item; j++) {
			cf = cf_hash[i].conf[j];
			//printf("Option %s %d\n",cf->name,cf->modified);
			if (cf->modified!=0) {
				cf->modified=0;
				switch (cf->type) {
					case CFT_INT:
						fprintf(f_dst, "%s %d\n", cf->name, CF_VAL(cf));
						break;
					case CFT_BOOLEAN:
						if (CF_BOOL(cf))
							fprintf(f_dst, "%s true\n", cf->name);
						else
							fprintf(f_dst, "%s false\n", cf->name);
						break;
					case CFT_STRING:
						fprintf(f_dst, "%s %s\n", cf->name, CF_STR(cf));
						break;
					case CFT_ARRAY:
						fprintf(f_dst, "%s ", cf->name);
						for (a = 0; a < CF_ARRAY_SIZE(cf) - 1; a++)
							fprintf(f_dst, "%d,", CF_ARRAY(cf)[a]);
						fprintf(f_dst, "%d\n", CF_ARRAY(cf)[a]);
						break;
					case CFT_ACTION:
					case CFT_ACTION_ARG:
						/* action are not available in the conf file */
						break;
					case CFT_STR_ARRAY:
						printf("TODO: Save CFT_STR_ARRAY\n");
						break;
				}
			}
		}
	}
	fclose(f_dst);

	remove(conf_file);
	rename(conf_file_dst, conf_file);

	if (name) free(name);
	if (conf_file) free(conf_file);

	return true;
}
Esempio n. 16
0
void cf_init(void) {

	cf_create_action_item("help", "Print this help and exit", 'h', print_help);
	cf_create_action_item("listgame", "Show all the game available in the romrc", 'l', show_all_game);
	cf_create_action_item("version", "Show version and exit", 'v', show_version);

	cf_create_bool_item("forcepc", "Force the PC to a correct value at startup", 0, GN_FALSE);
	cf_create_bool_item("dump", "Create a gno dump in the current dir and exit", 0, GN_FALSE);

	cf_create_bool_item("interpolation", "Merge the last frame and the current", 'I', GN_FALSE);
	cf_create_bool_item("raster", "Enable the raster interrupt", 'r', GN_FALSE);
	cf_create_bool_item("sound", "Enable sound", 0, GN_TRUE);
	cf_create_bool_item("showfps", "Show FPS at startup", 0, GN_FALSE);

	cf_create_bool_item("sleepidle", "Sleep when idle", 0, GN_FALSE);
	cf_create_bool_item("joystick", "Enable joystick support", 0, GN_TRUE);
	cf_create_bool_item("debug", "Start with inline debuger", 'D', GN_FALSE);
	cf_create_bool_item("hwsurface", "Use hardware surface for the screen", 'H', GN_TRUE);
#ifdef PANDORA
	cf_create_bool_item("vsync", "Synchronise the display with VBLANK", 0, GN_TRUE);
	cf_create_bool_item("autoframeskip", "Enable auto frameskip", 0, GN_FALSE);
	cf_create_bool_item("fullscreen", "Start gngeo in fullscreen", 'f', GN_TRUE);
	cf_create_bool_item("wide", "Use all the Pandora Screen", 0, GN_FALSE);
#else
	cf_create_bool_item("vsync", "Synchronise the display with VBLANK", 0, GN_FALSE);
	cf_create_bool_item("autoframeskip", "Enable auto frameskip", 0, GN_TRUE);
	cf_create_bool_item("fullscreen", "Start gngeo in fullscreen", 'f', GN_FALSE);
	
#endif
	cf_create_bool_item("pal", "Use PAL timing (buggy)", 'P', GN_FALSE);
	cf_create_bool_item("screen320", "Use 320x224 output screen (instead 304x224)", 0, GN_FALSE);
	cf_create_bool_item("bench", "Draw x frames, then quit and show average fps", 0, GN_FALSE);


	cf_create_string_item("country", "Set the contry to japan, asia, usa or europe", "...", 0, "europe");
	cf_create_string_item("system", "Set the system to home, arcade or unibios", "...", 0, "arcade");
#ifdef EMBEDDED_FS
	cf_create_string_item("rompath", "Tell gngeo where your roms are", "PATH", 'i', ROOTPATH"./roms");
	cf_create_string_item("biospath", "Tell gngeo where your neogeo bios is", "PATH", 'B', ROOTPATH"./roms");
	cf_create_string_item("datafile", "Tell gngeo where his ressource file is", "PATH", 'd', ROOTPATH"./gngeo_data.zip");
#else
	cf_create_string_item("rompath", "Tell gngeo where your roms are", "PATH", 'i', DATA_DIRECTORY);
	cf_create_string_item("biospath", "Tell gngeo where your neogeo bios is", "PATH", 'B', DATA_DIRECTORY);
	cf_create_string_item("datafile", "Tell gngeo where his ressource file is", "PATH", 'd', DATA_DIRECTORY"/gngeo_data.zip");
#endif
	//cf_create_string_item("romrcdir","Use STRING as romrc.d directory",0,DATA_DIRECTORY"/romrc.d");
	cf_create_string_item("libglpath", "Path to your libGL.so", "PATH", 0, "/usr/lib/libGL.so");
	cf_create_string_item("effect", "Use the specified effect (help for a list)", "Effect", 'e', "none");
	cf_create_string_item("blitter", "Use the specified blitter (help for a list)", "Blitter", 'b', "soft");
	cf_create_string_item("transpack", "Use the specified transparency pack", "Transpack", 't', "none");
	cf_create_string_item("p1control", "Player1 control configutation", "...", 0, default_p1control);
	cf_create_string_item("p2control", "Player2 control configutation", "...", 0, default_p2control);
/*
#if defined(GP2X) || defined(WIZ)
	cf_create_string_item("p1control", "Player1 control configutation", "...", 0,
			"UP=J0B0,DOWN=J0B4,LEFT=J0B2,RIGHT=J0B6,A=J0B14,B=J0B13,C=J0B12,D=J0B15,COIN=J0B9,START=J0B8,HOTKEY1=J0B10,HOTKEY2=J0B11");
	cf_create_string_item("p2control", "Player2 control configutation", "...", 0, "");
#elif defined(PANDORA)
	cf_create_string_item("p1control", "Player1 control configutation", "...", 0,
			"A=K281,B=K279,C=K278,D=K280,START=K308,COIN=K306,UP=K273,DOWN=K274,LEFT=K276,RIGHT=K275,MENU=K113");
	cf_create_string_item("p2control", "Player2 control configutation", "...", 0, "");
#elif defined (DINGUX)
	cf_create_string_item("p1control", "Player1 control configutation", "...", 0,
			"A=K308,B=K306,C=K304,D=K32,START=K13,COIN=K9,UP=K273,DOWN=K274,LEFT=K276,RIGHT=K275,MENU=K113");
	cf_create_string_item("p2control", "Player2 control configutation", "...", 0, "");
#else
	
	cf_create_string_item("p1control", "Player1 control configutation", "...", 0,
			"A=K119,B=K120,C=K113,D=K115,START=K38,COIN=K34,UP=K273,DOWN=K274,LEFT=K276,RIGHT=K275,MENU=K27");
	cf_create_string_item("p2control", "Player2 control configutation", "...", 0, "");
#endif
*/

	cf_create_array_item("p1hotkey0", "Player1 Hotkey 0 configuration", "...", 0, 4, default_p1hotkey0);
	cf_create_array_item("p1hotkey1", "Player1 Hotkey 1 configuration", "...", 0, 4, default_p1hotkey1);
	cf_create_array_item("p1hotkey2", "Player1 Hotkey 2 configuration", "...", 0, 4, default_p1hotkey2);
	cf_create_array_item("p1hotkey3", "Player1 Hotkey 3 configuration", "...", 0, 4, default_p1hotkey3);
	cf_create_array_item("p2hotkey0", "Player2 Hotkey 0 configuration", "...", 0, 4, default_p2hotkey0);
	cf_create_array_item("p2hotkey1", "Player2 Hotkey 1 configuration", "...", 0, 4, default_p2hotkey1);
	cf_create_array_item("p2hotkey2", "Player2 Hotkey 2 configuration", "...", 0, 4, default_p2hotkey2);
	cf_create_array_item("p2hotkey3", "Player2 Hotkey 3 configuration", "...", 0, 4, default_p2hotkey3);



	cf_create_int_item("scale", "Scale the resolution by X", "X", 0, 1);
	cf_create_int_item("samplerate", "Set the sample rate to RATE", "RATE", 0, 22050);
	cf_create_int_item("68kclock", "Overclock the 68k by x% (-x% for underclk)", "x", 0, 0);
	cf_create_int_item("z80clock", "Overclock the Z80 by x% (-x% for underclk)", "x", 0, 0);


#ifdef GP2X
	cf_create_bool_item("ramhack", "Enable CraigX's RAM timing hack", 0, GN_FALSE);
	cf_create_bool_item("tvout", "Enable Tvout (NTSC)", 0, GN_FALSE);
	cf_create_array_item("tv_offset", "Shift TV screen by x,y pixel", "x,y", 0, 2, default_tvoffset);
	cf_create_bool_item("940sync", "Accurate synchronisation between the both core", 0, GN_TRUE);
	cf_create_int_item("cpu_speed", "Overclock the GP2X cpu to x Mhz", "x", 0, 0);
	cf_create_string_item("frontend", "Execute CMD when exit. Usefull to return to Selector or Rage2x", "CMD", 0, "/usr/gp2x/gp2xmenu");
#endif
	//CF_SYSTEMOPT
	cf_get_item_by_name("rompath")->flags|=CF_SYSTEMOPT;
	cf_get_item_by_name("libglpath")->flags|=CF_SYSTEMOPT;
	cf_get_item_by_name("datafile")->flags|=CF_SYSTEMOPT;
}
Esempio n. 17
0
void main_loop(void)
{
    int neo_emu_done = 0;
    int overclk=CF_VAL(cf_get_item_by_name("overclock"));

    Uint32 cpu_68k_timeslice = (overclk==0?200000:200000+(overclk*200000/100.0));
    Uint32 cpu_68k_timeslice_scanline = cpu_68k_timeslice/262.0;
//    Uint32 cpu_z80_timeslice = 100000;
    Uint32 cpu_z80_timeslice = 73333;
    Uint32 tm_cycle=0;

    /*    Uint32 cpu_z80_timeslice=66666; // is it 4Mhz or 6Mhz ???? 4 seems to work fine....
       UPDATE: it's clear now that it's 6Mhz -> kof96 presentation */

    Uint32 cpu_z80_timeslice_interlace = cpu_z80_timeslice / (float) nb_interlace;
    char ksym_code[5];
    SDL_Event event;
    Uint16 scancode, i, a;
    char input_buf[20];
    Uint8 show_keysym=0;
    CONF_ITEM* item = cf_get_item_by_name("invertjoy");
    int invert_joy = 0;
    if (item)
    	invert_joy=CF_BOOL(item);

    reset_frame_skip();
    my_timer();
    //printf("Cpuspeed: %d\n",cpu_68k_timeslice);
/*
    printf("%s\n",&memory.cpu[0x100]);
    printf("NGH = %04x\n",READ_WORD(&memory.cpu[0x108]));
    printf("SSN = %04x\n",READ_WORD(&memory.cpu[0x114]));
*/

    while (!neo_emu_done) {
	if (conf.test_switch == 1)
	    conf.test_switch = 0;


	while (SDL_PollEvent(&event)) {
	    switch (event.type) {
	    case SDL_JOYAXISMOTION:
		joy_axe[event.jaxis.which][event.jaxis.axis] = event.jaxis.value;
		if (show_keysym) {
		    sprintf(ksym_code, "%d", event.jaxis.axis);
		    draw_message(ksym_code);
		}
		break;

	    case SDL_JOYHATMOTION:
		    switch (event.jhat.value) {
		    case SDL_HAT_CENTERED:
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which]] = 0;
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which] + 1] = 0;
			    break;
			    
		    case SDL_HAT_UP:
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which] + 1] = -32767;
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which]] = 0;
			    break;
			    
		    case SDL_HAT_DOWN:
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which] + 1] = 32767;
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which]] = 0;
			    break;
			    
		    case SDL_HAT_LEFT:
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which]] = -32767;
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which] + 1] = 0;
			    break;
			    
		    case SDL_HAT_RIGHT:
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which]] = 32767;
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which] + 1] = 0;
			    break;
			    
		    case SDL_HAT_RIGHTUP:
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which]] = 32767;
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which] + 1] = -32767;
			    break;
			    
		    case SDL_HAT_RIGHTDOWN:
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which]] = 32767;
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which] + 1] = 32767;
			    break;
			    
		    case SDL_HAT_LEFTUP:
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which]] = -32767;
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which] + 1] = -32767;
			    break;
			    
		    case SDL_HAT_LEFTDOWN:
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which]] = -32767;
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which] + 1] = 32767;
			    break;
			    
		    }
		    
		    if (show_keysym) {
			    sprintf(ksym_code, "%d", event.jhat.hat);
			    draw_message(ksym_code);
		    }
		    break;


	    case SDL_JOYBUTTONDOWN:
		joy_button[event.jbutton.which][event.jbutton.button] = 1;
		
		if (show_keysym) {
		    sprintf(ksym_code, "%d", event.jbutton.button);
		    draw_message(ksym_code);
		}
		break;
	    case SDL_JOYBUTTONUP:
		joy_button[event.jbutton.which][event.jbutton.button] = 0;
		break;

	    case SDL_KEYUP:
		if (player)
		{
			switch(event.key.keysym.sym)
			{
			case 273:
				key[264] = 0;
				break;
			case 275:
				key[274] = 0;
				break;
			case 274:
				key[261] = 0;
				break;
			case 276:
				key[260] = 0;
				break;
			case 122:
				key[108] = 0;
				break;
			case 120:
				key[59] = 0;
				break;
			case 97:
				key[111] = 0;
				break;
			case 115:
				key[112] = 0;
				break;
			case 49:
				key[50] = 0;
				break;
			case 51:
				key[52] = 0;
				break;
			default:
				key[event.key.keysym.sym] = 0;
				break;
			}
		}
		else
			key[event.key.keysym.sym] = 0;
		break;
	    case SDL_KEYDOWN:
		scancode = event.key.keysym.sym;
		if (show_keysym) {
		    sprintf(ksym_code, "%d", scancode);
		    draw_message(ksym_code);
		}
		if (player)
		{
			switch(scancode)
			{
			case 273:
				key[264] = 1;
				break;
			case 275:
				key[274] = 1;
				break;
			case 274:
				key[261] = 1;
				break;
			case 276:
				key[260] = 1;
				break;
			case 122:
				key[108] = 1;
				break;
			case 120:
				key[59] = 1;
				break;
			case 97:
				key[111] = 1;
				break;
			case 115:
				key[112] = 1;
				break;
			case 49:
				key[50] = 1;
				break;
			case 51:
				key[52] = 1;
				break;
			default:
				key[scancode] = 1;
				break;
			}
		}
		else
			key[scancode] = 1;

		switch (scancode) {
		case SDLK_ESCAPE:
		    neo_emu_done = 1;
#ifdef __QNXNTO__
		    shutdown = 1;
#endif
		    break;	// ESC
/*
		case SDLK_TAB:
		    main_gngeo_gui();
		    break;
*/
		case SDLK_F1:
		    draw_message("Reset");
		    //neogeo_init();
		    cpu_68k_reset();
		    break;
		case SDLK_F2:
		    take_screenshot();
		    draw_message("Screenshot saved");
		    break;
		case SDLK_F3:
		    draw_message("Test Switch ON");
		    conf.test_switch = 1;
		    break;
		case SDLK_F5:
		    show_fps ^= SDL_TRUE;
		    break;
		case SDLK_F4:
		    show_keysym = 1 - show_keysym;
		    if (show_keysym)
			draw_message("Show keysym code : ON");
		    else
			draw_message("Show keysym code : OFF");
		    break;
		case SDLK_F6:
		    slow_motion = 1 - slow_motion;
		    if (slow_motion)
			draw_message("SlowMotion : ON");
		    else {
			draw_message("SlowMotion : OFF");
			reset_frame_skip();
		    }
		    break;
		case SDLK_F7:
		    //screen_set_effect("scanline");
		    if (conf.debug) {
			dbg_step = 1;
		    }
		    break;
		case SDLK_F8: 
		{
		    int val;
		    char *endptr;
		    text_input("Save to slot [0-999]? ",16,227,input_buf,3);
		    val=strtol(input_buf,&endptr,10);
		    if (input_buf != endptr) {
			pending_save_state=val+1;
		    }
		}
		break;
		case SDLK_F9:
		{
		    int val;
		    char *endptr;
		    text_input("Load from slot [0-999]? ",16,227,input_buf,3);
		    val=strtol(input_buf,&endptr,10);
		    if (input_buf != endptr) {
			pending_load_state=val+1;
		    }
		}
		break; 
		case SDLK_F10:
		    autoframeskip ^= SDL_TRUE;
		    if (autoframeskip) {
			reset_frame_skip();
			draw_message("AutoFrameSkip : ON");
		    } else
			draw_message("AutoFrameSkip : OFF");
		    break;
		case SDLK_F11:
		    sleep_idle ^= SDL_TRUE;
		    if (sleep_idle)
			draw_message("Sleep idle : ON");
		    else
			draw_message("Sleep idle : OFF");
		    break;
		case SDLK_F12:
		    screen_fullscreen();
		    break;
#ifdef __QNXNTO__
		case SDLK_F13:
			neo_emu_done = 1;
			break;
		case SDLK_F14:
			if (player)
			{
				key[52] = 0;
				key[50] = 0;
				key[112] = 0;
				key[111] = 0;
				key[59] = 0;
				key[108] = 0;
				key[260] = 0;
				key[261] = 0;
				key[274] = 0;
				key[264] = 0;
			}
			player = !player;
			break;
#endif
		}
		break;
	    case SDL_VIDEORESIZE:
		conf.res_x=event.resize.w;
		conf.res_y=event.resize.h;
		screen_resize(event.resize.w, event.resize.h);
		break;
		case SDL_ACTIVEEVENT:
			if (event.active.state & SDL_APPINPUTFOCUS)
			{
				if (!event.active.gain)
				{
					int J;
					SDL_PauseAudio(1);
					while (1)
					{
						usleep(10000);
						if (SDL_PollEvent(&event))
						{
							if (event.type == SDL_ACTIVEEVENT)
							{
								if (event.active.state & SDL_APPINPUTFOCUS)
								{
									if (event.active.gain)
										break;
								}
							}
							else if (event.type == SDL_QUIT)
							{
								neo_emu_done = 1;
								break;
							}
						}
					}
					SDL_PauseAudio(0);
				    reset_frame_skip();
				}
			}
			break;
		case SDL_USEREVENT:
			reset_frame_skip();
			break;
	    case SDL_QUIT:
		neo_emu_done = 1;
#ifdef __QNXNTO__
		shutdown = 1;
#endif
		break;
	    default:
		break;
	    }
	}

	/* update the internal representation of keyslot */
	update_p1_key();
	update_p2_key();
	update_start();
	update_coin();

	if (slow_motion)
	    SDL_Delay(100);

	if (conf.sound) {
	    PROFILER_START(PROF_Z80);
	    for (i = 0; i < nb_interlace; i++) {
		cpu_z80_run(cpu_z80_timeslice_interlace);
		my_timer();
	    }
	    PROFILER_STOP(PROF_Z80);
	} /*
	    else
	    my_timer();*/

	if (!conf.debug) {
	    if (conf.raster) {
		for (i = 0; i < 261; i++) {
		    tm_cycle=cpu_68k_run(cpu_68k_timeslice_scanline-tm_cycle);
		    if (update_scanline())
			cpu_68k_interrupt(2);
		}
		tm_cycle=cpu_68k_run(cpu_68k_timeslice_scanline-tm_cycle);
		state_handling(pending_save_state,pending_load_state);
		
		update_screen();
		cpu_68k_interrupt(1);
	    } else {
		PROFILER_START(PROF_68K);
		tm_cycle=cpu_68k_run(cpu_68k_timeslice-tm_cycle);
		PROFILER_STOP(PROF_68K);
		a = neo_interrupt();
		
		/* state handling (we save/load before interrupt) */
		state_handling(pending_save_state,pending_load_state);
		
		if (a) {
		    cpu_68k_interrupt(a);
		}
	    }
	} else {
	    /* we arre in debug mode -> we are just here for event handling */
	    neo_emu_done=1;
	}
#ifdef ENABLE_PROFILER
	profiler_show_stat();
#endif
	PROFILER_START(PROF_ALL);
    }
}
Esempio n. 18
0
void cf_cache_conf(void) {
	char *country;
	char *system;
	/* cache some frequently used conf item */
	//	printf("Update Conf Cache, sample rate=%d -> %d\n",conf.sample_rate,CF_VAL(cf_get_item_by_name("samplerate")));
	conf.sound = CF_BOOL(cf_get_item_by_name("sound"));
	conf.vsync = CF_BOOL(cf_get_item_by_name("vsync"));
	conf.sample_rate = CF_VAL(cf_get_item_by_name("samplerate"));
	conf.debug = CF_BOOL(cf_get_item_by_name("debug"));
	conf.raster = CF_BOOL(cf_get_item_by_name("raster"));
	conf.pal = CF_BOOL(cf_get_item_by_name("pal"));

	conf.autoframeskip = CF_BOOL(cf_get_item_by_name("autoframeskip"));
	conf.show_fps = CF_BOOL(cf_get_item_by_name("showfps"));
	conf.sleep_idle = CF_BOOL(cf_get_item_by_name("sleepidle"));
	conf.screen320 = CF_BOOL(cf_get_item_by_name("screen320"));
#ifdef GP2X
	conf.accurate940 = CF_BOOL(cf_get_item_by_name("940sync"));
#endif
	country = cf_get_string_by_name("country");
	system = cf_get_string_by_name("system");
	if (!strcmp(system, "unibios")) {
		conf.system = SYS_UNIBIOS;
	} else {
		if (!strcmp(system, "home")) {
			conf.system = SYS_HOME;
		} else {
			conf.system = SYS_ARCADE;
		}
	}
	if (!strcmp(country, "japan")) {
		conf.country = CTY_JAPAN;
	} else if (!strcmp(country, "usa")) {
		conf.country = CTY_USA;
	} else if (!strcmp(country, "asia")) {
		conf.country = CTY_ASIA;
	} else {
		conf.country = CTY_EUROPE;
	}
}
Esempio n. 19
0
int main(int argc, char *argv[])
{
    char *rom_name;



#ifdef __AMIGA__
    BPTR file_lock = GetProgramDir();
    SetProgramDir(file_lock);
#endif
	signal(SIGSEGV, catch_me);

#ifdef WII
	//   SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_NOPARACHUTE);

	fatInitDefault();
#endif

    cf_init(); /* must be the first thing to do */
    cf_init_cmd_line();
    cf_open_file(NULL); /* Open Default configuration file */

    rom_name=cf_parse_cmd_line(argc,argv);

    /* print effect/blitter list if asked by user */
    if (!strcmp(CF_STR(cf_get_item_by_name("effect")),"help")) {
	print_effect_list();
	exit(0);
    }
    if (!strcmp(CF_STR(cf_get_item_by_name("blitter")),"help")) {
	print_blitter_list();
	exit(0);
    }

	init_sdl();

/* GP2X stuff */
#ifdef GP2X
    gp2x_init();
#endif
    if (gn_init_skin()!=SDL_TRUE) {
	    printf("Can't load skin...\n");
            exit(1);
    }    

	reset_frame_skip();

    if (conf.debug) conf.sound=0;

/* Launch the specified game, or the rom browser if no game was specified*/
	if (!rom_name) {
	//	rom_browser_menu();
		run_menu();
		printf("GAME %s\n",conf.game);
		if (conf.game==NULL) return 0;
	} else {

		if (init_game(rom_name)!=SDL_TRUE) {
			printf("Can't init %s...\n",rom_name);
            exit(1);
		}    
	}

	/* If asked, do a .gno dump and exit*/
    if (CF_BOOL(cf_get_item_by_name("dump"))) {
        char dump[8+4+1];
        sprintf(dump,"%s.gno",rom_name);
        dr_save_gno(&memory.rom,dump);
        close_game();
        return 0;
    }

    if (conf.debug)
	    debug_loop();
    else
	    main_loop();

    close_game();

    return 0;
}
Esempio n. 20
0
SDL_bool dr_load_game(DRIVER *dr,char *name) {
    unzFile *gz;
    int i;
    LIST *l;
    char *zip=get_zip_name(name);
    gz = unzOpen(zip);
    free(zip);
    if (gz==NULL) {
	return SDL_FALSE;
    }
    if (dr->special_bios) {
	memory.bios=malloc(dr->bios.size);
	memory.bios_size=dr->bios.size;
	if (!dr_load_section(gz,dr->bios,memory.bios)) return SDL_FALSE;
    }
    for (i=0;i<SEC_MAX;i++) {
	int s=dr->section[i].size;
	Uint8 *current_buf=NULL;
	//if (dr->section[i].item==NULL) continue;
	if (s==0) continue;
	//      printf("%p %d \n",dr->section[i].item,i);
	switch (i) {
	case SEC_CPU:
	    memory.cpu = malloc(s);
	    current_buf = memory.cpu;
	    memory.cpu_size = s;
	    break;
	case SEC_SFIX:
	    memory.sfix_game = malloc(s);
	    memory.fix_game_usage = malloc(s >> 5);
	    current_buf = memory.sfix_game;
	    memory.sfix_size = s;
	    break;
	case SEC_SM1:
	    memory.sm1 = malloc(s);
	    current_buf = memory.sm1;
	    memory.sm1_size = s;
	    break;
	case SEC_SOUND1:
	    memory.sound1 = malloc(s);
	    memory.sound1_size = s;
	    current_buf = memory.sound1;
	    break;
	case SEC_SOUND2:
	    memory.sound2 = malloc(s);
	    memory.sound2_size = s;
	    current_buf = memory.sound2;
	    break;
	case SEC_GFX:
	    memory.gfx = malloc(s);
	    //printf("Alloc %x for GFX: %p\n",s,memory.gfx);
	    memory.gfx_size = s;
	    current_buf = memory.gfx;
	    memory.pen_usage = malloc((s >> 7) * sizeof(int));
	    memset(memory.pen_usage, 0, (s >> 7) * sizeof(int));
	    memory.nb_of_tiles = s >> 7;
	    break;
	    /* TODO: Crypted rom */
	default:
	    break;
	}
	if (!dr_load_section(gz,dr->section[i],current_buf)) return SDL_FALSE;
    }
    unzClose(gz);

    /* TODO: Use directly the driver value insteed of recopying them */
    conf.game=dr->name;
    conf.rom_type=dr->rom_type;
    conf.special_bios=dr->special_bios;
    conf.extra_xor=dr->xor;
    set_bankswitchers(dr->banksw_type);
    for(i=0;i<6;i++)
	memory.bksw_unscramble[i]=dr->banksw_unscramble[i];
    for(i=0;i<64;i++)
	memory.bksw_offset[i]=dr->banksw_off[i];


    if (conf.rom_type == MGD2) {
	create_progress_bar("Convert MGD2");
	convert_mgd2_tiles(memory.gfx, memory.gfx_size);
	convert_mgd2_tiles(memory.gfx, memory.gfx_size);
	terminate_progress_bar();
    }
    if (conf.rom_type == MVS_CMC42) {
	create_progress_bar("Decrypt GFX ");
	kof99_neogeo_gfx_decrypt(conf.extra_xor);
	terminate_progress_bar();
    }
    if (conf.rom_type == MVS_CMC50) {
	create_progress_bar("Decrypt GFX ");
	kof2000_neogeo_gfx_decrypt(conf.extra_xor);
	terminate_progress_bar();
    }

    convert_all_char(memory.sfix_game, memory.sfix_size,
		     memory.fix_game_usage);


    if (CF_BOOL(cf_get_item_by_name("convtile"))) {
	create_progress_bar("Convert tile");
	for (i = 0; i < memory.nb_of_tiles; i++) {
	    convert_tile(i);
	    if (i%100==0) update_progress_bar(i,memory.nb_of_tiles);
	}
	terminate_progress_bar();
    }

    if (memory.sound2 == NULL) {
	memory.sound2 = memory.sound1;
	memory.sound2_size = memory.sound1_size;
    }
    //backup neogeo game vectors
    memcpy(memory.game_vector,memory.cpu,0x80);
    printf("                                                                             \r");

    return SDL_TRUE;
}
Esempio n. 21
0
File: emu.c Progetto: gillotte/gxgeo
void setup_misc_patch(char *name)
{
    sram_protection_hack = -1;
    if (!strcmp(name,"fatfury3") ||
            !strcmp(name,"samsho3") ||
            !strcmp(name,"samsho3a") ||
            !strcmp(name,"samsho4") ||
            !strcmp(name,"aof3") ||
            !strcmp(name,"rbff1") ||
            !strcmp(name,"rbffspec") ||
            !strcmp(name,"kof95") ||
            !strcmp(name,"kof96") ||
            !strcmp(name,"kof96h") ||
            !strcmp(name,"kof97") ||
            !strcmp(name,"kof97a") ||
            !strcmp(name,"kof97pls") ||
            !strcmp(name,"kof98") ||
            !strcmp(name,"kof98k") ||
            !strcmp(name,"kof98n") ||
            !strcmp(name,"kof99") ||
            !strcmp(name,"kof99a") ||
            !strcmp(name,"kof99e") ||
            !strcmp(name,"kof99n") ||
            !strcmp(name,"kof99p") ||
            !strcmp(name,"kof2000") ||
            !strcmp(name,"kof2000n") ||
            !strcmp(name,"kizuna") ||
            !strcmp(name,"lastblad") ||
            !strcmp(name,"lastblda") ||
            !strcmp(name,"lastbld2") ||
            !strcmp(name,"rbff2") ||
            !strcmp(name,"rbff2a") ||
            !strcmp(name,"mslug2") ||
            !strcmp(name,"mslug3") ||
            !strcmp(name,"garou") ||
            !strcmp(name,"garouo") ||
            !strcmp(name,"garoup"))
        sram_protection_hack = 0x100;



    if (!strcmp(name, "pulstar"))
        sram_protection_hack = 0x35a;


    if (!strcmp(name, "ssideki")) {
        WRITE_WORD_ROM(&memory.cpu[0x2240], 0x4e71);
    }


    if (!strcmp(name, "fatfury3")) {
        WRITE_WORD_ROM(memory.cpu, 0x0010);
    }


    /* Many mgd2 dump have a strange initial PC, so as some MVS */
    if ((!strcmp(name, "aodk")) ||
            (!strcmp(name, "bjourney")) ||
            (!strcmp(name, "maglord")) ||
            (!strcmp(name, "mosyougi")) ||
            (!strcmp(name, "twinspri")) ||
            (!strcmp(name, "whp")) ||
            (conf.rom_type == MGD2) ||
            (CF_BOOL(cf_get_item_by_name("forcepc"))) ) {
        Uint8 *RAM = memory.cpu;
        WRITE_WORD_ROM(&RAM[4], 0x00c0);
        WRITE_WORD_ROM(&RAM[6], 0x0402);
    }

    if (!strcmp(name, "mslugx")) {
        /* patch out protection checks */
        int i;
        Uint8 *RAM = memory.cpu;
        for (i = 0; i < memory.cpu_size; i += 2) {
            if ((READ_WORD_ROM(&RAM[i + 0]) == 0x0243) &&
                    (READ_WORD_ROM(&RAM[i + 2]) == 0x0001) &&  /* andi.w  #$1, D3 */
                    (READ_WORD_ROM(&RAM[i + 4]) == 0x6600)) {  /* bne xxxx */

                WRITE_WORD_ROM(&RAM[i + 4], 0x4e71);
                WRITE_WORD_ROM(&RAM[i + 6], 0x4e71);
            }
        }

        WRITE_WORD_ROM(&RAM[0x3bdc], 0x4e71);
        WRITE_WORD_ROM(&RAM[0x3bde], 0x4e71);
        WRITE_WORD_ROM(&RAM[0x3be0], 0x4e71);
        WRITE_WORD_ROM(&RAM[0x3c0c], 0x4e71);
        WRITE_WORD_ROM(&RAM[0x3c0e], 0x4e71);
        WRITE_WORD_ROM(&RAM[0x3c10], 0x4e71);

        WRITE_WORD_ROM(&RAM[0x3c36], 0x4e71);
        WRITE_WORD_ROM(&RAM[0x3c38], 0x4e71);
    }


}
Esempio n. 22
0
File: emu.c Progetto: gillotte/gxgeo
void main_loop(void)
{
    int neo_emu_done = 0;
    int m68k_overclk=CF_VAL(cf_get_item_by_name("68kclock"));
    int z80_overclk=CF_VAL(cf_get_item_by_name("z80clock"));
    int nb_frames=0;

    Uint32 cpu_68k_timeslice = (m68k_overclk==0?200000:200000+(m68k_overclk*200000/100.0));
    Uint32 cpu_68k_timeslice_scanline = cpu_68k_timeslice/262.0;
    Uint32 cpu_z80_timeslice = (z80_overclk==0?73333:73333+(z80_overclk*73333/100.0));
    Uint32 tm_cycle=0;

    Uint32 cpu_z80_timeslice_interlace = cpu_z80_timeslice / (float) nb_interlace;
    char ksym_code[5];
    Uint16 scancode, i, a;
    char input_buf[20];
    Uint8 show_keysym=0;
    int invert_joy=CF_BOOL(cf_get_item_by_name("invertjoy"));
    int x, y;
    for (x = 0; x < 2; x++) {
        for (y = 0; y < BUTTON_MAX; y++) {
            joy_button[x][y] = 0;
        }
    }

    reset_frame_skip();
    my_timer();
    /*
      printf("\tCpuspeed: %d\n",cpu_68k_timeslice);
      printf("\t%s\n",&memory.cpu[0x100]);
      printf("\tNGH = %04x\n",READ_WORD(&memory.cpu[0x108]));
      printf("\tSSN = %04x\n",READ_WORD(&memory.cpu[0x114]));
    */
    int loop_count = 0;
    while (!neo_emu_done) {
        if (conf.test_switch == 1) conf.test_switch = 0;

        neo_emu_done = read_input(joy_button, 0);

        // update the internal representation of keyslot
        update_p1_key();
        update_p2_key();
        update_start();
        update_coin();

        if (slow_motion) usleep(100);
        if (conf.sound) {
            /* run z80 */
            for (i = 0; i < nb_interlace; i++) {
                cpu_z80_run(cpu_z80_timeslice_interlace);
                my_timer();
            }
        }
        if (!conf.debug) {
            /* run m68k */
            if (conf.raster) {
                for (i = 0; i < 261; i++) {
                    tm_cycle=cpu_68k_run(cpu_68k_timeslice_scanline-tm_cycle);
                    if (update_scanline()) {
                        cpu_68k_interrupt(2);
                    }
                }
                tm_cycle=cpu_68k_run(cpu_68k_timeslice_scanline-tm_cycle);
                state_handling(pending_save_state,pending_load_state);

                update_screen();
                cpu_68k_interrupt(1);
            } else {
                tm_cycle=cpu_68k_run(cpu_68k_timeslice-tm_cycle);
                a = neo_interrupt();

                /* state handling (we save/load before interrupt) */
                state_handling(pending_save_state,pending_load_state);
                if (a) cpu_68k_interrupt(a);
            }
            ogc_update_stream();
        } else {
            /* we are in debug mode -> we are just here for event handling */
            neo_emu_done=1;
        }
    }
    ogc_close_audio();
}
Esempio n. 23
0
void open_bios(void)
{
    FILE *f;
    char *romfile;
    char *path = CF_STR(cf_get_item_by_name("rompath"));//conf.rom_path;
    int len = strlen(path) + 15;

    if (conf.game!=NULL) free_bios_memory();

    /* allocation de la ram */
    memory.ram = (Uint8 *) malloc(0x10000);
    memset(memory.ram,0,0x10000);
    memory.sfix_board = (Uint8 *) malloc(0x20000);
    memory.ng_lo = (Uint8 *) malloc(0x10000);

    /* partie video */
    memory.pal1 = (Uint8 *) malloc(0x2000);
    memory.pal2 = (Uint8 *) malloc(0x2000);

    memory.pal_pc1 = (Uint8 *) malloc(0x2000);
    memory.pal_pc2 = (Uint8 *) malloc(0x2000);

    memset(memory.video, 0, 0x20000);

    romfile = (char *) malloc(len);
    memset(romfile, 0, len);
    if (!conf.special_bios) {
      memory.bios = (Uint8 *) malloc(0x20000);
      memory.bios_size=0x20000;
      /* try new bios */
      if (conf.system==SYS_HOME) {
          sprintf(romfile, "%s/aes-bios.bin", path);
      } else {
          if (conf.country==CTY_JAPAN) {
              sprintf(romfile, "%s/vs-bios.rom", path);
          } else if (conf.country==CTY_USA) {
              sprintf(romfile, "%s/usa_2slt.bin", path);
          } else if (conf.country==CTY_ASIA) {
              sprintf(romfile, "%s/asia-s3.rom", path);
          } else {
              sprintf(romfile, "%s/sp-s2.sp1", path);
          }
      }
      f = fopen(romfile, "rb");
      if (f == NULL) {
          printf("Can't find %s\n", romfile);
          exit(1);
      }
      fread(memory.bios, 1, 0x20000, f);
      fclose(f);
    }
    sprintf(romfile, "%s/ng-sfix.rom", path);
    f = fopen(romfile, "rb");
    if (f == NULL) {
	/* try new bios */
	sprintf(romfile, "%s/sfix.sfx", path);
	f = fopen(romfile, "rb");
	if (f == NULL) {
	    printf("Can't find %s\n", romfile);
	    exit(1);
	}
    }
    fread(memory.sfix_board, 1, 0x20000, f);
    fclose(f);

    sprintf(romfile, "%s/ng-lo.rom", path);
    f = fopen(romfile, "rb");
    if (f == NULL) {
	/* try new bios */
	sprintf(romfile, "%s/000-lo.lo", path);
	f = fopen(romfile, "rb");
	if (f == NULL) {
	    printf("Can't find %s\n", romfile);
	    exit(1);
	}
    }
    fread(memory.ng_lo, 1, 0x10000, f);
    fclose(f);


    /* convert bios fix char */
    convert_all_char(memory.sfix_board, 0x20000, memory.fix_board_usage);

    fix_usage = memory.fix_board_usage;
    current_pal = memory.pal1;
    current_fix = memory.sfix_board;
    current_pc_pal = (Uint16 *) memory.pal_pc1;

    free(romfile);
}
Esempio n. 24
0
bool cf_save_file(char *filename, int flags) {
	char *conf_file = filename;
	char *conf_file_dst;
	FILE *f;
	FILE *f_dst;
	int i = 0, j, a;
	char buf[512];
	char name[32];
	char val[255];
	CONF_ITEM *cf;

	if (!conf_file) {
#ifdef EMBEDDED_FS
		int len = strlen("gngeorc") + strlen(ROOTPATH"conf/") + 1;
		conf_file = (char *) alloca(len * sizeof (char));
		sprintf(conf_file, ROOTPATH"conf/gngeorc");
#elif __AMIGA__
		int len = strlen("gngeorc") + strlen("/PROGDIR/data/") + 1;
		conf_file = (char *) alloca(len * sizeof (char));
		sprintf(conf_file, "/PROGDIR/data/gngeorc");
#else /* POSIX */
		int len = strlen("gngeorc") + strlen(getenv("HOME")) + strlen("/Documents/") + 1;
		conf_file = (char *) alloca(len * sizeof (char));
		sprintf(conf_file, "%s/Documents/gngeorc", getenv("HOME"));
#endif
	}
	conf_file_dst = alloca(strlen(conf_file) + 4);
	sprintf(conf_file_dst, "%s.t", conf_file);

	if ((f_dst = fopen(conf_file_dst, "w")) == 0) {
		//printf("Unable to open %s\n",conf_file);
		return false;
	}

	if ((f = fopen(conf_file, "rb"))) {

		//printf("Loading current .cf\n");

		while (!feof(f)) {
			i = 0;
			my_fgets(buf, 510, f);
			if (discard_line(buf)) {
				fprintf(f_dst, "%s\n", buf);
				continue;
			}

			//sscanf(buf, "%s %s", name, val);
			sscanf(buf, "%s ", name);
			strncpy(val, buf + strlen(name) + 1, 254);

			cf = cf_get_item_by_name(name);
			if (cf) {
				if (cf->modified) {
					cf->modified = 0;
					switch (cf->type) {
						case CFT_INT:
							fprintf(f_dst, "%s %d\n", cf->name, CF_VAL(cf));
							break;
						case CFT_BOOLEAN:
							if (CF_BOOL(cf))
								fprintf(f_dst, "%s true\n", cf->name);
							else
								fprintf(f_dst, "%s false\n", cf->name);
							break;
						case CFT_STRING:
							fprintf(f_dst, "%s %s\n", cf->name, CF_STR(cf));
							break;
						case CFT_ARRAY:
							fprintf(f_dst, "%s ", cf->name);
							for (a = 0; a < CF_ARRAY_SIZE(cf) - 1; a++)
								fprintf(f_dst, "%d,", CF_ARRAY(cf)[a]);
							fprintf(f_dst, "%d\n", CF_ARRAY(cf)[a]);
							break;
						case CFT_ACTION:
						case CFT_ACTION_ARG:
							break;
						case CFT_STR_ARRAY:
							printf("TODO: Save CFT_STR_ARRAY\n");
							break;
					}
				} else
					fprintf(f_dst, "%s\n", buf);
			}
		}
		fclose(f);

	}
	/* Now save options that were not in the previous file */
	for (i = 0; i < 128; i++) {
		for (j = 0; j < cf_hash[i].nb_item; j++) {
			cf = cf_hash[i].conf[j];
			//printf("Option %s %d\n",cf->name,cf->modified);
			if (cf->modified!=0) {
				cf->modified=0;
				switch (cf->type) {
					case CFT_INT:
						fprintf(f_dst, "%s %d\n", cf->name, CF_VAL(cf));
						break;
					case CFT_BOOLEAN:
						if (CF_BOOL(cf))
							fprintf(f_dst, "%s true\n", cf->name);
						else
							fprintf(f_dst, "%s false\n", cf->name);
						break;
					case CFT_STRING:
						fprintf(f_dst, "%s %s\n", cf->name, CF_STR(cf));
						break;
					case CFT_ARRAY:
						fprintf(f_dst, "%s ", cf->name);
						for (a = 0; a < CF_ARRAY_SIZE(cf) - 1; a++)
							fprintf(f_dst, "%d,", CF_ARRAY(cf)[a]);
						fprintf(f_dst, "%d\n", CF_ARRAY(cf)[a]);
						break;
					case CFT_ACTION:
					case CFT_ACTION_ARG:
						/* action are not available in the conf file */
						break;
					case CFT_STR_ARRAY:
						printf("TODO: Save CFT_STR_ARRAY\n");
						break;
				}
			}
		}
	}
	fclose(f_dst);

	remove(conf_file);
	rename(conf_file_dst, conf_file);

	return true;
}
Esempio n. 25
0
bool cf_open_file(char *filename) {
	/* if filename==NULL, we use the default one: $HOME/Documents/gngeorc */
	char *conf_file = filename;
	FILE *f;
	int i = 0;
	char buf[512];
	char name[32];
	char val[255];
	CONF_ITEM *cf;

	if (!conf_file) {
#ifdef EMBEDDED_FS
		int len = strlen("gngeorc") + strlen(ROOTPATH"conf/") + 1;
		conf_file = (char *) alloca(len * sizeof (char));
		sprintf(conf_file, ROOTPATH"conf/gngeorc");
#elif __AMIGA__
		int len = strlen("gngeorc") + strlen("/PROGDIR/data/") + 1;
		conf_file = (char *) alloca(len * sizeof (char));
		sprintf(conf_file, "/PROGDIR/data/gngeorc");
#else
		int len = strlen("gngeorc") + strlen(getenv("HOME")) + strlen("/Documents/") + 1;
		conf_file = (char *) alloca(len * sizeof (char));
		sprintf(conf_file, "%s/Documents/gngeorc", getenv("HOME"));
#endif
	}
	if ((f = fopen(conf_file, "rb")) == 0) {
		//printf("Unable to open %s\n",conf_file);
		return false;
	}

	while (!feof(f)) {
		i = 0;
		my_fgets(buf, 510, f);
		if (discard_line(buf))
			continue;
	
		/* TODO: Verify this on Win32 */
		sscanf(buf, "%s %s", name, val);

		//sscanf(buf, "%s ", name);
		//strncpy(val,buf+strlen(name)+1,254);

//		printf("%s|%s|\n",name,val);
		cf = cf_get_item_by_name(name);
		if (cf && !(cf->flags & CF_SETBYCMD) && (!cf->modified)) {
//			printf("Option %s\n",cf->name);
			switch (cf->type) {
				case CFT_INT:
					CF_VAL(cf) = atoi(val);
//                    printf("got val: %d\n",CF_VAL(cf));
					break;
				case CFT_BOOLEAN:
					CF_BOOL(cf) = (strcasecmp(val, "true") == 0 ? true : false);
					break;
				case CFT_STRING:
					strncpy(CF_STR(cf), val, 254);
					break;
				case CFT_ARRAY:
					read_array(CF_ARRAY(cf), val, CF_ARRAY_SIZE(cf));
					break;
				case CFT_ACTION:
				case CFT_ACTION_ARG:
					/* action are not available in the conf file */
					break;
				case CFT_STR_ARRAY:
					CF_STR_ARRAY(cf) = read_str_array(val, &CF_STR_ARRAY_SIZE(cf));
					break;
			}
		} else {
			/*printf("Unknow option %s\n",name);*/
			/* unknow option...*/
		}
	}

	cf_cache_conf();
	return true;
}