Previous 199869 Revisions Next

r21633 Wednesday 6th March, 2013 at 13:08:54 UTC by Fabio Priuli
(MESS) snes.c: updated the driver to only save the real amount of SRAM present on the cart. This means
   that old .nv files won't be directly compatible with newer exe, but you shall be able to keep your saves
   by backing them up and taking the first block of the correct size (e.g. if you take the first 8KB block of
   your old .nv for Super Metroid it should work fine with the new exe). At the same time, MESS should be
   now compatible with saves taken in other emulators. [Fabio Priuli]
[src/mame/includes]snes.h
[src/mame/machine]snes.c
[src/mess/machine]snescart.c

trunk/src/mame/machine/snes.c
r21632r21633
693693      value = snes_open_bus_r(space, 0);                              /* Reserved */
694694   }
695695   else
696      value = snes_ram[offset];
696      value = snes_ram[offset];   //ROM
697697
698698   return value;
699699}
r21632r21633
711711      value = state->snes_r_io(space, address);
712712   else if (address < 0x8000)                                      /* SRAM for mode_21, Reserved othewise */
713713   {
714      if (state->m_cart[0].mode == SNES_MODE_21 && state->m_cart[0].sram > 0)
714      if (state->m_cart[0].mode == SNES_MODE_21 && state->m_cart[0].m_nvram_size > 0)
715715      {
716716         /* Donkey Kong Country checks this and detects a copier if 0x800 is not masked out due to sram size */
717717         /* OTOH Secret of Mana does not work properly if sram is not mirrored on later banks */
718         int mask = (state->m_cart[0].sram - 1) & 0x7fff; /* Limit SRAM size to what's actually present */
719         value = snes_ram[0x306000 + ((offset - 0x6000) & mask)];
718         int mask = (state->m_cart[0].m_nvram_size - 1) & 0x7fff; /* Limit SRAM size to what's actually present */
719         value = state->m_cart[0].m_nvram[(offset - 0x6000) & mask];
720720      }
721721      else
722722      {
r21632r21633
725725      }
726726   }
727727   else
728      value = snes_ram[0x300000 + offset];
728      value = snes_ram[0x300000 + offset];    //ROM
729729
730730   return value;
731731}
r21632r21633
742742      if ((address < 0x8000) && (state->m_cart[0].mode == SNES_MODE_20))
743743         value = snes_open_bus_r(space, 0);                          /* Reserved */
744744      else
745         value = snes_ram[0x400000 + offset];
745         value = snes_ram[0x400000 + offset];    //ROM
746746   }
747747   else                                            /* Mode 21 & 25 */
748      value = snes_ram[0x400000 + offset];
748      value = snes_ram[0x400000 + offset];    //ROM
749749
750750   return value;
751751}
r21632r21633
760760   if (state->m_cart[0].mode & 5)                         /* Mode 20 & 22 */
761761   {
762762      if (address >= 0x8000)
763         value = snes_ram[0x600000 + offset];
763         value = snes_ram[0x600000 + offset];    //ROM
764764      else
765765      {
766766         logerror("(PC=%06x) snes_r_bank4: Unmapped external chip read: %04x\n",space.device().safe_pc(),address);
r21632r21633
768768      }
769769   }
770770   else if (state->m_cart[0].mode & 0x0a)                  /* Mode 21 & 25 */
771      value = snes_ram[0x600000 + offset];
771      value = snes_ram[0x600000 + offset];    //ROM
772772
773773   return value;
774774}
r21632r21633
782782
783783   if ((state->m_cart[0].mode & 5) && (address < 0x8000))     /* Mode 20 & 22 */
784784   {
785      if (state->m_cart[0].sram > 0x8000)
785      if (state->m_cart[0].m_nvram_size > 0x8000)
786786      {
787787         // In this case, SRAM is mapped in 0x8000 chunks at diff offsets: 0x700000-0x707fff, 0x710000-0x717fff, etc.
788         int mask = (state->m_cart[0].sram << 1) - 1;
789         mask &= ~0x8000;
790         value = snes_ram[0x700000 + (offset & mask)];
788         int mask = state->m_cart[0].m_nvram_size - 1;
789         offset = (offset / 0x10000) * 0x8000 + (offset & 0x7fff);
790         value = state->m_cart[0].m_nvram[offset & mask];
791791      }
792      else if (state->m_cart[0].sram > 0)
792      else if (state->m_cart[0].m_nvram_size > 0)
793793      {
794         int mask = state->m_cart[0].sram - 1;   /* Limit SRAM size to what's actually present */
795         value = snes_ram[0x700000 + (offset & mask)];
794         int mask = state->m_cart[0].m_nvram_size - 1;   /* Limit SRAM size to what's actually present */
795         value = state->m_cart[0].m_nvram[offset & mask];
796796      }
797797      else
798798      {
r21632r21633
801801      }
802802   }
803803   else
804      value = snes_ram[0x700000 + offset];
804      value = snes_ram[0x700000 + offset];    //ROM
805805
806806   return value;
807807}
r21632r21633
814814   if ((offset & 0xffff) < 0x8000)
815815      value = space.read_byte(offset);
816816   else
817      value = snes_ram[0x800000 + offset];
817      value = snes_ram[0x800000 + offset];    //ROM
818818
819819   return value;
820820}
r21632r21633
826826   UINT8 value = 0;
827827   UINT16 address = offset & 0xffff;
828828
829   if (state->m_cart[0].mode & 5)      /* Mode 20 & 22 */
829   if (state->m_cart[0].mode & 5 && address < 0x8000)      /* Mode 20 & 22 in 0x0000-0x7fff */
830830   {
831      if (address < 0x8000)
831      if (offset < 0x300000)
832832         value = space.read_byte(0x400000 + offset);
833833      else
834         value = snes_ram[0xc00000 + offset];
834      {
835         if (state->m_cart[0].m_nvram_size > 0x8000)
836         {
837            // In this case, SRAM is mapped in 0x8000 chunks at diff offsets: 0x700000-0x707fff, 0x710000-0x717fff, etc.
838            int mask = state->m_cart[0].m_nvram_size - 1;
839            offset = (offset / 0x10000) * 0x8000 + (offset & 0x7fff);
840            value = state->m_cart[0].m_nvram[offset & mask];
841         }
842         else if (state->m_cart[0].m_nvram_size > 0)
843         {
844            int mask = state->m_cart[0].m_nvram_size - 1;   /* Limit SRAM size to what's actually present */
845            value = state->m_cart[0].m_nvram[offset & mask];
846         }
847      }
835848   }
836   else                                /* Mode 21 & 25 */
837      value = snes_ram[0xc00000 + offset];
849   else
850      value = snes_ram[0xc00000 + offset];    //ROM
838851
839852   return value;
840853}
r21632r21633
868881      state->snes_w_io(space, address, data);
869882   else if (address < 0x8000)                      /* SRAM for mode_21, Reserved othewise */
870883   {
871      if ((state->m_cart[0].mode == SNES_MODE_21) && (state->m_cart[0].sram > 0))
884      if (state->m_cart[0].mode == SNES_MODE_21 && state->m_cart[0].m_nvram_size > 0)
872885      {
873886         /* Donkey Kong Country checks this and detects a copier if 0x800 is not masked out due to sram size */
874887         /* OTOH Secret of Mana does not work properly if sram is not mirrored on later banks */
875         int mask = (state->m_cart[0].sram - 1) & 0x7fff; /* Limit SRAM size to what's actually present */
876         snes_ram[0x306000 + ((offset - 0x6000) & mask)] = data;
888         int mask = (state->m_cart[0].m_nvram_size - 1) & 0x7fff; /* Limit SRAM size to what's actually present */
889         state->m_cart[0].m_nvram[(offset - 0x6000) & mask] = data;
877890      }
878891      else
879892         logerror("snes_w_bank2: Attempt to write to reserved address: %X = %02x\n", offset + 0x300000, data);
r21632r21633
907920
908921   if ((state->m_cart[0].mode & 5) && (address < 0x8000))         /* Mode 20 & 22 */
909922   {
910      if (state->m_cart[0].sram > 0x8000)
923      if (state->m_cart[0].m_nvram_size > 0x8000)
911924      {
912925         // In this case, SRAM is mapped in 0x8000 chunks at diff offsets: 0x700000-0x707fff, 0x710000-0x717fff, etc.
913         int mask = (state->m_cart[0].sram << 1) - 1;
914         mask &= ~0x8000;
915         snes_ram[0x700000 + (offset & mask)] = data;
926         int mask = state->m_cart[0].m_nvram_size - 1;
927         offset = (offset / 0x10000) * 0x8000 + (offset & 0x7fff);
928         state->m_cart[0].m_nvram[offset & mask] = data;
916929      }
917      else if (state->m_cart[0].sram > 0)
930      else if (state->m_cart[0].m_nvram_size > 0)
918931      {
919         int mask = state->m_cart[0].sram - 1;   /* Limit SRAM size to what's actually present */
920         snes_ram[0x700000 + (offset & mask)] = data;
932         int mask = state->m_cart[0].m_nvram_size - 1;   /* Limit SRAM size to what's actually present */
933         state->m_cart[0].m_nvram[offset & mask] = data;
921934      }
922935      else
923936         logerror("snes_w_bank5: Attempt to write to reserved address: %X = %02x\n", offset + 0x700000, data);
r21632r21633
943956   snes_state *state = space.machine().driver_data<snes_state>();
944957   UINT16 address = offset & 0xffff;
945958
946   if (state->m_cart[0].mode & 5)             /* Mode 20 & 22 */
959   if (state->m_cart[0].mode & 5 && address < 0x8000)      /* Mode 20 & 22 in 0x0000-0x7fff */
947960   {
948      if (address < 0x8000)
961      if (offset >= 0x300000)
949962      {
950         if (offset >= 0x3e0000)
951            logerror("Attempt to write to banks 0xfe - 0xff address: %X\n", offset);
952         else if (offset >= 0x300000)
953            snes_w_bank5(space, offset - 0x300000, data);
954         else if (offset >= 0x200000)
955            snes_w_bank4(space, offset - 0x200000, data);
963         if (state->m_cart[0].m_nvram_size > 0x8000)
964         {
965            // In this case, SRAM is mapped in 0x8000 chunks at diff offsets: 0x700000-0x707fff, 0x710000-0x717fff, etc.
966            int mask = state->m_cart[0].m_nvram_size - 1;
967            offset = (offset / 0x10000) * 0x8000 + (offset & 0x7fff);
968            state->m_cart[0].m_nvram[offset & mask] = data;
969            return;
970         }
971         else if (state->m_cart[0].m_nvram_size > 0)
972         {
973            int mask = state->m_cart[0].m_nvram_size - 1;   /* Limit SRAM size to what's actually present */
974            state->m_cart[0].m_nvram[offset & mask] = data;
975            return;
976         }
956977      }
957      else
958         logerror("(PC=%06x) snes_w_bank7: Attempt to write to ROM address: %X = %02x\n",space.device().safe_pc(),offset + 0xc00000, data);
978      logerror("(PC=%06x) snes_w_bank7: Attempt to write to ROM address: %X = %02x\n",space.device().safe_pc(),offset + 0xc00000, data);
959979   }
960980   else if (state->m_cart[0].mode & 0x0a)
961981      logerror("(PC=%06x) Attempt to write to ROM address: %X\n",space.device().safe_pc(),offset + 0xc00000);
r21632r21633
12321252/* for mame we use an init, maybe we will need more for the different games */
12331253DRIVER_INIT_MEMBER(snes_state,snes)
12341254{
1235   address_space &space = machine().device("maincpu")->memory().space(AS_PROGRAM);
12361255   UINT16 total_blocks, read_blocks;
12371256   UINT8 *rom;
12381257
12391258   rom = memregion("user3")->base();
12401259   snes_ram = auto_alloc_array_clear(machine(), UINT8, 0x1400000);
12411260
1261   m_cart[0].m_rom_size = memregion("user3")->bytes();
1262   m_cart[0].m_rom = auto_alloc_array_clear(machine(), UINT8, m_cart[0].m_rom_size);
1263   memcpy(m_cart[0].m_rom, rom, m_cart[0].m_rom_size);
1264
1265   m_cart[0].m_nvram_size = 0;
1266   if (rom[0x7fd8] > 0)
1267   {
1268      UINT32 nvram_size = (1024 << rom[0x7fd8]);
1269      if (nvram_size > 0x40000)
1270         nvram_size = 0x40000;
1271
1272      m_cart[0].m_nvram = auto_alloc_array_clear(machine(), UINT8, nvram_size);
1273      m_cart[0].m_nvram_size = nvram_size;
1274   }
1275
12421276   /* all NSS games seem to use MODE 20 */
12431277   m_cart[0].mode = SNES_MODE_20;
1244   m_cart[0].sram_max = 0x40000;
12451278   m_has_addon_chip = HAS_NONE;
12461279
12471280   /* Find the number of blocks in this ROM */
r21632r21633
12841317
12851318      read_blocks += repeat_blocks;
12861319   }
1287
1288   /* Find the amount of sram */
1289   m_cart[0].sram = snes_r_bank1(space, 0x00ffd8);
1290   if (m_cart[0].sram > 0)
1291   {
1292      m_cart[0].sram = (1024 << m_cart[0].sram);
1293      if (m_cart[0].sram > m_cart[0].sram_max)
1294         m_cart[0].sram = m_cart[0].sram_max;
1295   }
12961320}
12971321
12981322DRIVER_INIT_MEMBER(snes_state,snes_hirom)
12991323{
1300   address_space &space = machine().device("maincpu")->memory().space(AS_PROGRAM);
13011324   UINT16 total_blocks, read_blocks;
13021325   UINT8  *rom;
13031326
r21632r21633
13051328   snes_ram = auto_alloc_array(machine(), UINT8, 0x1400000);
13061329   memset(snes_ram, 0, 0x1400000);
13071330
1331   m_cart[0].m_rom_size = memregion("user3")->bytes();
1332   m_cart[0].m_rom = auto_alloc_array_clear(machine(), UINT8, m_cart[0].m_rom_size);
1333   memcpy(m_cart[0].m_rom, rom, m_cart[0].m_rom_size);
1334
1335   m_cart[0].m_nvram_size = 0;
1336   if (rom[0xffd8] > 0)
1337   {
1338      UINT32 nvram_size = (1024 << rom[0xffd8]);
1339      if (nvram_size > 0x40000)
1340         nvram_size = 0x40000;
1341
1342      m_cart[0].m_nvram = auto_alloc_array_clear(machine(), UINT8, nvram_size);
1343      m_cart[0].m_nvram_size = nvram_size;
1344   }
1345
13081346   m_cart[0].mode = SNES_MODE_21;
1309   m_cart[0].sram_max = 0x40000;
13101347   m_has_addon_chip = HAS_NONE;
13111348
13121349   /* Find the number of blocks in this ROM */
r21632r21633
13431380      memcpy(&snes_ram[0x800000 + read_blocks * 0x10000], &snes_ram[0x800000 + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
13441381      read_blocks += repeat_blocks;
13451382   }
1346
1347   /* Find the amount of sram */
1348   m_cart[0].sram = snes_r_bank1(space, 0x00ffd8);
1349   if (m_cart[0].sram > 0)
1350   {
1351      m_cart[0].sram = (1024 << m_cart[0].sram);
1352      if (m_cart[0].sram > m_cart[0].sram_max)
1353         m_cart[0].sram = m_cart[0].sram_max;
1354   }
13551383}
13561384
13571385
trunk/src/mame/includes/snes.h
r21632r21633
551551
552552struct snes_cart_info
553553{
554   UINT8 *m_rom;
555   UINT32 m_rom_size;
556   UINT8 *m_nvram;
557   UINT32 m_nvram_size;
554558   UINT8  mode;        /* ROM memory mode */
555   UINT32 sram;        /* Amount of sram in cart */
556559   UINT32 sram_max;    /* Maximum amount sram in cart (based on ROM mode) */
557   int    small_sram;
558560   int    slot_in_use; /* this is needed by Sufami Turbo slots (to check if SRAM has to be saved) */
559561};
560562
trunk/src/mess/machine/snescart.c
r21632r21633
123123static void snes_load_sram(running_machine &machine)
124124{
125125   snes_state *state = machine.driver_data<snes_state>();
126   UINT8 ii;
127   UINT8 *battery_ram, *ptr;
128
129   battery_ram = (UINT8*)malloc(state->m_cart[0].sram_max);
130   ptr = battery_ram;
131126   device_image_interface *image = dynamic_cast<device_image_interface *>(machine.device("cart"));
132   image->battery_load(battery_ram, state->m_cart[0].sram_max, 0xff);
133
134   if (state->m_cart[0].mode == SNES_MODE_20)
135   {
136      UINT32 size = state->m_cart[0].small_sram ? 0x8000 : 0x10000;
137
138      /* There could be some larger image needing banks 0x70 to 0x7f at address 0x8000 for ROM
139       * mirroring. These should be treated separately or data would be overwritten by SRAM */
140      for (ii = 0; ii < 16; ii++)
141      {
142         /* loading */
143         memmove(&snes_ram[0x700000 + (ii * 0x010000)], ptr, size);
144         /* mirroring */
145         memcpy(&snes_ram[0xf00000 + (ii * 0x010000)], &snes_ram[0x700000 + (ii * 0x010000)], size);
146         ptr += size;
147      }
148   }
149   else if (state->m_cart[0].mode == SNES_MODE_21)
150   {
151      for (ii = 0; ii < 16; ii++)
152      {
153         /* loading */
154         memmove(&snes_ram[0x306000 + (ii * 0x010000)], ptr, 0x2000);
155         /* mirroring */
156         memcpy(&snes_ram[0xb06000 + (ii * 0x010000)], &snes_ram[0x306000 + (ii * 0x010000)], 0x2000);
157         ptr += 0x2000;
158      }
159   }
160   else if (state->m_cart[0].mode == SNES_MODE_25)
161   {
162      for (ii = 0; ii < 16; ii++)
163      {
164         memmove(&snes_ram[0xb06000 + (ii * 0x010000)], ptr, 0x2000);
165         ptr += 0x2000;
166      }
167   }
168
169   free(battery_ram);
127   image->battery_load(state->m_cart[0].m_nvram, state->m_cart[0].m_nvram_size, 0xff);
170128}
171129
172130/* Saves the battery backed RAM from the appropriate memory area */
173131static void snes_save_sram(running_machine &machine)
174132{
175133   snes_state *state = machine.driver_data<snes_state>();
176   UINT8 ii;
177   UINT8 *battery_ram, *ptr;
178
179   battery_ram = (UINT8*)malloc(state->m_cart[0].sram_max);
180   ptr = battery_ram;
181
182   if (state->m_cart[0].mode == SNES_MODE_20)
183   {
184      UINT32 size = state->m_cart[0].small_sram ? 0x8000 : 0x10000;
185
186      for (ii = 0; ii < 16; ii++)
187      {
188         memmove(ptr, &snes_ram[0x700000 + (ii * 0x010000)], size);
189         ptr += size;
190      }
191   }
192   else if (state->m_cart[0].mode == SNES_MODE_21)
193   {
194      for (ii = 0; ii < 16; ii++)
195      {
196         memmove(ptr, &snes_ram[0x306000 + (ii * 0x010000)], 0x2000);
197         ptr += 0x2000;
198      }
199   }
200   else if (state->m_cart[0].mode == SNES_MODE_25)
201   {
202      for (ii = 0; ii < 16; ii++)
203      {
204         memmove(ptr, &snes_ram[0xb06000 + (ii * 0x010000)], 0x2000);
205         ptr += 0x2000;
206      }
207   }
208134   device_image_interface *image = dynamic_cast<device_image_interface *>(machine.device("cart"));
209   image->battery_save(battery_ram, state->m_cart[0].sram_max);
210
211   free(battery_ram);
135   image->battery_save(state->m_cart[0].m_nvram, state->m_cart[0].m_nvram_size);
212136}
213137
214138void snes_machine_stop(running_machine &machine)
r21632r21633
216140   snes_state *state = machine.driver_data<snes_state>();
217141
218142   /* Save SRAM */
219   if (state->m_cart[0].sram > 0)
143   if (state->m_cart[0].m_nvram_size > 0)
220144      snes_save_sram(machine);
221145}
222146
r21632r21633
437361
438362
439363/* This determines if a cart is in Mode 20, 21, 22 or 25; sets state->m_cart[0].mode and
440 state->m_cart[0].sram accordingly; and returns the offset of the internal header (needed to
441 detect BSX and ST carts) */
364 state->m_cart[0].sram_max accordingly; and returns the offset of the internal header
365 (needed to detect BSX and ST carts) */
442366static UINT32 snes_find_hilo_mode( device_image_interface &image, UINT8 *buffer, UINT32 offset, int cartid )
443367{
444368   snes_state *state = image.device().machine().driver_data<snes_state>();
r21632r21633
731655   logerror( " [%d]\n", snes_r_bank1(space, 0x00ffd6) );
732656
733657   logerror( "\tSize:          %d megabits [%d]\n", 1 << (snes_r_bank1(space, 0x00ffd7) - 7), snes_r_bank1(space, 0x00ffd7) );
734   logerror( "\tSRAM:          %d kilobits [%d]\n", state->m_cart[0].sram * 8, snes_ram[0xffd8] );
658   logerror( "\tSRAM:          %d kilobits [%d]\n", state->m_cart[0].m_nvram_size * 8, snes_ram[0xffd8] );
735659   logerror( "\tCountry:       %s [%d]\n", countries[snes_r_bank1(space, 0x00ffd9)], snes_r_bank1(space, 0x00ffd9) );
736660   logerror( "\tLicense:       %s [%X]\n", companies[snes_r_bank1(space, 0x00ffda)], snes_r_bank1(space, 0x00ffda) );
737661   logerror( "\tVersion:       1.%d\n", snes_r_bank1(space, 0x00ffdb) );
r21632r21633
773697
774698   if (SNES_CART_DEBUG) mame_printf_error("size %08X\n", m_cart_size - offset);
775699
700   m_cart[0].m_rom_size = m_cart_size;
701   m_cart[0].m_rom = auto_alloc_array_clear(machine, UINT8, m_cart[0].m_rom_size);
702   memcpy(m_cart[0].m_rom, ROM, m_cart[0].m_rom_size - offset);
703
776704   /* First, look if the cart is HiROM or LoROM (and set snes_cart accordingly) */
777705   int_header_offs = snes_find_hilo_mode(image, ROM, offset, 0);
778706
r21632r21633
914842            /* Loading data */
915843            memcpy(&snes_ram[0xc00000 + read_blocks * 0x10000], &ROM[0x000000 + read_blocks * 0x10000], 0x10000);
916844            /* Mirroring */
917            memcpy( &snes_ram[0x808000 + read_blocks * 0x10000], &snes_ram[0xc08000 + read_blocks * 0x10000], 0x8000);
845            memcpy(&snes_ram[0x808000 + read_blocks * 0x10000], &snes_ram[0xc08000 + read_blocks * 0x10000], 0x8000);
918846            read_blocks++;
919847         }
920848         /* ExHiROMs are supposed to be larger than 32Mbits! */
r21632r21633
1066994                  j++;
1067995               repeat_blocks = read_blocks % (128 >> (j - 1));
1068996
1069               memcpy( &snes_ram[read_blocks * 0x10000], &snes_ram[(read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
1070               memcpy( &snes_ram[0x800000 + read_blocks * 0x10000], &snes_ram[(read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
997               memcpy(&snes_ram[read_blocks * 0x10000], &snes_ram[(read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
998               memcpy(&snes_ram[0x800000 + read_blocks * 0x10000], &snes_ram[(read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
1071999               read_blocks += repeat_blocks;
10721000            }
10731001         }
r21632r21633
10771005   /* Detect special chips */
10781006   supported_type = snes_find_addon_chip(machine);
10791007
1080   /* Find the amount of cart ram (even if we call it sram...) */
1008   /* Find the amount of cart ram */
1009   m_cart[0].m_nvram_size = 0;
10811010   if (image.software_entry() == NULL)
10821011   {
1012      UINT32 nvram_size;
10831013      if ((m_has_addon_chip != HAS_SUPERFX))
1084         m_cart[0].sram = snes_r_bank1(space, 0x00ffd8);
1014         nvram_size = snes_r_bank1(space, 0x00ffd8);
10851015      else
1086         m_cart[0].sram = (snes_r_bank1(space, 0x00ffbd) & 0x07);
1016         nvram_size = (snes_r_bank1(space, 0x00ffbd) & 0x07);
10871017
1088      if (m_cart[0].sram > 0)
1018      if (nvram_size > 0)
10891019      {
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;
1020         nvram_size = (1024 << nvram_size);
1021         if (nvram_size > m_cart[0].sram_max)
1022            nvram_size = m_cart[0].sram_max;
1023
1024         m_cart[0].m_nvram_size = nvram_size;
10931025      }
1094//      printf("size %x\n", m_cart[0].sram);
1026//      printf("size %x\n", m_cart[0].m_nvram_size);
10951027   }
10961028   else
10971029   {
10981030      // if we are loading from softlist, take memory length from the xml
1099      m_cart[0].sram = image.get_software_region("nvram") ? image.get_software_region_length("nvram") : 0;
1031      m_cart[0].m_nvram_size = image.get_software_region("nvram") ? image.get_software_region_length("nvram") : 0;
11001032
1101      if (m_cart[0].sram > 0)
1033      if (m_cart[0].m_nvram_size > 0)
11021034      {
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);
1035         if (m_cart[0].m_nvram_size > m_cart[0].sram_max)
1036            fatalerror("Found more memory than max allowed (found: %x, max: %x), check xml file!\n", m_cart[0].m_nvram_size, m_cart[0].sram_max);
11051037      }
11061038      // TODO: Eventually sram handlers should point to the allocated cart:sram region!
11071039      // For now, we only use the region as a placeholder to carry size info...
1108//      printf("size %x\n", m_cart[0].sram);
1040//      printf("size %x\n", m_cart[0].m_nvram_size);
11091041   }
11101042
1111   /* adjust size for very large carts */
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;
1114   else
1115      m_cart[0].small_sram = 0;
1043   if (m_cart[0].m_nvram_size > 0)
1044      m_cart[0].m_nvram = auto_alloc_array_clear(machine, UINT8, m_cart[0].m_nvram_size);
11161045
11171046   /* Log snes_cart information */
11181047   snes_cart_log_info(machine, total_blocks, supported_type);
r21632r21633
12191148      read_blocks += repeat_blocks;
12201149   }
12211150
1151   // currently we still use snes_ram for STROM ram...
1152//  m_cart[slot_id].m_nvram_size = 0x20000;
1153//  m_cart[slot_id].m_nvram = auto_alloc_array_clear(machine, UINT8, m_cart[slot_id].m_nvram_size);
1154   m_cart[slot_id].m_nvram_size = 0;
1155
12221156   sufami_load_sram(machine, image.device().tag());
12231157
12241158   m_cart[slot_id].slot_in_use = 1; // aknowledge the cart in this slot, for saving sram at exit

Previous 199869 Revisions Next


© 1997-2024 The MAME Team