Ejemplo n.º 1
0
/* ID666
   ---------------------------------------------------------------- */
int SPC_get_id666 (const char *filename, SPC_ID666 * id)
{
    int err;
    FILE *fp;
    SPC_ID666 dummyid;

    if (id == NULL) {
        id = &dummyid;
    }

    fp = fopen(filename, "rb");
    if (fp == NULL) {
        return FALSE;
    }

    err = read_id666(fp, id);

    fclose(fp);

    return err ? FALSE : TRUE;
}
Ejemplo n.º 2
0
/* Load SPC file [CLEANUP]
   ---------------------------------------------------------------- */
int SPC_load (const char *fname, SPC_ID666 * id)
{
    FILE *fp;
    char temp[64];

    if (id) {
        memset(id, 0, sizeof(*id));
    }

    fp = fopen (fname, "rb");
    if (!fp)
        return FALSE;

    read_id666(fp, id);

    IAPU.OneCycle = ONE_APU_CYCLE; /* VP : moved this before call to S9xResetAPU !! */

    S9xInitAPU();
    S9xResetAPU();

    fseek(fp, 0x25, SEEK_SET);
    fread(&BackupAPURegisters.PC, 1, 2, fp);
    fread(&BackupAPURegisters.YA.B.A, 1, 1, fp);
    fread(&BackupAPURegisters.X, 1, 1, fp);
    fread(&BackupAPURegisters.YA.B.Y, 1, 1, fp);
    fread(&BackupAPURegisters.P, 1, 1, fp);
    fread(&BackupAPURegisters.S, 1, 1, fp);

    fseek(fp, 0x100, SEEK_SET);
    fread(BackupAPURAM, 1, 0x10000, fp);
    fread(BackupDSPRAM, 1, 128, fp);
    fread(temp, 1, 64, fp);
    fread(BackupAPUExtraRAM, 1, 64, fp);

    fclose(fp);

    RestoreSPC();

    return TRUE;
}
Ejemplo n.º 3
0
int main(int argc, char **argv)
{
	int res, i;
	int use_ppdev=0;
	int use_ppio=0;
	int io_specified=0;
	int reset_and_exit=0, status_line=1, loop=0, play_and_exit=0;
	char *filename;
	FILE *fptr=NULL;
	id666_tag tag;
	struct timeval tv_before, tv_now;
	
	signal(SIGINT, signal_handler);

	while((res =getopt(argc, argv, 

					"rslvhxed"
#ifdef PPDEV_SUPPORTED
					"p"
#endif
#ifdef PPIO_SUPPORTED
					"i"
#endif
					))>=0)
	{
		switch(res)
		{
			case 'd':
				g_debug = 1;
				break;
			case 'e':
				g_use_embedded = 1;
				break;
			case 'v':
				g_verbose = 1;
				break;
			case 's':
				status_line = 0;
				break;
			case 'l':
				loop = 1;
				break;
			case 'r':
				reset_and_exit = 1;
				break;
			case 'h':
				printhelp();
				return 0;
			case 'x':
				play_and_exit = 1;
				break;
#ifdef PPDEV_SUPPORTED
			case 'p':
				use_ppdev = 1;
				io_specified = 1;
				break;
#endif
#ifdef PPIO_SUPPORTED
			case 'i':
				use_ppio = 1;
				io_specified = 1;
				break;
#endif
			case '?':
				fprintf(stderr, "Unknown argument. try -h\n");
				return -1;
		}
	}

	
	if (argc-optind<=0 && !reset_and_exit) {
		fprintf(stderr, "No file specified. Try -h\n");
		return -2;
	}

#ifdef PPDEV_SUPPORTED
	if (!io_specified) {
		use_ppdev = 1;
		io_specified = 1;
	}
#endif

#ifdef PPIO_SUPPORTED
	if (!io_specified) {
		use_ppio = 1;
		io_specified = 1;
	}
#endif

	if (!io_specified) {
		fprintf(stderr, "No io layer for apu compiled\n");
		return -3;
	}
	
#ifdef PPDEV_SUPPORTED
	if (use_ppdev) {
		apu_ops = apu_ppdev_getOps();
	} 
	else 
#endif

#ifdef PPIO_SUPPORTED
	if (use_ppio)
	{
		apu_ops = apu_ppio_getOps();
	}
#endif


	apu_setOps(apu_ops);

	/* initialize the interface with the module.
	 * (Open device, get io permissions, etc...) */
	if (apu_ops->init("")<0) {
		return 1;
	}
	
	if (reset_and_exit) 
	{
		if (g_verbose) { printf("Resetting APU\n"); }					
		apu_reset();

		return 0;
	}



	for (i = optind; i<argc; i++)
	{
		if (g_exit_now) { break; }

		filename = argv[i];
			
		fptr = fopen(filename, "rb");
		if (fptr==NULL) { perror("fopen"); return 1; }

		read_id666(fptr, &tag);
	
		g_playing = 1;

                time_t start, end;
                start = time (NULL);

		printf("Now loading '%s'", filename);
		if (g_use_embedded) {
			printf(" using 'embedded' algo\n");
			if (LoadAPU_embedded(fptr)<0) { break; }
		} else  {
			printf("  \n");
			if (LoadAPU(fptr)<0) { break; }
		}

                end = time (NULL);
                printf("Took %ld seconds to load APU.\n", (end - start) );


		if (!g_playing) { continue; } // next
		if (g_exit_now) { break; }

		BOLD(); printf("Title: "); NORMAL();
		printf("%s\n", tag.title);
		BOLD(); printf("Game Title: "); NORMAL();
		printf("%s\n", tag.game_title);
		BOLD(); printf("Dumper: "); NORMAL();
		printf("%s\n", tag.name_of_dumper);
		BOLD(); printf("Comments: "); NORMAL();
		printf("%s\n", tag.comments);
		BOLD(); printf("Seconds: "); NORMAL();
		printf("%s\n", tag.seconds_til_fadeout);

		fclose(fptr);

		if (play_and_exit) {
			return 0;
		}

		gettimeofday(&tv_before, NULL);
		
		{
			int elaps_sec;
			int num_sec = atoi(tag.seconds_til_fadeout);
			int last_elaps_sec=-1;
	
			if (num_sec<1 || num_sec>999) {
				num_sec = 150;
			}
			if (strlen(tag.title)==0) {
				strncpy(tag.title, filename, 32);
			}
			
			if (g_exit_now) { break; }
			while (g_playing)
			{
				gettimeofday(&tv_now, NULL);
				elaps_sec = tv_now.tv_sec - tv_before.tv_sec;
				if (elaps_sec > num_sec) { break; }
				
				if (status_line)
				{
					if (last_elaps_sec != elaps_sec)
					{
						if (!loop) {
							BOLD(); printf("Time: "); NORMAL();
							printTime(elaps_sec);
							printf(" [");
							printTime(num_sec - elaps_sec);
							printf("] of ");
							printTime(num_sec);
							printf(" \r");
						}
						else {
							BOLD(); printf("Time: "); NORMAL();
							printTime(elaps_sec);
							printf(" \r");
						}
					}
					last_elaps_sec = elaps_sec;
					fflush(stdout);
				}
						
				usleep(7500); // update every 75 ms
			}
			if (g_playing)
				printf("\nFinished playing.\n");
			
			apu_reset();
			if (g_exit_now) { break; }
		}
		
	}
	
	apu_reset();

	return 0;
}