Path: utzoo!utgpu!attcan!uunet!seismo!sundc!pitstop!sun!decwrl!labrea!eos!ames!pacbell!hoptoad!tim From: tim@hoptoad.uucp (Tim Maroney) Newsgroups: comp.sys.mac Subject: Re: Calling CODE segments Message-ID: <5478@hoptoad.uucp> Date: 29 Sep 88 01:37:17 GMT References: <17742@glacier.STANFORD.EDU> Reply-To: tim@hoptoad.UUCP (Tim Maroney) Distribution: na Organization: Eclectic Software, San Francisco Lines: 42 In article <17742@glacier.STANFORD.EDU> leeke@glacier.UUCP (Steven D. Leeke) writes: >LSC reqires me to use their RememberA4/SetupA4 stuff on entry in the >CODE segment and RestoreA4 on exit to get at the globals (if any) in >the CODE segment - so I do. e.g. the CODE segment's main looks like: > >void main(p1,p2,p3,...,entryPoints) >{ > RememberA4(); > SetupA4(); > /* ... */ > RestoreA4(); >}; Look at page 85 of the User's Manual. You need to call RememberA0(), not RememberA4(). They're very different macros. Things are getting trashed because A4 is set to something silly, so all your global accesses are writing into random memory locations. >This seems to work well until I try to draw something from within the >"main" program (I don't draw in the code segment) - usually activating >or updating a window when a dialog the CODE segment loaded is being drawn. That's probably just the way it happens; change a few variables and you might have problems with drawing controls or dragging windows instead. But if you really want to know whether A5 is problematic, just drop into MacsBug or TMON at the beginning of the main program callback routine, and see if A5 is the same as the low-memory global CurrentA5. I'm pretty sure there is no reason to explicitly set A5 to CurrentA5 inside the callback routine, since the code resource shouldn't modify A5. But if you want, setting A5 to CurrentA5 in the callback routine couldn't hurt. >I've tried to use SetupA5 right after SetupA4 when I start my CODE segment, >for what it's worth, but it doesn't seem to make a difference. I'm not >an experienced ASM hacker period - especially on the Mac. This, I think, confirms my feelings that your problems are with A4. -- Tim Maroney, Consultant, Eclectic Software, sun!hoptoad!tim "I see little divinity about them or you. You talk to me of Christianity when you are in the act of hanging your enemies. Was there ever such blasphemous nonsense!" - Shaw, "The Devil's Disciple"