diff --git a/src/fix/main.c b/src/fix/main.c index a7053a17..ea7ca478 100644 --- a/src/fix/main.c +++ b/src/fix/main.c @@ -24,9 +24,10 @@ static void usage(void) { - printf("usage: rgbfix [-Ccjsv] [-k licensee_str] [-l licensee_id] " - "[-m mbc_type]\n" " [-n rom_version] [-p pad_value] " - "[-r ram_size] [-t title_str] file.gb\n"); + printf("usage: rgbfix [-Ccjsv] [-i game_id] [-k licensee_str] " + "[-l licensee_id]\n" " [-m mbc_type] [-n rom_version] " + "[-p pad_value] [-r ram_size]\n" + " [-t title_str] file.gb\n"); } int @@ -56,6 +57,7 @@ main(int argc, char *argv[]) /* all flags default to false unless options specify otherwise */ bool validate = false; bool settitle = false; + bool setid = false; bool colorcompatible = false; bool coloronly = false; bool nonjapan = false; @@ -68,6 +70,7 @@ main(int argc, char *argv[]) bool setversion = false; char *title = NULL; /* game title in ASCII */ + char *id = NULL; /* game ID in ASCII */ char *newlicensee = NULL; /* new licensee ID, two ASCII characters */ int licensee = -1; /* old licensee ID */ @@ -76,7 +79,7 @@ main(int argc, char *argv[]) int version = -1; /* mask ROM version number */ int padvalue = -1; /* to pad the rom with if it changes size */ - while ((ch = getopt(argc, argv, "Ccjk:l:m:n:p:sr:t:v")) != -1) { + while ((ch = getopt(argc, argv, "Cci:jk:l:m:n:p:sr:t:v")) != -1) { switch (ch) { case 'C': coloronly = true; @@ -84,6 +87,17 @@ main(int argc, char *argv[]) case 'c': colorcompatible = true; break; + case 'i': + setid = true; + + if (strlen(optarg) != 4) { + fprintf(stderr, "Game ID %s must be exactly 4 " + "characters\n", optarg); + exit(1); + } + + id = optarg; + break; case 'j': nonjapan = true; break; @@ -251,6 +265,11 @@ main(int argc, char *argv[]) * may conflict. */ + /* + * See also: Game ID at 0x13F–0x142. These four ASCII + * characters may conflict with the title. + */ + fseek(rom, 0x134, SEEK_SET); fwrite(title, 1, strlen(title) + 1, rom); @@ -258,6 +277,17 @@ main(int argc, char *argv[]) fputc(0, rom); } + if (setid) { + /* + * Offset 0x13F–0x142: Game ID + * This is a four-character game ID in ASCII (no high-bit + * characters). + */ + + fseek(rom,0x13F,SEEK_SET); + fwrite(id, 1, 4, rom); + } + if (colorcompatible) { /* * Offset 0x143: Game Boy Color Flag diff --git a/src/fix/rgbfix.1 b/src/fix/rgbfix.1 index 2fe222f8..0a9e6793 100644 --- a/src/fix/rgbfix.1 +++ b/src/fix/rgbfix.1 @@ -7,6 +7,7 @@ .Sh SYNOPSIS .Nm rgbfix .Op Fl Ccjsv +.Op Fl i Ar game_id .Op Fl k Ar licensee_str .Op Fl l Ar licensee_id .Op Fl m Ar mbc_type @@ -38,6 +39,12 @@ If both this and the flag are set, .Fl C takes precedence. +.It Fl i Ar game_id +Set the game ID string +.Pq Ad 0x13F No Ns \(en Ns Ad 0x142 +to a given string of exactly 4 characters. +If both this and the title are set, the game ID will overwrite the +overlapping portion of the title. .It Fl j Set the non-Japanese region flag: .Ad 0x14A @@ -82,6 +89,8 @@ to a given string, truncated to at most 16 characters. It is recommended to use 15 characters instead, to avoid clashing with the CGB flag .Pq Fl c No or Fl C . +If both this and the game ID are set, the game ID will overwrite the +overlapping portion of the title. .It Fl v Validate the header and fix checksums: the Nintendo character area .Pq Ad 0x104 No Ns \(en Ns Ad 0x133 ,