A Trip Down 8-Bit Memory Lane

Trivia question: What is the only open-source project (that I know of, at least) where I am listed in the AUTHORS file?

Trivia answer: FCE Ultra, an open-source NES emulator.

Back in the day (around two years or so ago), the main FCEU code base’s Linux version only supported SVGALib for graphics, which didn’t play nicely at all with my GeForce 2 card. There was an unofficial branch that used SDL for graphics, but audio playback was annoyingly choppy. About that time SDL support was added to the main code base, but the joystick didn’t work. So, I had my choice of bad audio quality or no keyboard support.

Naturally, not knowing anything about programming with SDL, I decided to add joystick support to the main code base. It didn’t help that the code base at that time was particularly ugly — the author was actually #including .c files (!) — but I managed to get joystick support added in. It certainly wasn’t pretty, but it did the job. I sent in the patch and, lo and behold, it got merged in.

What does this have to do with anything? Fast forward to the present. All this time I’ve still been using version 0.76 of the program, since it was the last version where I could still get my joystick to work. After 0.76 the input drivers in the code got overhauled, and suddenly I couldn’t get the program to see what joystick axes I wanted to use when configuring it at start-up. In the meantime several new versions had been released, but I never messed around with trying to trace the problem down, mainly since I never had any problems with 0.76, so I never felt a compelling reason to upgrade. Plus, a while ago the main FCEU developer announced he was stopping work on it to move on to other things, and an effort to fork the code base and overhaul it apparently died out soon after being announced. (As far as I can tell, FCEU is still in some sort of limbo state, sort of being maintained by its author but without any real development going on besides the odd bug fix.)

So why did I start playing with the latest version again? In 0.76, the only two real graphics options were full-screen (which I didn’t like too much since it hid the rest of the desktop) and running in a non-scalable window (which I liked less because the graphics were tiny). The latest versions had working scaling, but like I said, joystick support had mysteriously broken, and the config file had changed enough to preclude just using the old one. Possibly out of boredom, I decided to figure out just what the problem was.

Long story short, doing a little stracing and diving back into the source code (which isn’t as ugly nowadays as it used to be), I found the root of the problem. At configure time, FCEU sets up the joystick by asking you to move the axis you want to use. In principle, this is an improvement over how my original hack had just asked you to type the number of the axis, since you didn’t need the obscure knowledge that, say, the D-pad on a Gravis Xterminator maps to axes 7 and 8. The problem here was that, to distinguish between jitter and meaningful input, the code looks for input beyond a certain threshold before deciding “aha, that’s the axis the user wants.” Now, the D-pad’s axes on my Xterminator range from -1 to 1; since they’re discrete instead of analog, a larger range naturally isn’t needed. Naturally, the configuration code assumes that anything that tiny must be jitter, and so it ignores all attempts to set up those axes. Curiously, the only axis the config code would recognize as non-jitter on my Xterminator was the throttle slider. Clearly that’s no good.

Now, the Linux version of FCEU has a real problem with user-friendly configuration. Unlike in the Windows version (IIRC), the Linux version has no GUI whatsoever. All configuration is done either by command-line switches and the saved configuration file. Joystick setup is done at startup the first time you run FCEU and is saved in the config file later; there’s no way (that I can see, at least) to reconfigure it through FCEU except for deleting the config file and running it again. Even better, the configuration file is in binary. Binary! And for no good reason, since everything is basically just name/value pairs. Luckily it’s not too erudite — another peek at the source reveals it’s just fprintfing the data — so knowing that and the byte order on your system, you could edit it.

So, what I ended up doing was configuring FCEU to use the throttle slider for both the x and y axes, quitting, using xxd to go a hex dump of the config file, modifying the two bytes that represented the axis configuration, and doing a reverse hex dump to create the modified config file. So now it seems to work.

(One might think that inputs seen as mere jitter by the configuration would also be seen as mere jitter by the main input routines, but apparently not. Lucky for me.)

In principle, I could figure out how to fix the joystick configuration to handle axes with smaller ranges (which, unless SDL can tell you the range of the axes itself, would leave the problem of distinguishing cases where +/- 1 is jitter versus cases where +/- 1 is your full range of input) and make the configuration file saner (i.e., editable by the end user without resorting to a hex editor. If I were really ambitious, I could even create a GUI for the program so you wouldn’t need to rely on hacking a config file and passing half a dozen flags on the command line to get the setup you want. But on the other hand, there are plenty of things more appealing than contributing to a project that is currently undead at best; for example, right now I’m playing around with programming in Gtk#, and I start working this Friday at my summer job, which will take away lots of my current unemployed free time. The only motivation that’d be left is if I hadn’t been able to get it to working despite those problems. Besides, if I really wanted to do a nonnegligible amount of work on an NES emulator, I’m not entirely sure I’d want it to be on the FCEU code base (though, to be fair, it may not be the largely uncommented, ill-documented, .c-file-#including mess it used to be two years ago, and maybe the project is more alive than I think it is).

One Response

  1. I have the same problem; except that I don’t even have a throttle slider, so I can’t get it to recognize any axis, so there’s nothing to hex-edit.

Comments are closed.