[comp.lang.c] Replacing INT9 in C

<ACPS2924@Ryerson.Ca> (01/13/91)

Im writing an event manager and can't figure out how to replace INT9
the vector IRQ1 acts on with a key press.  All I want to do is when
the user presses a key I want to immediately remove it from the keyboard
buffer and place it in the event queue.  I know I have to replace
the INT9 vector.
So far I replace the INT9 with the following, in the new interrupt I call
the old interrupt 9 to do good housekeeping and then call INT16 to get
the key from the queue.  Low and behold big crash, why I dont know???
All this is being written in Turbo C++.  Any help would be most helpfull.
Anything Hints Suggestions Code fragments , even dread, assembler hints
would help.

Thanks in advance..

Peter
ACPS2924@ryerson.ca (Mailing address, it usually works)

dave@tygra.ddmi.com (David Conrad) (01/15/91)

In article <91013.015911ACPS2924@Ryerson.Ca> ACPS2924@Ryerson.Ca writes:
>So far I replace the INT9 with the following, in the new interrupt I call
>the old interrupt 9 to do good housekeeping and then call INT16 to get
>the key from the queue.  Low and behold big crash, why I dont know???
>
>Peter
>ACPS2924@ryerson.ca (Mailing address, it usually works)

Why are you replacing INT9?  Why not just replace INT16?  Also,
what's a `big crash'?  What exactly is happening?
--
David R. Conrad
dave@tygra.ddmi.com
-- 
=  CAT-TALK Conferencing Network, Computer Conferencing and File Archive  =
-  1-313-343-0800, 300/1200/2400/9600 baud, 8/N/1. New users use 'new'    - 
=  as a login id.  AVAILABLE VIA PC-PURSUIT!!! (City code "MIDET")        =
   E-MAIL Address: dave@DDMI.COM

martino@logitek.co.uk (Martin O'Nions) (01/16/91)

ACPS2924@Ryerson.Ca writes:

...

>So far I replace the INT9 with the following, in the new interrupt I call
>the old interrupt 9 to do good housekeeping and then call INT16 to get
>the key from the queue.  Low and behold big crash, why I dont know???
>All this is being written in Turbo C++.  Any help would be most helpfull.
>Anything Hints Suggestions Code fragments , even dread, assembler hints
>would help.

Not guarenteed, but stack problems are the most likely. Getting an asynchronous interrupt to call C is a problem, as your C code will use the stack present
when the H/W int was generated, rather than the one the compiler intended.
Couple this with the fact that all interrupts will do a far call, so small
model C wil look at the wrong place on the stack for the return address, and
the fact that your code almost certainly doesn't push all the registers it uses
and you end up with a real problem.....

I normally write an assembler 'wrapper' when I need to do this sort of thing.
You need to do:

	1. Restore Interrupts (unless you want to risk your clock ticks...)
	2. Store the stack segment and pointer SS/SP in local space
	3. Load SS and SP from local space (point them to an area reserved
	   by your code for the stack)
	4. Push everything your C uses! (compile to assembler first, then
	   check)
	5. Call your C code, using an appropriate model call (near or far)
	6. On return from the C, pop the saved registers
	7. Swap SS and SP back again
	8. Do an IRET to go back to the foreground process.

The above uses the phrase C code to refer to object code compiled from C - no
flames by request.

If you want any more detail, or just disagree, please feel free to mail me
( posting is not a guarenteed way to reach me - I woory about my News feed at
times!)

Have fun!

Martin

--
DISCLAIMER: All My Own Work (Unless stated otherwise)
--------------------------------------------------------------------------
Martin O'Nions            Logitek Group Support      martino@logitek.co.uk
--------------------------------------------------------------------------
There's been an accident they said/Your servant's cut in half - he's dead!
Indeed said Mr Jones, then please/Send me the half that's got my keys.
         (Harry Graham - Ruthless Rhymes for Heartless Homes)