-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_mgpr_pi.sh
executable file
·485 lines (454 loc) · 16.3 KB
/
install_mgpr_pi.sh
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
#!/bin/env bash
# MIT License
# Copyright (c) 2023 Neil Davis
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
swap_mb_required=1024 # Min 1GB swap is recommended to compile box86/box64. May be raised below if < 4GB physical RAM
box86_repo="https://github.com/ptitSeb/box86.git"
box86_ver="v0.2.8"
box86_build_dir="${HOME}/code/box86"
box86_make_jobs_concurrent=1 # make -j param. Will be set to $(nproc) if you have 4GB+ RAM
box64_repo="https://github.com/ptitSeb/box64.git"
box64_ver="v0.2.2" # Until a new release tag is made
box64_build_dir="${HOME}/code/box64"
box64_make_jobs_concurrent=1 # make -j param. Will be set to $(nproc) if you have 4GB+ RAM
badown_repo="https://github.com/stck-lzm/badown.git" # to help download from mediafire
badown_ver="master"
badown_dir="${HOME}/code/badown"
# Change this to your local Debian mirror for faster downloads
# https://www.debian.org/mirror/list
debian_package_mirror="ftp.us.debian.org/debian/"
mgpr_linux_tar_gz_url="https://www.mediafire.com/file/0c68v3eb4m4wgbd/mgpr_v1_4_6_linux_04_04_2016.tar.gz"
mgpr_dest_dir="${HOME}/mgpr_v1_4_6_linux" # Path for mgpr.
mgpr_launch_sh="${HOME}/bin/mgpr.sh" # Path of mgpr launch script
# These lines affect the mgpr config file generated in mgpr's 'cfg' dir
mgpr_cfg_name="nn.cfg" # The name of the configuration file.
mgpr_cfg_display_width=800 # if TATE mode is applied this will become height
mgpr_cfg_display_height=480 # if TATE mode is applied this will become width
mgpr_cfg_fullscreen=yes # Change to 'no' to disable fullscreen use (e.g. when running in a desktop window)
mgpr_cfg_tate_mode=yes # TATE mode rotates the game to play in portrait making better use of screen space.
mgpr_cfg_playfield_width=640 # if TATE mode is applied this will become height
mgpr_cfg_playfield_height=480 # if TATE mode is applied this will become width
mgpr_cfg_playfield_pos_x=80 # if TATE mode is applied this will become y pos
mgpr_cfg_playfield_pos_y=0 # if TATE mode is applied this will become x pos
# These lines affect the .xinitrc file generated to run mgpr under X11 from the CLI console.
mgpr_display_output_id="HDMI-1" # Change to 'DSI-1' if using DSI display (e.g. official 7" touch screen)
mgpr_display_rotate="normal" # Change to 'inverted' to rotate the screen 180 degrees in TATE mode.
# Helper func to determine if we're running on a 64-bit system
is_arm64() {
[[ $(uname -m) == "aarch64" ]]
}
script_dir="${PWD}"
# Check compatibility. We only support 'numbered' RPi revisions, i.e. 2, 3 & 4
rpi_version=$(grep -Po 'Raspberry Pi \K[[:digit:]+](?= Model)' /proc/cpuinfo)
if [[ -z "${rpi_version}" ]]; then
echo "Only RPi 2,3 & 4 devices are supported"
exit 1
fi
mem_phys_total_mb=$(($(cat /proc/meminfo | grep MemTotal | awk '{print $2}')/1024))
if [[ $mem_phys_total_mb -gt 3000 ]]; then
# 4GB+ RAM allows multiple concurrent builds up to CPU core count
box86_make_jobs_concurrent=$(nproc)
box64_make_jobs_concurrent=$(nproc)
else
swap_mb_required=2048 # 2 GB swap required if < 4 GB RAM
fi
echo "${mem_phys_total_mb} MB RAM. ${swap_mb_required} MB swap required"
if is_arm64; then
mgpr_linux_build_dir="static_64bit"
deb_pkg_arch="amd64"
rpi_arch="64-bit"
else
mgpr_linux_build_dir="static_32bit"
deb_pkg_arch="i386"
rpi_arch="32-bit"
fi
echo "Installing on Raspberry Pi ${rpi_version} (${rpi_arch}) with ${mem_phys_total_mb} MB RAM (Total)"
# Install the build environment
echo "Installing build tools and dependenices ..."
sudo apt -y install git build-essential cmake xinit x11-xserver-utils libpulse0 gawk \
libegl1-mesa-dev libgles2-mesa-dev libgl1-mesa-dev libgbm-dev libdrm-dev \
set_swap_file_size() {
source /etc/dphys-swapfile
echo "Setting swap file size to ${1}"
sudo dphys-swapfile swapoff
sudo sed -i 's/CONF_SWAPSIZE='"${CONF_SWAPSIZE}"'/CONF_SWAPSIZE='"${1}"'/g' /etc/dphys-swapfile
sudo dphys-swapfile setup
sudo dphys-swapfile swapon
}
source /etc/dphys-swapfile
conf_swapsize_orig=$CONF_SWAPSIZE
set_swap_file_size_for_box_build() {
if [ $CONF_SWAPSIZE -lt $swap_mb_required ]; then
echo "Swap size ${CONF_SWAPSIZE} MB is insufficient. "
set_swap_file_size $swap_mb_required
else
echo "Swap size ${CONF_SWAPSIZE} MB is sufficient"
fi
}
build_box86() {
if [[ ! -d "${box86_build_dir}" ]]; then
echo "Fetching box86 version ${box86_ver} from ${box86_repo}"
mkdir -p "${box86_build_dir}"
git -c advice.detachedHead=false clone --depth=1 -b "${box86_ver}" "${box86_repo}" "${box86_build_dir}"
fi
if [[ ! -f "${box86_build_dir}/box86" ]]; then
# Sort out swap file for building box86
set_swap_file_size_for_box_build
cd "${box86_build_dir}"
box86_rpi_build_flag="-DRPI${rpi_version}=1"
box86_rpi_make_flag="-j${box86_make_jobs_concurrent}"
echo "Building box86 with ${box86_rpi_build_flag} and make ${box86_rpi_make_flag} ..."
cmake . "${box86_rpi_build_flag}" -DCMAKE_BUILD_TYPE=RelWithDebInfo
make "${box86_rpi_make_flag}"
cd "${script_dir}"
else
echo "Skipping box86 build. Already built"
fi
}
install_box86() {
# Let's install box86
which_box86=$(which box86)
if [[ -z "${which_box86}" ]]; then
echo "box86 is not installed"
# Build box86
build_box86
# Install box86
echo "Installing box86"
cd "${box86_build_dir}"
sudo make install
sudo systemctl restart systemd-binfmt
cd "${script_dir}"
else
echo "box86 is already installed at ${which_box86}"
fi
}
build_box64() {
if [[ ! -d "${box64_build_dir}" ]]; then
echo "Fetching box64 version ${box64_ver} from ${box64_repo}"
mkdir -p "${box64_build_dir}"
git -c advice.detachedHead=false clone --depth=1 -b "${box64_ver}" "${box64_repo}" "${box64_build_dir}"
fi
if [[ ! -f "${box64_build_dir}/box64" ]]; then
# Sort out swap file for building box64
set_swap_file_size_for_box_build
cd "${box64_build_dir}"
box64_rpi_build_flag="-DRPI${rpi_version}ARM64=1"
box64_rpi_make_flag="-j${box64_make_jobs_concurrent}"
echo "Building box64 with ${box64_rpi_build_flag} and make ${box64_rpi_make_flag} ..."
cmake . "${box64_rpi_build_flag}" -DCMAKE_BUILD_TYPE=RelWithDebInfo
make "${box64_rpi_make_flag}"
cd "${script_dir}"
else
echo "Skipping box64 build. Already built"
fi
}
install_box64() {
# Let's install box64
which_box64=$(which box64)
if [[ -z "${which_box64}" ]]; then
echo "box64 is not installed"
# build box64
build_box64
#install box64
echo "Installing box64"
cd "${box64_build_dir}"
sudo make install
sudo systemctl restart systemd-binfmt
cd "${script_dir}"
else
echo "box64 is already installed at ${which_box64}"
fi
}
if is_arm64; then
install_box64
else
install_box86
fi
# Reset swap file
source /etc/dphys-swapfile
if [ $CONF_SWAPSIZE -gt $conf_swapsize_orig ]; then
echo "Reverting swap file to original size of ${conf_swapsize_orig} MB"
set_swap_file_size $conf_swapsize_orig
else
echo "Keeping existing swap file size ${CONF_SWAPSIZE}"
fi
# Let's grab badown to help us download MGPR from mediafire
if [[ ! -d "${badown_dir}" ]]; then
echo "Fetching badwown version ${badown_ver} from ${badown_repo}"
mkdir -p "${badown_dir}"
git -c advice.detachedHead=false clone --depth=1 -b "${badown_ver}" "${badown_repo}" "${badown_dir}"
else
echo "badown has already been downloaded"
fi
# Let's grab Monaco GP Remake
mgpr_tar_gz_dest="mgpr_v1_4_6_linux_04_04_2016.tar.gz"
if [[ ! -f "${mgpr_tar_gz_dest}" ]]; then
echo "Downloading mgpr from ${mgpr_linux_tar_gz_url} ..."
"${badown_dir}"/badown "${mgpr_linux_tar_gz_url}"
else
echo "MGPR Linux has already been downloaded"
fi
if [[ ! -d "${mgpr_dest_dir}" ]]; then
echo "Extracting ${mgpr_tar_gz_dest} ..."
mkdir -p "${mgpr_dest_dir}"
tar -xf "${mgpr_tar_gz_dest}" --strip-components=1 --directory "${mgpr_dest_dir}"
#rm "${mgpr_tar_gz_dest}"
fi
echo "Using ${mgpr_linux_build_dir} version of mgpr and ${deb_pkg_arch} architecture debian packages"
if [[ ! -f "${mgpr_dest_dir}/mgpr" ]]; then
cp "${mgpr_dest_dir}/linux_builds/${mgpr_linux_build_dir}/mgpr" "${mgpr_dest_dir}/"
fi
if [[ $(ls -l "${mgpr_dest_dir}"/*.so* | wc -l) -eq 0 ]]; then
echo "Fetching ${deb_pkg_arch} pkg dependencies for mgpr"
mkdir -p "${mgpr_dest_dir}"/debs
declare -a deb_pkgs=(\
"http://${debian_package_mirror}pool/main/libd/libdumb/libdumb1_0.9.3-6+b3_${deb_pkg_arch}.deb"\
"http://${debian_package_mirror}pool/main/f/flac/libflac8_1.3.3-2+deb11u1_${deb_pkg_arch}.deb"\
"http://${debian_package_mirror}pool/main/libv/libvorbis/libvorbisfile3_1.3.7-1_${deb_pkg_arch}.deb"\
"http://${debian_package_mirror}pool/main/o/openal-soft/libopenal1_1.19.1-2_${deb_pkg_arch}.deb"\
"http://${debian_package_mirror}pool/main/s/sndio/libsndio7.0_1.5.0-3_${deb_pkg_arch}.deb"\
"http://${debian_package_mirror}pool/main/libb/libbsd/libbsd0_0.11.3-1_${deb_pkg_arch}.deb"\
"http://${debian_package_mirror}pool/main/libm/libmd/libmd0_1.0.3-3_${deb_pkg_arch}.deb" \
"http://security.ubuntu.com/ubuntu/pool/main/libj/libjpeg-turbo/libjpeg-turbo8_1.5.2-0ubuntu5.18.04.6_${deb_pkg_arch}.deb"
)
for pkg in "${deb_pkgs[@]}"; do
wget -P "${mgpr_dest_dir}"/debs "${pkg}"
done
for deb in "${mgpr_dest_dir}"/debs/*; do
dpkg -x "${deb}" "${mgpr_dest_dir}"/debs
done
find "${mgpr_dest_dir}/debs" -name *.so* -print0 | xargs -0 mv -t "${mgpr_dest_dir}"
rm -rf "${mgpr_dest_dir}"/debs
else
echo "${deb_pkg_arch} pkg dependencies for mgpr have already been fetched"
fi
# Create .xinitrc for launching mgpr from CLI
mgpr_xinit_rc="${mgpr_dest_dir}/.xinitrc"
# if [[ ! -f "${mgpr_xinit_rc}" ]]; then
echo "Creating MGPR .xinitrc script"
cat <<EOF > "${mgpr_xinit_rc}"
cd "${mgpr_dest_dir}"
DISPLAY=:0 xrandr --output ${mgpr_display_output_id} --rotate ${mgpr_display_rotate}
./mgpr -cfg "\${MGPR_CFG}"
EOF
# else
# echo "MGPR .xinitrc ${mgpr_dest_dir}/.xinitrc already exists"
# fi
# Create user scripts to launch
mkdir -p $(dirname "${mgpr_launch_sh}")
# if [[ ! -f "${mgpr_launch_sh}" ]]; then
echo "Creating MGPR launch script"
cat <<EOF > "${mgpr_launch_sh}"
#!/bin/env bash
if [ -n "\$DISPLAY" ]; then
cd "${mgpr_dest_dir}"
./mgpr -cfg "${mgpr_cfg_name}"
else
MGPR_CFG="\$1"
if [[ -z "\${MGPR_CFG}" ]]; then
MGPR_CFG="${mgpr_cfg_name}"
fi
export MGPR_CFG
XINITRC=${mgpr_dest_dir}/.xinitrc xinit -- :0 -quiet vt\$XDG_VTNR
fi
EOF
chmod a+x "${mgpr_launch_sh}"
# else
# echo "MGPR launch script ${HOME}/bin/mgpr.sh already exists"
# fi
# Create MGPR config
echo "Creating MGPR cfg (${mgpr_dest_dir}/cfg/$mgpr_cfg_name)"
mkdir -p "${mgpr_dest_dir}"/cfg
cat << EOF > "${mgpr_dest_dir}"/cfg/"$mgpr_cfg_name"
DISPLAY resolution "${mgpr_cfg_display_width}x${mgpr_cfg_display_height}"
DISPLAY fullscreen ${mgpr_cfg_fullscreen}
DISPLAY window_frame no
DISPLAY set_window_pos no
DISPLAY window_pos_x 0
DISPLAY window_pos_y 0
DISPLAY scoreboard_mode "private"
DISPLAY playfield_w ${mgpr_cfg_playfield_width}
DISPLAY playfield_h ${mgpr_cfg_playfield_height}
DISPLAY playfield_x ${mgpr_cfg_playfield_pos_x}
DISPLAY playfield_y ${mgpr_cfg_playfield_pos_y}
DISPLAY rotate ${mgpr_cfg_tate_mode}
DISPLAY flip no
DISPLAY mirror no
DISPLAY filter yes
DISPLAY open_gl no
DISPLAY menu_contrast 20
DISPLAY playfield_stage yes
DISPLAY playfield_time yes
DISPLAY playfield_score yes
DISPLAY playfield_bonus yes
DISPLAY playfield_gear yes
DISPLAY playfield_infinite_lives no
DISPLAY playfield_get_ready yes
SOUND volume_master 100
SOUND radio_chat_enable yes
SOUND radio_chat_vol 100
SOUND attract_mode_sounds yes
SOUND loop_goal yes
SOUND loop_1st yes
SOUND loop_2nd no
SOUND loop_3rd no
SOUND loop_4th no
SOUND loop_5th no
SOUND volume_goal 100
SOUND volume_1st 80
SOUND volume_2nd 80
SOUND volume_3rd 80
SOUND volume_4th 80
SOUND volume_5th 80
SOUND cheers_goal 100
SOUND cheers_1st 50
SOUND cheers_2nd 40
SOUND cheers_3rd 30
SOUND cheers_4th 20
SOUND cheers_5th 10
SOUND volume_welcome 80
SOUND low_gear_base 0.8
SOUND low_gear_multiplier 20
SOUND hi_gear_base 0.4
SOUND hi_gear_multiplier 100
SOUND filename_welcome "trumpet.wav"
SOUND filename_goal "music.wav"
SOUND filename_1st "music.wav"
SOUND filename_2nd "trumpet.wav"
SOUND filename_3rd "trumpet.wav"
SOUND filename_4th "trumpet.wav"
SOUND filename_5th "trumpet.wav"
SOUND wav_bonus_overtake "beep_clean.wav"
SOUND vol_bonus_overtake 100
SOUND wav_bonus_award "beep_distorted.wav"
SOUND vol_bonus_award 100
SOUND wav_bonus_bridge "beep_distorted.wav"
SOUND vol_bonus_bridge 100
ARTWORK enable_bezel_artwork no
ARTWORK bezel_filename "scoreboard_w1024.bmp"
ARTWORK bezel_w 0
ARTWORK bezel_h 0
ARTWORK bezel_x 0
ARTWORK bezel_y 0
ARTWORK enable_led_artwork no
ARTWORK led_filename "speccy_multi3.bmp"
ARTWORK time_w 20
ARTWORK time_h 20
ARTWORK time_x 0
ARTWORK time_y 0
ARTWORK time_id 0
ARTWORK todays_best_w 20
ARTWORK todays_best_h 20
ARTWORK todays_best_1_x 0
ARTWORK todays_best_1_y 20
ARTWORK todays_best_1_id 1
ARTWORK todays_best_2_x 0
ARTWORK todays_best_2_y 40
ARTWORK todays_best_2_id 2
ARTWORK todays_best_3_x 0
ARTWORK todays_best_3_y 60
ARTWORK todays_best_3_id 3
ARTWORK todays_best_4_x 0
ARTWORK todays_best_4_y 80
ARTWORK todays_best_4_id 4
ARTWORK todays_best_5_x 0
ARTWORK todays_best_5_y 100
ARTWORK todays_best_5_id 5
ARTWORK your_score_w 20
ARTWORK your_score_h 20
ARTWORK your_score_x 0
ARTWORK your_score_y 120
ARTWORK your_score_id 6
ARTWORK players_to_date_w 20
ARTWORK players_to_date_h 20
ARTWORK players_to_date_x 0
ARTWORK players_to_date_y 140
ARTWORK players_to_date_id 7
ARTWORK ranking_w 20
ARTWORK ranking_h 20
ARTWORK ranking_x 0
ARTWORK ranking_y 160
ARTWORK ranking_id 8
ARTWORK super_racer_w 20
ARTWORK super_racer_h 20
ARTWORK super_racer_x 0
ARTWORK super_racer_y 180
ARTWORK overtake_filename "overtake_leds.bmp"
ARTWORK overtake_row_upper_w 20
ARTWORK overtake_row_upper_h 20
ARTWORK overtake_row_upper_x 0
ARTWORK overtake_row_upper_y 200
ARTWORK overtake_row_lower_w 20
ARTWORK overtake_row_lower_h 20
ARTWORK overtake_row_lower_x 0
ARTWORK overtake_row_lower_y 220
CONTROL steering_device "keys"
CONTROL steering_invert no
CONTROL steering_sensitivity 50
CONTROL steering_weight 50
CONTROL accelerator_device "keys"
CONTROL accelerator_invert no
CONTROL accelerator_range "0 to +1"
CONTROL gear_change_device "keys"
CONTROL gear_method "toggle"
CONTROL coin_a_device "keys"
CONTROL coin_b_device "keys"
CONTROL start_device "keys"
CONTROL key_accel "n"
CONTROL key_gear "m"
CONTROL key_coin_a "5"
CONTROL key_coin_b "6"
CONTROL key_start "1"
CONTROL key_left "z"
CONTROL key_right "x"
CONTROL key_exit "escape"
GAMEPLAY game_track "game_arcade.trk"
GAMEPLAY attract_track "attract_arcade.trk"
GAMEPLAY time_bridge_grace 5
GAMEPLAY time_puddle 350
GAMEPLAY puddle_steering 90
GAMEPLAY verge_trigger 40
GAMEPLAY verge_slow_down 70
GAMEPLAY marsh_trigger 50
GAMEPLAY marsh_slow_down 60
GAMEPLAY marsh_steering 90
GAMEPLAY surface_wobble_rate 5
GAMEPLAY time_grace_scenery 7
GAMEPLAY time_grace_verge 7
GAMEPLAY brake_low_gear 2
GAMEPLAY brake_high_gear 2
GAMEPLAY brake_wrong_gear 1.7
GAMEPLAY arcade_acceleration yes
GAMEPLAY brake_immediate 50
GAMEPLAY vertical_climb 50
GAMEPLAY vertical_fall 50
GAMEPLAY blink_frames_on 6
GAMEPLAY blink_frames_off 6
GAMEPLAY pro_monaco_gp_mode no
GAMEPLAY debug_track no
GAMEPLAY tarmac_normal_play_r 62
GAMEPLAY tarmac_normal_play_g 62
GAMEPLAY tarmac_normal_play_b 62
GAMEPLAY tarmac_extended_play_r 0
GAMEPLAY tarmac_extended_play_g 0
GAMEPLAY tarmac_extended_play_b 72
GAMEPLAY night_lights_fix yes
GAMEPLAY attract_mode_hiscore yes
GAMEPLAY end_game_you_placed no
GAMEPLAY end_game_stats no
EOF
cd "${script_dir}"