[comp.sys.mac.programmer] Using parameter blocks in ASM

gd1a+@andrew.cmu.edu (Glen M. Devries) (12/06/90)

How does one set up a parameter block in assembly. I need a pointer to
the block and then need to set up the contents. Where can it be? Must it
be in the application heap or can it be in the system heap?

                                        Any help would be appreciated,
                                                    Glen
                                                    gd1a+@andrew.cmu.edu

stevec@Apple.COM (Steve Christensen) (12/06/90)

gd1a+@andrew.cmu.edu (Glen M. Devries) writes:
>How does one set up a parameter block in assembly. I need a pointer to
>the block and then need to set up the contents. Where can it be? Must it
>be in the application heap or can it be in the system heap?

You can put the parameter block in a heap block as long as the block is locked
for the duration of a call.  A more common way is to allocate the space in a
stack frame, or if this is an application you're talking about, in the app's
global variable space (A5 relative).  For example, if you're talking about
a Device Manager parameter block, you could do something like this:

DoSomething	LINK	A6,#-ioQElSize		; put pb on the stack
		MOVEA.L	SP,A0			;  and point to it
		...				; do whatever with it
		UNLK	A6			; clean up the stack
		RTS

Obviously if you make an asynchronous call, you can't exit the routine until
the call completes, so in that case it would be better to allocate it on the
heap or in global space (apps only)...

steve

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  whoami?     Steve Christensen
  snail:      Apple Computer, 20525 Mariani Ave, MS-81CS, Cupertino, CA 95035
  internet:   stevec@apple.com
  AppleLink:  stevec
  CompuServe: 76174,1712

mneerach@iiic.ethz.ch (Matthias Ulrich Neeracher) (12/06/90)

In article <0bLHodC00WBL42hVc=@andrew.cmu.edu>, gd1a+@andrew.cmu.edu
(Glen M. Devries) writes:
> How does one set up a parameter block in assembly. I need a pointer to
> the block and then need to set up the contents. Where can it be? Must it
> be in the application heap or can it be in the system heap?

Both is possible, the block can even be on the stack (But beware of 
asynchronous calls which continue after the stack frame containing
the parameter block has been destroyed). 

You have to declare/allocate a nonrelocatable block the size of a 
ParamBlockRec. You should find this size already declared as a constant 
in some interface file. 

Hope this helps

Matthias

-----
Matthias Neeracher                                   mneerach@iiic.ethz.ch
   "These days, though, you have to be pretty technical before you can 
    even aspire to crudeness." -- William Gibson, _Johnny Mnemonic_

Chris.Gehlker@p12.f56.n114.z1.fidonet.org (Chris Gehlker) (12/08/90)

> How does one set up a parameter block in assembly. I need a pointer to
> the block and then need to set up the contents. Where can it be? Must it
> be in the application heap or can it be in the system heap?

I just do a moveq  #paramblocksize,d0
            _NewPtr
            move.l  a0,a3; or wherever to save the pointer.
Then I can address the elements of the parameter block as offsets from a3. 
You can also put them on the stack with a subq #paramblocksize, sp or do a
link a6 #-paramblocksize and put them in a stack frame.  Some parameter
blocks need to stay around after you exit your routine, however, so the
latter methods are not safe in all cases.

I don't think applications should put parameter blocks in system heap
but drivers, inits ect. may.  Just use _NewPtr,Sys if you want them in
system heap.

 

--  
Uucp: ...{gatech,ames,rutgers}!ncar!asuvax!stjhmc!56.12!Chris.Gehlker
Internet: Chris.Gehlker@p12.f56.n114.z1.fidonet.org