Saturday, December 15, 2012

Mednafen + Zenity - NES Quick Emulator GUI

I got this bash script over at Jeff Channell's Blog. To get it fully functional you'll need both mednafen and zenity installed, to do so in Ubuntu derivatives open up a terminal and enter:
[sourcecode language="bash"]
user@com$ sudo apt-get install mednafen zenity
[/sourcecode]

Then Jeff's script, I suggest assigning this as a .bashrc alias like `nes` or the like.
[sourcecode language="bash"]
#!/bin/bash

# NES Rom Browser
# Jeff Channell, 5.07.2006

medgui_conf=~/.medgui

function medgui_start ()
{
touch $medgui_conf
zenity --question --title="Default Rom Directory?" --text="Press OK to select a default rom folder, or hit Cancel to always use your Home directory."
case $? in
0)
ROMPATH=`zenity --file-selection --directory --title="Select Default ROM Directory"`
;;
*)
ROMPATH=~/
;;
esac
echo "ROMPATH=$ROMPATH" >> $medgui_conf
}

if [ -e "$medgui_conf" ]
then
ROMPATH=`sed -n '/^ROMPATH=/p' $medgui_conf | sed -e 's/^ROMPATH=//'`
else
zenity --question --text="No config file found. Would you like to create one?"
case $? in
0)
echo "Creating file"
medgui_start
;;
1)
echo "Error: Cannot find default config!"
exit 2
;;
esac
fi
cd $ROMPATH
SELECTEDROM=`zenity --file-selection --title="Select An NES Rom File..."`
case $? in
0)
if [ -e "$SELECTEDROM" ]
then
file "$SELECTEDROM" | grep NES
case $? in
0)
mednafen -nes.no8lim 1 -nes.stretch 1 -nes.xres 1024 -nes.yres 768 "$SELECTEDROM"
;;
*)
zenity --error --text="The selected file does not appear to be an NES rom file!"
exit 1
;;
esac
else
zenity --error --text="Error: File Does Not Exist!"
exit 1
fi
;;
1)
echo "No rom selected. Exiting...";;
-1)
echo "No rom selected. Exiting...";;
esac
[/sourcecode]

No comments:

Post a Comment