r/RetroPie • u/Chudley_Stump • 42m ago
Ports Folder Tips
I posted this already but reddit deleted it for some reason, so here it is again
1. Putting individual games into ports
example - Final Fantasy VII
put your rom in the ports folder
next you need to create a ff7.sh file in your ports folder. this is pretty simple. In retropie press f4 to goto command line
type "sudo nano RetroPie/roms/ports/ff7.sh"
Enter this text
#!/bin/bash
/opt/retropie/supplementary/runcommand/runcommand.sh 0 _SYS_ psx /home/pi/RetroPie/roms/ports/ff7.pbp
to save press ctrl+x then y then enter
Use these same steps for the rest of this tutuorial
for different systems you would change psx to the appropriate system and likewise for the roms filename and location

2. playing a video file and controlling it with a gamepad
example - fireplace.mp4
create a new fireplace.sh file in ports
#!/bin/bash
clear
/opt/retropie/admin/joy2key/joy2key.py /dev/input/js0 kcub1 kcuf1 0x2B 0x2D 0x70 0x1B 0x00 0x00
omxplayer --blank --loop /home/pi/RetroPie/roms/ports/fireplace.mp4
killall joy2key.py
clear
playing the video is pretty straight forward. omxplayer is the media player installed by default. --blank makes the background black for letterboxed videos --loop is self explanatory
for all available options, in command line type "omplayer --help | more"
getting joy2key to do what you want is the tricky part. And it is limited to the dpad and a,b,x,y buttons on your controller
- kcub1 = left arrow key
- kcuf1 = right arrow key
- kcuu1 = up arrow key
- kcud1 = down arrow key
then use the hex codes in this table for the other keys

in command line type "omplayer --keys" for a list of available controls
this part of the code - kcub1 kcuf1 0x2B 0x2D 0x70 0x1B 0x00 0x00 - corresponds to the dpad and buttons as follows... left right up down 0 1 2 3
0 1 2 3 will be different buttons depending on the gamepad, but is usually a,b,x,y. Though not always in that order. An easy way to find out is to configure your controller in the retropie menu and take notes
here is what happens when i play the clip with the above code using a usb snes controller
- dpad left = seek -30 seconds
- dpad right = seek +30 seconds
- dpad up = volume up
- dpad down = volume down
- A button = play/pause
- B button = exit
- X,Y buttons = not used
if you're using multiple controllers or a bluetooth controller, it is helpful to add the joy2key line multiple times changing the js0 to js1 and so on
/opt/retropie/admin/joy2key/joy2key.py /dev/input/js0 kcub1 kcuf1 0x2B 0x2D 0x70 0x1B 0x00 0x00
/opt/retropie/admin/joy2key/joy2key.py /dev/input/js1 kcub1 kcuf1 0x2B 0x2D 0x70 0x1B 0x00 0x00
it is important to add 0x00 0x00 to the end. joy2key will have issues if you don't assign an operation to all 8 input slots
https://reddit.com/link/1w70gro/video/u4n52nv8ehnh1/player
3. Clear Last Played
this method is inconvenient if you frequently add/remove systems...
create a clearlastplayed.sh
#!/bin/bash
sed -i '/<\/lastplayed>/d' /home/pi/.emulationstation/gamelists/ports/gamelist.xml
sed -i '/<\/playcount>/d' /home/pi/.emulationstation/gamelists/ports/gamelist.xml
reboot
you can restart emulationstation instead of rebooting, but i found that it causes ghost inputs to occur after its finished. So rebooting is best. For multiple systems you would copy and paste the two lines and change the gameslist folder to match.
I prefer to keep my gamelist.xml files in my roms folder and also like to have some text on the screen while its working for multiple systems so my code looks like this
#!/bin/bash
clear
echo "Clearing history..."
echo ""
sleep 1
sed -i '/<\/lastplayed>/d' /home/pi/RetroPie/roms/ports/gamelist.xml
sed -i '/<\/playcount>/d' /home/pi/RetroPie/roms/ports/gamelist.xml
echo "ports"
sleep 1
echo ""
echo "The system will now reboot "
sleep 1
reboot
incidentally, you can place your clearlastplayed.sh file in /home/pi/RetroPie/retropiemenu

4. powering on/off an external device
I have an old power switch tail from adafruit, but it is no longer manufactured. on amazon they sell these that are better
https://www.amazon.com/dp/B00WV7GMA2?lv=shuf&channelId=500&plpRedirect=mhFallback
for this we have to make onoff.sh
#!/bin/bash
python /home/pi/RetroPie/roms/ports/onoff.py
then we have to make onoff.py
#!/usr/bin/env python
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(21, GPIO.OUT)
if (GPIO.input(21) == 0):
GPIO.output(21, GPIO.HIGH)
else:
GPIO.output(21, GPIO.LOW)
if it doesn't work you may have to make one or both files executable. navigate to your ports folder from command line and type
sudo chmod +x onoff.py


using a raspberry pi zero 2w, gpio pin 21 is on the bottom right. ground is the bottom left. if you wish to use a different pin on your pi, you will have to change all the instances of the number 21 in the code above
