src/mame/machine/snes.c
| r3346 | r3347 | |
| 460 | 460 | } |
| 461 | 461 | } |
| 462 | 462 | 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]; |
| 473 | 464 | |
| 474 | 465 | return 0xff; |
| 475 | 466 | } |
| r3346 | r3347 | |
| 513 | 504 | } |
| 514 | 505 | } |
| 515 | 506 | 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]; |
| 522 | 508 | |
| 523 | 509 | return 0xff; |
| 524 | 510 | } |
| r3346 | r3347 | |
| 528 | 514 | { |
| 529 | 515 | UINT16 address = offset & 0xffff; |
| 530 | 516 | |
| 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 |
| 540 | 520 | return snes_ram[0x400000 + offset]; |
| 541 | | } |
| 542 | 521 | |
| 543 | 522 | return 0xff; |
| 544 | 523 | } |
| r3346 | r3347 | |
| 555 | 534 | else |
| 556 | 535 | return DSP1_getDr(); |
| 557 | 536 | } |
| 537 | else |
| 538 | return snes_ram[0x600000 + offset]; |
| 558 | 539 | |
| 559 | 540 | return 0xff; |
| 560 | 541 | } |
| r3346 | r3347 | |
| 562 | 543 | /* 0x800000 - 0xffffff */ |
| 563 | 544 | READ8_HANDLER( snes_r_bank4 ) |
| 564 | 545 | { |
| 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 ) |
| 566 | 554 | { |
| 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 ); |
| 569 | 557 | else |
| 570 | | return 0xff; |
| 558 | return snes_ram[0x800000 + offset]; |
| 571 | 559 | } |
| 572 | | else /* MODE_21 */ |
| 560 | else |
| 573 | 561 | { |
| 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 |
| 577 | 565 | return snes_ram[offset + 0x800000]; |
| 578 | | } |
| 566 | } |
| 579 | 567 | |
| 580 | 568 | return 0xff; |
| 581 | 569 | } |
| r3346 | r3347 | |
| 1484 | 1472 | /* for mame we use an init, maybe we will need more for the different games */ |
| 1485 | 1473 | DRIVER_INIT( snes ) |
| 1486 | 1474 | { |
| 1487 | | int i; |
| 1488 | | UINT16 totalblocks, readblocks; |
| 1475 | UINT16 total_blocks, read_blocks; |
| 1489 | 1476 | UINT8 *rom; |
| 1490 | 1477 | |
| 1491 | | rom = memory_region( machine, "user3" ); |
| 1478 | rom = memory_region(machine, "user3"); |
| 1492 | 1479 | snes_ram = auto_malloc(0x1000000); |
| 1493 | | memset( snes_ram, 0, 0x1000000 ); |
| 1480 | memset(snes_ram, 0, 0x1000000); |
| 1494 | 1481 | |
| 1495 | 1482 | /* all NSS games seem to use MODE 20 */ |
| 1496 | 1483 | snes_cart.mode = SNES_MODE_20; |
| 1497 | 1484 | snes_cart.sram_max = 0x40000; |
| 1498 | 1485 | |
| 1499 | 1486 | /* 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; |
| 1502 | 1489 | |
| 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 | */ |
| 1504 | 1501 | |
| 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) |
| 1506 | 1506 | { |
| 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++; |
| 1524 | 1512 | } |
| 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)); |
| 1525 | 1520 | |
| 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 | |
| 1526 | 1527 | /* 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) |
| 1529 | 1530 | { |
| 1530 | 1531 | 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) |
| 1532 | 1533 | snes_cart.sram = snes_cart.sram_max; |
| 1533 | 1534 | } |
| 1534 | 1535 | } |
| 1535 | 1536 | |
| 1536 | 1537 | DRIVER_INIT( snes_hirom ) |
| 1537 | 1538 | { |
| 1538 | | int i; |
| 1539 | | UINT16 totalblocks, readblocks; |
| 1539 | UINT16 total_blocks, read_blocks; |
| 1540 | 1540 | UINT8 *rom; |
| 1541 | 1541 | |
| 1542 | | rom = memory_region( machine, "user3" ); |
| 1542 | rom = memory_region(machine, "user3"); |
| 1543 | 1543 | snes_ram = auto_malloc(0x1000000); |
| 1544 | | memset( snes_ram, 0, 0x1000000 ); |
| 1544 | memset(snes_ram, 0, 0x1000000); |
| 1545 | 1545 | |
| 1546 | 1546 | snes_cart.mode = SNES_MODE_21; |
| 1547 | 1547 | snes_cart.sram_max = 0x40000; |
| 1548 | 1548 | |
| 1549 | 1549 | /* 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; |
| 1552 | 1552 | |
| 1553 | | /* FIXME: Insert crc check here */ |
| 1553 | /* See above for details about the way we fill banks 0x00 to 0x7f */ |
| 1554 | 1554 | |
| 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) |
| 1556 | 1560 | { |
| 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++; |
| 1564 | 1568 | } |
| 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)); |
| 1565 | 1576 | |
| 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 | |
| 1566 | 1584 | /* 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) |
| 1569 | 1587 | { |
| 1570 | 1588 | 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) |
| 1572 | 1590 | snes_cart.sram = snes_cart.sram_max; |
| 1573 | 1591 | } |
| 1574 | 1592 | } |
src/mess/machine/snescart.c
| r3346 | r3347 | |
| 353 | 353 | { |
| 354 | 354 | int i, supported_type = 0; |
| 355 | 355 | running_machine *machine = image->machine; |
| 356 | | UINT16 totalblocks, readblocks; |
| 356 | int total_blocks, read_blocks; |
| 357 | 357 | UINT32 offset; |
| 358 | 358 | UINT8 header[512]; |
| 359 | 359 | UINT8 *temp_buffer = auto_malloc(0x410000); |
| 360 | 360 | UINT8 valid_mode20, valid_mode21, valid_mode25; |
| 361 | 361 | |
| 362 | | memory_region_alloc(machine, "main", 0x1000000,0); |
| 362 | memory_region_alloc(machine, "main", 0x1000000, 0); |
| 363 | 363 | |
| 364 | | snes_ram = memory_region( machine, "main" ); |
| 364 | snes_ram = memory_region(machine, "main"); |
| 365 | 365 | memset( snes_ram, 0, 0x1000000 ); |
| 366 | 366 | |
| 367 | 367 | /* Check for a header (512 bytes) */ |
| 368 | 368 | 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)) |
| 371 | 371 | { |
| 372 | 372 | /* Found an SWC identifier */ |
| 373 | | logerror( "Found header(SWC) - Skipped\n" ); |
| 373 | logerror("Found header(SWC) - Skipped\n"); |
| 374 | 374 | } |
| 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)) |
| 376 | 376 | { |
| 377 | 377 | /* Some headers have the rom size at the start, if this matches with the |
| 378 | 378 | * actual rom size, we probably have a header */ |
| 379 | | logerror( "Found header(size) - Skipped\n" ); |
| 379 | logerror("Found header(size) - Skipped\n"); |
| 380 | 380 | } |
| 381 | | else if( (image_length(image) % 0x8000) == 512 ) |
| 381 | else if ((image_length(image) % 0x8000) == 512) |
| 382 | 382 | { |
| 383 | 383 | /* As a last check we'll see if there's exactly 512 bytes extra to this |
| 384 | 384 | * image. */ |
| 385 | | logerror( "Found header(extra) - Skipped\n" ); |
| 385 | logerror("Found header(extra) - Skipped\n"); |
| 386 | 386 | } |
| 387 | 387 | else |
| 388 | 388 | { |
| 389 | 389 | /* No header found so go back to the start of the file */ |
| 390 | | logerror( "No header found.\n" ); |
| 390 | logerror("No header found.\n"); |
| 391 | 391 | offset = 0; |
| 392 | 392 | image_fseek( image, offset, SEEK_SET ); |
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | /* We need to take a sample to test what mode we need to be in (the |
| 396 | 396 | 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 */ |
| 399 | 399 | |
| 400 | 400 | /* 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); |
| 404 | 404 | |
| 405 | 405 | /* Images larger than 32mbits are likely ExHiRom */ |
| 406 | 406 | if (valid_mode25) |
| r3346 | r3347 | |
| 428 | 428 | |
| 429 | 429 | /* FIXME: Insert crc check here */ |
| 430 | 430 | |
| 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 | */ |
| 432 | 446 | switch (snes_cart.mode) |
| 433 | 447 | { |
| 434 | 448 | 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 | |
| 435 | 479 | 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) |
| 449 | 487 | { |
| 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++; |
| 452 | 493 | } |
| 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) |
| 456 | 496 | { |
| 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; |
| 459 | 500 | } |
| 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 | } |
| 460 | 524 | break; |
| 461 | 525 | |
| 462 | 526 | 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 | } |
| 467 | 560 | break; |
| 468 | 561 | |
| 469 | 562 | default: |
| 470 | 563 | 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) |
| 483 | 568 | { |
| 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++; |
| 486 | 574 | } |
| 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 | } |
| 487 | 587 | break; |
| 488 | 588 | } |
| 489 | 589 | |
| 490 | | |
| 491 | 590 | /* Find the amount of sram */ |
| 492 | 591 | snes_cart.sram = snes_r_bank1(machine, 0x00ffd8); |
| 493 | 592 | if( snes_cart.sram > 0 ) |
| r3346 | r3347 | |
| 642 | 741 | |
| 643 | 742 | logerror( "ROM DETAILS\n" ); |
| 644 | 743 | 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) ); |
| 646 | 745 | logerror( "\tROM bank size: %s (LoROM: %d , HiROM: %d, ExHiROM: %d)\n", |
| 647 | 746 | (snes_cart.mode == SNES_MODE_20) ? "LoROM" : ((snes_cart.mode == SNES_MODE_21) ? "HiROM" : "ExHiROM"), |
| 648 | 747 | valid_mode20, valid_mode21, valid_mode25); |