Back to home page

DOS ain't dead

Forum index page

Log in | Register

Back to the forum
Board view  Mix view

Waiting for 3 (or 3.3) microseconds? 286 and up. (Developers)

posted by Rugxulo Homepage, Usono, 10.12.2012, 22:03

Hi, (not sure why Eric expects me to know anything, I'm quite far from expert)

> Context. I've been playing with Sound Blaster coding, so far in DOSBox.

Is this meant to be widely deployed? I mean, are there real machines that will be running this? SoundBlaster is quite rare on actual hardware these days except on old machines.

> The initialization routine is supposed to wait for 3 or 3.3 microseconds
> between the first two writes for the actual hardware.
>
> What is a good way to guarantee a wait for a few microseconds? Can I use
> the same code on a 286 while still guaranteeing long enough delay on a
> 64bit cpu who happens to be talking to a real sound blaster in an ISA slot?
> Those motherboards exists [even though I don't have one, nor a real sound
> blaster].

I think SoundBlaster is dead, I don't think (m)any people will use it. Sure, it's well-documented, even fun (I guess, never tried) to program for it, but it's fairly useless. Not trying to discourage you, just being realistic. :-/

> So far, I've just used interrupt 0x15 with ah=0x86 for a 1000 microsecond
> delay; which is long enough though quite excessive.

I'm still not sure if you intend this to work on real hardware (actual 286?) or just anything you can find (DOSBox). For instance, I don't think WinXP supports int 15h, 86h very well. And of course DOSBox isn't accurate timings at all. I think every instruction in DOSBox takes only a single (virtual) clock cycle. So it's not reliable for timings (and only simulates a fast 486 or slow 586, at best).

> I believe I'm looking at the official documents, where they use a delay
> loop of "dec al; jnz delay" where al has been initialized to 0. Hence
> looping 255 times. I'm not sure that method is "future proof" or even
> sufficient with a modern CPU.

Older in-order cpus (e.g. 486) were less sensitive to wonky timing variations since they didn't have as aggressive power management and were more commonly used in single-tasking DOS days. You could 99% reliably check the timings of their x86 instructions from documents, unlike today.

> Also related. The Sound Blaster is said to take 100 microseconds to
> initialize itself. What steps can I take to wait just that long until
> there is 0xaa from the status port of the card? Again, those steps should
> ideally work on both real 286 and a modern CPU.

Do you have a real 286 for testing? I imagine they are hard to find on eBay, at least in decent working order and reasonably priced. All the world's a VAX (32-bit) these days, so nobody cares for 16-bit anymore. But it shouldn't be too hard to look up docs for 286 (e.g. OpenWatcom's FTP site has the 286 and 287 manuals, IIRC). It should list the instruction timings. And from there is shouldn't be hard to measure. It might even be (vaguely) possible to find out all the speeds of every 286 clone in existence. Surely there couldn't have been that many variations.

> (Wikipedia):
> After the 6 and 8 MHz initial releases, it was subsequently scaled
> up to 12.5 MHz. (AMD and Harris later pushed the architecture to
> speeds as high as 20 MHz and 25 MHz, respectively.) On average,
> the 80286 had a speed of about 0.21 instructions per clock.[3]
> The 6 MHz model operated at 0.9 MIPS, the 10 MHz model at 1.5 MIPS,
> and the 12 MHz model at 2.66 MIPS.

As for a delay, not sure, but I'm naively guessing a slow DIV instruction or two would be good enough. Heck, even the 386, at fastest, could only do a single instruction in two clocks, so the 286 must be easier to write slowdown routines. But if you are targeting both real 286s, DOSBox, and modern 4 Ghz AMD64-capable machines, you're probably asking a bit too much.

 

Complete thread:

Back to the forum
Board view  Mix view
22762 Postings in 2122 Threads, 402 registered users (0 online)
DOS ain't dead | Admin contact
RSS Feed
powered by my little forum