src/mess/machine/nes.c
| r8151 | r8152 | |
| 59 | 59 | state->slow_banking = 0; |
| 60 | 60 | /* If we are loading a disk we have already filled state->fds_data and we don't want to overwrite it, |
| 61 | 61 | if we are loading a cart image identified as mapper 20 (probably wrong mapper...) we need to alloc |
| 62 | | memory for the bank 2 pointer */ |
| 62 | memory for use in nes_fds_r/nes_fds_w. Same goes for allocation of fds_ram (used for bank2) */ |
| 63 | 63 | if (state->fds_data == NULL) |
| 64 | | state->fds_data = auto_alloc_array(machine, UINT8, 0x8000); |
| 64 | { |
| 65 | UINT32 size = memory_region_length(machine, "maincpu") - 0x10000; |
| 66 | state->fds_data = auto_alloc_array_clear(machine, UINT8, size); |
| 67 | memcpy(state->fds_data, state->rom, size); // copy in fds_data the cart PRG |
| 68 | } |
| 69 | if (state->fds_ram == NULL) |
| 70 | state->fds_ram = auto_alloc_array(machine, UINT8, 0x8000); |
| 71 | |
| 65 | 72 | memory_install_read8_handler(space, 0x4030, 0x403f, 0, 0, nes_fds_r); |
| 66 | 73 | memory_install_read_bank(space, 0x6000, 0xdfff, 0, 0, "bank2"); |
| 67 | 74 | memory_install_read_bank(space, 0xe000, 0xffff, 0, 0, "bank1"); |
| r8151 | r8152 | |
| 70 | 77 | memory_install_write_bank(space, 0x6000, 0xdfff, 0, 0, "bank2"); |
| 71 | 78 | |
| 72 | 79 | memory_set_bankptr(machine, "bank1", &state->rom[0xe000]); |
| 73 | | memory_set_bankptr(machine, "bank2", state->fds_data); |
| 80 | memory_set_bankptr(machine, "bank2", state->fds_ram); |
| 74 | 81 | break; |
| 75 | 82 | case 50: |
| 76 | 83 | memory_install_write8_handler(space, 0x4020, 0x403f, 0, 0, nes_mapper50_add_w); |
| r8151 | r8152 | |
| 496 | 503 | |
| 497 | 504 | if ((magic[0] == 'N') && (magic[1] == 'E') && (magic[2] == 'S')) /* If header starts with 'NES' it is iNES */ |
| 498 | 505 | { |
| 506 | UINT32 prg_size; |
| 507 | |
| 499 | 508 | state->format = 1; // we use this to select between mapper_reset / unif_reset |
| 500 | 509 | |
| 501 | 510 | mapinfo = image_extrainfo(image); |
| r8151 | r8152 | |
| 577 | 586 | memory_region_free(image->machine, "gfx1"); |
| 578 | 587 | |
| 579 | 588 | /* Allocate them again with the proper size */ |
| 580 | | memory_region_alloc(image->machine, "maincpu", 0x10000 + (state->prg_chunks + 1) * 0x4000, 0); |
| 589 | prg_size = (state->prg_chunks == 1) ? 2 * 0x4000 : state->prg_chunks * 0x4000; |
| 590 | memory_region_alloc(image->machine, "maincpu", 0x10000 + prg_size, 0); |
| 581 | 591 | if (state->chr_chunks) |
| 582 | 592 | memory_region_alloc(image->machine, "gfx1", state->chr_chunks * 0x2000, 0); |
| 583 | 593 | |
| r8151 | r8152 | |
| 598 | 608 | { |
| 599 | 609 | image_fread(image, &state->rom[0x14000], 0x4000); |
| 600 | 610 | /* Mirror this bank into $8000 */ |
| 601 | | memcpy(&state->rom[0x10000], &state->rom [0x14000], 0x4000); |
| 611 | memcpy(&state->rom[0x10000], &state->rom[0x14000], 0x4000); |
| 602 | 612 | } |
| 603 | 613 | else |
| 604 | 614 | image_fread(image, &state->rom[0x10000], 0x4000 * state->prg_chunks); |
| r8151 | r8152 | |
| 635 | 645 | } |
| 636 | 646 | |
| 637 | 647 | #if SPLIT_CHR |
| 648 | if (state->chr_chunks > 0) |
| 638 | 649 | { |
| 639 | 650 | FILE *chrout; |
| 640 | 651 | char outname[255]; |
| r8151 | r8152 | |
| 667 | 678 | char magic2[4]; |
| 668 | 679 | UINT8 buffer[4]; |
| 669 | 680 | UINT32 chunk_length = 0, read_length = 0x20; |
| 670 | | UINT32 prg_start = 0, chr_start = 0; |
| 681 | UINT32 prg_start = 0, chr_start = 0, prg_size; |
| 671 | 682 | int prg_left = 0, chr_left = 0; // used to verify integrity of our unif image |
| 672 | 683 | char unif_mapr[32]; // here we should store MAPR chunks |
| 673 | 684 | UINT32 size = image_length(image); |
| r8151 | r8152 | |
| 732 | 743 | state->prg_chunks = unif_board->prgrom; |
| 733 | 744 | state->chr_chunks = unif_board->chrrom; |
| 734 | 745 | state->battery = unif_board->wram; // we should implement WRAM banks... |
| 735 | | // state->hard_mirroring = unif_board->nt; |
| 736 | | // state->four_screen_vram = ; |
| 746 | // state->hard_mirroring = unif_board->nt; |
| 747 | // state->four_screen_vram = ; |
| 737 | 748 | |
| 738 | 749 | /* Free the regions that were allocated by the ROM loader */ |
| 739 | 750 | memory_region_free(image->machine, "maincpu"); |
| 740 | 751 | memory_region_free(image->machine, "gfx1"); |
| 741 | 752 | |
| 742 | 753 | /* Allocate them again with the proper size */ |
| 743 | | memory_region_alloc(image->machine, "maincpu", 0x10000 + (state->prg_chunks + 1) * 0x4000, 0); |
| 754 | prg_size = (state->prg_chunks == 1) ? 2 * 0x4000 : state->prg_chunks * 0x4000; |
| 755 | memory_region_alloc(image->machine, "maincpu", 0x10000 + prg_size, 0); |
| 744 | 756 | if (state->chr_chunks) |
| 745 | 757 | memory_region_alloc(image->machine, "gfx1", state->chr_chunks * 0x2000, 0); |
| 746 | 758 | |
| r8151 | r8152 | |
| 918 | 930 | } |
| 919 | 931 | } while (size > read_length); |
| 920 | 932 | |
| 921 | | if (!mapr_chunk_found ) |
| 933 | if (!mapr_chunk_found) |
| 922 | 934 | fatalerror("UNIF should have a [MAPR] chunk to work. Check if your image has been corrupted"); |
| 923 | 935 | |
| 936 | #if SPLIT_PRG |
| 937 | { |
| 938 | FILE *prgout; |
| 939 | char outname[255]; |
| 940 | |
| 941 | sprintf(outname, "%s.prg", image_filename(image)); |
| 942 | prgout = fopen(outname, "wb"); |
| 943 | if (prgout) |
| 944 | { |
| 945 | fwrite(&state->rom[0x10000], 1, 0x4000 * state->prg_chunks, prgout); |
| 946 | printf("Created PRG chunk\n"); |
| 947 | } |
| 948 | |
| 949 | fclose(prgout); |
| 950 | } |
| 951 | #endif |
| 952 | |
| 953 | #if SPLIT_CHR |
| 954 | if (state->chr_chunks > 0) |
| 955 | { |
| 956 | FILE *chrout; |
| 957 | char outname[255]; |
| 958 | |
| 959 | sprintf(outname, "%s.chr", image_filename(image)); |
| 960 | chrout= fopen(outname, "wb"); |
| 961 | if (chrout) |
| 962 | { |
| 963 | fwrite(state->vrom, 1, 0x2000 * state->chr_chunks, chrout); |
| 964 | printf("Created CHR chunk\n"); |
| 965 | } |
| 966 | fclose(chrout); |
| 967 | } |
| 968 | #endif |
| 969 | |
| 924 | 970 | logerror("UNIF support is only very preliminary.\n"); |
| 925 | 971 | } |
| 926 | 972 | else |
| r8151 | r8152 | |
| 944 | 990 | // validate the xml fields |
| 945 | 991 | if (!prg_size) |
| 946 | 992 | fatalerror("No PRG entry for this software! Please check if the xml list got corrupted"); |
| 947 | | if (prg_size < 0x4000) |
| 993 | if (prg_size < 0x8000) |
| 948 | 994 | fatalerror("PRG entry is too small! Please check if the xml list got corrupted"); |
| 949 | 995 | |
| 950 | 996 | if (chr_size) |
| r8151 | r8152 | |
| 1006 | 1052 | if (image_length(image) % 65500) |
| 1007 | 1053 | header = 0x10; |
| 1008 | 1054 | |
| 1009 | | image_fseek(image, 0, SEEK_END); |
| 1010 | | state->fds_sides = (image_ftell(image) - header) / 65500; |
| 1011 | | state->fds_data = (UINT8*)image_malloc(image, state->fds_sides * 65500); |
| 1055 | state->fds_sides = (image_length(image) - header) / 65500; |
| 1012 | 1056 | |
| 1057 | if (state->fds_data == NULL) |
| 1058 | state->fds_data = (UINT8*)image_malloc(image, state->fds_sides * 65500); // I don't think we can arrive here ever, probably it can be removed... |
| 1059 | |
| 1013 | 1060 | /* if there is an header, skip it */ |
| 1014 | 1061 | image_fseek(image, header, SEEK_SET); |
| 1015 | 1062 | |
| r8151 | r8152 | |
| 1043 | 1090 | state->fds_sides = 0; |
| 1044 | 1091 | state->fds_data = NULL; |
| 1045 | 1092 | |
| 1093 | state->fds_data = auto_alloc_array_clear(machine, UINT8, 65500 * 2); |
| 1094 | state->fds_ram = auto_alloc_array_clear(machine, UINT8, 0x8000); |
| 1095 | state_save_register_global_pointer(machine, state->fds_ram, 0x8000); |
| 1096 | |
| 1046 | 1097 | floppy_install_load_proc(floppy_get_device(machine, 0), nes_load_proc); |
| 1047 | 1098 | floppy_install_unload_proc(floppy_get_device(machine, 0), nes_unload_proc); |
| 1048 | 1099 | } |