2015-11-28 15:03:30 -08:00
|
|
|
#!/usr/bin/env zsh
|
2024-03-26 15:08:14 -07:00
|
|
|
# YES_ZSH YES_BASH NO_DASH NO_ASH
|
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
|
|
|
|
2021-09-23 07:03:24 -07:00
|
|
|
sram_crop() {
|
2015-11-28 15:03:30 -08:00
|
|
|
tail -n +$((($1)/16+1))
|
|
|
|
}
|
|
|
|
|
2021-09-23 07:03:24 -07:00
|
|
|
sram_revend() {
|
2015-11-28 15:03:30 -08:00
|
|
|
objcopy -I binary -O binary --reverse-bytes=4 "$@"
|
|
|
|
}
|
|
|
|
|
2021-09-23 07:03:24 -07:00
|
|
|
sram_dump() {
|
2015-11-28 15:03:30 -08:00
|
|
|
xxd -ps -c 16 "$@"
|
|
|
|
}
|
|
|
|
|
2021-09-23 07:03:24 -07:00
|
|
|
sram_zeros() {
|
2015-11-28 15:03:30 -08:00
|
|
|
# one row (16) of zeros
|
|
|
|
yes "00000000000000000000000000000000" | head -n $1
|
|
|
|
}
|
|
|
|
|
|
|
|
game="$1"
|
|
|
|
in="$2"
|
|
|
|
out="$3"
|
|
|
|
|
2021-09-23 07:03:24 -07:00
|
|
|
if [ "$game" = "mm" ]; then
|
2015-11-28 15:03:30 -08:00
|
|
|
headsize=$((0x20800))
|
2021-09-23 07:03:24 -07:00
|
|
|
elif [ "$game" = "oot" ]; then
|
2015-11-28 15:03:30 -08:00
|
|
|
headsize=$((0x40800))
|
|
|
|
else
|
|
|
|
echo "Unknown game." >&2
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2021-09-23 07:03:24 -07:00
|
|
|
[ -e "$2" ] || { echo -E "input save does not exist" >&2; return 1; }
|
2015-11-28 15:03:30 -08:00
|
|
|
|
2021-09-23 07:03:24 -07:00
|
|
|
if [ "${in##*.}" = "SaveRAM" ]; then
|
|
|
|
sram_dump "$in" | sram_crop $headsize | sram_dump -r > "$out"
|
2015-11-28 15:03:30 -08:00
|
|
|
else
|
2021-09-23 07:03:24 -07:00
|
|
|
cat <(sram_zeros $(($headsize/16))) <(sram_dump "$in") | sram_dump -r > "$out"
|
2015-11-28 15:03:30 -08:00
|
|
|
fi
|
|
|
|
|
2021-09-23 07:03:24 -07:00
|
|
|
sram_revend "$out"
|
2015-11-28 15:03:30 -08:00
|
|
|
}
|
|
|
|
|
2021-08-02 13:48:46 -07:00
|
|
|
[ -n "${preload+-}" ] || sram "$@"
|