Mail Archives: djgpp/1997/06/15/21:33:33
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.
- Raw text -