TweetFollow Us on Twitter

Regions 2
Volume Number:4
Issue Number:9
Column Tag:Pascal Procedures

Fun With Regions, Part II

By Stephen Dubin, V.M.D., Ph.D.,, Thomas W. Moore, PH.D., Drexel University, Sheel Kishore, MS

In our previous paper (Fun with Regions Part I: High Level Language Implementation), we showed how it was possible to estimate the area of an arbitrarily drawn region from high level languages such as Pascal and C using repeated application of the ROM subroutine, PtInRgn. Although this approach is simple and intuitive, execution time is excessive for large or complex regions. Whenever part of a high level language routine consumes an inconveniently long execution time, the possibility of using assembly language to achieve better efficiency should be considered. Two fundamental approaches may be applied. A study of the code generated by the compiler may reveal unnecessary looping, inefficient use of registers or other complexities which can be streamlined. If savings can be made within loops executed many times, the resulting speedup can be significant. The second approach applies when the task at hand is relatively simple and straightforward. In this case, determination of a specific efficient algorithm is the key, with translation to assembly code following directly. In dealing with the area computation part of our regions manipulation, we have explored both of these approaches and found the latter approach to be clearly superior.

In the first article, we provided the C Language code for the area calculation program at the end of the article with major subroutines interpolated into the text as implemented in Pascal. In this installment, the “tables are turned”; the interpolated routines are implemented for the Megamax C development system and the Consulair (MDS) assembly language system [This is included in the source code due to space considerations-ED]. At the end of the article, a program using the most useful of the assembly language optimizations is shown for Turbo Pascal with explanation of minor changes needed for the TML Pascal Development system. We recognize that our program may not be the most elegant or efficient approach to the problems; but even where an attempt at optimization yielded poor or marginal results, an interesting and - hopefully - useful technique is explored.

Figure 1.

Several authors ( Morton, M.: Reduce Your Time in the Traps! MacTutor October 1986 pp 21-24. and Knaster, S.: “How to Write Macintosh Software.” Hayden, Hasbrouck Heights NJ, 1986, p 368 ) have advocated bypassing the trap dispatcher as a means of speeding routines in which ROM calls are made repeatedly. Certainly our CountPix routine, since it calls PtInRgn for every point within the region bounding box, is a candidate for this type of optimization. Mike Morton presents the underlying mechanism for this strategy, points out some cautions and pitfalls and shows how to do this task in Pascal using INLINE calls. Briefly, any call to the ROM must go through an intermediate step of finding the “true” address of the call in the particular version of the ROM in your machine before it can be invoked. When a ROM call is to be used many times, this address may be determined one time by means of the GetTrapAddress function early in the program; then you may employ some means of jumping to this address directly whenever the particular ROM call is to be used. In C language, the address might be acquired as follows:

trap = gettrapaddress(0xa8e8);   /*  trap is a global long integer */
 /* A8E8 is the trap # for ptinrgn */

In order to see how the jump might be made, consider the following “glue” routine which is used for ptinrgn by the Megamax system:

