src/mess/machine/nes.c
| r6027 | r6028 | |
| 87 | 87 | nes_battery_ram = nes.wram; |
| 88 | 88 | |
| 89 | 89 | /* Set up the memory handlers for the mapper */ |
| 90 | | //if (nes.format == 1) |
| 91 | 90 | switch (nes.mapper) |
| 92 | 91 | { |
| 93 | 92 | case 20: |
| r6027 | r6028 | |
| 129 | 128 | } |
| 130 | 129 | |
| 131 | 130 | /* Set up the mapper callbacks */ |
| 131 | if (nes.format == 1) |
| 132 | 132 | { |
| 133 | 133 | const mmc *mapper; |
| 134 | 134 | |
| r6027 | r6028 | |
| 149 | 149 | ppu_latch = NULL; |
| 150 | 150 | } |
| 151 | 151 | } |
| 152 | else if (nes.format == 2) |
| 153 | { |
| 154 | const unif *board; |
| 152 | 155 | |
| 153 | | //else if (nes.format == 2) |
| 154 | | //TODO: we have to set up memory banking for unif board as in the mapper case |
| 156 | board = nes_unif_lookup(nes.board); |
| 157 | if (board) |
| 158 | { |
| 159 | mmc_write_low = board->mmc_write_low; |
| 160 | mmc_read_low = board->mmc_read_low; |
| 161 | mmc_write_mid = board->mmc_write_mid; |
| 162 | mmc_write = board->mmc_write; |
| 163 | ppu_latch = board->ppu_latch; |
| 164 | } |
| 165 | else |
| 166 | { |
| 167 | logerror("Board %s is not yet supported, defaulting to no mapper.\n", nes.board); |
| 168 | mmc_write_low = mmc_write_mid = mmc_write = NULL; |
| 169 | mmc_read_low = NULL; |
| 170 | ppu_latch = NULL; |
| 171 | } |
| 172 | } |
| 155 | 173 | |
| 156 | 174 | /* Load a battery file, but only if there's no trainer since they share */ |
| 157 | 175 | /* overlapping memory. */ |
| r6027 | r6028 | |
| 190 | 208 | nes.mid_ram_enable = 1; |
| 191 | 209 | |
| 192 | 210 | /* Reset the mapper variables. Will also mark the char-gen ram as dirty */ |
| 193 | | //if (nes.format == 1) |
| 194 | | mapper_reset(machine, nes.mapper); |
| 211 | if (nes.format == 1) |
| 212 | mapper_reset(machine, nes.mapper); |
| 195 | 213 | |
| 196 | | //if (nes.format == 2) |
| 197 | | //unif_reset(machine, nes.board); |
| 214 | if (nes.format == 2) |
| 215 | unif_reset(machine, nes.board); |
| 198 | 216 | |
| 199 | 217 | /* Reset the serial input ports */ |
| 200 | 218 | in_0.shift = 0; |
| r6027 | r6028 | |
| 580 | 598 | logerror("**\n"); |
| 581 | 599 | logerror("Mapper: %d\n", nes.mapper); |
| 582 | 600 | logerror("PRG chunks: %02x, size: %06x\n", nes.prg_chunks, 0x4000 * nes.prg_chunks); |
| 583 | | // printf("Mapper: %d\n", nes.mapper); |
| 584 | | // printf("PRG chunks: %02x, size: %06x\n", nes.prg_chunks, 0x4000 * nes.prg_chunks); |
| 601 | printf("Mapper: %d\n", nes.mapper); |
| 602 | printf("PRG chunks: %02x, size: %06x\n", nes.prg_chunks, 0x4000 * nes.prg_chunks); |
| 585 | 603 | |
| 586 | 604 | /* Read in any chr chunks */ |
| 587 | 605 | if (nes.chr_chunks > 0) |
| r6027 | r6028 | |
| 611 | 629 | |
| 612 | 630 | logerror("CHR chunks: %02x, size: %06x\n", nes.chr_chunks, 0x4000 * nes.chr_chunks); |
| 613 | 631 | logerror("**\n"); |
| 614 | | // printf("CHR chunks: %02x, size: %06x\n", nes.chr_chunks, 0x4000 * nes.chr_chunks); |
| 615 | | // printf("**\n"); |
| 632 | printf("CHR chunks: %02x, size: %06x\n", nes.chr_chunks, 0x4000 * nes.chr_chunks); |
| 633 | printf("**\n"); |
| 616 | 634 | |
| 617 | 635 | /* Attempt to load a battery file for this ROM. If successful, we */ |
| 618 | 636 | /* must wait until later to move it to the system memory. */ |
| r6027 | r6028 | |
| 626 | 644 | char magic2[4]; |
| 627 | 645 | UINT8 buffer[4]; |
| 628 | 646 | UINT32 chunk_length = 0, read_length = 0x20; |
| 647 | UINT32 prg_start = 0, chr_start = 0; |
| 648 | UINT32 prg_left = 0, chr_left = 0; // used to verify integrity of our unif image |
| 629 | 649 | char unif_mapr[32]; // here we should store MAPR chunks |
| 630 | 650 | UINT32 size = image_length(image); |
| 631 | 651 | const unif *unif_board; |
| r6027 | r6028 | |
| 658 | 678 | memset(magic2, '\0', sizeof(magic2)); |
| 659 | 679 | image_fread(image, &magic2, 4); |
| 660 | 680 | |
| 681 | /* Preliminary checks: the first chunk MUST be MAPR! */ |
| 682 | if (read_length == 0x20 && ((magic2[0] != 'M') || (magic2[1] != 'A') || (magic2[2] != 'P') || (magic2[3] != 'R'))) |
| 683 | fatalerror("First chunk of data in UNIF should be [MAPR]. Check if your image has been corrupted\n"); |
| 684 | |
| 685 | /* Preliminary checks: multiple MAPR chunks are FORBIDDEN! */ |
| 686 | if (read_length > 0x20 && ((magic2[0] == 'M') && (magic2[1] == 'A') && (magic2[2] == 'P') && (magic2[3] == 'R'))) |
| 687 | fatalerror("UNIF should not have multiple [MAPR] chunks. Check if your image has been corrupted\n"); |
| 688 | |
| 661 | 689 | /* What kind of chunk do we have here? */ |
| 662 | 690 | if ((magic2[0] == 'M') && (magic2[1] == 'A') && (magic2[2] == 'P') && (magic2[3] == 'R')) |
| 663 | 691 | { |
| 664 | | int i; |
| 692 | // int i; |
| 665 | 693 | logerror("[MAPR] chunk found: "); |
| 666 | 694 | image_fread(image, &buffer, 4); |
| 667 | 695 | chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24); |
| r6027 | r6028 | |
| 671 | 699 | |
| 672 | 700 | read_length += (chunk_length + 8); |
| 673 | 701 | |
| 674 | | unif_board = nes_unif_lookup(unif_mapr); // this does not work atm, it's mainly a proof of concept |
| 702 | unif_board = nes_unif_lookup(unif_mapr); |
| 675 | 703 | |
| 676 | | for(i = 0; i < chunk_length; i++) |
| 677 | | logerror("%c", unif_mapr[i]); |
| 678 | | logerror("\n"); |
| 704 | // for(i = 0; i < chunk_length; i++) |
| 705 | // logerror("%c", unif_mapr[i]); |
| 706 | // logerror("\n"); |
| 707 | logerror("%s\n", unif_mapr); |
| 679 | 708 | |
| 680 | 709 | if (unif_board == NULL) |
| 681 | 710 | { |
| 682 | 711 | fatalerror("Unsupported UNIF board.\n"); |
| 683 | 712 | // logerror("Unsupported UNIF board.\n"); |
| 684 | 713 | } |
| 714 | |
| 715 | nes.mapper = 0; // this allows us to set up memory handlers without duplicating code (for the moment) |
| 716 | nes.board = unif_board->board; |
| 717 | nes.prg_chunks = unif_board->prgrom; |
| 718 | nes.chr_chunks = unif_board->chrrom; |
| 719 | nes.battery = unif_board->wram; // we should implement WRAM banks... |
| 720 | nes.hard_mirroring = unif_board->nt; |
| 721 | // nes.four_screen_vram = ; |
| 722 | |
| 723 | /* Free the regions that were allocated by the ROM loader */ |
| 724 | memory_region_free(image->machine, "maincpu"); |
| 725 | memory_region_free(image->machine, "gfx1"); |
| 726 | |
| 727 | /* Allocate them again with the proper size */ |
| 728 | memory_region_alloc(image->machine, "maincpu", 0x10000 + (nes.prg_chunks + 1) * 0x4000, 0); |
| 729 | if (nes.chr_chunks) |
| 730 | memory_region_alloc(image->machine, "gfx1", nes.chr_chunks * 0x2000, 0); |
| 731 | |
| 732 | nes.rom = memory_region(image->machine, "maincpu"); |
| 733 | nes.vrom = memory_region(image->machine, "gfx1"); |
| 734 | nes.vram = memory_region(image->machine, "gfx2"); |
| 735 | nes.wram = memory_region(image->machine, "user1"); |
| 736 | |
| 737 | /* for validation purposes */ |
| 738 | prg_left = unif_board->prgrom * 0x4000; |
| 739 | chr_left = unif_board->chrrom * 0x2000; |
| 685 | 740 | } |
| 686 | 741 | else if ((magic2[0] == 'R') && (magic2[1] == 'E') && (magic2[2] == 'A') && (magic2[3] == 'D')) |
| 687 | 742 | { |
| r6027 | r6028 | |
| 749 | 804 | } |
| 750 | 805 | else if ((magic2[0] == 'P') && (magic2[1] == 'C') && (magic2[2] == 'K')) |
| 751 | 806 | { |
| 752 | | logerror("[PCKx] chunk found. No support yet.\n"); |
| 807 | logerror("[PCK%c] chunk found. No support yet.\n", magic2[3]); |
| 753 | 808 | image_fread(image, &buffer, 4); |
| 754 | 809 | chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24); |
| 755 | 810 | |
| r6027 | r6028 | |
| 757 | 812 | } |
| 758 | 813 | else if ((magic2[0] == 'C') && (magic2[1] == 'C') && (magic2[2] == 'K')) |
| 759 | 814 | { |
| 760 | | logerror("[CCKx] chunk found. No support yet.\n"); |
| 815 | logerror("[CCK%c] chunk found. No support yet.\n", magic2[3]); |
| 761 | 816 | image_fread(image, &buffer, 4); |
| 762 | 817 | chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24); |
| 763 | 818 | |
| r6027 | r6028 | |
| 765 | 820 | } |
| 766 | 821 | else if ((magic2[0] == 'P') && (magic2[1] == 'R') && (magic2[2] == 'G')) |
| 767 | 822 | { |
| 768 | | logerror("[PRGx] chunk found. No support yet.\n"); |
| 823 | logerror("[PRG%c] chunk found. ", magic2[3]); |
| 769 | 824 | image_fread(image, &buffer, 4); |
| 770 | 825 | chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24); |
| 771 | 826 | |
| 827 | logerror("It consists of %d 16K-blocks.\n", chunk_length / 0x4000); |
| 828 | /* Validation */ |
| 829 | prg_left -= chunk_length; |
| 830 | if (prg_left < 0) |
| 831 | fatalerror("PRG chunks larger than expected by board %s!\n", unif_mapr); |
| 832 | |
| 833 | /* Read in the program chunks */ |
| 834 | if (nes.prg_chunks == 1) |
| 835 | { |
| 836 | image_fread(image, &nes.rom[0x14000], chunk_length); |
| 837 | /* Mirror the only bank into $8000 */ |
| 838 | memcpy(&nes.rom[0x10000], &nes.rom[0x14000], chunk_length); |
| 839 | } |
| 840 | else |
| 841 | image_fread(image, &nes.rom[0x10000 + prg_start], chunk_length); |
| 842 | |
| 843 | prg_start += chunk_length; |
| 772 | 844 | read_length += (chunk_length + 8); |
| 773 | 845 | } |
| 774 | 846 | else if ((magic2[0] == 'C') && (magic2[1] == 'H') && (magic2[2] == 'R')) |
| 775 | 847 | { |
| 776 | | logerror("[CHRx] chunk found. No support yet.\n"); |
| 848 | logerror("[CHR%c] chunk found. ", magic2[3]); |
| 777 | 849 | image_fread(image, &buffer, 4); |
| 778 | 850 | chunk_length = buffer[0] | (buffer[1] << 8) | (buffer[2] << 16) | (buffer[3] << 24); |
| 779 | 851 | |
| 852 | logerror("It consists of %d 8K-blocks.\n", chunk_length / 0x2000); |
| 853 | /* validation */ |
| 854 | chr_left -= chunk_length; |
| 855 | if (chr_left < 0) |
| 856 | fatalerror("CHR chunks larger than expected by board %s!\n", unif_mapr); |
| 857 | |
| 858 | image_fread(image, nes.vrom + chr_start, chunk_length); |
| 859 | |
| 860 | chr_start += chunk_length; |
| 780 | 861 | read_length += (chunk_length + 8); |
| 781 | 862 | } |
| 782 | 863 | else |
| r6027 | r6028 | |
| 787 | 868 | } while (size > read_length); |
| 788 | 869 | |
| 789 | 870 | logerror("UNIF support is only very preliminary.\n"); |
| 790 | | return INIT_FAIL; // if we let Unif init to pass, emulation would crash due to no PRG/CHR settings ;-) |
| 791 | 871 | } |
| 792 | 872 | |
| 793 | 873 | return INIT_PASS; |
src/mess/machine/nes_mmc.c
| r6027 | r6028 | |
| 39 | 39 | * 064 has many IRQ problems (due to the way we implement CPU based IRQ) - see Skull & Crossbones. |
| 40 | 40 | Klax has problems as well (even if it uses scanline based IRQ, according to Disch's docs). |
| 41 | 41 | * 067 some 1-line glitches that cannot be solved without a better implementation for cycle-based IRQs |
| 42 | | * 071 Fire Hawk is not properly working (it requires one hack to support both boards using this mapper) |
| 43 | 42 | * 072, 086, 092 lack samples support (maybe others as well) |
| 44 | 43 | * 073 16 bit IRQ mode is not implemented |
| 45 | 44 | * 077 Requires 4-screen mirroring. Currently, it is very glitchy |
| r6027 | r6028 | |
| 81 | 80 | * 032 - Major League needs hardwired mirroring (missing windows and glitched field in top view, otherwise) |
| 82 | 81 | * 034 - Impossible Mission II is not like BxROM games (it writes to 0x7ffd-0x7fff, instead of 0x8000). It is still |
| 83 | 82 | unplayable though (see above) |
| 83 | * 071 - Fire Hawk is different from other Camerica games (no hardwired mirroring) |
| 84 | 84 | * 078 - Cosmo Carrier needs a different mirroring than Holy Diver |
| 85 | 85 | * 113 - HES 6-in-1 requires mirroring (check Bookyman playfield), while other games break with this (check AV Soccer) |
| 86 | 86 | * 153 - Famicom Jump II uses a different board (or the same in a very different way) |
| r6027 | r6028 | |
| 4750 | 4750 | |
| 4751 | 4751 | *************************************************************/ |
| 4752 | 4752 | |
| 4753 | | static WRITE8_HANDLER( mapper71_m_w ) |
| 4754 | | { |
| 4755 | | LOG_MMC(("mapper71_m_w offset: %04x, data: %02x\n", offset, data)); |
| 4756 | | |
| 4757 | | prg16_89ab(space->machine, data); |
| 4758 | | } |
| 4759 | | |
| 4760 | 4753 | static WRITE8_HANDLER( mapper71_w ) |
| 4761 | 4754 | { |
| 4762 | 4755 | LOG_MMC(("mapper71_w offset: %04x, data: %02x\n", offset, data)); |
| 4763 | 4756 | |
| 4764 | | if (offset >= 0x4000) |
| 4757 | switch (offset & 0x7000) |
| 4758 | { |
| 4759 | case 0x0000: |
| 4760 | case 0x1000: |
| 4761 | if (nes.crc_hack) |
| 4762 | set_nt_mirroring((data & 0x10) ? PPU_MIRROR_HIGH : PPU_MIRROR_LOW); |
| 4763 | break; |
| 4764 | case 0x4000: |
| 4765 | case 0x5000: |
| 4766 | case 0x6000: |
| 4767 | case 0x7000: |
| 4765 | 4768 | prg16_89ab(space->machine, data); |
| 4769 | break; |
| 4770 | } |
| 4766 | 4771 | } |
| 4767 | 4772 | |
| 4768 | 4773 | /************************************************************* |
| r6027 | r6028 | |
| 11116 | 11121 | { 68, "SunSoft 4", NULL, NULL, NULL, mapper68_w, NULL, NULL, NULL }, |
| 11117 | 11122 | { 69, "SunSoft FME", NULL, NULL, NULL, mapper69_w, NULL, NULL, mapper69_irq }, |
| 11118 | 11123 | { 70, "74161/32 Bandai", NULL, NULL, NULL, mapper70_w, NULL, NULL, NULL }, |
| 11119 | | { 71, "Camerica", NULL, NULL, mapper71_m_w, mapper71_w, NULL, NULL, NULL }, |
| 11124 | { 71, "Camerica", NULL, NULL, NULL, mapper71_w, NULL, NULL, NULL }, |
| 11120 | 11125 | { 72, "74161/32 Jaleco", NULL, NULL, NULL, mapper72_w, NULL, NULL, NULL }, |
| 11121 | 11126 | { 73, "Konami VRC 3", NULL, NULL, NULL, mapper73_w, NULL, NULL, konami_irq }, |
| 11122 | 11127 | { 74, "Waixing Type A", NULL, NULL, NULL, mapper74_w, NULL, NULL, mapper4_irq }, |
| r6027 | r6028 | |
| 11377 | 11382 | case 155: |
| 11378 | 11383 | mmc_cmd1 = 0; |
| 11379 | 11384 | mmc_count = 0; |
| 11380 | | MMC1_regs[0] = 0x0f; |
| 11385 | MMC1_regs[0] = 0;//0x0f; |
| 11381 | 11386 | MMC1_regs[1] = MMC1_regs[2] = MMC1_regs[3] = 0; |
| 11382 | 11387 | set_nt_mirroring(PPU_MIRROR_HORZ); |
| 11383 | 11388 | MMC1_set_chr(space->machine); |
| r6027 | r6028 | |
| 11674 | 11679 | case 65: |
| 11675 | 11680 | case 67: |
| 11676 | 11681 | case 69: |
| 11677 | | case 71: |
| 11678 | 11682 | case 72: |
| 11679 | 11683 | case 78: |
| 11680 | 11684 | case 92: |
| r6027 | r6028 | |
| 11690 | 11694 | prg16_89ab(space->machine, nes.prg_chunks - 2); |
| 11691 | 11695 | prg16_cdef(space->machine, nes.prg_chunks - 1); |
| 11692 | 11696 | break; |
| 11697 | case 71: |
| 11698 | set_nt_mirroring(PPU_MIRROR_HORZ); |
| 11699 | prg16_89ab(space->machine, 0); |
| 11700 | prg16_cdef(space->machine, nes.prg_chunks - 1); |
| 11701 | break; |
| 11693 | 11702 | case 76: |
| 11694 | 11703 | prg8_89(space->machine, 0); |
| 11695 | 11704 | prg8_ab(space->machine, 1); |
| r6027 | r6028 | |
| 12180 | 12189 | static const unif unif_list[] = |
| 12181 | 12190 | { |
| 12182 | 12191 | /* UNIF LOW_W, LOW_R, MED_W, HIGH_W, PPU_latch, scanline CB, hblank CB PRG CHR NVW WRAM CRAM NMT IDX*/ |
| 12183 | | { "UNL-SACHEN-8259A", mapper141_l_w, NULL, mapper141_m_w, NULL, NULL, NULL, NULL, 256, 256, 0, 0, CHRRAM_0, 0, SACHEN_8259A}, |
| 12192 | { "UNL-SACHEN-8259A", mapper141_l_w, NULL, mapper141_m_w, NULL, NULL, NULL, NULL, 16, 32, 0, 0, CHRRAM_0, 0, SACHEN_8259A}, |
| 12184 | 12193 | }; |
| 12185 | 12194 | |
| 12186 | 12195 | const unif *nes_unif_lookup( const char *board ) |