comparison romdb.c @ 776:cbf97d335444

Full support for Sega mapper when it comes to data. Code in remapped sections may not work reliably. SSF2 now works.
author Michael Pavone <pavone@retrodev.com>
date Mon, 20 Jul 2015 21:15:34 -0700
parents 22728a57d7f3
children 79b10b421d3c
comparison
equal deleted inserted replaced
775:22728a57d7f3 776:cbf97d335444
271 address &= 0xE; 271 address &= 0xE;
272 address >>= 1; 272 address >>= 1;
273 gen->bank_regs[address] = value; 273 gen->bank_regs[address] = value;
274 if (!address) { 274 if (!address) {
275 if (value & 1) { 275 if (value & 1) {
276 context->mem_pointers[2] = NULL; 276 for (int i = 0; i < 8; i++)
277 {
278 context->mem_pointers[gen->mapper_start_index + i] = NULL;
279 }
277 } else { 280 } else {
278 context->mem_pointers[2] = cart + 0x200000/2; 281 //Used for games that only use the mapper for SRAM
279 } 282 context->mem_pointers[gen->mapper_start_index] = cart + 0x200000/2;
283 //For games that need more than 4MB
284 for (int i = 1; i < 8; i++)
285 {
286 context->mem_pointers[gen->mapper_start_index + i] = cart + 0x40000*gen->bank_regs[i];
287 }
288 }
289 } else {
290 context->mem_pointers[gen->mapper_start_index + address] = cart + 0x40000*value;
280 } 291 }
281 return context; 292 return context;
282 } 293 }
283 294
284 m68k_context * write_bank_reg_b(uint32_t address, m68k_context * context, uint8_t value) 295 m68k_context * write_bank_reg_b(uint32_t address, m68k_context * context, uint8_t value)
285 { 296 {
286 if (address & 1) { 297 if (address & 1) {
287 genesis_context * gen = context->system; 298 write_bank_reg_w(address, context, value);
288 address &= 0xE;
289 address >>= 1;
290 gen->bank_regs[address] = value;
291 if (!address) {
292 if (value & 1) {
293 context->mem_pointers[2] = NULL;
294 } else {
295 context->mem_pointers[2] = cart + 0x200000/2;
296 }
297 }
298 } 299 }
299 return context; 300 return context;
300 } 301 }
301 eeprom_map *find_eeprom_map(uint32_t address, genesis_context *gen) 302 eeprom_map *find_eeprom_map(uint32_t address, genesis_context *gen)
302 { 303 {
524 525
525 info->map[1].start = 0x200000; 526 info->map[1].start = 0x200000;
526 info->map[1].end = 0x400000; 527 info->map[1].end = 0x400000;
527 info->map[1].mask = 0x1FFFFF; 528 info->map[1].mask = 0x1FFFFF;
528 info->map[1].flags = MMAP_READ | MMAP_PTR_IDX | MMAP_FUNC_NULL; 529 info->map[1].flags = MMAP_READ | MMAP_PTR_IDX | MMAP_FUNC_NULL;
529 info->map[1].ptr_index = 2; 530 info->map[1].ptr_index = info->mapper_start_index = 0;
530 info->map[1].read_16 = (read_16_fun)read_sram_w;//these will only be called when mem_pointers[2] == NULL 531 info->map[1].read_16 = (read_16_fun)read_sram_w;//these will only be called when mem_pointers[2] == NULL
531 info->map[1].read_8 = (read_8_fun)read_sram_b; 532 info->map[1].read_8 = (read_8_fun)read_sram_b;
532 info->map[1].write_16 = (write_16_fun)write_sram_area_w;//these will be called all writes to the area 533 info->map[1].write_16 = (write_16_fun)write_sram_area_w;//these will be called all writes to the area
533 info->map[1].write_8 = (write_8_fun)write_sram_area_b; 534 info->map[1].write_8 = (write_8_fun)write_sram_area_b;
534 info->map[1].buffer = cart + 0x200000; 535 info->map[1].buffer = cart + 0x200000;
569 uint8_t *rom; 570 uint8_t *rom;
570 tern_node *root; 571 tern_node *root;
571 uint32_t rom_size; 572 uint32_t rom_size;
572 int index; 573 int index;
573 int num_els; 574 int num_els;
575 uint16_t ptr_index;
574 } map_iter_state; 576 } map_iter_state;
575 577
576 void eeprom_read_fun(char *key, tern_val val, void *data) 578 void eeprom_read_fun(char *key, tern_val val, void *data)
577 { 579 {
578 int bit = atoi(key); 580 int bit = atoi(key);
725 } else if(state->info->save_type == RAM_FLAG_EVEN) { 727 } else if(state->info->save_type == RAM_FLAG_EVEN) {
726 map->flags |= MMAP_ONLY_EVEN; 728 map->flags |= MMAP_ONLY_EVEN;
727 } 729 }
728 map->mask = calc_mask(state->info->save_size, start, end); 730 map->mask = calc_mask(state->info->save_size, start, end);
729 } else if (!strcmp(dtype, "Sega mapper")) { 731 } else if (!strcmp(dtype, "Sega mapper")) {
730 map->buffer = state->rom + offset; 732 state->info->mapper_start_index = state->ptr_index++;
731 //TODO: Calculate this 733 state->info->map_chunks+=7;
732 map->ptr_index = 2; 734 state->info->map = realloc(state->info->map, sizeof(memmap_chunk) * state->info->map_chunks);
733 map->flags = MMAP_READ | MMAP_PTR_IDX | MMAP_FUNC_NULL; 735 memset(state->info->map + state->info->map_chunks - 7, 0, sizeof(memmap_chunk) * 7);
734 map->mask = calc_mask(state->rom_size - offset, start, end); 736 map = state->info->map + state->index;
735 char *save_device = tern_find_path(node, "save\0device\0").ptrval; 737 char *save_device = tern_find_path(node, "save\0device\0").ptrval;
736 if (save_device && !strcmp(save_device, "SRAM")) { 738 if (save_device && !strcmp(save_device, "EEPROM")) {
737 process_sram_def(key, state);
738 map->read_16 = (read_16_fun)read_sram_w;//these will only be called when mem_pointers[2] == NULL
739 map->read_8 = (read_8_fun)read_sram_b;
740 map->write_16 = (write_16_fun)write_sram_area_w;//these will be called all writes to the area
741 map->write_8 = (write_8_fun)write_sram_area_b;
742 } else if (save_device && !strcmp(save_device, "EEPROM")) {
743 process_eeprom_def(key, state); 739 process_eeprom_def(key, state);
744 add_eeprom_map(node, start & map->mask, end & map->mask, state); 740 add_eeprom_map(node, start & map->mask, end & map->mask, state);
745 map->write_16 = write_eeprom_i2c_w; 741 }
746 map->write_8 = write_eeprom_i2c_b; 742 for (int i = 0; i < 7; i++, state->index++, map++)
747 map->read_16 = read_eeprom_i2c_w; 743 {
748 map->read_8 = read_eeprom_i2c_b; 744 map->start = start + i * 0x80000;
749 } 745 map->end = start + (i + 1) * 0x80000;
750 state->info->map_chunks++; 746 map->mask = 0x7FFFF;
751 state->info->map = realloc(state->info->map, sizeof(memmap_chunk) * state->info->map_chunks); 747 map->buffer = state->rom + offset + i * 0x80000;
752 state->index++; 748 map->ptr_index = state->ptr_index++;
753 memset(state->info->map + state->info->map_chunks - 1, 0, sizeof(memmap_chunk)); 749 if (i < 3 || !save_device) {
754 map = state->info->map + state->index; 750 map->flags = MMAP_READ | MMAP_PTR_IDX;
751 } else {
752 map->flags = MMAP_READ | MMAP_PTR_IDX | MMAP_FUNC_NULL;
753 if (!strcmp(save_device, "SRAM")) {
754 process_sram_def(key, state);
755 map->read_16 = (read_16_fun)read_sram_w;//these will only be called when mem_pointers[2] == NULL
756 map->read_8 = (read_8_fun)read_sram_b;
757 map->write_16 = (write_16_fun)write_sram_area_w;//these will be called all writes to the area
758 map->write_8 = (write_8_fun)write_sram_area_b;
759 } else if (!strcmp(save_device, "EEPROM")) {
760 map->write_16 = write_eeprom_i2c_w;
761 map->write_8 = write_eeprom_i2c_b;
762 map->read_16 = read_eeprom_i2c_w;
763 map->read_8 = read_eeprom_i2c_b;
764 }
765 }
766 }
755 map->start = 0xA13000; 767 map->start = 0xA13000;
756 map->end = 0xA13100; 768 map->end = 0xA13100;
757 map->mask = 0xFF; 769 map->mask = 0xFF;
758 map->write_16 = (write_16_fun)write_bank_reg_w; 770 map->write_16 = (write_16_fun)write_bank_reg_w;
759 map->write_8 = (write_8_fun)write_bank_reg_b; 771 map->write_8 = (write_8_fun)write_bank_reg_b;
815 info.save_size = 0; 827 info.save_size = 0;
816 info.map = malloc(sizeof(memmap_chunk) * info.map_chunks); 828 info.map = malloc(sizeof(memmap_chunk) * info.map_chunks);
817 info.eeprom_map = NULL; 829 info.eeprom_map = NULL;
818 info.num_eeprom = 0; 830 info.num_eeprom = 0;
819 memset(info.map, 0, sizeof(memmap_chunk) * info.map_chunks); 831 memset(info.map, 0, sizeof(memmap_chunk) * info.map_chunks);
820 map_iter_state state = {&info, rom, entry, rom_size, 0, info.map_chunks - base_chunks}; 832 map_iter_state state = {&info, rom, entry, rom_size, 0, info.map_chunks - base_chunks, 0};
821 tern_foreach(map, map_iter_fun, &state); 833 tern_foreach(map, map_iter_fun, &state);
822 memcpy(info.map + state.index, base_map, sizeof(memmap_chunk) * base_chunks); 834 memcpy(info.map + state.index, base_map, sizeof(memmap_chunk) * base_chunks);
823 } else { 835 } else {
824 add_memmap_header(&info, rom, rom_size, base_map, base_chunks); 836 add_memmap_header(&info, rom, rom_size, base_map, base_chunks);
825 } 837 }