[comp.sys.mac.programmer] Accessing global variables from MPW

STORKEL@RICE.BITNET (Scott Storkel) (05/03/89)

I have a question about the way MPW C and Pascal generate code that makes use
of the QuickDraw global variables. If I wanted to change the seed for the
random number generator, I would do the following from assembly language:

                    MOVE.L   (A5),A0
                    MOVE.L   Time, randSeed(A0)

Here, randSeed has the value $-7E. If I do something like the following

                    qd.randSeed = (*(long *) 0x20C);

the code produced looks like the following:

                    MOVE.L   $20C, $FF7E(A5)

$FF7E is $-82 by the way. The code that I'm working with is an animation
for the Last Screen Saver project I mentioned a while ago. The code gets called
when the screen needs to be blanked. Everything works fine if the screen saver
comes on while running under the Finder. If an applications is running,  the
generated code does not work. The reference to $FF7E(A5) is NOT the randSeed
global variable, in fact it is usually some random spot in memory.

My question is, why isn't the compiler generating code like my first assembly
language example? Does the fact that the reference to a global variable doesn't
work have anything to do with the fact that the animation code never calls
InitGraf or any of the other ToolBox initialization calls? Is there any way to
work around this problem? Do MPW 3.0 (I'm using 2.0.2) and the Lightspeed
compilers have this problem?

I would appreciate some enlightenment. Please respond directly to me, and I
will summarize to the net if there is enough interest.


Scott Storkel
Macintosh Software Development
Rice University

alibaba@ucscb.UCSC.EDU (Alexander M. Rosenberg) (05/03/89)

Not to nitpick, but for assembly, the recommended (and probably best)
replacement random seed is RndSeed. IM I under Random in QuickDraw
mentions this. RndSeed changes by the number of ticks since the
last change in mouse button state. It may also change in other places.
You are least likely to get a repeated sequence this way, unless the
change is happening at startup time (not too many mouse clicks then).

-------------------------------------------------------------------------------
-  Alexander M. Rosenberg  - INTERNET: alibaba@ucscb.ucsc.edu   - Yoyodyne    -
-  Crown College, UCSC     - UUCP:...!ucbvax!ucscc!ucscb!alibaba- Propulsion  -
-  Santa Cruz, CA 95064    - BITNET:alibaba%ucscb@ucscc.BITNET  - Systems     -
-  (408) 426-8869          - Disclaimer: Nobody is my employer  - :-)         -
-                          - so nobody cares what I say.        -             -