Skip to content

Instantly share code, notes, and snippets.

@frame
Last active May 20, 2021 14:20
Show Gist options
  • Save frame/55141081793b7bfaf0c2f36fdb0b06a0 to your computer and use it in GitHub Desktop.
Save frame/55141081793b7bfaf0c2f36fdb0b06a0 to your computer and use it in GitHub Desktop.

Retropie Setup

Preparations on Windows/MacOS

hdmi_force_hotplug=1
hdmi_group=2
hdmi_mode=16

(Power up external HDMI screen and set resultion to 1024x768@60Hz)

Picade first boot

  • Connect USB keyboard
  • F4 to exit Emulationstation
  • $ sudo raspi-config
2 Network Option
	N1 Hostname
		picade
	N2 Wi-fi
		AT Austria
			OK, Enter SSID, Enter Password
5 Interface Options
	P2	SSH
			Ok
Leave
  • $ sudo reboot
  • Disconnect USB keyboard

Via SSH

  • $ passwd
  • nano ~/.bash_aliases
alias ll='ls -al'
alias vol0='amixer set 'PCM' 0%'
alias vol1='amixer set 'PCM' 70%'
alias volup='amixer set 'PCM' 10%+'
alias voldown='amixer set 'PCM' 10%-'
  • $ sudo RetroPie-Setup/retropie_setup.sh
U Update
	Ok
C Configuration / tools
	802 autostart
		1 Start Emulation Station at boot
	805 configedit
		2 Advanced configuration
			1 Configure Libretro options
				0 all/retroarch.cfg
					14 video_scale_integer (true)
				14 mame-libretro/retroarch.cfg
R Reboot
  • $ curl -sS https://get.pimoroni.com/picadehat | bash
  • $ mkdir ~/picade-hat && cd "$_"
  • $ git clone https://github.com/pimoroni/picade-hat .
  • $ sudo ./install.sh
Picade HAT: Installer
Notice: building picade.dtbo
Notice: copying /boot/config.txt to /boot/config.txt.picade-preinstall
Installed: /boot/overlays/picade.dtbo
Installed /etc/udev/rules.d/10-picade.rules
Installed /etc/asound.conf
Config: Added "dtoverlay=picade" to /boot/config.txt
Config: Added "dtparam=audio=off" to /boot/config.txt
Config: Skipped "hdmi_force_hotplug=1", already exists in /boot/config.txt
  • $ sudo reboot
  • $ sudo apt-get install qt5-default
  • $ mkdir ~/skysource && cd "$_"
  • $ wget -q -O - https://raw.githubusercontent.com/muldjord/skyscraper/master/update_skyscraper.sh | bash
  • # killall emulationstation
  • # Skyscraper
  • $ nano ~/.skyscraper/skyscript.sh && chmod +x "$_"
#!/bin/bash
Skyscraper -p mame-libretro -s arcadedb --pretend
Skyscraper -p mame-libretro -s screenscraper --pretend
Skyscraper -p mame-libretro -s localdb
  • $ nano ~/.skyscraper/config.ini
[main]
gamelistFolder="/home/pi/.emulationstation/gamelists"
mediaFolder="/home/pi/.emulationstation/media"
videos="true"
brackets="false"
unattend="true"
interactive="true"

[mame-libretro]
artworkXml="artwork_mame-libretro.xml"
  • $ nano ~/.skyscraper/artwork_mame-libretro.xml
<?xml version="1.0" encoding="UTF-8"?>
<artwork>
  <output type="screenshot" width="640" height="480">
    <layer resource="screenshot" x="20" width="520" height="390" align="center" valign="middle">
    </layer>
    <layer resource="wheel" width="250" x="-10" align="right">
      <shadow distance="5" softness="5" opacity="70"/>
    </layer>
  </output>
</artwork>

Start random mame game every 19 minutes:

  • $ nano /opt/retropieconfigs/all/retroarch-core-options.cfg
