ref: b4814b06b95ebc426b2f4c2783fe171d6adc52af
parent: 4ee2eb845b6343ce761126afb5f7926b02b06cb3
author: GreenAndEievui <liambennett22@live.com>
date: Wed Apr 28 07:57:43 EDT 2021
Updated RGBFIX to report when non-zero bytes are overwritten Also updated many .err files with the new warning.
--- a/src/fix/main.c
+++ b/src/fix/main.c
@@ -654,6 +654,22 @@
}
/**
+ * @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 output File descriptor to be used for writing, may be equal to `input`
* @param name The file's name, to be displayed for error output
@@ -681,6 +697,7 @@
// Accept partial reads if the file contains at least the header
if (fixSpec & (FIX_LOGO | TRASH_LOGO)) {
+ warnNonZero(rom0, 0x0104, sizeof(ninLogo), "Nintendo logo");
if (fixSpec & FIX_LOGO) {
memcpy(&rom0[0x104], ninLogo, sizeof(ninLogo));
} else {
@@ -689,36 +706,56 @@
}
}
- if (title)
+ if (title) {
+ warnNonZero(rom0, 0x134, titleLen, "title");
memcpy(&rom0[0x134], title, titleLen);
+ }
- if (gameID)
+ if (gameID) {
+ warnNonZero(rom0, 0x13f, gameIDLen, "manufacturer code");
memcpy(&rom0[0x13f], gameID, gameIDLen);
+ }
- if (model != DMG)
+ if (model != DMG) {
+ warnNonZero(rom0, 0x143, 1, "CGB flag");
rom0[0x143] = model == BOTH ? 0x80 : 0xc0;
+ }
- if (newLicensee)
+ if (newLicensee) {
+ warnNonZero(rom0, 0x144, newLicenseeLen, "new licensee code");
memcpy(&rom0[0x144], newLicensee, newLicenseeLen);
+ }
- if (sgb)
+ if (sgb) {
+ warnNonZero(rom0, 0x146, 1, "SGB flag");
rom0[0x146] = 0x03;
+ }
// If a valid MBC was specified...
- if (cartridgeType < MBC_NONE)
+ if (cartridgeType < MBC_NONE) {
+ warnNonZero(rom0, 0x147, 1, "cartridge type");
rom0[0x147] = cartridgeType;
+ }
- if (ramSize != UNSPECIFIED)
+ if (ramSize != UNSPECIFIED) {
+ warnNonZero(rom0, 0x149, 1, "RAM size");
rom0[0x149] = ramSize;
+ }
- if (!japanese)
+ if (!japanese) {
+ warnNonZero(rom0, 0x14a, 1, "destination code");
rom0[0x14a] = 0x01;
+ }
- if (oldLicensee != UNSPECIFIED)
+ if (oldLicensee != UNSPECIFIED) {
+ warnNonZero(rom0, 0x14b, 1, "old licensee code");
rom0[0x14b] = oldLicensee;
+ }
- if (romVersion != UNSPECIFIED)
+ if (romVersion != UNSPECIFIED) {
+ warnNonZero(rom0, 0x14c, 1, "mask ROM version number");
rom0[0x14c] = romVersion;
+ }
// Remain to be handled the ROM size, and header checksum.
// The latter depends on the former, and so will be handled after it.
@@ -818,6 +855,7 @@
for (uint16_t i = 0x134; i < 0x14d; i++)
sum -= rom0[i] + 1;
+ warnNonZero(rom0, 0x14d, 1, "header checksum");
rom0[0x14d] = fixSpec & TRASH_HEADER_SUM ? ~sum : sum;
}
@@ -841,6 +879,7 @@
if (fixSpec & TRASH_GLOBAL_SUM)
globalSum = ~globalSum;
+ warnNonZero(rom0, 0x14e, 2, "global checksum");
rom0[0x14e] = globalSum >> 8;
rom0[0x14f] = globalSum & 0xff;
}
@@ -915,8 +954,6 @@
free(romx);
}
-#undef trySeek
-
static bool processFilename(char const *name)
{
nbErrors = 0;
@@ -1015,7 +1052,7 @@
#define SPEC_H TRASH_HEADER_SUM
#define SPEC_g FIX_GLOBAL_SUM
#define SPEC_G TRASH_GLOBAL_SUM
-#define or(new, bad) \
+#define overrideSpec(new, bad) \
do { \
if (fixSpec & SPEC_##bad) \
fprintf(stderr, \
@@ -1023,30 +1060,30 @@
fixSpec = (fixSpec & ~SPEC_##bad) | SPEC_##new; \
} while (0)
case 'l':
- or(l, L);
+ overrideSpec(l, L);
break;
case 'L':
- or(L, l);
+ overrideSpec(L, l);
break;
case 'h':
- or(h, H);
+ overrideSpec(h, H);
break;
case 'H':
- or(H, h);
+ overrideSpec(H, h);
break;
case 'g':
- or(g, G);
+ overrideSpec(g, G);
break;
case 'G':
- or(G, g);
+ overrideSpec(G, g);
break;
default:
fprintf(stderr, "warning: Ignoring '%c' in fix spec\n",
*musl_optarg);
-#undef or
+#undef overrideSpec
}
musl_optarg++;
}
--- a/test/fix/bad-fix-char.err
+++ b/test/fix/bad-fix-char.err
@@ -1,3 +1,4 @@
warning: Ignoring 'm' in fix spec
warning: Ignoring 'a' in fix spec
warning: Ignoring 'o' in fix spec
+warning: Overwrote a non-zero byte in the Nintendo logo
--- a/test/fix/color.err
+++ b/test/fix/color.err
@@ -1,0 +1,1 @@
+warning: Overwrote a non-zero byte in the CGB flag
--- a/test/fix/compatible.err
+++ b/test/fix/compatible.err
@@ -1,0 +1,1 @@
+warning: Overwrote a non-zero byte in the CGB flag
--- a/test/fix/fix-override.err
+++ b/test/fix/fix-override.err
@@ -1,1 +1,2 @@
warning: 'l' overriding 'L' in fix spec
+warning: Overwrote a non-zero byte in the Nintendo logo
--- a/test/fix/gameid-trunc.err
+++ b/test/fix/gameid-trunc.err
@@ -1,1 +1,2 @@
warning: Truncating game ID "FOUR!" to 4 chars
+warning: Overwrote a non-zero byte in the manufacturer code
--- a/test/fix/gameid.err
+++ b/test/fix/gameid.err
@@ -1,0 +1,1 @@
+warning: Overwrote a non-zero byte in the manufacturer code
--- a/test/fix/header-edit.err
+++ b/test/fix/header-edit.err
@@ -1,0 +1,2 @@
+warning: Overwrote a non-zero byte in the CGB flag
+warning: Overwrote a non-zero byte in the header checksum
--- a/test/fix/header-trash.err
+++ b/test/fix/header-trash.err
@@ -1,0 +1,1 @@
+warning: Overwrote a non-zero byte in the header checksum
--- a/test/fix/header.err
+++ b/test/fix/header.err
@@ -1,0 +1,1 @@
+warning: Overwrote a non-zero byte in the header checksum
--- a/test/fix/jp.err
+++ b/test/fix/jp.err
@@ -1,0 +1,1 @@
+warning: Overwrote a non-zero byte in the destination code
--- a/test/fix/logo-trash.err
+++ b/test/fix/logo-trash.err
@@ -1,0 +1,1 @@
+warning: Overwrote a non-zero byte in the Nintendo logo
--- a/test/fix/logo.err
+++ b/test/fix/logo.err
@@ -1,0 +1,1 @@
+warning: Overwrote a non-zero byte in the Nintendo logo
--- a/test/fix/mbc.err
+++ b/test/fix/mbc.err
@@ -1,0 +1,1 @@
+warning: Overwrote a non-zero byte in the cartridge type
--- a/test/fix/mbcless-ram.err
+++ b/test/fix/mbcless-ram.err
@@ -1,1 +1,3 @@
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
--- a/test/fix/new-lic-trunc.err
+++ b/test/fix/new-lic-trunc.err
@@ -1,1 +1,2 @@
warning: Truncating new licensee "HOMEBREW" to 2 chars
+warning: Overwrote a non-zero byte in the new licensee code
--- a/test/fix/new-lic.err
+++ b/test/fix/new-lic.err
@@ -1,0 +1,1 @@
+warning: Overwrote a non-zero byte in the new licensee code
--- a/test/fix/old-lic-hex.err
+++ b/test/fix/old-lic-hex.err
@@ -1,0 +1,1 @@
+warning: Overwrote a non-zero byte in the old licensee code
--- a/test/fix/old-lic.err
+++ b/test/fix/old-lic.err
@@ -1,0 +1,1 @@
+warning: Overwrote a non-zero byte in the old licensee code
--- a/test/fix/ram.err
+++ b/test/fix/ram.err
@@ -1,0 +1,1 @@
+warning: Overwrote a non-zero byte in the RAM size
--- a/test/fix/ramful-mbc-no-ram.err
+++ b/test/fix/ramful-mbc-no-ram.err
@@ -1,1 +1,3 @@
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
--- a/test/fix/ramful-mbc.err
+++ b/test/fix/ramful-mbc.err
@@ -1,0 +1,2 @@
+warning: Overwrote a non-zero byte in the cartridge type
+warning: Overwrote a non-zero byte in the RAM size
--- a/test/fix/ramless-mbc.err
+++ b/test/fix/ramless-mbc.err
@@ -1,0 +1,2 @@
+warning: Overwrote a non-zero byte in the cartridge type
+warning: Overwrote a non-zero byte in the RAM size
--- a/test/fix/rom-ram.err
+++ b/test/fix/rom-ram.err
@@ -1,1 +1,2 @@
warning: ROM+RAM / ROM+RAM+BATTERY are under-specified and poorly supported
+warning: Overwrote a non-zero byte in the cartridge type
--- a/test/fix/sgb-licensee.err
+++ b/test/fix/sgb-licensee.err
@@ -1,1 +1,3 @@
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
--- a/test/fix/sgb.err
+++ b/test/fix/sgb.err
@@ -1,0 +1,1 @@
+warning: Overwrote a non-zero byte in the SGB flag
--- a/test/fix/title-color-trunc-rev.err
+++ b/test/fix/title-color-trunc-rev.err
@@ -1,1 +1,3 @@
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
--- a/test/fix/title-color-trunc.err
+++ b/test/fix/title-color-trunc.err
@@ -1,1 +1,3 @@
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
--- a/test/fix/title-compat-trunc-rev.err
+++ b/test/fix/title-compat-trunc-rev.err
@@ -1,1 +1,3 @@
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
--- a/test/fix/title-compat-trunc.err
+++ b/test/fix/title-compat-trunc.err
@@ -1,1 +1,3 @@
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
--- a/test/fix/title-gameid-trunc-rev.err
+++ b/test/fix/title-gameid-trunc-rev.err
@@ -1,1 +1,3 @@
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
--- a/test/fix/title-gameid-trunc.err
+++ b/test/fix/title-gameid-trunc.err
@@ -1,1 +1,3 @@
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
--- a/test/fix/title-pad.err
+++ b/test/fix/title-pad.err
@@ -1,0 +1,1 @@
+warning: Overwrote a non-zero byte in the title
--- a/test/fix/title-trunc.err
+++ b/test/fix/title-trunc.err
@@ -1,1 +1,2 @@
warning: Truncating title "0123456789ABCDEFGHIJK" to 16 chars
+warning: Overwrote a non-zero byte in the title
--- a/test/fix/title.err
+++ b/test/fix/title.err
@@ -1,0 +1,1 @@
+warning: Overwrote a non-zero byte in the title
--- a/test/fix/verify-pad.err
+++ b/test/fix/verify-pad.err
@@ -1,0 +1,2 @@
+warning: Overwrote a non-zero byte in the Nintendo logo
+warning: Overwrote a non-zero byte in the header checksum
--- a/test/fix/verify-trash.err
+++ b/test/fix/verify-trash.err
@@ -1,0 +1,2 @@
+warning: Overwrote a non-zero byte in the Nintendo logo
+warning: Overwrote a non-zero byte in the header checksum
--- a/test/fix/verify.err
+++ b/test/fix/verify.err
@@ -1,0 +1,2 @@
+warning: Overwrote a non-zero byte in the Nintendo logo
+warning: Overwrote a non-zero byte in the header checksum
--- a/test/fix/version.err
+++ b/test/fix/version.err
@@ -1,0 +1,1 @@
+warning: Overwrote a non-zero byte in the mask ROM version number