Sunday, September 29, 2013

Compiling Snes9x on Ubuntu

After looking into the various SNES emulators available for Linux it looks like Snes9x is the only one that is of high quality and currently maintained. ZSNES seems to work pretty well, but it won't compile on 64-bit, giving you a very old emulator running as a 32-bit binary for the foreseeable future.

I used these instructions on a 64-bit Ubuntu 12.04 machine and a 32-bit Ubuntu 13.10 machine. There are two sets of instructions here. One is for compiling the Unix version of Snes9x and the other is for install the GTK3 version. Theses instructions worked perfectly on 12.04 but on 13.10 the GTK3 version segfaults. I don't know if the issue is with 13.10 or perhaps an incompatibility with my laptop's hardware and Snes9x GTK.

The currently maintained codebase of Snes9x is hosted up on github so we will need to install git. We'll get all the tools required to build the source code while we are at it.
sudo apt-get install git build-essential
Now we can check out the codebase.
git clone https://github.com/snes9xgit/snes9x.git
cd snes9x

Part 1 - Building the Unix version of Snes9x
The Unix version does not contain any sort of interface save for the running game itself. It supports a number of command-line switches. Unfortunately it does not seem to provide any way of running in fullscreen mode.

First we need the dependent libraries.
sudo apt-get install zlib1g-dev libpng12-dev xorg-dev
Now we can compile.
cd unix
autoconf
./configure --enable-netplay
make
sudo cp snes9x /usr/bin/
sudo chown root:root /usr/bin/snes9x
Now we have an executable binary named snes9x. You can go ahead and execute it passing in a SNES rom as the first argument or with no arguments for a list of acceptable options.

To create an entry in our desktop menu create the following file and save it as /usr/share/applications/snes9x.desktop
[Desktop Entry]
Version=1.0
Name=Snes9x
Comment=A portable, freeware Super Nintendo Entertainment System (SNES) emulator.
GenericName=Snes9x
Keywords=Games
Exec=snes9x
Terminal=false
X-MultipleArgs=false
Type=Application
Icon=/usr/share/pixmaps/snes9x.png
Categories=Game
StartupWMClass=Snes9x
StartupNotify=true
Finally, find an icon you want to use and save it as /usr/share/pixmaps/snes9x.png You can get a good icon to use here.
sudo wget http://maxolasersquad.com/snes9x.png -O /usr/share/pixmaps/snes9x.png

Part 2 - Building the GTK3 version of Snes9x
The GTK3 version includes a nice GTK interface with all sorts of configurable options, including fullscreen.

First we need to get the dependent libraries.
sudo apt-get install intltool autoconf automake libglib2.0-dev gawk libgtk-3-dev libxml2-dev libxv-dev libsdl1.2-dev libpulse-dev libportaudio-dev 
As of Ubuntu 15.10, instead of libportaudio-dev you need to install portaudio19-dev.
If you want a GTK2 build then install libgtk2.0-dev and you can leave out libgtk-3-dev.
Now we can generate the install scripts and compile.
cd gtk
./autogen.sh
./configure --with-gtk3
make

sudo cp snes9x-gtk /usr/bin/
sudo chown root:root /usr/bin/snes9x-gtk
You can leave out --with-gtk3 if you want a gtk2 build instead.

Now we have an executable binary named snes9x-gtk.

To create an entry in our desktop menu create the following file and save it as /usr/share/applications/snes9x.desktop
[Desktop Entry]
Version=1.0
Name=Snes9x GTK
Comment=A portable, freeware Super Nintendo Entertainment System (SNES) emulator.
GenericName=Snes9x GTK
Keywords=Games
Exec=snes9x-gtk
Terminal=false
X-MultipleArgs=false
Type=Application
Icon=/usr/share/pixmaps/snes9x.png
Categories=Game
StartupWMClass=Snes9x
StartupNotify=true
Finally, find an icon you want to use and save it as /usr/share/pixmaps/snes9x.png You can get a good icon to use here.
sudo wget http://maxolasersquad.com/snes9x.png -O /usr/share/pixmaps/snes9x.png

7 comments:

  1. For building newer versions of snes9x-gtk (1.56 and up) you need to install meson and sdl2.0 libraries

    ``sudo apt install meson ninja libsdl2-dev``

    Build instructions:

    cd to snes9x/gtk
    run: ``$ meson builddir``. It then will check for required libraries
    cd into builddir and run ``ninja``. And then will compile

    Cheers, and happy retrogaming!

    ReplyDelete
  2. Thank you Diego. I was stucked at the snes9x-gtk build!

    ReplyDelete
  3. hey theres no more ./autogen.sh, how do we install this thing now?

    ReplyDelete
    Replies
    1. Read the first coment

      sudo apt install meson libsdl2-dev
      cd to snes9x/gtk
      meson builddir
      cd builddir
      ninja
      sudo cp snes9x-gtk /usr/bin
      sudo chown root:root /usr/bin/snes9x-gtk

      Delete
  4. libpng12 is no longer in debian stable. you can work around this by downloading the source code and compiling it yourself. it should build fine with build-essentials installed.

    http://www.libpng.org/pub/png/libpng.html

    ReplyDelete
  5. on ubuntu impish you need to install gtkmm-3.0-dev as well

    before you run meson builddir be sure to run git submodule update --init !

    my comment above from 2 years ago about libpng12 still stands. the source code compiles quickly and easily.

    ReplyDelete
  6. also if you want to play zipped/compressed roms, you need to install the minizip dev packages

    ReplyDelete