Esempio n. 1
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);
}
Esempio n. 2
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);
}
Esempio n. 3
0
void* ByteArrayInputStream::s_open(void* vp,int sz)
{
	if(vp==NULL || sz<=0)return NULL;
	return memfile_copy((char*)vp,sz);
}