Log In  


How to run Picotron games on Batocera

I wanted to run Picotron 0.3.0d2 on my Raspberry Pi5 with Batocera 43.1.
Batocera uses EmulationStation as frontend, so I wanted to be able to select a game and then the game should be automatically started in Picotron. When the game is closed by the user (exit cartridge from the context menu), Picotron should also be closed.
It turned out to achieve all of this, it was quite a journey.
I can't guarantee that this solution will work with future versions of Batocera / Picotron.

Preparations

Download Batocera for Raspberry Pi 5 and write the image onto a USB stick. Boot the Raspberry Pi from the stick once so Batocera can configure itself.
The USB stick contains two partitions: BATOCERA and SHARE. We will only have to add some files on the SHARE partition.
Copy your picotron folder to the SHARE partition, so that /SHARE/picotron/ contains all picotron files (use the raspberry pi version!).
Create a new folder /SHARE/roms/picotron/ and put all your cart files in there.

EmulationStation configuration

Go to /SHARE/system/configs/emulationstation/ and create a new textfile es_systems_picotron.cfg with the following content:

<systemList>
  <system>
    <name>picotron</name>
    <fullname>Picotron</fullname>
    <path>/userdata/roms/picotron</path>
    <extension>.p64 .P64 .png .PNG</extension>
    <command>bash /userdata/picotron/launch_picotron.sh %ROM%</command>
    <platform>picotron</platform>
    <theme>picotron</theme>
  </system>
</systemList>

(Note: if you just want to start Picotron without any games, use
<command>bash /userdata/picotron/picotron</command>
instead. You don't need to do any additional steps, but you would probably still need a cart in the roms folder or otherwise EmulationStation may not show the entry for Picotron in the menu.)

Create the Picotron launch script

Go to SHARE/picotron/ and create a new textfile launch_picotron.sh with the following content:

#!/bin/bash
# define paths on the writable SHARE partition
PICOTRON_DATA="/userdata/system/configs/picotron_home"
TARGET_DIR="$PICOTRON_DATA/drive/desktop"
SYSTEM_DIR="$PICOTRON_DATA/drive/appdata/system"
TRIGGER_FILE="$SYSTEM_DIR/exit_trigger.tmp"

# force folder on SHARE partition
mkdir -p "$TARGET_DIR"
mkdir -p "$SYSTEM_DIR"

# delete old kill trigger file and copy cart file to the virtual desktop
rm -f "$TRIGGER_FILE"
cp -f "$1" "$TARGET_DIR/game.p64.png"

# copy startup.lua to the right place
cp -f /userdata/system/configs/picotron/startup.lua "$SYSTEM_DIR/startup.lua"

# start Picotron with outsourced home folder 
batocera-resolution min
/userdata/picotron/picotron -home "$PICOTRON_DATA" -f &
PICOTRON_PID=$!

# wait until game has been closed
while [ ! -f "$TRIGGER_FILE" ]; do
    sleep 0.2
    if ! kill -0 $PICOTRON_PID 2>/dev/null; then
        break
    fi
done

# clean up and finish
kill $PICOTRON_PID
rm -f "$TRIGGER_FILE"
rm -f "$TARGET_DIR/game.p64.png"
batocera-resolution max

Deposit startup.lua

Create a new folder /SHARE/system/configs/picotron/ and create a new text file startup.lua in the new folder with the following content:

local game_pid = nil
local boot_frames = 0

function _init()
    window{
        width = 480,
        height = 270,
        has_frame = false,
        moveable = false,
        resizeable = false,
        autoclose = true
    }

    game_pid = create_process("/desktop/game.p64.png")
end

function _update()
    if game_pid and boot_frames < 60 then
        boot_frames = boot_frames + 1
    end

    if game_pid and boot_frames >= 60 then
        if stat(499) != game_pid then
            store("/appdata/system/exit_trigger.tmp", "kill")
            exit()
        end
    end
end

function _draw()
    cls(0)
end

This is all. You can now boot Batocera on the Raspberry Pi again and you should be able to start Picotron games. I still have some issues with wrong button mappings, but I noticed that there is this file /SHARE/system/configs/picotron_home/sdl_controllers.txt for adding your own mappings.

Troubleshooting

Make sure that the /SHARE/picotron/picotron assembly is executable. Make sure files can be read from the /SHARE/roms/picotron/ folder. Make also sure all scripts have read access.

I need some explanation!

The es_systems_picotron.cfg just creates a new entry for the EmulationStation menu and defines which command needs to be started. In our case we start the script launch_picotron.sh.
The script creates a workaround for the readonly system of Batocera as we need to copy the selected cart file from the roms folder to our picotron home folder. We need to do this, because Picotron can't handle cart files as command attributes (except in headless mode, but this is useless if you want to see any graphical output).
So the cart file is copied to the home folder as game.p64.png. Then the lua script file startup.lua is copied into the Picotron system folder. Then Picotron is started and it detects the startup.lua script and executes it. The startup.lua script basically tells Picotron to load game.p64.png and run it.
When a game cart is exited this does not automatically close Picotron. So for this to happen the scripts will use a temporary trigger file. This file is created by startup.lua when the game is exited and if it exists the launch script will detect it and kill the Picotron process and delete the temporary trigger file.
And if you wonder: yes, I could not have come up with all of this without the help of AI.
P.S. here is a short video: https://youtu.be/7FTUrZYW7Dw

2


AWESOME!!!!!!!!!!!


Great! Thanks for sharing! BTW love your cabinet, is there anything published describing the process you did this?


There is no cabinet building tutorial from me. I did not make the shell myself, I bought it years ago from some arcade machines online shop with the stickers already applied. I only replaced the original plate for the controls with a 3D printed one to change button layout and add some USB ports. I did install all the hardware inside myself (monitor, sound and marquee light system, raspberry pi, control sticks and buttons and added holes to the shell to have additional buttons left and right for pinball games. However there are some good arcade cabinet building tutorials online.



[Please log in to post a comment]