Previous 199869 Revisions Next

r21568 Monday 4th March, 2013 at 15:09:43 UTC by Miodrag Milanović
small cleanup (nw)
[src/mess/drivers]studio2.c timex.c
[src/mess/includes]studio2.h

trunk/src/mess/includes/studio2.h
r21567r21568
5050   DECLARE_READ_LINE_MEMBER( ef4_r );
5151   DECLARE_WRITE_LINE_MEMBER( q_w );
5252   DECLARE_INPUT_CHANGED_MEMBER( reset_w );
53   DECLARE_DEVICE_IMAGE_LOAD_MEMBER( st2_cartslot_load );
5354   DECLARE_DEVICE_IMAGE_LOAD_MEMBER( studio2_cart_load );
5455
5556   /* keyboard state */
trunk/src/mess/drivers/timex.c
r21567r21568
174174
175175static timex_cart_t timex_cart;
176176
177
178DEVICE_IMAGE_LOAD_LEGACY( timex_cart )
179{
180   int file_size;
181   UINT8 * file_data;
182
183   int chunks_in_file = 0;
184
185   int i;
186
187   logerror ("Trying to load cart\n");
188
189   file_size = image.length();
190
191   if (file_size < 0x09)
192   {
193      logerror ("Bad file size\n");
194      return IMAGE_INIT_FAIL;
195   }
196
197   file_data = (UINT8 *)malloc(file_size);
198   if (file_data == NULL)
199   {
200      logerror ("Memory allocating error\n");
201      return IMAGE_INIT_FAIL;
202   }
203
204   image.fread(file_data, file_size);
205
206   for (i=0; i<8; i++)
207      if(file_data[i+1]&0x02) chunks_in_file++;
208
209   if (chunks_in_file*0x2000+0x09 != file_size)
210   {
211      free (file_data);
212      logerror ("File corrupted\n");
213      return IMAGE_INIT_FAIL;
214   }
215
216   switch (file_data[0x00])
217   {
218      case 0x00:  logerror ("DOCK cart\n");
219            timex_cart.type = TIMEX_CART_DOCK;
220            timex_cart.data = (UINT8*) malloc (0x10000);
221            if (!timex_cart.data)
222            {
223               free (file_data);
224               logerror ("Memory allocate error\n");
225               return IMAGE_INIT_FAIL;
226            }
227            chunks_in_file = 0;
228            for (i=0; i<8; i++)
229            {
230               timex_cart.chunks = timex_cart.chunks | ((file_data[i+1]&0x01)<<i);
231               if (file_data[i+1]&0x02)
232               {
233                  memcpy (timex_cart.data+i*0x2000, file_data+0x09+chunks_in_file*0x2000, 0x2000);
234                  chunks_in_file++;
235               }
236               else
237               {
238                  if (file_data[i+1]&0x01)
239                     memset (timex_cart.data+i*0x2000, 0x00, 0x2000);
240                  else
241                     memset (timex_cart.data+i*0x2000, 0xff, 0x2000);
242               }
243            }
244            free (file_data);
245            break;
246
247      default:    logerror ("Cart type not supported\n");
248            free (file_data);
249            timex_cart.type = TIMEX_CART_NONE;
250            return IMAGE_INIT_FAIL;
251   }
252
253   logerror ("Cart loaded\n");
254   logerror ("Chunks %02x\n", timex_cart.chunks);
255   return IMAGE_INIT_PASS;
256}
257
258DEVICE_IMAGE_UNLOAD_LEGACY( timex_cart )
259{
260   if (timex_cart.data)
261   {
262      free (timex_cart.data);
263      timex_cart.data = NULL;
264   }
265   timex_cart.type = TIMEX_CART_NONE;
266   timex_cart.chunks = 0x00;
267}
268
269177const timex_cart_t *timex_cart_data(void)
270178{
271179   return &timex_cart;
r21567r21568
712620
713621DEVICE_IMAGE_LOAD_MEMBER( spectrum_state, timex_cart )
714622{
715   return device_load_timex_cart( image );
623   int file_size;
624   UINT8 * file_data;
625
626   int chunks_in_file = 0;
627
628   int i;
629
630   logerror ("Trying to load cart\n");
631
632   file_size = image.length();
633
634   if (file_size < 0x09)
635   {
636      logerror ("Bad file size\n");
637      return IMAGE_INIT_FAIL;
638   }
639
640   file_data = (UINT8 *)malloc(file_size);
641   if (file_data == NULL)
642   {
643      logerror ("Memory allocating error\n");
644      return IMAGE_INIT_FAIL;
645   }
646
647   image.fread(file_data, file_size);
648
649   for (i=0; i<8; i++)
650      if(file_data[i+1]&0x02) chunks_in_file++;
651
652   if (chunks_in_file*0x2000+0x09 != file_size)
653   {
654      free (file_data);
655      logerror ("File corrupted\n");
656      return IMAGE_INIT_FAIL;
657   }
658
659   switch (file_data[0x00])
660   {
661      case 0x00:  logerror ("DOCK cart\n");
662            timex_cart.type = TIMEX_CART_DOCK;
663            timex_cart.data = (UINT8*) malloc (0x10000);
664            if (!timex_cart.data)
665            {
666               free (file_data);
667               logerror ("Memory allocate error\n");
668               return IMAGE_INIT_FAIL;
669            }
670            chunks_in_file = 0;
671            for (i=0; i<8; i++)
672            {
673               timex_cart.chunks = timex_cart.chunks | ((file_data[i+1]&0x01)<<i);
674               if (file_data[i+1]&0x02)
675               {
676                  memcpy (timex_cart.data+i*0x2000, file_data+0x09+chunks_in_file*0x2000, 0x2000);
677                  chunks_in_file++;
678               }
679               else
680               {
681                  if (file_data[i+1]&0x01)
682                     memset (timex_cart.data+i*0x2000, 0x00, 0x2000);
683                  else
684                     memset (timex_cart.data+i*0x2000, 0xff, 0x2000);
685               }
686            }
687            free (file_data);
688            break;
689
690      default:    logerror ("Cart type not supported\n");
691            free (file_data);
692            timex_cart.type = TIMEX_CART_NONE;
693            return IMAGE_INIT_FAIL;
694   }
695
696   logerror ("Cart loaded\n");
697   logerror ("Chunks %02x\n", timex_cart.chunks);
698   return IMAGE_INIT_PASS;
716699}
717700
718701
719702DEVICE_IMAGE_UNLOAD_MEMBER( spectrum_state, timex_cart )
720703{
721   device_unload_timex_cart( image );
704   if (timex_cart.data)
705   {
706      free (timex_cart.data);
707      timex_cart.data = NULL;
708   }
709   timex_cart.type = TIMEX_CART_NONE;
710   timex_cart.chunks = 0x00;
722711}
723712
724713
trunk/src/mess/drivers/studio2.c
r21567r21568
234234***************************************************************************/
235235
236236/*-------------------------------------------------
237    DEVICE_IMAGE_LOAD( st2_cartslot_load )
237    DEVICE_IMAGE_LOAD_MEMBER( studio2_state, st2_cartslot_load )
238238-------------------------------------------------*/
239239
240DEVICE_IMAGE_LOAD_LEGACY( st2_cartslot_load )
240DEVICE_IMAGE_LOAD_MEMBER( studio2_state, st2_cartslot_load )
241241{
242242   st2_header header;
243243
r21567r21568
512512DEVICE_IMAGE_LOAD_MEMBER( studio2_state, studio2_cart_load )
513513{
514514   if (image.software_entry() == NULL)
515      return device_load_st2_cartslot_load(image);
515      return DEVICE_IMAGE_LOAD_MEMBER_NAME(st2_cartslot_load)(image);
516516   else
517517   {
518518      // WARNING: list code currently assume that cart mapping starts at 0x400.

Previous 199869 Revisions Next


© 1997-2024 The MAME Team