Saturday, 28 March 2009 14:57

A while back, I had a need for a GUI frontend for the game emulator mednafen, so here's a quick and dirty bash script I wrote. It requires mednafen and Zenity.

#!/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

As it stands, this script does checks to see if the ROM file loaded is an NES ROM. If you're planning on playing other types of ROMs, you'll have to change the script to your tastes, as I only had NES ROMs to test this with.

Last Updated on Wednesday, 22 April 2009 21:53
 

Add your comment

Your name:
Comment:
  The word for verification. Lowercase letters only with no spaces.
Word verification:

The Joomla!® name is used under a limited license from Open Source Matters in the United States and other countries. Jeff Channell is not affiliated with or endorsed by Open Source Matters or the Joomla!® Project.

Santorum
Joomla Extensions