From: Shawn Hargreaves Newsgroups: comp.os.msdos.djgpp Subject: Re: Timer interrupt Date: Sun, 15 Jun 1997 19:25:43 +0100 Organization: None Distribution: world Message-ID: References: <33A41FD6 DOT DBDF55C1 AT abc DOT se> NNTP-Posting-Host: talula.demon.co.uk MIME-Version: 1.0 Lines: 29 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Henrik Baarnhielm writes: >I am coding a player for RAD-files (adlib music) and I have to hook the >timer interrupt and reprogram the timer to tick faster. This means I >have to chain to the old interrupt routine, but not every time because I >reprogram the timer to tick 50 ticks/sec and the normal rate is 18.2 >ticks/sec. As you have noticed, the libc functions don't support wrappers that only sometimes need to chain to the original handler. You need to implement your own wrapper routine: for an example of how to do this, look at irq.c and irqwrap.s from Allegro. I just made the C routine return an integer: if it is zero the wrapper returns directly, otherwise it chains to the original handler. Writing a wrapper isn't really very hard, you just have to be careful about what order you initialise things in, and make sure you put them back afterwards. In particular you will need to switch to a custom stack, so you need to store the address of the original stack: _don't_ push this until after you've loaded your new stack pointer! :-) and remember that the selectors could contain anything at the start of your routine, so you need to use a %cs override unitl you've loaded a known value into %ds. Normally you should exit with an "sti ; iret", but you can use ljmp to call the old handler instead (at this point you should have put %ds back, so again a %cs override is needed). -- 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.