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 Earth - View and contr...
Google Earth gives you a wealth of imagery and geographic information. Explore destinations like Maui and Paris, or browse content from Wikipedia, National Geographic, and more. Google Earth combines... Read more
QuickBooks R12 - Financial...
QuickBooks helps you manage your business easily and efficiently. Organize your finances all in one place, track money going in and out of your business, and spot areas where you can save. Built for... Read more
Google Earth - View and contr...
Google Earth gives you a wealth of imagery and geographic information. Explore destinations like Maui and Paris, or browse content from Wikipedia, National Geographic, and more. Google Earth combines... Read more
QuickBooks R12 - Financial...
QuickBooks helps you manage your business easily and efficiently. Organize your finances all in one place, track money going in and out of your business, and spot areas where you can save. Built for... Read more
FileZilla 3.24.0 - Fast and reliable FTP...
FileZilla (ported from Windows) is a fast and reliable FTP client and server with lots of useful features and an intuitive interface. Version 3.24.0: New The context menu for remote file search... Read more
Bookends 12.7.8 - Reference management a...
Bookends is a full-featured bibliography/reference and information-management system for students and professionals. Bookends uses the cloud to sync reference libraries on all the Macs you use.... Read more
Duplicate Annihilator 5.8.3 - Find and d...
Duplicate Annihilator takes on the time-consuming task of comparing the images in your iPhoto library using effective algorithms to make sure that no duplicate escapes. Duplicate Annihilator detects... Read more
BusyContacts 1.1.6 - Fast, efficient con...
BusyContacts is a contact manager for OS X that makes creating, finding, and managing contacts faster and more efficient. It brings to contact management the same power, flexibility, and sharing... Read more
MarsEdit 3.7.10 - Quick and convenient b...
MarsEdit is a blog editor for OS X that makes editing your blog like writing email, with spell-checking, drafts, multiple windows, and even AppleScript support. It works with with most blog services... Read more
BusyCal 3.1.4 - Powerful calendar app wi...
BusyCal is an award-winning desktop calendar that combines personal productivity features for individuals with powerful calendar sharing capabilities for families and workgroups. Its unique features... Read more

Super Mario Run dashes onto Android in M...
Super Mario Run was one of the biggest mobile launches in 2016 before it was met with a lukewarm response by many. While the game itself plays a treat, it's pretty hard to swallow the steep price for the full game. With that said, Android users... | Read more »
WarFriends Beginner's Guide: How to...
Chillingo's new game, WarFriends, is finally available world wide, and so far it's a refreshing change from common mobile game trends. The game's a mix of tower defense, third person shooter, and collectible card game. There's a lot to unpack here... | Read more »
Super Gridland (Entertainment)
Super Gridland 1.0 Device: iOS Universal Category: Entertainment Price: $1.99, Version: 1.0 (iTunes) Description: Match. Build. Survive. "exquisitely tuned" - Rock Paper Shotgun No in-app purches, and no ads! | Read more »
Red's Kingdom (Games)
Red's Kingdom 1.0 Device: iOS Universal Category: Games Price: $4.99, Version: 1.0 (iTunes) Description: Mad King Mac has kidnapped your father and stolen your golden nut! Solve puzzles and battle goons as you explore and battle your... | Read more »
Turbo League Guide: How to tame the cont...
| Read more »
Fire Emblem: Heroes coming to Google Pla...
Nintendo gave us our first look at Fire Emblem: Heroes, the upcoming mobile Fire Emblem game the company hinted at last year. Revealed at the Fire Emblem Direct event held today, the game will condense the series' tactical RPG combat into bite-... | Read more »
ReSlice (Music)
ReSlice 1.0 Device: iOS Universal Category: Music Price: $9.99, Version: 1.0 (iTunes) Description: Audio Slice Machine Slice your audio samples with ReSlice and create flexible musical atoms which can be triggered by MIDI notes or... | Read more »
Stickman Surfer rides in with the tide t...
Stickson is back and this time he's taken up yet another extreme sport - surfing. Stickman Surfer is out this Thursday on both iOS and Android, so if you've been following the other Stickman adventures, you might be interested in picking this one... | Read more »
Z-Exemplar (Games)
Z-Exemplar 1.4 Device: iOS Universal Category: Games Price: $3.99, Version: 1.4 (iTunes) Description: | Read more »
5 dastardly difficult roguelikes like th...
Edmund McMillen's popular roguelike creation The Binding of Isaac: Rebirth has finally crawled onto mobile devices. It's a grotesque dual-stick shooter that tosses you into an endless, procedurally generated basement as you, the pitiable Isaac,... | Read more »

