1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-11-05 05:49:02 -08:00
rc/sh/sram

52 lines
1 KiB
Text
Raw Normal View History

2015-11-28 15:03:30 -08:00
#!/usr/bin/env zsh
2021-07-29 00:37:35 -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
sram_crop() {
2015-11-28 15:03:30 -08:00
tail -n +$((($1)/16+1))
}
sram_revend() {
2015-11-28 15:03:30 -08:00
objcopy -I binary -O binary --reverse-bytes=4 "$@"
}
sram_dump() {
2015-11-28 15:03:30 -08:00
xxd -ps -c 16 "$@"
}
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"
if [ "$game" = "mm" ]; then
2015-11-28 15:03:30 -08:00
headsize=$((0x20800))
elif [ "$game" = "oot" ]; then
2015-11-28 15:03:30 -08:00
headsize=$((0x40800))
else
echo "Unknown game." >&2
return 1
fi
[ -e "$2" ] || { echo -E "input save does not exist" >&2; return 1; }
2015-11-28 15:03:30 -08:00
if [ "${in##*.}" = "SaveRAM" ]; then
sram_dump "$in" | sram_crop $headsize | sram_dump -r > "$out"
2015-11-28 15:03:30 -08:00
else
cat <(sram_zeros $(($headsize/16))) <(sram_dump "$in") | sram_dump -r > "$out"
2015-11-28 15:03:30 -08:00
fi
sram_revend "$out"
2015-11-28 15:03:30 -08:00
}
[ -n "${preload+-}" ] || sram "$@"