summaryrefslogtreecommitdiff
path: root/romdb.c
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2016-05-01 16:25:16 -0700
committerMichael Pavone <pavone@retrodev.com>2016-05-01 16:25:16 -0700
commitfff70f259a51d3acf0596e5380a938d55a38fd0f (patch)
tree1a42fc49df9a1b07314b01d0b52d566d9c88dc17 /romdb.c
parent93c128f5e2f6c42934d5fbd7a15417a4b33bd2ca (diff)
Improve parsing of game name from ROM header
Diffstat (limited to 'romdb.c')
-rw-r--r--romdb.c53
1 files changed, 36 insertions, 17 deletions
diff --git a/romdb.c b/romdb.c
index 940b3f7..4018db1 100644
--- a/romdb.c
+++ b/romdb.c
@@ -6,7 +6,9 @@
#include "blastem.h"
#include "menu.h"
-#define TITLE_START 0x150
+#define DOM_TITLE_START 0x120
+#define DOM_TITLE_END 0x150
+#define TITLE_START DOM_TITLE_END
#define TITLE_END (TITLE_START+48)
#define GAME_ID_OFF 0x183
#define GAME_ID_LEN 8
@@ -397,28 +399,45 @@ tern_node *load_rom_db()
char *get_header_name(uint8_t *rom)
{
+ //TODO: Should probably prefer the title field that corresponds to the user's region preference
uint8_t *last = rom + TITLE_END - 1;
uint8_t *src = rom + TITLE_START;
-
- while (last > src && (*last <= 0x20 || *last >= 0x80))
+
+ for (;;)
{
- last--;
- }
- if (last == src) {
- //TODO: Use other name field
- return strdup("UNKNOWN");
- } else {
- last++;
- char *ret = malloc(last - (rom + TITLE_START) + 1);
- uint8_t *dst;
- for (dst = ret; src < last; src++)
+ while (last > src && (*last <= 0x20 || *last >= 0x80))
{
- if (*src >= 0x20 && *src < 0x80) {
- *(dst++) = *src;
+ last--;
+ }
+ if (last == src) {
+ if (src == rom + TITLE_START) {
+ src = rom + DOM_TITLE_START;
+ last = rom + DOM_TITLE_END - 1;
+ } else {
+ return strdup("UNKNOWN");
+ }
+ } else {
+ last++;
+ char *ret = malloc(last - (rom + TITLE_START) + 1);
+ uint8_t *dst;
+ uint8_t last_was_space = 1;
+ for (dst = ret; src < last; src++)
+ {
+ if (*src >= 0x20 && *src < 0x80) {
+ if (*src == ' ') {
+ if (last_was_space) {
+ continue;
+ }
+ last_was_space = 1;
+ } else {
+ last_was_space = 0;
+ }
+ *(dst++) = *src;
+ }
}
+ *dst = 0;
+ return ret;
}
- *dst = 0;
- return ret;
}
}