mame2003-skip_disclaimer = "enabled"
mame2003-skip_warnings = "enabled"

Bash version

  • $ mkdir ~/random-mame && cd "$_"
  • $ nano random-mame.sh
#!/bin/bash
killall -q emulationstation retroarch

ROM=`xmlstarlet sel -B -T -t -c "/gameList/game[$RANDOM mod last() + 1]/path" ~/.emulationstation/gamelists/mame-libretro/gamelist.xml`
echo launching $ROM

/opt/retropie/emulators/retroarch/bin/retroarch \
-L /opt/retropie/libretrocores/lr-mame2003/mame2003_libretro.so \
--config /opt/retropie/configs/mame-libretro/retroarch.cfg \
"$ROM" \
--appendconfig /dev/shm/retroarch.cfg \
&
  • crontab -l | { cat; echo "*/19 * * * * /home/pi/random-mame/random-mame.sh"; } | crontab -

PHP Version

This version is superior: It features a block-list (nslasher, raiden2 and thndrbld never worked on my setup) and makes sure all games get displayed before it shuffles the whole list again.

  • $ sudo apt install php-cli php-xml
  • $ mkdir ~/random-mame && cd "$_"
  • $ nano random-mame.php
<?php

chdir(dirname(__FILE__));

$xml = '/home/pi/.emulationstation/gamelists/mame-libretro/gamelist.xml';
$json = 'queue.json';
$blocked = [
    'nslasher.zip',
    'raiden2.zip',
    'thndrbld.zip'
];

$valid = true;
if (!file_exists($json)) {
    $valid = false;
} else {
    $queue = json_decode(file_get_contents($json));
    if ($queue === false || !is_countable($queue) || !count($queue)) {
        $valid = false;
    }
}

$queue = false;
if (!$valid) {
    $roms = simplexml_load_string(file_get_contents($xml));
    if (is_countable($roms) && count($roms)) {
        $queue = [];
        foreach ($roms as $rom) {
            if (!in_array(basename((string)$rom->path), $blocked)) {
                $queue[] = (string)$rom->path;
            }
        }
        shuffle($queue);
        file_put_contents($json, json_encode($queue, JSON_PRETTY_PRINT));
    }
} else {
    $queue = json_decode(file_get_contents($json));
}

if ($queue !== false && is_countable($queue) && count($queue)) {
    $rom = array_shift($queue);
    file_put_contents($json, json_encode($queue, JSON_PRETTY_PRINT));
    echo 'launching ' . $rom . "\n";
    shell_exec('killall -q emulationstation retroarch');
    shell_exec('/opt/retropie/emulators/retroarch/bin/retroarch -L /opt/retropie/libretrocores/lr-mame2003/mame2003_libretro.so --config /opt/retropie/configs/mame-libretro/retroarch.cfg "' . $rom . '" --appendconfig /dev/shm/retroarch.cfg >/dev/null 2>/dev/null &');
}
  • crontab -l | { cat; echo "*/19 * * * * php /home/pi/random-mame/random-mame.php"; } | crontab -

Emulationstation:

D-PAD UP/DOWN/LEFT/RIGHT -> Stick
START -> Right button
SELECT -> Left button
A -> Yellow upper row
B -> Red upper row
X -> Yellow lower row
Y -> Red lower row
LEFT SHOULDER -> Blue upper row
RIGHT SHOULDER -> Blue lower row
HOTKEY ENABLE -> Front left

Keep things up to date

Note: Don't run apt upgrade or apt dist-upgrade because it will overwrite optimized packages and kernels. Only use retropie_setup.sh to update the system.

System

  • $ sudo RetroPie-Setup/retropie_setup.sh
U Update

Skyscraper

  • $ cd ~/skysource
  • $ ./update_skyscraper.sh

picade-hat

  • $ cd ~/picade-hat
  • $ git pull
  • # sudo ./install.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment