Mercurial > repos > blastem
comparison romdb.c @ 1195:b8ba086b96ed
Improved parsing of cartridge region header
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 24 Jan 2017 21:26:46 -0800 |
parents | 22e87b739ad6 |
children | 53fc7efdfdab |
comparison
equal
deleted
inserted
replaced
1194:1ad0ec7e3939 | 1195:b8ba086b96ed |
---|---|
439 return ret; | 439 return ret; |
440 } | 440 } |
441 } | 441 } |
442 } | 442 } |
443 | 443 |
444 char *region_chars = "UB4JEA"; | 444 char *region_chars = "JUEW"; |
445 uint8_t region_bits[] = {REGION_U, REGION_U, REGION_U, REGION_J, REGION_E, REGION_E}; | 445 uint8_t region_bits[] = {REGION_J, REGION_U, REGION_E, REGION_J|REGION_U|REGION_E}; |
446 | 446 |
447 uint8_t translate_region_char(uint8_t c) | 447 uint8_t translate_region_char(uint8_t c) |
448 { | 448 { |
449 for (int i = 0; i < sizeof(region_bits); i++) | 449 for (int i = 0; i < sizeof(region_bits); i++) |
450 { | 450 { |
451 if (c == region_chars[i]) { | 451 if (c == region_chars[i]) { |
452 return region_bits[i]; | 452 return region_bits[i]; |
453 } | 453 } |
454 } | 454 } |
455 return 0; | 455 uint8_t bin_region = 0; |
456 if (c >= '0' && c <= '9') { | |
457 bin_region = c - '0'; | |
458 } else if (c >= 'A' && c <= 'F') { | |
459 bin_region = c - 'A' + 0xA; | |
460 } else if (c >= 'a' && c <= 'f') { | |
461 bin_region = c - 'a' + 0xA; | |
462 } | |
463 uint8_t ret = 0; | |
464 if (bin_region & 8) { | |
465 ret |= REGION_E; | |
466 } | |
467 if (bin_region & 4) { | |
468 ret |= REGION_U; | |
469 } | |
470 if (bin_region & 1) { | |
471 ret |= REGION_J; | |
472 } | |
473 return ret; | |
456 } | 474 } |
457 | 475 |
458 uint8_t get_header_regions(uint8_t *rom) | 476 uint8_t get_header_regions(uint8_t *rom) |
459 { | 477 { |
460 uint8_t regions = 0; | 478 uint8_t regions = 0; |