Previous 15994 Revisions Next

r3347 Monday 29th September, 2008 at 18:10:10 UTC by Fabio Priuli
[SNES] Moved cart mirroring at loading time (MAME part submitted to MAMEDev as well)
[src/mame/machine]snes.c
[src/mess/machine]snescart.c

src/mame/machine/snes.c
r3346r3347
460460      }
461461   }
462462   else
463   {
464      if( snes_cart.mode == SNES_MODE_20 )
465      {
466         return snes_ram[offset];
467      }
468      else   /* MODE_21 */
469      {
470         return snes_ram[0xc00000 + offset];
471      }
472   }
463      return snes_ram[offset];
473464
474465   return 0xff;
475466}
r3346r3347
513504      }
514505   }
515506   else
516   {
517      if( snes_cart.mode == SNES_MODE_20 )
518         return snes_ram[0x300000 + offset];
519      else   /* MODE_21 */
520         return snes_ram[0xf00000 + offset];
521   }
507      return snes_ram[0x300000 + offset];
522508
523509   return 0xff;
524510}
r3346r3347
528514{
529515   UINT16 address = offset & 0xffff;
530516
531   if( snes_cart.mode == SNES_MODE_20 )
532   {
533      if( address <= 0x7fff )
534         return 0xff;      /* Reserved */
535      else
536         return snes_ram[0x400000 + offset];
537   }
538   else   /* MODE_21 */
539   {
517   if( snes_cart.mode == SNES_MODE_20 && address <= 0x7fff )
518      return 0xff;      /* Reserved */
519   else
540520      return snes_ram[0x400000 + offset];
541   }
542521
543522   return 0xff;
544523}
r3346r3347
555534      else
556535         return DSP1_getDr();
557536   }
537   else
538      return snes_ram[0x600000 + offset];
558539
559540   return 0xff;
560541}
r3346r3347
562543/* 0x800000 - 0xffffff */
563544READ8_HANDLER( snes_r_bank4 )
564545{
565   if( snes_cart.mode == SNES_MODE_20 )
546   if (offset <= 0x3fffff)
547   {
548      if ((offset & 0xffff) < 0x8000)
549         return program_read_byte( offset );
550      else
551         return snes_ram[0x800000 + offset];
552   }
553   else if ( offset <= 0x5fffff )
566554   {
567      if( offset <= 0x5fffff )
568         return program_read_byte(offset );
555      if( snes_cart.mode == SNES_MODE_20 && (offset & 0xffff) < 0x8000)
556         return program_read_byte( offset );
569557      else
570         return 0xff;
558         return snes_ram[0x800000 + offset];
571559   }
572   else   /* MODE_21 */
560   else
573561   {
574      if( offset <= 0x3fffff )
575         return program_read_byte(offset );
576      else
562      if( snes_cart.mode == SNES_MODE_20 )
563         return 0xff;
564      else
577565         return snes_ram[offset + 0x800000];
578   }
566   }     
579567
580568   return 0xff;
581569}
r3346r3347
14841472/* for mame we use an init, maybe we will need more for the different games */
14851473DRIVER_INIT( snes )
14861474{
1487   int i;
1488   UINT16 totalblocks, readblocks;
1475   UINT16 total_blocks, read_blocks;
14891476   UINT8  *rom;
14901477
1491   rom = memory_region( machine, "user3" );
1478   rom = memory_region(machine, "user3");
14921479   snes_ram = auto_malloc(0x1000000);
1493   memset( snes_ram, 0, 0x1000000 );
1480   memset(snes_ram, 0, 0x1000000);
14941481
14951482   /* all NSS games seem to use MODE 20 */
14961483   snes_cart.mode = SNES_MODE_20;
14971484   snes_cart.sram_max = 0x40000;
14981485
14991486   /* Find the number of blocks in this ROM */
1500   //totalblocks = ((mame_fsize(file) - offset) >> (snes_cart.mode == MODE_20 ? 15 : 16));
1501   totalblocks = (memory_region_length(machine, "user3") / 0x8000) - 1;
1487   total_blocks = (memory_region_length(machine, "user3") / 0x8000);
1488   read_blocks = 0;
15021489
1503   /* FIXME: Insert crc check here */
1490   /* Loading all the data blocks from cart, we only partially cover banks 0x00 to 0x7f. Therefore, we
1491    * have to mirror the blocks until we reach the end. E.g. for a 11Mbits image (44 blocks), we proceed
1492    * as follows:
1493    * 11 Mbits = 8 Mbits (blocks 1->32) + 2 Mbits (blocks 33->40) + 1 Mbit (blocks 41->44).
1494    * Hence, we fill memory up to 16 Mbits (banks 0x00 to 0x3f) mirroring the final part:
1495    * 8 Mbits (blocks 1->32) + 2 Mbits (blocks 33->40) + 1 Mbit (blocks 41->44) + 1 Mbit (blocks 41->44)
1496    *   + 2 Mbits (blocks 33->40) + 1 Mbit (blocks 41->44) + 1 Mbit (blocks 41->44).
1497    * And we repeat the same blocks in the second half of the banks (banks 0x40 to 0x7f).
1498    * This is likely what happens in the real SNES as well, because the unit cannot be aware of the exact
1499    * size of data in the cart (procedure confirmed by byuu)
1500    */
15041501
1505   readblocks = 0;
1502   /* LoROM carts load data in banks 0x00 to 0x7f at address 0x8000 (actually up to 0x7d, because 0x7e and
1503    * 0x7f are overwritten by WRAM). Each block is also mirrored in banks 0x80 to 0xff (up to 0xff for real)
1504    */
1505   while (read_blocks < 128 && read_blocks < total_blocks)
15061506   {
1507      /* In mode 20, all blocks are 32kb. There are upto 96 blocks, giving a
1508         * total of 24mbit(3mb) of ROM.
1509         * The first 48 blocks are located in banks 0x00 to 0x2f at address
1510         * 0x8000.  They are mirrored in banks 0x80 to 0xaf.
1511         * The next 16 blocks are located in banks 0x30 to 0x3f at address
1512         * 0x8000.  They are mirrored in banks 0xb0 to 0xbf.
1513         * The final 32 blocks are located in banks 0x40 - 0x5f at address
1514         * 0x8000.  They are mirrored in banks 0xc0 to 0xdf.
1515         */
1516      i = 0;
1517      while( i < 96 && readblocks <= totalblocks )
1518      {
1519         //mame_fread( file, &snes_ram[(i++ * 0x10000) + 0x8000], 0x8000);
1520         memcpy(&snes_ram[(i * 0x10000) + 0x8000], &rom[i * 0x8000], 0x8000);
1521         i++;
1522         readblocks++;
1523      }
1507      /* Loading data */
1508      memcpy(&snes_ram[0x008000 + read_blocks * 0x10000], &rom[read_blocks * 0x08000], 0x8000);
1509      /* Mirroring */
1510      memcpy(&snes_ram[0x808000 + read_blocks * 0x10000], &snes_ram[0x8000 + read_blocks * 0x10000], 0x8000);
1511      read_blocks++;
15241512   }
1513   /* Filling banks up to 0x7f and their mirrors */
1514   while (read_blocks % 128)
1515   {
1516      int j = 0, repeat_blocks;
1517      while ((read_blocks % (128 >> j)) && j < 7)
1518         j++;
1519      repeat_blocks = read_blocks % (128 >> (j - 1));
15251520
1521      memcpy(&snes_ram[read_blocks * 0x10000], &snes_ram[(read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
1522      memcpy(&snes_ram[0x800000 + read_blocks * 0x10000], &snes_ram[0x800000 + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
1523
1524      read_blocks += repeat_blocks;
1525   }
1526
15261527   /* Find the amount of sram */
1527   snes_cart.sram = snes_r_bank1(machine,0x00ffd8);
1528   if( snes_cart.sram > 0 )
1528   snes_cart.sram = snes_r_bank1(machine, 0x00ffd8);
1529   if (snes_cart.sram > 0)
15291530   {
15301531      snes_cart.sram = ((1 << (snes_cart.sram + 3)) / 8);
1531      if( snes_cart.sram > snes_cart.sram_max )
1532      if (snes_cart.sram > snes_cart.sram_max)
15321533         snes_cart.sram = snes_cart.sram_max;
15331534   }
15341535}
15351536
15361537DRIVER_INIT( snes_hirom )
15371538{
1538   int i;
1539   UINT16 totalblocks, readblocks;
1539   UINT16 total_blocks, read_blocks;
15401540   UINT8  *rom;
15411541
1542   rom = memory_region( machine, "user3" );
1542   rom = memory_region(machine, "user3");
15431543   snes_ram = auto_malloc(0x1000000);
1544   memset( snes_ram, 0, 0x1000000 );
1544   memset(snes_ram, 0, 0x1000000);
15451545
15461546   snes_cart.mode = SNES_MODE_21;
15471547   snes_cart.sram_max = 0x40000;
15481548
15491549   /* Find the number of blocks in this ROM */
1550   //totalblocks = ((mame_fsize(file) - offset) >> (snes_cart.mode == MODE_20 ? 15 : 16));
1551   totalblocks = (memory_region_length(machine, "user3") / 0x10000) - 1;
1550   total_blocks = (memory_region_length(machine, "user3") / 0x10000);
1551   read_blocks = 0;
15521552
1553   /* FIXME: Insert crc check here */
1553   /* See above for details about the way we fill banks 0x00 to 0x7f */
15541554
1555   readblocks = 0;
1555   /* HiROM carts load data in banks 0xc0 to 0xff. Each bank is fully mirrored in banks 0x40 to 0x7f
1556    * (actually up to 0x7d, because 0x7e and 0x7f are overwritten by WRAM). The top half (address
1557    * range 0x8000 - 0xffff) of each bank is also mirrored in banks 0x00 to 0x3f and 0x80 to 0xbf.
1558    */
1559   while (read_blocks < 64 && read_blocks < total_blocks)
15561560   {
1557      i = 0;
1558      while( i < 64 && readblocks <= totalblocks )
1559      {
1560         memcpy( &snes_ram[0xc00000 + (i * 0x10000)],  &rom[i * 0x10000], 0x10000);
1561         i++;
1562         readblocks++;
1563      }
1561      /* Loading data */
1562      memcpy(&snes_ram[0xc00000 + read_blocks * 0x10000], &rom[read_blocks * 0x10000], 0x10000);
1563      /* Mirroring */
1564      memcpy(&snes_ram[0x008000 + read_blocks * 0x10000], &snes_ram[0xc08000 + read_blocks * 0x10000], 0x8000);
1565      memcpy(&snes_ram[0x400000 + read_blocks * 0x10000], &snes_ram[0xc00000 + read_blocks * 0x10000], 0x10000);
1566      memcpy(&snes_ram[0x808000 + read_blocks * 0x10000], &snes_ram[0xc08000 + read_blocks * 0x10000], 0x8000);
1567      read_blocks++;
15641568   }
1569   /* Filling banks up to 0x7f and their mirrors */
1570   while (read_blocks % 64)
1571   {
1572      int j = 0, repeat_blocks;
1573      while ((read_blocks % (64 >> j)) && j < 6)
1574         j++;
1575      repeat_blocks = read_blocks % (64 >> (j - 1));
15651576
1577      memcpy(&snes_ram[0xc00000 + read_blocks * 0x10000], &snes_ram[0xc00000 + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
1578      memcpy(&snes_ram[read_blocks * 0x10000], &snes_ram[(read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
1579      memcpy(&snes_ram[0x400000 + read_blocks * 0x10000], &snes_ram[0x400000 + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
1580      memcpy(&snes_ram[0x800000 + read_blocks * 0x10000], &snes_ram[0x800000 + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
1581      read_blocks += repeat_blocks;
1582   }
1583
15661584   /* Find the amount of sram */
1567   snes_cart.sram = snes_r_bank1(machine,0x00ffd8);
1568   if( snes_cart.sram > 0 )
1585   snes_cart.sram = snes_r_bank1(machine, 0x00ffd8);
1586   if (snes_cart.sram > 0)
15691587   {
15701588      snes_cart.sram = ((1 << (snes_cart.sram + 3)) / 8);
1571      if( snes_cart.sram > snes_cart.sram_max )
1589      if (snes_cart.sram > snes_cart.sram_max)
15721590         snes_cart.sram = snes_cart.sram_max;
15731591   }
15741592}
src/mess/machine/snescart.c
r3346r3347
353353{
354354   int i, supported_type = 0;
355355   running_machine *machine = image->machine;
356   UINT16 totalblocks, readblocks;
356   int total_blocks, read_blocks;
357357   UINT32 offset;
358358   UINT8 header[512];
359359   UINT8 *temp_buffer = auto_malloc(0x410000);
360360   UINT8 valid_mode20, valid_mode21, valid_mode25;
361361
362   memory_region_alloc(machine, "main", 0x1000000,0);
362   memory_region_alloc(machine, "main", 0x1000000, 0);
363363
364   snes_ram = memory_region( machine, "main" );
364   snes_ram = memory_region(machine, "main");
365365   memset( snes_ram, 0, 0x1000000 );
366366
367367   /* Check for a header (512 bytes) */
368368   offset = 512;
369   image_fread( image, header, 512 );
370   if( (header[8] == 0xaa) && (header[9] == 0xbb) && (header[10] == 0x04) )
369   image_fread(image, header, 512);
370   if ((header[8] == 0xaa) && (header[9] == 0xbb) && (header[10] == 0x04))
371371   {
372372      /* Found an SWC identifier */
373      logerror( "Found header(SWC) - Skipped\n" );
373      logerror("Found header(SWC) - Skipped\n");
374374   }
375   else if( (header[0] | (header[1] << 8)) == (((image_length(image) - 512) / 1024) / 8) )
375   else if ((header[0] | (header[1] << 8)) == (((image_length(image) - 512) / 1024) / 8))
376376   {
377377      /* Some headers have the rom size at the start, if this matches with the
378378         * actual rom size, we probably have a header */
379      logerror( "Found header(size) - Skipped\n" );
379      logerror("Found header(size) - Skipped\n");
380380   }
381   else if( (image_length(image) % 0x8000) == 512 )
381   else if ((image_length(image) % 0x8000) == 512)
382382   {
383383      /* As a last check we'll see if there's exactly 512 bytes extra to this
384384         * image. */
385      logerror( "Found header(extra) - Skipped\n" );
385      logerror("Found header(extra) - Skipped\n");
386386   }
387387   else
388388   {
389389      /* No header found so go back to the start of the file */
390      logerror( "No header found.\n" );
390      logerror("No header found.\n");
391391      offset = 0;
392392      image_fseek( image, offset, SEEK_SET );
393393   }
394394
395395   /* We need to take a sample to test what mode we need to be in (the
396396   sample has to be quite large to cope with large carts in ExHiRom) */
397   image_fread( image, temp_buffer, 0x40ffff );
398   image_fseek( image, offset, SEEK_SET );   /* Rewind */
397   image_fread(image, temp_buffer, 0x40ffff);
398   image_fseek(image, offset, SEEK_SET);   /* Rewind */
399399
400400   /* Now to determine if this is a lo-ROM, a hi-ROM or an extended lo/hi-ROM */
401   valid_mode20 = snes_validate_infoblock( temp_buffer, 0x007fc0 );
402   valid_mode21 = snes_validate_infoblock( temp_buffer, 0x00ffc0 );
403   valid_mode25 = snes_validate_infoblock( temp_buffer, 0x40ffc0 );
401   valid_mode20 = snes_validate_infoblock(temp_buffer, 0x007fc0);
402   valid_mode21 = snes_validate_infoblock(temp_buffer, 0x00ffc0);
403   valid_mode25 = snes_validate_infoblock(temp_buffer, 0x40ffc0);
404404
405405   /* Images larger than 32mbits are likely ExHiRom */
406406   if (valid_mode25)
r3346r3347
428428
429429   /* FIXME: Insert crc check here */
430430
431   readblocks = 1;
431   /* How many blocks of data are available to be loaded? */
432   total_blocks = ((image_length(image) - offset) / (snes_cart.mode & 0x05 ? 0x8000 : 0x10000));
433   read_blocks = 0;
434
435   /* Loading all the data blocks from cart, we only partially cover banks 0x00 to 0x7f. Therefore, we
436    * have to mirror the blocks until we reach the end. E.g. for a 11Mbits image (44 blocks), we proceed
437    * as follows:
438    * 11 Mbits = 8 Mbits (blocks 1->32) + 2 Mbits (blocks 33->40) + 1 Mbit (blocks 41->44).
439    * Hence, we fill memory up to 16 Mbits (banks 0x00 to 0x3f) mirroring as follows
440    * 8 Mbits (blocks 1->32) + 2 Mbits (blocks 33->40) + 1 Mbit (blocks 41->44) + 1 Mbit (blocks 41->44)
441    *   + 2 Mbits (blocks 33->40) + 1 Mbit (blocks 41->44) + 1 Mbit (blocks 41->44)
442    * and we repeat the same blocks in the second half of the banks (banks 0x40 to 0x7f).
443    * This is likely what happens in the real SNES as well, because the unit cannot be aware of the exact
444    * size of data in the cart (procedure confirmed by byuu)
445    */
432446   switch (snes_cart.mode)
433447   {
434448      case SNES_MODE_21:
449      /* HiROM carts load data in banks 0xc0 to 0xff. Each bank is fully mirrored in banks 0x40 to 0x7f
450       * (actually up to 0x7d, because 0x7e and 0x7f are overwritten by WRAM). The top half (address
451       * range 0x8000 - 0xffff) of each bank is also mirrored in banks 0x00 to 0x3f and 0x80 to 0xbf.
452       */
453         while (read_blocks < 64 && read_blocks < total_blocks)
454         {
455            /* Loading data */
456            image_fread(image, &snes_ram[0xc00000 + read_blocks * 0x10000], 0x10000);
457            /* Mirroring */
458            memcpy(&snes_ram[0x008000 + read_blocks * 0x10000], &snes_ram[0xc08000 + read_blocks * 0x10000], 0x8000);
459            memcpy(&snes_ram[0x400000 + read_blocks * 0x10000], &snes_ram[0xc00000 + read_blocks * 0x10000], 0x10000);
460            memcpy(&snes_ram[0x808000 + read_blocks * 0x10000], &snes_ram[0xc08000 + read_blocks * 0x10000], 0x8000);
461            read_blocks++;
462         }
463         /* Filling banks up to 0xff and their mirrors */
464         while (read_blocks % 64)
465         {
466            int j = 0, repeat_blocks;
467            while ((read_blocks % (64 >> j)) && j < 6)
468               j++;
469            repeat_blocks = read_blocks % (64 >> (j - 1));
470
471            memcpy(&snes_ram[0xc00000 + read_blocks * 0x10000], &snes_ram[0xc00000 + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
472            memcpy(&snes_ram[read_blocks * 0x10000], &snes_ram[(read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
473            memcpy(&snes_ram[0x400000 + read_blocks * 0x10000], &snes_ram[0x400000 + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
474            memcpy(&snes_ram[0x800000 + read_blocks * 0x10000], &snes_ram[0x800000 + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
475            read_blocks += repeat_blocks;
476         }
477         break;
478
435479      case SNES_MODE_25:
436         /* In mode 21, all blocks are 64kb. There are upto 96 blocks, giving a
437         * total of 48mbit(6mb) of ROM.
438         * The first 64 blocks are located in banks 0xc0 to 0xff. The top 32k of
439         * each bank is mirrored in banks 0x00 to 0x3f.
440         * The final 32 blocks are located in banks 0x40 to 0x5f.
441         * Extended HiROM has a different mirroring, with the first 64 blocks
442         * having top half mirrored in banks 0x08 to 0xbf and the final 32 blocks
443         * having top half mirrored in banks 0x00 to 0x1f
444         */
445         /* read first 64 blocks */
446         totalblocks = ((image_length(image) - offset) / 0x10000);
447         i = 0;
448         while( i < 64 && readblocks <= totalblocks )
480      /* Extendend HiROM carts start to load data in banks 0xc0 to 0xff. However, they exceed the
481       * available space in these banks, and continue loading at banks 0x40 to 0x7f. The top half
482       * (address range 0x8000 - 0xffff) of each bank is also mirrored either to banks 0x00 to 0x3f
483       * (for data in banks 0x40 to 0x7f) or to banks 0x80 to 0xbf (for data in banks 0xc0 to 0xff)
484       */
485         /* Reading the first 64 blocks */
486         while (read_blocks < 64 && read_blocks < total_blocks)
449487         {
450            image_fread( image, &snes_ram[0xc00000 + (i++ * 0x10000)], 0x10000);
451            readblocks++;
488            /* Loading data */
489            image_fread(image, &snes_ram[0xc00000 + read_blocks * 0x10000], 0x10000);
490            /* Mirroring */
491            memcpy( &snes_ram[0x808000 + read_blocks * 0x10000], &snes_ram[0xc08000 + read_blocks * 0x10000], 0x8000);
492            read_blocks++;
452493         }
453         /* read the next 32 blocks */
454         i = 0;
455         while( i < 32 && readblocks <= totalblocks )
494         /* ExHiROMs are supposed to be larger than 32Mbits! */
495         if (read_blocks < 64)
456496         {
457            image_fread( image, &snes_ram[0x400000 + (i++ * 0x10000)], 0x10000);
458            readblocks++;
497            logerror("This image has been identified as ExHiROM, but it's too small!\n");
498            logerror("Please verify if it's corrupted. If it's not please report this as a bug.\n");
499            return INIT_FAIL;
459500         }
501         /* Scaling down the counter */
502         read_blocks -= 64;
503         /* Reading the next blocks */
504         while (read_blocks < 64  && read_blocks < (total_blocks - 64))
505         {
506            /* Loading data */
507            image_fread(image, &snes_ram[0x400000 + read_blocks * 0x10000], 0x10000);
508            /* Mirroring */
509            memcpy(&snes_ram[0x8000 + read_blocks * 0x10000], &snes_ram[0x408000 + read_blocks * 0x10000], 0x8000);
510            read_blocks++;
511         }
512         /* Filling banks up to 0x7f and their mirrors */
513         while (read_blocks % 64)
514         {
515            int j = 0, repeat_blocks;
516            while ((read_blocks % (64 >> j)) && j < 6)
517               j++;
518            repeat_blocks = read_blocks % (64 >> (j - 1));
519
520            memcpy(&snes_ram[0x400000 + read_blocks * 0x10000], &snes_ram[0x400000 + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
521            memcpy(&snes_ram[read_blocks * 0x10000], &snes_ram[(read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
522            read_blocks += repeat_blocks;
523         }
460524         break;
461525
462526      case SNES_MODE_22:
463         /* This is used by SDD-1 games (and others?). It requires to switch the
464         * content of banks at 0xc0-0xff according to MMC registers $4804-$4807 */
465         logerror( "This type of carts (ExLoROM) is still unsupported in M.E.S.S.\n" );
466         return INIT_FAIL;
527      /* "Extendend LoROM" carts have their data loaded in banks 0x00 to 0x3f at address 0x8000.
528       * These are then mirrored in banks 0x40 to 0x7f, both at address 0x0000 and at address
529       * 0x8000, in banks 0x80 to 0xbf at address 0x8000 and in banks 0xc0 to 0xff, both at address
530       * 0x0000 and at address 0x8000. Notice that SDD-1 games (Star Ocean and Street Fighter Zero 2)
531       * also use SNES_MODE_22, but we still don't support their bankswitch mechanism: the content
532       * of banks at 0xc0 to 0xff changes according to MMC registers $4804-$4807
533       */
534         while (read_blocks < 64 && read_blocks < total_blocks)
535         {
536            /* Loading data */
537            image_fread( image, &snes_ram[0x8000 + read_blocks * 0x10000], 0x8000);
538            /* Mirroring */
539            memcpy(&snes_ram[0x400000 + read_blocks * 0x10000], &snes_ram[0x8000 + read_blocks * 0x10000], 0x8000);
540            memcpy(&snes_ram[0x408000 + read_blocks * 0x10000], &snes_ram[0x8000 + read_blocks * 0x10000], 0x8000);
541            memcpy(&snes_ram[0x808000 + read_blocks * 0x10000], &snes_ram[0x8000 + read_blocks * 0x10000], 0x8000);
542            memcpy(&snes_ram[0xc00000 + read_blocks * 0x10000], &snes_ram[0x8000 + read_blocks * 0x10000], 0x8000);
543            memcpy(&snes_ram[0xc08000 + read_blocks * 0x10000], &snes_ram[0x8000 + read_blocks * 0x10000], 0x8000);
544            read_blocks++;
545         }
546         /* Filling banks up to 0x3f and their mirrors */
547         while (read_blocks % 64)
548         {
549            int j = 0, repeat_blocks;
550            while ((read_blocks % (64 >> j)) && j < 6)
551               j++;
552            repeat_blocks = read_blocks % (64 >> (j - 1));
553
554            memcpy(&snes_ram[read_blocks * 0x10000], &snes_ram[(read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
555            memcpy(&snes_ram[0x800000 + read_blocks * 0x10000], &snes_ram[0x800000 + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
556            memcpy(&snes_ram[0x400000 + read_blocks * 0x10000], &snes_ram[0x400000 + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
557            memcpy(&snes_ram[0xc00000 + read_blocks * 0x10000], &snes_ram[0xc00000 + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
558            read_blocks += repeat_blocks;
559         }
467560         break;
468561
469562      default:
470563      case SNES_MODE_20:
471         /* In mode 20, all blocks are 32kb. There are upto 96 blocks, giving a
472         * total of 24mbit(3mb) of ROM.
473         * The first 48 blocks are located in banks 0x00 to 0x2f at address
474         * 0x8000.  They are mirrored in banks 0x80 to 0xaf.
475         * The next 16 blocks are located in banks 0x30 to 0x3f at address
476         * 0x8000.  They are mirrored in banks 0xb0 to 0xbf.
477         * The final 32 blocks are located in banks 0x40 to 0x5f at address
478         * 0x8000.  They are mirrored in banks 0xc0 to 0xdf.
479         */
480         totalblocks = ((image_length(image) - offset) / 0x8000);
481         i = 0;
482         while( i < 96 && readblocks <= totalblocks )
564      /* LoROM carts load data in banks 0x00 to 0x7f at address 0x8000 (actually up to 0x7d, because 0x7e and
565       * 0x7f are overwritten by WRAM). Each block is also mirrored in banks 0x80 to 0xff (up to 0xff for real)
566       */
567         while (read_blocks < 128 && read_blocks < total_blocks)
483568         {
484            image_fread( image, &snes_ram[(i++ * 0x10000) + 0x8000], 0x8000);
485            readblocks++;
569            /* Loading data */
570            image_fread(image, &snes_ram[0x8000 + read_blocks * 0x10000], 0x8000);
571            /* Mirroring */
572            memcpy(&snes_ram[0x808000 + (read_blocks * 0x10000)], &snes_ram[0x8000 + (read_blocks * 0x10000)], 0x8000);
573            read_blocks++;
486574         }
575         /* Filling banks up to 0x7f and their mirrors */
576         while (read_blocks % 128)
577         {
578            int j = 0, repeat_blocks;
579            while ((read_blocks % (128 >> j)) && j < 7)
580               j++;
581            repeat_blocks = read_blocks % (128 >> (j - 1));
582
583            memcpy( &snes_ram[read_blocks * 0x10000], &snes_ram[(read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
584            memcpy( &snes_ram[0x800000 + read_blocks * 0x10000], &snes_ram[(read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000);
585            read_blocks += repeat_blocks;
586         }
487587         break;
488588   }
489589
490
491590   /* Find the amount of sram */
492591   snes_cart.sram = snes_r_bank1(machine, 0x00ffd8);
493592   if( snes_cart.sram > 0 )
r3346r3347
642741
643742      logerror( "ROM DETAILS\n" );
644743      logerror( "===========\n\n" );
645      logerror( "\tTotal blocks:  %d (%dmb)\n", totalblocks, totalblocks / (snes_cart.mode == SNES_MODE_20 ? 32 : 16) );
744      logerror( "\tTotal blocks:  %d (%dmb)\n", total_blocks, total_blocks / (snes_cart.mode & 5 ? 32 : 16) );
646745      logerror( "\tROM bank size: %s (LoROM: %d , HiROM: %d, ExHiROM: %d)\n",
647746                        (snes_cart.mode == SNES_MODE_20) ? "LoROM" : ((snes_cart.mode == SNES_MODE_21) ? "HiROM" : "ExHiROM"),
648747                              valid_mode20, valid_mode21, valid_mode25);

Previous 15994 Revisions Next


© 1998-2018 The MESS Team