Previous 199869 Revisions Next

r21632 Wednesday 6th March, 2013 at 12:44:03 UTC by Fabio Priuli
minor cleanup. nw.
[src/mess/machine]snescart.c

trunk/src/mess/machine/snescart.c
r21631r21632
750750{
751751   int supported_type = 1;
752752   running_machine &machine = image.device().machine();
753   snes_state *state = machine.driver_data<snes_state>();
754753   address_space &space = machine.device( "maincpu")->memory().space( AS_PROGRAM );
755754   int total_blocks, read_blocks, has_bsx_slot = 0, st_bios = 0;
756755   UINT32 offset, int_header_offs;
757   UINT8 *ROM = state->memregion("cart")->base();
756   UINT8 *ROM = memregion("cart")->base();
758757
759758   if (image.software_entry() == NULL)
760      state->m_cart_size = image.length();
759      m_cart_size = image.length();
761760   else
762      state->m_cart_size = image.get_software_region_length("rom");
761      m_cart_size = image.get_software_region_length("rom");
763762
764763   /* Check for a header (512 bytes), and skip it if found */
765   offset = snes_skip_header(image, state->m_cart_size);
764   offset = snes_skip_header(image, m_cart_size);
766765
767766   if (image.software_entry() == NULL)
768767   {
769768      image.fseek(offset, SEEK_SET);
770      image.fread( ROM, state->m_cart_size - offset);
769      image.fread(ROM, m_cart_size - offset);
771770   }
772771   else
773      memcpy(ROM, image.get_software_region("rom") + offset, state->m_cart_size - offset);
772      memcpy(ROM, image.get_software_region("rom") + offset, m_cart_size - offset);
774773
775   if (SNES_CART_DEBUG) mame_printf_error("size %08X\n", state->m_cart_size - offset);
774   if (SNES_CART_DEBUG) mame_printf_error("size %08X\n", m_cart_size - offset);
776775
777776   /* First, look if the cart is HiROM or LoROM (and set snes_cart accordingly) */
778777   int_header_offs = snes_find_hilo_mode(image, ROM, offset, 0);
r21631r21632
788787         if (ROM[int_header_offs + 0x1a] == 0x33 || ROM[int_header_offs + 0x1a] == 0xff)
789788         {
790789            // BS-X Flash Cart
791            state->m_cart[0].mode = SNES_MODE_BSX;
790            m_cart[0].mode = SNES_MODE_BSX;
792791         }
793792      }
794793   }
r21631r21632
813812      if (!memcmp(ROM + int_header_offs, "Satellaview BS-X     ", 21))
814813      {
815814         //BS-X Base Cart
816         state->m_cart[0].mode = SNES_MODE_BSX;
815         m_cart[0].mode = SNES_MODE_BSX;
817816         // handle RAM
818817      }
819818      else
820819      {
821         state->m_cart[0].mode = (int_header_offs ==0x007fc0) ? SNES_MODE_BSLO : SNES_MODE_BSHI;
820         m_cart[0].mode = (int_header_offs ==0x007fc0) ? SNES_MODE_BSLO : SNES_MODE_BSHI;
822821         // handle RAM?
823822      }
824823   }
r21631r21632
826825   /* Then, detect Sufami Turbo carts */
827826   if (!memcmp(ROM, "BANDAI SFC-ADX", 14))
828827   {
829      state->m_cart[0].mode = SNES_MODE_ST;
828      m_cart[0].mode = SNES_MODE_ST;
830829      if (!memcmp(ROM + 16, "SFC-ADX BACKUP", 14))
831830         st_bios = 1;
832831   }
833832
834   if (SNES_CART_DEBUG) mame_printf_error("mode %d\n", state->m_cart[0].mode);
833   if (SNES_CART_DEBUG) mame_printf_error("mode %d\n", m_cart[0].mode);
835834
836835   /* FIXME: Insert crc check here? */
837836
838837   /* How many blocks of data are available to be loaded? */
839   total_blocks = ((state->m_cart_size - offset) / (state->m_cart[0].mode & 0xa5 ? 0x8000 : 0x10000));
838   total_blocks = ((m_cart_size - offset) / (m_cart[0].mode & 0xa5 ? 0x8000 : 0x10000));
840839   read_blocks = 0;
841840
842841   if (SNES_CART_DEBUG) mame_printf_error("blocks %d\n", total_blocks);
r21631r21632
852851    * This is likely what happens in the real SNES as well, because the unit cannot be aware of the exact
853852    * size of data in the cart (procedure confirmed by byuu)
854853    */
855   switch (state->m_cart[0].mode)
854   switch (m_cart[0].mode)
856855   {
857856      case SNES_MODE_21:
858857      /* HiROM carts load data in banks 0xc0 to 0xff. Each bank is fully mirrored in banks 0x40 to 0x7f
r21631r21632
10181017         /* not handled yet */
10191018         mame_printf_error("This is a BS-X Satellaview image: MESS does not support these yet, sorry.\n");
10201019         /* so treat it like MODE_20 */
1021         state->m_cart[0].mode = SNES_MODE_20;
1020         m_cart[0].mode = SNES_MODE_20;
10221021         /* and load it as such... */
10231022
10241023      default:
r21631r21632
10811080   /* Find the amount of cart ram (even if we call it sram...) */
10821081   if (image.software_entry() == NULL)
10831082   {
1084      if ((state->m_has_addon_chip != HAS_SUPERFX))
1085         state->m_cart[0].sram = snes_r_bank1(space, 0x00ffd8);
1083      if ((m_has_addon_chip != HAS_SUPERFX))
1084         m_cart[0].sram = snes_r_bank1(space, 0x00ffd8);
10861085      else
1087         state->m_cart[0].sram = (snes_r_bank1(space, 0x00ffbd) & 0x07);
1086         m_cart[0].sram = (snes_r_bank1(space, 0x00ffbd) & 0x07);
10881087
1089      if (state->m_cart[0].sram > 0)
1088      if (m_cart[0].sram > 0)
10901089      {
1091         state->m_cart[0].sram = (1024 << state->m_cart[0].sram);
1092         if (state->m_cart[0].sram > state->m_cart[0].sram_max)
1093            state->m_cart[0].sram = state->m_cart[0].sram_max;
1090         m_cart[0].sram = (1024 << m_cart[0].sram);
1091         if (m_cart[0].sram > m_cart[0].sram_max)
1092            m_cart[0].sram = m_cart[0].sram_max;
10941093      }
1095//      printf("size %x\n", state->m_cart[0].sram);
1094//      printf("size %x\n", m_cart[0].sram);
10961095   }
10971096   else
10981097   {
10991098      // if we are loading from softlist, take memory length from the xml
1100      state->m_cart[0].sram = image.get_software_region("nvram") ? image.get_software_region_length("nvram") : 0;
1099      m_cart[0].sram = image.get_software_region("nvram") ? image.get_software_region_length("nvram") : 0;
11011100
1102      if (state->m_cart[0].sram > 0)
1101      if (m_cart[0].sram > 0)
11031102      {
1104         if (state->m_cart[0].sram > state->m_cart[0].sram_max)
1105            fatalerror("Found more memory than max allowed (found: %x, max: %x), check xml file!\n", state->m_cart[0].sram, state->m_cart[0].sram_max);
1103         if (m_cart[0].sram > m_cart[0].sram_max)
1104            fatalerror("Found more memory than max allowed (found: %x, max: %x), check xml file!\n", m_cart[0].sram, m_cart[0].sram_max);
11061105      }
11071106      // TODO: Eventually sram handlers should point to the allocated cart:sram region!
11081107      // For now, we only use the region as a placeholder to carry size info...
1109//      printf("size %x\n", state->m_cart[0].sram);
1108//      printf("size %x\n", m_cart[0].sram);
11101109   }
11111110
11121111   /* adjust size for very large carts */
1113   if (state->m_cart[0].mode == SNES_MODE_20 && ((state->m_cart_size - offset) > 0x200000 || state->m_cart[0].sram > (32 * 1024)))
1114      state->m_cart[0].small_sram = 1;
1112   if (m_cart[0].mode == SNES_MODE_20 && ((m_cart_size - offset) > 0x200000 || m_cart[0].sram > (32 * 1024)))
1113      m_cart[0].small_sram = 1;
11151114   else
1116      state->m_cart[0].small_sram = 0;
1115      m_cart[0].small_sram = 0;
11171116
11181117   /* Log snes_cart information */
11191118   snes_cart_log_info(machine, total_blocks, supported_type);
r21631r21632
11281127DEVICE_IMAGE_LOAD_MEMBER( snes_state,sufami_cart )
11291128{
11301129   running_machine &machine = image.device().machine();
1131   snes_state *state = machine.driver_data<snes_state>();
11321130   int total_blocks, read_blocks;
11331131   int st_bios = 0, slot_id = 0;
11341132   UINT32 offset, st_data_offset = 0;
11351133   UINT8 *ROM = image.device().machine().root_device().memregion(image.device().tag())->base();
11361134
1137   snes_ram = state->memregion("maincpu")->base();
1135   snes_ram = memregion("maincpu")->base();
11381136
11391137   if (strcmp(image.device().tag(), ":slot_a") == 0)
11401138   {
r21631r21632
11491147   }
11501148
11511149   if (image.software_entry() == NULL)
1152      state->m_cart_size = image.length();
1150      m_cart_size = image.length();
11531151   else
1154      state->m_cart_size = image.get_software_region_length("rom");
1152      m_cart_size = image.get_software_region_length("rom");
11551153
11561154   /* Check for a header (512 bytes), and skip it if found */
1157   offset = snes_skip_header(image, state->m_cart_size);
1155   offset = snes_skip_header(image, m_cart_size);
11581156
11591157   if (image.software_entry() == NULL)
11601158   {
11611159      image.fseek(offset, SEEK_SET);
1162      image.fread( ROM, state->m_cart_size - offset);
1160      image.fread(ROM, m_cart_size - offset);
11631161   }
11641162   else
1165      memcpy(ROM, image.get_software_region("rom") + offset, state->m_cart_size - offset);
1163      memcpy(ROM, image.get_software_region("rom") + offset, m_cart_size - offset);
11661164
1167   if (SNES_CART_DEBUG) mame_printf_error("size %08X\n", state->m_cart_size - offset);
1165   if (SNES_CART_DEBUG) mame_printf_error("size %08X\n", m_cart_size - offset);
11681166
11691167   /* Detect Sufami Turbo carts */
11701168   if (!memcmp(ROM, "BANDAI SFC-ADX", 14))
11711169   {
1172      state->m_cart[slot_id].mode = SNES_MODE_ST;
1170      m_cart[slot_id].mode = SNES_MODE_ST;
11731171      if (!memcmp(ROM + 16, "SFC-ADX BACKUP", 14))
11741172         st_bios = 1;
11751173   }
r21631r21632
11901188   /* FIXME: Insert crc check here? */
11911189
11921190   /* How many blocks of data are available to be loaded? */
1193   total_blocks = (state->m_cart_size - offset) / 0x8000;
1191   total_blocks = (m_cart_size - offset) / 0x8000;
11941192   read_blocks = 0;
11951193
11961194   if (SNES_CART_DEBUG)
r21631r21632
12231221
12241222   sufami_load_sram(machine, image.device().tag());
12251223
1226   state->m_cart[slot_id].slot_in_use = 1; // aknowledge the cart in this slot, for saving sram at exit
1224   m_cart[slot_id].slot_in_use = 1; // aknowledge the cart in this slot, for saving sram at exit
12271225
12281226   auto_free(image.device().machine(), ROM);
12291227

Previous 199869 Revisions Next


© 1997-2024 The MAME Team