Last active
August 9, 2019 21:21
-
-
Save markegli/98b46da60052b721a4ba85d91ad1c9e9 to your computer and use it in GitHub Desktop.
Raspberry Pi PICO-8 console autostart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This file lives at ~/.config/lxsession/LXDE-pi/autostart | |
# Default autostart from /etc/xdg/lxsession/LXDE-pi/autostart | |
# Uncomment for normal desktop. | |
#@lxpanel --profile LXDE-pi | |
#@pcmanfm --desktop --profile LXDE-pi | |
#@xscreensaver -no-splash | |
#point-rpi | |
# Instead, run custom startup script | |
lxterminal --command="~/startup.sh" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This file lives at ~/startup.sh | |
# This script tries to mount the floppy drive, | |
# if not already mounted, and take appropriate action. | |
# Some helper functions: | |
# Counts down, then shuts down. | |
timer_down() { | |
echo 'shutting down in...' | |
i=5 | |
while test $i -gt 0 | |
do | |
echo "$i" | |
i=$((i-1)) | |
sleep 1s | |
done | |
# Tells the attached HDMI device to enter standby mode. | |
# Requires cec-utils | |
# echo standby 0 | cec-client -s -d 1 | |
sudo shutdown now | |
} | |
# Reports a failure | |
fail() { | |
echo "Floppy boot failed: $*." 1>&2 | |
timer_down | |
} | |
# Starts the normal desktop | |
pixel() { | |
lxpanel --profile LXDE-pi & | |
pcmanfm --desktop --profile LXDE-pi & | |
point-rpi & | |
} | |
# Launches PICO-8, shuts down when it closes. | |
# Launches a special launcher cart. Adjust for where you have PICO-8 installed. | |
pico8() { | |
~/pico-8/pico8_dyn -run '~/.lexaloffle/pico-8/carts/launcher.p8.png'; timer_down | |
} | |
# Launches DOSBox. | |
# I don't have this set up, so fail for now. | |
dosbox() { | |
fail 'DOSBox is not configured' | |
} | |
# Actual script: | |
# Check for the mounted floppy drive. | |
# This requires an entry for /media/floppy in /etc/fstab. | |
# Assuming your floppy is at /dev/sda, something like: | |
# /dev/sda /media/floppy vfat owner,group,umask=000,noauto,sync 0 0 | |
while ! (cat /proc/mounts | grep -Pq '\s/media/floppy/?\s' -) && ! sudo mount /media/floppy | |
do | |
# TODO: figure out something similar that doesn't require keyboard. | |
# retry a fixed number of times? | |
read -p 'No floppy disk found. Retry? [Y/n] ' -n1 retry | |
if (echo "$retry" | grep -iq n -) | |
then | |
timer_down | |
fi | |
done | |
# Get a listing of the files on the floppy | |
files=$(ls -1b /media/floppy) | |
# Autorun section. In theory this is dangerous, but who's going to troll you? | |
#autorun=$(echo "$files" | grep -Pim1 '^autorun(.sh)?' -) | |
#if test ! -z "$autorun" | |
#then | |
# echo "Autorun script. Launching /media/floppy/$autorun." | |
# /media/floppy/$autorun | |
#elif ... | |
# Check for a PICO-8 cart | |
if echo "$files" | grep -Piq '.p8(.png)?$' - | |
then | |
echo 'PICO-8 cart detected. Launching PICO-8.' | |
pico8 | |
# Check for a DOS executable, as an example | |
elif echo "$files" | grep -Piq '.exe$' - | |
then | |
echo 'EXE detected. Launching DOSBox.' | |
dosbox | |
# Other checks can be added here: launch emulators for game ROMs, etc. | |
else | |
# TODO: do something else since a user without mouse and keyboard is stranded. | |
echo 'Falling back to PIXEL environment.' | |
pixel | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This file lives at ~/startup.sh | |
# This script tries to mount the floppy drive, | |
# if not already mounted, and then boot PICO-8. | |
# Some helper functions: | |
# Counts down, then shuts down. | |
timer_down() { | |
echo 'shutting down in...' | |
i=5 | |
while test $i -gt 0 | |
do | |
echo "$i" | |
i=$((i-1)) | |
sleep 1s | |
done | |
# Tells the attached HDMI device to enter standby mode. | |
# Requires cec-utils | |
# echo standby 0 | cec-client -s -d 1 | |
sudo shutdown now | |
} | |
# Reports a failure | |
fail() { | |
echo "Floppy boot failed: $*." 1>&2 | |
timer_down | |
} | |
# Check for the mounted floppy drive. | |
# This requires an entry for /media/floppy in /etc/fstab. | |
# Assuming your floppy is at /dev/sda, something like: | |
# /dev/sda /media/floppy vfat owner,group,umask=000,noauto,sync 0 0 | |
if ! (cat /proc/mounts | grep -Pq '\s/media/floppy/?\s' -) && ! sudo mount /media/floppy | |
then | |
# Fail if the floppy drive can't be mounted. | |
fail "no floppy disk found." | |
fi | |
# Launches PICO-8, shuts down when it closes. | |
# Launches a special launcher cart. Adjust for where you have PICO-8 installed. | |
~/pico-8/pico8_dyn -run '~/.lexaloffle/pico-8/carts/launcher.p8.png'; timer_down |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment