Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!hp4nl!dnlunx!dnlts!nugteren From: nugteren@pttrnl.nl Newsgroups: comp.sys.mac.programmer Subject: Problems installing interrupt handler (INIT part 2) Message-ID: <59949.27414ca8@pttrnl.nl> Date: 14 Nov 90 12:54:47 GMT Organization: PTT Research Neher Laboratories, The Netherlands Lines: 72 Hi, I have written an interrupt handler in Think C, that catches incoming characters from the serial port and manipulates these in the background (i.e. invisible to the user). It works fine as an application, but I am having troubles installing it in the background (memory resident etc.). I'm new to MacIntosh programming so I would appreciate any help greatly. The program is written in what I might be an unconventional way (and messy too), I'm not sure : The basic structure of the program is : _______________________________________________________________________________ ManipulateChars() /* this is the real interrupt handler */ /* it is called every time the serial driver*/ /* receives three characters */ { SaveRegisters(); /* assembly-stub : puts registers on stack */ SetUpA5(); /* Sets upreg A5 for globals */ DoYourThingWithChars(); /* main routine : uses incoming characters */ StartDriver(Async); /* Starts ROM Serial Driver, asynchronously */ /* Specifies ManipulateChars() as */ /* completion-routine */ RestoreA5(); RestoreRegisters(); /* Cleans up registers */ } main() /* main() is only called once. */ { InitialiseSerPort(); /* set's baud rate, parity etc. */ StartDriver(Async); /* Same function as above */ while(1){} /* Keeps program resident. It's got to go. */ } _______________________________________________________________________________ The function main() is only executed once. It initialises the serial port, sets baudrate etc.. Then StartDriver() opens ROM Serial Driver and starts it reading characters asynchronously. It specifies ManipulateChars() as completion routine, which is the actual interrupt handler. After this, the program is gets caught in a closed loop (which I put there to stop the Mac from leaving the program and releasing the memory). When a certain amount of characters has been received, the serial driver generates an interrupt and causes a jump to the completion routine ManipulateChars(). The program, when compiled as an application, works fine. Now, obviously ,I have to get rid of that closed loop, so the Mac can exit main() and get on with life. How can I get the Mac to leave main() without releasing the heap space? Also, the program must be combined with an INIT somehow, because it has to startup and install itself in the background in startup time. Should I convert the whole program to an INIT or create a loader INIT that loads the code in separately ? How do I go about this with Think C? The program uses global variables (but not QuickDraw). I gather this may be somewhat of a problem in an INIT. Or does Think C take care of this problem by using register A4 to address globals ? The program should stay resident indefinitely and not be reinitialised. Do I have to load it into the system heap? How do I do this with Think C ? If someone actually made it all the way through this letter, and can answer one/more/all of the above questions, I would be grateful indeed. Thanks in advance, Nils Nugteren.