ref: fd724d10e4d518eed59b1c03602e3fe899cc7dce
parent: 07802fffc9afa4fe6579c49fcf6954b517388e01
author: Anthony J. Bentley <[email protected]>
date: Thu Dec 29 15:22:06 EST 2011
Add support for the four‐character game ID.
--- 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 @@
/* 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 @@
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 @@
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 @@
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,11 +265,27 @@
* 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);
while (ftell(rom) < 0x143)
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) {
--- 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 @@
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 @@
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 ,