| 584 | } |
| 585 | |
| 586 | int UNIFLoad(const char *name, FCEUFILE *fp) { |
| 587 | FCEU_fseek(fp, 0, SEEK_SET); |
| 588 | FCEU_fread(&unhead, 1, 4, fp); |
| 589 | if (memcmp(&unhead, "UNIF", 4)) |
| 590 | return LOADER_INVALID_FORMAT; |
| 591 | |
| 592 | ResetCartMapping(); |
| 593 | |
| 594 | ResetExState(0, 0); |
| 595 | ResetUNIF(); |
| 596 | if (!FCEU_read32le(&unhead.info, fp) |
| 597 | || (FCEU_fseek(fp, 0x20, SEEK_SET) < 0) |
| 598 | || !LoadUNIFChunks(fp)) |
| 599 | { |
| 600 | FreeUNIF(); |
| 601 | ResetUNIF(); |
| 602 | FCEU_PrintError("Error reading UNIF ROM image."); |
| 603 | return LOADER_HANDLED_ERROR; |
| 604 | } |
| 605 | |
| 606 | struct md5_context md5; |
| 607 | md5_starts(&md5); |
| 608 | for (int x = 0; x < 32; x++) |
| 609 | if (malloced[x]) { |
| 610 | md5_update(&md5, malloced[x], mallocedsizes[x]); |
| 611 | } |
| 612 | md5_finish(&md5, UNIFCart.MD5); |
| 613 | FCEU_printf(" ROM MD5: 0x"); |
| 614 | for (int x = 0; x < 16; x++) |
| 615 | FCEU_printf("%02x", UNIFCart.MD5[x]); |
| 616 | FCEU_printf("\n"); |
| 617 | memcpy(&GameInfo->MD5, &UNIFCart.MD5, sizeof(UNIFCart.MD5)); |
| 618 | |
| 619 | int result = InitializeBoard(); |
| 620 | switch (result) |
| 621 | { |
| 622 | case 0: |
| 623 | goto init_ok; |
| 624 | case 1: |
| 625 | FCEU_PrintError("UNIF mapper \"%s\" is not supported at all.", sboardname); |
| 626 | break; |
| 627 | case 2: |
| 628 | FCEU_PrintError("Unable to allocate CHR-RAM."); |
| 629 | break; |
| 630 | } |
| 631 | FreeUNIF(); |
| 632 | ResetUNIF(); |
| 633 | return LOADER_HANDLED_ERROR; |
| 634 | |
| 635 | init_ok: |
| 636 | |
| 637 | FCEU_LoadGameSave(&UNIFCart); |
| 638 | strcpy(LoadedRomFName, name); //For the debugger list |
| 639 | GameInterface = UNIFGI; |
| 640 | currCartInfo = &UNIFCart; |
| 641 | return LOADER_OK; |
| 642 | } |
no test coverage detected