Oldskooler Ramblings

the unlikely child born of the home computer wars

The crazy upside-down world of 8088 hardware programming

Posted by Trixter on March 28, 2007


I’m rewriting the 8088 Corruption player for the talk I’m giving at Block Party. No doubt this is a form of procrastination (I haven’t even done any PowerPoint slides yet) but I also have a fear of the player crashing when I’m showing it off, which would be a serious blow to my fragile ego. For one particular demonstration, I was going to wow the audience with a double-rate version of Corruption. Yes, 60 frames per second on an XT. The memory speed is there, but there’s so little CPU time left over that the poor disk can’t keep memory filled, and it rebuffers constantly — every four seconds, which is hardly fun to watch.

(This is going somewhere; trust me.)

Although it would be “cheating”, I have a hardware LIM EMS 4.0 board in my 8088 with 2MB of RAM in it. Last night I started to write a version of the player that buffered to EMS, then to system RAM where it could be transferred to CGA RAM. I figured, hey, maybe I can delay the rebuffering for a few more seconds for the presentation so I don’t look like an idiot.

I found that doing so was slower than simply reading the data from disk right into regular memory. You read that correctly: RAM buffering was slower than hard disk buffering. WTF?

I thought about why this might be, and when I figured it out, I started laughing. It’s a perfect example of just how wrong it is what I’m doing. Here’s the explanation:

  • Old IBM PCs have a DMA controller in them to move memory around instead of forcing the CPU to do it. On a PC/XT, it’s primarily used when reading from disk, because the slower the disk, the slower the transfer and the longer the CPU would be hung up. The DMA controller can move a byte of memory in one cycle, giving it a maximum memory move speed of about 960KB/s.
  • My hard disk, however, is not what the DMA chip was designed to help with — it’s a 340MB IDE drive connected to an 8-bit IDE controller. It’s about 5-10x faster than what was available in 1983. It maxes out around 300KB/s.
  • Moving memory around maxes out at a top speed of 240KB/s.

Do you see where this is going? I’ve put a hard disk in my machine whose transfer speed, thanks to copying help from the DMA controller, exceeds the CPU’s ability to move memory around. Let’s word that another way in case it’s not obvious: The hard drive is faster than the RAM.

That’s just wrong.

It is probably the only configuration in the entire IBM PC/compatible family where this is the case (where the hard drive is faster than RAM). Any 286 or higher, with its 16-bit memory accesses, would be faster at moving memory around. Crazy upside-down world of 8088 hardware!!

So I’ll use this newfound realization to write a DMA version of the player to keep memory filled while playing, right? Nope. The only way to do that is to switch to reading absolute disk sectors, and that means the player would work on my machine only. Not an option.

4 Responses to “The crazy upside-down world of 8088 hardware programming”

  1. qkumba said

    >The only way to do that is to switch to reading absolute disk sectors, and that means the player would work on my machine only.

    It would be more accurate so say that it would require a FAT partition on DOS, where caching the TS list is easy, and reading the hard disk is allowed, but it’s still a problem. :-)

  2. Trixter said

    It has nothing to do with the filesystem; the reason it would work on my machine only is because every controller’s low-level interface is different and I’d have to write code that works with my controller only (and my controller is an ADP-50, very uncommon).

    The speed improvement would be marginal anyway. The amount of DOS/BIOS overhead saved is tiny compared to the length of the transfer, and the CPU is still held up during the transfer so it’s not a “background” transfer anyway.

    Now, if I had a SCSI disk with a bus-mastering controller that used a memory window, it truly WOULD be in the background. But I have had terrible luck with 8-bit SCSI controllers on a regular XT. After my talk I’ll most likely pursue it :)

  3. anon said

    http://ced.kmitnb.ac.th/wws/micropro/8237/whatdma.htm

    “Note: The 8237 does allow two channels to be connected together to allow memory-to-memory DMA operations in a non-“fly-by” mode, but nobody in the PC industry uses this scarce resource this way since it is faster to move data between memory locations using the CPU. ”

    I guess that doesn’t apply to you…

    It looks like it’s almost time for Block Party. What’d solution did you come up with?

  4. Trixter said

    I didn’t — it plays for 4 seconds then loads for 4 seconds. I leave it as an exercise to the reader on how to optimize it (I will be suggesting one possible way at the end of the presentation).

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

 
%d bloggers like this: