From: Shawn Hargreaves Newsgroups: comp.os.msdos.djgpp Subject: Re: Sound problem - Allegro, etc... Date: Mon, 20 Oct 1997 20:26:33 +0100 Organization: None Distribution: world Message-ID: References: NNTP-Posting-Host: talula.demon.co.uk MIME-Version: 1.0 Lines: 62 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Alistair Bain writes: >I'm programming modex and have the routine running at 60fps no problem. >As soon as I initialise the sound I start getting jerks in the motion, >if I cut the number of sprites down to, say, 1 then I still get the same >problem, what's going on?!! Being in mode-X, you are probably using some kind of page flipping system, right? I can explain what is causing the problem, but I'm afraid I don't have any easy answer about how to fix it :-) Probably the worst thing about the PC hardware is that there is no interrupt for the video retrace, so you have to poll a status bit to determine when it is taking place (actually a few cards do support an interrupt, but not in a sufficiently standard or widespread way for it to be useful). So any time that your program syncs with the retrace, or does a page flip (which requires a retrace sync to know when the flip has taken place), it has to sit there in a little loop polling the retrace bit in the VGA card until it changes from a zero to a one :-) The trouble is, if a soundcard interrupt comes along at the wrong time, it is possible for the soundcard handler to get control just as the retrace begins, and release control just after it is finished, so this little poll loop never notices that the retrace has occured. Result: it waits until the next retrace, and your animation skips a frame. How to avoid this is a big problem, and there are no easy answers... Fix #1: don't use Win95. This problem seems to be far less frequent in a clean DOS environment, I've no idea why. Fix #2: don't sync with the retrace at all :-) That is just ducking the issue, but it does work! Maybe you could provide both a mode-X page flipping system, and a simple RAM->VRAM double buffer without any retrace sync, and let people choose whichever works best. Some machines (like mine) never suffer from the problem, I suppose because the soundcard processes quickly enough, or the retrace interval lasts longer than normal, while on other systems it seems to happen all the time... Fix #3: do clever things with the timer chip to detect when the retrace should be. Allegro can do this in a clean DOS environment (use the timer_simulate_retrace() function), but unfortunately that doesn't work under Win95 because Microsoft don't provide good enough emulation of the PIT hardware. Try running the Allegro demo.exe in a mode-X resolution, though, and notice the difference between when you select the retrace synced vs. normal page flipping modes... Fix #4: (hypothetical, not yet any use at all :-) Wait a year or so until you can use the VBE 3.0 or VBE/AF 2.0 interfaces. Neither of these has yet been ratified, let alone actually implemented, and I've yet to see a copy of the specs, but according to Kendall Bennett (from SciTech) they both provide a triple buffering mechanism. This will allow you to request a page flip, carry on doing other stuff in your mainline code, and then at some later point poll the video card to see if the flip has yet occured. This will be a kind of "dirty" flag rather than a "retrace in progress" bit, so it won't matter if you are a little bit late in detecting it, and all our problems will be solved! I don't think this is possible with the standard VGA register set, though, so it will probably only work on SVGA boards and will need a driver like UniVBE... -- Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/ Beauty is a French phonetic corruption of a short cloth neck ornament.