Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!apple!apple.com!rmh From: rmh@apple.com (Rick Holzgrafe) Newsgroups: comp.sys.mac.programmer Subject: Re: HELP - Asynchronous Sound Manager Calls Message-ID: <12153@goofy.Apple.COM> Date: 18 Feb 91 23:10:59 GMT Sender: usenet@Apple.COM Organization: Apple Computer, Inc. Lines: 36 References:<6797@munnari.oz.au> <9102180558.AA13374@enuxha.eas.asu.edu> In article <9102180558.AA13374@enuxha.eas.asu.edu> trotter@ENUXHA.EAS.ASU.EDU (Russell T. Trotter) writes: > Make sure your callback routine is > doing the "right " thing with A5 and all. Russell's right - let me explain a bit. Your program (all Mac programs) access their code and global variables via offsets from the value of register A5. The Mac sets up A5 for you just before your program begins, and MultiFinder makes sure it's always correct when you're running in the foreground, or when you're given time to run in the background. But when other apps are running, A5 is set for *their* code and data. And the catch is that async completion routines happen below MultiFinder's level - so A5 is not guaranteed correct when these routines run. A simple solution for you, since your routine needs to access only one variable, is to declare a record that contains (first) the sound managerparameter block, followed by a pointer to your "soundIsDone" variable. Initialize that pointer before calling SoundPlay. The sound manager won't mind the extra baggage on the parameter block; it will just look at what it needs and ignore the rest. When your completion routine is called, retrieve the pointer and use it to set the variable; this avoids any use of A5. It's also possible to pass the value of A5 itself, set it, and then access your code and globals as usual. When you're done, you *must* restore the former A5 before exiting. Hope this helps. ========================================================================== Rick Holzgrafe | {sun,voder,nsc,mtxinu,dual}!apple!rmh Software Engineer | AppleLink HOLZGRAFE1 rmh@apple.com Apple Computer, Inc. | "All opinions expressed are mine, and do 20525 Mariani Ave. MS: 3-PK | not necessarily represent those of my Cupertino, CA 95014 | employer, Apple Computer Inc."