Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!unisoft!hoptoad!tim From: tim@hoptoad.uucp (Tim Maroney) Newsgroups: comp.sys.mac.programmer Subject: Re: Standard File and Desk Accessories Message-ID: <7635@hoptoad.uucp> Date: 12 Jun 89 23:30:45 GMT References: <50967@tut.cis.ohio-state.edu> <7547@hoptoad.uucp> <4972@umd5.umd.edu> <51276@tut.cis.ohio-state.edu> <2015@husc6.harvard.edu> <1241@speedy.mcnc.org> <2024@husc6.harvard.edu> <13855@dartvax.Dartmouth.EDU> <7610@hoptoad.uucp> <13870@dartvax.Dartmouth.EDU> Reply-To: tim@hoptoad.UUCP (Tim Maroney) Organization: Eclectic Software, San Francisco Lines: 87 In article <13870@dartvax.Dartmouth.EDU> earleh@eleazar.dartmouth.edu (Earle R. Horton) writes: > "Scratch20, Scratch8, and ToolScratch will not be preserved across > calls to the routines in the Macintosh ROM. ApplScratch will be > preserved; it should be used only by application programs and not > by desk accessories or other drivers." > Phonebook: Assembly Language Programming Chapter > > Standard File makes a whole bunch of ROM calls. This means that >the three scratch areas dedicated to tool use cannot be used. Thanks for the correction. (But are you really still using the phone book?) >Saving >and restoring the value at location zero (an interrupt vector) will >not work across Standard File, because background tasks are allowed to >run while Standard File is active, and lots of tasks will have a >chance to see it. (I'm assuming MultiFinder here.) I'm satisfied with saying that you can't use location zero because it's blecchy, but as someone else pointed out, what if other software also wants to use it? Anyway, I think it goes without saying that any location in the first page belongs to the OS and should be used only in explicitly sanctioned ways. (By the way, it's not an interrupt vector, exactly. It's the reset vector, but due to the way the Mac maps memory, it will never be consulted from RAM. I can't find a reference, but during reset, the ROM is mapped in at address 0.) > It's not nice to use ApplScratch, even though you think it >extremely unlikely that the application will need it during the >Standard File call. What if the call to Standard File causes the >application's grow zone function to be called, and the grow zone >function uses ApplScratch? True, but pretty obscure. I think I could live with this level of compatibility. Grow zone routines ought to use globals anyway; they are guaranteed to find the proper A5 in CurrentA5. >Grow zone functions are just an example; >my point is that it is possible for the code of the current >application to get control in the midst of a call to Standard File. Other than the grow zone routine, how? > ToolScratch is definitely out, given what IM says about its >volatility. Yes. >ApplScratch is out, too, because it is just barely >possible for the application code to need or modify it during the call >to Standard File. Murphy's Law equates "just barely possible" with >"will happen," as I am sure you know already. Murphy's Law is a joke. If everything bad that could happen did happen, no one would ever finish a hundred lines of code. I think a realistic assessment shows that the chances that the grow zone routine will need ApplScratch are so small that they can be neglected. I mean, if you want to get absolutely technical, Standard File can't even be called from a desk accessory, because DAs aren't allowed to allocate more than 3K of RAM. If you violate this, it's possible you will crash. But in real life, it's not a problem. >There are aesthetic >problems with the use of low memory globals for this sort of thing, >too. Many people will just not use them if there is another method. Oh sure, I'm not saying this is the best method by any means. The best method is still to use the refCon of the main DA window; the second best, to use the private storage field of the DCE in the unit table; the third, to write into code space. None of these involve low-memory globals, except for walking the unit table, a process described officially in one of the tech notes. >"People forget how fast you did a job, but they remember how well you >did it." Salada Tag Lines Not in my experience.... -- Tim Maroney, Mac Software Consultant, sun!hoptoad!tim, tim@toad.com Postal: 424 Tehama, SF CA 94103; Phone: (415) 495-2934 "Do what you wanna, do what you will; Just don't mess up your neighbor's thrill. And when you pay the bill, kindly leave a little tip To help the next poor sucker on his one-way trip." - Frank Zappa, "You Are What You Is"