Price Scanner via

Twelve South Releases RelaxedLeather Cases fo...
Inspired by the laid-back luxury of burnished leather boots and crafted in rich tones of taupe, herb and marsala, RelaxedLeather cases deliver smart, easy protection for the iPhone 7. Each genuine... Read more
Week’s Best Deal: New 2016 13-inch 2.0GHz Mac...
Amazon has the new 2016 13″ 2.0GHz non-Touch Bar MacBook Pros on sale for a limited time for $225 off MSRP including free shipping: - 13″ 2.0GHz MacBook Pro, Space Gray (MLL42LL/A): $1274.99 $225 off... Read more
Back in stock: Apple refurbished Mac minis fr...
Apple has Certified Refurbished Mac minis available starting at $419. Apple’s one-year warranty is included with each mini, and shipping is free: - 1.4GHz Mac mini: $419 $80 off MSRP - 2.6GHz Mac... Read more
Apple Ranked ‘Most Intimate Brand’
The top ranked ‘”intimate” brands continued to outperform the S&P and Fortune 500 indices in revenue and profit over the past 10 years, according to MBLM’s Brand Intimacy 2017 Report, the largest... Read more
B-Eng introduces SSD Health Check for Mac OS
Fehraltorf, Switzerland based independant Swiss company- B-Eng has announced the release and immediate availability of SSD Health Check 1.0, the company’s new hard drive utility for Mac OS X. As the... Read more
Apple’s Education discount saves up to $300 o...
Purchase a new Mac or iPad using Apple’s Education Store and take up to $300 off MSRP. All teachers, students, and staff of any educational institution qualify for the discount. Shipping is free: -... Read more
4-core 3.7GHz Mac Pro on sale for $2290, save...
Guitar Center has the 3.7GHz 4-core Mac Pro (MD253LL/A) on sale for $2289.97 including free shipping or free local store pickup (if available). Their price is a $710 savings over standard MSRP for... Read more
128GB Apple iPad Air 2, refurbished, availabl...
Apple has Certified Refurbished 128GB iPad Air 2s WiFis available for $419 including free shipping. That’s an $80 savings over standard MSRP for this model. A standard Apple one-year warranty is... Read more
13-inch 2.7GHz Retina MacBook Pro on sale for...
B&H Photo has the 2015 13″ 2.7GHz/128GB Retina Apple MacBook Pro on sale for $100 off MSRP. Shipping is free, and B&H charges NY tax only: - 13″ 2.7GHz/128GB Retina MacBook Pro (MF839LL/A): $... Read more
Laptop Market – Flight To Quality? – The ‘Boo...
Preliminary quarterly PC shipments data released by Gartner Inc. last week reveal an interesting disparity between sales performance of major name PC vendors as opposed to that of less well-known... Read more

Jobs Board

*Apple* macOS Systems Integration Administra...
…most exceptional support available in the industry. SCI is seeking an Junior Apple macOS systems integration administrator that will be responsible for providing Read more
*Apple* Retail - Multiple Positions- Deer Pa...
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* 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* Technician - nfrastructure (United S...
Let’s Work Together Apple Technician This position is based in Portland, ME Life at nfrastructure At nfrastructure, we understand that our success results from our Read more
*Apple* Mobile Master - Best Buy (United Sta...
**467692BR** **Job Title:** Apple Mobile Master **Location Number:** 000602-Columbia MO-Store **Job Description:** **What does a Best Buy Apple Mobile Master Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.