Stop the Presses, LJ Index and more.
Listing 1. sound.c
#include <math.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/soundcard.h>
int main(void)
  unsigned short int wave[44100]; /* our wavetable */
  int c; /* a counter */
  int out; /* audio out */
  /* open /dev/dsp for write only */
  out = open("/dev/dsp",O_WRONLY);
  /* now we use ioctl to set audio quality */
  c=16; /* 16 bits */
  c=1;  /* 1 channel */
  c=44100; /* 44.1KHz */
  /* this generates the wavetable of our sines
   * it's standard trig, so play around with
   * whatever crazy equations you want to hear!
  for (c=0; c<44100; c++) {
    wave[c] =8000*sin(220*2*M_PI*(c+13)/44100);
  /* now we write the wavetable to /dev/dsp
   * as though writing to a simple file
   * we'll loop for 5 seconds of sheer joy
  for (c=0; c<5; c++)
    write(out, wave, sizeof(wave));
  close(out); /* close /dev/dsp ! */
  return 0; /* satisfy gcc */

This listing is available by anonymous download in the file ftp.linuxjournal.com/pub/lj/listings/issue71/3836.tgz.

GAME FOCUS—>MAME Emulation of 1951 games

Imagine if computers had a use: if you could walk in, turn one on, and use it for something. Case in point: suppose that on your wall lived an enormous, flat panel monitor, and controlling it, a Linux box—very fast, faster even than normal. What to do? Revel in high culture! What's that, you say? Play games, that is, bigger and better than you've ever seen them before. What games? Antique games. Vintage games. Aged rarities. Far more than just games, these are cultural entities, which so many of us grew up with, and which once resided in arcades and pizza parlors when games cost a quarter to play. As is well-known, aging does a lot for software. Unlike people, who grow old and die, computer programs gain in energy with age, and when double-compiled and then stored in silicon casks for several years, the bits reduce and compress, leaving stronger elemental semiconductor properties, while taking out the fire. A fine vintage game is more fun than vi!

Oh, but arcade machines were often 6502-based, or even 68000-based (and a host of others); at any rate, not x86. How can we possibly run these programs, and where are we going to get the code? Fortunately, in 1997 a very cool Italian hacker by the name of Nicola Salmoria began a project to write an emulator for old hardware in order to preserve classic games so that they would never be forgotten, but enjoyed and shared around the world. Within a short time, MAME had grown to support over a thousand games, with 1951 at last count.

MAME can be played in X or console mode, and on several different platforms (including DOS, Macintosh and Amiga). You need to have a fairly fast machine in order to get the best performance on complicated games, but the farther back in time you go, the less processor-intensive the games are. If you have anything halfway decent in terms of hardware, you can enjoy the finer elements of computer culture.

The one problem is that MAME is only an emulator; it doesn't include the ROM images. You have to get ROMs, but apparently it is quite illegal (a felony) to duplicate these things. Hence, instead of openly distributing these images, we have to make secret hunts over the Web to find them. Fortunately, it's very easy to find huge ROM repositories, even though Dave's Classics, which used to be the most complete location, was coerced into taking the ROMs off-line a couple of years ago. Major gaming companies are upset with ROMs, probably since they see emulation ultimately encompassing the console games they currently make (or maybe they realize the older games are superior in game play anyway). Either way, it's a major greed issue. Many of them have taken steps to make emulation itself completely illegal, which would be such an abuse of government authority that it rather invalidates any arguments against ROMs based on “moral” or “ethical” grounds, since holding civil liberties hostage at corporate or economic whim is probably not ethical, and one who is flagrantly unethical has little validity to impose moral censure on others. But then, we've seen it before when lobbyists tried to make mpegs illegal, simply because the record industry might lose money, and without any regard to the technological implications of outlawing algorithms for being too efficient, let alone the civil libertarian issues involved.

Nevertheless, every now and then some fool makes a big fuss over emulation and how immoral it is, and tries to spoil everyone's fun, so we're forced to distribute games underground. I've always considered copyright law to be illegitimate. I even opted out of becoming a professional programmer because I decided it would be immoral for me to write proprietary software, so you can imagine where I stand on this issue. Nevertheless, the world is swarming with particularly evil people in whom the money drive has taken hostage all forms of reason and compassion, and these people are legally allowed to lock you in an iron cage for five years if you get convicted. In addition to stealing your life, the feds can abscond with $50,000 (or perhaps more) for every count. How's that for thievery? Maybe “piracy” is a better name for how the government behaves than for the act of duplicating bits. But I digress.

Games, games, games! We can have so much fun as long as no one catches on. Fortunately, even if the Web goes down, so many people have stockpiled ROMs and burned them onto CDs that you can probably get them from anyone. But what can we do to protect our hobby?

One technique that works is cyber-squatting; no, not bad-faith domain name squatting, but merely claiming the unused “property” as our own by using it. People took over abandoned farms after the plague, and no one complained. By mixing their labor (<\#224> la ESR's perennial favorite, John Locke), they made the farms their own (and MAME was certainly a lot of labor). Or we can use the law of the sea, sunken-treasure metaphor, whatever ways we can possibly think of to justify it! If we continue in this vein for long enough, the so-called “property” will fall into public domain on account of disuse. (The squatter tradition ensures that wasted resources are put to good use, and in the case of video games, these wasted treasures could bring so much entertainment to so many.) Get ready for homesteading the arcade-o-sphere.

Another technique is one that was most effective in the DeCSS situation. One Slashdotter called it the “whack the mole” phenomenon, whereby every time one site is closed, two more pop up. (The name comes from a popular carnival game where in poor little plastic moles get bopped.) What with Don Marti's Great International DVD Source Code Distribution Contest, maybe we'll find some truly clever ways to get information passed around. As with DeCSS and mpegs, authoritarians soon found it was impossible to win, and either gave up (with mpegs) or lost (with DeCSS). Commercial forces will fight hard on this one, and the situation is a bit unclear, nowhere near as pure as the GNU/Linux movement. Maybe it will even make the movement look bad if we participate in ROM trafficking, but we as a society have an interest in seeing that these games are preserved. After all, they are part of the culture of a developing technology and relate much about our times.

If, of course, you believe in “intellectual property” and that copyright restrictions have to be respected no matter what, or you just don't want to commit felonies, what should you do? Well, rather than writing hate mail or telling the teacher, just ignore MAME and go develop some completely free wares under the GPL. If you really have to say angry things and call people “pirates” and whatnot, there is a place for people like you: Usenet.

For the rest of us, let's dig in (archaeologically/anthropologically speaking) and enjoy! www.mame.net

—Jason Kroll