# HG changeset patch # User Michael Pavone # Date 1485322006 28800 # Node ID b8ba086b96ed5c1d30199c72bf5e2d5b3fdbb3c8 # Parent 1ad0ec7e39390e463f166654b07707c1a96629e9 Improved parsing of cartridge region header diff -r 1ad0ec7e3939 -r b8ba086b96ed romdb.c --- a/romdb.c Tue Jan 24 20:53:10 2017 -0800 +++ b/romdb.c Tue Jan 24 21:26:46 2017 -0800 @@ -441,18 +441,36 @@ } } -char *region_chars = "UB4JEA"; -uint8_t region_bits[] = {REGION_U, REGION_U, REGION_U, REGION_J, REGION_E, REGION_E}; +char *region_chars = "JUEW"; +uint8_t region_bits[] = {REGION_J, REGION_U, REGION_E, REGION_J|REGION_U|REGION_E}; uint8_t translate_region_char(uint8_t c) -{ +{ for (int i = 0; i < sizeof(region_bits); i++) { if (c == region_chars[i]) { return region_bits[i]; } } - return 0; + uint8_t bin_region = 0; + if (c >= '0' && c <= '9') { + bin_region = c - '0'; + } else if (c >= 'A' && c <= 'F') { + bin_region = c - 'A' + 0xA; + } else if (c >= 'a' && c <= 'f') { + bin_region = c - 'a' + 0xA; + } + uint8_t ret = 0; + if (bin_region & 8) { + ret |= REGION_E; + } + if (bin_region & 4) { + ret |= REGION_U; + } + if (bin_region & 1) { + ret |= REGION_J; + } + return ret; } uint8_t get_header_regions(uint8_t *rom)