Thursday 3 July 2008

A perfect Linux MAME cab installation

Debian


First, the Debian installation. Wherever possible I've taken the simplest options, such as using ftpd and telnetd rather than more elaborate remote administration tools. Any hacks have been done in the correct Debian fashion and are on show for anyone to see and adapt.


Installation


This example uses Debian Linux 4.0 (etch). Whatever method you choose to install with, choose defaults throughout except with the below:



  • Hostname can be whatever you like, I choose mame

  • Domain should normally be set to example, test, or invalid. If you want to know why, read RFC 2606. You'll know if it needs to be set to anything else!

  • When partitioning, change the mount options to noatime,sync.

  • Create a new user account called mame.

  • When asked about "Software selection" unselect everything.


Customisation


After the forced reboot, we run through the steps needed to tweak the OS for our needs.



  1. Get our system bang up to date: aptitude update && aptitude dist-upgrade

  2. Install tools we'll need: aptitude install telnetd ftpd fbset mingetty

  3. Move the installed /etc/fb.modes somewhere safe: mv /etc/fb.modes /etc/fb.modes.sample

  4. Enable the framebuffer. This can be done in three ways: compiling one or more drivers into the kernel and loading the appropriate one at boot (hardest), by adding one or more as modules to the initial RAM disk and loading at boot (easier), or by loading them in the startup scripts (easiest). I add them all to the startup scripts, it's the quickest and easiest to fix.

    • You'll need to identify what modules are available: ls -R /lib/modules/`uname -r`/kernel/drivers/video/ | grep .ko | sed s/.ko// | sort. Currently, the list I use is: arcfb aty128fb atyfb cirrusfb cyber2000fb cyblafb gx1fb gxfb hgafb i810fb intelfb kyrofb matroxfb neofb nvidiafb pm2fb radeonfb s1d13xxxfb savagefb sisfb sstfb tdfxfb tridentfb. Not all of these have been tested on an arcade monitor, but all should be suitable for PC use.

    • This will help you identify what hardware is in the machine: lspci | grep VGA

    • To load modules via the initial RAM disk (initrd):

      1. nano -w /etc/initramfs-tools/modules

      2. update-initramfs -u



    • To load modules from the startup scripts: nano -w /etc/modules.



  5. Logging in automatically as the mame user is accomplished by editing /etc/inittab (we're replacing getty with mingetty for tty1 - the first console - and setting the mame user to automatically login): sed -ie 's,getty 38400 tty1,mingetty --autologin=mame tty1,g' /etc/inittab

  6. Giving root telnet and ftp access is bad security practice - but it makes our lives a bit easier when setting up the system. You could always skip this and use su, or reverse the changes once you're happy with everything.

    • nano -w/etc/securetty and add the following:

      # Telnet
      pts/0
      pts/1
      pts/2
      pts/3
      pts/4
      pts/5
      pts/6
      pts/7
      pts/8
      pts/9

    • Allow root ftp access: sed -i 's/\#root/root/g' /etc/ftpusers



  7. To stop DHCP taking an age when not connected to a network, edit /etc/network/interfaces and replace the keyword "auto" with "allow-hotplug" except on the loopback interface (lo)

  8. We want to add some fake kernel parameters to our grub menu. This tells update-grub to add extra boot options other than the standard and single user. /proc/cmdline contains the boot parameters and we can run scripts based on this to configure the system automatically.

    1. Edit /boot/grub/menu.lst. add extra #altoptions = lines as follows:

      # altoptions=(15.75kHz Horizontal) hclock=15.75 fbcon=rotate_all:0
      # altoptions=(15.75kHz Vertical) hclock=15.75 fbcon=rotate_all:1
      # altoptions=(16.5kHz Horizontal) hclock=16.5 fbcon=rotate_all:0
      # altoptions=(16.5kHz Vertical) hclock=16.5 fbcon=rotate_all:1
      # altoptions=(25kHz Horizontal) hclock=25 fbcon=rotate_all:0
      # altoptions=(25kHz Vertical) hclock=25 fbcon=rotate_all:1
      # altoptions=(31.5kHz Horizontal) hclock=31.5 fbcon=rotate_all:0
      # altoptions=(31.5kHz Vertical) hclock=31.5 fbcon=rotate_all:1
      # altoptions=(15.75+25+31.5kHz Horizontal) hclock=15.75+25+31.5 fbcon=rotate_all:0
      # altoptions=(15.75+25+31.5kHz Vertical) hclock=15.75+25.31.5 fbcon=rotate_all:1

    2. Change the "default" line to read "saved" instead of "0". This will remember our previous selection and use this for the next boot.

    3. Add a line right at the top of the file that reads: setkey enter control This maps the Enter key to the standard MAME entry for P1B1 - the Left Control key. Enter is still found at it's default position. We can now change the boot option using a keyboard or a MAME mapped joystick!

    4. Save the file, then run update-grub to commit the changes.



  9. Create arcade script:

    1. nano -w /etc/init.d/arcade



    2. #! /bin/bash

      case "$1" in
      start)
      # Modelines
      if grep hclock=15.75+25+31.5 /proc/cmdline > /dev/null ; then
      echo "Using 15.75+25+31.5kHz modelines..."
      ln -sf /etc/fb.modes.15.75+25+31.5 /etc/fb.modes
      elif grep hclock=15.75 /proc/cmdline > /dev/null ; then
      echo "Using 15.75kHz modelines..."
      ln -sf /etc/fb.modes.15.75 /etc/fb.modes
      elif grep hclock=16.5 /proc/cmdline > /dev/null ; then
      echo "Using 16.5kHz modelines..."
      ln -sf /etc/fb.modes.16.5 /etc/fb.modes
      elif grep hclock=25 /proc/cmdline > /dev/null ; then
      echo "Using 25kHz modelines..."
      ln -sf /etc/fb.modes.25 /etc/fb.modes
      elif grep hclock=31.5 /proc/cmdline > /dev/null ; then
      echo "Using 31.5kHz modelines..."
      ln -sf /etc/fb.modes.31.5 /etc/fb.modes
      else
      echo "No monitor type chosen, using generic PC VGA..."
      fbset --all -match -xres 640 -yres 480
      ln -sf /etc/fb.modes.sample /etc/fb.modes
      fi

      # Rotation
      if grep fbcon=rotate_all:0 /proc/cmdline > /dev/null ; then
      echo "Using horizontal monitor..."
      # Console
      echo 0 > /sys/class/graphics/fbcon/rotate_all
      # MAME
      sed -i 's/^rotate *0/rotate 1/g' /home/mame/.mame/mame.ini
      sed -i 's/^ror *1/ror 0/g' /home/mame/.mame/mame.ini
      # AdvanceMENU
      sed -i 's/vertical include$/vertical exclude$/g' /home/mame/.advance/advmenu.rc
      sed -i 's/vertical exclude_not$/vertical exclude$/g' /home/mame/.advance/advmenu.rc
      elif grep fbcon=rotate_all:1 /proc/cmdline > /dev/null ; then
      echo "Using vertical monitor..."
      # Console
      echo 1 > /sys/class/graphics/fbcon/rotate_all
      # MAME
      sed -i 's/^rotate *0/rotate 1/g' /home/mame/.mame/mame.ini
      sed -i 's/^ror *0/ror 1/g' /home/mame/.mame/mame.ini
      # AdvanceMENU
      sed -i 's/vertical include$/vertical exclude_not$/g' /home/mame/.advance/advmenu.rc
      sed -i 's/vertical exclude$/vertical exclude_not$/g' /home/mame/.advance/advmenu.rc
      else
      echo "Using rotate mode (vertical on horizontal)..."
      # MAME
      sed -i 's/^rotate *0/rotate 1/g' /home/mame/.mame/mame.ini
      sed -i 's/^ror *1/ror 0/g' /home/mame/.mame/mame.ini
      # AdvanceMENU
      sed -i 's/vertical exclude_not$/vertical include$/g' /home/mame/.advance/advmenu.rc
      sed -i 's/vertical exclude$/vertical include$/g' /home/mame/.advance/advmenu.rc
      fi
      ;;
      stop)
      echo "Clearing fb.modes..."
      ln -sf /etc/fb.modes.sample /etc/fb.modes
      echo "Clearing rotation..."
      # MAME
      sed -i 's/^rotate *0/rotate 1/g' /home/mame/.mame/mame.ini
      sed -i 's/^ror *1/ror 0/g' /home/mame/.mame/mame.ini
      # AdvanceMENU
      sed -i 's/vertical exclude_not$/vertical include$/g' /home/mame/.advance/advmenu.rc
      sed -i 's/vertical exclude$/vertical include$/g' /home/mame/.advance/advmenu.rc
      # Console
      echo 0 > /sys/class/graphics/fbcon/rotate_all
      ;;
      *)
      echo "Usage: /etc/init.d/jamma {start|stop}"
      exit 1
      ;;
      esac

      exit 0

    3. Make it executable: chmod +x /etc/init.d/arcade

    4. Run automatically on boot: update-rc.d arcade defaults 50



  10. Edit udev permissions so that any user can write to the framebuffer tty

    1. nano -w /etc/udev/permissions



    2. KERNEL=="tty0", MODE="0666", GROUP="root"
      KERNEL=="tty[1-9]*", GROUP="root"



  11. Edit the mame user login script

    1. nano -w /home/mame/.bash_profile

    2. Add the following lines:

      export SDL_VIDEO_YUV_DIRECT=1
      export SDL_VIDEODRIVER=directfb
      export SDLMAME_DESKTOPDIM=640x480
      export DFBARGS=depth=16,no-debug,no-trace,desktop-buffer-mode=frontonly,no-cursor,no-banner,quiet,dma,sync,no-vt-switch,disable-module=x11,disable-module=joystick,disable-module=linux_input,bg-color=000000
      advmenu




