Mercurial > repos > blastem
comparison segacd.c @ 2123:50385ae2617b
Attempt to select an appropriate Sega/Mega CD BIOS file based on region and config
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 10 Mar 2022 22:33:08 -0800 |
parents | bb478feccca2 |
children | 8a67b043ba25 |
comparison
equal
deleted
inserted
replaced
2122:bb478feccca2 | 2123:50385ae2617b |
---|---|
3 #include "cd_graphics.h" | 3 #include "cd_graphics.h" |
4 #include "genesis.h" | 4 #include "genesis.h" |
5 #include "util.h" | 5 #include "util.h" |
6 #include "debug.h" | 6 #include "debug.h" |
7 #include "gdb_remote.h" | 7 #include "gdb_remote.h" |
8 #include "blastem.h" | |
8 | 9 |
9 #define SCD_MCLKS 50000000 | 10 #define SCD_MCLKS 50000000 |
10 #define SCD_PERIPH_RESET_CLKS (SCD_MCLKS / 10) | 11 #define SCD_PERIPH_RESET_CLKS (SCD_MCLKS / 10) |
11 #define TIMER_TICK_CLKS 1536 | 12 #define TIMER_TICK_CLKS 1536 |
12 | 13 |
1266 {0xFF8000, 0xFF8200, 0x0001FF, .read_16 = sub_gate_read16, .write_16 = sub_gate_write16, .read_8 = sub_gate_read8, .write_8 = sub_gate_write8} | 1267 {0xFF8000, 0xFF8200, 0x0001FF, .read_16 = sub_gate_read16, .write_16 = sub_gate_write16, .read_8 = sub_gate_read8, .write_8 = sub_gate_write8} |
1267 }; | 1268 }; |
1268 | 1269 |
1269 segacd_context *cd = calloc(sizeof(segacd_context), 1); | 1270 segacd_context *cd = calloc(sizeof(segacd_context), 1); |
1270 uint32_t firmware_size; | 1271 uint32_t firmware_size; |
1271 cd->rom = (uint16_t *)read_bundled_file("cdbios.bin", &firmware_size); | 1272 uint8_t region = force_region; |
1273 if (!region) { | |
1274 char * def_region = tern_find_path_default(config, "system\0default_region\0", (tern_val){.ptrval = "U"}, TVAL_PTR).ptrval; | |
1275 if (!info->regions || (info->regions & translate_region_char(toupper(*def_region)))) { | |
1276 region = translate_region_char(toupper(*def_region)); | |
1277 } else { | |
1278 region = info->regions; | |
1279 } | |
1280 } | |
1281 const char *key; | |
1282 if (region & REGION_E) { | |
1283 key = "system\0scd_bios_eu\0"; | |
1284 } else if (region & REGION_J) { | |
1285 key = "system\0scd_bios_jp\0"; | |
1286 } else { | |
1287 key = "system\0scd_bios_us\0"; | |
1288 } | |
1289 char *bios_path = tern_find_path_default(config, key, (tern_val){.ptrval = "cdbios.bin"}, TVAL_PTR).ptrval; | |
1290 cd->rom = (uint16_t *)read_bundled_file(bios_path, &firmware_size); | |
1291 if (!cd->rom) { | |
1292 fatal_error("Failed to load Sega CD BIOS from %s\n", bios_path); | |
1293 } | |
1272 uint32_t adjusted_size = nearest_pow2(firmware_size); | 1294 uint32_t adjusted_size = nearest_pow2(firmware_size); |
1273 if (adjusted_size != firmware_size) { | 1295 if (adjusted_size != firmware_size) { |
1274 cd->rom = realloc(cd->rom, adjusted_size); | 1296 cd->rom = realloc(cd->rom, adjusted_size); |
1275 } | 1297 } |
1276 cd->rom_mut = malloc(adjusted_size); | 1298 cd->rom_mut = malloc(adjusted_size); |