Beispiel #1
0
static void InitializeBoard(void)
{
   if(!sboardname)
    throw MDFN_Error(0, _("Missing UNIF board name."));

   for(auto const& bm : bmap)
   {
    if(!strcmp((char *)sboardname, (char *)bm.name))
    {
     for(unsigned i = 0; i < 16; i++)
     {
      if((bm.prg_rm & (1U << i)) && !malloced[i])
       throw MDFN_Error(0, _("Missing PRG ROM %u."), i);
     }

     if(!malloced[16])
     {
      if(bm.flags & BMCFLAG_32KCHRR)
	CHRRAMSize = 32768;
      else
	CHRRAMSize = 8192;

      UNIFchrrama = (uint8 *)MDFN_malloc_T(CHRRAMSize, _("CHR RAM"));
      SetupCartCHRMapping(0,UNIFchrrama,CHRRAMSize,1);
     }

     if(bm.flags & BMCFLAG_FORCE4)
      mirrortodo=4;
     InitBoardMirroring();
     bm.init(&UNIFCart);
     return;
    }
   }
   throw MDFN_Error(0, _("Board type not supported."));
}
Beispiel #2
0
static void LoadPRG(Stream *fp)
{
 uint32 t;
 unsigned z;

 z = uchead.ID[3] - '0';	// FIXME hex

 if(z > 15)
  throw MDFN_Error(0, "Invalid PRG ROM index '%c'.\n", uchead.ID[3]);

 MDFN_printf(_("PRG ROM %u size: %u\n"), z, uchead.info);

 if(malloced[z])
  free(malloced[z]);

 t = FixRomSize(uchead.info, 2048);

 malloced[z] = (uint8 *)MDFN_malloc_T(t, _("PRG ROM"));
 mallocedsizes[z] = t;
 memset(malloced[z] + uchead.info, 0xFF, t - uchead.info);

 fp->read(malloced[z], uchead.info);

 SetupCartPRGMapping(z,malloced[z],t,0); 
}
Beispiel #3
0
static void InitBoardMirroring(void)
{
 if(mirrortodo<0x4)
  SetupCartMirroring(mirrortodo,1,0);
 else if(mirrortodo==0x4)
 {
  exntar = (uint8 *)MDFN_malloc_T(2048, _("Nametable RAM"));
  SetupCartMirroring(4,1,exntar);
 }
 else
  SetupCartMirroring(0,0,0);
}
Beispiel #4
0
static void SetBoardName(Stream *fp)
{
 assert(uchead.info <= (SIZE_MAX - 1));
 boardname = (uint8*)MDFN_malloc_T((size_t)uchead.info + 1, _("Board Name"));

 fp->read(boardname, uchead.info);
 boardname[uchead.info] = 0;
 MDFN_RemoveControlChars((char*)boardname);

 MDFN_printf(_("Board name: %s\n"), boardname);
 sboardname=boardname;
 if(!memcmp(boardname,"NES-",4) || !memcmp(boardname,"UNL-",4) || !memcmp(boardname,"HVC-",4) || !memcmp(boardname,"BTL-",4) || !memcmp(boardname,"BMC-",4))
  sboardname+=4;
}
Beispiel #5
0
void MDFNSS_GetStateInfo(const char *filename, StateStatusStruct *status)
{
 uint32 StateShowPBWidth;
 uint32 StateShowPBHeight;
 uint8 *previewbuffer = NULL;

 try
 {
  GZFileStream fp(filename, GZFileStream::MODE::READ);
  uint8 header[32];

  fp.read(header, 32);

  uint32 width = MDFN_de32lsb(header + 24);
  uint32 height = MDFN_de32lsb(header + 28);

  if(width > 1024)
   width = 1024;

  if(height > 1024)
   height = 1024;

  previewbuffer = (uint8 *)MDFN_malloc_T(3 * width * height, _("Save state preview buffer"));
  fp.read(previewbuffer, 3 * width * height);

  StateShowPBWidth = width;
  StateShowPBHeight = height;
 }
 catch(std::exception &e)
 {
  if(previewbuffer != NULL)
  {
   MDFN_free(previewbuffer);
   previewbuffer = NULL;
  }

  StateShowPBWidth = MDFNGameInfo->nominal_width;
  StateShowPBHeight = MDFNGameInfo->nominal_height;
 }

 status->gfx = previewbuffer;
 status->w = StateShowPBWidth;
 status->h = StateShowPBHeight;
}
Beispiel #6
0
static void NAME(Stream *fp)
{
 char* namebuf = NULL;

 assert(uchead.info <= (SIZE_MAX - 1));
 namebuf = (char*)MDFN_malloc_T((size_t)uchead.info + 1, "Name");

 fp->read(namebuf, uchead.info);

 namebuf[uchead.info] = 0;
 MDFN_RemoveControlChars(namebuf);

 MDFN_printf(_("Name: %s\n"), namebuf);

 if(!MDFNGameInfo->name)
  MDFNGameInfo->name = namebuf;
 else
 {
  free(namebuf);
  namebuf = NULL;
 }
}
Beispiel #7
0
//-----------------------------------------------------------------------------
// rom_loaded()
//-----------------------------------------------------------------------------
void rom_loaded(void)
{
	//Extract the header
	rom_header = (RomHeader*)(ngpc_rom.data);

	//Rom Name
	for(int i = 0; i < 12; i++)
	{
		if (rom_header->name[i] >= 32 && rom_header->name[i] < 128)
			ngpc_rom.name[i] = rom_header->name[i];
		else
			ngpc_rom.name[i] = ' ';
	}
	ngpc_rom.name[12] = 0;

	rom_hack();	//Apply a hack if required!

	rom_display_header();

	ngpc_rom.orig_data = (uint8 *)MDFN_malloc_T(ngpc_rom.length, _("ROM FLASH backup"));
	memcpy(ngpc_rom.orig_data, ngpc_rom.data, ngpc_rom.length);
}
Beispiel #8
0
MD_Cart_Type_SRAM::MD_Cart_Type_SRAM(const md_game_info *ginfo, const uint8 *ROM, const uint32 ROM_size)
{
 this->rom = ROM;
 this->rom_size = ROM_size;

 sram_start = ginfo->sram_start;
 sram_end = ginfo->sram_end;

 sram_size = 0;

 sram_start &= 0xFFFFFE;
 sram_end |= 0x000001;

 if((uint32)(sram_end - sram_start) >= 0x10000 || sram_start == sram_end)
 {
  sram_end = sram_start + 0xFFFF;
 }
 sram_size = sram_end - sram_start + 1;

 //printf("%08x %08x %08x\n", sram_start, sram_end, sram_size);

 sram = (uint8 *)MDFN_malloc_T(sram_size, _("Cart SRAM"));
 memset(sram, 0xFF, sram_size);
}
Beispiel #9
0
uint32 HuC_Load(MDFNFILE* fp)
{
 uint32 crc = 0;

 try
 {
  uint32 sf2_threshold = 2048 * 1024;
  uint32 sf2_required_size = 2048 * 1024 + 512 * 1024;
  uint64 len = fp->size();
  uint64 m_len = (len + 8191)&~8191;
  bool sf2_mapper = FALSE;

  if(m_len >= sf2_threshold)
  {
   sf2_mapper = TRUE;

   if(m_len != sf2_required_size)
    m_len = sf2_required_size;
  }

  IsPopulous = 0;
  PCE_IsCD = 0;


  HuCROM = (uint8 *)MDFN_malloc_T(m_len, _("HuCard ROM"));
  memset(HuCROM, 0xFF, m_len);
  fp->read(HuCROM, std::min<uint64>(m_len, len));

  md5_context md5;
  md5.starts();
  md5.update(HuCROM, std::min<uint64>(m_len, len));
  md5.finish(MDFNGameInfo->MD5);

  crc = crc32(0, HuCROM, std::min<uint64>(m_len, len));

  MDFN_printf(_("ROM:       %lluKiB\n"), (unsigned long long)(std::min<uint64>(m_len, len) / 1024));
  MDFN_printf(_("ROM CRC32: 0x%04x\n"), crc);
  MDFN_printf(_("ROM MD5:   0x%s\n"), md5_context::asciistr(MDFNGameInfo->MD5, 0).c_str());

  memset(ROMSpace, 0xFF, 0x88 * 8192 + 8192);

  if(m_len == 0x60000)
  {
   memcpy(ROMSpace + 0x00 * 8192, HuCROM, 0x20 * 8192);
   memcpy(ROMSpace + 0x20 * 8192, HuCROM, 0x20 * 8192);
   memcpy(ROMSpace + 0x40 * 8192, HuCROM + 0x20 * 8192, 0x10 * 8192);
   memcpy(ROMSpace + 0x50 * 8192, HuCROM + 0x20 * 8192, 0x10 * 8192);
   memcpy(ROMSpace + 0x60 * 8192, HuCROM + 0x20 * 8192, 0x10 * 8192);
   memcpy(ROMSpace + 0x70 * 8192, HuCROM + 0x20 * 8192, 0x10 * 8192);
  }
  else if(m_len == 0x80000)
  {
   memcpy(ROMSpace + 0x00 * 8192, HuCROM, 0x40 * 8192);
   memcpy(ROMSpace + 0x40 * 8192, HuCROM + 0x20 * 8192, 0x20 * 8192);
   memcpy(ROMSpace + 0x60 * 8192, HuCROM + 0x20 * 8192, 0x20 * 8192);
  }
  else
  {
   memcpy(ROMSpace + 0x00 * 8192, HuCROM, (m_len < 1024 * 1024) ? m_len : 1024 * 1024);
  }

  for(int x = 0x00; x < 0x80; x++)
  {
   HuCPUFastMap[x] = ROMSpace;
   PCERead[x] = HuCRead;
  }

  if(!memcmp(HuCROM + 0x1F26, "POPULOUS", strlen("POPULOUS")))
  {
   uint8 *PopRAM = ROMSpace + 0x40 * 8192;
   memset(PopRAM, 0xFF, 32768);

   LoadSaveMemory(MDFN_MakeFName(MDFNMKF_SAV, 0, "sav"), PopRAM, 32768);

   IsPopulous = 1;

   MDFN_printf("Populous\n");

   for(int x = 0x40; x < 0x44; x++)
   {
    HuCPUFastMap[x] = &PopRAM[(x & 3) * 8192] - x * 8192;
    PCERead[x] = HuCRead;
    PCEWrite[x] = HuCRAMWrite;
   }
   MDFNMP_AddRAM(32768, 0x40 * 8192, PopRAM);
  }
  else
  {
   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.
   
   LoadSaveMemory(MDFN_MakeFName(MDFNMKF_SAV, 0, "sav"), SaveRAM, 2048);

   PCEWrite[0xF7] = SaveRAMWrite;
   PCERead[0xF7] = SaveRAMRead;
   MDFNMP_AddRAM(2048, 0xF7 * 8192, SaveRAM);
  }

  // 0x1A558
  //if(len >= 0x20000 && !memcmp(HuCROM + 0x1A558, "STREET FIGHTER#", strlen("STREET FIGHTER#")))
  if(sf2_mapper)
  {
   for(int x = 0x40; x < 0x80; x++)
   {
    // FIXME: PCE_FAST
    HuCPUFastMap[x] = NULL; // Make sure our reads go through our read function, and not a table lookup
    PCERead[x] = HuCSF2Read;
   }
   PCEWrite[0] = HuCSF2Write;
   MDFN_printf("Street Fighter 2 Mapper\n");
   HuCSF2Latch = 0;
  }
 }
 catch(...)
 {
  Cleanup();
  throw;
 }

 return crc;
}
Beispiel #10
0
void HuC_Load(const uint8 *data, uint32 len, uint32 crc32, bool DisableBRAM, SysCardType syscard)
{
 const uint32 sf2_threshold = 2048 * 1024;
 uint32 m_len = (len + 8191) &~ 8191;
 bool sf2_mapper = FALSE;
 bool mcg_mapper = FALSE;
 bool UseBRAM = FALSE;

 //
 // Obvious, but anyway: catch exceptions and free any allocated memory here, otherwise when code higher up calls HuC_Close(), it might wipe out save game files.
 //
 try
 {
  if(len >= 8192 && !memcmp(data + 0x1FD0, "MCGENJIN", 8))
   mcg_mapper = TRUE;

  if(!syscard && m_len >= sf2_threshold && !mcg_mapper)
  {
   sf2_mapper = TRUE;

   // Only used the "extended" SF2 mapper if it's considerably larger than the normal SF2 mapper size.
   if(m_len < (512 * 1024 * 6))
    m_len = 512 * 1024 * 5;
   else
    m_len = round_up_pow2(m_len - 512 * 1024) + 512 * 1024;

   if(m_len > 8912896)
    throw MDFN_Error(0, _("ROM image is too large for extended SF2 mapper!"));

   HuCSF2BankMask = ((m_len - 512 * 1024) / (512 * 1024)) - 1;

   //printf("%d %d, %02x\n", len, m_len, HuCSF2BankMask);
  }

  IsPopulous = 0;
  PCE_IsCD = 0;

  if(syscard == SYSCARD_NONE)
  {
   md5_context md5;
   md5.starts();
   md5.update(data, len);
   md5.finish(MDFNGameInfo->MD5);

   MDFN_printf(_("ROM:       %dKiB\n"), (len + 1023) / 1024);
   MDFN_printf(_("ROM CRC32: 0x%08x\n"), crc32);
   MDFN_printf(_("ROM MD5:   0x%s\n"), md5_context::asciistr(MDFNGameInfo->MD5, 0).c_str());
  }

  if(syscard != SYSCARD_NONE)
  {
   CDRAM = (uint8 *)MDFN_calloc_T(1, 8 * 8192, _("CD RAM"));

   for(int x = 0x80; x < 0x88; x++)
   {
    ROMMap[x] = &CDRAM[(x - 0x80) * 8192] - x * 8192;
    HuCPU->SetFastRead(x, ROMMap[x] + x * 8192);

    HuCPU->SetReadHandler(x, CDRAMRead);
    HuCPU->SetWriteHandler(x, CDRAMWrite);
   }
   MDFNMP_AddRAM(8 * 8192, 0x80 * 8192, CDRAM);

   UseBRAM = TRUE;
  }

  if(mcg_mapper)
  {
   mcg = new MCGenjin(data, len);

   for(unsigned i = 0; i < 128; i++)
   {
    HuCPU->SetFastRead(i, NULL);
    HuCPU->SetReadHandler(i, MCG_ReadHandler);
    HuCPU->SetWriteHandler(i, MCG_WriteHandler);
   }

   goto BRAM_Init; // SO EVIL YES EVVIIIIIL(FIXME)
  }

  HuCROM = (uint8 *)MDFN_malloc_T(m_len, _("HuCard ROM"));

  memset(HuCROM, 0xFF, m_len);
  memcpy(HuCROM, data, (m_len < len) ? m_len : len);

  if(m_len == 0x60000)
  {
   for(int x = 0; x < 128; x++)
   {
    ROMMap[x] = &HuCROM[(x & 0x1F) * 8192] - x * 8192;

    HuCPU->SetFastRead(x, ROMMap[x] + x * 8192);
    HuCPU->SetReadHandler(x, HuCRead);
   }

   for(int x = 64; x < 128; x++)
   {
    ROMMap[x] = &HuCROM[((x & 0xF) + 32) * 8192] - x * 8192;

    HuCPU->SetFastRead(x, ROMMap[x] + x * 8192);
    HuCPU->SetReadHandler(x, HuCRead);
   }
  }
  else if(m_len == 0x80000)
  {
   for(int x = 0; x < 64; x++)
   {
    ROMMap[x] = &HuCROM[(x & 0x3F) * 8192] - x * 8192;

    HuCPU->SetFastRead(x, ROMMap[x] + x * 8192);
    HuCPU->SetReadHandler(x, HuCRead);
   }
   for(int x = 64; x < 128; x++)
   {
    ROMMap[x] = &HuCROM[((x & 0x1F) + 32) * 8192] - x * 8192;

    HuCPU->SetFastRead(x, ROMMap[x] + x * 8192);
    HuCPU->SetReadHandler(x, HuCRead);
   }
  }
  else
  {
   for(int x = 0; x < 128; x++)
   {
    uint8 bank = x % (m_len / 8192);
   
    ROMMap[x] = &HuCROM[bank * 8192] - x * 8192;

    HuCPU->SetFastRead(x, ROMMap[x] + x * 8192);
    HuCPU->SetReadHandler(x, HuCRead);
   }
  }

  if(syscard)
  {
   if(syscard == SYSCARD_3 || syscard == SYSCARD_ARCADE)
   {
    SysCardRAM = (uint8 *)MDFN_calloc_T(1, 24 * 8192, _("System Card RAM"));

    for(int x = 0x68; x < 0x80; x++)
    {
     ROMMap[x] = &SysCardRAM[(x - 0x68) * 8192] - x * 8192;
     HuCPU->SetFastRead(x, ROMMap[x] + x * 8192);

     HuCPU->SetReadHandler(x, SysCardRAMRead);
     HuCPU->SetWriteHandler(x, SysCardRAMWrite);
    } 
    MDFNMP_AddRAM(24 * 8192, 0x68 * 8192, SysCardRAM); 
   }

   if(syscard == SYSCARD_ARCADE)
   {
    arcade_card = new ArcadeCard();

    for(int x = 0x40; x < 0x44; x++)
    {
     ROMMap[x] = NULL;
     HuCPU->SetFastRead(x, NULL);

     HuCPU->SetReadHandler(x, AC_PhysRead);
     HuCPU->SetWriteHandler(x, AC_PhysWrite);
    }
   }
  }
  else
  {
   if(!memcmp(HuCROM + 0x1F26, "POPULOUS", strlen("POPULOUS")))
   {
    gzFile fp;
  
    PopRAM = (uint8 *)MDFN_malloc_T(32768, _("Populous RAM"));
    memset(PopRAM, 0xFF, 32768);

    if((fp = gzopen(MDFN_MakeFName(MDFNMKF_SAV, 0, "sav").c_str(), "rb")))
    {
     gzread(fp, PopRAM, 32768);
     gzclose(fp);
    }

    IsPopulous = 1;
    MDFN_printf("Populous\n");
    for(int x = 0x40; x < 0x44; x++)
    {
     ROMMap[x] = &PopRAM[(x & 3) * 8192] - x * 8192;
     HuCPU->SetFastRead(x, ROMMap[x] + x * 8192);

     HuCPU->SetReadHandler(x, HuCRead);
     HuCPU->SetWriteHandler(x, HuCRAMWrite);
    }
    MDFNMP_AddRAM(32768, 0x40 * 8192, PopRAM);
   }
   else if(crc32 == 0x34dc65c4) // Tsushin Booster
   {
    gzFile fp;

    TsushinRAM = (uint8*)MDFN_malloc_T(0x8000, _("Tsushin Booster RAM"));
    memset(TsushinRAM, 0xFF, 0x8000);

    if((fp = gzopen(MDFN_MakeFName(MDFNMKF_SAV, 0, "sav").c_str(), "rb")))
    {
     gzread(fp, TsushinRAM, 32768);
     gzclose(fp);
    }

    IsTsushin = 1;
    MDFN_printf("Tsushin Booster\n");
    for(int x = 0x88; x < 0x8C; x++)
    {
     ROMMap[x] = &TsushinRAM[(x & 3) * 8192] - x * 8192;
     HuCPU->SetFastRead(x, ROMMap[x] + x * 8192);

     HuCPU->SetReadHandler(x, HuCRead);
     HuCPU->SetWriteHandler(x, HuCRAMWrite);
    }
    MDFNMP_AddRAM(32768, 0x88 * 8192, TsushinRAM);
   }
   else
    UseBRAM = TRUE;

   // 0x1A558
   if(sf2_mapper)
   {
    for(int x = 0x20; x < 0x40; x++)
     HuCPU->SetReadHandler(x, HuCSF2ReadLow);
    for(int x = 0x40; x < 0x80; x++)
    {
     HuCPU->SetFastRead(x, NULL);		// Make sure our reads go through our read function, and not a table lookup
     HuCPU->SetReadHandler(x, HuCSF2Read);
    }
    HuCPU->SetWriteHandler(0, HuCSF2Write);

    MDFN_printf("Street Fighter 2 Mapper\n");
    HuCSF2Latch = 0;
   }
  }	// end else to if(syscard)

  BRAM_Init:

  BRAM_Disabled = DisableBRAM;
  if(BRAM_Disabled)
   UseBRAM = false;

  if(UseBRAM)
  {
   gzFile fp;

   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((fp = gzopen(MDFN_MakeFName(MDFNMKF_SAV, 0, "sav").c_str(), "rb")))
   {
    gzread(fp, SaveRAM, 2048);
    gzclose(fp);
   }

   HuCPU->SetWriteHandler(0xF7, SaveRAMWrite);
   HuCPU->SetReadHandler(0xF7, SaveRAMRead);
   MDFNMP_AddRAM(2048, 0xF7 * 8192, SaveRAM);
  }
 }
 catch(...)
 {
  Cleanup();
  throw;
 }
}