SDLMAME



  1. Install SDL: aptitude install make libsdl-dev libgconf2-dev Sadly the development libraries for SDL in Debian depend on huge amounts of other packages, but these are only needed for compiling! Once compiled, you can happily purge the above packages, and install libsdl by itself.

  2. Grab the source from http://rbelmont.mameworld.info/?page_id=163.

  3. Decompress: 7z x sdlmame*.zip

  4. cd sdlmame*

  5. A small change is needed to the source to get it to compile on Debian:

    1. nano -w src/osd/sdl/sdlsync.h

    2. Change #define THREAD_COOPERATIVE (1) to #define THREAD_COOPERATIVE (0).



  6. Compile:

    1. make clean

    2. make NO_X11=1 NO_OPENGL=1




Notes



  • Enable switchres in mame.ini. Enable window in mame.ini

  • You can optimize disk performance with hdparm. Be careful and read the documentation!

    1. aptitude install hdparm

    2. Check performance with: hdparm -Tt /dev/hda

    3. nano -w /etc/conf.d/hdparm

    4. invoke-rc.d hdparm start

    5. Check performance again



  • Changing the system volume is done with the tool alsamixer. Use the m key to unmute a channel and set a sensible volume. AdvanceMAME normalises game volume so you don't need to touch volume inside it.

  • Trimming down disk usage:

    1. aptitude install localepurge

    2. aptitude purge tasksel tasksel-data cron logrotate info man-db manpages ed vim-common vim-tiny installation-report iptables netcat libsasl2 dictionaries-common ispell usbutils laptop-detect dmidecode eject ibritish myspell-en-gb wbritish util-linux-locales groff-base bsdmainutils



  • If the install was done with a netinst CD, or you simply want to use internet sources only, comment out the CD-ROM entry in /etc/apt/sources.list

  • Compiling a custom kernel

    1. Install tools necessary to recompile the kernel: aptitude install kernel-package linux-source build-essential libncurses5-dev bzip2

    2. Decompress kernel sources:

      1. tar jxf /usr/src/linux-source-*.tar.bz2

      2. cd /usr/src/linux-source*



    3. Edit /etc/kernel-pkg.conf with your personal details if desired

    4. Clean up any old compile data and use the current kernel configuration:

      1. make-kpkg clean

      2. cp /boot/config-`uname -r` ./.config



    5. Make changes to the kernel configuration: make menuconfig

    6. Compile your custom kernel: make-kpkg --initrd kernel_image kernel_headers

    7. Install custom kernel: dpkg -i kernel-image-x.y.z.yy.mm.dd_10.00.Custom_i386.deb



Labels: , , , ,

1 Comments:

Blogger Unknown said...

Hi there, I'm trying to get my arcade monitor working but I'm hitting a stumbling block. All I get on the screen is a garbled mess. I think I'm missing some files:

in the line:

ln -sf /etc/fb.modes.15.75+25+31.5 /etc/fb.modes

I don't have any fb.modes.15... files there al I had was fb.modes which I moved as suggested.

Any ideas?

19 May 2009 at 22:07  

Post a Comment

Subscribe to Post Comments [Atom]

<< Home