mirror of
https://github.com/notwa/rc
synced 2025-02-05 07:43:22 -08:00
add n64 sram filetype converter
This commit is contained in:
parent
354fca3a17
commit
5b0a96372b
1 changed files with 50 additions and 0 deletions
50
sh/sram
Normal file
50
sh/sram
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
#!/usr/bin/env zsh
|
||||||
|
|
||||||
|
sram() {
|
||||||
|
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"
|
||||||
|
}
|
||||||
|
|
||||||
|
sram "$@"
|
Loading…
Add table
Reference in a new issue