Previous 199869 Revisions Next

r21986 Wednesday 20th March, 2013 at 13:42:36 UTC by Fabio Priuli
(MESS) megadriv: fixed support of SMD files (those with 512k header), broken
by the recent developments. [Fabio Priuli]

Thanks goes to Carl for providing test cases.
As long as supporting these legacy formats remains easy, I see no reason not to ;)
[src/mess/machine]md_slot.c

trunk/src/mess/machine/md_slot.c
r21985r21986
389389 *************************************/
390390
391391/* code taken directly from GoodGEN by Cowering */
392static int genesis_is_SMD(unsigned char *buf,unsigned int len)
392static int genesis_is_SMD(unsigned char *buf, unsigned int len)
393393{
394394   if (buf[0x2080] == 'S' && buf[0x80] == 'E' && buf[0x2081] == 'G' && buf[0x81] == 'A')
395395      return 1;
r21985r21986
459459int base_md_cart_slot_device::load_nonlist()
460460{
461461   unsigned char *ROM, *tmpROM;
462   UINT32 len = m_cart->get_padded_size(length()); // if cart size is not (2^n * 64K), the system will see anyway that size so we need to alloc a bit more space
462   bool is_smd, is_md;
463   UINT32 tmplen = length(), offset, len;
463464
465   // STEP 1: store a (possibly headered) copy of the file and determine its type (SMD? MD? BIN?)
466   tmpROM = global_alloc_array(unsigned char, tmplen);
467   fread(tmpROM, tmplen);
468   is_smd = genesis_is_SMD(&tmpROM[0x200], tmplen - 0x200);
469   is_md = (tmpROM[0x80] == 'E') && (tmpROM[0x81] == 'A') && (tmpROM[0x82] == 'M' || tmpROM[0x82] == 'G');
470
471   // take header into account, if any
472   offset = is_smd ? 0x200 : 0;
473
474   // STEP 2: allocate space for the real copy of the game
475   // if cart size is not (2^n * 64K), the system will see anyway that size so we need to alloc a bit more space
476   len = m_cart->get_padded_size(tmplen - offset);
464477   // this contains an hack for SSF2: its current bankswitch code needs larger rom space to work
465478   m_cart->rom_alloc(machine(), (len == 0x500000) ? 0x900000 : len);
466479
480
481   // STEP 3: copy the game data in the appropriate way
467482   ROM = (unsigned char *)m_cart->get_rom_base();
468   tmpROM = global_alloc_array(unsigned char, len);
469483
470   // STEP 1: determine the file type (SMD? MD? BIN?)
471   fread(tmpROM, len);
472
473   /* is this a SMD file? */
474   if (genesis_is_SMD(&tmpROM[0x200], len))
484   if (is_smd)
475485   {
476486      mame_printf_debug("SMD!\n");
477487
478      for (int ptr = 0; ptr < (len - 0x200) / 0x2000; ptr += 2)
488      for (int ptr = 0; ptr < (tmplen - 0x200) / 0x2000; ptr += 2)
479489      {
480490         for (int x = 0; x < 0x2000; x++)
481491         {
482            *ROM++ = *(tmpROM + 0x200 + ((ptr + 1) * 0x2000) + x);
483            *ROM++ = *(tmpROM + 0x200 + ((ptr + 0) * 0x2000) + x);
492            ROM[ptr * 0x2000 + x * 2 + 0] = tmpROM[0x200 + ((ptr + 1) * 0x2000) + x];
493            ROM[ptr * 0x2000 + x * 2 + 1] = tmpROM[0x200 + ((ptr + 0) * 0x2000) + x];
484494         }
485495      }
486
487      len -= 0x200;
488496   }
489   /* is this a MD file? */
490   else if ((tmpROM[0x80] == 'E') && (tmpROM[0x81] == 'A') && (tmpROM[0x82] == 'M' || tmpROM[0x82] == 'G'))
497   else if (is_md)
491498   {
492499      mame_printf_debug("MD!\n");
493500
494      for (int ptr = 0; ptr < len; ptr += 2)
501      for (int ptr = 0; ptr < tmplen; ptr += 2)
495502      {
496         ROM[ptr] = tmpROM[(len >> 1) + (ptr >> 1)];
503         ROM[ptr] = tmpROM[(tmplen >> 1) + (ptr >> 1)];
497504         ROM[ptr + 1] = tmpROM[(ptr >> 1)];
498505      }
499506   }
500   /* BIN it is, then */
501507   else
502508   {
509      mame_printf_debug("BIN!\n");
510
503511      fseek(0, SEEK_SET);
504512      fread(ROM, len);
505513   }
r21985r21986
507515   global_free(tmpROM);
508516
509517   // if we allocated a ROM larger that the file (e.g. due to uneven cart size), set remaining space to 0xff
510   if (len > length())
511      memset(m_cart->get_rom_base() + length()/2, 0xffff, (len - length())/2);
518   if (len > (tmplen - offset))
519      memset(m_cart->get_rom_base() + (tmplen - offset)/2, 0xffff, (len - tmplen + offset)/2);
512520
513   // STEP 2: determine the cart type (to deal with pirate mappers & eeprom)
514   m_type = get_cart_type(ROM, length());
515521
522   // STEP 4: determine the cart type (to deal with sram/eeprom & pirate mappers)
523   m_type = get_cart_type(ROM, len);
524
516525   // handle mirroring of ROM, unless it's SSF2 or Pier Solar
517526   if (m_type != SSF2 && m_type != PSOLAR)
518527      m_cart->rom_map_setup(len);
519528
529
520530#ifdef LSB_FIRST
521531   unsigned char fliptemp;
522532   // is this really needed nowadays?
r21985r21986
889899
890900   if (open_image_file(options))
891901   {
892      UINT32 len = core_fsize(m_file);
902      UINT32 len = core_fsize(m_file), offset = 0;;
893903      UINT8 *ROM = global_alloc_array(UINT8, len);
894904      int type;
895905
896906      core_fread(m_file, ROM, len);
897907
898      type = get_cart_type(ROM, len);
908      if (genesis_is_SMD(&ROM[0x200], len - 0x200))
909            offset = 0x200;
910
911      type = get_cart_type(ROM + offset, len - offset);
899912      slot_string = md_get_slot(type);
900913
901914      global_free(ROM);

Previous 199869 Revisions Next


© 1997-2024 The MAME Team