Previous 199869 Revisions Next

r31795 Wednesday 27th August, 2014 at 07:07:58 UTC by Fabio Priuli
(MESS) vcs_slot: avoid possible crashes when loading a new game from the internal UI. nw.
[src/emu/bus/vcs]vcs_slot.c

trunk/src/emu/bus/vcs/vcs_slot.c
r31794r31795
178178
179179bool vcs_cart_slot_device::call_load()
180180{
181   UINT8 *ROM;
182   UINT32 len;
183
184   if (software_entry() != NULL)
185      len = get_software_region_length("rom");
186   else
187      len = length();
188
189   //printf("Size: 0x%X\n", len);
190
191   // check that filesize is among the supported ones
192   switch (len)
181   if (m_cart)
193182   {
194   case 0x00800:
195   case 0x01000:
196   case 0x02000:
197   case 0x028ff:
198   case 0x02900:
199   case 0x03000:
200   case 0x04000:
201   case 0x08000:
202   case 0x10000:
203   case 0x80000:
204      break;
205
206   default:
207      seterror(IMAGE_ERROR_UNSUPPORTED, "Invalid rom file size" );
208      return IMAGE_INIT_FAIL;
209   }
210
211   m_cart->rom_alloc(len);
212   ROM = m_cart->get_rom_base();
213
214   if (software_entry() != NULL)
215   {
216      const char *pcb_name;
217      memcpy(ROM, get_software_region("rom"), len);
218
219      if ((pcb_name = get_feature("slot")) != NULL)
220         m_type = vcs_get_pcb_id(pcb_name);
183      UINT8 *ROM;
184      UINT32 len;
185     
186      if (software_entry() != NULL)
187         len = get_software_region_length("rom");
221188      else
189         len = length();
190     
191      //printf("Size: 0x%X\n", len);
192     
193      // check that filesize is among the supported ones
194      switch (len)
222195      {
223         // identify type based on size
224         switch (len)
196         case 0x00800:
197         case 0x01000:
198         case 0x02000:
199         case 0x028ff:
200         case 0x02900:
201         case 0x03000:
202         case 0x04000:
203         case 0x08000:
204         case 0x10000:
205         case 0x80000:
206            break;
207           
208         default:
209            seterror(IMAGE_ERROR_UNSUPPORTED, "Invalid rom file size" );
210            return IMAGE_INIT_FAIL;
211      }
212     
213      m_cart->rom_alloc(len);
214      ROM = m_cart->get_rom_base();
215     
216      if (software_entry() != NULL)
217      {
218         const char *pcb_name;
219         memcpy(ROM, get_software_region("rom"), len);
220         
221         if ((pcb_name = get_feature("slot")) != NULL)
222            m_type = vcs_get_pcb_id(pcb_name);
223         else
225224         {
226            case 0x800:
227               m_type = A26_2K;
228               break;
229            case 0x1000:
230               m_type = A26_4K;
231               break;
232            case 0x2000:
233               m_type = A26_F8;
234               break;
235            case 0x28ff:
236            case 0x2900:
237               m_type = A26_DPC;
238               break;
239            case 0x3000:
240               m_type = A26_FA;
241               break;
242            case 0x4000:
243               m_type = A26_F6;
244               break;
245            case 0x8000:
246               m_type = A26_F4;
247               break;
248            case 0x10000:
249               m_type = A26_32IN1;
250               break;
251            case 0x80000:
252               m_type = A26_3F;
253               break;
254            default:
255               m_type = A26_4K;
256               printf("Unrecognized cart type!\n");
257               break;
225            // identify type based on size
226            switch (len)
227            {
228               case 0x800:
229                  m_type = A26_2K;
230                  break;
231               case 0x1000:
232                  m_type = A26_4K;
233                  break;
234               case 0x2000:
235                  m_type = A26_F8;
236                  break;
237               case 0x28ff:
238               case 0x2900:
239                  m_type = A26_DPC;
240                  break;
241               case 0x3000:
242                  m_type = A26_FA;
243                  break;
244               case 0x4000:
245                  m_type = A26_F6;
246                  break;
247               case 0x8000:
248                  m_type = A26_F4;
249                  break;
250               case 0x10000:
251                  m_type = A26_32IN1;
252                  break;
253               case 0x80000:
254                  m_type = A26_3F;
255                  break;
256               default:
257                  m_type = A26_4K;
258                  printf("Unrecognized cart type!\n");
259                  break;
260            }
261           
258262         }
259         
260263      }
261   }
262   else
263   {
264      fread(ROM, len);
265      m_type = identify_cart_type(ROM, len);
266   }
267
268   //printf("Type: %s\n", vcs_get_slot(m_type));
269
270   // check for Special Chip (128bytes of RAM)
271   if (len == 0x2000 || len == 0x4000 || len == 0x8000)
272      if (detect_super_chip(ROM, len))
264      else
273265      {
274         m_cart->ram_alloc(0x80);
275         //printf("Super Chip detected!\n");
266         fread(ROM, len);
267         m_type = identify_cart_type(ROM, len);
276268      }
277   // Super chip games:
278   // dig dig, crystal castles, millipede, stargate, defender ii, jr. Pac Man,
279   // desert falcon, dark chambers, super football, sprintmaster, fatal run,
280   // off the wall, shooting arcade, secret quest, radar lock, save mary, klax
281
282   // add CBS RAM+ (128bytes of RAM)
283   if (m_type == A26_FA)
284      m_cart->ram_alloc(0x100);
285   // add M Network RAM
286   else if (m_type == A26_E7)
287      m_cart->ram_alloc(0x800);
288   // add Commavid RAM
289   else if (m_type == A26_CV)
290      m_cart->ram_alloc(0x400);
291   // add Starpath Superchager RAM
292   else if (m_type == A26_SS)
293      m_cart->ram_alloc(0x1800);
294   // add Boulder Dash RAM
295   else if (m_type == A26_3E)
296      m_cart->ram_alloc(0x8000);
297
298   // pass a pointer to the now allocated ROM for the DPC chip
299   if (m_type == A26_DPC)
300      m_cart->setup_addon_ptr((UINT8 *)m_cart->get_rom_base() + 0x2000);
301
269     
270      //printf("Type: %s\n", vcs_get_slot(m_type));
271     
272      // check for Special Chip (128bytes of RAM)
273      if (len == 0x2000 || len == 0x4000 || len == 0x8000)
274         if (detect_super_chip(ROM, len))
275         {
276            m_cart->ram_alloc(0x80);
277            //printf("Super Chip detected!\n");
278         }
279      // Super chip games:
280      // dig dig, crystal castles, millipede, stargate, defender ii, jr. Pac Man,
281      // desert falcon, dark chambers, super football, sprintmaster, fatal run,
282      // off the wall, shooting arcade, secret quest, radar lock, save mary, klax
283     
284      // add CBS RAM+ (128bytes of RAM)
285      if (m_type == A26_FA)
286         m_cart->ram_alloc(0x100);
287      // add M Network RAM
288      else if (m_type == A26_E7)
289         m_cart->ram_alloc(0x800);
290      // add Commavid RAM
291      else if (m_type == A26_CV)
292         m_cart->ram_alloc(0x400);
293      // add Starpath Superchager RAM
294      else if (m_type == A26_SS)
295         m_cart->ram_alloc(0x1800);
296      // add Boulder Dash RAM
297      else if (m_type == A26_3E)
298         m_cart->ram_alloc(0x8000);
299     
300      // pass a pointer to the now allocated ROM for the DPC chip
301      if (m_type == A26_DPC)
302         m_cart->setup_addon_ptr((UINT8 *)m_cart->get_rom_base() + 0x2000);
303     
304      return IMAGE_INIT_PASS;
305   }
306   
302307   return IMAGE_INIT_PASS;
303308}
304309

Previous 199869 Revisions Next


© 1997-2024 The MAME Team