Exemplo n.º 1
0
int NSFLoad(int fp)
{
  int x;

  FCEU_fseek(fp,0,SEEK_SET);
  FCEU_fread(&NSFHeader,1,0x80,fp);
  if(memcmp(NSFHeader.ID,"NESM\x1a",5))
                  return 0;
  NSFHeader.SongName[31]=NSFHeader.Artist[31]=NSFHeader.Copyright[31]=0;

  LoadAddr=NSFHeader.LoadAddressLow;
  LoadAddr|=NSFHeader.LoadAddressHigh<<8;

  if(LoadAddr<0x6000)
  {
   FCEUD_PrintError("Invalid load address.");
   return(0);
  }
  InitAddr=NSFHeader.InitAddressLow;
  InitAddr|=NSFHeader.InitAddressHigh<<8;

  PlayAddr=NSFHeader.PlayAddressLow;
  PlayAddr|=NSFHeader.PlayAddressHigh<<8;

  NSFSize=FCEU_fgetsize(fp)-0x80;

  NSFMaxBank=((NSFSize+(LoadAddr&0xfff)+4095)/4096);
  NSFMaxBank=uppow2(NSFMaxBank);

  if(!(NSFDATA=(uint8 *)FCEU_malloc(NSFMaxBank*4096)))
   return 0;

  FCEU_fseek(fp,0x80,SEEK_SET);
  memset(NSFDATA,0x00,NSFMaxBank*4096);
  FCEU_fread(NSFDATA+(LoadAddr&0xfff),1,NSFSize,fp);

  NSFMaxBank--;

  BSon=0;
  for(x=0;x<8;x++)
   BSon|=NSFHeader.BankSwitch[x];

 FCEUGameInfo.type=GIT_NSF;
 FCEUGameInfo.input[0]=FCEUGameInfo.input[1]=SI_GAMEPAD;
 FCEUGameInfo.cspecial=SIS_NSF;

 for(x=0;;x++)
 {
  if(NSFROM[x]==0x20)
  {
   NSFROM[x+1]=InitAddr&0xFF;
   NSFROM[x+2]=InitAddr>>8;
   NSFROM[x+8]=PlayAddr&0xFF;
   NSFROM[x+9]=PlayAddr>>8;
   break;
  }
 }
Exemplo n.º 2
0
int UNIFLoad(const char *name, FCEUFILE *fp)
{
	FCEU_fseek(fp,0,SEEK_SET);
	FCEU_fread(&unhead,1,4,fp);
	if(memcmp(&unhead,"UNIF",4))
		return 0;

	ResetCartMapping();

	ResetExState(0,0);
	ResetUNIF();
	if(!FCEU_read32le(&unhead.info,fp))
		goto aborto;
	if(FCEU_fseek(fp,0x20,SEEK_SET)<0)
		goto aborto;
	if(!LoadUNIFChunks(fp))
		goto aborto;
	{
		int x;
		struct md5_context md5;

		md5_starts(&md5);

		for(x=0;x<32;x++)
			if(malloced[x])
			{
				md5_update(&md5,malloced[x],mallocedsizes[x]);
			}
			md5_finish(&md5,UNIFCart.MD5);
			FCEU_printf(" ROM MD5:  0x");
			for(x=0;x<16;x++)
				FCEU_printf("%02x",UNIFCart.MD5[x]);
			FCEU_printf("\n");
			memcpy(&GameInfo->MD5,&UNIFCart.MD5,sizeof(UNIFCart.MD5));
	}

	if(!InitializeBoard())
		goto aborto;

	#if !defined(GEKKO)|| !defined(_XBOX)
	FCEU_LoadGameSave(&UNIFCart);
	#endif

	strcpy(LoadedRomFName,name); //For the debugger list
	GameInterface=UNIFGI;
	return 1;

aborto:

	FreeUNIF();
	ResetUNIF();


	return 0;
}
Exemplo n.º 3
0
int UNIFLoad(const char *name, int fp)
{
        FCEU_fseek(fp,0,SEEK_SET);
        FCEU_fread(&unhead,1,4,fp);
        if(memcmp(&unhead,"UNIF",4))
         return 0;

	ResetCartMapping();

        ResetExState(0,0);
        ResetUNIF();
        if(!FCEU_read32(&unhead.info,fp))
	 goto aborto;
        if(FCEU_fseek(fp,0x20,SEEK_SET)<0)
	 goto aborto;
        if(!LoadUNIFChunks(fp))
	 goto aborto;
	{
	 int x;
	 struct md5_context md5;

	 md5_starts(&md5);

	 for(x=0;x<32;x++)
	  if(malloced[x])
	  {
	   md5_update(&md5,malloced[x],mallocedsizes[x]);
	  }
	  md5_finish(&md5,UNIFCart.MD5);
          FCEU_printf(" ROM MD5:  0x");
          for(x=0;x<16;x++)
           FCEU_printf("%02x",UNIFCart.MD5[x]);
          FCEU_printf("\n");
	  memcpy(FCEUGameInfo.MD5,UNIFCart.MD5,sizeof(UNIFCart.MD5));
	}

        if(!InitializeBoard())
	 goto aborto;

	FCEU_LoadGameSave(&UNIFCart);
        GameInterface=UNIFGI;
        return 1;

	aborto:

	FreeUNIF();
	ResetUNIF();


	return 0;
}
Exemplo n.º 4
0
int LoadUNIFChunks(FCEUFILE *fp)
{
	int x;
	int t;
	for(;;)
	{
		t=FCEU_fread(&uchead,1,4,fp);
		if(t<4)
		{
			if(t>0)
				return 0;
			return 1;
		}
		if(!(FCEU_read32le(&uchead.info,fp)))
			return 0;
		t=0;
		x=0;
		//printf("Funky: %s\n",((uint8 *)&uchead));
		while(bfunc[x].name)
		{
			if(!memcmp(&uchead,bfunc[x].name,strlen(bfunc[x].name)))
			{
				if(!bfunc[x].init(fp))
					return 0;
				t=1;
				break;
			}
			x++;
		}
		if(!t)
			if(FCEU_fseek(fp,uchead.info,SEEK_CUR)<0)
				return(0);
	}
}
Exemplo n.º 5
0
int NSFLoad(const char *name, FCEUFILE *fp)
{
	int x;

	fprintf(stderr,"NSFLoad ...\n");

	FCEU_fseek(fp,0,SEEK_SET);
	FCEU_fread(&NSFHeader,1,0x80,fp);
	if(memcmp(NSFHeader.ID,"NESM\x1a",5))
		return 0;
	NSFHeader.SongName[31]=NSFHeader.Artist[31]=NSFHeader.Copyright[31]=0;

	LoadAddr=NSFHeader.LoadAddressLow;
	LoadAddr|=NSFHeader.LoadAddressHigh<<8;

	if(LoadAddr<0x6000)
	{
		FCEUD_PrintError("Invalid load address.");
		return(0);
	}
	InitAddr=NSFHeader.InitAddressLow;
	InitAddr|=NSFHeader.InitAddressHigh<<8;

	PlayAddr=NSFHeader.PlayAddressLow;
	PlayAddr|=NSFHeader.PlayAddressHigh<<8;

	NSFSize=FCEU_fgetsize(fp)-0x80;

	NSFMaxBank=((NSFSize+(LoadAddr&0xfff)+4095)/4096);
	NSFMaxBank=PRGsize[0]=uppow2(NSFMaxBank);

	if(!(NSFDATA=(uint8 *)FCEU_malloc(NSFMaxBank*4096)))
		return 0;

	FCEU_fseek(fp,0x80,SEEK_SET);
	memset(NSFDATA,0x00,NSFMaxBank*4096);
	FCEU_fread(NSFDATA+(LoadAddr&0xfff),1,NSFSize,fp);

	NSFMaxBank--;

	BSon=0;
	for(x=0;x<8;x++)
	{
		BSon|=NSFHeader.BankSwitch[x];
	}

	if(BSon==0)
	{
		BankCounter=0x00;
   
 		if ((NSFHeader.LoadAddressHigh & 0x70) >= 0x70)
		{
			//Ice Climber, and other F000 base address tunes need this
			BSon=0xFF;
		}
		else {
			for(x=(NSFHeader.LoadAddressHigh & 0x70) / 0x10;x<8;x++)
			{
				NSFHeader.BankSwitch[x]=BankCounter;
				BankCounter+=0x01; 
			}
			BSon=0;
			}
	}

	for(x=0;x<8;x++)
		BSon|=NSFHeader.BankSwitch[x];

	GameInfo->type=GIT_NSF;
	GameInfo->input[0]=GameInfo->input[1]=SI_GAMEPAD;
	GameInfo->cspecial=SIS_NSF;

	for(x=0;;x++)
	{
		if(NSFROM[x]==0x20)
		{
			NSFROM[x+1]=InitAddr&0xFF;
			NSFROM[x+2]=InitAddr>>8;
			NSFROM[x+8]=PlayAddr&0xFF;
			NSFROM[x+9]=PlayAddr>>8;
			break;
		}
	}