Welcome to mirror list, hosted at ThFree Co, Russian Federation.

retroarch-clover-child « bin « retroarch.hmod - github.com/ClusterM/retroarch-clover.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f975df5ae81c6b7a7f11582b0e6b4032eb2c468d (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/bin/sh

HOME=/etc/libretro
corename=$1
core=$HOME/core/$1_libretro.so
rom=$2
filename=$(basename "$rom")
id=${filename%.*}
extension="${filename##*.}"
autosave="/var/cache/$id.state.auto"
rsram="/var/cache/$id.srm"
rsav="/var/cache/$id.sav"
t_suffix=_time.txt
demo_time=30
shift 2

while [ $# -gt 0 ]; do
  [ "$1" == "--load-state-file" ] && load=$2
  [ "$1" == "--save-on-quit" ] && save=$2
  [ "$1" == "--rollback-input-dir" ] && load=$2/savestate
  [ "$1" == "--rollback-output-dir" ] && save=$2/savestate
  [ "$1" == "--save-screenshot-on-quit" ] && screenshot=$2
  [ "$1" == "--save-data-backing-file" ] && sram=$2
  [ "$1" == "--graphic-filter" ] && filter=$2
  [ "$1" == "--video-mode" ] && [ "$2" == "crt-filter" ] && filter=crt720
  [ "$1" == "--video-mode" ] && [ "$2" == "keep-aspect-ratio" ] && filter=gpu720
  [ "$1" == "--video-mode" ] && [ "$2" == "pixel-perfect" ] && filter=ppu
  [ "$1" == "--ra-extra" ] && extra=$2
  [ "$1" == "--ra-nosaves" ] && nosaves=1
  [ "$1" == "--load-time-path" ] && timefile_load=$2
  [ "$1" == "--save-time-path" ] && timefile_save=$2
  [ "$1" == "--replay-inputs" ] && demo=1
  [ "$1" == "--decorative-frame-path" ] && frame=$2
  shift
done

[ "$filter" == "crt720" ] && crt=1

[ -z "$timefile_save" ] && timefile_save=$save$t_suffix
[ -z "$timefile_load" ] && timefile_load=$load$t_suffix

[ ! -z "$demo" ] && load=$(dirname $load)/savestate

# saves if any
rm -f /var/cache/*.state /var/cache/*.auto /var/cache/*.srm /var/cache/*.sav
if [ ! -z "$load" ] && [ -f "$load" ] && [ -z "$nosaves" ]; then
  if [ $(hexdump -n 2 -e '1/1 "%02X"' "$load") == "1F8B" ]; then
    cp -f "$load" "$autosave.gz"
    gunzip -f "$autosave.gz"
  else
    cp -f "$load" "$autosave"
  fi
fi
# Nestopia names FDS saves as $id.sav, so here's a quick fix
if [ "$corename" == "nestopia" ] && [ "$extension" == "fds" ]; then
  [ ! -z "$sram" ] && [ -f "$sram" ] && cp -f "$sram" "$rsav"
else
  [ ! -z "$sram" ] && [ -f "$sram" ] && cp -f "$sram" "$rsram"
fi

smooth=$(cat /etc/libretro/$filter.smooth)
sed -i -e 's/video_smooth = "[^"]*"/video_smooth = "'$smooth'"/g' /etc/libretro/retroarch.cfg
ratio=$(cat /etc/libretro/$filter.ratio)
sed -i -e 's/aspect_ratio_index = "[^"]*"/aspect_ratio_index = "'$ratio'"/g' /etc/libretro/retroarch.cfg
overlay=$(cat /etc/libretro/$filter.overlay)
sed -i -e 's/input_overlay_enable = "[^"]*"/input_overlay_enable = "'$overlay'"/g' /etc/libretro/retroarch.cfg

[ ! -z "$crt" ] && overlay1=scanlines.png
if [ ! -z "$frame" ]; then
  [ -z "$crt" ] && overlay1=$frame.png || overlay2=$frame.png
fi
overlay1=$(echo "$overlay1" | sed 's/\//\\\//g')
overlay2=$(echo "$overlay2" | sed 's/\//\\\//g')
sed -i -e 's/overlay0_overlay = "[^"]*"/overlay0_overlay = "'$overlay1'"/g' /etc/libretro/.config/retroarch/overlay/scanlines.cfg
sed -i -e 's/overlay0_desc0_overlay = "[^"]*"/overlay0_desc0_overlay = "'$overlay2'"/g' /etc/libretro/.config/retroarch/overlay/scanlines.cfg

# Start timestamp
ts=$(date +"%s")
tm=0
[ -f "$timefile_load" ] && tm=$(cat "$timefile_load")

retroarch -c "$HOME/retroarch.cfg" -vfL "$core" "$rom" $extra &
rpid=$!

# searching for input devices
for i in $(ls /dev/input/event?) ;do
  id=$(basename $i)
  name=$(cat /sys/class/input/$id/device/name)
  [ "$name" == "sunxi-knob" ] && power_file=$i
  [ "$name" == "sunxi-keyboard" ] && reset_file=$i
  [ "$name" == "Nintendo Clovercon - controller1" ] && controller1_file=$i
  [ "$name" == "Nintendo Clovercon - controller2" ] && controller2_file=$i
done

dd if=$power_file of=/dev/null count=1 2> /dev/null &
power_pid=$!
dd if=$reset_file of=/dev/null count=1 2> /dev/null &
reset_pid=$!

# Demo mode enabled
if [ ! -z "$demo" ]; then
  if [ ! -z "$controller1_file" ]; then
    dd if=$controller1_file of=/dev/null count=1 2> /dev/null &
    anybutton1_pid=$!
  fi
  if [ ! -z "$controller2_file" ]; then
    dd if=$controller2_file of=/dev/null count=1 2> /dev/null &
    anybutton2_pid=$!
  fi
fi

sleep 6
rm -f /var/cache/*.state /var/cache/*.auto /var/cache/*.srm /var/cache/*.sav

# Playing games until reset pressed
while [ true ]; do
  kill -0 $rpid 2> /dev/null || break
  kill -0 $reset_pid 2> /dev/null || break
  kill -0 $power_pid 2> /dev/null || break
  if [ ! -z "$demo" ]; then
    # Exit on any button
    if [ ! -z "$anybutton1_pid" ]; then
      kill -0 $anybutton1_pid 2> /dev/null || break
    fi
    if [ ! -z "$anybutton2_pid" ]; then
      kill -0 $anybutton2_pid 2> /dev/null || break
    fi
    # Or after some time
    ts2=$(date +"%s")
    tp=$((ts2 - ts))
    [ "$tp" -ge "$demo_time" ] && break
  fi
  usleep 200000
done

# Screenshot! It's not so fast, doing it in a background...
if [ ! -z "$screenshot" ] && [ -z "$nosaves" ]; then
  fbgrab -z 5 "$screenshot" &
  sshot_pid=$!
fi

kill $rpid 2> /dev/null
kill -KILL $reset_pid 2> /dev/null
kill -KILL $power_pid 2> /dev/null
[ ! -z "$anybutton1_pid" ] && kill -KILL $anybutton1_pid 2> /dev/null
[ ! -z "$anybutton2_pid" ] && kill -KILL $anybutton2_pid 2> /dev/null

[ ! -z "$sshot_pid" ] && wait $sshot_pid
wait $rpid

[ ! -z "$save" ] && mkdir -p $(dirname "$save")
[ ! -z "$sram" ] && mkdir -p $(dirname "$sram")
[ ! -z "$screenshot" ] && mkdir -p $(dirname "$screenshot")

# Saves!
if [ ! -z "$save" ] && [ -f "$autosave" ] && [ -z "$nosaves" ]; then
  gzip -f "$autosave" && mv -f "$autosave.gz" "$save"
  # Time
  ts2=$(date +"%s")
  tm=$((tm + ts2 - ts))
  echo $tm > "$timefile_save"
fi
if [ "$corename" == "nestopia" ] && [ "$extension" == "fds" ]; then
  [ ! -z "$sram" ] && [ -f "$rsav" ] && mv -f "$rsav" "$sram"
else
  [ ! -z "$sram" ] && [ -f "$rsram" ] && mv -f "$rsram" "$sram"
fi

grep "video_smooth =" /etc/libretro/retroarch.cfg | grep true && current_smooth=true || current_smooth=false
echo $current_smooth > /etc/libretro/$filter.smooth
grep "input_overlay_enable =" /etc/libretro/retroarch.cfg | grep true && current_overlay=true || current_overlay=false
echo $current_overlay > /etc/libretro/$filter.overlay
current_ratio=$(cat /etc/libretro/retroarch.cfg | grep "aspect_ratio_index = " | sed 's/[^0-9]*//g')
echo $current_ratio > /etc/libretro/$filter.ratio

# Back to the shell
/etc/init.d/S81clover-mcp start