mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Updated RGBFIX to report when non-zero bytes are overwritten
Also updated many .err files with the new warning.
This commit is contained in:
@@ -653,6 +653,22 @@ static ssize_t writeBytes(int fd, void *buf, size_t len)
|
|||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param rom0 A pointer to rom0
|
||||||
|
* @param startAddr What address to begin checking from
|
||||||
|
* @param size How many bytes to check
|
||||||
|
* @param areaName Name to be displayed in the warning message
|
||||||
|
*/
|
||||||
|
static void warnNonZero(uint8_t *rom0, uint16_t startAddr, uint8_t size, char const *areaName)
|
||||||
|
{
|
||||||
|
for (uint8_t i = 0; i < size; i++) {
|
||||||
|
if (rom0[i + startAddr] != 0) {
|
||||||
|
fprintf(stderr, "warning: Overwrote a non-zero byte in the %s\n", areaName);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param input File descriptor to be used for reading
|
* @param input File descriptor to be used for reading
|
||||||
* @param output File descriptor to be used for writing, may be equal to `input`
|
* @param output File descriptor to be used for writing, may be equal to `input`
|
||||||
@@ -681,6 +697,7 @@ static void processFile(int input, int output, char const *name, off_t fileSize)
|
|||||||
// Accept partial reads if the file contains at least the header
|
// Accept partial reads if the file contains at least the header
|
||||||
|
|
||||||
if (fixSpec & (FIX_LOGO | TRASH_LOGO)) {
|
if (fixSpec & (FIX_LOGO | TRASH_LOGO)) {
|
||||||
|
warnNonZero(rom0, 0x0104, sizeof(ninLogo), "Nintendo logo");
|
||||||
if (fixSpec & FIX_LOGO) {
|
if (fixSpec & FIX_LOGO) {
|
||||||
memcpy(&rom0[0x104], ninLogo, sizeof(ninLogo));
|
memcpy(&rom0[0x104], ninLogo, sizeof(ninLogo));
|
||||||
} else {
|
} else {
|
||||||
@@ -689,36 +706,56 @@ static void processFile(int input, int output, char const *name, off_t fileSize)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (title)
|
if (title) {
|
||||||
|
warnNonZero(rom0, 0x134, titleLen, "title");
|
||||||
memcpy(&rom0[0x134], title, titleLen);
|
memcpy(&rom0[0x134], title, titleLen);
|
||||||
|
}
|
||||||
|
|
||||||
if (gameID)
|
if (gameID) {
|
||||||
|
warnNonZero(rom0, 0x13f, gameIDLen, "manufacturer code");
|
||||||
memcpy(&rom0[0x13f], gameID, gameIDLen);
|
memcpy(&rom0[0x13f], gameID, gameIDLen);
|
||||||
|
}
|
||||||
|
|
||||||
if (model != DMG)
|
if (model != DMG) {
|
||||||
|
warnNonZero(rom0, 0x143, 1, "CGB flag");
|
||||||
rom0[0x143] = model == BOTH ? 0x80 : 0xc0;
|
rom0[0x143] = model == BOTH ? 0x80 : 0xc0;
|
||||||
|
}
|
||||||
|
|
||||||
if (newLicensee)
|
if (newLicensee) {
|
||||||
|
warnNonZero(rom0, 0x144, newLicenseeLen, "new licensee code");
|
||||||
memcpy(&rom0[0x144], newLicensee, newLicenseeLen);
|
memcpy(&rom0[0x144], newLicensee, newLicenseeLen);
|
||||||
|
}
|
||||||
|
|
||||||
if (sgb)
|
if (sgb) {
|
||||||
|
warnNonZero(rom0, 0x146, 1, "SGB flag");
|
||||||
rom0[0x146] = 0x03;
|
rom0[0x146] = 0x03;
|
||||||
|
}
|
||||||
|
|
||||||
// If a valid MBC was specified...
|
// If a valid MBC was specified...
|
||||||
if (cartridgeType < MBC_NONE)
|
if (cartridgeType < MBC_NONE) {
|
||||||
|
warnNonZero(rom0, 0x147, 1, "cartridge type");
|
||||||
rom0[0x147] = cartridgeType;
|
rom0[0x147] = cartridgeType;
|
||||||
|
}
|
||||||
|
|
||||||
if (ramSize != UNSPECIFIED)
|
if (ramSize != UNSPECIFIED) {
|
||||||
|
warnNonZero(rom0, 0x149, 1, "RAM size");
|
||||||
rom0[0x149] = ramSize;
|
rom0[0x149] = ramSize;
|
||||||
|
}
|
||||||
|
|
||||||
if (!japanese)
|
if (!japanese) {
|
||||||
|
warnNonZero(rom0, 0x14a, 1, "destination code");
|
||||||
rom0[0x14a] = 0x01;
|
rom0[0x14a] = 0x01;
|
||||||
|
}
|
||||||
|
|
||||||
if (oldLicensee != UNSPECIFIED)
|
if (oldLicensee != UNSPECIFIED) {
|
||||||
|
warnNonZero(rom0, 0x14b, 1, "old licensee code");
|
||||||
rom0[0x14b] = oldLicensee;
|
rom0[0x14b] = oldLicensee;
|
||||||
|
}
|
||||||
|
|
||||||
if (romVersion != UNSPECIFIED)
|
if (romVersion != UNSPECIFIED) {
|
||||||
|
warnNonZero(rom0, 0x14c, 1, "mask ROM version number");
|
||||||
rom0[0x14c] = romVersion;
|
rom0[0x14c] = romVersion;
|
||||||
|
}
|
||||||
|
|
||||||
// Remain to be handled the ROM size, and header checksum.
|
// Remain to be handled the ROM size, and header checksum.
|
||||||
// The latter depends on the former, and so will be handled after it.
|
// The latter depends on the former, and so will be handled after it.
|
||||||
@@ -818,6 +855,7 @@ static void processFile(int input, int output, char const *name, off_t fileSize)
|
|||||||
|
|
||||||
for (uint16_t i = 0x134; i < 0x14d; i++)
|
for (uint16_t i = 0x134; i < 0x14d; i++)
|
||||||
sum -= rom0[i] + 1;
|
sum -= rom0[i] + 1;
|
||||||
|
warnNonZero(rom0, 0x14d, 1, "header checksum");
|
||||||
rom0[0x14d] = fixSpec & TRASH_HEADER_SUM ? ~sum : sum;
|
rom0[0x14d] = fixSpec & TRASH_HEADER_SUM ? ~sum : sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -841,6 +879,7 @@ static void processFile(int input, int output, char const *name, off_t fileSize)
|
|||||||
|
|
||||||
if (fixSpec & TRASH_GLOBAL_SUM)
|
if (fixSpec & TRASH_GLOBAL_SUM)
|
||||||
globalSum = ~globalSum;
|
globalSum = ~globalSum;
|
||||||
|
warnNonZero(rom0, 0x14e, 2, "global checksum");
|
||||||
rom0[0x14e] = globalSum >> 8;
|
rom0[0x14e] = globalSum >> 8;
|
||||||
rom0[0x14f] = globalSum & 0xff;
|
rom0[0x14f] = globalSum & 0xff;
|
||||||
}
|
}
|
||||||
@@ -915,8 +954,6 @@ free_romx:
|
|||||||
free(romx);
|
free(romx);
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef trySeek
|
|
||||||
|
|
||||||
static bool processFilename(char const *name)
|
static bool processFilename(char const *name)
|
||||||
{
|
{
|
||||||
nbErrors = 0;
|
nbErrors = 0;
|
||||||
@@ -1015,7 +1052,7 @@ do { \
|
|||||||
#define SPEC_H TRASH_HEADER_SUM
|
#define SPEC_H TRASH_HEADER_SUM
|
||||||
#define SPEC_g FIX_GLOBAL_SUM
|
#define SPEC_g FIX_GLOBAL_SUM
|
||||||
#define SPEC_G TRASH_GLOBAL_SUM
|
#define SPEC_G TRASH_GLOBAL_SUM
|
||||||
#define or(new, bad) \
|
#define overrideSpec(new, bad) \
|
||||||
do { \
|
do { \
|
||||||
if (fixSpec & SPEC_##bad) \
|
if (fixSpec & SPEC_##bad) \
|
||||||
fprintf(stderr, \
|
fprintf(stderr, \
|
||||||
@@ -1023,30 +1060,30 @@ do { \
|
|||||||
fixSpec = (fixSpec & ~SPEC_##bad) | SPEC_##new; \
|
fixSpec = (fixSpec & ~SPEC_##bad) | SPEC_##new; \
|
||||||
} while (0)
|
} while (0)
|
||||||
case 'l':
|
case 'l':
|
||||||
or(l, L);
|
overrideSpec(l, L);
|
||||||
break;
|
break;
|
||||||
case 'L':
|
case 'L':
|
||||||
or(L, l);
|
overrideSpec(L, l);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'h':
|
case 'h':
|
||||||
or(h, H);
|
overrideSpec(h, H);
|
||||||
break;
|
break;
|
||||||
case 'H':
|
case 'H':
|
||||||
or(H, h);
|
overrideSpec(H, h);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'g':
|
case 'g':
|
||||||
or(g, G);
|
overrideSpec(g, G);
|
||||||
break;
|
break;
|
||||||
case 'G':
|
case 'G':
|
||||||
or(G, g);
|
overrideSpec(G, g);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "warning: Ignoring '%c' in fix spec\n",
|
fprintf(stderr, "warning: Ignoring '%c' in fix spec\n",
|
||||||
*musl_optarg);
|
*musl_optarg);
|
||||||
#undef or
|
#undef overrideSpec
|
||||||
}
|
}
|
||||||
musl_optarg++;
|
musl_optarg++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
warning: Ignoring 'm' in fix spec
|
warning: Ignoring 'm' in fix spec
|
||||||
warning: Ignoring 'a' in fix spec
|
warning: Ignoring 'a' in fix spec
|
||||||
warning: Ignoring 'o' in fix spec
|
warning: Ignoring 'o' in fix spec
|
||||||
|
warning: Overwrote a non-zero byte in the Nintendo logo
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
warning: Overwrote a non-zero byte in the CGB flag
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
warning: Overwrote a non-zero byte in the CGB flag
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
warning: 'l' overriding 'L' in fix spec
|
warning: 'l' overriding 'L' in fix spec
|
||||||
|
warning: Overwrote a non-zero byte in the Nintendo logo
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
warning: Truncating game ID "FOUR!" to 4 chars
|
warning: Truncating game ID "FOUR!" to 4 chars
|
||||||
|
warning: Overwrote a non-zero byte in the manufacturer code
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
warning: Overwrote a non-zero byte in the manufacturer code
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
warning: Overwrote a non-zero byte in the CGB flag
|
||||||
|
warning: Overwrote a non-zero byte in the header checksum
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
warning: Overwrote a non-zero byte in the header checksum
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
warning: Overwrote a non-zero byte in the header checksum
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
warning: Overwrote a non-zero byte in the destination code
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
warning: Overwrote a non-zero byte in the Nintendo logo
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
warning: Overwrote a non-zero byte in the Nintendo logo
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
warning: Overwrote a non-zero byte in the cartridge type
|
||||||
|
|||||||
@@ -1 +1,3 @@
|
|||||||
warning: MBC "ROM" has no RAM, but RAM size was set to 2
|
warning: MBC "ROM" has no RAM, but RAM size was set to 2
|
||||||
|
warning: Overwrote a non-zero byte in the cartridge type
|
||||||
|
warning: Overwrote a non-zero byte in the RAM size
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
warning: Truncating new licensee "HOMEBREW" to 2 chars
|
warning: Truncating new licensee "HOMEBREW" to 2 chars
|
||||||
|
warning: Overwrote a non-zero byte in the new licensee code
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
warning: Overwrote a non-zero byte in the new licensee code
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
warning: Overwrote a non-zero byte in the old licensee code
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
warning: Overwrote a non-zero byte in the old licensee code
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
warning: Overwrote a non-zero byte in the RAM size
|
||||||
|
|||||||
@@ -1 +1,3 @@
|
|||||||
warning: MBC "MBC3+RAM" has RAM, but RAM size was set to 0
|
warning: MBC "MBC3+RAM" has RAM, but RAM size was set to 0
|
||||||
|
warning: Overwrote a non-zero byte in the cartridge type
|
||||||
|
warning: Overwrote a non-zero byte in the RAM size
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
warning: Overwrote a non-zero byte in the cartridge type
|
||||||
|
warning: Overwrote a non-zero byte in the RAM size
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
warning: Overwrote a non-zero byte in the cartridge type
|
||||||
|
warning: Overwrote a non-zero byte in the RAM size
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
warning: ROM+RAM / ROM+RAM+BATTERY are under-specified and poorly supported
|
warning: ROM+RAM / ROM+RAM+BATTERY are under-specified and poorly supported
|
||||||
|
warning: Overwrote a non-zero byte in the cartridge type
|
||||||
|
|||||||
@@ -1 +1,3 @@
|
|||||||
warning: SGB compatibility enabled, but old licensee is 0x45, not 0x33
|
warning: SGB compatibility enabled, but old licensee is 0x45, not 0x33
|
||||||
|
warning: Overwrote a non-zero byte in the SGB flag
|
||||||
|
warning: Overwrote a non-zero byte in the old licensee code
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
warning: Overwrote a non-zero byte in the SGB flag
|
||||||
|
|||||||
@@ -1 +1,3 @@
|
|||||||
warning: Truncating title "0123456789ABCDEF" to 15 chars
|
warning: Truncating title "0123456789ABCDEF" to 15 chars
|
||||||
|
warning: Overwrote a non-zero byte in the title
|
||||||
|
warning: Overwrote a non-zero byte in the CGB flag
|
||||||
|
|||||||
@@ -1 +1,3 @@
|
|||||||
warning: Truncating title "0123456789ABCDEF" to 15 chars
|
warning: Truncating title "0123456789ABCDEF" to 15 chars
|
||||||
|
warning: Overwrote a non-zero byte in the title
|
||||||
|
warning: Overwrote a non-zero byte in the CGB flag
|
||||||
|
|||||||
@@ -1 +1,3 @@
|
|||||||
warning: Truncating title "0123456789ABCDEF" to 15 chars
|
warning: Truncating title "0123456789ABCDEF" to 15 chars
|
||||||
|
warning: Overwrote a non-zero byte in the title
|
||||||
|
warning: Overwrote a non-zero byte in the CGB flag
|
||||||
|
|||||||
@@ -1 +1,3 @@
|
|||||||
warning: Truncating title "0123456789ABCDEF" to 15 chars
|
warning: Truncating title "0123456789ABCDEF" to 15 chars
|
||||||
|
warning: Overwrote a non-zero byte in the title
|
||||||
|
warning: Overwrote a non-zero byte in the CGB flag
|
||||||
|
|||||||
@@ -1 +1,3 @@
|
|||||||
warning: Truncating title "0123456789ABCDEF" to 11 chars
|
warning: Truncating title "0123456789ABCDEF" to 11 chars
|
||||||
|
warning: Overwrote a non-zero byte in the title
|
||||||
|
warning: Overwrote a non-zero byte in the manufacturer code
|
||||||
|
|||||||
@@ -1 +1,3 @@
|
|||||||
warning: Truncating title "0123456789ABCDEF" to 11 chars
|
warning: Truncating title "0123456789ABCDEF" to 11 chars
|
||||||
|
warning: Overwrote a non-zero byte in the title
|
||||||
|
warning: Overwrote a non-zero byte in the manufacturer code
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
warning: Overwrote a non-zero byte in the title
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
warning: Truncating title "0123456789ABCDEFGHIJK" to 16 chars
|
warning: Truncating title "0123456789ABCDEFGHIJK" to 16 chars
|
||||||
|
warning: Overwrote a non-zero byte in the title
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
warning: Overwrote a non-zero byte in the title
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
warning: Overwrote a non-zero byte in the Nintendo logo
|
||||||
|
warning: Overwrote a non-zero byte in the header checksum
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
warning: Overwrote a non-zero byte in the Nintendo logo
|
||||||
|
warning: Overwrote a non-zero byte in the header checksum
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
warning: Overwrote a non-zero byte in the Nintendo logo
|
||||||
|
warning: Overwrote a non-zero byte in the header checksum
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
warning: Overwrote a non-zero byte in the mask ROM version number
|
||||||
|
|||||||
Reference in New Issue
Block a user