Esempio n. 1
0
CRom::CRom(const char *romfile)
{
	mWriteEnable=FALSE;
	Reset();

	// Initialise ROM
	for(int loop=0;loop<ROM_SIZE;loop++) mRomData[loop]=DEFAULT_ROM_CONTENTS;

	// Load up the file

	MDFNFILE BIOSFile;

	if(!BIOSFile.Open(romfile, NULL, _("Lynx Boot ROM")))
	{
	 throw MDFN_Error(0, "");	// FIXME: (make MDFNFILE throw exceptions instead of calling MDFN_PrintError())
	}

	if(BIOSFile.Size() < 512)
	{
	 throw MDFN_Error(0, _("The Lynx Boot ROM Image is an incorrect size."));
	}

	memcpy(mRomData, BIOSFile.Data(), 512);

	BIOSFile.Close();
}
Esempio n. 2
0
CRom::CRom(const char *romfile)
{
   unsigned loop;
   mWriteEnable=FALSE;
   Reset();

   // Initialise ROM
   for(loop = 0;loop < ROM_SIZE;loop++)
      mRomData[loop]=DEFAULT_ROM_CONTENTS;

   // Load up the file

   MDFNFILE BIOSFile;

   if(!BIOSFile.Open(romfile, NULL, _("Lynx Boot ROM")))
   {
      /* Could not open Lynx boot ROM. */
      return;
   }

   if(BIOSFile.f_size < 512)
   {
      /* Lynx Boot ROM image is of an incorrect size. */
      return;
   }

   memcpy(mRomData, BIOSFile.f_data, 512);

   BIOSFile.Close();
}
Esempio n. 3
0
void vbjinInit() {

	return;
	MDFNGameInfo = &EmulatedVB;

	MDFNFILE* fp = new MDFNFILE();
	fp->Open("C:\\wario.vb",NULL);
	MDFNGameInfo->Load(NULL,fp);

//	initialized = true;

	//	extern void VBINPUT_SetInput(int port, const char *type, void *ptr);

	const char * typez;
	//const char * padData;
//	padData = malloc(8);
	typez = (const char*)malloc(16);
	MDFNGameInfo->SetInput(1,typez,&pcejin.pads[0]);
//	MDFNGameInfo->SetInput(1,typez,adData);

	sndinit();

	MDFNGameInfo->SetSoundRate(44100);



	MDFNGI *CurGame=NULL;

	CurGame = MDFNGameInfo;
	VTBuffer[0] = new MDFN_Surface(NULL, CurGame->pitch / sizeof(uint32), CurGame->fb_height, CurGame->pitch / sizeof(uint32), MDFN_COLORSPACE_RGB, 0, 8, 16, 24);
	VTBuffer[1] = new MDFN_Surface(NULL, CurGame->pitch / sizeof(uint32), CurGame->fb_height, CurGame->pitch / sizeof(uint32), MDFN_COLORSPACE_RGB, 0, 8, 16, 24);
	VTLineWidths[0] = (MDFN_Rect *)calloc(CurGame->fb_height, sizeof(MDFN_Rect));
	VTLineWidths[1] = (MDFN_Rect *)calloc(CurGame->fb_height, sizeof(MDFN_Rect));
}
Esempio n. 4
0
// Return FALSE on fatal error(IPS file found but couldn't be applied),
// or TRUE on success(IPS patching succeeded, or IPS file not found).
static bool LoadIPS(MDFNFILE &GameFile, const char *path)
{
    FILE *IPSFile;

    MDFN_printf(_("Applying IPS file \"%s\"...\n"), path);

    IPSFile = fopen(path, "rb");
    if(!IPSFile)
    {
        ErrnoHolder ene(errno);

        MDFN_printf(_("Failed: %s\n"), ene.StrError());

        if(ene.Errno() == ENOENT)
            return(1);
        else
        {
            MDFN_PrintError(_("Error opening IPS file: %s\n"), ene.StrError());
            return(0);
        }
    }

    if(!GameFile.ApplyIPS(IPSFile))
    {
        fclose(IPSFile);
        return(0);
    }
    fclose(IPSFile);

    return(1);
}
Esempio n. 5
0
	static int								ModuleLoad				()
	{
		//Load the BIOS
		MDFNFILE biosFile;
		if(biosFile.Open(MDFN_MakeFName(MDFNMKF_FIRMWARE, 0, MDFN_GetSettingS("pcsxr.bios").c_str()).c_str(), 0))
		{
			if(biosFile.size == 512 * 1024)
			{
				memcpy(BiosBuffer, biosFile.data, 512 * 1024);
			}
			else
			{
				MDFN_printf("pcsxr: BIOS file size incorrect\n");
			}
		}
		else
		{
			MDFN_printf("pcsxr: Failed to load bios\n");
			return 0;
		}
	
		//Setup the config structure
		memset(&Config, 0, sizeof(Config));
		Config.PsxAuto = 1;
		Config.Cpu = MDFN_GetSettingB("pcsxr.recompiler") ? CPU_DYNAREC : CPU_INTERPRETER;
		Config.SlowBoot = MDFN_GetSettingB("pcsxr.slowboot");
		strcpy(Config.PluginsDir, "builtin");
		strcpy(Config.Gpu, "builtin");
		strcpy(Config.Spu, "builtin");
		strcpy(Config.Pad1, "builtin");
		strcpy(Config.Pad2, "builtin");
		strcpy(Config.Cdr, "builtin");
		strcpy(Config.Net, "Disabled");
		strncpy(Config.Mcd1, MDFN_MakeFName(MDFNMKF_SAV, 0, "sav").c_str(), MAXPATHLEN);
		strncpy(Config.Mcd2, MDFN_MakeFName(MDFNMKF_SAV, 0, "sav2").c_str(), MAXPATHLEN);

		//Init psx cpu emulator and memory mapping
		EmuInit();

		//Open and initialize all of the plugins
		OpenPlugins();

		//Load memory cards
		LoadMcds(Config.Mcd1, Config.Mcd2);

		//Get cdrom ID and init PPF support...
		CheckCdrom();

		//Reset the emulated CPU and Memory
		EmuReset();

		//Prepares the game to run, either runs the CPU thru the bios or finds and loads the game EXE if using the emulated bios
		LoadCdrom();

		//TODO: Set the clock if the machine is PAL

		//Just say two 1M pages, for fun not profit
		MDFNMP_Init(1024 * 1024, 2);
		MDFNMP_AddRAM(1024 * 1024 * 2, 0, (uint8_t*)psxM);

		return 1;
	}
