src/mess/machine/nes.c
| r8220 | r8221 | |
| 174 | 174 | /* memory subsystem is set up. When this routine is called */ |
| 175 | 175 | /* everything is ready, so we can just copy over the data */ |
| 176 | 176 | /* we loaded before. */ |
| 177 | | memcpy(state->battery_ram, state->battery_data, NES_BATTERY_SIZE); |
| 177 | memcpy(state->battery_ram, state->battery_data, state->battery_size); |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | // to be probably removed (it does nothing since a long time) |
| 180 | 181 | int nes_ppu_vidaccess( running_device *device, int address, int data ) |
| 181 | 182 | { |
| 182 | | // nes_state *state = (nes_state *)device->machine->driver_data; |
| 183 | | |
| 184 | | /* TODO: this is a bit of a hack, needed to get Argus, ASO, etc to work */ |
| 185 | | /* but, B-Wings, submath (j) seem to use this location differently... */ |
| 186 | | // if (state->chr_chunks && (address & 0x3fff) < 0x2000) |
| 187 | | // { |
| 188 | | // int vrom_loc; |
| 189 | | // vrom_loc = (nes_vram[(address & 0x1fff) >> 10] * 16) + (address & 0x3ff); |
| 190 | | // data = state->vrom [vrom_loc]; |
| 191 | | // } |
| 192 | 183 | return data; |
| 193 | 184 | } |
| 194 | 185 | |
| r8220 | r8221 | |
| 304 | 295 | |
| 305 | 296 | /* Write out the battery file if necessary */ |
| 306 | 297 | if (state->battery) |
| 307 | | image_battery_save(state->cart, state->battery_ram, NES_BATTERY_SIZE); |
| 298 | image_battery_save(state->cart, state->battery_ram, state->battery_size); |
| 308 | 299 | } |
| 309 | 300 | |
| 310 | 301 | |
| r8220 | r8221 | |
| 521 | 512 | DEVICE_IMAGE_LOAD( nes_cart ) |
| 522 | 513 | { |
| 523 | 514 | nes_state *state = (nes_state *)image->machine->driver_data; |
| 524 | | const char *mapinfo; |
| 525 | | int mapint1 = 0, mapint2 = 0, mapint3 = 0, mapint4 = 0, goodcrcinfo = 0; |
| 526 | | char magic[4]; |
| 527 | | char skank[8]; |
| 528 | | int local_options = 0; |
| 529 | | char m; |
| 530 | | int i; |
| 531 | 515 | |
| 532 | 516 | if (image_software_entry(image) == NULL) |
| 533 | 517 | { |
| 518 | const char *mapinfo; |
| 519 | int mapint1 = 0, mapint2 = 0, mapint3 = 0, mapint4 = 0, goodcrcinfo = 0; |
| 520 | char magic[4], extend[5]; |
| 521 | int local_options = 0; |
| 522 | char m; |
| 523 | |
| 534 | 524 | /* Check first 4 bytes of the image to decide if it is UNIF or iNES */ |
| 535 | 525 | /* Unfortunately, many .unf files have been released as .nes, so we cannot rely on extensions only */ |
| 536 | 526 | memset(magic, '\0', sizeof(magic)); |
| r8220 | r8221 | |
| 539 | 529 | if ((magic[0] == 'N') && (magic[1] == 'E') && (magic[2] == 'S')) /* If header starts with 'NES' it is iNES */ |
| 540 | 530 | { |
| 541 | 531 | UINT32 prg_size; |
| 542 | | |
| 543 | 532 | state->format = 1; // we use this to select between mapper_reset / unif_reset |
| 533 | state->ines20 = 0; |
| 534 | state->battery_size = NES_BATTERY_SIZE; // with iNES we can only support 8K WRAM battery (iNES 2.0 might fix this) |
| 544 | 535 | |
| 536 | // check if the image is recognized by nes.hsi |
| 545 | 537 | mapinfo = image_extrainfo(image); |
| 546 | 538 | |
| 547 | | if (mapinfo) |
| 539 | // image_extrainfo() resets the file position back to start. |
| 540 | // Let's skip past the magic header once again. |
| 541 | image_fseek(image, 4, SEEK_SET); |
| 542 | |
| 543 | image_fread(image, &state->prg_chunks, 1); |
| 544 | image_fread(image, &state->chr_chunks, 1); |
| 545 | /* Read the first ROM option byte (offset 6) */ |
| 546 | image_fread(image, &m, 1); |
| 547 | |
| 548 | /* Interpret the iNES header flags */ |
| 549 | state->mapper = (m & 0xf0) >> 4; |
| 550 | local_options = m & 0x0f; |
| 551 | |
| 552 | /* Read the second ROM option byte (offset 7) */ |
| 553 | image_fread(image, &m, 1); |
| 554 | |
| 555 | switch (m & 0xc) |
| 548 | 556 | { |
| 557 | case 0x4: |
| 558 | case 0xc: |
| 559 | // probably the header got corrupted: don't trust upper bits for mapper |
| 560 | break; |
| 561 | |
| 562 | case 0x8: // it's iNES 2.0 format |
| 563 | state->ines20 = 1; |
| 564 | case 0x0: |
| 565 | default: |
| 566 | state->mapper = state->mapper | (m & 0xf0); |
| 567 | break; |
| 568 | } |
| 569 | |
| 570 | if (mapinfo /* && !state->ines20 */) |
| 571 | { |
| 549 | 572 | if (4 == sscanf(mapinfo,"%d %d %d %d", &mapint1, &mapint2, &mapint3, &mapint4)) |
| 550 | 573 | { |
| 574 | /* image is present in nes.hsi: overwrite the header settings with these */ |
| 551 | 575 | state->mapper = mapint1; |
| 552 | 576 | local_options = mapint2 & 0x0f; |
| 553 | 577 | state->crc_hack = mapint2 & 0xf0; // this is used to differentiate among variants of the same Mapper (see nes_mmc.c) |
| r8220 | r8221 | |
| 555 | 579 | state->chr_chunks = mapint4; |
| 556 | 580 | logerror("NES.HSI info: %d %d %d %d\n", mapint1, mapint2, mapint3, mapint4); |
| 557 | 581 | goodcrcinfo = 1; |
| 582 | state->ines20 = 0; |
| 558 | 583 | } |
| 559 | 584 | else |
| 560 | 585 | { |
| r8220 | r8221 | |
| 566 | 591 | logerror("NES: No extrainfo found\n"); |
| 567 | 592 | } |
| 568 | 593 | |
| 569 | | if (!goodcrcinfo) |
| 570 | | { |
| 571 | | // image_extrainfo() resets the file position back to start. |
| 572 | | // Let's skip past the magic header once again. |
| 573 | | image_fseek(image, 4, SEEK_SET); |
| 574 | | |
| 575 | | image_fread(image, &state->prg_chunks, 1); |
| 576 | | image_fread(image, &state->chr_chunks, 1); |
| 577 | | /* Read the first ROM option byte (offset 6) */ |
| 578 | | image_fread(image, &m, 1); |
| 579 | | |
| 580 | | /* Interpret the iNES header flags */ |
| 581 | | state->mapper = (m & 0xf0) >> 4; |
| 582 | | local_options = m & 0x0f; |
| 583 | | |
| 584 | | /* Read the second ROM option byte (offset 7) */ |
| 585 | | image_fread(image, &m, 1); |
| 586 | | |
| 587 | | /* Check for skanky headers */ |
| 588 | | image_fread(image, &skank, 8); |
| 589 | | |
| 590 | | /* If the header has junk in the unused bytes, assume the extra mapper byte is also invalid */ |
| 591 | | /* We only check the first 4 unused bytes for now */ |
| 592 | | for (i = 0; i < 4; i ++) |
| 593 | | { |
| 594 | | logerror("%02x ", skank[i]); |
| 595 | | if (skank[i] != 0x00) |
| 596 | | { |
| 597 | | logerror("(skank: %d)", i); |
| 598 | | } |
| 599 | | } |
| 600 | | logerror("\n"); |
| 601 | | |
| 602 | | state->mapper = state->mapper | (m & 0xf0); |
| 603 | | } |
| 604 | | |
| 605 | 594 | state->hard_mirroring = local_options & 0x01; |
| 606 | 595 | state->battery = local_options & 0x02; |
| 607 | 596 | state->trainer = local_options & 0x04; |
| r8220 | r8221 | |
| 616 | 605 | if (state->four_screen_vram) |
| 617 | 606 | logerror("-- 4-screen VRAM\n"); |
| 618 | 607 | |
| 608 | if (state->ines20) |
| 609 | { |
| 610 | logerror("Extended iNES format:\n"); |
| 611 | image_fread(image, &extend, 5); |
| 612 | state->mapper |= (extend[0] & 0x0f) << 8; |
| 613 | logerror("-- mapper: %d\n", state->mapper); |
| 614 | logerror("-- submapper: %d\n", (extend[0] & 0xf0) >> 4); |
| 615 | state->prg_chunks |= ((extend[1] & 0x0f) << 8); |
| 616 | state->chr_chunks |= ((extend[1] & 0xf0) << 4); |
| 617 | logerror("-- PRG chunks: %d\n", state->prg_chunks); |
| 618 | logerror("-- CHR chunks: %d\n", state->chr_chunks); |
| 619 | logerror("-- PRG NVWRAM: %d\n", extend[2] & 0x0f); |
| 620 | logerror("-- PRG WRAM: %d\n", (extend[2] & 0xf0) >> 4); |
| 621 | logerror("-- CHR NVWRAM: %d\n", extend[3] & 0x0f); |
| 622 | logerror("-- CHR WRAM: %d\n", (extend[3] & 0xf0) >> 4); |
| 623 | logerror("-- TV System: %d\n", extend[4] & 3); |
| 624 | } |
| 625 | |
| 619 | 626 | /* Free the regions that were allocated by the ROM loader */ |
| 620 | 627 | memory_region_free(image->machine, "maincpu"); |
| 621 | 628 | memory_region_free(image->machine, "gfx1"); |
| r8220 | r8221 | |
| 639 | 646 | image_fread(image, &state->wram[0x1000], 0x200); |
| 640 | 647 | |
| 641 | 648 | /* Read in the program chunks */ |
| 649 | image_fread(image, &state->rom[0x10000], 0x4000 * state->prg_chunks); |
| 642 | 650 | if (state->prg_chunks == 1) |
| 643 | | { |
| 644 | | image_fread(image, &state->rom[0x14000], 0x4000); |
| 645 | | /* Mirror this bank into $8000 */ |
| 646 | | memcpy(&state->rom[0x10000], &state->rom[0x14000], 0x4000); |
| 647 | | } |
| 648 | | else |
| 649 | | image_fread(image, &state->rom[0x10000], 0x4000 * state->prg_chunks); |
| 651 | memcpy(&state->rom[0x14000], &state->rom[0x10000], 0x4000); |
| 650 | 652 | |
| 651 | 653 | #if SPLIT_PRG |
| 652 | 654 | { |
| r8220 | r8221 | |
| 700 | 702 | logerror("**\n"); |
| 701 | 703 | // printf("CHR chunks: %02x, size: %06x\n", state->chr_chunks, 0x4000 * state->chr_chunks); |
| 702 | 704 | // printf("**\n"); |
| 703 | | |
| 704 | | /* Attempt to load a battery file for this ROM. If successful, we */ |
| 705 | | /* must wait until later to move it to the system memory. */ |
| 706 | | if (state->battery) |
| 707 | | image_battery_load(image, state->battery_data, NES_BATTERY_SIZE, 0x00); |
| 708 | | |
| 709 | 705 | } |
| 710 | 706 | else if ((magic[0] == 'U') && (magic[1] == 'N') && (magic[2] == 'I') && (magic[3] == 'F')) /* If header starts with 'UNIF' it is UNIF */ |
| 711 | 707 | { |
| r8220 | r8221 | |
| 763 | 759 | state->mapper = 0; // this allows us to set up memory handlers without duplicating code (for the moment) |
| 764 | 760 | state->board = unif_board->board; |
| 765 | 761 | state->battery = unif_board->wram; // we should implement WRAM banks... |
| 762 | state->battery_size = NES_BATTERY_SIZE; // FIXME: we should allow for smaller battery! |
| 766 | 763 | // state->hard_mirroring = unif_board->nt; |
| 767 | 764 | // state->four_screen_vram = ; |
| 768 | 765 | |
| r8220 | r8221 | |
| 1028 | 1025 | |
| 1029 | 1026 | state->format = 2; // temporarily treat this as a unif file |
| 1030 | 1027 | state->board = image_get_feature(image); |
| 1031 | | state->battery = 0; // presence of a battery should be read from .xml |
| 1032 | 1028 | state->mapper = 0; // this allows us to set up memory handlers without duplicating code (for the moment) |
| 1033 | 1029 | |
| 1030 | state->battery = (image_get_software_region(image, "bwram") != NULL) ? 1 : 0; |
| 1031 | state->battery_size = image_get_software_region_length(image, "bwram"); |
| 1032 | |
| 1034 | 1033 | // FIXME: we need to handle the remaining variables. on the short term, we might |
| 1035 | 1034 | // create a table for the various mappers (based on the 'feature' value in xml), |
| 1036 | 1035 | // but on the long term we need to rework the whole emulation to first use the |
| r8220 | r8221 | |
| 1041 | 1040 | //state->hard_mirroring = ; |
| 1042 | 1041 | //state->trainer = ; |
| 1043 | 1042 | //state->four_screen_vram = ; |
| 1044 | | |
| 1045 | | /* Attempt to load a battery file for this ROM. If successful, we */ |
| 1046 | | /* must wait until later to move it to the system memory. */ |
| 1047 | | if (state->battery) |
| 1048 | | image_battery_load(image, state->battery_data, NES_BATTERY_SIZE, 0x00); |
| 1049 | 1043 | } |
| 1050 | 1044 | |
| 1045 | /* Attempt to load a battery file for this ROM. If successful, we */ |
| 1046 | /* must wait until later to move it to the system memory. */ |
| 1047 | if (state->battery) |
| 1048 | image_battery_load(image, state->battery_data, state->battery_size, 0x00); |
| 1049 | |
| 1051 | 1050 | return INIT_PASS; |
| 1052 | 1051 | } |
| 1053 | 1052 | |
src/mess/machine/nes_unif.c
| r8220 | r8221 | |
| 1186 | 1186 | { "VIRGIN-SNROM", NULL, NULL, NULL, mapper1_w, NULL, NULL, NULL, 16, 0, 8, 0, CHRRAM_8, NT_HORZ, STD_SNROM}, |
| 1187 | 1187 | // below are boards we need for the new PCB-based code (and by list support): no unif file is known to use them, but they are needed to handle iNES file like PCBs. |
| 1188 | 1188 | { "DAOU-306", NULL, NULL, NULL, mapper156_w, NULL, NULL, NULL, 256, 128, 0, 0, 0, 0, OPENCORP_DAOU306}, // mapper 156 |
| 1189 | | { "IREM-H-3001", NULL, NULL, NULL, NULL, NULL, NULL, NULL, 256, 128, 0, 0, 0, 0, IREM_H3001}, // mapper 65 |
| 1189 | { "IREM-H-3001", NULL, NULL, NULL, mapper65_w, NULL, NULL, irem_irq, 256, 128, 0, 0, 0, 0, IREM_H3001}, // mapper 65 |
| 1190 | 1190 | { "BANDAI-DATACH", NULL, NULL, mapper16_m_w, mapper16_w, NULL, NULL, bandai_irq, 256, 128, 0, 0, 0, 0, BANDAI_DATACH}, // mapper 157 |
| 1191 | 1191 | { "BANDAI-KARAOKE", NULL, NULL, NULL, mapper188_w, NULL, NULL, NULL, 256, 128, 0, 0, 0, 0, BANDAI_KARAOKE}, // mapper 188 |
| 1192 | 1192 | { "BANDAI-OEKAKIDS", NULL, NULL, NULL, mapper96_w, NULL, NULL, NULL, 256, 128, 0, 0, 0, 0, BANDAI_OEKAKIDS}, // mapper 96 |