Previous 199869 Revisions Next

r21738 Saturday 9th March, 2013 at 07:46:16 UTC by Fabio Priuli
another minor cleanup. nw.
[src/mess/machine]snescart.c

trunk/src/mess/machine/snescart.c
r21737r21738
297297
298298   /* Check for a header (512 bytes) */
299299   if (image.software_entry() == NULL)
300      image.fread( header, 512);
300      image.fread(header, 512);
301301   else
302302      memcpy(header, image.get_software_region("rom"), 512);
303303
r21737r21738
330330/* This determines if a cart is in Mode 20, 21, 22 or 25; sets state->m_cart[0].mode and
331331 state->m_cart[0].sram_max accordingly; and returns the offset of the internal header
332332 (needed to detect BSX and ST carts) */
333static UINT32 snes_find_hilo_mode( device_image_interface &image, UINT8 *buffer, UINT32 offset, int cartid )
333static UINT32 snes_find_hilo_mode( device_image_interface &image, UINT8 *buffer, UINT32 len, UINT32 offset, int cartid )
334334{
335335   snes_state *state = image.device().machine().driver_data<snes_state>();
336336   UINT8 valid_mode20, valid_mode21, valid_mode25;
r21737r21738
339339   /* Now to determine if this is a lo-ROM, a hi-ROM or an extended lo/hi-ROM */
340340   valid_mode20 = snes_validate_infoblock(buffer, 0x007fc0);
341341   valid_mode21 = snes_validate_infoblock(buffer, 0x00ffc0);
342   valid_mode25 = snes_validate_infoblock(buffer, 0x40ffc0);
342   valid_mode25 = (len > 0x40ffc0) ? snes_validate_infoblock(buffer, 0x40ffc0) : 0;
343343
344344   /* Images larger than 32mbits are likely ExHiRom */
345345   if (valid_mode25)
r21737r21738
561561   return supported_type;
562562}
563563
564static void snes_cart_log_info( running_machine &machine, UINT8* ROM, int supported )
564static void snes_cart_log_info( running_machine &machine, UINT8* ROM, UINT32 len, int supported )
565565{
566566   snes_state *state = machine.driver_data<snes_state>();
567567   device_image_interface *image = dynamic_cast<device_image_interface *>(machine.device("cart"));
568568   char title[21], rom_id[4], company_id[2];
569569   int i, company, has_ram = 0, has_sram = 0;
570570   UINT32 offset = snes_skip_header(*image, state->m_cart_size);
571   UINT32 hilo_mode = snes_find_hilo_mode(*image, ROM, offset, 0);
571   UINT32 hilo_mode = snes_find_hilo_mode(*image, ROM, len, offset, 0);
572572
573573   /* Company */
574574   for (i = 0; i < 2; i++)
r21737r21738
645645   int supported_type = 1;
646646   int has_bsx_slot = 0, st_bios = 0;
647647   UINT32 offset, int_header_offs;
648   UINT8 *ROM = memregion("cart")->base();
649648
650649   if (image.software_entry() == NULL)
651650      m_cart_size = image.length();
652651   else
653652      m_cart_size = image.get_software_region_length("rom");
654653
655   /* Check for a header (512 bytes), and skip it if found */
654   // Check for a header (512 bytes), and skip it if found
656655   offset = snes_skip_header(image, m_cart_size);
657656
657   // Allocate rom pointer
658   m_cart[0].m_rom_size = m_cart_size - offset;
659   m_cart[0].m_rom = auto_alloc_array_clear(machine(), UINT8, m_cart[0].m_rom_size);
660
658661   if (image.software_entry() == NULL)
659662   {
660663      image.fseek(offset, SEEK_SET);
661      image.fread(ROM, m_cart_size - offset);
664      image.fread(m_cart[0].m_rom, m_cart_size - offset);
662665   }
663666   else
664      memcpy(ROM, image.get_software_region("rom") + offset, m_cart_size - offset);
667      memcpy(m_cart[0].m_rom, image.get_software_region("rom") + offset, m_cart_size - offset);
665668
666669   if (SNES_CART_DEBUG) mame_printf_error("size %08X\n", m_cart_size - offset);
667670
668   m_cart[0].m_rom_size = m_cart_size;
669   m_cart[0].m_rom = auto_alloc_array_clear(machine(), UINT8, m_cart[0].m_rom_size);
670   memcpy(m_cart[0].m_rom, ROM, m_cart[0].m_rom_size - offset);
671   // Setup the bank map to handle mirroring of ROM up to 8MB of accessible memory
671672   rom_map_setup(m_cart[0].m_rom_size);
672673
673   /* First, look if the cart is HiROM or LoROM (and set snes_cart accordingly) */
674   int_header_offs = snes_find_hilo_mode(image, ROM, offset, 0);
674   // Check if the cart is HiROM or LoROM (and set variables accordingly)
675   int_header_offs = snes_find_hilo_mode(image, m_cart[0].m_rom, m_cart[0].m_rom_size, offset, 0);
675676
676   /* Then, detect BS-X carts */
677   // Detect presence of BS-X Flash Cart
678   if ((ROM[int_header_offs + 0x13] == 0x00 || ROM[int_header_offs + 0x13] == 0xff) &&
679         ROM[int_header_offs + 0x14] == 0x00)
677   // Detect BS-X carts:
678   // 1. Detect BS-X Flash Cart
679   if ((m_cart[0].m_rom[int_header_offs + 0x13] == 0x00 || m_cart[0].m_rom[int_header_offs + 0x13] == 0xff) &&
680         m_cart[0].m_rom[int_header_offs + 0x14] == 0x00)
680681   {
681      UINT8 n15 = ROM[int_header_offs + 0x15];
682      UINT8 n15 = m_cart[0].m_rom[int_header_offs + 0x15];
682683      if (n15 == 0x00 || n15 == 0x80 || n15 == 0x84 || n15 == 0x9c || n15 == 0xbc || n15 == 0xfc)
683684      {
684         if (ROM[int_header_offs + 0x1a] == 0x33 || ROM[int_header_offs + 0x1a] == 0xff)
685         if (m_cart[0].m_rom[int_header_offs + 0x1a] == 0x33 || m_cart[0].m_rom[int_header_offs + 0x1a] == 0xff)
685686         {
686687            // BS-X Flash Cart
687688            mame_printf_error("This is a game with BS-X slot: MESS does not support these yet, sorry.\n");
r21737r21738
690691      }
691692   }
692693
693   // Detect presence of BS-X flash cartridge connector
694   if ((ROM[int_header_offs - 14] == 'Z') && (ROM[int_header_offs - 11] == 'J'))
694   // 2. Detect presence of BS-X flash cartridge connector
695   if ((m_cart[0].m_rom[int_header_offs - 14] == 'Z') && (m_cart[0].m_rom[int_header_offs - 11] == 'J'))
695696   {
696      UINT8 n13 = ROM[int_header_offs - 13];
697      UINT8 n13 = m_cart[0].m_rom[int_header_offs - 13];
697698      if ((n13 >= 'A' && n13 <= 'Z') || (n13 >= '0' && n13 <= '9'))
698699      {
699         if (ROM[int_header_offs + 0x1a] == 0x33 ||
700            (ROM[int_header_offs - 10] == 0x00 && ROM[int_header_offs - 4] == 0x00))
700         if (m_cart[0].m_rom[int_header_offs + 0x1a] == 0x33 ||
701            (m_cart[0].m_rom[int_header_offs - 10] == 0x00 && m_cart[0].m_rom[int_header_offs - 4] == 0x00))
701702         {
702703            has_bsx_slot = 1;
703704         }
r21737r21738
708709   if (has_bsx_slot)
709710   {
710711      mame_printf_error("This is a game with BS-X slot: MESS does not support these yet, sorry.\n");
711      if (!memcmp(ROM + int_header_offs, "Satellaview BS-X     ", 21))
712      if (!memcmp(m_cart[0].m_rom + int_header_offs, "Satellaview BS-X     ", 21))
712713      {
713714         //BS-X Base Cart
714715         m_cart[0].mode = SNES_MODE_20; //SNES_MODE_BSX;
715         // handle RAM
716716      }
717717      else
718718      {
719719         m_cart[0].mode = (int_header_offs == 0x007fc0) ? SNES_MODE_20 : SNES_MODE_21; //SNES_MODE_BSLO : SNES_MODE_BSHI;
720         // handle RAM?
721720      }
722721   }
723722
724723   /* Then, detect Sufami Turbo carts */
725   if (!memcmp(ROM, "BANDAI SFC-ADX", 14))
724   if (!memcmp(m_cart[0].m_rom, "BANDAI SFC-ADX", 14))
726725   {
727726      m_cart[0].mode = SNES_MODE_ST;
728      if (!memcmp(ROM + 16, "SFC-ADX BACKUP", 14))
727      if (!memcmp(m_cart[0].m_rom + 16, "SFC-ADX BACKUP", 14))
729728         st_bios = 1;
730729   }
731730   if (st_bios)
r21737r21738
741740   if (SNES_CART_DEBUG) mame_printf_error("mode %d\n", m_cart[0].mode);
742741
743742   /* Detect special chips */
744   supported_type = snes_find_addon_chip(machine(), ROM, int_header_offs);
743   supported_type = snes_find_addon_chip(machine(), m_cart[0].m_rom, int_header_offs);
745744
746745   /* Find the amount of cart ram */
747746   m_cart[0].m_nvram_size = 0;
r21737r21738
749748   {
750749      UINT32 nvram_size;
751750      if ((m_has_addon_chip != HAS_SUPERFX))
752         nvram_size = ROM[int_header_offs + 0x18];
751         nvram_size = m_cart[0].m_rom[int_header_offs + 0x18];
753752      else
754         nvram_size = (ROM[0x007fbd] & 0x07);
753         nvram_size = (m_cart[0].m_rom[0x007fbd] & 0x07);
755754
756755      if (nvram_size > 0)
757756      {
r21737r21738
782781      m_cart[0].m_nvram = auto_alloc_array_clear(machine(), UINT8, m_cart[0].m_nvram_size);
783782
784783   /* Log snes_cart information */
785   snes_cart_log_info(machine(), ROM, supported_type);
784   snes_cart_log_info(machine(), m_cart[0].m_rom, m_cart[0].m_rom_size, supported_type);
786785
787786   /* Load SRAM */
788787   if (m_cart[0].m_nvram_size > 0)

Previous 199869 Revisions Next


© 1997-2024 The MAME Team