comparison romdb.c @ 1006:9ab35686a025

Improve parsing of game name from ROM header
author Michael Pavone <pavone@retrodev.com>
date Sun, 01 May 2016 16:25:16 -0700
parents 4c17c7f46331
children 5fb64487b6e1
comparison
equal deleted inserted replaced
1005:580a806aef6a 1006:9ab35686a025
4 #include "romdb.h" 4 #include "romdb.h"
5 #include "util.h" 5 #include "util.h"
6 #include "blastem.h" 6 #include "blastem.h"
7 #include "menu.h" 7 #include "menu.h"
8 8
9 #define TITLE_START 0x150 9 #define DOM_TITLE_START 0x120
10 #define DOM_TITLE_END 0x150
11 #define TITLE_START DOM_TITLE_END
10 #define TITLE_END (TITLE_START+48) 12 #define TITLE_END (TITLE_START+48)
11 #define GAME_ID_OFF 0x183 13 #define GAME_ID_OFF 0x183
12 #define GAME_ID_LEN 8 14 #define GAME_ID_LEN 8
13 #define ROM_END 0x1A4 15 #define ROM_END 0x1A4
14 #define RAM_ID 0x1B0 16 #define RAM_ID 0x1B0
395 return db; 397 return db;
396 } 398 }
397 399
398 char *get_header_name(uint8_t *rom) 400 char *get_header_name(uint8_t *rom)
399 { 401 {
402 //TODO: Should probably prefer the title field that corresponds to the user's region preference
400 uint8_t *last = rom + TITLE_END - 1; 403 uint8_t *last = rom + TITLE_END - 1;
401 uint8_t *src = rom + TITLE_START; 404 uint8_t *src = rom + TITLE_START;
402 405
403 while (last > src && (*last <= 0x20 || *last >= 0x80)) 406 for (;;)
404 { 407 {
405 last--; 408 while (last > src && (*last <= 0x20 || *last >= 0x80))
406 }
407 if (last == src) {
408 //TODO: Use other name field
409 return strdup("UNKNOWN");
410 } else {
411 last++;
412 char *ret = malloc(last - (rom + TITLE_START) + 1);
413 uint8_t *dst;
414 for (dst = ret; src < last; src++)
415 { 409 {
416 if (*src >= 0x20 && *src < 0x80) { 410 last--;
417 *(dst++) = *src; 411 }
418 } 412 if (last == src) {
419 } 413 if (src == rom + TITLE_START) {
420 *dst = 0; 414 src = rom + DOM_TITLE_START;
421 return ret; 415 last = rom + DOM_TITLE_END - 1;
416 } else {
417 return strdup("UNKNOWN");
418 }
419 } else {
420 last++;
421 char *ret = malloc(last - (rom + TITLE_START) + 1);
422 uint8_t *dst;
423 uint8_t last_was_space = 1;
424 for (dst = ret; src < last; src++)
425 {
426 if (*src >= 0x20 && *src < 0x80) {
427 if (*src == ' ') {
428 if (last_was_space) {
429 continue;
430 }
431 last_was_space = 1;
432 } else {
433 last_was_space = 0;
434 }
435 *(dst++) = *src;
436 }
437 }
438 *dst = 0;
439 return ret;
440 }
422 } 441 }
423 } 442 }
424 443
425 char *region_chars = "UB4JEA"; 444 char *region_chars = "UB4JEA";
426 uint8_t region_bits[] = {REGION_U, REGION_U, REGION_U, REGION_J, REGION_E, REGION_E}; 445 uint8_t region_bits[] = {REGION_U, REGION_U, REGION_U, REGION_J, REGION_E, REGION_E};