Example #1
0
void HuC_LoadCD(const char *bios_path)
{
 static const FileExtensionSpecStruct KnownBIOSExtensions[] =
 {
  { ".pce", gettext_noop("PC Engine ROM Image") },
  { ".bin", gettext_noop("PC Engine ROM Image") },
  { ".bios", gettext_noop("BIOS Image") },
  { NULL, NULL }
 };

 try
 {
	 MDFNFILE fp(bios_path, KnownBIOSExtensions, _("CD BIOS"));

	 memset(ROMSpace, 0xFF, 262144);

	 memcpy(ROMSpace, fp.Data() + (fp.Size() & 512), ((fp.Size() & ~512) > 262144) ? 262144 : (fp.Size() &~ 512) );

	 fp.Close();

	 PCE_IsCD = 1;
	 PCE_InitCD();

	 md5_context md5;
	 md5.starts();
	 // md5_update(&md5, HuCROM, 262144);

	 #if 0
	 int32 track = CDIF_GetFirstTrack();
	 int32 last_track = CDIF_GetLastTrack();
	 bool DTFound = 0;
	 for(; track <= last_track; track++)
	 {
		CDIF_Track_Format format;

		if(CDIF_GetTrackFormat(track, format) && format == CDIF_FORMAT_MODE1)
		{
		 DTFound = 1;
		 break;
		}
	 }

	 if(DTFound) // Only add the MD5 hash if we were able to find a data track.
	 {
		uint32 start_sector = CDIF_GetTrackStartPositionLBA(track);
		uint8 sector_buffer[2048];

		for(int x = 0; x < 128; x++)
		{
		 memset(sector_buffer, 0, 2048);
		 CDIF_ReadSector(sector_buffer, NULL, start_sector + x, 1);
		 md5.update(sector_buffer, 2048);
		}
	 }
	 md5.finish(MDFNGameInfo->MD5);
	 MDFN_printf(_("CD MD5(first 256KiB):   0x%s\n"), md5_context::asciistr(MDFNGameInfo->MD5, 0).c_str());
	 #endif

	 MDFN_printf(_("Arcade Card Emulation:  %s\n"), PCE_ACEnabled ? _("Enabled") : _("Disabled"));
	 for(int x = 0; x < 0x40; x++)
	 {
		HuCPUFastMap[x] = ROMSpace;
		PCERead[x] = HuCRead;
	 }

	 for(int x = 0x68; x < 0x88; x++)
	 {
		HuCPUFastMap[x] = ROMSpace;
		PCERead[x] = HuCRead;
		PCEWrite[x] = HuCRAMWrite;
	 }
	 PCEWrite[0x80] = HuCRAMWriteCDSpecial; 	// Hyper Dyne Special hack
	 MDFNMP_AddRAM(262144, 0x68 * 8192, ROMSpace + 0x68 * 8192);

	 if(PCE_ACEnabled)
	 {
			arcade_card = new ArcadeCard();

		for(int x = 0x40; x < 0x44; x++)
		{
		 HuCPUFastMap[x] = NULL;
		 PCERead[x] = ACPhysRead;
		 PCEWrite[x] = ACPhysWrite;
		}
	 }

	 gzFile srp;

	 memset(SaveRAM, 0x00, 2048);
	 memcpy(SaveRAM, BRAM_Init_String, 8);	// So users don't have to manually intialize the file cabinet
							// in the CD BIOS screen.

	 if((srp = gzopen(MDFN_MakeFName(MDFNMKF_SAV, 0, "sav").c_str(), "rb")))
	 {
		gzread(srp, SaveRAM, 2048);
		gzclose(srp);
	 }
	 PCEWrite[0xF7] = SaveRAMWrite;
	 PCERead[0xF7] = SaveRAMRead;
	 MDFNMP_AddRAM(2048, 0xF7 * 8192, SaveRAM);
 }
 catch(...)
 {
  Cleanup();
  throw;
 }
}
Example #2
0
static void DumpCUEISOWAV(void)
{
 FILE *cuep = fopen("cd.cue", "wb");

 for(int track = CDIF_GetFirstTrack(); track <= CDIF_GetLastTrack(); track++)
 {
  CDIF_Track_Format format;
  uint32 sectors;

  sectors = cdrfile_get_track_sec_count(p_cdrfile, track);
  CDIF_GetTrackFormat(track, format);

  if(format == CDIF_FORMAT_AUDIO)
  {
   char buf[256];
   sprintf(buf, "%d.wav", track);

   static SNDFILE *sfp;
   SF_INFO slinfo;
   memset(&slinfo, 0, sizeof(SF_INFO));

   fprintf(cuep, "FILE \"%s\" WAVE\n", buf);
   fprintf(cuep, " TRACK %02d AUDIO\n", track);
   fprintf(cuep, "  INDEX 01 00:00:00\n");

   slinfo.samplerate = 44100;
   slinfo.channels = 2;
   slinfo.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16;

   sfp = sf_open(buf, SFM_WRITE, &slinfo);
   for(uint32 i = 0; i < sectors; i++)
   {
    uint8 secbuf[2352];

    CDIF_ReadAudioSector((int16*)secbuf, NULL, CDIF_GetTrackStartPositionLBA(track) + i);

    sf_writef_short(sfp, (int16*)secbuf, 2352 / 4);
   }
   sf_close(sfp);
  }
  else
  {
   char buf[256];
   sprintf(buf, "%d.iso", track);
   FILE *fp = fopen(buf, "wb");

   fprintf(cuep, "FILE \"%s\" BINARY\n", buf);
   fprintf(cuep, " TRACK %02d MODE1/2048\n", track);
   fprintf(cuep, "  INDEX 01 00:00:00\n");


   for(uint32 i = 0; i < sectors; i++)
   {
    uint8 secbuf[2048];
    CDIF_ReadSector(secbuf, NULL, CDIF_GetTrackStartPositionLBA(track) + i, 1);
    fwrite(secbuf, 1, 2048, fp);
   }
   fclose(fp);
  }
 }
 fclose(cuep);
}