distribution/packages/jelos/sources/scripts/setsettings.sh
fewtarius 58769c80d3
* Restructure JELOS to use .config/system and system.cfg for configuration.
* Update games to use .config/game/configs moving configurations out of the system config root.
* Split modules into a separate package (packages/misc/modules).
* Remove some unused packages and move a few virtual packages to packages/virtual.
2022-02-26 21:40:30 -05:00

734 lines
28 KiB
Bash
Executable file

#!/bin/bash
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2019-present Shanti Gilbert (https://github.com/shantigilbert)
# Copyright (C) 2020-present Fewtarius
# TODO: Set Atari800 to Atari5200 when neeeded / done?
# TODO: retroachivements / done?
# I use ${} for easier reading
# IMPORTANT: This script should not return (echo) anything other than the shader if its set
. /etc/profile
. /etc/os-release
RETROACHIEVEMENTS=(arcade atari2600 atari7800 atarilynx colecovision famicom fbn fds gamegear gb gba gbah gbc gbch gbh genesis genh ggh intellivision mastersystem megacd megadrive megadrive-japan msx msx2 n64 neogeo neogeocd nes nesh ngp ngpc odyssey2 pcengine pcenginecd pcfx pokemini psp psx sega32x segacd sfc sg-1000 snes snesh snesmsu1 supergrafx supervision tg16 tg16cd vectrex virtualboy wonderswan wonderswancolor)
NOREWIND=(sega32x psx zxspectrum odyssey2 mame n64 dreamcast atomiswave naomi neogeocd saturn psp pspminis)
NORUNAHEAD=(psp sega32x n64 dreamcast atomiswave naomi neogeocd saturn)
# The following systems are listed as they don't need the Analogue D-Pad mode on RA
NOANALOGUE=(n64 psx wonderswan wonderswancolor psp pspminis dreamcast)
IS32BITCORE=(pcsx_rearmed parallel_n64)
INDEXRATIOS=(4/3 16/9 16/10 16/15 21/9 1/1 2/1 3/2 3/4 4/1 9/16 5/4 6/5 7/9 8/3 8/7 19/12 19/14 30/17 32/9 config squarepixel core custom)
CONF="/storage/.config/system/configs/system.cfg"
SOURCERACONF="/usr/config/retroarch/retroarch.cfg"
RACONF="/storage/.config/retroarch/retroarch.cfg"
RAAPPENDCONF="/tmp/raappend.cfg"
RACORECONF="/storage/.config/retroarch/retroarch-core-options.cfg"
TMP_BEZEL="/tmp/351elec-bezel.cfg"
SNAPSHOTS="/storage/roms/savestates"
PLATFORM=${1,,}
ROM="${2##*/}"
CORE=${3,,}
SHADERSET=0
LOGSDIR="/var/log"
LOGFILE="exec.log"
EE_DEVICE=${HW_DEVICE}
#Autosave
AUTOSAVE="$@"
AUTOSAVE="${AUTOSAVE#*--autosave=*}"
AUTOSAVE="${AUTOSAVE% --*}"
#Snapshot
SNAPSHOT="$@"
SNAPSHOT="${SNAPSHOT#*--snapshot=*}"
### Enable logging
if [ "$(get_es_setting string LogLevel)" == "minimal" ]; then
LOG=false
else
LOG=true
VERBOSE=true
fi
function log() {
if [ ${LOG} == true ]; then
if [[ ! -d "$LOGSDIR" ]]; then
mkdir -p "$LOGSDIR"
fi
DATE=$(date +"%b %d %H:%M:%S")
echo "${DATE} ${MYNAME}: $1" 2>&1 >> ${LOGSDIR}/${LOGFILE}
fi
}
## Create / delete raappend.cfg
echo -n > "${RAAPPENDCONF}"
### Move operations to /tmp so we're not writing to the microSD slowing us down.
### Also test the file to ensure it's not 0 bytes which can happen if someone presses reset.
if [ ! -s ${RACONF} ]; then
log "Fix broken RA conf"
cp -f "${SOURCERACONF}" "${RACONF}"
fi
if [ ! -d "${SNAPSHOTS}/${PLATFORM}" ]; then
mkdir -p "${SNAPSHOTS}/${PLATFORM}"
fi
function doexit() {
log "Exiting.."
sync
exit 0
}
function get_setting() {
log "Get Settings function (${1})"
#We look for the setting on the ROM first, if not found we search for platform and lastly we search globally
escaped_rom_name=$(echo "${ROM}" | sed -E 's|([][])|\\\1|g')
PAT="s|^${PLATFORM}\[\"${escaped_rom_name}\"\][\.-]${1}=\(.*\)|\1|p"
EES=$(sed -n "${PAT}" "${CONF}" | head -1)
if [ -z "${EES}" ]; then
PAT="s|^${PLATFORM}[\.-]${1}=\(.*\)|\1|p"
EES=$(sed -n "${PAT}" "${CONF}" | head -1)
fi
if [ -z "${EES}" ]; then
PAT="s|^global[\.-].*${1}=\(.*\)|\1|p"
EES=$(sed -n "${PAT}" "${CONF}" | head -1)
fi
[ -z "${EES}" ] && EES="false"
}
function array_contains () {
local array="$1[@]"
local seeking=$2
local in=1
for element in "${!array}"; do
if [[ $element == "$seeking" ]]; then
in=0
break
fi
done
return $in
}
## Logging
log "setsettings.sh"
log "Platform: ${PLATFORM}"
log "ROM: ${ROM}"
log "Core: ${CORE}"
##
## Global Setting that have to stay in retroarch.cfg
## All setttings that should apply when retroarch is run as standalone
##
### Wifi
## Cleanup old settings first
#sed -i "/wifi_enabled/d" ${RACONF}
## Get configuration from system.cfg and set to retroarch.cfg
#if [ "$(get_setting wifi.enabled)" = "1" ]; then
# echo 'wifi_enabled = "true"' >> ${RACONF}
#else
# echo 'wifi_enabled = "false"' >> ${RACONF}
#fi
# RA menu rgui, ozone, glui or xmb (fallback if everthing else fails)
# if empty (auto in ES) do nothing to enable configuration in RA
get_setting "retroarch.menu_driver"
if [ "${EES}" != "false" ]; then
# delete setting only if we set new ones
# therefore configuring in RA is still possible
sed -i "/menu_driver/d" ${RACONF}
sed -i "/menu_linear_filter/d" ${RACONF}
# Set new menu driver
if [ "${EES}" == "rgui" ]; then
# menu_liner_filter is only needed for rgui
echo 'menu_driver = "rgui"' >> ${RACONF}
echo 'menu_linear_filter = "true"' >> ${RACONF}
elif [ "${EES}" == "ozone" ]; then
echo 'menu_driver = "ozone"' >> ${RACONF}
elif [ "${EES}" == "glui" ]; then
echo 'menu_driver = "glui"' >> ${RACONF}
else
# play it save and set xmb if nothing else matches
echo 'menu_driver = "xmb"' >> ${RACONF}
fi
fi
##
## Global Settings that go into the temorary config file
##
## FPS
# Get configuration from system.cfg and set to retroarch.cfg
get_setting "showFPS"
[ "${EES}" == "1" ] && echo 'fps_show = "true"' >> ${RAAPPENDCONF} || echo 'fps_show = "false"' >> ${RAAPPENDCONF}
## RetroAchievements / Cheevos
# Get configuration from system.cfg and set to retroarch.cfg
get_setting "retroachievements"
for i in "${!RETROACHIEVEMENTS[@]}"; do
if [[ "${RETROACHIEVEMENTS[$i]}" = "${PLATFORM}" ]]; then
if [ "${EES}" == "1" ]; then
echo 'cheevos_enable = "true"' >> ${RAAPPENDCONF}
get_setting "retroachievements.username"
echo "cheevos_username = \"${EES}\"" >> ${RAAPPENDCONF}
get_setting "retroachievements.password"
echo "cheevos_password = \"${EES}\"" >> ${RAAPPENDCONF}
# retroachievements_hardcore_mode
get_setting "retroachievements.hardcore"
[ "${EES}" == "1" ] && echo 'cheevos_hardcore_mode_enable = "true"' >> ${RAAPPENDCONF} || echo 'cheevos_hardcore_mode_enable = "false"' >> ${RAAPPENDCONF}
# retroachievements_leaderboards
get_setting "retroachievements.leaderboards"
if [ "${EES}" == "enabled" ]; then
echo 'cheevos_leaderboards_enable = "true"' >> ${RAAPPENDCONF}
elif [ "${EES}" == "trackers only" ]; then
echo 'cheevos_leaderboards_enable = "trackers"' >> ${RAAPPENDCONF}
elif [ "${EES}" == "notifications only" ]; then
echo 'cheevos_leaderboards_enable = "notifications"' >> ${RAAPPENDCONF}
else
echo 'cheevos_leaderboards_enable = "false"' >> ${RAAPPENDCONF}
fi
# retroachievements_verbose_mode
get_setting "retroachievements.verbose"
[ "${EES}" == "1" ] && echo 'cheevos_verbose_enable = "true"' >> ${RAAPPENDCONF} || echo 'cheevos_verbose_enable = "false"' >> ${RAAPPENDCONF}
# retroachievements_automatic_screenshot
get_setting "retroachievements.screenshot"
[ "${EES}" == "1" ] && echo 'cheevos_auto_screenshot = "true"' >> ${RAAPPENDCONF} || echo 'cheevos_auto_screenshot = "false"' >> ${RAAPPENDCONF}
# cheevos_richpresence_enable
get_setting "retroachievements.richpresence"
[ "${EES}" == "1" ] && echo 'cheevos_richpresence_enable = "true"' >> ${RAAPPENDCONF} || echo 'cheevos_richpresence_enable = "false"' >> ${RAAPPENDCONF}
# cheevos_challenge_indicators
get_setting "retroachievements.challengeindicators"
[ "${EES}" == "1" ] && echo 'cheevos_challenge_indicators = "true"' >> ${RAAPPENDCONF} || echo 'cheevos_challenge_indicators = "false"' >> ${RAAPPENDCONF}
# cheevos_test_unofficial
get_setting "retroachievements.testunofficial"
[ "${EES}" == "1" ] && echo 'cheevos_test_unofficial = "true"' >> ${RAAPPENDCONF} || echo 'cheevos_test_unofficial = "false"' >> ${RAAPPENDCONF}
# cheevos_badges_enable
get_setting "retroachievements.badges"
[ "${EES}" == "1" ] && echo 'cheevos_badges_enable = "true"' >> ${RAAPPENDCONF} || echo 'cheevos_badges_enable = "false"' >> ${RAAPPENDCONF}
# cheevos_start_active
get_setting "retroachievements.active"
[ "${EES}" == "1" ] && echo 'cheevos_start_active = "true"' >> ${RAAPPENDCONF} || echo 'cheevos_start_active = "false"' >> ${RAAPPENDCONF}
# cheevos_unlock_sound_enable
get_setting "retroachievements.soundenable"
[ "${EES}" == "1" ] && echo 'cheevos_unlock_sound_enable = "true"' >> ${RAAPPENDCONF} || echo 'cheevos_unlock_sound_enable = "false"' >> ${RAAPPENDCONF}
else
echo 'cheevos_enable = "false"' >> ${RAAPPENDCONF}
echo 'cheevos_username = ""' >> ${RAAPPENDCONF}
echo 'cheevos_password = ""' >> ${RAAPPENDCONF}
echo 'cheevos_hardcore_mode_enable = "false"' >> ${RAAPPENDCONF}
echo 'cheevos_leaderboards_enable = "false"' >> ${RAAPPENDCONF}
echo 'cheevos_verbose_enable = "false"' >> ${RAAPPENDCONF}
echo 'cheevos_test_unofficial = "false"' >> ${RAAPPENDCONF}
echo 'cheevos_unlock_sound_enable = "false"' >> ${RAAPPENDCONF}
echo 'cheevos_auto_screenshot = "false"' >> ${RAAPPENDCONF}
echo 'cheevos_badges_enable = "false"' >> ${RAAPPENDCONF}
echo 'cheevos_start_active = "false"' >> ${RAAPPENDCONF}
echo 'cheevos_richpresence_enable = "false"' >> ${RAAPPENDCONF}
echo 'cheevos_challenge_indicators = "false"' >> ${RAAPPENDCONF}
fi
fi
done
## Netplay
# Get configuration from system.cfg and set to retroarch.cfg
get_setting "netplay"
if [ "${EES}" == "false" ] || [ "${EES}" == "none" ] || [ "${EES}" == "0" ]; then
echo 'netplay = false' >> ${RAAPPENDCONF}
else
echo 'netplay = true' >> ${RAAPPENDCONF}
get_setting "netplay.mode"
NETPLAY_MODE=${EES}
# Security : hardcore mode disables save states, which would kill netplay
sed -i '/cheevos_hardcore_mode_enable =/d' ${RAAPPENDCONF}
echo 'cheevos_hardcore_mode_enable = "false"' >> ${RAAPPENDCONF}
if [[ "${NETPLAY_MODE}" == "host" ]]; then
# Quite strangely, host mode requires netplay_mode to be set to false when launched from command line
echo 'netplay_mode = false' >> ${RAAPPENDCONF}
echo 'netplay_client_swap_input = false' >> ${RAAPPENDCONF}
get_setting "netplay.port"
echo "netplay_ip_port = ${EES}" >> ${RAAPPENDCONF}
elif [[ "${NETPLAY_MODE}" == "client" ]]; then
# But client needs netplay_mode = true ... bug ?
echo 'netplay_mode = true' >> ${RAAPPENDCONF}
get_setting "netplay.client.ip"
echo "netplay_ip_address = ${EES}" >> ${RAAPPENDCONF}
get_setting "netplay.client.port"
echo "netplay_ip_port = ${EES}" >> ${RAAPPENDCONF}
echo 'netplay_client_swap_input = true' >> ${RAAPPENDCONF}
fi # Host or Client
# relay
get_setting "netplay.relay"
if [[ ! -z "${EES}" && "${EES}" != "false" ]]; then
echo 'netplay_use_mitm_server = true' >> ${RAAPPENDCONF}
echo "netplay_mitm_server = ${EES}" >> ${RAAPPENDCONF}
else
echo 'netplay_use_mitm_server = false' >> ${RAAPPENDCONF}
# sed -i "/netplay_mitm_server/d" ${RACONF}
fi
get_setting "netplay.frames"
echo "netplay_delay_frames = ${EES}" >> ${RAAPPENDCONF}
get_setting "netplay.nickname"
echo "netplay_nickname = ${EES}" >> ${RAAPPENDCONF}
# spectator mode
get_setting "netplay.spectator"
[ "${EES}" == "1" ] && echo 'netplay_spectator_mode_enable = true' >> ${RAAPPENDCONF} || echo 'netplay_spectator_mode_enable = false' >> ${RAAPPENDCONF}
get_setting "netplay_public_announce"
[ "${EES}" == "1" ] && echo 'netplay_public_announce = true' >> ${RAAPPENDCONF} || echo 'netplay_public_announce = false' >> ${RAAPPENDCONF}
fi
## AI Translation Service
# Get configuration from system.cfg and set to retroarch.cfg
get_setting "ai_service_enabled"
if [ "${EES}" == "false" ] || [ "${EES}" == "none" ] || [ "${EES}" == "0" ]; then
echo 'ai_service_enable = "false"' >> ${RAAPPENDCONF}
else
# Translation table to get the values RA needs
declare -A LangCodes=( ["false"]="0"
["En"]="1"
["Fr"]="3"
["Pt"]="49"
["De"]="5"
["El"]="30"
["Es"]="2"
["Cs"]="8"
["Da"]="9"
["Hr"]="11"
["Hu"]="35"
["It"]="4"
["Ja"]="6"
["Ko"]="12"
["Nl"]="7"
["Nn"]="46"
["Po"]="48"
["Ro"]="50"
["Ru"]="51"
["Sv"]="10"
["Tr"]="59"
["Zh"]="13"
)
echo 'ai_service_enable = "true"' >> ${RAAPPENDCONF}
get_setting "ai_target_lang"
AI_LANG=${EES}
# [[ "$AI_LANG" == "false" ]] && AI_LANG="0"
get_setting "ai_service_url"
AI_URL=${EES}
echo "ai_service_target_lang = \"${LangCodes[${AI_LANG}]}\"" >> ${RAAPPENDCONF}
if [ "${AI_URL}" == "false" ] || [ "${AI_URL}" == "auto" ] || [ "${AI_URL}" == "none" ]; then
echo "ai_service_url = \"http://ztranslate.net/service?api_key=BATOCERA&mode=Fast&output=png&target_lang=${AI_LANG}" >> ${RAAPPENDCONF}
else
echo "ai_service_url = \"${AI_URL}&mode=Fast&output=png&target_lang=${AI_LANG}" >> ${RAAPPENDCONF}
fi
fi
##
## Global/System/Game specific settings
##
## Ratio
# Get configuration from system.cfg and set to retroarch.cfg
get_setting "ratio"
if [[ "${EES}" == "false" ]]; then
# 22 is the "Core Provided" aspect ratio and its set by default if no other is selected
echo 'aspect_ratio_index = "22"' >> ${RAAPPENDCONF}
else
for i in "${!INDEXRATIOS[@]}"; do
if [[ "${INDEXRATIOS[$i]}" = "${EES}" ]]; then
break
fi
done
echo "aspect_ratio_index = \"${i}\"" >> ${RAAPPENDCONF}
fi
## Bilinear filtering
# Get configuration from system.cfg and set to retroarch.cfg
get_setting "smooth"
[ "${EES}" == "1" ] && echo 'video_smooth = "true"' >> ${RAAPPENDCONF} || echo 'video_smooth = "false"' >> ${RAAPPENDCONF}
## Video Integer Scale
# Get configuration from system.cfg and set to retroarch.cfg
get_setting "integerscale"
[ "${EES}" == "1" ] && echo 'video_scale_integer = "true"' >> ${RAAPPENDCONF} || echo 'video_scale_integer = "false"' >> ${RAAPPENDCONF}
## RGA Scaling / CTX Scaling
# Get configuration from system.cfg and set to retroarch.cfg
get_setting "rgascale"
[ "${EES}" == "1" ] && echo 'video_ctx_scaling = "true"' >> ${RAAPPENDCONF} || echo 'video_ctx_scaling = "false"' >> ${RAAPPENDCONF}
## Shaderset
# Get configuration from system.cfg and set to retroarch.cfg
get_setting "shaderset"
if [ "${EES}" == "false" ] || [ "${EES}" == "none" ] || [ "${EES}" == "0" ]; then
echo 'video_shader_enable = "false"' >> ${RAAPPENDCONF}
echo 'video_shader = ""' >> ${RAAPPENDCONF}
else
echo "video_shader = \"${EES}\"" >> ${RAAPPENDCONF}
echo 'video_shader_enable = "true"' >> ${RAAPPENDCONF}
echo "--set-shader /tmp/shaders/${EES}"
fi
## Filterset
# Get configuration from system.cfg and set to retroarch.cfg
get_setting "filterset"
if [ "${EES}" == "false" ] || [ "${EES}" == "none" ]; then
echo 'video_filter = ""' >> ${RAAPPENDCONF}
else
# Turn off RGA scaling first - just in case
sed -i "/video_ctx_scaling/d" ${RAAPPENDCONF}
echo 'video_ctx_scaling = "false"' >> ${RAAPPENDCONF}
if array_contains IS32BITCORE ${CORE}; then
echo "video_filter = \"/usr/share/retroarch/filters/32bit/video/${EES}\"" >> ${RAAPPENDCONF}
else
echo "video_filter = \"/usr/share/retroarch/filters/64bit/video/${EES}\"" >> ${RAAPPENDCONF}
fi
fi
## Set correct path for video- and audio-filters
if array_contains IS32BITCORE ${CORE}; then
echo 'audio_filter_dir = "/usr/share/retroarch/filters/32bit/audio"' >> ${RAAPPENDCONF}
echo 'video_filter_dir = "/usr/share/retroarch/filters/32bit/video"' >> ${RAAPPENDCONF}
else
echo 'audio_filter_dir = "/usr/share/retroarch/filters/64bit/audio"' >> ${RAAPPENDCONF}
echo 'video_filter_dir = "/usr/share/retroarch/filters/64bit/video"' >> ${RAAPPENDCONF}
fi
## Rewind
# Get configuration from system.cfg and set to retroarch.cfg
get_setting "rewind"
(for e in "${NORUNAHEAD[@]}"; do [[ "${e}" == "${PLATFORM}" ]] && exit 0; done) && RA=0 || RA=1
if [ $RA == 1 ] && [ "${EES}" == "1" ]; then
echo 'rewind_enable = "true"' >> ${RAAPPENDCONF}
else
echo 'rewind_enable = "false"' >> ${RAAPPENDCONF}
fi
## Incrementalsavestates
# Get configuration from system.cfg and set to retroarch.cfg
get_setting "incrementalsavestates"
if [ "${EES}" == "false" ] || [ "${EES}" == "none" ] || [ "${EES}" == "0" ]; then
echo 'savestate_auto_index = "false"' >> ${RAAPPENDCONF}
echo 'savestate_max_keep = "50"' >> ${RAAPPENDCONF}
else
echo 'savestate_auto_index = "true"' >> ${RAAPPENDCONF}
echo 'savestate_max_keep = "0"' >> ${RAAPPENDCONF}
fi
## Autosave
# Get configuration from system.cfg and set to retroarch.cfg
get_setting "autosave"
if [ "${EES}" == "false" ] || [ "${EES}" == "none" ] || [ "${EES}" == "0" ]; then
echo 'savestate_auto_save = "false"' >> ${RAAPPENDCONF}
echo 'savestate_auto_load = "false"' >> ${RAAPPENDCONF}
else
echo 'savestate_auto_save = "true"' >> ${RAAPPENDCONF}
echo 'savestate_auto_load = "true"' >> ${RAAPPENDCONF}
fi
## Snapshots
echo 'savestate_directory = "'"${SNAPSHOTS}/${PLATFORM}"'"' >> ${RAAPPENDCONF}
if [ ! -z ${SNAPSHOT} ]
then
sed -i "/savestate_auto_load =/d" ${RAAPPENDCONF}
sed -i "/savestate_auto_save =/d" ${RAAPPENDCONF}
if [ ${AUTOSAVE} == "1" ]; then
echo 'savestate_auto_load = "true"' >> ${RAAPPENDCONF}
echo 'savestate_auto_save = "true"' >> ${RAAPPENDCONF}
else
echo 'savestate_auto_load = "false"' >> ${RAAPPENDCONF}
echo 'savestate_auto_save = "false"' >> ${RAAPPENDCONF}
fi
echo "state_slot = \"${SNAPSHOT}\"" >> ${RAAPPENDCONF}
fi
## Runahead
# Get configuration from system.cfg and set to retroarch.cfg
get_setting "runahead"
(for e in "${NORUNAHEAD[@]}"; do [[ "${e}" == "${PLATFORM}" ]] && exit 0; done) && RA=0 || RA=1
if [ $RA == 1 ]; then
if [ "${EES}" == "false" ] || [ "${EES}" == "none" ] || [ "${EES}" == "0" ]; then
echo 'run_ahead_enabled = "false"' >> ${RAAPPENDCONF}
echo 'run_ahead_frames = "1"' >> ${RAAPPENDCONF}
else
echo 'run_ahead_enabled = "true"' >> ${RAAPPENDCONF}
echo "run_ahead_frames = \"${EES}\"" >> ${RAAPPENDCONF}
fi
fi
## Secondinstance
# Get configuration from system.cfg and set to retroarch.cfg
get_setting "secondinstance"
(for e in "${NORUNAHEAD[@]}"; do [[ "${e}" == "${PLATFORM}" ]] && exit 0; done) && RA=0 || RA=1
if [ $RA == 1 ]; then
[ "${EES}" == "1" ] && echo 'run_ahead_secondary_instance = "true"' >> ${RAAPPENDCONF} || echo 'run_ahead_secondary_instance = "false"' >> ${RAAPPENDCONF}
fi
## D-Pad to Analogue support, option in ES is missing atm but is managed as global.analogue=1 in system.cfg (that is made by postupdate.sh)
# Get configuration from system.cfg and set to retroarch.cfg
get_setting "analogue"
(for e in "${NOANALOGUE[@]}"; do [[ "${e}" == "${PLATFORM}" ]] && exit 0; done) && RA=1 || RA=0
if [ $RA == 1 ] || [ "${EES}" == "false" ] || [ "${EES}" == "0" ]; then
echo 'input_player1_analog_dpad_mode = "0"' >> ${RAAPPENDCONF}
else
echo 'input_player1_analog_dpad_mode = "1"' >> ${RAAPPENDCONF}
fi
##
## Settings for special cores
##
## atari800 core needs other settings when emulation atari5200
if [ "${CORE}" == "atari800" ]; then
log "Atari 800 section"
ATARICONF="/storage/.config/system/configs/atari800.cfg"
ATARI800CONF="/storage/.config/retroarch/config/Atari800/Atari800.opt"
[[ ! -f "$ATARI800CONF" ]] && touch "$ATARI800CONF"
sed -i "/atari800_system =/d" ${RACORECONF}
sed -i "/RAM_SIZE=/d" ${ATARICONF}
sed -i "/STEREO_POKEY=/d" ${ATARICONF}
sed -i "/BUILTIN_BASIC=/d" ${ATARICONF}
sed -i "/atari800_system =/d" ${ATARI800CONF}
if [ "${PLATFORM}" == "atari5200" ]; then
echo "atari800_system = \"5200\"" >> ${RACORECONF}
echo "atari800_system = \"5200\"" >> ${ATARI800CONF}
echo "RAM_SIZE=16" >> ${ATARICONF}
echo "STEREO_POKEY=0" >> ${ATARICONF}
echo "BUILTIN_BASIC=0" >> ${ATARICONF}
else
echo "atari800_system = \"800XL (64K)\"" >> ${RACORECONF}
echo "atari800_system = \"800XL (64K)\"" >> ${ATARI800CONF}
echo "RAM_SIZE=64" >> ${ATARICONF}
echo "STEREO_POKEY=1" >> ${ATARICONF}
echo "BUILTIN_BASIC=1" >> ${ATARICONF}
fi
fi
## Gambatte
if [ "${CORE}" == "gambatte" ]; then
log "Gambatte section"
GAMBATTECONF="/storage/.config/retroarch/config/Gambatte/Gambatte.opt"
if [ ! -f "$GAMBATTECONF" ]; then
# set some defaults
echo 'gambatte_gbc_color_correction = "disabled"' > ${GAMBATTECONF}
else
sed -i "/gambatte_gb_colorization =/d" ${GAMBATTECONF}
sed -i "/gambatte_gb_internal_palette =/d" ${GAMBATTECONF}
fi
get_setting "renderer.colorization"
if [ "${EES}" == "false" ] || [ "${EES}" == "auto" ] || [ "${EES}" == "none" ]; then
echo "gambatte_gb_colorization = \"disabled\"" >> ${GAMBATTECONF}
elif [ "${EES}" == "Best Guess" ]; then
echo "gambatte_gb_colorization = \"auto\"" >> ${GAMBATTECONF}
elif [ "${EES}" == "GBC" ] || [ "${EES}" == "SGB" ]; then
echo "gambatte_gb_colorization = \"${EES}\"" >> ${GAMBATTECONF}
else
echo "gambatte_gb_colorization = \"internal\"" >> ${GAMBATTECONF}
echo "gambatte_gb_internal_palette = \"${EES}\"" >> ${GAMBATTECONF}
fi
fi
# We set up the controller index
#sed -i "/input_libretro_device_p1/d" ${RACONF}
CONTROLLERS="$@"
CONTROLLERS="${CONTROLLERS#*--controllers=*}"
for i in 1 2 3 4 5; do
log "Controller section (${1})"
if [[ "$CONTROLLERS" == *p${i}* ]]; then
PINDEX="${CONTROLLERS#*-p${i}index }"
PINDEX="${PINDEX%% -p${i}guid*}"
#sed -i "/input_player${i}_joypad_index =/d" ${RACONF}
echo "input_player${i}_joypad_index = \"${PINDEX}\"" >> ${RAAPPENDCONF}
# Setting controller type for different cores
if [ "${PLATFORM}" == "atari5200" ]; then
sed -i "/input_libretro_device_p${i}/d" ${RAAPPENDCONF}
echo "input_libretro_device_p${i} = \"513\"" >> ${RAAPPENDCONF}
fi
fi
done
##
## Bezels / Decorations
##
# List of possible Bezel Folders
BEZELDIR=(/tmp/overlays/bezels /storage/roms/bezels)
# Define the resolutions of the differen systems (0:x 1:y 2:width 3:height) as seen in Scaling -> Aspect Ration -> Custom
# RG351P/M=480x320
# RG351V=640x480
if [ "${EE_DEVICE}" == "RG351P" ]; then
declare -A SystemViewport=(
['standard']="1 1 479 319"
['gb']="80 16 320 288"
['gbc']="80 16 320 288"
['supervision']="80 0 320 320"
['gamegear']="80 16 320 288"
['pokemini']="96 64 288 192"
['ngp']="80 8 320 304"
['ngpc']="80 8 320 304"
['wonderswan']="16 16 448 288"
['wonderswancolor']="16 16 448 288"
)
else #Must be the V then
declare -A SystemViewport=(
['standard']="1 1 639 479"
['gb']="80 24 480 432"
['gbc']="80 24 480 432"
['supervision']="80 0 480 480"
['gamegear']="80 24 480 432"
['pokemini']="128 112 384 256"
['ngp']="80 12 480 456"
['ngpc']="80 12 480 456"
['wonderswan']="96 96 448 288"
['wonderswancolor']="96 96 448 288"
)
fi
# Get configuration from system.cfg and set to retroarch.cfg
BEZEL=$(get_setting 'bezel' ${PLATFORM} "${ROM}")
if [[ -z "${BEZEL}" ]]; then
BEZEL=default
fi
log "bezel: ${BEZEL} platform: ${PLATFORM} rom: ${ROM}"
if [ "${BEZEL}" != "false" ] && [ "${BEZEL}" != "none" ] && [ "${BEZEL}" != "0" ] && [ ${SystemViewport[${PLATFORM}]+_} ]; then
# set path
for p in ${BEZELDIR[@]}; do
if [ -d "${p}"/"${BEZEL}" ]; then
path="${p}"/"${BEZEL}"
fi
done
BEZEL_SYSTEM=$(get_setting 'bezel.system.override' ${PLATFORM} "${ROM}")
if [[ -z "${BEZEL_SYSTEM}" || "${BEZEL_SYSTEM}" == "AUTO" ]]; then
BEZEL_SYSTEM=${PLATFORM}
fi
BEZEL_SYSTEM_PNG=${path}/systems/${BEZEL_SYSTEM}.png
log "Bezel system png: ${BEZEL_SYSTEM_PNG}"
GAME_BEZEL_OVERRIDE=$(get_setting 'bezel.game.override' ${PLATFORM} "${ROM}")
log "Game bezel override: ${GAME_BEZEL_OVERRIDE}"
if [[ -z "${GAME_BEZEL_OVERRIDE}" || "${GAME_BEZEL_OVERRIDE}" == "AUTO" ]]; then
log "No game specific override found. Looking for games"
# is there a $ROM.cfg?
# excatctly the same / just the name / default
# Random bezels have to match $ROM./d+.cfg
romdir="${path}/systems/${BEZEL_SYSTEM}/games"
pushd "${romdir}" &> /dev/null
for romname in "${ROM%.*}" "${ROM%% (*}" "default"; do
log "Looking at: ${romdir}/${romname}"
# Somehow the regex of the busybox find does not know about "+" WTF?
pattern=".*${romname}"\\.[0-9][0-9]*\\.cfg
readarray -t filelist < <(find "${romdir}" -regex "${pattern}" -exec basename "{}" \;)
log "file list: ${filelist}"
count=${#filelist[*]}
if [ ${count} -gt 0 ]; then
ran=$(($RANDOM%${count}))
game_cfg="${romdir}/${filelist[${ran}]}"
log "Using random config: ${game_cfg}"
break
elif [ -f "${romdir}/${romname}".cfg ]; then
game_cfg="${romdir}/${romname}".cfg
log "Using rom config: ${game_cfg}"
break
fi
done
popd &> /dev/null
else
game_cfg=${path}/systems/${BEZEL_SYSTEM}/games/${GAME_BEZEL_OVERRIDE}.cfg
fi
if [[ -f "${game_cfg}" ]]; then
log "game config file exists: ${game_cfg}"
contents=$(cat "${game_cfg}" | awk '{$1=$1};1') #awk strips off leading/trailing whitespace
BEZEL_SYSTEM_PNG=${path}/systems/${BEZEL_SYSTEM}/games/${contents}
fi
log "bezel png: ${BEZEL_SYSTEM_PNG}"
if [[ -f "${BEZEL_SYSTEM_PNG}" ]]; then
# create the temporary bezel for retroarch
echo "overlays = 1" > ${TMP_BEZEL}
echo "overlay0_full_screen = true" >> ${TMP_BEZEL}
echo "overlay0_normalized = true" >> ${TMP_BEZEL}
echo "overlay0_overlay = \"${BEZEL_SYSTEM_PNG}\"" >> ${TMP_BEZEL}
count=0
if [[ -d "${path}/systems/${BEZEL_SYSTEM}/overlays/" ]]; then
for overlay_png in $(ls -1 ${path}/systems/${BEZEL_SYSTEM}/overlays/*.png) ; do
overlay_name="${overlay_png%.*}"
overlay_name="$(basename ${overlay_name})"
overlay_setting=$(get_setting "bezel.overlay.${overlay_name}" ${PLATFORM} "${ROM}")
if [[ "${overlay_setting}" == "0" ]];then
continue
fi
log "Adding overlay. name: ${overlay_name} overlay setting: ${overlay_setting} png: ${overlay_png}"
echo "overlay0_desc${count}_overlay = \"${overlay_png}\"" >> ${TMP_BEZEL}
echo "overlay0_desc${count} = \"nul,0.5,0.5,rect,0.5,0.5\"" >> ${TMP_BEZEL}
count=$(expr $count + 1)
done
fi
echo "overlay0_descs = ${count}" >> ${TMP_BEZEL}
bezelcfg="${TMP_BEZEL}"
fi
fi
if [[ -n "${bezelcfg}" ]]; then
log "using bezel"
# configure bezel
echo 'input_overlay_enable = "true"' >> ${RAAPPENDCONF}
echo "input_overlay = \"${bezelcfg}\"" >> ${RAAPPENDCONF}
echo 'input_overlay_hide_in_menu = "true"' >> ${RAAPPENDCONF}
echo 'input_overlay_opacity = "1.000000"' >> ${RAAPPENDCONF}
echo 'input_overlay_show_inputs = "2"' >> ${RAAPPENDCONF}
# delete / set scaling and aspect ratio:
sed -i "/video_scale_integer/d" ${RAAPPENDCONF}
sed -i "/aspect_ratio_index/d" ${RAAPPENDCONF}
echo 'video_scale_integer = "false"' >> ${RAAPPENDCONF}
echo 'aspect_ratio_index = "23"' >> ${RAAPPENDCONF}
# configure custom scaling
# needs some grouping to reflect the hack systems as well (i. e. gb=gb, gbh, gbc and gbch)
declare -a resolution=(${SystemViewport[${PLATFORM}]})
echo "custom_viewport_x = \"${resolution[0]}\"" >> ${RAAPPENDCONF}
echo "custom_viewport_y = \"${resolution[1]}\"" >> ${RAAPPENDCONF}
echo "custom_viewport_width = \"${resolution[2]}\"" >> ${RAAPPENDCONF}
echo "custom_viewport_height = \"${resolution[3]}\"" >> ${RAAPPENDCONF}
else
log "not using bezel"
# disable decorations
echo 'input_overlay_enable = "false"' >> ${RAAPPENDCONF}
# set standard resolution for custom scaling
declare -a resolution=(${SystemViewport["standard"]})
echo "custom_viewport_x = \"${resolution[0]}\"" >> ${RAAPPENDCONF}
echo "custom_viewport_y = \"${resolution[1]}\"" >> ${RAAPPENDCONF}
echo "custom_viewport_width = \"${resolution[2]}\"" >> ${RAAPPENDCONF}
echo "custom_viewport_height = \"${resolution[3]}\"" >> ${RAAPPENDCONF}
fi
##
## Clean Exit
##
doexit