www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/04/29/12:08:01

Date: Mon, 29 Apr 1996 23:59:41 -0800 (GMT)
From: "Rafael R. Sevilla" <rsevilla AT upd DOT edu DOT ph>
To: mhommel AT trumpet DOT aix DOT calpoly DOT edu, DJGPP Mail Server <djgpp AT delorie DOT com>
Subject: Re: Help w/ timer
Message-ID: <Pine.SOL.3.91.960429232433.5929B-100000@sauron>
MIME-Version: 1.0

Yes, I've tried doing that before, and there are several things that you 
should know when making the timer tick really fast like that:

1. Your timer interrupt routine (which hooks to INT 08), should be written
in assembly language to make things as fast as possible. A timer routine
that takes too long is the fastest way to a red switch crash. And if you
don't have one...You have to write one. No way around it. Not doing so and
instead sitting around waiting for timer ticks is the easiest way to
create race conditions, and trust me, debugging code with race conditions
is the worst sort of debugging possible--even worse than memory leaks. 
Make the timer code as simple as possible and squeeze out every last 
cycle you can.

2. The timer routine should call the original INT 08 handler 18.2 times
every second, so as to keep the normal system functions operating. Of
course, if you're willing to suspend the normal system timer and
everything else while you're playing your WAV file it's just fine. Play
music in the background this way at your own peril! 

3. Disable ALL interrupts before hooking INT 8 and reprogramming the 
timer. This of course goes without saying. Reenable them when you're 
ready to rock.

4. When writing the timer interrupt code, take note that 11 kHz is 90.9
microseconds, or 4500 clocks at 50 MHz, and 22 kHz is 45us, or some 2250
clocks, and this is your deadline--your timer routine should finish
everything within this span of time, or else you risk a red switch crash. 
For lower clock rates you'll have even less cycles. With this sort of
deadline you can see why assembly language is stressed. And in order to
play music in the background you'll have to call the old INT 8 every so
often, and the length of a default INT 8 handler varies from system to
system, and it may not leave you with enough time before your 45us
deadline runs out. 

I've actually succeeded in making a fast timer that plays WAV files to 
the PC speaker, but this was before djgpp and protected mode programming, 
so I don't know what other problems might arise. If you wish I can 
privately mail you the code I wrote (in pure 8086 assembler of course, in 
TASM format), so you can see how this might be done. It's a little long 
(some 250 lines) so I don't feel I should post it to the djgpp newsgroup.

-------------------------------------------------------------------------
University of the Philippines                           Rafael R. Sevilla
PABX/OVCA: Diliman Networking Project          rsevilla AT sauron DOT upd DOT edu DOT ph
-------------------------------------------------------------------------



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019