Esempio n. 1
0
//poll input for gui2
void gui2_poll()
{
	static u32 old_joy1 = 0;
	u32 new_joy1,joy1 = 0;

	//hack to make sure key isnt held down
	if(joykeys[config.gui_keys[0]])	joy1 |= INPUT_MENU;
	if(joykeys[config.gui_keys[1]])	joy1 |= INPUT_LOADSTATE;
	if(joykeys[config.gui_keys[2]])	joy1 |= INPUT_SAVESTATE;
	if(joykeys[config.gui_keys[4]])	joy1 |= INPUT_SCREENSHOT;
	new_joy1 = joy1 & ~old_joy1;
	old_joy1 = joy1;
	//end hack
	if(new_joy1 & INPUT_MENU) {
		//dont let user exit gui if rom is not loaded
		if((pce == 0) || (pce->rom == 0))
			return;
		gui_active ^= 1;
		memset(gui_draw_getscreen(),GUI_COLOR_OFFSET,gui_draw_getscreenpitch()*gui_draw_getscreenheight());
		if(gui_active == 0)
			sound_play();
		else {
			sound_pause();
			video_copyscreen();
		}
	}
	else if(gui_active) return;
	else if(new_joy1 & INPUT_LOADSTATE)	loadstate();
	else if(new_joy1 & INPUT_SAVESTATE)	savestate();
#ifdef SCREENSHOTS
	else if(new_joy1 & INPUT_SCREENSHOT)screenshot();
#endif
}
Esempio n. 2
0
bool savestate_load(EMUFILE* is)
{
	SAV_silent_fail_flag = false;
	char header[16];
	is->fread(header,16);
	if(is->fail() || memcmp(header,magic,16))
		return false;

	u32 ssversion,len,comprlen;
	if(!read32le(&ssversion,is)) return false;
	if(!read32le(&_DESMUME_version,is)) return false;
	if(!read32le(&len,is)) return false;
	if(!read32le(&comprlen,is)) return false;

	if(ssversion != SAVESTATE_VERSION) return false;

	std::vector<u8> buf(len);

   is->fread((char*)&buf[0],len-32);

	//GO!! READ THE SAVESTATE
	//THERE IS NO GOING BACK NOW
	//reset the emulator first to clean out the host's state

	NDS_Reset();

	//reset some options to their old defaults which werent saved
	nds._DebugConsole = FALSE;

	//GPU_Reset(MainScreen.gpu, 0);
	//GPU_Reset(SubScreen.gpu, 1);
	//gfx3d_reset();
	//gpu3D->NDS_3D_Reset();
	//SPU_Reset();

	EMUFILE_MEMORY mstemp(&buf);
	bool x = ReadStateChunks(&mstemp,(s32)len);

	if(!x && !SAV_silent_fail_flag)
	{
		msgbox->error("Error loading savestate. It failed halfway through;\nSince there is no savestate backup system, your current game session is wrecked");
		return false;
	}

	loadstate();

	if(nds.ConsoleType != CommonSettings.ConsoleType) {
		printf("WARNING: forcing console type to: ConsoleType=%d\n",nds.ConsoleType);
	}

	if((nds._DebugConsole!=0) != CommonSettings.DebugConsole) {
			printf("WARNING: forcing console debug mode to: debugmode=%s\n",nds._DebugConsole?"TRUE":"FALSE");
	}


	return true;
}
Esempio n. 3
0
int gbcLoadState(const char* filename)
{
    loadstate(filename);

    vram_dirty();
    pal_dirty();
    sound_dirty();
    mem_updatemap();

    return 1;
}
Esempio n. 4
0
void emu_init(char *save)
{
	FILE *state = NULL;

	if(save && *save) {
		state = fopen(save, "r");
		if(state) {
			loadstate(state);
			fclose(state);
		}
	}
}
Esempio n. 5
0
/*
 * do_file - load or save game data in the given file
 *
 * Returns true on success and false on failure.
 *
 * @desc is a brief user-provided description (<20 bytes) of the state.
 * If no description is provided, set @desc to NULL.
 *
 */