boolean ptinrgn(pt, rgn)  /* as copied from qd13.c  */
point *pt;
rgnhandle rgn;
    asm {
 subq #2,A7 /* make room on the stack for the result */
 move.l pt(A6),A0/*  address of point into A0 */
 move.l (A0),-(A7) /*  dereference and put onto stack*/
 move.l rgn(A6),-(A7)/* region handle onto stack */
 dc.w 0xa8e8/* call the ROM for ptinrgn */
 move.b (A7)+,D0 /* result into D0 where C expects to find the answer 
 ext.w D0 /* sign extend the result */

Note that with Megamax inline assembly, the compiler takes care of setting up (and tearing down) the stack frame. Automatic (local) variables are accessed using the name of the variable as a displacement from A6. Global variables are treated similarly as offsets from A4. Thus if we have safely installed the true ROM address of ptinrgn in “trap”, we can write a “new improved” version of the glue routine as follows:

boolean zptinrgn(pt, rgn) /* same as ptinrgn except */
point *pt;/*  bypasses the trap dispatcher */
rgnhandle rgn;
    asm {
 subq #2,A7 /* make room on the stack for the result */
 move.l pt(A6),A0/* address of point into A0*/
 move.l (A0),-(A7) /* dereference and put onto stack */
 move.l rgn(A6),-(A7)/* region handle onto stack */
 move.l trap(A4),A2/* address of “true address” of ptinrgn into A2 */ 

 jsr  (A2)  /* dereference once and jump there */
 move.b (A7)+,D0 /* result into D0 where C expects to find the answer 
 ext.w D0 /* sign extend the result */

When this version was used in place of ptinrgn, the time needed to estimate the area of a region was decreased by 15% for small simple regions and about 9% for larger and more complex ones. Although this would ordinarily be considered a significant improvement, it is little comfort to know that a five minute computation can now be completed in only four and a quarter minutes.

Upon examination of the disassembled code for counbtpix(), we noticed that the most often used variables were the points delimiting the region bounding box as well as the “exploring” point on which we called ptinrgn. Following classical optimization strategy, the next step was to set up these data structures on registers rather than to fetch them every time the coordinates of the exploring point were incremented. The code for this implementation of the countpix function is shown below:

bcountpix(theregion) /* sets up test point on registers  */
rgnhandle theregion;

 move.l trap(A4),A2; address of ptinregn
 move.w #0xA8E8,D0 ; trap number for ptinrgn
 dc.w   0xA146   ; call the trap, address is in A0
 move.l A0,A2    ; put it into A2
 move.l theregion(A6),A3  ; regionhandle 
 move.l (A3),A1  ; dereference once
 move.l 2(A1),D4 ; topleft of rgnbox
 move.l 6(A1),D5 ; botright of rgnbox
 move.l D4,D6    ; copy of TL as VH current point
 cmp.w  D5,D6    ; compare horizontal
 blt.s  vertest  ; go on
 swap D4  ; D4 is now HV
 addq.w #1,D4    ; down 1 row
 swap D4; now D4 is back to HV
 move.l D4,D6    ; make this the current test point
 swap D6; now is HV
 swap D5; now is RB
 cmp.w  D5,D6    ; compare vertical
 blt.s  pointest ; go on
 bra.s  done; 
 swap D5; back to BR
 swap D6; back to VH
 subq #2,A7 ; make room for result
 move.l D6,-(A7) ; point onto stack
 move.l theregion(A6),-(A7) ; rgnhandle onto stack
 jsr  (A2); go to ROM
 move.b (A7)+,D0 ; result onto stack
 tst.b  D0; was it true?
 beq  skip; not this time  
 addq.l #1,numpix(A4); yes, increment the counter
 addq.w #1,D6    ; over 1 column
 bra.s  hortest  ; back for another point

As with the previous attempt at optimization, the speed increase with this approach was marginal at best. Our final attempt in this direction was to examine the code for ptinregn in the ROM in order to transpose (plagiarize?) it directly into the above routine. The result was surprising as well as disappointing. Although there was a measurable but tiny improvement for small simple regions, ones for which optimization was not needed anyway, the time needed to calculate the area of large, complex or disjoint regions increased significantly!! Our theory as to why this happens is based on the way in which the 68000 accesses ROM and RAM. Accesses to RAM (where the program resides) are shared with the video display, sound generator and disk speed controller. This leads to a RAM access rate of approximately six megahertz. The ROM has a “direct line” and is accessed at 7.83 MHz (Inside Macintosh. III-18, Addison-Wesley, Reading MA, 1985).

All of this preoccupation with ptinregn led to an understanding of why the area computation takes so long for large or complex regions. A flow chart of how ptinregn works is shown in figure 1. Unless the region under examination is rectangular, it may be necessary to examine all of the region data, one word at a time, before deciding whether the point is indeed in the region. This is particularly true as the exploring point moves toward increasing values in the vertical (y) component. Clearly, our original countpix procedure, which calls ptinregn on every point in the bounding box, covers the same ground many times. Based on a conviction that the region information should be adequate to permit estimation of the area with one pass, we resolved to implement a specific algorithm “from the ground up.”

As mentioned in the first installment of this article, region information is stored in memory in a way designed to require minimal space. A clear understanding of this method of encoding region boundaries is necessary in order to design our area calculating algorithm. To illustrate this process, consider the simple region plotted in Figure 2. The numbers on the plot are the coordinates of the “corners” of the outlined region. A memory dump of the data representing this region is shown below the graph. In order to design an algorithm for area calculation, we must understand the method of encoding the region in memory. As explained in our previous paper, the first five words of this data list are the data size in bytes (44) followed by the “upper left” and “lower right” coordinates of the rectangular boundary of the region - the regnbbox (100,100,220,200). Following these five words we find the information needed to compute area. Only horizontal boundary information is stored. The region being defined consists of the (rectangular) area under a given boundary line, extending down to the next horizontal boundary line encountered. Horizontal boundary lines are indicated by a y coordinate word, followed by start and stop x values (more than one pair if the line has multiple segments). The flag word, #7FFF, marks the end of the boundary segments at a particular y value. Therefore, the sixth word of data (100) is the y coordinate of the top boundary line of the region. It is followed by x values 100 (start of line) and 200 (end of line). Then we get a flag indicating that no more boundary segments exist at this level. The next horizontal boundary is the line from (125,150) to (180,150). Therefore we find 150 (y value) and 125,180 (x start and stop values) to be the next three words of the data. In this manner, the remaining data can be seen to define the region of figure 2. The double flag indicates the end of the data table.

The question now is how to use this table to calculate the area of the region thus defined. The arrangement of the data suggests dividing the area into rectangular pieces and adding their areas. We might start by subtracting the first x value (100) from the second (200) to get the width of the top of the first rectangle (marked “A”). The y value of this line could be put aside to be subtracted from the next y value (170) yielding the height of the rectangle. The product of these dimensions is one component of the final area

The x values following the 150 are endpoints of a new horizontal boundary line. Since this line falls under the previous boundary, it represents the bottom of a rectangular piece rather than the top of a new one. From here (y = 150 ) our region will now grow downward in two rectangular pieces, B and C. To calculate the areas of these pieces, we must make use of the two new x values found in the data table (125,180). If we arrange all x values found so far in order of magnitude (100, 125, 180, 200), the appropriate widths can be found by pairing the values and subtracting the first from the second in each pair. This is a rule we can use in our algorithm: maintain an ordered list of all encountered x values, pair them and subtract the first of each pair from the second. The sum of these differences will be the total width at the top of each of the rectangular regions. The y coordinate at the top of B and C is subtracted from the next y coordinate found (170-150) to determine the height of these rectangles. Height times width is then added to the accumulating total area.

One problem remains: how to end the process? Following y value 170, we find x values of 100 and 125 in the data. One leg of our descending area ends here so we would like our x table to list just 180, 200 (the top of D) from here on. Therefore, the final rule we need for our area algorithm is to remove entries from the x value ordered list whenever they are matched by a newly encountered x value. At the final y value (220), we subtract the remaining x pair (200-180), and multiply by the last y difference (220-170), giving the area of the last piece, D.

A flowchart of this process is given in figure 3. The routine as implemented to provide a linkable object file using the MDS (now Consulair) 68000 assembly system is shown below. Using the TTAA (Tom Terrific Area Algorithm), even the largest and most complex region that could be drawn on the Macintosh screen could have its area estimated in less than 20 seconds. Such regions take as long as ten minutes using the old CountPix.

This is the code for use with the MDS assembler to produce the file ACountPix.REL. This can then be linked to a Pascal or other “main” program.

;Pascal Usage: Function ACountPix( theRegion:RgnHandle) : LongInt;
;This function emulates CountPix
;  Written by Thomas W. Moore, Ph.D. and Stephen Dubin, V.M.D., Ph.D.
;Copyright © 1987
 XDEF  ACountPix
; The buffer is allocated in the calling program even though it might 
; more elegant to allocate it here with a DS statement; however Turbo
; Pascal V1.0 seems intolerant of this. ( p 335 of the Turbo Pascal manual)
;-------------------------------- INCLUDES ------------------------

Include Traps.D  ; Use System and ToolBox traps
Include ToolEqu.D; Use ToolBox equates

 link A6,#0 ; set up frame pointer
 movem.lA0-A3/D0-D7,-(A7) ; save the world
 clr.l  -(A7)  ; make room on stack for result
 movea.l8(A6),A0 ; region handle into A0
 movea.l(A0),A0  ; dereference => pointer in A0
 clr.l  D7; set area to zero
 lea  myBUF(A5),A1 ; lowest address of x list
rectcheck:; see whether it is a rect and if so - do  the job here
 cmpi.w #10,(A0) ; is this a single rectangle
 bne.s  morework ; if not do the big job
 move.w 4(A0),D1 ; left
 move.w 8(A0),D2 ; right
 move.w 2(A0),D3 ; top
 move.w 6(A0),D4 ; bottom
 sub.w  D1,D2  ; width
 sub.w  D3,D4  ; height
 mulu.w D2,D4  ; area in D4
 move.w D4,D7  ; lower word into D7
 bra  done

morework: ; get ready for some serious work
 lea  10(A0),A0  ; beginning of region info
 clr.l  D4;
 clr.l  D2;
 move.l #512,D3  ; size of buffer to hold ordered list of x values
 adda.l D3,A1  ; highest address in buffer
 movea.lA1,A2  ; copy in A2
 movea.lA1,A3  ; another in A3
 move.w #-1,(A1) ; -1 in highest x address so that 1st x entry will be 

gety:   ; read in y coordinate of next horizontalboundary       
 move.w (A0)+, D3; latest y value
 jsr  calc
 move.w (A0)+,D1 ; new x value
 cmpi.w #$7fff,D1; flag indicates no more x values at this y
 bne  storex; if no flag, it is a new x
 move.w (A0),D1  ; next word of region info
 cmpi.w #$7fff,D1; all done?
 beq  done; yes go home
 bra  gety; no, get next y

storex: ; place new x value in proper place in ordered list
 movea.lA3,A1  ; A3 points to highest x value in ordered list
 cmp.w  (A1),D1  ; compare new x value to largest entry
 bne  s1; if not equal, it must be added to list
 addq #2,A3 ; if match, remove from list
 bra  getx; next x
 lea  -2(A3),A3  ; add a space at high end of list for new x
 bgt.s  insert ; if new x value is greatest, put it on top
mkroom: ; new x is not greatest so we must   move list values up to make 
 move.w (A1)+,-4(A1) ; move data  up (1 word net distance)
 cmp.w  (A1),D1  ; compare next list entry
 beq.s  remove ; if it matches, remove it
 bcc.s  insert ; it is greater, so put it above
 cmpa.l A1,A2  ; are we at bottom?
 bne  mkroom; no, move another one up
insert: ; insert new x value in ordered place in list
 move.w D1,-(A1) ; insert above present location
 bra  getx;
remove: ; erases an entry from the list
 subq #2,A1 ; point to next higher
 cmpa.l A1,A3  ; is it the top?
 beq  shrink; yes so exit
 move.w -(A1),4(A1); move greater x values down to replace
 bra  r1; value removed
 addq #4,A3 ; if a match occurred, list shrinks by 2 words
 bra  getx; one that we didn’t insert and one that we erased
calc:   ; determine new Height
 sub.w   D3,D4 ; Y old - Y new
 neg.w  D4; Height of the rectangle(s)
newW:   ; prepare for Width calculation
 clr.l  D2; Will receive width
 clr.l  D1; work reg
 movea.lA2,A1  ; reset A1 to point to least x value in list
dx:; check to see if all x pairs have been used. 
 ; multiply H x W and add to area
 cmpa.l A1,A3  ; A3 points to greatest x value in  list
 bne  morex ; if not equal, not all x’s have been  used
 mulu   D4,D2  ; H x W
 add.l  D2,D7  ; add to accumulating area
 move.w D3,D4  ; for next time
morex:  ; subtracts x values in pairs adding differences to accumulating 
 move.w -(A1),D1 ; Xi (lower x value of a pair)
 sub.w  -(A1),D1 ; Xi - Xi+1 (length of a horizontal boundary segment)
 neg.w  D1; Xi+1 - Xi (correct sign)
 add.w  D1,D2  ; W (add to accumulating width)
 bra  dx;
 move.l D7,12(A6); store result “under” the last parameter
 movem.l(A7)+,A0-A3/D0-D7 ; restore registers
 unlk A6; restore original stack
 move.l (A7)+,A0 ; get return address
 addq.l #4,A7  ; remove parameters
 jmp  (A0); return this way

The same algorithm can be used with the very convenient inline assembly facility of the Megamax and other C development systems. Because these compilers take care of “tending the stack” for you, the entry and exit procedures are significantly simplified. For the Megamax systems, they are as follows:

rgnhandle theregion;
 move.l theregion(A6),A0  ; regionhandle  note: local variables are 
 referred off A6
 move.l (A0),A0  ; dereference once => region pointer
 clr.l  D7; set area to zero
 lea  buf(A6),A1 ; lowest address of x list


/*  Everything in between is the same as in ACountPix.Asm above */ 
 move.l D7,numpix(A4);report the answer note: global variables 
 are referred offA4 

This is the code for our main calling program as implemented in Turbo Pascal:

{PasArea.Pas }
{Copyright 1987 by Stephen Dubin, V.M.D.and Thomas W. Moore,Ph.D. }
{Prepared with Turbo Pascal V1.0                                  }
{ Users of other Pascal systems should particularly check the “preamble”}
{ portion of their program (Linking directives, “uses”, “includes”, etc.}
{ also check usage of type “point” - TML doesn’t like use of pt.h and}
{ pt.v as control elements in a for statement.                       

program PasArea; 

{$R-}               { Turn off range checking               }
{$I-}               { Turn off I/O error checking           }
{$R PasArea.rsrc}   { Identify resource file                }
{$U-}               { Turn off auto link to runtime units   }
{$L ACountPix.Rel } { Link in Assembly Language Segment}
{$D+}               { Embed Procedure Labels                }

uses  Memtypes,QuickDraw,OSIntf,ToolIntf,PackIntf;

  FileMenuID = 1;{ the File menu}
  OptionMenuID = 2;{ the option menu}
  WindResID = 1; { the resource id of my window}
  BUF   = array[1..512] of Integer; { Make it bigger if you are really 
  myMenus : Array[FileMenuId..OptionMenuID] of MenuHandle; 
  Done : Boolean;
  MyWindow : WindowPtr;   
  TotalRegion   :   RgnHandle;
  Numpix        :   Longint;
  myBUF         : BUF;
function ACountPix( theRegion:RgnHandle) : LongInt; external;

function CountPix(theRegion : RgnHandle): LongInt;       
 pt : Point;
 rgn    :   Region;
 temp   :   LongInt;
 x      :   Integer;
 y      :   Integer;
   temp   :=  0;
   rgn  :=  theRegion^^;
   for  x  := rgn.rgnBBox.left  to  rgn.rgnBBox.right do 
     pt.h := x;
            for y := to rgn.rgnBBox.bottom do
 pt.v := y;
                if  PtInRgn( pt, TheRegion) then  temp := temp + 1;
        CountPix := temp;
{ Turbo seems to accept pt.h and pt.v as control elements but TML does}
{ not. Some format checkers agree with TML}

procedure Wipe;  
    r   :   Rect;

procedure Data;  
    rgn         :   Region;
    rgnpntr     :   Ptr;
    size        :   Integer;
    thebuf      :   BUF;
    bfpntr      :   Ptr;
    myString    :   Str255;
    i           :   Integer;
    x           :   Integer;
    y           :   Integer;
    rgn  :=  totalRegion^^;
    rgnpntr := ptr(totalRegion^); 
    size := rgn.rgnSize;
    if size > 800 then size:= 800;
    bfpntr := ptr(@thebuf);
    DrawString(‘Here are the first 400 words of the region data. (FLAG 
= 32767)’);
    x := 10;
    y := 20;
    for i  := 1  to  (size div 2) do 
        if theBuf[i] < 32766 then 
                if theBuf[i] <10  then DrawString(‘ ‘);
                if theBuf[i] <100 then DrawString(‘ ‘);
                if theBuf[i] < 1000 then DrawString(‘ ‘);
                if theBuf[i] < 10000 then DrawString(‘ ‘);
        if theBuf[i] > 32766 then DrawString(‘ FLAG’);
        x := x + 30;
        if (i mod 16) = 0 then
            x := 10;
            y := y+10;

procedure OvalRegion;
    RectA : Rect;
   TotalRegion := NewRgn;
   SetRect(RectA, 170,175,195,200);

procedure Contour; 
    p1  :   Point;
    p2  :   Point;
    OldTick :  Longint;
  TotalRegion := NewRgn;
  OldTick := TickCount;
    p2 := p1;  
  Until Button = True;  
    Repeat Until (OldTick <> TickCount);
  Until Button <> True;  
  Repeat Until (OldTick <> TickCount);

procedure Example; 
    TotalRegion := NewRgn;

procedure FreeBox; 
    p1  :   Point;
    p2  :   Point;
    p3  :   Point;
    OldTick :  Longint;
    MyRect  :  Rect;
    TotalRegion := NewRgn;
    OldTick := TickCount;
    p2 := p1;  
    Until Button = True;   
    Repeat Until (OldTick <> TickCount);
        Until  EqualPt(p2,p3) <> True;   
   Repeat Until (OldTick <> TickCount);
   p2 := p3;   
   Until Button <> True;

procedure Area;  
    NumTix  :   LongInt;
    MoreTix :   LongInt;
    TicString   :   Str255;
    PixString   :   Str255;  
   MoveTo(10,20); DrawString(‘ Using Pascal ‘); 
   NumTix := TickCount;
   NumPix :=  CountPix( TotalRegion ); 
   MoreTix := TickCount - NumTix;
   MoveTo(10,30); DrawString(‘ Tickcount = ‘);
   MoveTo(120,30); DrawString(TicString);
   MoveTo(10,40); DrawString(‘ Pixel Number = ‘);
   MoveTo(120,40); DrawString(PixString);    
   MoveTo(10,50); DrawString(‘ Using Tom Terrific ‘); 
   NumTix := TickCount;
   NumPix :=  ACountPix( TotalRegion ); 
   MoreTix := TickCount - NumTix;
   MoveTo(10,60); DrawString(‘ Tickcount = ‘);
   MoveTo(120,60); DrawString(TicString);
   MoveTo(10,70); DrawString(‘ Pixel Number = ‘);
   MoveTo(120,70); DrawString(PixString);  

procedure ProcessMenu(codeWord : Longint);   
  menuNum : Integer;
  itemNum : Integer;
  if codeWord <> 0 then 
      menuNum := HiWord(codeWord);
      itemNum := LoWord(codeWord);
      case menuNum of 
        FileMenuID :Done := true; 
        OptionMenuID :
                case ItemNum of
                    1:Contour;      {Contour}
                    2:FreeBox;      {Freebox}
                    3:OvalRegion;   {Oval}
                    4:Example;      {Example}
                    5: Area;        {Area}
                    6:Data;         {Region Data}
                end; { of ItemNum case}               
       end;{ of MenuNum case}

procedure DealWithMouseDowns(theEvent: EventRecord);
  location : Integer;
  windowPointedTo : WindowPtr;
  mouseLoc : point;
  windowLoc : integer;
  VandH : Longint;
  Height : Integer;
  Width : Integer;
  mouseLoc := theEvent.where;
  windowLoc := FindWindow(mouseLoc,windowPointedTo);
  case windowLoc of
    inMenuBar : 

procedure MainEventLoop;
  Event : EventRecord;
  theItem : integer;
    if GetNextEvent(everyEvent, Event) then
      case Event.what of
       mouseDown : DealWithMouseDowns(Event);
  until Done;

procedure MakeMenus; 
  index : Integer;
  for index := FileMenuId to OptionMenuID do
      myMenus[index] := GetMenu(index);

{  Main Program   }
  Done := false;   FlushEvents(everyEvent,0);        InitGraf(@thePort);
   InitFonts;    InitWindows;   InitMenus;     InitDialogs(nil);
  MyWindow := GetNewWindow(WindResID,nil,Pointer(-1)); 
  TotalRegion := NewRgn;   {Lazy way to avoid bomb if your select “Area” 

Here is the resource file for use with the above program (Turbo Pascal):

*   Resource listing from file: “PasArea.R”.


Type AREA = STR 
PasArea, by Stephen Dubin and Thomas W. Moore Copyright © 1987 

Fun with Regions II
40 5 330 505
Visible NoGoAway


Compute Area
Region Data

In order to compile the same program with TML Pascal V2.0, a few minor adjustments were needed. The preamble was changed to:

program TMPasArea;

{$T APPL AREA} { set the type and creator}
{$B+} { set the bundle bit}
{$L TMPasAreaRes}{ link the resource file too...}

uses MacIntf;

{ Constant, Type and Variable declarations as above are the same as in 
PasArea.Pas above}

{Declare the Assembly Language routine as external }
function ACountPix( theRegion:RgnHandle) : LongInt; external;
{$U ACountPix  } 
{ This directive will not appear in the .link file unless it follows 
the declaration of the }
{ relocatable object file as external}

The only change needed in the body of the program was in the high level CountPix function. A form that compiled with TML is:

function CountPix(theRegion : RgnHandle): LongInt;
 pt : Point;
 rgn    :   Region;
 temp   :   LongInt;
 x :   Integer;
 y :   Integer;
   temp   :=  0;
   rgn  :=  theRegion^^;
   for  x  := rgn.rgnBBox.left  to  rgn.rgnBBox.right do 
            pt.h := x;
            for y := to rgn.rgnBBox.bottom do
                   pt.v := y;
                   if  PtInRgn( pt, TheRegion) then  temp := temp + 1;
        CountPix := temp;

TML does not seem to like having pt.h and pt.v as control elements. PasMat, a Pascal formatting and syntax checking program, agrees with TML on this point. In keeping with our local traditions, the first non-comment line of our TML resource file was “TMPasAreaRes”. Although it probably is of little interest in these days of monstrous memories, the TML version of the program requires 3,305 bytes of memory; whereas the Turbo program weighs in at a hefty 10,855 bytes.

Some final zingers for the reader - Although it was certainly necessary for us to use assembler to plumb the depths of the ROM and to work out the algorithm for making our area measurement lightning fast; one might consider whether the same algorithm might now be implemented entirely from C, Pascal or possibly Basic. Would the speed be degraded to any appreciable extent? Will a new call AreaRgn be found in the 512K Roms on the Mack III’s?


Community Search:
MacTech Search:

Software Updates via MacUpdate

Quicken 4.6.3 - Complete personal financ...
Quicken makes managing your money easier than ever. Whether paying bills, upgrading from Windows, enjoying more reliable downloads, or getting expert product help, Quicken's new and improved features... Read more
Smultron 10.0 - Easy-to-use, powerful te...
Smultron 10 is an elegant and powerful text editor that is easy to use. You can use Smultron 10 to create or edit any text document. Everything from a web page, a note or a script to any single piece... Read more
Apple Numbers 4.3 - Apple's spreads...
With Apple Numbers, sophisticated spreadsheets are just the start. The whole sheet is your canvas. Just add dramatic interactive charts, tables, and images that paint a revealing picture of your data... Read more
Apple Pages 6.3 - Apple's word proc...
Apple Pages is a powerful word processor that gives you everything you need to create documents that look beautiful. And read beautifully. It lets you work seamlessly between Mac and iOS devices, and... Read more
Opera 47.0.2631.83 - High-performance We...
Opera is a fast and secure browser trusted by millions of users. With the intuitive interface, Speed Dial and visual bookmarks for organizing favorite sites, news feature with fresh, relevant content... Read more
BetterTouchTool 2.304 - Customize multi-...
BetterTouchTool adds many new, fully customizable gestures to the Magic Mouse, Multi-Touch MacBook trackpad, and Magic Trackpad. These gestures are customizable: Magic Mouse: Pinch in / out (zoom... Read more
Drive Genius 5.0.5 - $49.50 (50% off)
Drive Genius features a comprehensive Malware Scan. Automate your malware protection. Protect your investment from any threat. The Malware Scan is part of the automated DrivePulse utility. DrivePulse... Read more
Apple Configurator 2.5 - Configure and d...
Apple Configurator makes it easy to deploy iPad, iPhone, iPod touch, and Apple TV devices in your school or business. Use Apple Configurator to quickly configure large numbers of devices connected to... Read more
Apple Keynote 7.3 - Apple's present...
Easily create gorgeous presentations with the all-new Keynote, featuring powerful yet easy-to-use tools and dazzling effects that will make you a very hard act to follow. The Theme Chooser lets you... Read more
Vivaldi 1.12.955.36 - An advanced browse...
Vivaldi is a browser for our friends. In 1994, two programmers started working on a web browser. Our idea was to make a really fast browser, capable of running on limited hardware, keeping in mind... Read more

Another Lost Phone: Laura's Story...
Another Lost Phone: Laura's Story 1.0 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0 (iTunes) Description: Another Lost Phone is a game about exploring the social life of a young woman whose phone you have just... | Read more »
The Witness (Games)
The Witness 1.0 Device: iOS Universal Category: Games Price: $9.99, Version: 1.0 (iTunes) Description: You wake up, alone, on a strange island full of puzzles that will challenge and surprise you. You don't remember who you are, and... | Read more »
Egg, Inc. guide - how to build your gold...
Egg, Inc.'s been around for some time now, but don't you believe for one second that this quirky clicker game has gone out of style. The game keeps popping up on Reddit and other community forums thanks to the outlandish gameplay (plus, the... | Read more »
The best deals on the App Store this wee...
Good news, everyone! Your favorite day of the week has arrived at last -- it's discount roundup day! This fine Wednesday evening we're gathering up the hottest deals on the App Store. We've got action platformers, we've got puzzle games, we've got... | Read more »
Morphite (Games)
Morphite 1.08 Device: iOS Universal Category: Games Price: $7.99, Version: 1.08 (iTunes) Description: | Read more »
Fitness AR (Healthcare & Fitness)
Fitness AR 0.1.1 Device: iOS Universal Category: Healthcare & Fitness Price: $2.99, Version: 0.1.1 (iTunes) Description: Explore your Strava bike rides and runs in augmented reality. A beautiful 3D terrain map, powered by Mapbox... | Read more »
ARise (Games)
ARise 1.0 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0 (iTunes) Description: **ARKit only Puzzle game****Chapter 1 available now - More worlds coming soon!** ARise is an experience about perspective. Using the AR... | Read more »
The best games to play while you wait fo...
SteamWorld Dig 2 is out this week on PC and Switch, and people are understandably excited. This clever series by Image and Form combines our favorite metroidvania mechanics with an esquisite universe, excellent storytelling, and true wit. While... | Read more »
Drag'n'Boom beginner's gu...
Have you ever wanted to burn and pillage a village as a bloodthirsty dragon? If you answered yes to that question, Drag'n'Boom offers you the perfect chance to do so, casting you as an adorable little dragon that wants to set humankind aflame. It... | Read more »
Thimbleweed Park (Games)
Thimbleweed Park 1.0.0 Device: iOS Universal Category: Games Price: $9.99, Version: 1.0.0 (iTunes) Description: A brand new adventure game from Ron Gilbert and Gary Winnick, creators of the classics Monkey Island and Maniac Mansion!... | Read more »

Price Scanner via

Apple restocks Certified Refurbished 13-inch...
Apple has Certified Refurbished 2015 13″ MacBook Airs available starting at $719 and 2016 models available starting at $809. An Apple one-year warranty is included with each MacBook, and shipping is... Read more
Is iPhone X Really The Future Of The Smartpho...
Should iPhone X even be called a telephone? It does of course support telephony and texting, but its main feature set is oriented to other things. It is also debatable whether it makes any rational... Read more
OtterBox Announces Full Case Lineup for iPhon...
Apple revolutionized the smartphone industry 10 years ago with the original iPhone, and OtterBox has set the standard of protection from the very beginning by protecting every generation of iPhone.... Read more
LifeProof Introduces What’s NEXT Cases for iP...
LifeProof built its reputation on sleek, ultra-protective iPhone cases. From 360-degree coverage to the first screenless waterproof case, the protection pioneer has always pushed the limits.... Read more
Apple Refurbished 2016 15-inch MacBook Pros a...
Apple has Certified Refurbished 2016 15″ Touch Bar MacBook Pros available starting at $1949. An Apple one-year warranty is included with each model, and shipping is free: – 15″ 2.7GHz Touch Bar Space... Read more
Wednesday deal: 15-inch MacBook Pros for up t...
B&H Photo has 2017 15″ MacBook Pros on sale for $150-$200 off MSRP. Shipping is free, and B&H charges sales tax in NY & NJ only: – 15″ 2.8GHz MacBook Pro Space Gray: $2199, $200 off MSRP... Read more
2.6GHz Mac mini on sale for $599, $100 off MS...
B&H Photo has the 2.6GHz Mac mini (MGEN2LL/A) on sale for $599 including free shipping plus NY sales tax only. Their price is $100 off MSRP. Read more
Snag a 15-inch 2.2GHz Retina MacBook Pro, App...
Apple has Certified Refurbished 2015 15″ 2.2GHz Retina MacBook Pros available for $1699. That’s $300 off original MSRP, and it’s the lowest price available for a 15″ MacBook Pro currently offered by... Read more
Apple Refurbished 3TB Time Capsule for $279,...
Apple has Certified Refurbished 3TB Time Capsules available for $279 including free shipping plus Apple’s standard one-year warranty. Their price is $120 off MSRP. Read more
19% off Smart Battery Cases for iPhone 7
Amazon has both Black and White Smart Battery Cases for iPhone 7s available for $80.41 including free shipping. Their price is $18.59, or 19%, off MSRP. Read more

Jobs Board

Full time *Apple* Hardware Tech needed - ma...
…high level of attention to detail Ethics, integrity and trust Be a geek & Previous Apple experience a must. Previous Apple Retail or other Apple Specialist Read more
Development Operations and Site Reliability E...
Development Operations and Site Reliability Engineer, Apple Payment Gateway Job Number: 57572631 Santa Clara Valley, California, United States Posted: Jul. 27, 2017 Read more
*Apple* Store - Technical Specialist - Apple...
…customers purchase our products, you're the one who helps them get more out of their new Apple technology. Your day in the Apple Store is filled with a range of Read more
*Apple* Retail - Multiple Positions - Apple,...
Job Description: Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, Read more
*Apple* News Product Marketing Mgr., Publish...
Job Summary The Apple News Product Marketing Manager will work closely with a cross-functional group to assist in defining and marketing new features and services. Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.