Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
214 changes: 214 additions & 0 deletions scriptmodules/helpers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
#!/usr/bin/env bash

# This file is part of RetroPie-Extra, a supplement to RetroPie.
# For more information, please visit:
#
# https://github.com/RetroPie/RetroPie-Setup
# https://github.com/Exarkuniv/RetroPie-Extra
#
# See the LICENSE file distributed with this source and at
# https://raw.githubusercontent.com/Exarkuniv/RetroPie-Extra/master/LICENSE
#
# Shared utility functions for RetroPie-Extra scriptmodules.
# Source this file from individual scriptmodules to reduce code duplication.

# Download Doom shareware and Freedoom WADs to the ports/doom directory.
# Usage: _download_doom_port_wads
function _download_doom_port_wads() {
mkRomDir "ports"
mkRomDir "ports/doom"
if [[ ! -f "$romdir/ports/doom/doom1.wad" ]]; then
wget "$__archive_url/doom1.wad" -O "$romdir/ports/doom/doom1.wad"
fi

if [[ ! -f "$romdir/ports/doom/freedoom1.wad" ]]; then
wget "https://github.com/freedoom/freedoom/releases/download/v0.12.1/freedoom-0.12.1.zip"
unzip freedoom-0.12.1.zip
mv freedoom-0.12.1/*.wad "$romdir/ports/doom"
rm -rf freedoom-0.12.1
rm freedoom-0.12.1.zip
fi
}

# Download Doom shareware and Freedoom WADs to the doom system directory.
# Usage: _download_doom_system_wads
function _download_doom_system_wads() {
mkRomDir "doom"
if [[ ! -f "$romdir/doom/doom1.wad" ]]; then
wget "$__archive_url/doom1.wad" -O "$romdir/doom/doom1.wad"
fi

if [[ ! -f "$romdir/doom/freedoom1.wad" ]]; then
wget "https://github.com/freedoom/freedoom/releases/download/v0.12.1/freedoom-0.12.1.zip"
unzip freedoom-0.12.1.zip
mv freedoom-0.12.1/*.wad "$romdir/doom"
rm -rf freedoom-0.12.1
rm freedoom-0.12.1.zip
fi
}

# Register Doom WAD files as ports for a given engine.
# Checks for common WAD files and adds port entries for each one found.
#
# Usage: _add_doom_wad_ports "engine_prefix" "Engine Name" "command"
# engine_prefix: short name used for port IDs (e.g. "chocolate", "crispy", "eternity")
# engine_name: display name prefix (e.g. "Chocolate", "Crispy", "Eternity")
# command: the executable command (e.g. "$md_inst/crispy-doom")
#
# Example: _add_doom_wad_ports "crispy" "Crispy" "$md_inst/crispy-doom"
function _add_doom_wad_ports() {
local prefix="$1"
local name="$2"
local cmd="$3"

local wad_dir="$romdir/ports/doom"

if [[ -f "$wad_dir/doom1.wad" ]]; then
chown $user:$user "$wad_dir/doom1.wad"
addPort "$md_id" "${prefix}-doom1" "$name Doom Shareware" "$cmd -iwad $wad_dir/doom1.wad"
fi

if [[ -f "$wad_dir/doom.wad" ]]; then
chown $user:$user "$wad_dir/doom.wad"
addPort "$md_id" "${prefix}-doom" "$name Doom Registered" "$cmd -iwad $wad_dir/doom.wad"
fi

if [[ -f "$wad_dir/freedoom1.wad" ]]; then
chown $user:$user "$wad_dir/freedoom1.wad"
addPort "$md_id" "${prefix}-freedoom1" "$name Free Doom: Phase 1" "$cmd -iwad $wad_dir/freedoom1.wad"
fi

if [[ -f "$wad_dir/freedoom2.wad" ]]; then
chown $user:$user "$wad_dir/freedoom2.wad"
addPort "$md_id" "${prefix}-freedoom2" "$name Free Doom: Phase 2" "$cmd -iwad $wad_dir/freedoom2.wad"
fi

if [[ -f "$wad_dir/doom2.wad" ]]; then
chown $user:$user "$wad_dir/doom2.wad"
addPort "$md_id" "${prefix}-doom2" "$name Doom II: Hell on Earth" "$cmd -iwad $wad_dir/doom2.wad"
fi

if [[ -f "$wad_dir/doomu.wad" ]]; then
chown $user:$user "$wad_dir/doomu.wad"
addPort "$md_id" "${prefix}-doomu" "$name Ultimate Doom" "$cmd -iwad $wad_dir/doomu.wad"
fi

if [[ -f "$wad_dir/tnt.wad" ]]; then
chown $user:$user "$wad_dir/tnt.wad"
addPort "$md_id" "${prefix}-doomtnt" "$name Final Doom - TNT: Evilution" "$cmd -iwad $wad_dir/tnt.wad"
fi

if [[ -f "$wad_dir/plutonia.wad" ]]; then
chown $user:$user "$wad_dir/plutonia.wad"
addPort "$md_id" "${prefix}-doomplutonia" "$name Final Doom - The Plutonia Experiment" "$cmd -iwad $wad_dir/plutonia.wad"
fi
}

# Register Heretic/Hexen/Strife WAD files as ports for chocolate-doom style engines.
# These WADs use separate binaries (e.g. chocolate-heretic, chocolate-hexen).
#
# Usage: _add_heretic_hexen_strife_ports "engine_prefix" "Engine Name" "base_cmd_prefix"
# engine_prefix: short name used for port IDs (e.g. "chocolate", "eternity")
# engine_name: display name prefix (e.g. "Chocolate", "Eternity")
# heretic_cmd: command for heretic (e.g. "$md_inst/chocolate-heretic")
# hexen_cmd: command for hexen (e.g. "$md_inst/chocolate-hexen") - optional
# strife_cmd: command for strife (e.g. "$md_inst/chocolate-strife") - optional
#
# Example: _add_heretic_hexen_strife_ports "chocolate" "Chocolate" "$md_inst/chocolate-heretic" "$md_inst/chocolate-hexen" "$md_inst/chocolate-strife"
function _add_heretic_hexen_strife_ports() {
local prefix="$1"
local name="$2"
local heretic_cmd="$3"
local hexen_cmd="$4"
local strife_cmd="$5"

local wad_dir="$romdir/ports/doom"

if [[ -n "$heretic_cmd" ]]; then
if [[ -f "$wad_dir/heretic1.wad" ]]; then
chown $user:$user "$wad_dir/heretic1.wad"
addPort "$md_id" "${prefix}-heretic1" "$name Heretic Shareware" "$heretic_cmd -iwad $wad_dir/heretic1.wad"
fi

if [[ -f "$wad_dir/heretic.wad" ]]; then
chown $user:$user "$wad_dir/heretic.wad"
addPort "$md_id" "${prefix}-heretic" "$name Heretic Registered" "$heretic_cmd -iwad $wad_dir/heretic.wad"
fi
fi

if [[ -n "$hexen_cmd" ]]; then
if [[ -f "$wad_dir/hexen.wad" ]]; then
chown $user:$user "$wad_dir/hexen.wad"
addPort "$md_id" "${prefix}-hexen" "$name Hexen" "$hexen_cmd -iwad $wad_dir/hexen.wad"
fi

if [[ -f "$wad_dir/hexdd.wad" && -f "$wad_dir/hexen.wad" ]]; then
chown $user:$user "$wad_dir/hexdd.wad"
addPort "$md_id" "${prefix}-hexdd" "$name Hexen: Deathkings of the Dark Citadel" "$hexen_cmd -iwad $wad_dir/hexen.wad -file $wad_dir/hexdd.wad"
fi
fi

if [[ -n "$strife_cmd" ]]; then
if [[ -f "$wad_dir/strife1.wad" ]]; then
chown $user:$user "$wad_dir/strife1.wad"
addPort "$md_id" "${prefix}-strife1" "$name Strife" "$strife_cmd -iwad $wad_dir/strife1.wad"
fi
fi
}

# Build a libretro core using Makefile.libretro.
# Usage: _build_libretro_core "core_name"
# core_name: name of the .so output (without _libretro.so suffix)
#
# Example: _build_libretro_core "2048"
function _build_libretro_core() {
local core_name="$1"
make -f Makefile.libretro clean
make -f Makefile.libretro
md_ret_require="$md_build/${core_name}_libretro.so"
}

# Configure a libretro core as a port.
# Usage: _configure_libretro_port "port_name" "display_name" "core_file"
# port_name: short name for the port (e.g. "2048", "craft")
# display_name: human-readable name (e.g. "2048", "Craft")
# core_file: .so filename (e.g. "2048_libretro.so")
#
# Example: _configure_libretro_port "2048" "2048" "2048_libretro.so"
function _configure_libretro_port() {
local port_name="$1"
local display_name="$2"
local core_file="$3"

setConfigRoot "ports"
addPort "$md_id" "$port_name" "$display_name" "$md_inst/$core_file"
ensureSystemretroconfig "ports/$port_name"
}

# Configure a libretro core as a system emulator.
# Usage: _configure_libretro_system "system" "core_file" [is_default] [system_name] [extensions]
# system: system name (e.g. "megadrive", "uzebox")
# core_file: .so filename (e.g. "blastem_libretro.so")
# is_default: 1 or 0, whether this is the default emulator (default: 1)
# system_name: display name for the system (optional, passed to addSystem)
# extensions: file extensions (optional, passed to addSystem)
#
# Example: _configure_libretro_system "megadrive" "blastem_libretro.so"
# Example: _configure_libretro_system "uzebox" "uzem_libretro.so" 1 "Uzem" ".uze .zip"
function _configure_libretro_system() {
local system="$1"
local core_file="$2"
local is_default="${3:-1}"
local system_name="$4"
local extensions="$5"

mkRomDir "$system"
ensureSystemretroconfig "$system"

addEmulator "$is_default" "$md_id" "$system" "$md_inst/$core_file"
if [[ -n "$system_name" ]]; then
addSystem "$system" "$system_name" "$extensions"
else
addSystem "$system"
fi
}
12 changes: 4 additions & 8 deletions scriptmodules/libretrocores/lr-2048.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
# https://raw.githubusercontent.com/Exarkuniv/RetroPie-Extra/master/LICENSE
#

source "$(dirname "${BASH_SOURCE[0]}")/../helpers.sh"

rp_module_id="lr-2048"
rp_module_desc="2048 engine - 2048 port for libretro"
rp_module_licence="Unl https://raw.githubusercontent.com/libretro/libretro-2048/master/COPYING"
Expand All @@ -22,9 +24,7 @@ function sources_lr-2048() {
}

function build_lr-2048() {
make -f Makefile.libretro clean
make -f Makefile.libretro
md_ret_require="$md_build/2048_libretro.so"
_build_libretro_core "2048"
}

function install_lr-2048() {
Expand All @@ -34,9 +34,5 @@ function install_lr-2048() {
}

function configure_lr-2048() {
setConfigRoot "ports"

addPort "$md_id" "2048" "2048" "$md_inst/2048_libretro.so"

ensureSystemretroconfig "ports/2048"
_configure_libretro_port "2048" "2048" "2048_libretro.so"
}
6 changes: 3 additions & 3 deletions scriptmodules/libretrocores/lr-bk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
# https://raw.githubusercontent.com/Exarkuniv/RetroPie-Extra/master/LICENSE
#

source "$(dirname "${BASH_SOURCE[0]}")/../helpers.sh"

rp_module_id="lr-bk"
rp_module_desc="Elektronika БК-0010/0011/Terak 8510a emulator - BK port for libretro"
rp_module_help="ROM Extension: .bin .zip .7z\n\nCopy your roms to $romdir/bk\n\nCopy the following BIOS files to $biosdir/bk:\nMONIT10.ROM (BK-0010/0010.01);\nFOCAL10.ROM (BK-0010);\nBASIC10.ROM (BK-0010.01);\nDISK_327.ROM (BK-0010.01/0011M + FDD);\nB11M_BOS.ROM, BAS11M_0.ROM, BAS11M_1.ROM and B11M_EXT.ROM (BK-0011M + FDD);\nTERAK.ROM (Terak 8510/a)."
Expand All @@ -23,9 +25,7 @@ function sources_lr-bk() {
}

function build_lr-bk() {
make -f Makefile.libretro clean
make -f Makefile.libretro
md_ret_require="$md_build/bk_libretro.so"
_build_libretro_core "bk"
}

function install_lr-bk() {
Expand Down
12 changes: 4 additions & 8 deletions scriptmodules/libretrocores/lr-blastem.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
# https://raw.githubusercontent.com/Exarkuniv/RetroPie-Extra/master/LICENSE
#

source "$(dirname "${BASH_SOURCE[0]}")/../helpers.sh"

rp_module_id="lr-blastem"
rp_module_desc="Sega Genesis emu - BlastEm port for libretro"
rp_module_help="ROM Extensions: .md .bin .smd .zip .7z\n\nCopy the required BIOS file rom.db to $biosdir"
Expand All @@ -23,9 +25,7 @@ function sources_lr-blastem() {
}

function build_lr-blastem() {
make -f Makefile.libretro clean
make -f Makefile.libretro
md_ret_require="$md_build/blastem_libretro.so"
_build_libretro_core "blastem"
}

function install_lr-blastem() {
Expand All @@ -36,9 +36,5 @@ function install_lr-blastem() {
}

function configure_lr-blastem() {
mkRomDir "megadrive"
ensureSystemretroconfig "megadrive"

addEmulator 1 "$md_id" "megadrive" "$md_inst/blastem_libretro.so"
addSystem "megadrive"
_configure_libretro_system "megadrive" "blastem_libretro.so"
}
12 changes: 4 additions & 8 deletions scriptmodules/libretrocores/lr-craft.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
# https://raw.githubusercontent.com/Exarkuniv/RetroPie-Extra/master/LICENSE
#

source "$(dirname "${BASH_SOURCE[0]}")/../helpers.sh"

rp_module_id="lr-craft"
rp_module_desc="Minecraft engine - Craft port for libretro"
rp_module_licence="MIT https://raw.githubusercontent.com/libretro/Craft/master/LICENSE.md"
Expand All @@ -22,9 +24,7 @@ function sources_lr-craft() {
}

function build_lr-craft() {
make -f Makefile.libretro clean
make -f Makefile.libretro
md_ret_require="$md_build/craft_libretro.so"
_build_libretro_core "craft"
}

function install_lr-craft() {
Expand All @@ -34,9 +34,5 @@ function install_lr-craft() {
}

function configure_lr-craft() {
setConfigRoot "ports"

addPort "$md_id" "craft" "Craft" "$md_inst/craft_libretro.so"

ensureSystemretroconfig "ports/craft"
_configure_libretro_port "craft" "Craft" "craft_libretro.so"
}
6 changes: 3 additions & 3 deletions scriptmodules/libretrocores/lr-genesis-plus-gx-EX.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#
# [lr-genesis-plus-gx-EX for Sega Channel Revival] https://github.com/BillyTimeGames/Genesis-Plus-GX-Expanded-Rom-Size.git +P4PR1UM Compatibility (202507)

source "$(dirname "${BASH_SOURCE[0]}")/../helpers.sh"

rp_module_id="lr-genesis-plus-gx-EX"
rp_module_desc="Fork of lr-genesis-plus-gx + Expanded Rom Size Support"
rp_module_help="ROM Extensions: .bin .cue .gen .gg .iso .md .sg .smd .sms .zip\nCopy your Game Gear roms to $romdir/gamegear\nMasterSystem roms to $romdir/mastersystem\nMegadrive / Genesis roms to $romdir/megadrive\nSG-1000 roms to $romdir/sg-1000\nSegaCD roms to $romdir/segacd\nThe Sega CD requires the BIOS files bios_CD_U.bin and bios_CD_E.bin and bios_CD_J.bin copied to $biosdir"
Expand All @@ -22,9 +24,7 @@ function sources_lr-genesis-plus-gx-EX() {
}

function build_lr-genesis-plus-gx-EX() {
make -f Makefile.libretro clean
make -f Makefile.libretro
md_ret_require="$md_build/genesis_plus_gx_libretro.so"
_build_libretro_core "genesis_plus_gx"
}

function install_lr-genesis-plus-gx-EX() {
Expand Down
6 changes: 3 additions & 3 deletions scriptmodules/libretrocores/lr-numero.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# If no user is specified (for RetroPie below v4.8.9)
if [[ -z "$__user" ]]; then __user="$SUDO_USER"; [[ -z "$__user" ]] && __user="$(id -un)"; fi

source "$(dirname "${BASH_SOURCE[0]}")/../helpers.sh"

rp_module_id="lr-numero"
rp_module_desc="lr-numero - Numero is a libretro core for emulating the TI-83 family of graphing calculators."
rp_module_help="ROM Extensions: .8xp .8xk .8xg\n\nPlace TI-83 ROMs in: $romdir/ti83/\n\nPlace TI-83 BIOS in: $biosdir/\nti83se.rom TI-83 Silver Edition *Recommended*\nti83plus.rom TI-83 Plus\nti83.rom TI-83\n\n{RESET/RESTART in RetroArch to CLEAR the Entire Memory}\n\nMore Info:\ngithub.com/nbarkhina/numero/blob/master/README.md\n\n{ti83se.rom}:\nhttps://web.archive.org/web/20230208002249/http://tiroms.weebly.com/uploads/1/1/0/5/110560031/ti83se.rom\n\n{ti83plus.rom}\nhttps://web.archive.org/web/20230208002249/http://tiroms.weebly.com/uploads/1/1/0/5/110560031/ti83plus.rom"
Expand All @@ -25,9 +27,7 @@ function sources_lr-numero() {
}

function build_lr-numero() {
make -f Makefile.libretro clean
make -f Makefile.libretro
md_ret_require="$md_build/numero_libretro.so"
_build_libretro_core "numero"
}

function install_lr-numero() {
Expand Down
6 changes: 3 additions & 3 deletions scriptmodules/libretrocores/lr-oberon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
# https://raw.githubusercontent.com/Exarkuniv/RetroPie-Extra/master/LICENSE
#

source "$(dirname "${BASH_SOURCE[0]}")/../helpers.sh"

rp_module_id="lr-oberon"
rp_module_desc="Oberon RISC emulator for libretro"
rp_module_help="ROM Extensions: .dsk\n\nOberon RISC disk images are copied to $romdir/ports/oberon"
Expand All @@ -27,9 +29,7 @@ function sources_lr-oberon() {
}

function build_lr-oberon() {
make -f Makefile.libretro clean
make -f Makefile.libretro
md_ret_require="$md_build/oberon_libretro.so"
_build_libretro_core "oberon"
}

function install_lr-oberon() {
Expand Down
Loading