2015-11-28 15:03:30 -08:00
|
|
|
#!/usr/bin/env zsh
|
2021-07-29 00:37:35 -07:00
|
|
|
# YES_ZSH
|
2015-11-28 15:03:30 -08:00
|
|
|
|
2021-07-30 17:57:08 -07:00
|
|
|
sram() { ### @-
|
|
|
|
### convert between a couple saveram formats for N64 emulators.
|
2015-11-28 15:03:30 -08:00
|
|
|
die() {
|
|
|
|
echo -E "$@">&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
crop() {
|
|
|
|
tail -n +$((($1)/16+1))
|
|
|
|
}
|
|
|
|
|
|
|
|
revend() {
|
|
|
|
objcopy -I binary -O binary --reverse-bytes=4 "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
dump() {
|
|
|
|
xxd -ps -c 16 "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
zeros() {
|
|
|
|
# one row (16) of zeros
|
|
|
|
yes "00000000000000000000000000000000" | head -n $1
|
|
|
|
}
|
|
|
|
|
|
|
|
game="$1"
|
|
|
|
in="$2"
|
|
|
|
out="$3"
|
|
|
|
|
|
|
|
if [[ "$game" == "mm" ]]; then
|
|
|
|
headsize=$((0x20800))
|
|
|
|
elif [[ "$game" == "oot" ]]; then
|
|
|
|
headsize=$((0x40800))
|
|
|
|
else
|
|
|
|
echo "Unknown game." >&2
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
[ -e "$2" ] || die "input save does not exist"
|
|
|
|
|
|
|
|
if [[ "${in##*.}" == "SaveRAM" ]] then
|
|
|
|
dump "$in" | crop $headsize | dump -r > "$out"
|
|
|
|
else
|
|
|
|
cat <(zeros $(($headsize/16))) <(dump "$in") | dump -r > "$out"
|
|
|
|
fi
|
|
|
|
|
|
|
|
revend "$out"
|
|
|
|
}
|
|
|
|
|
2021-08-02 13:48:46 -07:00
|
|
|
[ -n "${preload+-}" ] || sram "$@"
|