comparison romdb.c @ 866:69a6ec208111

Menu ROM now pulls real file names from the OS rather than using a fake list
author Michael Pavone <pavone@retrodev.com>
date Fri, 06 Nov 2015 12:19:39 -0800
parents 46bb673eed4e
children 54ffba3768d6
comparison
equal deleted inserted replaced
865:305c85c0b954 866:69a6ec208111
2 #include <string.h> 2 #include <string.h>
3 #include "config.h" 3 #include "config.h"
4 #include "romdb.h" 4 #include "romdb.h"
5 #include "util.h" 5 #include "util.h"
6 #include "blastem.h" 6 #include "blastem.h"
7 #include "menu.h"
7 8
8 #define TITLE_START 0x150 9 #define TITLE_START 0x150
9 #define TITLE_END (TITLE_START+48) 10 #define TITLE_END (TITLE_START+48)
10 #define GAME_ID_OFF 0x183 11 #define GAME_ID_OFF 0x183
11 #define GAME_ID_LEN 8 12 #define GAME_ID_LEN 8
333 genesis_context *gen = ((m68k_context *)context)->system; 334 genesis_context *gen = ((m68k_context *)context)->system;
334 eeprom_map *map = find_eeprom_map(address, gen); 335 eeprom_map *map = find_eeprom_map(address, gen);
335 if (!map) { 336 if (!map) {
336 fatal_error("Could not find EEPROM map for address %X\n", address); 337 fatal_error("Could not find EEPROM map for address %X\n", address);
337 } 338 }
338 339
339 uint16_t expanded, mask; 340 uint16_t expanded, mask;
340 if (address & 1) { 341 if (address & 1) {
341 expanded = value; 342 expanded = value;
342 mask = 0xFF; 343 mask = 0xFF;
343 } else { 344 } else {
403 404
404 char *get_header_name(uint8_t *rom) 405 char *get_header_name(uint8_t *rom)
405 { 406 {
406 uint8_t *last = rom + TITLE_END - 1; 407 uint8_t *last = rom + TITLE_END - 1;
407 uint8_t *src = rom + TITLE_START; 408 uint8_t *src = rom + TITLE_START;
408 409
409 while (last > src && (*last <= 0x20 || *last >= 0x80)) 410 while (last > src && (*last <= 0x20 || *last >= 0x80))
410 { 411 {
411 last--; 412 last--;
412 } 413 }
413 if (last == src) { 414 if (last == src) {
488 if (ram_flags != RAM_FLAG_BOTH) { 489 if (ram_flags != RAM_FLAG_BOTH) {
489 save_size /= 2; 490 save_size /= 2;
490 } 491 }
491 info->save_size = save_size; 492 info->save_size = save_size;
492 info->save_buffer = malloc(save_size); 493 info->save_buffer = malloc(save_size);
493 494
494 info->map_chunks = base_chunks + (ram_start >= rom_end ? 2 : 3); 495 info->map_chunks = base_chunks + (ram_start >= rom_end ? 2 : 3);
495 info->map = malloc(sizeof(memmap_chunk) * info->map_chunks); 496 info->map = malloc(sizeof(memmap_chunk) * info->map_chunks);
496 memset(info->map, 0, sizeof(memmap_chunk)*2); 497 memset(info->map, 0, sizeof(memmap_chunk)*2);
497 memcpy(info->map+2, base_map, sizeof(memmap_chunk) * base_chunks); 498 memcpy(info->map+2, base_map, sizeof(memmap_chunk) * base_chunks);
498 499
499 if (ram_start >= rom_end) { 500 if (ram_start >= rom_end) {
500 info->map[0].end = rom_end < 0x400000 ? nearest_pow2(rom_end) - 1 : 0xFFFFFF; 501 info->map[0].end = rom_end < 0x400000 ? nearest_pow2(rom_end) - 1 : 0xFFFFFF;
501 //TODO: ROM mirroring 502 //TODO: ROM mirroring
502 info->map[0].mask = 0xFFFFFF; 503 info->map[0].mask = 0xFFFFFF;
503 info->map[0].flags = MMAP_READ; 504 info->map[0].flags = MMAP_READ;
504 info->map[0].buffer = rom; 505 info->map[0].buffer = rom;
505 506
506 info->map[1].start = ram_start; 507 info->map[1].start = ram_start;
507 info->map[1].mask = info->save_mask; 508 info->map[1].mask = info->save_mask;
508 info->map[1].end = ram_end + 1; 509 info->map[1].end = ram_end + 1;
509 info->map[1].flags = MMAP_READ | MMAP_WRITE; 510 info->map[1].flags = MMAP_READ | MMAP_WRITE;
510 511
511 if (ram_flags == RAM_FLAG_ODD) { 512 if (ram_flags == RAM_FLAG_ODD) {
512 info->map[1].flags |= MMAP_ONLY_ODD; 513 info->map[1].flags |= MMAP_ONLY_ODD;
513 } else if (ram_flags == RAM_FLAG_EVEN) { 514 } else if (ram_flags == RAM_FLAG_EVEN) {
514 info->map[1].flags |= MMAP_ONLY_EVEN; 515 info->map[1].flags |= MMAP_ONLY_EVEN;
515 } 516 }
518 //Assume the standard Sega mapper 519 //Assume the standard Sega mapper
519 info->map[0].end = 0x200000; 520 info->map[0].end = 0x200000;
520 info->map[0].mask = 0xFFFFFF; 521 info->map[0].mask = 0xFFFFFF;
521 info->map[0].flags = MMAP_READ; 522 info->map[0].flags = MMAP_READ;
522 info->map[0].buffer = rom; 523 info->map[0].buffer = rom;
523 524
524 info->map[1].start = 0x200000; 525 info->map[1].start = 0x200000;
525 info->map[1].end = 0x400000; 526 info->map[1].end = 0x400000;
526 info->map[1].mask = 0x1FFFFF; 527 info->map[1].mask = 0x1FFFFF;
527 info->map[1].flags = MMAP_READ | MMAP_PTR_IDX | MMAP_FUNC_NULL; 528 info->map[1].flags = MMAP_READ | MMAP_PTR_IDX | MMAP_FUNC_NULL;
528 info->map[1].ptr_index = info->mapper_start_index = 0; 529 info->map[1].ptr_index = info->mapper_start_index = 0;
529 info->map[1].read_16 = (read_16_fun)read_sram_w;//these will only be called when mem_pointers[2] == NULL 530 info->map[1].read_16 = (read_16_fun)read_sram_w;//these will only be called when mem_pointers[2] == NULL
530 info->map[1].read_8 = (read_8_fun)read_sram_b; 531 info->map[1].read_8 = (read_8_fun)read_sram_b;
531 info->map[1].write_16 = (write_16_fun)write_sram_area_w;//these will be called all writes to the area 532 info->map[1].write_16 = (write_16_fun)write_sram_area_w;//these will be called all writes to the area
532 info->map[1].write_8 = (write_8_fun)write_sram_area_b; 533 info->map[1].write_8 = (write_8_fun)write_sram_area_b;
533 info->map[1].buffer = cart + 0x200000; 534 info->map[1].buffer = cart + 0x200000;
534 535
535 memmap_chunk *last = info->map + info->map_chunks - 1; 536 memmap_chunk *last = info->map + info->map_chunks - 1;
536 memset(last, 0, sizeof(memmap_chunk)); 537 memset(last, 0, sizeof(memmap_chunk));
537 last->start = 0xA13000; 538 last->start = 0xA13000;
538 last->end = 0xA13100; 539 last->end = 0xA13100;
539 last->mask = 0xFF; 540 last->mask = 0xFF;
543 } else { 544 } else {
544 info->map_chunks = base_chunks + 1; 545 info->map_chunks = base_chunks + 1;
545 info->map = malloc(sizeof(memmap_chunk) * info->map_chunks); 546 info->map = malloc(sizeof(memmap_chunk) * info->map_chunks);
546 memset(info->map, 0, sizeof(memmap_chunk)); 547 memset(info->map, 0, sizeof(memmap_chunk));
547 memcpy(info->map+1, base_map, sizeof(memmap_chunk) * base_chunks); 548 memcpy(info->map+1, base_map, sizeof(memmap_chunk) * base_chunks);
548 549
549 info->map[0].end = rom_end > 0x400000 ? rom_end : 0x400000; 550 info->map[0].end = rom_end > 0x400000 ? rom_end : 0x400000;
550 info->map[0].mask = rom_end < 0x400000 ? nearest_pow2(rom_end) - 1 : 0xFFFFFF; 551 info->map[0].mask = rom_end < 0x400000 ? nearest_pow2(rom_end) - 1 : 0xFFFFFF;
551 info->map[0].flags = MMAP_READ; 552 info->map[0].flags = MMAP_READ;
552 info->map[0].buffer = rom; 553 info->map[0].buffer = rom;
553 info->save_type = SAVE_NONE; 554 info->save_type = SAVE_NONE;
701 map->flags = MMAP_READ; 702 map->flags = MMAP_READ;
702 map->mask = calc_mask(state->rom_size - offset, start, end); 703 map->mask = calc_mask(state->rom_size - offset, start, end);
703 } else if (!strcmp(dtype, "EEPROM")) { 704 } else if (!strcmp(dtype, "EEPROM")) {
704 process_eeprom_def(key, state); 705 process_eeprom_def(key, state);
705 add_eeprom_map(node, start, end, state); 706 add_eeprom_map(node, start, end, state);
706 707
707 map->write_16 = write_eeprom_i2c_w; 708 map->write_16 = write_eeprom_i2c_w;
708 map->write_8 = write_eeprom_i2c_b; 709 map->write_8 = write_eeprom_i2c_b;
709 map->read_16 = read_eeprom_i2c_w; 710 map->read_16 = read_eeprom_i2c_w;
710 map->read_8 = read_eeprom_i2c_b; 711 map->read_8 = read_eeprom_i2c_b;
711 map->mask = 0xFFFFFF; 712 map->mask = 0xFFFFFF;
717 map->flags |= MMAP_ONLY_ODD; 718 map->flags |= MMAP_ONLY_ODD;
718 } else if(state->info->save_type == RAM_FLAG_EVEN) { 719 } else if(state->info->save_type == RAM_FLAG_EVEN) {
719 map->flags |= MMAP_ONLY_EVEN; 720 map->flags |= MMAP_ONLY_EVEN;
720 } 721 }
721 map->mask = calc_mask(state->info->save_size, start, end); 722 map->mask = calc_mask(state->info->save_size, start, end);
723 } else if (!strcmp(dtype, "RAM")) {
724 uint32_t size = strtol(tern_find_ptr_default(node, "size", "0"), NULL, 16);
725 if (!size || size > map->end - map->start) {
726 size = map->end - map->start;
727 }
728 map->buffer = malloc(size);
729 map->mask = calc_mask(size, start, end);
730 map->flags = MMAP_READ | MMAP_WRITE;
731 char *bus = tern_find_ptr_default(node, "bus", "both");
732 if (!strcmp(dtype, "odd")) {
733 map->flags |= MMAP_ONLY_ODD;
734 } else if (!strcmp(dtype, "even")) {
735 map->flags |= MMAP_ONLY_EVEN;
736 } else {
737 map->flags |= MMAP_CODE;
738 }
722 } else if (!strcmp(dtype, "Sega mapper")) { 739 } else if (!strcmp(dtype, "Sega mapper")) {
723 state->info->mapper_start_index = state->ptr_index++; 740 state->info->mapper_start_index = state->ptr_index++;
724 state->info->map_chunks+=7; 741 state->info->map_chunks+=7;
725 state->info->map = realloc(state->info->map, sizeof(memmap_chunk) * state->info->map_chunks); 742 state->info->map = realloc(state->info->map, sizeof(memmap_chunk) * state->info->map_chunks);
726 memset(state->info->map + state->info->map_chunks - 7, 0, sizeof(memmap_chunk) * 7); 743 memset(state->info->map + state->info->map_chunks - 7, 0, sizeof(memmap_chunk) * 7);
758 map->start = 0xA13000; 775 map->start = 0xA13000;
759 map->end = 0xA13100; 776 map->end = 0xA13100;
760 map->mask = 0xFF; 777 map->mask = 0xFF;
761 map->write_16 = (write_16_fun)write_bank_reg_w; 778 map->write_16 = (write_16_fun)write_bank_reg_w;
762 map->write_8 = (write_8_fun)write_bank_reg_b; 779 map->write_8 = (write_8_fun)write_bank_reg_b;
780 } else if (!strcmp(dtype, "MENU")) {
781 //fake hardware for supporting menu
782 map->buffer = NULL;
783 map->mask = 0xFF;
784 map->write_16 = menu_write_w;
785 map->read_16 = menu_read_w;
763 } else { 786 } else {
764 fatal_error("Invalid device type for ROM DB map entry %d with address %s\n", state->index, key); 787 fatal_error("Invalid device type for ROM DB map entry %d with address %s\n", state->index, key);
765 } 788 }
766 state->index++; 789 state->index++;
767 } 790 }
776 if (rom[GAME_ID_OFF + i] <= ' ') { 799 if (rom[GAME_ID_OFF + i] <= ' ') {
777 product_id[i] = 0; 800 product_id[i] = 0;
778 break; 801 break;
779 } 802 }
780 product_id[i] = rom[GAME_ID_OFF + i]; 803 product_id[i] = rom[GAME_ID_OFF + i];
781 804
782 } 805 }
783 printf("Product ID: %s\n", product_id); 806 printf("Product ID: %s\n", product_id);
784 tern_node * entry = tern_find_ptr(rom_db, product_id); 807 tern_node * entry = tern_find_ptr(rom_db, product_id);
785 if (!entry) { 808 if (!entry) {
786 puts("Not found in ROM DB, examining header\n"); 809 puts("Not found in ROM DB, examining header\n");
792 printf("Found name: %s\n", info.name); 815 printf("Found name: %s\n", info.name);
793 info.name = strdup(info.name); 816 info.name = strdup(info.name);
794 } else { 817 } else {
795 info.name = get_header_name(rom); 818 info.name = get_header_name(rom);
796 } 819 }
797 820
798 char *dbreg = tern_find_ptr(entry, "regions"); 821 char *dbreg = tern_find_ptr(entry, "regions");
799 info.regions = 0; 822 info.regions = 0;
800 if (dbreg) { 823 if (dbreg) {
801 while (*dbreg != 0) 824 while (*dbreg != 0)
802 { 825 {
804 } 827 }
805 } 828 }
806 if (!info.regions) { 829 if (!info.regions) {
807 info.regions = get_header_regions(rom); 830 info.regions = get_header_regions(rom);
808 } 831 }
809 832
810 tern_node *map = tern_find_ptr(entry, "map"); 833 tern_node *map = tern_find_ptr(entry, "map");
811 if (map) { 834 if (map) {
812 info.save_type = SAVE_NONE; 835 info.save_type = SAVE_NONE;
813 info.map_chunks = tern_count(map); 836 info.map_chunks = tern_count(map);
814 if (info.map_chunks) { 837 if (info.map_chunks) {
826 add_memmap_header(&info, rom, rom_size, base_map, base_chunks); 849 add_memmap_header(&info, rom, rom_size, base_map, base_chunks);
827 } 850 }
828 } else { 851 } else {
829 add_memmap_header(&info, rom, rom_size, base_map, base_chunks); 852 add_memmap_header(&info, rom, rom_size, base_map, base_chunks);
830 } 853 }
831 854
832 return info; 855 return info;
833 } 856 }