Implement warning diagnostic flags for RGBFIX (#1766)

* Implement warning diagnostic flags for RGBFIX

* `-m/--mbc-type help` prints to stdout

* Support `-m list` as well as `-m help`

* Make invalid `rgbfix -l` characters a fatal error, like other invalid CLI arguments

* Refactor fix/main.cpp into multiple files
This commit is contained in:
Rangi
2025-07-26 12:11:52 -04:00
committed by GitHub
parent 87c10988ed
commit 0df5b7b86d
76 changed files with 1357 additions and 1006 deletions

View File

@@ -1,3 +0,0 @@
‡Ýà!H0‡;<ýNË—ñãí=ÌÊÏç^{ KC}b“Q¤&<14>3ð ñ/]¿—¹”d<E2809D>ÙZ=ÃÀ¢bÄaËi:öeSŸ>ñU@¼Ay<aeš‰¹$vfÅå­ˆ┚ý¬gŒ VC†ò~>•‘¨þ©† ³s_ Úç&nWFoKÚšíX`'ñêÁ§ë·blƒ{‡›Œ¿
¯­çÎ8îù†<$:VÍ"ã³™Ú<E284A2>h™ÑD©¤Ð¶ñ­QcµïØÐ㸺Zû§T†ž©ø½¨ºVۼݪÏ4ªÐd T“« ÄI<1A>
Ô(/×»ç¿{hÝ:ƒ<>QmÓ$*|  íVPéó.^"&é<äŒk!š<>é`àù2ÝÝêê &Bû lÍ7föèšZe¤yf.˜mƒýØ ¯!³Œ<C2B3><C592>óN5„õd†EÁ¦qF×

View File

@@ -1,4 +1 @@
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
FATAL: Invalid character 'm' in fix spec

View File

@@ -1 +1,2 @@
warning: Overwrote a non-zero byte in the CGB flag
warning: [-Woverwrite]
Overwrote a non-zero byte in the CGB flag

View File

@@ -1 +1,2 @@
warning: Overwrote a non-zero byte in the CGB flag
warning: [-Woverwrite]
Overwrote a non-zero byte in the CGB flag

View File

@@ -1 +1,2 @@
warning: Overwrote a non-zero byte in the logo
warning: [-Woverwrite]
Overwrote a non-zero byte in the logo

View File

@@ -1 +1,2 @@
warning: Overwrote a non-zero byte in the cartridge type
warning: [-Woverwrite]
Overwrote a non-zero byte in the cartridge type

View File

@@ -1,2 +1,2 @@
FATAL: "<filename>" too short, expected at least 336 ($150) bytes, got only 0
error: "<filename>" too short, expected at least 336 ($150) bytes, got only 0
Fixing "<filename>" failed with 1 error

View File

@@ -1,2 +1,3 @@
warning: 'l' overriding 'L' in fix spec
warning: Overwrote a non-zero byte in the Nintendo logo
warning: [-Woverwrite]
Overwrote a non-zero byte in the Nintendo logo

View File

@@ -1,2 +1,4 @@
warning: Truncating game ID "FOUR!" to 4 chars
warning: Overwrote a non-zero byte in the manufacturer code
warning: [-Wtruncation]
Truncating game ID "FOUR!" to 4 chars
warning: [-Woverwrite]
Overwrote a non-zero byte in the manufacturer code

View File

@@ -1 +1,2 @@
warning: Overwrote a non-zero byte in the manufacturer code
warning: [-Woverwrite]
Overwrote a non-zero byte in the manufacturer code

View File

@@ -1 +1,2 @@
warning: Overwrote a non-zero byte in the global checksum
warning: [-Woverwrite]
Overwrote a non-zero byte in the global checksum

View File

@@ -1 +1,2 @@
warning: Overwrote a non-zero byte in the global checksum
warning: [-Woverwrite]
Overwrote a non-zero byte in the global checksum

View File

@@ -1 +1,2 @@
warning: Overwrote a non-zero byte in the global checksum
warning: [-Woverwrite]
Overwrote a non-zero byte in the global checksum

View File

@@ -1 +1,2 @@
warning: Overwrote a non-zero byte in the global checksum
warning: [-Woverwrite]
Overwrote a non-zero byte in the global checksum

View File

@@ -1,2 +1,4 @@
warning: Overwrote a non-zero byte in the CGB flag
warning: Overwrote a non-zero byte in the header checksum
warning: [-Woverwrite]
Overwrote a non-zero byte in the CGB flag
warning: [-Woverwrite]
Overwrote a non-zero byte in the header checksum

View File

@@ -1 +1,2 @@
warning: Overwrote a non-zero byte in the header checksum
warning: [-Woverwrite]
Overwrote a non-zero byte in the header checksum

View File

