Previous 199869 Revisions Next

r22586 Sunday 28th April, 2013 at 04:29:12 UTC by Robbbert
(MESS) Homelab, vc4000, d6800: fixed memory leak
[src/mess/drivers]d6800.c homelab.c vc4000.c

trunk/src/mess/drivers/vc4000.c
r22585r22586
533533   int quick_length;
534534   UINT8 *quick_data;
535535   int read_;
536   int result = IMAGE_INIT_FAIL;
536537
537538   quick_length = image.length();
538539   quick_data = (UINT8*)malloc(quick_length);
r22585r22586
540541   {
541542      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file");
542543      image.message(" Cannot open file");
543      return IMAGE_INIT_FAIL;
544544   }
545
546   read_ = image.fread( quick_data, quick_length);
547   if (read_ != quick_length)
545   else
548546   {
549      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file");
550      image.message(" Cannot read the file");
551      return IMAGE_INIT_FAIL;
552   }
553
554   if (mame_stricmp(image.filetype(), "tvc")==0)
555   {
556      if (quick_data[0] != 2)
547      read_ = image.fread( quick_data, quick_length);
548      if (read_ != quick_length)
557549      {
558         image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header");
559         image.message(" Invalid header");
560         return IMAGE_INIT_FAIL;
550         image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file");
551         image.message(" Cannot read the file");
561552      }
553      else
554      {
555         if (mame_stricmp(image.filetype(), "tvc")==0)
556         {
557            if (quick_data[0] != 2)
558            {
559               image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header");
560               image.message(" Invalid header");
561            }
562            else
563            {
564               quick_addr = quick_data[1] * 256 + quick_data[2];
565               exec_addr = quick_data[3] * 256 + quick_data[4];
562566
563      quick_addr = quick_data[1] * 256 + quick_data[2];
564      exec_addr = quick_data[3] * 256 + quick_data[4];
567               space.write_byte(0x08be, quick_data[3]);
568               space.write_byte(0x08bf, quick_data[4]);
565569
566      space.write_byte(0x08be, quick_data[3]);
567      space.write_byte(0x08bf, quick_data[4]);
570               for (i = 0; i < quick_length - 5; i++)
571                  if ((quick_addr + i) < 0x1600)
572                     space.write_byte(i + quick_addr, quick_data[i+5]);
568573
569      for (i = 0; i < quick_length - 5; i++)
570         if ((quick_addr + i) < 0x1600)
571            space.write_byte(i + quick_addr, quick_data[i+5]);
574               /* display a message about the loaded quickload */
575               image.message(" Quickload: size=%04X : start=%04X : end=%04X : exec=%04X",quick_length-5,quick_addr,quick_addr+quick_length-5,exec_addr);
572576
573      /* display a message about the loaded quickload */
574      image.message(" Quickload: size=%04X : start=%04X : end=%04X : exec=%04X",quick_length-5,quick_addr,quick_addr+quick_length-5,exec_addr);
577               // Start the quickload
578               m_maincpu->set_pc(exec_addr);
579               result = IMAGE_INIT_PASS;
580            }
581         }
582         else
583         if (mame_stricmp(image.filetype(), "pgm")==0)
584         {
585            if (quick_data[0] != 0)
586            {
587               image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header");
588               image.message(" Invalid header");
589            }
590            else
591            {
592               exec_addr = quick_data[1] * 256 + quick_data[2];
575593
576      // Start the quickload
577      m_maincpu->set_pc(exec_addr);
578      return IMAGE_INIT_PASS;
579   }
580   else
581   if (mame_stricmp(image.filetype(), "pgm")==0)
582   {
583      if (quick_data[0] != 0)
584      {
585         image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header");
586         image.message(" Invalid header");
587         return IMAGE_INIT_FAIL;
588      }
594               if (exec_addr >= quick_length)
595               {
596                  image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Exec address beyond end of file");
597                  image.message(" Exec address beyond end of file");
598               }
599               else
600               if (quick_length < 0x904)
601               {
602                  image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too short");
603                  image.message(" File too short");
604               }
605               else
606               // some programs store data in PVI memory and other random places. This is not supported.
607               if (quick_length > 0x1600)
608               {
609                  image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too long");
610                  image.message(" File too long");
611               }
612               else
613               {
614                  for (i = quick_addr; i < quick_length; i++)
615                     if (i < 0x1600)
616                        space.write_byte(i, quick_data[i]);
589617
590      exec_addr = quick_data[1] * 256 + quick_data[2];
618                  /* display a message about the loaded quickload */
619                  image.message(" Quickload: size=%04X : exec=%04X",quick_length,exec_addr);
591620
592      if (exec_addr >= quick_length)
593      {
594         image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Exec address beyond end of file");
595         image.message(" Exec address beyond end of file");
596         return IMAGE_INIT_FAIL;
621                  // Start the quickload
622                  m_maincpu->set_pc(exec_addr);
623                  result = IMAGE_INIT_PASS;
624               }
625            }
626         }
597627      }
598
599      if (quick_length < 0x904)
600      {
601         image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too short");
602         image.message(" File too short");
603         return IMAGE_INIT_FAIL;
604      }
605
606      // some programs store data in PVI memory and other random places. This is not supported.
607      if (quick_length > 0x1600)
608      {
609         image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too long");
610         image.message(" File too long");
611         return IMAGE_INIT_FAIL;
612      }
613
614      for (i = quick_addr; i < quick_length; i++)
615         if (i < 0x1600)
616            space.write_byte(i, quick_data[i]);
617
618      /* display a message about the loaded quickload */
619      image.message(" Quickload: size=%04X : exec=%04X",quick_length,exec_addr);
620
621      // Start the quickload
622      m_maincpu->set_pc(exec_addr);
623      return IMAGE_INIT_PASS;
628      free (quick_data);
624629   }
625   else
626      return IMAGE_INIT_FAIL;
630   return result;
627631}
628632
629633
trunk/src/mess/drivers/d6800.c
r22585r22586
338338{
339339   address_space &space = m_maincpu->space(AS_PROGRAM);
340340   int i;
341   int quick_addr = 0x0200;
341   int quick_addr = 0x200;
342342   int exec_addr = 0xc000;
343343   int quick_length;
344344   UINT8 *quick_data;
345345   int read_;
346   int result = IMAGE_INIT_FAIL;
346347
347348   quick_length = image.length();
348349   quick_data = (UINT8*)malloc(quick_length);
r22585r22586
350351   {
351352      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file");
352353      image.message(" Cannot open file");
353      return IMAGE_INIT_FAIL;
354354   }
355
356   read_ = image.fread( quick_data, quick_length);
357   if (read_ != quick_length)
355   else
358356   {
359      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file");
360      image.message(" Cannot read the file");
361      return IMAGE_INIT_FAIL;
362   }
357      read_ = image.fread( quick_data, quick_length);
358      if (read_ != quick_length)
359      {
360         image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file");
361         image.message(" Cannot read the file");
362      }
363      else
364      {
365         for (i = 0; i < quick_length; i++)
366            if ((quick_addr + i) < 0x800)
367               space.write_byte(i + quick_addr, quick_data[i]);
363368
364   for (i = 0; i < quick_length; i++)
365      if ((quick_addr + i) < 0x800)
366         space.write_byte(i + quick_addr, quick_data[i]);
369         /* display a message about the loaded quickload */
370         image.message(" Quickload: size=%04X : start=%04X : end=%04X : exec=%04X",quick_length,quick_addr,quick_addr+quick_length,exec_addr);
367371
368   /* display a message about the loaded quickload */
369   image.message(" Quickload: size=%04X : start=%04X : end=%04X : exec=%04X",quick_length,quick_addr,quick_addr+quick_length,exec_addr);
372         // Start the quickload
373         m_maincpu->set_pc(exec_addr);
370374
371   // Start the quickload
372   m_maincpu->set_pc(exec_addr);
373   return IMAGE_INIT_PASS;
375         result = IMAGE_INIT_PASS;
376      }
377
378      free( quick_data );
379   }
380
381   return result;
374382}
375383
376384static MACHINE_CONFIG_START( d6800, d6800_state )
trunk/src/mess/drivers/homelab.c
r22585r22586
1010
1111    ToDO:
1212    - HTP files should be a cassette format, not a quickload.
13    - Quickloads cause the emulated machine to hang or reboot.
1314    - homelab2 - cassette to fix.
1415                 Note that rom code 0x40-48 is meaningless garbage,
1516                 had to patch to stop it crashing. Need a new dump.
r22585r22586
661662   {
662663      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file");
663664      image.message(" Cannot open file");
665      free(quick_data);
664666      return IMAGE_INIT_FAIL;
665667   }
666668
r22585r22586
669671   {
670672      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file");
671673      image.message(" Cannot read the file");
674      free(quick_data);
672675      return IMAGE_INIT_FAIL;
673676   }
674677
r22585r22586
678681   {
679682      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header");
680683      image.message(" Invalid header");
684      free(quick_data);
681685      return IMAGE_INIT_FAIL;
682686   }
683687
r22585r22586
687691      {
688692         image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File name too long");
689693         image.message(" File name too long");
694         free(quick_data);
690695         return IMAGE_INIT_FAIL;
691696      }
692697
r22585r22586
700705   {
701706      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Unexpected EOF while getting file size");
702707      image.message(" Unexpected EOF while getting file size");
708      free(quick_data);
703709      return IMAGE_INIT_FAIL;
704710   }
705711
r22585r22586
711717   {
712718      image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too large");
713719      image.message(" File too large");
720      free(quick_data);
714721      return IMAGE_INIT_FAIL;
715722   }
716723
r22585r22586
726733         snprintf(message, ARRAY_LENGTH(message), "%s: Unexpected EOF while writing byte to %04X", pgmname, (unsigned) j);
727734         image.seterror(IMAGE_ERROR_INVALIDIMAGE, message);
728735         image.message("%s: Unexpected EOF while writing byte to %04X", pgmname, (unsigned) j);
736         free(quick_data);
729737         return IMAGE_INIT_FAIL;
730738      }
731739      space.write_byte(j, ch);
732740   }
733741
742   free(quick_data);
734743   return IMAGE_INIT_PASS;
735744}
736745

Previous 199869 Revisions Next


© 1997-2024 The MAME Team