Example #1
0
/*===  FUNCTION  ============================================================*
Name:           test_qes_seqfile_write
Description:    Tests the qes_seqfile_write function from qes_seqfile.c
 *===========================================================================*/
static void
test_qes_seqfile_write (void *ptr)
{
    struct qes_seq *seq = qes_seq_create();
    size_t expt_bytes = 0;
    ssize_t res = 0;
    struct qes_seqfile *sf = NULL;
    char *fname = NULL;
    char *crc = NULL;

    (void) ptr;
    /* Make a seq to write */
    qes_seq_fill_name(seq, "HWI-TEST", 8);
    qes_seq_fill_comment(seq, "testseq 1 2 3", 13);
    qes_seq_fill_seq(seq, "ACTCAATT", 8);
    qes_seq_fill_qual(seq, "IIIIIIII", 8);
    expt_bytes = 1 + 8 + 1 + 13 + 1 +   /* @ + name + ' ' + comment + '\n' */
                 8 + 1 + 2 + 8 + 1;     /* seq + '\n' + "+\n" + qual + '\n' */
    /* Test with a FASTQ seqfile */
    fname = get_writable_file();
    tt_assert(fname != NULL);
    sf = qes_seqfile_create(fname, "wT");
    qes_seqfile_set_format(sf, FASTQ_FMT);
    res = qes_seqfile_write(sf, seq);
    tt_int_op(res, ==, expt_bytes);
    qes_seqfile_destroy(sf); /* Has to happen here to flush it */
    crc = crc32_file(fname);
    tt_str_op(crc, ==, "d4665941");
    clean_writable_file(fname);
    free(crc);
    fname = NULL;
    crc = NULL;
    /* Test with a FASTA seqfile */
    expt_bytes = 1 + 8 + 1 + 13 + 1 +   /* @ + name + ' ' + comment + '\n' */
                 8 + 1;                 /* seq + '\n'*/
    fname = get_writable_file();
    tt_assert(fname != NULL);
    sf = qes_seqfile_create(fname, "wT");
    qes_seqfile_set_format(sf, FASTA_FMT);
    /* do the write */
    res = qes_seqfile_write(sf, seq);
    tt_int_op(res, ==, expt_bytes);
    qes_seqfile_destroy(sf); /* Flush it */
    crc = crc32_file(fname);
    tt_str_op(crc, ==, "0a295c77");
    clean_writable_file(fname);
    fname = NULL;
    /* Check with bad params that it returns -2 */
    res = qes_seqfile_write(NULL, seq);
    tt_int_op(res, ==, -2);
    res = qes_seqfile_write(sf, NULL);
    tt_int_op(res, ==, -2);
end:
    qes_seqfile_destroy(sf);
    qes_seq_destroy(seq);
    if (fname != NULL) free(fname);
    if (crc != NULL) free(crc);
}
Example #2
0
uint32_t CFileUtils::crc32_file(const char* filepath) throw (CSyscallException)
{
    int fd = open(filepath, O_RDONLY);
    if (-1 == fd)
        THROW_SYSCALL_EXCEPTION(NULL, errno, "open");

    sys::CloseHelper<int> ch(fd);
    return crc32_file(fd);
}
Example #3
0
/********************* Ready BIOS */
int identify_bios(char *biossux)
    {
    app_data.crc = crc32_file(biossux); 
                 if (app_data.crc == 0x8016A315){
                                                 strcpy(odyssey2, biossux);
                                                 o2flag = 1;
                                                }
                 if (app_data.crc == 0xE20A9F41){
                                                 strcpy(g7400, biossux);
                                                 g74flag = 1;
                                                }
                 if (app_data.crc == 0xA318E8D6){
                                                 strcpy(c52, biossux);
                                                 c52flag = 1;
                                                }
                 if (app_data.crc == 0x11647CA5){
                                                 strcpy(jopac, biossux);
                                                 jopflag = 1;
                                                }
    return(0);
    }