static bool do_file(char *path, char *desc, bool is_load) {
    char buf[200], desc_buf[20];
    int fd, file_mode;
    
    /* set file mode */
    file_mode = is_load ? O_RDONLY : (O_WRONLY | O_CREAT);
  
    /* attempt to open file descriptor here */
    if ((fd = open(path, file_mode, 0666)) < 0)
        return false;

    /* load/save state */
    if (is_load)
    {
        /* load description */
        read(fd, desc_buf, 20);
    
        /* load state */
        loadstate(fd);
    
        /* print out a status message so the user knows the state loaded */
        snprintf(buf, 200, "Loaded state from \"%s\"", path);
        rb->splash(HZ * 1, buf);
    }
    else
    {
        /* build description buffer */
        memset(desc_buf, 0, 20);
        if (desc)
            strlcpy(desc_buf, desc, 20);

        /* save state */
        write(fd, desc_buf, 20);
        savestate(fd);
    }
    
    /* close file descriptor */
    close(fd);

    /* return true (for success) */
    return true;
}
Esempio n. 6
0
int
loadstate_f(Mach *m, uint slot)
{
	FILE *fp;

	if (slot >= nelem(m->state))
		return -EINVAL;

	fp = xfopen("%u.sav", "rb", slot);
	if (!fp)
		return -errno;

	if (fread(m->state[slot], 1, sizeof(m->state[slot]), fp) != sizeof(m->state[slot]))
		return -errno;

	loadstate(m, m->state[slot]);
	fclose(fp);

	return 0;
}
Esempio n. 7
0
void state_poll()
{
    static const int savekeys[] = {
        SDL_SCANCODE_0, SDL_SCANCODE_1, SDL_SCANCODE_2, SDL_SCANCODE_3, SDL_SCANCODE_4,
        SDL_SCANCODE_5, SDL_SCANCODE_6, SDL_SCANCODE_7, SDL_SCANCODE_8, SDL_SCANCODE_9
    };

    if (keystate[SDL_SCANCODE_LCTRL])
    {
        for (int i=0;i<10;i++)
            if (keyreleased[savekeys[i]])
                savestate(slotname(i));
    }
    else if (keystate[SDL_SCANCODE_LSHIFT])
    {
        for (int i=0;i<10;i++)
            if (keyreleased[savekeys[i]])
                loadstate(slotname(i));
    }
}
Esempio n. 8
0
void state_load(int n)
{
	FILE *f;
	char *name;

	if (n < 0) n = saveslot;
	if (n < 0) n = 0;
	name = malloc(strlen(saveprefix) + 5);
	sprintf(name, "%s.%03d", saveprefix, n);

	if ((f = fopen(name, "rb")))
	{
		loadstate(f);
		fclose(f);
		vram_dirty();
		pal_dirty();
		sound_dirty();
		mem_updatemap();
	}
	free(name);
}
Esempio n. 9
0
/*
 * do_file - load or save game data in the given file
 *
 * Returns true on success and false on failure.
 *
 * @desc is a brief user-provided description (<20 bytes) of the state.
 * If no description is provided, set @desc to NULL.
 *
 */
