TweetFollow Us on Twitter

Apr 89 Letters
Volume Number:5
Issue Number:4
Column Tag:Letters


By David E. Smith, Editor & Publisher, MacTutor

Aztec C

Rich Heady

San Diego, CA

Aztec C is all I was told it would be, and I’m already pleased with the results. It is particularly gratifying to have access to “intermediate code” again after being locked inside Lightspeed C’s projects for the past 18 months, and more gratifying still to find the assembly code already optimized to the point where I may not need to go through cleaning up the little stupidities. There is nothing wrong with Lightspeed C; in fact, it remains a superior prototyping environment. But at the point where I began to look beyond the prototype to a shippable product, it was a relief to find Aztec C ready to finish the job. Aztec C might carve a bigger niche in the Macintosh world by appealing to the “1 Meg programmer” who wants to produce polished code without larding on RAM and without wading into the complexity of MPW.

Typos upon Typos

Ajay Nath

Oakland Gardens, NY

I’ve been writing a driver for my plotter, and I’ve been looking at the code you presented in MacTutor, Volume 3, Number 11 and 12. I’ve caught some errors in the code you presented on page 57 (#12). The code in the procedure DrvrStorage():


asm {
 MOVEQ  #8, D0
 MOVE.L UTableBase, A0
 MOVE.L (A0), OutDctlEntry

I wrote to you about this error before, but you printed my correction incorrectly! (You did print my explanation of why the author’s code was wrong correctly.) [Sorry, we will double our efforts. -ed]

On page 59 in the procedure MyPrDlgMain() at the end of this proc a pointer is freed and then accessed as follows:

/* 2 */

free(+p); /*ptr is being freed by a subroutine */
if (tp->fDolt) (void) MyPrValidate(hPrint);
 /*we accessed the ptr we freed */
return (tp->fDolt); /* you did it again! */

if (tp->fDolt) is true the subroutine “MyPrValidate” will be called, and it calls traps like GetResource and LoadResource which will move memory so that doing a subsequent “return(tp->fDolt)” may be pointing to garbage.

One way to fix this is to do the following:

/* 3 */

{ Boolean theResult; 
 /* a local variable to hold function result */
theResult = tp->fDolt; /*save the value of fDolt */
free (tp);
if (theResult) (void) MyPrValidate(hPrint);
return (theResult);

on page 58 in the procedure “MyPrintDefault(hPrint)” one of the lines:

**hPrint = **theDefault;

the same line appears on page 59 near the end of the procedure MyPrValidate(hPrint)

What the author is trying to do is to fill in the fields of the data structure that hPrint points to, what he actually does is mess up the hPrint handle. What he should do is something like this:

/* 4 */
BlockMove(*theDefault, *hPrint, sizeof(TPrint));

and probably:

/* 5 */

 /* unload resource now that we’re done */

It is a good article which provides information on how to write printer drivers, but some of the code is incorrect.

In MacTutor, Vol. 4, #11, the code presented by Donald Koscheka to do a string comparison uses the “DBRA” instruction incorrectly. When you loop using “DBRA” you use the word (16 bits) in the register you use as a loop counter; Mr. Koscheka uses register D1 as his loop counter and sets its value by doing:

 MOVE.B (A))+, D1; get length of string 1

This sets the lower 8 bits of D1, NOT the lower word. The correct way to load the value of the loop counter in this case is to:


            MoveQ #0, D0; set D0 = 0;
            Move.B(A0)+, D0      ; D0 = string length

Also when using the “DBRA” instruction, the register must actually have the loop count -1 in it, i.e. if you want to loop 10 times, put 9 in the register. Mr. Koscheka doesn’t do this. I realize that he was showing a code fragment, but the purpose of his article was to show how to use assembly language and allowing such errors to slip in does readers a disservice.

FORTRAN Math Libraries

Michael M. J. Tracy

Pittstown, NJ

I am writing in response to Tatsuhito Koya’s request (Feb 1989, Vol. 5 No. 2) for information on FORTRAN math libraries that will run on the Mac. There is an excellent book out called ‘Numerical Recipes: The Art of Scientific Computing’ by William H. Press, Brian P. Flannery, Saul A. Teukolsky & William T. Vetterling (Cambridge University Press, ISBN 0 521 30811 9). I refer to this book infinitely more often than ‘Inside Macintosh’ when writing scientific applications on the Mac (and it’s cheaper too, about $35 hard cover). The book provides the source code for over 200 subroutines. Its real value to the user, however, is in the eloquent and intelligent discussion of the principles underlying each algorithm, explaining the strengths and weaknesses, and usually providing alternative algorithms so that the cautious user can cross check results. I have learned a lot from this book. Listing from the contents page, the book covers; solution of linear algebraic equations; interpolation and extrapolation; integration of functions; evaluation of functions; special functions; random numbers; sorting; root finding and non-linear sets of equations; minimization and maximization of functions; eigensystems; fourier transform spectral methods; statistical description of data; modeling of data; integration of ordinary differential equations; two point boundary value problems; partial differential equations. There are two versions of the book. The original edition gave the subroutine listings in both FORTRAN and Pascal. By popular demand, a second version was released which presents the C source code listings (written somewhat from the perspective of a FORTRAN programmer who wishes to convert to C, and provides structures and functions for handling complex numbers). Macintosh compatible disks containing the source code are also available from the publishers.

All FORTRAN subroutines that I have used work well, and have compiled without any problems under both MacFortran and Language Systems Fortran. Some subroutines, however, need to have the ‘SAVE’ statement added at the beginning (as required by the ANSI 77 FORTRAN standard) if local variables need to be preserved between subroutine calls, such as in the random number generators.

Further Optimizations

John F. Reiser

Beaverton, OR

The code for optimized string comparisons (Letters, Jan. ’89, p. 106) is on the right track, but the listing contains a bug and the inner loop can be improved further. If the length of the first string is 128 or more, then the iteration count in register D1 gets an incorrect value via sign extension using EXT.W. The loop can be shortened by combining the break-out test with the iteration count control:


A0 -> Pascal string 1
A1 -> Pascal string 2
D0 <- 0 if not equal, 1 if equal

CompareString  Moveq #0,D0; clear high bits
 Move.B (A0), D0 ; length of first string
@10Cmp.B(A0)+, (A1)+ ; mismatch?
 Dbne D0, @10  ; stop when .ne., or at end
 Sne  D0; D0.B = -1 if .ne.; 0 if .eq.
 Addq.B #1, D0 ; D0.B = 0 if .ne.; 1 if .eq.
 Ext.W  D0; Dbne can set bits 7-15

VBL Animation Problems

David Oster

Berkeley, CA

I am appalled by Dick Chandler’s article, “VBL Task Animation” in the February 1989 issue of MacTutor. Yes, his program works, but only because it is a top. Any real program that tries the technique he describes will fail miserably.

Look, his VBL task calls GetIcon and PlotIcon at VBL interrupt time. In his application, the main loop just busy waits for the user to press the Button. A real application would be calling GetNextEvent(), or doing something. For example, each time the user looks at a menu. When the menu goes away, it slams those bits back and deallocates the handle.

GetIcon calls GetResource(). What if the VBL task calls it while the Memory Manager is shuffling the heap to allocate memory for the main loop. Crash city. PlotIcon calls CopyBits(), which clips against the clipRgn and visRgn of the underlying grafPort. What if the VBL task calls it while the Memory Manager is shuffling the heap to allocate memory for the main loop? Crash city.

Even if your program is clean, you do not know what trap patches the user has installed: Maybe he is using an INIT that overrides some trap your program needs, and the override will do memory allocation. For example, Dick’s program calls Button() from its main loop, and many INITs override button, so they will get called while the mouse is down.

So, you can only do animation at interrupt time if you can guarantee that no user or system task will allocate memory in the main loop.

Dick’s program doesn’t guarantee this, since it calls Button() from its main loop, and Button() may have been overriden by an INIT. Since there is so little the main loop can safely do, you might as well give up on VBL Task animation, and just do animation in your main loop, busy waiting until TickCount changes to pause between animation frames.

TWindow Manager Update

Thomas Fruin

Las Condes, Santiago, Chile

After a four month trek through the Latin American country of Peru (that left me penniless), I was delighted upon arrival at my fathers place in Santiago de Chile to find last December’s copy of MacTutor with my Tool Window Manager article. And the generous cheque that was included couldn’t have come at a better time!

Since the article was sent off to you, several programs have been written making use of TWindow. This caused a few small bugs to surface. I would like to take this opportunity to correct them.

The TWindow Manager incorrectly assumes that the calling application will always process every activate or deactivate event by calling TGetNextEvent. However, when multiple dialog boxes are put up, or dialogs following other dialogs without a call to TGetNextEvent in between, some activate or deactivate events may “linger”. This may cause the wrong (de)activation to occur when TGetNextEvent finally is called.

My solution is a utility function FlushActivateEvents(), with the following code:

/* 8 */

static void FlushActivateEvents()

 toBeActivated = toBeDeactivated = nil;
 result = GetNextEvent(activMask, &theEvent);
 result = GetNextEvent(activMask, &theEvent);

When called, this function effectively flushes (removes) every activate and deactivate event from the system: both official events and TWindow Manager internal events.

A call to FlushActivateEvents needs to be inserted in THideWindow and another call in TShowWindow. Both these calls should be made right after the very first if statement, where is checked if the window is still visible or invisible. That is all.

A minor oversight is that the WindowExists function is not defined static. It should be because it is internal to the TWindow Manager.

Finally, I can announce that I have written an MPW Pascal INTERFACE unit, that allows you to call the TWindow Manager from MPW pascal programs. This required more small modifications to the TWindow Manager source. As soon as I get someone to send me my disks from Holland, I will send the new versions of the software to MacTutor. By the way, this version of software also includes a TWaitNextEvent (although this is a trivial addition).

Publication of my article has definitely encouraged me to write more, so expect to see other stuff from me!

Absoft MacFortran to LS Fortran

Bert Waggoner

Riverside, CA

After over a year of reading your journal and programming the Macintosh things are beginning to make a little sense. Now I’d like to give a little back. Here are some notes on the new Language Systems Fortran compiler for MPW that you may wish to pass on to other readers:

I just received the Language Systems (LS) Fortran compiler v1.2 for MPW, and it looks very good. Now, using MPW, I can code in C and have access to the vast array of scientific subroutines written in Fortran (including those of my boss, who is reluctant to learn another language. We are developing chemical transport models for the Macintosh, and, until now, I have been translating his Fortran code to Think C. Microsoft C and Fortran for the IBM PC’s have been on speaking terms for some time - it’s about time the Mac caught up).

Here are some changes I had to make to get an Absoft MacFortran program to compile with LS Fortran:

- the preconnected file units for screen and printer I/O are reversed!

- any WHILE ( )/REPEAT loops must be replaced by DO WHILE ( )/END DO,

- LS Fortran doesn’t have a SELECT CASE statement (sigh),

- IF statements must have enclosing parentheses, i.e. use IF (X .EQ. Y) THEN, not IF X .EQ. Y Then,

- the ACCEPT statement must specify a format,

- there were several differences in filing handling, such as no POSITION or ACCESS key words for the OPEN statement IN LS Fortran.

There are, undoubtably, many other differences. As for toolbox access, LS Fortran’s implementation is different and cleaner, and the language allows for structures. Last, but not least, LS Fortran has a decent manual with lots of examples. Now my problem is converting my Think C code to MPW C. Would any readers like to share their experiences with this?

SysEnvirons From MacFortran

James Wishart

Long Island, NY

In the course of developing an instrument control and data acquisition application in Absoft MacFortran/020, I needed to call SysEnvirons to check for the 68881 floating point processor. Unfortunately, Absoft did not include the trap dispatch parameter for the call in their include files. With the help of additional documentation on the Toolbx.sub routine provided by Lee Rimar of Absoft, I found the correct parameter to be z’09014010'. The following program demonstrates how to call SysEnvirons in Absoft MacFortran.

c 9

program TestSysEnvirons
implicit none

integer*4 toolbx
integer*2 oserr, i
integer*4 version

integer*1 SysEnvRec(16)

integer*2 environsVersion
integer*2 machineType
integer*1 systemVersion(2)
integer*2 processor
logical*1 hasFPU
logical*1 hasColorQD
integer*2 keyBoardType
integer*2 atDrvrVersNum
integer*2 sysVRefNum

equivalence (SysEnvRec(1), environsVersion)
equivalence (SysEnvRec(3), machineType)
equivalence (SysEnvRec(5), systemVersion(1))
equivalence (SysEnvRec(7), processor)
equivalence (SysEnvRec(9), hasFPU)
equivalence (SysEnvRec(10), hasColorQD)
equivalence (SysEnvRec(11), keyBoardType)
equivalence (SysEnvRec(13), atDrvrVersNum)
equivalence (SysEnvRec(15), sysVRefNum)

Parameter (SYSENVIRONS = Z’09014010')
oserr = 0
version = 2
do (i=1,16)
 SysEnvRec(i) = 0

oserr=toolbx(SYENVIRONS, version, SysEnvRec)

if (oserr .ne. -5501) then
 write(9,*) ‘environsVersion = ‘, environsVersion
 write(9,*) ‘machineType = ‘, machineType
 write(9,1) systemVersion(1), systemVersion(2)
1format(‘systemVersion = ‘, z2, “.”, z2)
 write(9,*) ‘processor = ‘, processor
 write(9,*) ‘hasFPU = “, hasFPU
 write(9,*) ‘hasColorQD = ‘, hasColorQD
 write(9,*) ‘keyBoardType = ‘, keyBoardType
 write(9,*) ‘atDrvrVersNum = ‘, atDrvrVersNum
 write(9,*) ‘sysVRefNum = ‘,sysVRefNum
select case (oserr)
 case (0)
 case (-5500)
 write(9,*) ‘System version is less than 4.2’
 case (-5501)
 write(9,*) ‘Bad version selector - no data returned’
 case (-5502)
 write(9,*) ‘Version ‘, version,’ requested, version ‘,
+environsVersion, ‘ returned.’
 case default
 write(9,*) ‘Unspecified error #’, oserr
end select

write(9,*) ‘Hit RETURN to exit program’

A Usenet message from David Phillip Oster brought my attention to the fact that programs should watch for disk insertion events in their main loops and call DIBadMount if the inserted disk cannot be mounted. Implementing this feature requires two more undocumented trap dispatch parameter, DIBadMount (z’9E952200', routine #0) and DIUnload (z’9E908000', routine #4) from Pack2, Disk Initialization. The following code fragment uses the event manager variables defined in the example in the MacFortran manual. (Notice that the Pack2 routine selector must be added to the end of the argument list.) See Inside Macintosh Vol. 2 for the result codes returned in the two byte variable err.

c 10

select case (what)
 case(7)! 7 = Disk insertion
 if (shift(message, -16) .ne. 0) then
 call toolbx(INITCURSOR)
 err = toolbx(DIBADMOUNT, z’00640064', message, 0)
 call toolbx(DIUNLOAD, 4)

The remaining Pack2 parameters should be as follows, but I have not tested these: DILoad: z’9E908000', routine #2; DIFormat: z’9E949000', routine #6; DIVerify: z’9E949000', routine #8; DIZero: z’9E94E200' or z’9E94C200', routine #10.

I want to thank Jay Lieske for his “Fortran Printing Interface” article in August, 1988 issue as well as all of the people who contributed information about Classic Mac analog board failures. Every month I pace in front of my mailbox until MacTutor arrives.

Author Incentive Program Correction

Kirk Chase

Anaheim, CA

In the December ’89 MacTutor, we made a correction on the Author Incentive Program initiated by Apple. Additional reimbursement is ONLY FOR APPLE EMPLOYEES. Those not employed by Apple DO NOT QUALIFY. We are sorry for any confusion that may have resulted over this and hope this clears up any mistaken notions. If you are with Apple, and if you want more information, please contact Stacey Farmer in public relations, who is now in charge of the program, for more information.


Community Search:
MacTech Search:

Software Updates via MacUpdate

Google Chrome 61.0.3163.100 - Modern and...
Google Chrome is a Web browser by Google, created to be a modern platform for Web pages and applications. It utilizes very fast loading of Web pages and has a V8 engine, which is a custom built... Read more
iMazing 2.4.2 - Complete iOS device mana...
iMazing (was DiskAid) is the ultimate iOS device manager with capabilities far beyond what iTunes offers. With iMazing and your iOS device (iPhone, iPad, or iPod), you can: Copy music to and from... Read more
Quicken 4.6.4 - 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
Yasu 4.0.5 - System maintenance app.
Yasu was created with system administrators who service large groups of workstations in mind, Yasu (Yet Another System Utility) was made to do a specific group of maintenance tasks quickly within a... Read more
Stacks 3.5.5 - New way to create pages i...
Stacks is a new way to create pages in RapidWeaver. It's a plugin designed to combine drag-and-drop simplicity with the power of fluid layout. Features Fluid Layout: Stacks lets you build pages... Read more
Things 3.2 - Elegant personal task manag...
Things is a task management solution that helps to organize your tasks in an elegant and intuitive way. Things combines powerful features with simplicity through the use of tags and its intelligent... Read more
Tweetbot 2.5.3 - Popular Twitter client.
Tweetbot is a full-featured OS X Twitter client with a lot of personality. Whether it's the meticulously-crafted interface, sounds and animation, or features like multiple timelines and column views... Read more
Hopper Disassembler 4.2.19- - Binary dis...
Hopper Disassembler is a binary disassembler, decompiler, and debugger for 32- and 64-bit executables. It will let you disassemble any binary you want, and provide you all the information about its... Read more
Monosnap 3.4.0 - Versatile screenshot ut...
Monosnap lets you capture screenshots, share files, and record video and .gifs! Capture Capture full screen, just part of the screen, or a selected window Make your crop area pixel perfect with our... Read more
Duet - Use your iPad as an exter...
Duet is the first app that allows you to use your iDevice as an extra display for your Mac using the Lightning or 30-pin cable. Note: This app requires a $14.99 iOS companion app. Version Read more

The best visual novels on mobile
Narrative games have been around for ages, but only now have they been creeping into the mainstream spotlight. These games tell some of the industry's finest stories, and they break new ground in terms of gameplay and mechanics regularly. Here are... | Read more »
The best new games we played this week -...
It's pretty much been one big release after another. We were privy to a bunch of surprises this week, with a lot of games we'd been waiting for quite some time dropping unexpectedly. We hope you're free this weekend, because there is a lot for... | Read more »
Stormbound: Kingdom Wars guide - how to...
Stormbound: Kingdom Wars is an excellent new RTS turned card battler out now on iOS and Android. Lovers of strategy will get a lot of enjoyment out of Stormbound's chess-like mechanics, and it's cardbased units are perfect for anyone who loves the... | Read more »
The best AR apps and games on iOS right...
iOS 11 has officially launched, and with it comes Apple's ARKit, a helpful framework that makes it easier than ever for developers to create mobile AR experiences. To celebrate the occassion, we're featuring some of the best AR apps and games on... | Read more »
Phoenix Wright: Ace Attorney - Spirit of...
Phoenix Wright: Ace Attorney - Spirit of Justice 1.00.00 Device: iOS Universal Category: Games Price: $.99, Version: 1.00.00 (iTunes) Description: ************************************************※IMPORTANT※・Please read the “When... | Read more »
Kpressor (Utilities)
Kpressor 1.0.0 Device: iOS Universal Category: Utilities Price: $4.99, Version: 1.0.0 (iTunes) Description: The ultimate ZIP compression application for iPhone and iPad. - Full integration of iOS 11 with support for multitasking.-... | Read more »
Find out how you can save £35 and win a...
Nothing raises excitement like a good competition, and we’re thrilled to announce our latest contest. We’ll be sending one lucky reader and a friend to the Summoners War World Arena Championship at Le Comedia in Paris on October 7th. It’s the... | 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 »

Price Scanner via

Sunday sale: 13-inch 3.1GHz MacBook Pros for...
Amazon has 2017 13″ 3.1GHz MacBook Pros on sale today for up to $150 off MSRP, each including free shipping: – 13″ 3.1GHz/256GB Space Gray MacBook Pro (MPXV2LL/A): $1649.99 $150 off MSRP – 13″ 3.1GHz... Read more
Looking for a 2017 12″ Retina MacBook? Save $...
Apple has Certified Refurbished 2017 12″ Retina MacBooks available for $200-$240 off the cost of new models. Apple will include a standard one-year warranty with each MacBook, and shipping is free.... Read more
Apple Offering Up To $455 Credit Toward iPhon...
iPhone 8 and 8 Plus are now available at the Apple Store, and you can receive up to $375 credit toward a new iPhone purchase when you trade in your eligible smartphone. Photo Courtesy Apple Just... Read more
AnyTrans Offers iOS Users Three Ways For Movi...
iMobie Inc. today announceed AnyTrans v6.0.1, which now can help iOS users move all data to iPhone 8/8 Plus seamlessly. The software is available both on Mac and Windows and fully able to move all... Read more
Snag a 13-inch 2.3GHz MacBook Pro for $100 of...
B&H Photo has 2017 13″ 2.3GHz MacBook Pros in stock today and on sale for $100 off MSRP, each including free shipping plus NY & NJ sales tax only: – 13-inch 2.3GHz/128GB Space Gray MacBook... Read more
Verizon offers new iPhone 8 for $100-$300 off...
Verizon is offering the new iPhone 8 for up to $300 off MSRP with an eligible trade-in: • $300 off: iPhone 6S/6S Plus/7/7 Plus, Google Pixel XL, LG G6, Moto Z2 Force, Samsung Galaxy S7/S7 edge/S8/S8... Read more
Apple Refurbished 2017 13-inch MacBook Pros a...
Apple has Certified Refurbished 2017 13″ Touch Bar MacBook Pros in stock today and available for $200-$300 off MSRP. A standard Apple one-year warranty is included with each MacBook, and shipping is... Read more
OWC USB-C Travel Dock with 5 Ports Connectivi...
OWC have announced the new OWC USB-C Travel Dock, the latest addition to their line of connectivity solutions. The USB-C Travel Dock lets you connect its integrated USB-C cable to a Mac or PC laptop... Read more
Pelican Products, Inc. Unveils Cases For All...
Pelican Products, Inc. has announced the launch of its full line of cases including Voyager, Adventurer, Protector, Ambassador, Interceptor (for the Apple iPhone 8 and 8 Plus backwards compatible... Read more
$100 off new 2017 13-inch MacBook Airs
B&H Photo has 2017 13″ MacBook Airs on sale today for $100 off MSRP including free shipping. B&H charges NY & NJ sales tax only: – 13″ 1.8GHz/128GB MacBook Air (MQD32LL/A): $899, $100 off... Read more

Jobs Board

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
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* 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
Instructional Designer, *Apple* Product Doc...
Job Summary The Apple Product Documentation team is looking for an instructional designer or a video editor to write user documentation for its professional video 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
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.