Esempio n. 6
0
MDFNGI *MDFNI_LoadGame(const char *force_module, const char *name)
{
    MDFNFILE GameFile;
    struct stat stat_buf;
    std::vector<FileExtensionSpecStruct> valid_iae;

    if(strlen(name) > 4 && (!strcasecmp(name + strlen(name) - 4, ".cue") || !strcasecmp(name + strlen(name) - 4, ".toc") || !strcasecmp(name + strlen(name) - 4, ".m3u")))
    {
        return(MDFNI_LoadCD(force_module, name));
    }

    if(!stat(name, &stat_buf) && !S_ISREG(stat_buf.st_mode))
    {
        return(MDFNI_LoadCD(force_module, name));
    }

    MDFNI_CloseGame();

    LastSoundMultiplier = 1;

    MDFNGameInfo = NULL;

    MDFN_printf(_("Loading %s...\n"),name);

    MDFN_indent(1);

    GetFileBase(name);

    // Construct a NULL-delimited list of known file extensions for MDFN_fopen()
    for(unsigned int i = 0; i < MDFNSystems.size(); i++)
    {
        const FileExtensionSpecStruct *curexts = MDFNSystems[i]->FileExtensions;

        // If we're forcing a module, only look for extensions corresponding to that module
        if(force_module && strcmp(MDFNSystems[i]->shortname, force_module))
            continue;

        if(curexts)
            while(curexts->extension && curexts->description)
            {
                valid_iae.push_back(*curexts);
                curexts++;
            }
    }
    {
        FileExtensionSpecStruct tmpext = { NULL, NULL };
        valid_iae.push_back(tmpext);
    }

    if(!GameFile.Open(name, &valid_iae[0], _("game")))
    {
        MDFNGameInfo = NULL;
        return 0;
    }

    if(!LoadIPS(GameFile, MDFN_MakeFName(MDFNMKF_IPS, 0, 0).c_str()))
    {
        MDFNGameInfo = NULL;
        GameFile.Close();
        return(0);
    }

    MDFNGameInfo = NULL;

    for(std::list<MDFNGI *>::iterator it = MDFNSystemsPrio.begin(); it != MDFNSystemsPrio.end(); it++)  //_unsigned int x = 0; x < MDFNSystems.size(); x++)
    {
        char tmpstr[256];
        trio_snprintf(tmpstr, 256, "%s.enable", (*it)->shortname);

        if(force_module)
        {
            if(!strcmp(force_module, (*it)->shortname))
            {
                if(!(*it)->Load)
                {
                    GameFile.Close();

                    if((*it)->LoadCD)
                        MDFN_PrintError(_("Specified system only supports CD(physical, or image files, such as *.cue and *.toc) loading."));
                    else
                        MDFN_PrintError(_("Specified system does not support normal file loading."));
                    MDFN_indent(-1);
                    MDFNGameInfo = NULL;
                    return 0;
                }
                MDFNGameInfo = *it;
                break;
            }
        }
        else
        {
            // Is module enabled?
            if(!MDFN_GetSettingB(tmpstr))
                continue;

            if(!(*it)->Load || !(*it)->TestMagic)
                continue;

            if((*it)->TestMagic(name, &GameFile))
            {
                MDFNGameInfo = *it;
                break;
            }
        }
    }

    if(!MDFNGameInfo)
    {
        GameFile.Close();

        if(force_module)
            MDFN_PrintError(_("Unrecognized system \"%s\"!"), force_module);
        else
            MDFN_PrintError(_("Unrecognized file format.  Sorry."));

        MDFN_indent(-1);
        MDFNGameInfo = NULL;
        return 0;
    }

    MDFN_printf(_("Using module: %s(%s)\n\n"), MDFNGameInfo->shortname, MDFNGameInfo->fullname);
    MDFN_indent(1);

    assert(MDFNGameInfo->soundchan != 0);

    MDFNGameInfo->soundrate = 0;
    MDFNGameInfo->name = NULL;
    MDFNGameInfo->rotated = 0;

    if(MDFNGameInfo->Load(name, &GameFile) <= 0)
    {
        GameFile.Close();
        MDFN_indent(-2);
        MDFNGameInfo = NULL;
        return(0);
    }

    if(MDFNGameInfo->GameType != GMT_PLAYER)
    {
        MDFN_LoadGameCheats(NULL);
        MDFNMP_InstallReadPatches();
    }

    MDFNI_SetLayerEnableMask(~0ULL);

#ifdef WANT_DEBUGGER
    MDFNDBG_PostGameLoad();
#endif

    MDFNSS_CheckStates();
    MDFNMOV_CheckMovies();

    MDFN_ResetMessages();	// Save state, status messages, etc.

    MDFN_indent(-2);

    if(!MDFNGameInfo->name)
    {
        unsigned int x;
        char *tmp;

        MDFNGameInfo->name = (UTF8 *)strdup(GetFNComponent(name));

        for(x=0; x<strlen((char *)MDFNGameInfo->name); x++)
        {
            if(MDFNGameInfo->name[x] == '_')
                MDFNGameInfo->name[x] = ' ';
        }
        if((tmp = strrchr((char *)MDFNGameInfo->name, '.')))
            *tmp = 0;
    }

    PrevInterlaced = false;
    deint.ClearState();

    TBlur_Init();

    MDFN_StateEvilBegin();


    last_sound_rate = -1;
    memset(&last_pixel_format, 0, sizeof(MDFN_PixelFormat));

    return(MDFNGameInfo);
}
Esempio n. 7
0
int HuCLoadCD(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 }
 };

 MDFNFILE fp;

 if(!fp.Open(bios_path, KnownBIOSExtensions, _("CD BIOS")))
 {
  return(0);
 }

 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();
   if(!arcade_card)
   {
    MDFN_PrintError(_("Error creating %s object"), "ArcadeCard");
    //Cleanup();	// TODO
    return(0);
   }

  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);
 return(1);
}
Esempio n. 8
0
MDFNGI *MDFNI_LoadGame(const char *force_module, const char *name)
{
   MDFNFILE GameFile;
	std::vector<FileExtensionSpecStruct> valid_iae;
   MDFNGameInfo = MDFNGI_CORE;

	MDFN_printf(_("Loading %s...\n"),name);

	MDFN_indent(1);

	// Construct a NULL-delimited list of known file extensions for MDFN_fopen()
   const FileExtensionSpecStruct *curexts = MDFNGameInfo->FileExtensions;

   while(curexts->extension && curexts->description)
   {
      valid_iae.push_back(*curexts);
      curexts++;
   }

	if(!GameFile.Open(name, &valid_iae[0], _("game")))
   {
      MDFNGameInfo = NULL;
      return 0;
   }

	MDFN_printf(_("Using module: %s(%s)\n\n"), MDFNGameInfo->shortname, MDFNGameInfo->fullname);
	MDFN_indent(1);

	//
	// Load per-game settings
	//
	// Maybe we should make a "pgcfg" subdir, and automatically load all files in it?
	// End load per-game settings
	//

   if(MDFNGameInfo->Load(name, &GameFile) <= 0)
   {
      GameFile.Close();
      MDFN_indent(-2);
      MDFNGameInfo = NULL;
      return(0);
   }

	MDFN_LoadGameCheats(NULL);
	MDFNMP_InstallReadPatches();

	MDFN_ResetMessages();	// Save state, status messages, etc.

	MDFN_indent(-2);

	if(!MDFNGameInfo->name)
   {
      unsigned int x;
      char *tmp;

      MDFNGameInfo->name = (UTF8 *)strdup(GetFNComponent(name));

      for(x=0;x<strlen((char *)MDFNGameInfo->name);x++)
      {
         if(MDFNGameInfo->name[x] == '_')
            MDFNGameInfo->name[x] = ' ';
      }
      if((tmp = strrchr((char *)MDFNGameInfo->name, '.')))
         *tmp = 0;
   }

   return(MDFNGameInfo);
}
Esempio n. 9
0
int HuCLoadCD(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 }
 };

 MDFNFILE fp;

 if(!fp.Open(bios_path, KnownBIOSExtensions, "CD BIOS"))
  return(0);

 memset(ROMSpace, 0xFF, 262144);

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

 fp.Close();

 PCE_IsCD = 1;
 PCE_InitCD();

 md5_context md5;
 md5.starts();

 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)
 {
   try
   {
    arcade_card = new ArcadeCard();
   }
   catch(std::exception &e)
   {
    MDFN_PrintError(_("Error creating %s object: %s"), "ArcadeCard", e.what());
    return(0);
   }

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

 FILE *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 = fopen(MDFN_MakeFName(MDFNMKF_SAV, 0, "sav").c_str(), "rb")))
 {
  fread(SaveRAM, 2048, 1, srp);
  fclose(srp);
 }
 PCEWrite[0xF7] = SaveRAMWrite;
 PCERead[0xF7] = SaveRAMRead;
 MDFNMP_AddRAM(2048, 0xF7 * 8192, SaveRAM);
 return(1);
}