#!/usr/bin/env zsh # YES_ZSH YES_BASH NO_DASH NO_ASH sram() { ### @- ### convert between a couple saveram formats for N64 emulators. sram_crop() { tail -n +$((($1)/16+1)) } sram_revend() { objcopy -I binary -O binary --reverse-bytes=4 "$@" } sram_dump() { xxd -ps -c 16 "$@" } sram_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" ] || { echo -E "input save does not exist" >&2; return 1; } if [ "${in##*.}" = "SaveRAM" ]; then sram_dump "$in" | sram_crop $headsize | sram_dump -r > "$out" else cat <(sram_zeros $(($headsize/16))) <(sram_dump "$in") | sram_dump -r > "$out" fi sram_revend "$out" } [ -n "${preload+-}" ] || sram "$@"