Example #4
0
/********************* Search ROM */
int suck_roms()
{
    int i;
    rom_f = 1;
    for (i=0; i<contax; ++i)                    
        {
                 strcpy(romssux,romdir);
                 strcat(romssux,arkivo[i]);
                 app_data.crc = crc32_file(romssux);
                 if (app_data.crc == crcx)
                                  {
                                  if ((app_data.crc == 0xD7089068)||(app_data.crc == 0xB0A7D723)||
                                  (app_data.crc == 0x0CA26992)||(app_data.crc == 0x0B6EB25B)||
                                  (app_data.crc == 0x06861A9C)||(app_data.crc == 0xB2F0F0B4)||
                                  (app_data.crc == 0x68560DC7)||(app_data.crc == 0x0D2D721D)||
                                  (app_data.crc == 0xC4134DF8)||(app_data.crc == 0xA75C42F8))
                                  rom_f = 0;
                                  }
        }
return(0); 
}
Example #5
0
int archive_extract(char *archiveFile, char *filename, char *dir)
{
	char buf[BUFFER_SIZE] = { 0 }, fn[1024] = { 0 };
	uint64_t filePos = 0, fileSize = 0, originalSize = 0, remaining;
	uint32_t crc = 0;
	int fd, fdOut, i, rc;
	unsigned int numFiles = 0;
	int hdrSize = 0, readlen = 0, ret = 0;
	bool compressed = false, encrypted = false;
	tArchiveFile *files = NULL;

	if (gBufferSize == 0)
		gBufferSize = BUFFER_SIZE;

	if ((filename == NULL) || (strlen(filename) == 0)) {
		DPRINTF("Filename for extraction is not specified\n");
		return -EIO;
	}

	if ((dir == NULL) || (strlen(dir) == 0)) {
		DPRINTF("Directory for extraction is not specified\n");
		return -EIO;
	}

	if ((dir[0] != '.') && (access(dir, F_OK) == 0)) {
		struct stat buf;

		stat(dir, &buf);
		if (!S_ISDIR(buf.st_mode)) {
			DPRINTF("File system object %s is not a directory\n", dir);
			return -EEXIST;
		}
	}

	fd = open(archiveFile, O_RDONLY | O_LFILE);
	if (fd < 0) {
		int errno_saved = errno;
		DPRINTF("Cannot open archive file %s, error code %d (%s)\n", filename, errno_saved, strerror(errno_saved));
		return -errno_saved;
	}

	files = archive_read_header(fd, &numFiles, &hdrSize);
	if (files == NULL)
		return -EIO;

	if (numFiles == 0)
		return 0;

	filePos = hdrSize;
	for (i = 0; i < numFiles; i++) {
		if (strcmp(files[i].name, filename) == 0) {
			compressed = (files[i].compressed_size != files[i].size);
			crc = files[i].crc;
			encrypted = files[i].encrypted ? true : false;
			originalSize = files[i].size;
			fileSize = files[i].compressed_size;
			break;
		}

		filePos += files[i].compressed_size;
	}

	free(files);

	lseek(fd, filePos, SEEK_SET);
	if (compressed) {
		snprintf(tempDir, sizeof(tempDir), "/tmp/archiver-%d", getpid());
		mkdir(tempDir, 0755);
		snprintf(fn, sizeof(fn), "%s/%s", tempDir, filename);
	}
	else
		snprintf(fn, sizeof(fn), "%s/%s", dir, filename);

	fdOut = open(fn, O_WRONLY | O_CREAT | O_TRUNC | O_SYNC | O_LFILE, 0644);
	if (fdOut < 0) {
		int errno_saved = errno;
		DPRINTF("Cannot open output file %s, error code %d (%s)\n", filename, errno_saved, strerror(errno_saved));
		close(fd);
		return -errno_saved;
	}

	remaining = fileSize;
	readlen = (fileSize > BUFFER_SIZE) ? BUFFER_SIZE : fileSize;
	while ((remaining > 0) && ((rc = read(fd, buf, readlen)) > 0)) {
		if (write(fdOut, buf, rc) != rc) {
			close(fd);
			close(fdOut);
			DPRINTF("Cannot write data to %s\n", fn);
			return -EIO;
		}
		remaining -= readlen;
		readlen = (fileSize > BUFFER_SIZE) ? BUFFER_SIZE : fileSize;
	}

	if ((lseek(fdOut, 0, SEEK_CUR) != fileSize) && (!compressed && !encrypted)) {
		DPRINTF("Invalid output file size (expected %"PRIi64", is %"PRIi64")\n", fileSize, lseek(fdOut, 0, SEEK_CUR));
		return -EIO;
	}

	close(fd);
	close(fdOut);

	if (compressed) {
		int err;
		char outFile[1024] = { 0 };
		float compression;
		unsigned long long origSize, newSize;

		snprintf(outFile, sizeof(outFile), "%s/%s", dir, filename);

		if (encrypted) {
			char *tmpFn = get_random_file_name();
			DPRINTF("%s: Decrypting ...\n", __FUNCTION__);
			if (mincrypt_decrypt_file(fn, tmpFn, NULL, NULL, VECTOR_MULTIPLIER) != 0) {
				fprintf(stderr, "Decryption failed!\n");
				ret = -EIO;
			}
			if ((ret == 0) && (err = xz_process_data(tmpFn, outFile, 1, gBufferSize, 1, &compression, &origSize, &newSize))) {
				fprintf(stderr, "Decompression of %s failed with error %d!\n", basename(fn), err);
				ret = -EIO;
			}
			unlink(tmpFn);
		}
		else
			if ((err = xz_process_data(fn, outFile, 1, gBufferSize, 1, &compression, &origSize, &newSize))) {
				fprintf(stderr, "Decompression of %s failed with error %d!\n", basename(fn), err);
				ret = -EIO;
			}

		unlink(fn);
		rmdir(tempDir);

		/* Ensure we won't exceed file size since read *may* be done by big chunks */
		truncate(outFile, originalSize);

		if (crc32_file(outFile, gBufferSize) != crc) {
			DPRINTF("CRC is not valid (expected 0x%"PRIx32", found 0x%"PRIx32"; on compressed)\n",
					crc, crc32_file(outFile, gBufferSize));
			ret = -EINVAL;
			//unlink(outFile);
		}

		if (ret == 0)
			DPRINTF("Extraction of %s done successfully\n", filename);
		else
			DPRINTF("Extraction error code %d\n", ret);
	}
	else {
		if (encrypted) {
			char *tmpFn = get_random_file_name();
			if (mincrypt_decrypt_file(fn, tmpFn, "test", "test", VECTOR_MULTIPLIER) != 0) {
				fprintf(stderr, "Decryption failed!\n");
				ret = -EIO;
			}
			else
				rename(tmpFn, fn);

			DPRINTF("fn => '%s'\n", fn);
			if (ret == 0)
				DPRINTF("Extraction of %s done successfully\n", filename);
			else
				DPRINTF("Extraction error code %d\n", ret);
		}

		if ((crc32_file(fn, gBufferSize) != crc) || (fileSize == 0)) {
			DPRINTF("CRC is not valid (expected 0x%"PRIx32", found 0x%"PRIx32"; on non-compressed)\n",
					crc, crc32_file(fn, gBufferSize));
			ret = -EINVAL;
			//unlink(fn);
		}
		else
			DPRINTF("Extraction of done %s successfully\n", filename);
	}

	return ret;
}
Example #6
0
int archive_addFileToList(tArchiveFile *files, char *fn, long size, char *tmpDir)
{
	char outFile[256] = { 0 };
	int err;
	unsigned long long origSize, newSize;
	float compression;

	if (fn == NULL)
		return _fileNum;

	if (size == 0)
		size = get_file_size(fn);

	if ((strlen(tempDir) == 0) && (tmpDir != NULL)) {
		strncpy(tempDir, tmpDir, sizeof(tempDir));
		mkdir(tmpDir, 0755);
	}

	DPRINTF("Creating directory %s\n", tmpDir);
	mkdir(tmpDir, 0755);

	snprintf(outFile, sizeof(outFile), "%s/%s", tmpDir, basename(fn));
	DPRINTF("Setting up outFile to %s\n", outFile);

	if (_encryption) {
		int fd;
		char *tmpFn = get_random_file_name();
		if ((err = xz_process_data(fn, tmpFn, 0, gBufferSize, 1, &compression, &origSize, &newSize))) {
			fprintf(stderr, "Compression of %s failed with error %d!\n", basename(fn), err);
			return _fileNum;
		}
		if (mincrypt_encrypt_file(tmpFn, outFile, NULL, NULL, VECTOR_MULTIPLIER) != 0)
			fprintf(stderr, "Encryption failed!\n");
		unlink(tmpFn);

		fd = open(outFile, O_RDONLY | O_LFILE);
		newSize = lseek(fd, 0, SEEK_END);
		close(fd);

		DPRINTF("%s: New file size is %lld bytes (%s)\n", __FUNCTION__, newSize, outFile);
	}
	else
		if ((err = xz_process_data(fn, outFile, 0, gBufferSize, 1, &compression, &origSize, &newSize))) {
			fprintf(stderr, "Compression of %s failed with error %d!\n", basename(fn), err);
			return _fileNum;
		}

	DPRINTF("Compression ratio: %.2f%% (original size = %lld bytes, new size = %lld bytes, fn = %s)\n",
			compression, origSize, newSize, basename(fn));

	if (newSize >= origSize) {
		DPRINTF("New file %s is bigger or of the same size like original. Disabling compression...\n", outFile);
		rename(fn, outFile);
		newSize = origSize;
	}

	DPRINTF("%s: Adding file #%d: %s\n", __FUNCTION__, _fileNum + 1, fn);

	files[_fileNum].name = strdup( basename(fn) );
	files[_fileNum].size = origSize;
	files[_fileNum].compressed_size = newSize;
	files[_fileNum].crc = crc32_file(fn, gBufferSize);
	files[_fileNum].encrypted = _encryption ? true : false;

	_fileNum++;

	return _fileNum;
}
Example #7
0
int main( int argc, char **argv )
{
    npost_param_t param;

    int ret = npost_parse( argc, argv, &param );

    if ( ret < 0 ) {
        printf( "Error parsing commandline arguments.\n" );
        exit(1);
    }

    // First try to make just one connection, and see if it fails
    int testfd = 0;
    signal( SIGPIPE, SIG_IGN );
    ret = nntp_connect( &testfd, param.server, param.port, param.username, param.password );
    if( ret == CONNECT_FAILURE )
    {
        printf( "Failed to make even a single connection! Exiting...\n" );
        return -1;
    }
    nntp_logoff( &testfd );

    // Initialize a handle to be used by the threads
    npost_t h;

    memcpy( &h, &param, sizeof(npost_param_t) );
    h.threads = NULL;
    h.head = NULL;
    h.tail = NULL;
    h.mut = malloc( sizeof(pthread_mutex_t) );
    pthread_mutex_init( h.mut, NULL);

    h.cond_list_empty = malloc( sizeof(pthread_cond_t) );
    pthread_cond_init( h.cond_list_empty, NULL );

    // Let's add parts to the queue!
    size_t blocksize = YENC_LINE_LENGTH * param.lines;
    for( int f = 0; f < param.n_split_files; f++ )
    {
        diskfile_t *df = &param.split_files[f];
        crc32_file( df );
        int parts = (param.split_files[f].filesize + blocksize - 1) / blocksize;

        for( int p = 0; p < parts; p++ )
        {
            if( h.head == NULL )
            {
                h.head = malloc( sizeof(npost_item_t) );
                h.tail = h.head;
            }
            else
            {
                h.tail->next = malloc( sizeof(npost_item_t) );
                h.tail = h.tail->next;
            }

            h.tail->filenum = f;
            h.tail->partnum = p;
            h.tail->next = NULL;
        }
    }

    // Initialize the threads, and give each thread its own copy of the handle
    h.threads = malloc( param.threads * sizeof(pthread_t) );

    for ( int i = 0; i < param.threads; i++ )
        pthread_create( &h.threads[i], NULL, poster_thread, &h );

    for( int i = 0; i < param.threads; i++ )
        pthread_join( h.threads[i], NULL );

    // free all the mallocs!
    free( h.threads );

    pthread_mutex_destroy( h.mut );
    free( h.mut );

    pthread_cond_destroy( h.cond_list_empty );
    free( h.cond_list_empty );

    free( param.server );
    free( param.username );
    free( param.password );
    free( param.name );
    free( param.email );
    free( param.newsgroups );
    free( param.comment );

    for ( int i = 0; i < param.n_input_files; i++ )
    {
        free( param.input_files[i].filename_in );
        free( param.input_files[i].filename_out );
    }
    free( param.input_files );

    for ( int i = 0; i < param.n_split_files; i++ )
    {
        free( param.split_files[i].filename_in );
        free( param.split_files[i].filename_out );
    }
    free( param.split_files );

    return 0;

}
Example #8
0
static void load_cart(char *file){
	FILE *fn;
	long l;
	int i, nb;

	app_data.crc = crc32_file(file);
	if (app_data.crc == 0xAFB23F89) app_data.exrom = 1;  /* Musician */
	if (app_data.crc == 0x3BFEF56B) app_data.exrom = 1;  /* Four in 1 Row! */
	if (app_data.crc == 0x9B5E9356) app_data.exrom = 1;  /* Four in 1 Row! (french) */

	if (((app_data.crc == 0x975AB8DA) || (app_data.crc == 0xE246A812)) && (!app_data.debug)) {
		fprintf(stderr,"Error: file %s is an incomplete ROM dump\n",file_v);
		exit(EXIT_FAILURE);
	}
	
    fn=fopen(file,"rb");
	if (!fn) {
		fprintf(stderr,"Error loading %s\n",file_v);
		exit(EXIT_FAILURE);
	}
	printf("Loading: \"%s\"  Size: ",file_v);
	l = filesize(fn);
	
    if ((l % 1024) != 0) {
		fprintf(stderr,"Error: file %s is an invalid ROM dump\n",file_v);
		exit(EXIT_FAILURE);
	}
		
  /* special MegaCART design by Soeren Gust */
	if ((l == 32768) || (l == 65536) || (l == 131072) || (l == 262144) || (l == 524288) || (l == 1048576)) {
		app_data.megaxrom = 1;
		app_data.bank = 1;
		megarom = malloc(1048576);
		if (megarom == NULL) {
			fprintf(stderr, "Out of memory loading %s\n", file);
			exit(EXIT_FAILURE);
			}
		if (fread(megarom, l, 1, fn) != 1) {
			fprintf(stderr,"Error loading %s\n",file);
			exit(EXIT_FAILURE);
		}
		
        /* mirror shorter files into full megabyte */
		if (l < 65536) memcpy(megarom+32768,megarom,32768);
		if (l < 131072) memcpy(megarom+65536,megarom,65536);
		if (l < 262144) memcpy(megarom+131072,megarom,131072);
		if (l < 524288) memcpy(megarom+262144,megarom,262144);
		if (l < 1048576) memcpy(megarom+524288,megarom,524288);
		/* start in bank 0xff */
		memcpy(&rom_table[0][1024], megarom + 4096*255 + 1024, 3072);
		printf("MegaCart %ldK", l / 1024);
		nb = 1;
	} else if (((l % 3072) == 0))
	  {
		app_data.three_k = 1;
		nb = l/3072;

		for (i=nb-1; i>=0; i--) {
			if (fread(&rom_table[i][1024],3072,1,fn) != 1) {
				fprintf(stderr,"Error loading %s\n",file);
				exit(EXIT_FAILURE);
			}
		}
		printf("%dK",nb*3);

	} else {

		nb = l/2048;

		if ((nb == 2) && (app_data.exrom)) {

			if (fread(&extROM[0], 1024,1,fn) != 1) {
				fprintf(stderr,"Error loading %s\n",file);
				exit(EXIT_FAILURE);
			}
			if (fread(&rom_table[0][1024],3072,1,fn) != 1) {
				fprintf(stderr,"Error loading %s\n",file);
				exit(EXIT_FAILURE);
			}
			printf("3K EXROM");

		} else {

			for (i=nb-1; i>=0; i--) {
				if (fread(&rom_table[i][1024],2048,1,fn) != 1) {
					fprintf(stderr,"Error loading %s\n",file);
					exit(EXIT_FAILURE);
				}
				memcpy(&rom_table[i][3072],&rom_table[i][2048],1024); /* simulate missing A10 */
			}
			printf("%dK",nb*2);

		}
	}
	fclose(fn);
	rom = rom_table[0];
	if (nb==1)
			app_data.bank = 1;
	else if (nb==2)
		app_data.bank = app_data.exrom ? 1 : 2;
	else if (nb==4)
		app_data.bank = 3;
	else 
		app_data.bank = 4;
	
    if ((rom_table[nb-1][1024+12]=='O') && (rom_table[nb-1][1024+13]=='P') && (rom_table[nb-1][1024+14]=='N') && (rom_table[nb-1][1024+15]=='B')) app_data.openb=1;
	
    printf("  CRC: %08lX\n",app_data.crc);
}
Example #9
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);
}
Example #10
0
bool retro_load_game(const struct retro_game_info *info)
{
    char bios_file_path[256];
    const char *full_path, *system_directory_c;

    enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565;
    if (!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt))
    {
        if (log_cb)
            log_cb(RETRO_LOG_INFO, "[O2EM]: RGB565 is not supported.\n");
        return false;
    }

    struct retro_input_descriptor desc[] = {
       { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT,  "Left" },
       { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP,    "Up" },
       { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN,  "Down" },
       { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "Right" },
       { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A,     "Fire" },

       { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT,  "Left" },
       { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP,    "Up" },
       { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN,  "Down" },
       { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "Right" },
       { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A,     "Action" },

       { 0 },
    };

   environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, desc);

    full_path = info->path;
    system_directory_c = NULL;

    // BIOS is required
    environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &system_directory_c);
    if (!system_directory_c)
    {
       if (log_cb)
          log_cb(RETRO_LOG_WARN, "[O2EM]: no system directory defined, unable to look for o2rom.bin\n");
       return false;
    }
    else
    {

#ifdef _WIN32
      char slash = '\\';
#else
      char slash = '/';
#endif

       snprintf(bios_file_path, sizeof(bios_file_path), "%s%c%s", system_directory_c, slash, "o2rom.bin");

       if (!does_file_exist(bios_file_path))
       {
          if (log_cb)
             log_cb(RETRO_LOG_WARN, "[O2EM]: o2rom.bin not found, cannot load BIOS\n");
          return false;
       }
    }

    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;
    app_data.fullscreen = 0;
    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();

    init_audio();

    app_data.crc = crc32_file(full_path);

    //suck_bios();
    o2flag = 1;

    crcx = app_data.crc;
    //suck_roms();

    load_bios(bios_file_path);

    load_cart(full_path);
    //if (app_data.voice) load_voice_samples(path2);

    init_display();

    init_cpu();

    init_system();

    set_score(app_data.scoretype, app_data.scoreaddress, app_data.default_highscore);

    return true;
}