static bool do_file(char *path/*, char *desc*/, bool is_load) {
  int fd; //, file_mode;

  /* load/save state */
  if (is_load) {
    fd = open(path, O_RDONLY );
    if(!fd) {
      printf("Retry...\n"); 
      fd = open(path, O_RDONLY );
      if(!fd) return false;
      else printf("File opened!\n");
    }
    else printf("File opened!\n");

    /* load state */
    loadstate(fd);
    printf("Loaded state from \"%s\"\n", path);

  } else {
    fd = open(path, O_WRONLY | O_CREAT );
    if(!fd) {
      printf("Retry...\n"); 
      fd = open(path, O_WRONLY | O_CREAT ); 
      if(!fd) return false;
      else printf("File opened!\n");
    }
    else printf("File opened!\n");

    /* save state */
    savestate(fd);
  }

  /* close file descriptor */
  close(fd);

  /* return true (for success) */
  return true;
}
int main()
{
	Super* super = Super::getInstance();
	super->getWindow();
	super->getWindow().setVerticalSyncEnabled(true);
	super->getWindow().setFramerateLimit(60);
	NormalBlock normal(sf::Vector2f(100, 100));
	//super->getStateManager().pushState(new WordMapState());
	//super->getStateManager().pushState(new IntroScreen());    
	LoadingState loadstate("MAPJEVEL.png");
	loadstate.update(*super);

	//super->getStateManager().pushState(new WordMapState());
	super->getStateManager().pushState(new IntroScreen());    

    while (super->getWindow().isOpen())
    {
        sf::Event event;
        while (super->getWindow().pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                super->getWindow().close();
        }
		//EntityManager::getInstance()->update();
		//EntityManager::getInstance()->render();
		//super->update();

		normal.render();

		//super->draw();
       
    }

	super->getStateManager().clear();
	delete super;

    return 0;
}
Esempio n. 11
0
void handle_key(void){
	if (NeedsPoll) poll_keyboard();


	if (key[syskeys[0]] || key[KEY_ESC]) {
		do {
			rest(5);
			if (NeedsPoll) poll_keyboard();
		} while (key[syskeys[0]] || key[KEY_ESC]);
		key_done=1;
	}

if (key[syskeys[1]]) {
		do {
			rest(5);
			if (NeedsPoll) poll_keyboard();
		} while (key[syskeys[1]]);

		mute_audio();
		mute_voice();
		abaut();

		do {
			rest(5);
			if (NeedsPoll) poll_keyboard();

			if (key[KEY_ALT] && key[KEY_ENTER]) {
				app_data.fullscreen = app_data.fullscreen ? 0 : 1;
				grmode();
				abaut();
				do {
					rest(5);
					if (NeedsPoll) poll_keyboard();
				} while (key[KEY_ENTER]);
			}		

		} while ((!key[syskeys[1]]) && (!key[KEY_ESC]) && (!key[syskeys[0]]));
		do {
			rest(5);
			if (NeedsPoll) poll_keyboard();
		} while (key[syskeys[1]]);
		
		init_sound_stream();
	}		

if (key[syskeys[5]])
	{
		if (savestate(app_data.statefile)==0)
		{
			display_msg("Savefile saved.",5);
		}
		do {
			rest(5);
			if (NeedsPoll) poll_keyboard();
		} while (key[syskeys[5]]);

	}

	/* LOAD STATE */
	if (key[syskeys[6]])
	{
		int stateError;
		if ((stateError=loadstate(app_data.statefile))==0)
		{
			display_msg("Savefile loaded.",5);
		}
		else if (stateError>=199)
		{
			if (stateError==199) display_msg("Wrong ROM-File for Savefile.",5);
			else if (stateError==200+ROM_O2) display_msg("Wrong BIOS for Savefile: O2ROM needed.",5);
			else if (stateError==200+ROM_G7400) display_msg("Wrong BIOS for Savefile: G7400 ROM needed.",5);
			else if (stateError==200+ROM_C52) display_msg("Wrong BIOS for Savefile: C52 ROM needed.",5);
			else if (stateError==200+ROM_JOPAC) display_msg("Wrong BIOS for Savefile: JOPAC ROM needed.",5);
			else display_msg("Wrong BIOS for Savefile: UNKNOWN ROM needed.",5);
		}
		do {
			rest(5);
			if (NeedsPoll) poll_keyboard();
		} while (key[syskeys[6]]);
	}

	if (key[syskeys[2]]) key_debug=1;

	if (key[syskeys[3]]) {
		init_cpu();
		init_roms();
		init_vpp();
		clearscr();
		do {
			rest(5);
			if (NeedsPoll) poll_keyboard();
		} while (key[syskeys[3]]);
	}

    /* SET HIGHSCORE */
	if (key[syskeys[7]])
	{
		set_score(app_data.scoretype, app_data.scoreaddress, app_data.default_highscore);
	}


	if (key[syskeys[4]]) {
		BITMAP *bmp;
		PALETTE pal;
		char *p;
		static char name[1024];
		static int scshot_counter = 0;

		if (strlen(app_data.scshot)>0){
			if ((p=strchr(app_data.scshot,'@'))) {
				*p = 0;
				sprintf(name, "%s%02d%s", app_data.scshot, scshot_counter++, p+1);
				*p = '@';
			} else {
				strcpy(name, app_data.scshot);
			}
			get_palette(pal);
			bmp = create_sub_bitmap(screen, 0, 0, SCREEN_W, SCREEN_H);
			save_bitmap(name, bmp, pal);
			destroy_bitmap(bmp);
			do {
				rest(5);
				if (NeedsPoll) poll_keyboard();
			} while (key[syskeys[4]]);
		}
	}

	// switch joystick
	if (key[syskeys[8]]) {
		joyswitch = joyswitch ? 0 : 1;

		set_defjoykeys(0,joyswitch);
		set_defjoykeys(1,joyswitch ? 0 : 1);
		int tmp = app_data.stick[0];
		app_data.stick[0] = app_data.stick[1];
		app_data.stick[1] = tmp;

		do {
			rest(5);
			if (NeedsPoll) poll_keyboard();
		} while (key[syskeys[8]]);

	}

	if (key[KEY_ALT] && key[KEY_ENTER]) {
		app_data.fullscreen = app_data.fullscreen ? 0 : 1;
		grmode();
		do {
			rest(5);
			if (NeedsPoll) poll_keyboard();
		} while (key[KEY_ENTER]);
	}		

}
Esempio n. 12
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",
Esempio n. 13
0
void demo(char *name)
{
    sprintf_sd(fn)("demos/%s.cdgz", name);
    loadstate(fn);
    demoloading = true;
};
Esempio n. 14
0
void loadgame(char *name)
{
    sprintf_sd(fn)("savegames/%s.csgz", name);
    loadstate(fn);
};
Esempio n. 15
0
void demo(char *name) {
	IString fn;
	std::sprintf(fn, "demos/%s.cdgz", name);
	loadstate(fn);
	demoloading = true;
}
Esempio n. 16
0
void loadgame(char *name) {
	char fn[_MAXDEFSTR];
	std::sprintf(fn, "savegames/%s.csgz", name);
	loadstate(fn);
}
Esempio n. 17
0
//run 1 NES frame with FF/REW control
void play() {
    static int framecount=0;
    static int fcount = 0;
    int forward = 0;
    int backward = 0;

    do_cheat();

    global_playcount++;
    if(global_playcount > 6)
        global_playcount = 0;

    if(nifi_stat)
        __emuflags &= ~(FASTFORWARD | REWIND);		//when nifi enabled, disable the fastforward & rewind.

    forward = __emuflags & FASTFORWARD;
    backward = __emuflags & REWIND;

    if(backward) { // for rolling back... a nice function?
        swiWaitForVBlank();
        framecount++;
        if(framecount>2) {
            framecount-=3;
            if(firstsave!=lastsave) {
                lastsave--;
                if(lastsave<0)
                    lastsave=maxsaves-1;
                loadstate(freemem_start+SAVESTATESIZE*lastsave);
                EMU_Run();
            }
        }
    } else {
        if(__emuflags & SOFTRENDER) {
            if(!(forward) && (fcount >= debuginfo[6] && fcount - debuginfo[6] < 10) ) // disable VBlank to speed up emulation.
                swiWaitForVBlank();
        } else {
            if(!(forward)) {
                if(__emuflags & PALSYNC) {
                    if(__emuflags & (SOFTRENDER | PALTIMING))
                        __emuflags ^= PALSYNC;
                    if(REG_VCOUNT < 190) {
                        swiWaitForVBlank();
                    }
                }
                else {
                    if((!(__emuflags & ALLPIXEL)) || (all_pix_start != 0))
                        swiWaitForVBlank();
                }
            }
        }

        if(!(__emuflags & PALTIMING && global_playcount == 6)) {
            EMU_Run(); //run a frame
            framecount++;
            if(framecount>8) {	//save state every 9th frame
                framecount-=9;
                savestate(freemem_start+SAVESTATESIZE*lastsave);
                lastsave++;
                if(lastsave>=maxsaves)
                    lastsave=0;
                if(lastsave==firstsave) {
                    firstsave++;
                    if(firstsave>=maxsaves)
                        firstsave=0;
                }
            }
        }
        else {
            if((__emuflags & PALTIMING) && (__emuflags & ALLPIXEL) && !(__emuflags & SOFTRENDER))
                swiWaitForVBlank();
        }
    }

    if(__emuflags & SOFTRENDER) {
        __emuflags &= ~AUTOSRAM;
        __rendercount++;
        if(SOFT_FRAMESKIP <= 1 ||__rendercount == 1) {
            if(__emuflags & ALLPIXEL)
                render_sub();
            render_all();
        }
        if(!(forward) && __rendercount >= SOFT_FRAMESKIP)
            __rendercount = 0;
        if((forward) && __rendercount > 16)
            __rendercount = 0;
    } else if(__emuflags & ALLPIXEL) {
        render_sub();
    }

    fcount++;
    if(fcount > 59)
        fcount = 0;

    __emuflags &= ~(FASTFORWARD | REWIND);
}
Esempio n. 18
0
int main(int argc, const char *argv[])
{
    ez::ezOptionParser opt;

    opt.overview = "GenEmu -- Sega Genesis Emulator";
    opt.syntax = "genemu [OPTIONS] rom";
    opt.add("",0,0,0,"Display usage instructions.", "-h", "--help");
    opt.add("",0,-1,',',"Apply Game Genie codes [format=ABCD-EFGH]", "--gamegenie", "--gg");
    opt.add("",0,1,0,"Force console type [accepted values: PAL or NTSC]", "--mode", "--type");
    opt.add("",0,-1,',',"Make screenshots on the specified frames and exit", "--screenshots");
    opt.add("",0,1,0,"Load from saved state", "--load");

    opt.parse(argc, argv);
    if (opt.isSet("-h"))
    {
        std::string usage;
        opt.getUsage(usage, 120);
        std::cout << usage;
        return 0;
    }
    std::vector<std::string*> args;
    if (opt.firstArgs.size() >= 2)
    {
        strcpy(romname, opt.firstArgs[1]->c_str());
    }
    else if (opt.lastArgs.size() >= 1)
        strcpy(romname, opt.lastArgs[0]->c_str());
    else
    {
        std::cerr << "ERROR: no ROM specified\n";
        return 2;
    }

    int romsize;
    if (strstr(romname, ".smd"))
        romsize = load_smd(romname);
    else
        romsize = load_bin(romname);
    mem_init(romsize);

#if 0
    uint16_t checksum = 0;
    for (int i=0;i<(romsize-512)/2;i++)
        checksum += m68k_read_memory_16(512+i*2);
    assert(checksum == m68k_read_memory_16(0x18e));
#endif

#if 1
    char buf[256];
    int pc = 0;
    strcpy(buf, argv[1]);
    strcat(buf, ".asm");
    FILE *f = fopen(buf, "w");
    while (pc < romsize) {
        int oplen = m68k_disassemble(buf, pc, M68K_CPU_TYPE_68000);
        fprintf(f, "%06x\t%s\n", pc, buf);
        pc += oplen;
    }
    fclose(f);
#endif

    if (opt.isSet("--mode"))
    {
        std::string mode;
        opt.get("--mode")->getString(mode);
        if (mode == "PAL")
        {
            VERSION_PAL = 1;
            std::cerr << "Forced mode: PAL\n";
        }
        else if (mode == "NTSC")
        {
            VERSION_PAL = 0;
            std::cerr << "Forced mode: NTSC\n";
        }
        else
        {
            std::cerr << "ERROR: invalid mode: " << mode << std::endl;
            return 2;
        }
    }

    std::vector<int> ss_frames;
    int ss_idx = 0;

    hw_init(YM2612_FREQ, VERSION_PAL ? 50 : 60);

    if (!opt.isSet("--screenshots"))
    {
        hw_enable_video(true);
        hw_enable_audio(true);
        gfx_enable(true);
    }
    else
    {
        opt.get("--screenshots")->getInts(ss_frames);
    }

    CPU_M68K.init();
    CPU_Z80.init();

    MASTER_CLOCK = 0;
    CPU_M68K.reset();
    VDP.reset();

    if (opt.isSet("--load"))
    {
        std::string sn;
        opt.get("--load")->getString(sn);
        loadstate(sn.c_str());
    }

    while (hw_poll())
    {
        if (ss_idx < ss_frames.size() && framecounter == ss_frames[ss_idx])
        {
            gfx_enable(true);
        }

        int numscanlines = VDP.num_scanlines();

        uint8_t *screen;
        int pitch;
        hw_beginframe(&screen, &pitch);

        int16_t *audio; int nsamples;
        hw_beginaudio(&audio, &nsamples);
        int audio_index = 0;
        int audio_step = (nsamples << 16) / numscanlines;

        for (int sl=0;sl<numscanlines;++sl)
        {
            CPU_M68K.run(MASTER_CLOCK + VDP_CYCLES_PER_LINE);
            CPU_Z80 .run(MASTER_CLOCK + VDP_CYCLES_PER_LINE);

            vdp_scanline(screen);
            screen += pitch;

            int prev_index = audio_index;
            audio_index += audio_step;
            YM2612Update(audio + ((prev_index+0x8000)>>16)*2, (audio_index-prev_index+0x8000)>>16);

            MASTER_CLOCK += VDP_CYCLES_PER_LINE;
        }

        hw_endaudio();
        hw_endframe();

        if (framecounter == 100 && opt.isSet("--gamegenie"))
        {
            std::vector<std::string> codes;
            opt.get("--gamegenie")->getStrings(codes);
            for (int i=0;i<codes.size();++i)
                mem_apply_gamegenie(codes[i].c_str());
        }

        if (ss_idx < ss_frames.size() && framecounter == ss_frames[ss_idx])
        {
            static char ssname[2048];
            sprintf(ssname, "%s.%d.%s.bmp", romname, framecounter, (VERSION_PAL ? "PAL" : "NTSC"));
            std::cerr << "Saving screenshot " << ssname << std::endl;
            hw_save_screenshot(ssname);

            sprintf(ssname, "%s.%d.%s.gs", romname, framecounter, (VERSION_PAL ? "PAL" : "NTSC"));
            savestate(ssname);

            ++ss_idx;
            if (ss_idx == ss_frames.size())
                break;
        }

        ++framecounter;
        state_poll();
    }

#if 0
    checksum = 0;
    for (int i=0;i<(romsize-512)/2;i++)
        checksum += m68k_read_memory_16(512+i*2);
    assert(checksum == m68k_read_memory_16(0x18e));
#endif

#if 0
    {
    char buf[256];
    int pc = 0xffffee00;
    FILE *f = fopen(buf, "w");
    while (pc <= 0xffffef00) {
        int oplen = m68k_disassemble(buf, pc, M68K_CPU_TYPE_68000);
        fprintf(stdout, "%06x\t%s\n", pc, buf);
        pc += oplen;
    }
    fclose(f);
    }
#endif

    return 0;
}
Esempio n. 19
0
/* The main function */
int main(int argc, char const *argv[])
{
	DBusError dbe;
	struct state_st state;

        /* Parse the command line. */
	if (argv[1] && argv[1][0] == 'd')
	{       /* Debug dump */
		assert(loadstate(&state));
		dumpop(&state);
		return 0;
	} else if (argv[1] && argv[1][0] == 'r')
	{       /* Repair the GA state. */
		unsigned i;

		assert(loadstate(&state));
		for (i = 0; i < G_N_ELEMENTS(state.pop); i++)
		{       /* Ensure that genes are bounded. */
			struct genome_st *g = &state.pop[i];
			if (g->window > TIMEOUT)
				g->window = TIMEOUT;
			else if (g->window < 3)
				g->window = 3;
			if (g->threshold <= 0)
				g->threshold = 0.1;
			else if (g->threshold >= 1)
				g->threshold = 0.9;
		}
		savestate(&state);
		return 0;
	}

        /* Redirect stdio. */
	assert((stderr = fopen(FNAME".err", "a")) != NULL);
	assert((stdout = fopen(FNAME".log", "a")) != NULL);

        /* Initialize infrastructure for the test. */
	Loop = g_main_loop_new(0, 0);

	DBus = dbus_bus_get(DBUS_BUS_SESSION, NULL);
	dbus_connection_setup_with_g_main(DBus, g_main_context_default());
	dbus_error_init(&dbe);
	dbus_bus_add_match(DBus, "type='method_call',interface='com.nokia.HildonDesktop.AppMgr',member='LaunchApplication'", &dbe);
	assert(!dbus_error_is_set(&dbe));

	Dpy = XOpenDisplay(NULL);
	assert(Dpy != NULL);

	if (!loadstate(&state))
		initpop(&state);

        /* Test */
	eval(&state.pop[state.idx++]);
	if (state.idx >= G_N_ELEMENTS(state.pop))
		generation(&state);

        /* Done and reboot. */
	savestate(&state);
	if (argv[1])
		system("echo reboot | sudo gainroot");

	return 0;
} /* main */
Esempio n. 20
0
static void click_loadstate()
{
	loadstate();
	joykeys[config.gui_keys[0]] = 1;
}
Esempio n. 21
0
/********************* Main*/
int omain(int argc, char *argv[]){
	int i, cnt, cntt, cnttt, way;
	static char file[MAXC], attr[MAXC], val[MAXC], *p, *binver;
	#if defined(ALLEGRO_WINDOWS)
	binver = "Windows binary";
	#elif defined(ALLEGRO_DOS)
	binver = "DOS binary";
	#elif defined(ALLEGRO_LINUX)
	binver = "Linux binary";
	#elif defined(ALLEGRO_BEOS)
	binver = "BEOS binary";
	#elif defined(ALLEGRO_QNX)
	binver = "QNX binary";
	#elif defined(ALLEGRO_UNIX)
	binver = "UNIX binary";
	#elif defined(ALLEGRO_MPW)
	binver = "MacOS binary";
	#else
	binver = "Unknown binary";
	#endif
	printf("%s %s\n","\nO2EM v" O2EM_VERSION " " RELEASE_DATE "  - ", binver);
	printf("Free Odyssey2 / Videopac+ Emulator - http://o2em.sourceforge.net\n");
	printf("Created by Daniel Boris (c)1996/1998\n");
    printf("Developed by:\n");
	printf("     Andre de la Rocha since version 0.80\n");
	printf("     Arlindo M. de Oliveira since version 1.16\n");
    printf("\n");

    app_data.debug = 0;
	app_data.stick[0] = app_data.stick[1] = 1;
	app_data.sticknumber[0] = app_data.sticknumber[1] = 0;
	set_defjoykeys(0,0);
	set_defjoykeys(1,1);
	set_defsystemkeys();
	app_data.bank = 0;
	app_data.limit = 1;
	app_data.sound_en = 1;
	app_data.speed = 100;
	app_data.wsize = 2;
	#ifdef ALLEGRO_DOS
	app_data.fullscreen = 1;
	#else
	app_data.fullscreen = 0;
	#endif
	app_data.scanlines = 0;
	app_data.voice = 1;
	app_data.window_title = "O2EM v" O2EM_VERSION;
	app_data.svolume = 100;
	app_data.vvolume = 100;
	app_data.filter = 0;
	app_data.exrom = 0;
	app_data.three_k = 0;
	app_data.crc = 0;
	app_data.scshot = scshot;
	app_data.statefile = statefile;
	app_data.euro = 0;
	app_data.openb = 0;
	app_data.vpp = 0;
	app_data.bios = 0;
	app_data.scoretype = 0;
	app_data.scoreaddress = 0;
	app_data.default_highscore = 0;
	app_data.breakpoint = 65535;
	app_data.megaxrom = 0;
	strcpy(file,"");
	strcpy(file_l,"");
	strcpy(bios_l,"");
    strcpy(bios,"");
	strcpy(scshot,"");
	strcpy(statefile,"");
    strcpy(xrom,"");
	strcpy(scorefile,"highscore.txt");
	read_default_config();
	if (argc >= 2){
    for(i=1; i<argc; i++) {
		if (argv[i][0] != '-') 	{
			strncat(file,argv[i],MAXC-1);
	        file[MAXC-1]=0;
	        strcpy(file_v,file);
		} else {
			p=strtok(argv[i],"=");
	        if (p){
				strncpy(attr,p+1,MAXC-1);
				attr[MAXC-1]=0;
			   } else
				strcpy(attr,"");
			    p=strtok(NULL,"=");
			if (p){
				strncpy(val,p,MAXC-1);
				val[MAXC-1]=0;
			    if (!strcmp(attr,"romdir")||!strcmp(attr,"ROMDIR"))
                   {
                    strcpy(romdir,val);
                    strcat(romdir,file);
                    strcpy(file,romdir);
                    strcpy(romdir,val);
                   }
                if (!strcmp(attr,"biosdir")||!strcmp(attr,"BIOSDIR"))
                   {
                    strcpy(biosdir,val);
                   }                                       
            } else
			strcpy(val,"");
			strlwr(attr);
			if (!parse_option(attr, val)) exit(EXIT_FAILURE);
		}
    }
    if (helpflag) helpus();
    if (strlen(file)==0) {
		fprintf(stderr,"Error: file name missing\n");
		exit(EXIT_FAILURE);
	}

#ifdef __LIBRETRO__
sprintf(statefile,"%s.state\0",file);
#endif
	printf("Starting emulation ...\n");
#ifndef __LIBRETRO__
	allegro_init();
	install_timer();
#endif
	init_audio();

#ifndef __LIBRETRO__
	printf("Using Allegro %s\n",allegro_id);
#endif 


/********************** ROMs if Launcher running... */
    k = strchr(romdir, '/'); 

    launcher_flag_r = strchr(file, '\\');

    if (k != 0) {
                 strcpy (xrom,romdir);
                }
                else if (!launcher_flag_r)
                        {

                        strcpy(xrom,"roms/");
                        strcpy(romdir,file);
#ifndef __LIBRETRO__
                        strcpy(file,xrom);
                        strcat(file,romdir);
#endif
                        strcpy(romdir,xrom);

                        }
                        else
                        {    
         
                        cnt = 0;
                        cntt = 0;
                        cnttt = 0;
                        way = 0;
                        for (cnt=0; file[cnt] != '\0'; cnt=cnt+1) 
                        { 
                        if ( file[cnt] == '\\' ) 
                           {
                           cnttt = cnt;
                           }
                        } 
                        for (cnt=0; cnt<=cnttt; cnt++)
                        { 
                        file_l[cnt] = file[cnt];
                        } 

                        strcpy (romdir,file_l);
                        strcpy (xrom,romdir);
                        }

#ifdef __LIBRETRO__
#ifdef AND
	sprintf(xrom,"%s\0","/mnt/sdcard/O2EM/roms/");
	strcpy(romdir,xrom);
#else
	sprintf(xrom,"%s\0","./roms/");
	strcpy(romdir,xrom);
#endif
#endif


    file_name(xrom);

    if (contax < 3)
                 {
                 printf("\nROMs directory empty!\n");
                 exit(EXIT_FAILURE);
                 }

    app_data.crc = crc32_file(file);

    crcx = app_data.crc;
    suck_roms(); 

/********************** BIOSs if Launcher running... */     
launcher_flag_b = strchr(bios, '\\');

if (!launcher_flag_b){
    k = strchr(biosdir, '/');

    if (k != 0) {    
                 strcpy (xbios,biosdir);
                }
                else           
                        {
                        strcpy (xbios,"bios/");
                        strcpy (biosdir,xbios);
                        }
#ifdef __LIBRETRO__
#ifdef AND
	sprintf(xbios,"%s\0","/mnt/sdcard/O2EM/bios/");
	strcpy (biosdir,xbios);
#else	
	sprintf(xbios,"%s\0","./bios/");
	strcpy (biosdir,xbios);
#endif
#endif

    file_name(xbios);

    if (contax < 3)
                 {
                 printf("\nBIOS directory empty!\n");
                 exit(EXIT_FAILURE);                 
                 }

    suck_bios();

    c_j = strcmp(bios,"jopac");
    if ((rom_f!=1) && (c_j!=0)) strcpy(bios,g7400);
    if ((!o2flag) && (!jopflag) && (!c52flag) && (!g74flag))
                                              {
                                             printf("\ndir '%s' without BIOS !",biosdir);
                                             exit(EXIT_FAILURE);
                                              }
    printf("BIOS found:\n");
    if (!strcmp(bios,"g7400")){
                               strcpy(bios,g7400);
                               if (g74flag != 1) {
                                             printf("\nG7400 BIOS not found !");
                                             exit(EXIT_FAILURE);
                                             } 
                               }
    if (g74flag) printf("  G7400 VP+\n");
    if (!strcmp(bios,"c52")){ 
                             strcpy(bios,c52);
                             if (c52flag != 1) {
                                             printf("\nC52 BIOS not found !");
                                             exit(EXIT_FAILURE);
                                             } 
                                 }
    if (c52flag) printf("  C52\n");
    if (!strcmp(bios,"jopac")){
                               strcpy(bios,jopac);
                               if (jopflag != 1) {
                                          printf("\nJOPAC BIOS not found !");
                                          exit(EXIT_FAILURE);
                                             } 
                               }
    if (jopflag) printf("  JOPAC VP+\n");
    if ((!strcmp(bios,"")) || (!strcmp(bios,"o2rom")))
                            {
                            strcpy(bios,odyssey2);
                            if ((!o2flag)&&(!c52flag)&&(rom_f)){
                                             printf("Odyssey2 BIOS not found !\n");
                                             exit(EXIT_FAILURE);
                                             } 
                            if ((!o2flag)&&(c52flag)&&(rom_f)){
                                             printf("\nOdyssey2 BIOS not found !\n");
                                             printf("Loading C52 BIOS ... ");
                                             strcpy(bios,c52);
                                             }
                            }
    if (o2flag) printf("  Odyssey 2\n");
    }                                           
    if (launcher_flag_b)
       {
       identify_bios(bios);
                if (rom_f!=1)
                   {
                   if (!((g74flag)||(jopflag)))
                      {
                      fprintf(stderr,"\nError: ROM only VP+ BIOS");
                      exit(EXIT_FAILURE);
                      }
                   }
       }      


      if (!launcher_flag_b)
                  {  
                  if (rom_f!=1)
                     {  
                     if (!((g74flag)||(jopflag)))
                         {
                         printf("\nROM only VP+ BIOS\n");
                         exit(EXIT_FAILURE);
                         }
                     if (!(g74flag))
                         {
                         printf("\nVP+ G7400 BIOS not found !");
                         printf("\nLoading VP+ Jopac BIOS ...");
                         strcpy(bios,jopac);
                         }
                     }
                  }
    load_bios(bios);

	load_cart(file);
	if (app_data.voice) load_voice_samples(path);

	init_display();

	init_cpu();

	init_system();

	set_score(app_data.scoretype, app_data.scoreaddress, app_data.default_highscore);
	int stateError;
	if ((stateError=loadstate(app_data.statefile))==0)
	{
		printf("Savefile loaded.");
	}
	else if (stateError>=199)
	{
		if (stateError==199) fprintf(stderr,"Wrong ROM-File for Savefile.");
		else if (stateError==200+ROM_O2) fprintf(stderr,"Wrong BIOS for Savefile: O2ROM needed.");
		else if (stateError==200+ROM_G7400) fprintf(stderr,"Wrong BIOS for Savefile: G7400 ROM needed.");
		else if (stateError==200+ROM_C52) fprintf(stderr,"Wrong BIOS for Savefile: C52 ROM needed.");
		else if (stateError==200+ROM_JOPAC) fprintf(stderr,"Wrong BIOS for Savefile: JOPAC ROM needed.");
		else fprintf(stderr,"Wrong BIOS for Savefile: UNKNOWN ROM needed.");
		return(0);
	}
	if (app_data.debug) key_debug=1;
	#ifndef _DEBUG
	#ifdef ALLEGRO_WINDOWS
	FreeConsole();
	#endif
	#endif

#ifdef __LIBRETRO__
return 1;
#endif
	run();

    if (app_data.scoretype!=0) save_highscore(get_score(app_data.scoretype, app_data.scoreaddress), scorefile);
	exit(EXIT_SUCCESS);
 }
if (!strcmp(attr,"help")||!strcmp(attr,"HELP")) helpus();
printf("type o2em -help");
exit(EXIT_SUCCESS);
}