@@ -1 +1,2 @@
warning: Overwrote a non-zero byte in the header checksum
warning: [-Woverwrite]
Overwrote a non-zero byte in the header checksum

View File

@@ -1,4 +1,4 @@
error: Features incompatible with MBC ("mbc1+multirumble")
FATAL: Features incompatible with MBC ("mbc1+multirumble")
Accepted MBC names:
ROM ($00) [aka ROM_ONLY]
MBC1 ($01), MBC1+RAM ($02), MBC1+RAM+BATTERY ($03)

View File

@@ -1 +1,2 @@
warning: Overwrote a non-zero byte in the destination code
warning: [-Woverwrite]
Overwrote a non-zero byte in the destination code

View File

@@ -1 +1,2 @@
warning: Overwrote a non-zero byte in the Nintendo logo
warning: [-Woverwrite]
Overwrote a non-zero byte in the Nintendo logo

View File

@@ -1 +1,2 @@
warning: Overwrote a non-zero byte in the Nintendo logo
warning: [-Woverwrite]
Overwrote a non-zero byte in the Nintendo logo

View File

@@ -1 +1,2 @@
warning: MBC "ROM+RAM+BATTERY" is under-specified and poorly supported
warning: [-Wmbc]
MBC "ROM+RAM+BATTERY" is under-specified and poorly supported

View File

@@ -1 +1,2 @@
warning: MBC "ROM+RAM" is under-specified and poorly supported
warning: [-Wmbc]
MBC "ROM+RAM" is under-specified and poorly supported

View File

@@ -1 +1,2 @@
warning: Overwrote a non-zero byte in the cartridge type
warning: [-Woverwrite]
Overwrote a non-zero byte in the cartridge type

View File

@@ -1,3 +1,6 @@
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
warning: [-Wmbc]
MBC "ROM" has no RAM, but RAM size was set to 2
warning: [-Woverwrite]
Overwrote a non-zero byte in the cartridge type
warning: [-Woverwrite]
Overwrote a non-zero byte in the RAM size

View File

@@ -1,2 +1,4 @@
warning: Truncating new licensee "HOMEBREW" to 2 chars
warning: Overwrote a non-zero byte in the new licensee code
warning: [-Wtruncation]
Truncating new licensee "HOMEBREW" to 2 chars
warning: [-Woverwrite]
Overwrote a non-zero byte in the new licensee code

View File

@@ -1 +1,2 @@
warning: Overwrote a non-zero byte in the new licensee code
warning: [-Woverwrite]
Overwrote a non-zero byte in the new licensee code

View File

@@ -1,2 +1,2 @@
FATAL: Failed to open "noexist" for reading+writing: No such file or directory
error: Failed to open "noexist" for reading+writing: No such file or directory
Fixing "noexist" failed with 1 error

View File

@@ -1 +1,2 @@
warning: Overwrote a non-zero byte in the old licensee code
warning: [-Woverwrite]
Overwrote a non-zero byte in the old licensee code

View File

@@ -1 +1,2 @@
warning: Overwrote a non-zero byte in the old licensee code
warning: [-Woverwrite]
Overwrote a non-zero byte in the old licensee code

View File

@@ -1 +1,2 @@
warning: Overwrote a non-zero byte in the RAM size
warning: [-Woverwrite]
Overwrote a non-zero byte in the RAM size

View File

@@ -1,3 +1,6 @@
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
warning: [-Wmbc]
MBC "MBC3+RAM" has RAM, but RAM size was set to 0
warning: [-Woverwrite]
Overwrote a non-zero byte in the cartridge type
warning: [-Woverwrite]
Overwrote a non-zero byte in the RAM size

View File

@@ -1,2 +1,4 @@
warning: Overwrote a non-zero byte in the cartridge type
warning: Overwrote a non-zero byte in the RAM size
warning: [-Woverwrite]
Overwrote a non-zero byte in the cartridge type
warning: [-Woverwrite]
Overwrote a non-zero byte in the RAM size

View File

@@ -1,2 +1,4 @@
warning: Overwrote a non-zero byte in the cartridge type
warning: Overwrote a non-zero byte in the RAM size
warning: [-Woverwrite]
Overwrote a non-zero byte in the cartridge type
warning: [-Woverwrite]
Overwrote a non-zero byte in the RAM size

View File

@@ -1,3 +1,6 @@
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
warning: [-Wsgb]
SGB compatibility enabled, but old licensee is 0x45, not 0x33
warning: [-Woverwrite]
Overwrote a non-zero byte in the SGB flag
warning: [-Woverwrite]
Overwrote a non-zero byte in the old licensee code

View File

