comparison romdb.c @ 1413:3d7f668dce3d

Sonic 3 & Knuckles lock-on is now 100% functional with working saves
author Michael Pavone <pavone@retrodev.com>
date Thu, 22 Jun 2017 23:40:05 -0700
parents 780fbe0b97be
children d94855080529
comparison
equal deleted inserted replaced
1412:909c72c4e5a1 1413:3d7f668dce3d
492 address >>= 1; 492 address >>= 1;
493 gen->bank_regs[address] = value; 493 gen->bank_regs[address] = value;
494 if (!address) { 494 if (!address) {
495 if (value & 1) { 495 if (value & 1) {
496 //Used for games that only use the mapper for SRAM 496 //Used for games that only use the mapper for SRAM
497 if (context->mem_pointers[gen->mapper_start_index]) {
498 gen->mapper_temp = context->mem_pointers[gen->mapper_start_index];
499 }
497 context->mem_pointers[gen->mapper_start_index] = NULL; 500 context->mem_pointers[gen->mapper_start_index] = NULL;
498 //For games that need more than 4MB 501 //For games that need more than 4MB
499 for (int i = 4; i < 8; i++) 502 for (int i = 4; i < 8; i++)
500 { 503 {
501 context->mem_pointers[gen->mapper_start_index + i] = NULL; 504 context->mem_pointers[gen->mapper_start_index + i] = NULL;
502 } 505 }
503 } else { 506 } else {
504 //Used for games that only use the mapper for SRAM 507 //Used for games that only use the mapper for SRAM
505 context->mem_pointers[gen->mapper_start_index] = gen->cart + 0x200000/2; 508 if (!context->mem_pointers[gen->mapper_start_index]) {
509 context->mem_pointers[gen->mapper_start_index] = gen->mapper_temp;
510 }
506 //For games that need more than 4MB 511 //For games that need more than 4MB
507 for (int i = 4; i < 8; i++) 512 for (int i = 4; i < 8; i++)
508 { 513 {
509 context->mem_pointers[gen->mapper_start_index + i] = gen->cart + 0x40000*gen->bank_regs[i]; 514 context->mem_pointers[gen->mapper_start_index + i] = gen->cart + 0x40000*gen->bank_regs[i];
510 } 515 }
1092 state->info->map_chunks += matching_chunks - 1; 1097 state->info->map_chunks += matching_chunks - 1;
1093 state->info->map = realloc(state->info->map, sizeof(memmap_chunk) * state->info->map_chunks); 1098 state->info->map = realloc(state->info->map, sizeof(memmap_chunk) * state->info->map_chunks);
1094 memset(state->info->map + state->info->map_chunks - (matching_chunks - 1), 0, sizeof(memmap_chunk) * (matching_chunks - 1)); 1099 memset(state->info->map + state->info->map_chunks - (matching_chunks - 1), 0, sizeof(memmap_chunk) * (matching_chunks - 1));
1095 map = state->info->map + state->index; 1100 map = state->info->map + state->index;
1096 } 1101 }
1097 for (int i = 0; i < matching_chunks; i++) 1102 for (int i = 0; i < lock_info.map_chunks; i++)
1098 { 1103 {
1099 if (lock_info.map[i].start >= 0xC00000 || lock_info.map[i].end <= 0x200000) { 1104 if (lock_info.map[i].start >= 0xC00000 || lock_info.map[i].end <= 0x200000) {
1100 continue; 1105 continue;
1101 } 1106 }
1102 *map = lock_info.map[i]; 1107 *map = lock_info.map[i];
1169 map->read_16 = nor_flash_read_w; 1174 map->read_16 = nor_flash_read_w;
1170 map->read_8 = nor_flash_read_b; 1175 map->read_8 = nor_flash_read_b;
1171 map->mask = 0xFFFFFF; 1176 map->mask = 0xFFFFFF;
1172 } else if (!strcmp(dtype, "Sega mapper")) { 1177 } else if (!strcmp(dtype, "Sega mapper")) {
1173 state->info->mapper_start_index = state->ptr_index++; 1178 state->info->mapper_start_index = state->ptr_index++;
1174 state->info->map_chunks+=7; 1179 char *variant = tern_find_ptr_default(node, "variant", "full");
1175 state->info->map = realloc(state->info->map, sizeof(memmap_chunk) * state->info->map_chunks);
1176 memset(state->info->map + state->info->map_chunks - 7, 0, sizeof(memmap_chunk) * 7);
1177 map = state->info->map + state->index;
1178 char *save_device = tern_find_path(node, "save\0device\0", TVAL_PTR).ptrval; 1180 char *save_device = tern_find_path(node, "save\0device\0", TVAL_PTR).ptrval;
1179 if (save_device && !strcmp(save_device, "EEPROM")) { 1181 if (save_device && !strcmp(save_device, "EEPROM")) {
1180 process_eeprom_def(key, state); 1182 process_eeprom_def(key, state);
1181 add_eeprom_map(node, start & map->mask, end & map->mask, state); 1183 add_eeprom_map(node, start & map->mask, end & map->mask, state);
1182 } else if (save_device && !strcmp(save_device, "SRAM")) { 1184 } else if (save_device && !strcmp(save_device, "SRAM")) {
1185 //no save definition in ROM DB entry, but there is an SRAM header 1187 //no save definition in ROM DB entry, but there is an SRAM header
1186 //this support is mostly to handle homebrew that uses the SSF2 product ID 1188 //this support is mostly to handle homebrew that uses the SSF2 product ID
1187 //in an attempt to signal desire for the full Sega/SSF2 mapper, but also uses SRAM unlike SSF2 1189 //in an attempt to signal desire for the full Sega/SSF2 mapper, but also uses SRAM unlike SSF2
1188 read_ram_header(state->info, state->rom); 1190 read_ram_header(state->info, state->rom);
1189 } 1191 }
1190 for (int i = 0; i < 7; i++, state->index++, map++) 1192 if (!strcmp(variant, "save-only")) {
1191 { 1193 state->info->map_chunks+=1;
1192 map->start = start + i * 0x80000; 1194 state->info->map = realloc(state->info->map, sizeof(memmap_chunk) * state->info->map_chunks);
1193 map->end = start + (i + 1) * 0x80000; 1195 memset(state->info->map + state->info->map_chunks - 1, 0, sizeof(memmap_chunk) * 1);
1194 map->mask = 0x7FFFF; 1196 map = state->info->map + state->index;
1195 map->buffer = state->rom + offset + i * 0x80000; 1197 map->start = start;
1196 map->ptr_index = state->ptr_index++; 1198 map->end = end;
1197 if (i < 3) { 1199 offset &= nearest_pow2(state->rom_size) - 1;
1198 map->flags = MMAP_READ | MMAP_PTR_IDX | MMAP_CODE; 1200 map->buffer = state->rom + offset;
1201 map->mask = calc_mask(state->rom_size - offset, start, end);
1202 map->ptr_index = state->info->mapper_start_index;
1203 map->flags = MMAP_READ | MMAP_PTR_IDX | MMAP_CODE | MMAP_FUNC_NULL;
1204 if (save_device && !strcmp(save_device, "EEPROM")) {
1205 map->write_16 = write_eeprom_i2c_w;
1206 map->write_8 = write_eeprom_i2c_b;
1207 map->read_16 = read_eeprom_i2c_w;
1208 map->read_8 = read_eeprom_i2c_b;
1199 } else { 1209 } else {
1200 map->flags = MMAP_READ | MMAP_PTR_IDX | MMAP_CODE | MMAP_FUNC_NULL; 1210 map->read_16 = (read_16_fun)read_sram_w;//these will only be called when mem_pointers[ptr_idx] == NULL
1201 if (save_device && !strcmp(save_device, "EEPROM")) { 1211 map->read_8 = (read_8_fun)read_sram_b;
1202 map->write_16 = write_eeprom_i2c_w; 1212 map->write_16 = (write_16_fun)write_sram_area_w;//these will be called all writes to the area
1203 map->write_8 = write_eeprom_i2c_b; 1213 map->write_8 = (write_8_fun)write_sram_area_b;
1204 map->read_16 = read_eeprom_i2c_w; 1214 }
1205 map->read_8 = read_eeprom_i2c_b; 1215 state->index++;
1216 map++;
1217 } else {
1218 state->info->map_chunks+=7;
1219 state->info->map = realloc(state->info->map, sizeof(memmap_chunk) * state->info->map_chunks);
1220 memset(state->info->map + state->info->map_chunks - 7, 0, sizeof(memmap_chunk) * 7);
1221 map = state->info->map + state->index;
1222 for (int i = 0; i < 7; i++, state->index++, map++)
1223 {
1224 map->start = start + i * 0x80000;
1225 map->end = start + (i + 1) * 0x80000;
1226 map->mask = 0x7FFFF;
1227 map->buffer = state->rom + offset + i * 0x80000;
1228 map->ptr_index = state->ptr_index++;
1229 if (i < 3) {
1230 map->flags = MMAP_READ | MMAP_PTR_IDX | MMAP_CODE;
1206 } else { 1231 } else {
1207 map->read_16 = (read_16_fun)read_sram_w;//these will only be called when mem_pointers[2] == NULL 1232 map->flags = MMAP_READ | MMAP_PTR_IDX | MMAP_CODE | MMAP_FUNC_NULL;
1208 map->read_8 = (read_8_fun)read_sram_b; 1233 if (save_device && !strcmp(save_device, "EEPROM")) {
1209 map->write_16 = (write_16_fun)write_sram_area_w;//these will be called all writes to the area 1234 map->write_16 = write_eeprom_i2c_w;
1210 map->write_8 = (write_8_fun)write_sram_area_b; 1235 map->write_8 = write_eeprom_i2c_b;
1236 map->read_16 = read_eeprom_i2c_w;
1237 map->read_8 = read_eeprom_i2c_b;
1238 } else {
1239 map->read_16 = (read_16_fun)read_sram_w;//these will only be called when mem_pointers[2] == NULL
1240 map->read_8 = (read_8_fun)read_sram_b;
1241 map->write_16 = (write_16_fun)write_sram_area_w;//these will be called all writes to the area
1242 map->write_8 = (write_8_fun)write_sram_area_b;
1243 }
1211 } 1244 }
1212 } 1245 }
1213 } 1246 }
1214 map->start = 0xA13000; 1247 map->start = 0xA13000;
1215 map->end = 0xA13100; 1248 map->end = 0xA13100;