trunk/src/mess/machine/md_slot.c
| r21985 | r21986 | |
| 389 | 389 | *************************************/ |
| 390 | 390 | |
| 391 | 391 | /* code taken directly from GoodGEN by Cowering */ |
| 392 | | static int genesis_is_SMD(unsigned char *buf,unsigned int len) |
| 392 | static int genesis_is_SMD(unsigned char *buf, unsigned int len) |
| 393 | 393 | { |
| 394 | 394 | if (buf[0x2080] == 'S' && buf[0x80] == 'E' && buf[0x2081] == 'G' && buf[0x81] == 'A') |
| 395 | 395 | return 1; |
| r21985 | r21986 | |
| 459 | 459 | int base_md_cart_slot_device::load_nonlist() |
| 460 | 460 | { |
| 461 | 461 | unsigned char *ROM, *tmpROM; |
| 462 | | UINT32 len = m_cart->get_padded_size(length()); // if cart size is not (2^n * 64K), the system will see anyway that size so we need to alloc a bit more space |
| 462 | bool is_smd, is_md; |
| 463 | UINT32 tmplen = length(), offset, len; |
| 463 | 464 | |
| 465 | // STEP 1: store a (possibly headered) copy of the file and determine its type (SMD? MD? BIN?) |
| 466 | tmpROM = global_alloc_array(unsigned char, tmplen); |
| 467 | fread(tmpROM, tmplen); |
| 468 | is_smd = genesis_is_SMD(&tmpROM[0x200], tmplen - 0x200); |
| 469 | is_md = (tmpROM[0x80] == 'E') && (tmpROM[0x81] == 'A') && (tmpROM[0x82] == 'M' || tmpROM[0x82] == 'G'); |
| 470 | |
| 471 | // take header into account, if any |
| 472 | offset = is_smd ? 0x200 : 0; |
| 473 | |
| 474 | // STEP 2: allocate space for the real copy of the game |
| 475 | // if cart size is not (2^n * 64K), the system will see anyway that size so we need to alloc a bit more space |
| 476 | len = m_cart->get_padded_size(tmplen - offset); |
| 464 | 477 | // this contains an hack for SSF2: its current bankswitch code needs larger rom space to work |
| 465 | 478 | m_cart->rom_alloc(machine(), (len == 0x500000) ? 0x900000 : len); |
| 466 | 479 | |
| 480 | |
| 481 | // STEP 3: copy the game data in the appropriate way |
| 467 | 482 | ROM = (unsigned char *)m_cart->get_rom_base(); |
| 468 | | tmpROM = global_alloc_array(unsigned char, len); |
| 469 | 483 | |
| 470 | | // STEP 1: determine the file type (SMD? MD? BIN?) |
| 471 | | fread(tmpROM, len); |
| 472 | | |
| 473 | | /* is this a SMD file? */ |
| 474 | | if (genesis_is_SMD(&tmpROM[0x200], len)) |
| 484 | if (is_smd) |
| 475 | 485 | { |
| 476 | 486 | mame_printf_debug("SMD!\n"); |
| 477 | 487 | |
| 478 | | for (int ptr = 0; ptr < (len - 0x200) / 0x2000; ptr += 2) |
| 488 | for (int ptr = 0; ptr < (tmplen - 0x200) / 0x2000; ptr += 2) |
| 479 | 489 | { |
| 480 | 490 | for (int x = 0; x < 0x2000; x++) |
| 481 | 491 | { |
| 482 | | *ROM++ = *(tmpROM + 0x200 + ((ptr + 1) * 0x2000) + x); |
| 483 | | *ROM++ = *(tmpROM + 0x200 + ((ptr + 0) * 0x2000) + x); |
| 492 | ROM[ptr * 0x2000 + x * 2 + 0] = tmpROM[0x200 + ((ptr + 1) * 0x2000) + x]; |
| 493 | ROM[ptr * 0x2000 + x * 2 + 1] = tmpROM[0x200 + ((ptr + 0) * 0x2000) + x]; |
| 484 | 494 | } |
| 485 | 495 | } |
| 486 | | |
| 487 | | len -= 0x200; |
| 488 | 496 | } |
| 489 | | /* is this a MD file? */ |
| 490 | | else if ((tmpROM[0x80] == 'E') && (tmpROM[0x81] == 'A') && (tmpROM[0x82] == 'M' || tmpROM[0x82] == 'G')) |
| 497 | else if (is_md) |
| 491 | 498 | { |
| 492 | 499 | mame_printf_debug("MD!\n"); |
| 493 | 500 | |
| 494 | | for (int ptr = 0; ptr < len; ptr += 2) |
| 501 | for (int ptr = 0; ptr < tmplen; ptr += 2) |
| 495 | 502 | { |
| 496 | | ROM[ptr] = tmpROM[(len >> 1) + (ptr >> 1)]; |
| 503 | ROM[ptr] = tmpROM[(tmplen >> 1) + (ptr >> 1)]; |
| 497 | 504 | ROM[ptr + 1] = tmpROM[(ptr >> 1)]; |
| 498 | 505 | } |
| 499 | 506 | } |
| 500 | | /* BIN it is, then */ |
| 501 | 507 | else |
| 502 | 508 | { |
| 509 | mame_printf_debug("BIN!\n"); |
| 510 | |
| 503 | 511 | fseek(0, SEEK_SET); |
| 504 | 512 | fread(ROM, len); |
| 505 | 513 | } |
| r21985 | r21986 | |
| 507 | 515 | global_free(tmpROM); |
| 508 | 516 | |
| 509 | 517 | // if we allocated a ROM larger that the file (e.g. due to uneven cart size), set remaining space to 0xff |
| 510 | | if (len > length()) |
| 511 | | memset(m_cart->get_rom_base() + length()/2, 0xffff, (len - length())/2); |
| 518 | if (len > (tmplen - offset)) |
| 519 | memset(m_cart->get_rom_base() + (tmplen - offset)/2, 0xffff, (len - tmplen + offset)/2); |
| 512 | 520 | |
| 513 | | // STEP 2: determine the cart type (to deal with pirate mappers & eeprom) |
| 514 | | m_type = get_cart_type(ROM, length()); |
| 515 | 521 | |
| 522 | // STEP 4: determine the cart type (to deal with sram/eeprom & pirate mappers) |
| 523 | m_type = get_cart_type(ROM, len); |
| 524 | |
| 516 | 525 | // handle mirroring of ROM, unless it's SSF2 or Pier Solar |
| 517 | 526 | if (m_type != SSF2 && m_type != PSOLAR) |
| 518 | 527 | m_cart->rom_map_setup(len); |
| 519 | 528 | |
| 529 | |
| 520 | 530 | #ifdef LSB_FIRST |
| 521 | 531 | unsigned char fliptemp; |
| 522 | 532 | // is this really needed nowadays? |
| r21985 | r21986 | |
| 889 | 899 | |
| 890 | 900 | if (open_image_file(options)) |
| 891 | 901 | { |
| 892 | | UINT32 len = core_fsize(m_file); |
| 902 | UINT32 len = core_fsize(m_file), offset = 0;; |
| 893 | 903 | UINT8 *ROM = global_alloc_array(UINT8, len); |
| 894 | 904 | int type; |
| 895 | 905 | |
| 896 | 906 | core_fread(m_file, ROM, len); |
| 897 | 907 | |
| 898 | | type = get_cart_type(ROM, len); |
| 908 | if (genesis_is_SMD(&ROM[0x200], len - 0x200)) |
| 909 | offset = 0x200; |
| 910 | |
| 911 | type = get_cart_type(ROM + offset, len - offset); |
| 899 | 912 | slot_string = md_get_slot(type); |
| 900 | 913 | |
| 901 | 914 | global_free(ROM); |