Geekism and gunkism

One of my ongoing projects is getting old computer games (particularly the old Windmill Software games) to run properly on modern hardware. One technique for doing this that I have recently been experimenting with is emulation - specifically, the Multiple Emulator Super System. This is almost there, as it features cycle-exact emulation of an 8088 processor and hardware-level emulation of a CGA card, thus getting the graphics and speed just right for these old games.

The one place MESS falls down is its emulation of the 8253 Programmable Interval Timer. This small but very important circuit exists almost unchanged in every PC ever made (as well as a number of other computers such as the Telenova Compis, the INDATA DAI, the Sharp MZ-700 and the Tesla PMD-85).

In modern operating systems, the 8253 is used by the task scheduler to interrupt whatever the machine is currently doing so that another program can get a chance at running, but these old games used it for advanced sound effects and "random" number generation. As such, they generally pushed it to the limits of its capabilities, so a very accurate emulation is needed to get these games to work properly.

The 8253 is well documented but unfortunately (though understandably) all the documentation available is written for people who want to program the thing or build a computer a which uses it, rather than for people who want to duplicate its functionality in an emulator. So there are a number of obscure edge-cases like "what happens if you do x, but half way through you do y" which aren't documented. In the interests of accuracy, I want to get these edge cases to work just as they would on the real hardware.

I'm finding myself having to do some real science to figure out the internals of this chip - formulating hypotheses and devising and running experiments to prove or disprove these hypotheses, and gradually constructing a "grand unified theory of the 8253" (if you will). Sometimes it's pretty straightforward, but other times tne observations must be made indirectly. For example, some of these experiments require timing as accurate as a millionth of a second, but this is a fraction of the time it takes to actually read data from or write data to the device in question. So the only way to do these experiments is to fire a whole load of data at the chip ("tuned" to maximize the probability of creating the desired event), record what comes back and then sort through the results (sometimes using statistical methods) to figure out if the edge case that I'm trying to reproduce actually happened, and if so what the result was. If the experiment is run enough times, hopefully the event I'm looking for will actually happen. It's quite a lot like doing high energy particle physics, except I'm searching for logic gates instead of Higgs bosons.


The bathroom sink was draining really slowly, so I decided to remove the U-bend and clean it out. You would not believe the evil things that lurked in there - a foul-smelling black, grey and green sludge held together with human hair. I would have taken a picture of it, but it was so unholy I doubt it would show up in photographs (like vampires in that respect). Hours and a long hot shower later, I still feel dirty.

One Response to “Geekism and gunkism”

  1. [...] finally got my 8253 timer project finished. One minor hurdle that I didn’t anticipate is that MESS’s abstraction of the [...]

Leave a Reply