aboutsummaryrefslogtreecommitdiff
path: root/hakchi/bin/snes
blob: 4447455c369642eecfa8efac191956d3aef02276 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/sh

setFileName(){
  filename="$(readlink -f "$1")"
  filebase="$(basename "$filename")"
  extension="${filebase##*.}"
}

getSfrom(){
  local rom="$(hexdump -e '1/4 "%u"' -s8 -n4 "$1")"
  local footer="$(hexdump -e '1/4 "%u"' -s20 -n4 "$1")"
  local size="$(hexdump -e '1/4 "%u"' -s$((footer+1)) -n4 "$1")"
  dd "status=none" "if=$1" "iflag=skip_bytes" "skip=$rom" "bs=$size" "count=1"
}

setFileName "$1"
shift

tmppath="/tmp/rom"
rm -rf "$tmppath"
mkdir -p "$tmppath"
cd "$tmppath"

if [ "$extension" = "7z" ]; then
  tiny7zx x "$filename"
  filename="$tmppath/$(ls | head -n1)"
  filename_str="${filename// /_}"
  mv "$filename" "$filename_str"
  setFileName "$filename_str"
fi

if [ "$extension" = "sfrom" ]; then
  filename_str="$filebase.sfc"
  getSfrom "$filename" > "$filename_str"
  setFileName "$filename_str"
fi

exec retroarch-clover snes9x "$filename" "$@"