cd "path to folder containing roms"
romchecksum () {
# Ben Boldt's Mac ROM Checksum Verifier
# https://web.archive.org/web/20180217090913/https://www.d.umn.edu/~bold0070/projects/checksum/
local therom="$1"
perl -E '
$ck = 0;
$bytesRead = read (STDIN, $buffer, 4);
$i = 4;
while ($bytesRead = read (STDIN, $buffer, 2) && $i < 3145728) {
$num = unpack 'n', $buffer;
$ck += $num;
$i += 2;
}
printf("%08x\n", $ck & 0xffffffff);
' < "$therom"
}
IFS=$'\n'
for therom in $(find . \( -size 1M -o -size 2M -o -size 3M -o -size 4M -o -size 5M -o -size 6M \) -not -path "*.src/*"); do
echo $(
romsize=$(stat -f "%z" "$therom")
thebytes=$(dd if="$therom" bs=32 count=1 2> /dev/null | xxd -p)
checksum="$(romchecksum "$therom")"
printf "%s.%s %dMiB %s " "${thebytes:16:4}" "${thebytes:36:4}" $((romsize / 1024 / 1024)) "${thebytes:0:8}"
[[ $checksum == ${thebytes:0:8} ]] && printf " √ " || printf "${checksum} x "
md5 -q "$therom"
) '"'"$therom"'"'
done | sort > romlist.txt