@@ -1,2 +1,4 @@
warning: Overwrote a non-zero byte in the SGB flag
warning: SGB compatibility enabled, but old licensee was 0xc5, not 0x33
warning: [-Woverwrite]
Overwrote a non-zero byte in the SGB flag
warning: [-Wsgb]
SGB compatibility enabled, but old licensee was 0xc5, not 0x33

View File

@@ -1 +1,2 @@
warning: Overwrote a non-zero byte in the SGB flag
warning: [-Woverwrite]
Overwrote a non-zero byte in the SGB flag

View File

@@ -58,31 +58,33 @@ runTest () {
fi
if [[ -z "$variant" ]]; then
cp "$desired_input" out.gb
if [[ -n "$(eval "$RGBFIX" $flags out.gb '2>out.err')" ]]; then
echo "${bold}${red}Fixing $1 in-place shouldn't output anything on stdout!${rescolors}${resbold}"
our_rc=1
fi
eval "$RGBFIX" $flags out.gb '>out.out' '2>out.err'
subst=out.gb
elif [[ "$variant" = ' piped' ]]; then
# Stop! This is not a Useless Use Of Cat. Using cat instead of
# stdin redirection makes the input an unseekable pipe - a scenario
# that's harder to deal with.
# shellcheck disable=SC2002
cat "$desired_input" | eval $RGBFIX "$flags" - '>out.gb' '2>out.err'
cat "$desired_input" | eval "$RGBFIX" $flags - '>out.gb' '2>out.err'
subst='<stdin>'
elif [[ "$variant" = ' output' ]]; then
cp "$desired_input" input.gb
if [[ -n "$(eval "$RGBFIX" $flags -o out.gb input.gb '2>out.err')" ]]; then
our_rc=1
fi
eval "$RGBFIX" $flags -o out.gb input.gb '>out.out' '2>out.err'
subst=input.gb
fi
if [[ -r "$2/$1.out" ]]; then
desired_outname="$2/$1.out"
else
desired_outname=/dev/null
fi
if [[ -r "$2/$1.err" ]]; then
desired_errname="$2/$1.err"
else
desired_errname=/dev/null
fi
sed "s/$subst/<filename>/g" out.out | tryDiff "$desired_outname" - "$1.out${variant}"
(( our_rc = our_rc || $? ))
sed "s/$subst/<filename>/g" out.err | tryDiff "$desired_errname" - "$1.err${variant}"
(( our_rc = our_rc || $? ))

View File

@@ -1,3 +1,6 @@
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
warning: [-Wtruncation]
Truncating title "0123456789ABCDEF" to 15 chars
warning: [-Woverwrite]
Overwrote a non-zero byte in the title
warning: [-Woverwrite]
Overwrote a non-zero byte in the CGB flag

View File

@@ -1,3 +1,6 @@
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
warning: [-Wtruncation]
Truncating title "0123456789ABCDEF" to 15 chars
warning: [-Woverwrite]
Overwrote a non-zero byte in the title
warning: [-Woverwrite]
Overwrote a non-zero byte in the CGB flag

View File

@@ -1,3 +1,6 @@
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
warning: [-Wtruncation]
Truncating title "0123456789ABCDEF" to 15 chars
warning: [-Woverwrite]
Overwrote a non-zero byte in the title
warning: [-Woverwrite]
Overwrote a non-zero byte in the CGB flag

View File

@@ -1,3 +1,6 @@
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
warning: [-Wtruncation]
Truncating title "0123456789ABCDEF" to 15 chars
warning: [-Woverwrite]
Overwrote a non-zero byte in the title
warning: [-Woverwrite]
Overwrote a non-zero byte in the CGB flag

View File

@@ -1,3 +1,6 @@
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
warning: [-Wtruncation]
Truncating title "0123456789ABCDEF" to 11 chars
warning: [-Woverwrite]
Overwrote a non-zero byte in the title
warning: [-Woverwrite]
Overwrote a non-zero byte in the manufacturer code

View File

@@ -1,3 +1,6 @@
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
warning: [-Wtruncation]
Truncating title "0123456789ABCDEF" to 11 chars
warning: [-Woverwrite]
Overwrote a non-zero byte in the title
warning: [-Woverwrite]
Overwrote a non-zero byte in the manufacturer code

View File

@@ -1 +1,2 @@
warning: Overwrote a non-zero byte in the title
warning: [-Woverwrite]
Overwrote a non-zero byte in the title

View File

@@ -1,2 +1,4 @@
warning: Truncating title "0123456789ABCDEFGHIJK" to 16 chars
warning: Overwrote a non-zero byte in the title
warning: [-Wtruncation]
Truncating title "0123456789ABCDEFGHIJK" to 16 chars
warning: [-Woverwrite]
Overwrote a non-zero byte in the title

View File

@@ -1 +1,2 @@
warning: Overwrote a non-zero byte in the title
warning: [-Woverwrite]
Overwrote a non-zero byte in the title

View File

@@ -1,2 +1,2 @@
FATAL: "<filename>" too short, expected at least 336 ($150) bytes, got only 20
error: "<filename>" too short, expected at least 336 ($150) bytes, got only 20
Fixing "<filename>" failed with 1 error

View File

@@ -1 +1 @@
error: Failed to parse TPP1 major revision number
FATAL: Failed to parse TPP1 major revision number

View File

@@ -1 +1 @@
error: Failed to parse TPP1 minor revision number
FATAL: Failed to parse TPP1 minor revision number

View File

@@ -1,5 +1,10 @@
warning: Overwrote a non-zero byte in the cartridge type
warning: Overwrote a non-zero byte in the TPP1 identification code
warning: Overwrote a non-zero byte in the TPP1 revision number
warning: Overwrote a non-zero byte in the RAM size
warning: Overwrote a non-zero byte in the TPP1 feature flags
warning: [-Woverwrite]
Overwrote a non-zero byte in the cartridge type
warning: [-Woverwrite]
Overwrote a non-zero byte in the TPP1 identification code
warning: [-Woverwrite]
Overwrote a non-zero byte in the TPP1 revision number
warning: [-Woverwrite]
Overwrote a non-zero byte in the RAM size
warning: [-Woverwrite]
Overwrote a non-zero byte in the TPP1 feature flags

View File

@@ -1,5 +1,10 @@
warning: TPP1 overwrites region flag for its identification code, ignoring `-j`
warning: Overwrote a non-zero byte in the cartridge type
warning: Overwrote a non-zero byte in the TPP1 identification code
warning: Overwrote a non-zero byte in the TPP1 revision number
warning: Overwrote a non-zero byte in the TPP1 feature flags
warning: [-Wmbc]
TPP1 overwrites region flag for its identification code, ignoring `-j`
warning: [-Woverwrite]
Overwrote a non-zero byte in the cartridge type
warning: [-Woverwrite]
Overwrote a non-zero byte in the TPP1 identification code
warning: [-Woverwrite]
Overwrote a non-zero byte in the TPP1 revision number
warning: [-Woverwrite]
Overwrote a non-zero byte in the TPP1 feature flags

View File

@@ -1,2 +1,2 @@
FATAL: "<filename>" too short, expected at least 340 ($154) bytes, got only 339
error: "<filename>" too short, expected at least 340 ($154) bytes, got only 339
Fixing "<filename>" failed with 1 error

View File

@@ -1 +1 @@
error: RGBFIX only supports TPP1 version 1.0
FATAL: RGBFIX only supports TPP1 version 1.0

View File

@@ -1 +1 @@
error: TPP1 minor revision number must be 8-bit
FATAL: TPP1 minor revision number must be 8-bit

View File

@@ -1,4 +1,4 @@
error: Unknown MBC "MBC1337"
FATAL: Unknown MBC "MBC1337"
Accepted MBC names:
ROM ($00) [aka ROM_ONLY]
MBC1 ($01), MBC1+RAM ($02), MBC1+RAM+BATTERY ($03)

View File

@@ -1,3 +1,6 @@
warning: Overwrote a non-zero byte in the Nintendo logo
warning: Overwrote a non-zero byte in the header checksum
warning: Overwrote a non-zero byte in the global checksum
warning: [-Woverwrite]
Overwrote a non-zero byte in the Nintendo logo
warning: [-Woverwrite]
Overwrote a non-zero byte in the header checksum
warning: [-Woverwrite]
Overwrote a non-zero byte in the global checksum

View File

@@ -1,3 +1,6 @@
warning: Overwrote a non-zero byte in the Nintendo logo
warning: Overwrote a non-zero byte in the header checksum
warning: Overwrote a non-zero byte in the global checksum
warning: [-Woverwrite]
Overwrote a non-zero byte in the Nintendo logo
warning: [-Woverwrite]
Overwrote a non-zero byte in the header checksum
warning: [-Woverwrite]
Overwrote a non-zero byte in the global checksum

View File

@@ -1,3 +1,6 @@
warning: Overwrote a non-zero byte in the Nintendo logo
warning: Overwrote a non-zero byte in the header checksum
warning: Overwrote a non-zero byte in the global checksum
warning: [-Woverwrite]
Overwrote a non-zero byte in the Nintendo logo
warning: [-Woverwrite]
Overwrote a non-zero byte in the header checksum
warning: [-Woverwrite]
Overwrote a non-zero byte in the global checksum

View File

@@ -1 +1,2 @@
warning: Overwrote a non-zero byte in the mask ROM version number
warning: [-Woverwrite]
Overwrote a non-zero byte in the mask ROM version number