[comp.sys.mac] VBL tasks, offscreen bitmaps, Lightspeed Pascal, etc.

florman@randvax.UUCP (Bruce Florman) (05/07/87)

    I'm not a Mac guru by any means, but I've been noodling about with
VBL tasks, PICTs and BitMaps in Lightspeed Pascal for the past few days.
So Peter Wu's and James Moore's postings seemed to be aimed right at me.

pwu@uwmacc.UUCP (Peter Wu) writes:
>According to inside mac a VBL routine need to preserve some registers.
>Is there a way I can do this in pascal? I'm using lightspeed pascal.
>The VBL routine is used to sample data from the serial port at 500ms
>interval.

    On entry, a Pascal routine will save all of the necessary registers
automatically except A5.  A5 is usually a sacred register, pointing to
the application globals, but since a VBL task is initiated by an
interrupt, A5 may hold some other value.  Fortunately the routines
SetUpA5 and RestoreA5 are available (see Inside Macintosh p. II-386).
Just make a call to SetUpA5 on entry to your task and RestoreA5 on exit.


jmm@miro.Berkeley.EDU (James Moore) writes:
>1.  How does one get mBarHeight from Lightspeed Pascal?

    According to Inside Mac, p I-341, "The menu bar is white, 20 pixels
high, and as wide as the screen, with a 1-pixel black lower border.  The
menu titles in it are always in the system font and the system font size."
So it sounds like you can just declare a constant.

>2.  I'm having trouble changing bitmaps.  I'd like to draw 
>off the screen, but I seem to be doing something wrong.
	[further description of problem]

>3.  I'm having a problem getting PICT resources onto the screen.
	[further description of problem]

    Here is an excerpt from one of my recent efforts that may (or may
not) help.



    procedure AllocateBM (var theBM : BitMap);
    { Using bounds Rect of theBM, AllocateBM calculates the }
    { rowBytes and allocates storage for the appropriate BitImage. }
      var
	width, height : INTEGER;
    begin
      with theBM, bounds do
	begin
	  width := right - left;
	  height := bottom - top;
	  rowBytes := 2 * ((width + 15) div 16); { the magic formula }
	  baseAddr := NewPtr(rowBytes * height)
	end
    end;

    procedure GetBM (var theBM : BitMap; id : INTEGER);
    { Given the resource id of a PICT resource, GetBM }
    { allocates a BitMap and draws the picture into it. }
      const
	PICT = $50494354; { ascii 'P' 'I' 'C' and 'T' }
      var
	rsrc : PicHandle;
	oldBits : BitMap;
    begin
      rsrc := PicHandle(GetResource(ResType(PICT), id));
      with theBM, bounds do
	begin
	  bounds := rsrc^^.picFrame;
	  OffsetRect(bounds, -left, -top)
	end;
      AllocateBM(theBM);
      oldBits := thePort^.portBits;
      SetPortBits(theBM);
      DrawPicture(rsrc, theBM.bounds);
      SetPortBits(oldBits);
      ReleaseResource(Handle(rsrc))
    end;

dgold@apple.UUCP (David Goldsmith) (05/09/87)

In article <971@randvax.UUCP> florman@randvax.UUCP (Bruce Florman) writes:
>jmm@miro.Berkeley.EDU (James Moore) writes:
>>1.  How does one get mBarHeight from Lightspeed Pascal?
>
>    According to Inside Mac, p I-341, "The menu bar is white, 20 pixels
>high, and as wide as the screen, with a 1-pixel black lower border.  The
>menu titles in it are always in the system font and the system font size."
>So it sounds like you can just declare a constant.
This actually isn't a good idea; after Inside Macintosh (vol. I-III) were
published, changes to the system software were made such that the menu bar
height is no longer a constant (this is also the case on the Radius FPD).
The best way to get MBarHeight is to declare a type pInt = ^INTEGER, then
cast the constant address of MBarHeight ($BAA - only on 128K ROMs - assume
"20" if not on 128K ROMs) to type pInt and dereference it.  In MPW Pascal,
this would be:  theHeight := pInt($BAA)^; in other Pascals you may have
to use intermediate variables.
-- 
David Goldsmith
Apple Computer, Inc.
MacApp Group

AppleLink: GOLDSMITH1
UUCP:  {nsc,dual,sun,voder,ucbvax!mtxinu}!apple!dgold
CSNET: dgold@apple.CSNET, dgold%apple@CSNET-RELAY
BIthe fis k3UHXp

dtw@f.gp.cs.cmu.edu (Duane Williams) (05/09/87)

David Goldsmith of Apple Computer Inc. writes:
> This actually isn't a good idea; after Inside Macintosh (vol. I-III) were
> published, changes to the system software were made such that the menu bar
> height is no longer a constant (this is also the case on the Radius FPD).

Let's remember this the next time we hear developers getting castigated for 
breaking the rules set forth in Inside Macintosh.  Sometimes people obey
the rules, then Apple changes the rules, and then we read articles about
how programs fail to work with new software from Apple because the authors
didn't follow the rules.  Sometimes yes, but not always.