コード例 #1
0
ファイル: fds.c プロジェクト: Aleyr/nesemu2
static int loadbios(cart_t *ret,char *filename)
{
	memfile_t *file;
	int n = 0;

	//open bios file
	if((file = memfile_open(filename,"rb")) == 0) {
		log_printf("loadbios:  error opening fds bios '%s'\n",filename);
		return(1);
	}

	//setup prg for bios
	ret->prg.size = 0x2000;
	ret->prg.mask = 0x1FFF;
	ret->prg.data = (u8*)mem_alloc(0x2000);

	//read bios
	if(memfile_read(ret->prg.data,1,0x2000,file) != 0x2000) {
		log_printf("loadbios:  error reading bios file '%s'\n",filename);
		n = 1;
	}
	else
		log_printf("loadbios:  loaded bios file '%s'\n",filename);

	//close bios file handle
	memfile_close(file);

	//return
	return(n);
}
コード例 #2
0
int movie_save(char *filename)
{
	memfile_t *file;
	u8 flags;

	if(filename) {
		if(nes->movie.filename)
			mem_free(nes->movie.filename);
		nes->movie.filename = mem_strdup(filename);
	}
	else if(nes->movie.filename == 0) {
		log_printf("movie_save:  error!  no filename given and movie doesnt have filename set\n");
		return(0);
	}

	if(nes->movie.len == 0) {
		log_printf("movie_save:  no movie data to save, just setting filename\n");
		return(0);
	}
	if(nes->movie.mode & MOVIE_RECORD) {
		log_printf("movie_save:  still recording, stopping...\n");
		movie_stop();
	}
	if((file = memfile_open(nes->movie.filename,"wb")) == 0) {
		log_printf("movie_save:  error opening movie '%s'\n",filename);
		return(1);
	}
	memfile_seek(nes->movie.state,0,SEEK_SET);

	flags = (nes->movie.mode & MOVIE_TEST) ? 1 : 0;

	//header (just ident for now)
	memfile_write(movie_ident,1,4,file);
	memfile_write(&flags,1,sizeof(u8),file);

	//save input device configuration
	memfile_write(&nes->inputdev[0]->id,1,sizeof(int),file);
	memfile_write(&nes->inputdev[1]->id,1,sizeof(int),file);
	memfile_write(&nes->expdev->id,1,sizeof(int),file);

	//save movie data
	memfile_write(&nes->movie.startframe,1,sizeof(u32),file);
	memfile_write(&nes->movie.endframe,1,sizeof(u32),file);
	memfile_write(&nes->movie.crc32,1,sizeof(u32),file);
	memfile_write(&nes->movie.len,1,sizeof(u32),file);
	log_printf("movie_save:  start, end = %d, %d :: len = %d bytes\n",nes->movie.startframe,nes->movie.endframe,nes->movie.len);
	memfile_write(nes->movie.data,1,nes->movie.len,file);

	//append savestate to end of movie
	memfile_copy(file,nes->movie.state,memfile_size(nes->movie.state));
	memfile_close(file);
	return(0);
}
コード例 #3
0
int movie_load(char *filename)
{
	memfile_t *file;
	u32 size;
	u8 flags;
	int devid[3];
	char ident[5];

	movie_unload();
	if((file = memfile_open(filename,"rb")) == 0) {
		log_printf("movie_load:  error opening movie '%s'\n",filename);
		return(1);
	}
	//need header and stuff here
	memfile_read(ident,1,4,file);
	if(memcmp(ident,movie_ident,4) != 0) {
		log_printf("movie_load:  bad movie ident\n");
		memfile_close(file);
		return(2);
	}

	//read movie flags
	memfile_read(&flags,1,sizeof(u8),file);
	if(flags & 1)
		nes->movie.mode |= MOVIE_TEST;

	//set required input devices
	memfile_read(&devid[0],1,sizeof(int),file);
	memfile_read(&devid[1],1,sizeof(int),file);
	memfile_read(&devid[2],1,sizeof(int),file);
	nes_set_inputdev(0,devid[0]);
	nes_set_inputdev(1,devid[1]);
	nes_set_inputdev(2,devid[2]);

	//read movie data
	memfile_read(&nes->movie.startframe,1,sizeof(u32),file);
	memfile_read(&nes->movie.endframe,1,sizeof(u32),file);
	memfile_read(&nes->movie.crc32,1,sizeof(u32),file);
	memfile_read(&nes->movie.len,1,sizeof(u32),file);
	log_printf("movie_load:  start, end = %d, %d :: len = %d bytes\n",nes->movie.startframe,nes->movie.endframe,nes->movie.len);
	nes->movie.data = (u8*)mem_alloc(nes->movie.len);
	memfile_read(nes->movie.data,1,nes->movie.len,file);
	size = memfile_size(file) - memfile_tell(file);
	nes->movie.state = memfile_create();
	memfile_copy(nes->movie.state,file,size);
	memfile_close(file);
	return(0);
}
コード例 #4
0
ファイル: emu.c プロジェクト: Aleyr/nesemu2
int emu_mainloop_test(char *script)
{
	u64 t,total,frames;
	char line[1024],*rom,*test,*p;
	memfile_t *file;
	int testrunning = 0;

	log_printf("emu_mainloop_test:  starting automated tests from '%s'\n",script);

	if((file = memfile_open(script,"rb")) == 0) {
		log_printf("emu_mainloop_test:  error opening test script '%s'\n",script);
		return(0);
	}

	//begin the main loop
	total = 0;
	frames = 0;
	while(quit == 0) {
		if(nes->movie.mode & (MOVIE_CRCFAIL | MOVIE_CRCPASS)) {
			if(nes->movie.mode & MOVIE_CRCFAIL)
				log_printf("emu_mainloop_test:  test over.  failed. (rom = '%s')\n",rom);
			if(nes->movie.mode & MOVIE_CRCPASS)
				log_printf("emu_mainloop_test:  test over.  passed. (rom = '%s')\n",rom);
			testrunning = 0;
		}
		if(testrunning == 0) {
			do {
				if(memfile_gets(line,1024,file) == 0) {
					quit++;
					p = 0;
					break;
				}
				p = str_eatwhitespace(line);
				log_printf("line:  %s",p);
			} while(*p == '#');
			if(p == 0)
				break;
			rom = str_eatwhitespace(strtok(p,";\r\n"));
			test = str_eatwhitespace(strtok(0,";\r\n"));
			log_printf("rom, test = '%s', '%s'\n",rom,test);
			if(emu_event(E_LOADROM,(void*)rom) == 0) {
				if(emu_event(E_LOADMOVIE,(void*)test) == 0) {
					emu_event(E_PLAYMOVIE,0);
					testrunning = 1;
				}
			}
		}
		t = system_gettick();
		system_checkevents();
		input_poll();
		video_startframe();
		if(running && nes->cart) {
			nes_frame();
		}
		video_endframe();
		total += system_gettick() - t;
		frames++;
	}
	log_printf("fps:  %f (%d frames)\n",(double)frames / (double)total * system_getfrequency(),frames);
	memfile_close(file);
	return(0);
}