potts@itl.itd.umich.edu (Paul Potts) (06/26/91)
I need the advice of someone with a good understanding of register usage. Also, Rich Siegel and Jim Reekes, I have some questions for you. I am having severe problems with my sound objects crashing when built into code-resource (XFCN) form. I have done (I think) all the obvious things: set my code resource to multi-segment, RememberA0() and SetupA4(), lock the code resource while it is running, include ANSI-A4 instead of ANSI, etc. I am using the following routines from the THINK C library: sscanf() sprintf() strcpy (a version I re-wrote to do error-checking, in C and not assembly) strtok Most of the crashes I am getting seem to center around registers getting nuked. Part of the problem is that I don't have a good understanding of how registers are used in code resources. Here is what a couple of typical crashes looks like: - SndDoImmediate is called from one of my objects. It tries to do a JSR(a0) and jumps to a bad address (like 5ad2) and hits an illegal instruction. - SndNewChannel is called from one of my objects. Hypercard calls my XFCN, my XFCN's "main" calls one of my objects, my object does a JSR to something like $fad2(a4), which is a valid address, and then an address error occurs at SndNewCh +031c when it tries to test a bit referenced off of (a0). - SndNewChannel is called from one of my objects. Hypercard calls my XFCN, my XFCN's "main" calls one of my objects, my OpenChannel routine calls SndNewChannel, and I get a bus error while reading data from a bad location when SndNewChannel hits something like TST.W ($001e)A4. All of these crashes have something in common: a4 and a0 seem to be incorrect when they happen. I can pretty reliably produce one of these errors after a major context switch (If I switch Hypercard to the background, back to the foreground, and then try to play a tone again). But they happen in other instances too. Here are some questions: - Does the sound manager have a special need for register a4? If so, does this make it impossible for me to call the sound manager from an XFCN? Or can I preserve a4 and restore it after making sound manager calls? - Why is A0 getting trashed? - What registers do the ANSI-A4 routines sscanf() and sprintf() need? Is it possible that they are conflicting with my a0 and/or a4? - I have re-written strtok to use a2 and a3 instead of a0 and a1. Is this the right approach? What are the approved registers to use? Sorry these are such amateurish questions. I've not been programming the Mac for all that long. Thanks in advance for any help you can give. -Paul Potts- potts@itl.itd.umich.edu Paul_Potts@um.cc.umich.edu