Beispiel #1
0
char* cf_parse_cmd_line(int argc, char *argv[]) {
	int c;
	CONF_ITEM *cf;


	option_index = optind = 0;
#ifdef WII
	return NULL;
#endif
	while ((c = getopt_long(argc, argv, shortopt, longopt, &option_index)) != EOF) {
		//if (c != 0) {
//			printf("c=%d\n",c);
			cf = cf_get_item_by_val(c&0xFFF);
			if (cf) {
				cf->flags |= CF_SETBYCMD;
//				printf("flags %s set on cmd line\n", cf->name);
				switch (cf->type) {

					case CFT_INT:
						CF_VAL(cf) = atoi(optarg);
						break;
					case CFT_BOOLEAN:
					if (c & 0x1000)
						CF_BOOL(cf) = 0;
					else
						CF_BOOL(cf) = 1;
						break;
					case CFT_STRING:
						strcpy(CF_STR(cf), optarg);
						//printf("conf %s %s\n",CF_STR(cf),optarg);
						break;
					case CFT_ARRAY:
						read_array(CF_ARRAY(cf), optarg, CF_ARRAY_SIZE(cf));
						break;
					case CFT_ACTION_ARG:
						strcpy(CF_STR(cf), optarg);
						if (cf->action) {
							exit(cf->action(cf));
						}
						break;
					case CFT_ACTION:
						if (cf->action) {
							exit(cf->action(cf));
						}
						break;
					case CFT_STR_ARRAY:
						/* TODO */
						break;
				}
			//}
		}
	}
	cf_cache_conf();
	if (optind >= argc)
		return NULL;

	return strdup(argv[optind]);
}
Beispiel #2
0
void cf_reset_to_default(void) {
	int i,j;
	CONF_ITEM *cf;
	for (i = 0; i < 128; i++) {
		for (j = 0; j < cf_hash[i].nb_item; j++) {
			cf = cf_hash[i].conf[j];
			if (cf && !cf->modified && !(cf->flags & CF_SETBYCMD)) {
				switch (cf->type) {
					case CFT_INT:
						CF_VAL(cf) = cf->data.dt_int.default_val;
						break;
					case CFT_BOOLEAN:
						CF_BOOL(cf) = cf->data.dt_bool.default_bool;
						break;
					case CFT_STRING:
						CF_STR(cf)=rstrcpy(CF_STR(cf), cf->data.dt_str.default_str, 254);
						break;
					case CFT_ARRAY:
						memcpy(cf->data.dt_array.array, cf->data.dt_array.default_array,
								CF_ARRAY_SIZE(cf) * sizeof (int));
						//read_array(CF_ARRAY(cf), val, CF_ARRAY_SIZE(cf));
						break;
					default:
						break;
				}
			}
		}
	}
}
Beispiel #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);
}
Beispiel #4
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.rendermode = CF_VAL(cf_get_item_by_name("rendermode"));
    conf.vpad_alpha = CF_VAL(cf_get_item_by_name("vpad_alpha"));
    conf.wiimote = CF_VAL(cf_get_item_by_name("wiimote"));
    
	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_STR(cf_get_item_by_name("country"));
	system = CF_STR(cf_get_item_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;
	}
}
Beispiel #5
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;
}
Beispiel #6
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);
}
Beispiel #7
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;
}
Beispiel #8
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;
}
Beispiel #9
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;
}
Beispiel #10
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;
}
Beispiel #11
0
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);
    }


}
Beispiel #12
0
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();
}
Beispiel #13
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;
}
Beispiel #14
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;
}
Beispiel #15
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;
}
Beispiel #16
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);
    }
}