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

GraphicConverter 11.2.2 - $39.95
GraphicConverter is an all-purpose image-editing program that can import 200 different graphic-based formats, edit the image, and export it to any of 80 available file formats. The high-end editing... Read more
VueScan 9.7.30 - Scanner software with a...
VueScan is a scanning program that works with most high-quality flatbed and film scanners to produce scans that have excellent color fidelity and color balance. VueScan is easy to use, and has... Read more
Things 3.12.6 - Elegant personal task ma...
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
Skim 1.5.11 - PDF reader and note-taker...
Skim is a PDF reader and note-taker for OS X. It is designed to help you read and annotate scientific papers in PDF, but is also great for viewing any PDF file. Skim includes many features and has a... Read more
Navicat Premium Essentials 15.0.20 - Pro...
Navicat Premium Essentials is a compact version of Navicat which provides basic and necessary features you will need to perform simple administration on a database. It supports the latest features... Read more
Affinity Photo 1.8.4 - Digital editing f...
Affinity Photo - redefines the boundaries for professional photo editing software for the Mac. With a meticulous focus on workflow it offers sophisticated tools for enhancing, editing and retouching... Read more
EtreCheck Pro 6.3 - For troubleshooting...
EtreCheck is an app that displays the important details of your system configuration and allow you to copy that information to the Clipboard. It is meant to be used with Apple Support Communities to... Read more
beaTunes 5.2.11 - Organize your music co...
beaTunes is a full-featured music player and organizational tool for music collections. How well organized is your music library? Are your artists always spelled the same way? Any R.E.M. vs REM?... Read more
Bookends 13.4.4 - 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
Affinity Designer 1.8.4 - Vector graphic...
Affinity Designer is an incredibly accurate vector illustrator that feels fast and at home in the hands of creative professionals. It intuitively combines rock solid and crisp vector art with... Read more

Latest Forum Discussions

See All

Global Spy is an intriguing 2D spy sim f...
Developer Yuyosoft Innovations' Global Spy launched last month for iOS and Android, though if you missed it at the time, we're here to tell you why it's well worth a go. This one's all about international espionage, tracking down elusive spies,... | Read more »
Distract Yourself With These Great Mobil...
There’s a lot going on right now, and I don’t really feel like trying to write some kind of pithy intro for it. All I’ll say is lots of people have been coming together and helping each other in small ways, and I’m choosing to focus on that as I... | Read more »
Hyena Squad is sci-fi turn-based strateg...
Wave Light Games has just revealed its latest release, Hyena Squad, a turn-based RPG set in a space station infested by gross aliens and the living dead. The announcement was first reported on by Touch Arcade. [Read more] | Read more »
Idle Guardians: Never Die is a pixel art...
SuperPlanet has been fairly prolific with game releases so far this year with both Evil Hunter Tycoon and Lucid Adventure releasing earlier this year. Now, they've released another idle RPG called Idle Guardians: Never Die, which you can download... | Read more »
Ruinverse, Kemco's latest RPG, now...
Kemco's latest RPG endeavour, Ruinverse, initially launched for both iOS and Android earlier this month. It was released as a premium title that also had additional in-app purchases. Now, the developers have decided to release a freemium version... | Read more »
The 5 Best Mobile Platformers
Touch screens and action-oriented gameplay don't typically mix, but over the course of pondering the best platformers on mobile, I found myself having a really hard time picking just five. Quite a few developers have found really creative ways to... | Read more »
Clash Royale: The Road to Legendary Aren...
Supercell recently celebrated its 10th anniversary and their best title, Clash Royale, is as good as it's ever been. Even for lapsed players, returning to the game is as easy as can be. If you want to join us in picking the game back up, we've put... | Read more »
Endless runner Monster Dash will relaunc...
Remember Monster Dash? Well, it's set to return to a mobile device near you after having been pulled from stores in 2017 to meet GDPR compliance. This one first launched all the way back in August of 2010. Over ten years later, it's heading into... | Read more »
Auto Battle Chess is a colourful genre s...
Auto Battle Chess is an interesting hodgepodge of genres that aims to offer the ultimate auto chess experience. That's a pretty tall order, though with the game now out for Android, I suppose we don't have to wait to see if it lives up to its... | Read more »
Tom and Jerry: Chase hits 1 million pre-...
NetEase's 1v4 asymmetrical multiplayer game Tom and Jerry: Chase recently became available to pre-order for both iOS and Android in Southeast Asia. It's clearly proving to be a highly anticipated title too since it has now reached 1 million pre-... | Read more »

Price Scanner via

Expercom offers $320 discount on the 6-core 1...
Apple reseller Expercom has the Silver 16″ 6-core MacBook Pro on sale for a limited time for $2079 shipped. Their price is $320 off Apple’s MSRP for this model, and it’s the cheapest price currently... Read more
Apple announces Education pricing for new 202...
Purchase a new 2020 iMac or iMac Pro at Apple using Apple’s Education discount, and take up to $400 off MSRP. All teachers, students, and staff of any educational institution with a .edu email... Read more
Apple reseller Expercom offers $256 discount...
Expercom has Apple’s new 2020 10-core iMac Pro available for order and on sale for $4743 shipped. Their price is $256 off Apple’s MSRP for this new model, and it’s the cheapest price we’ve seen so... Read more
Apple releases refreshed 2020 27″ iMacs with...
Apple today released updated versions of their 27″ iMacs featuring 10th generation Intel processors, SSDs across the board, a better 5K display, and improvements to the camera, speakers, and mic.... Read more
Xfinity Mobile promo: Take $200-$350 off Appl...
New customers can take $200 off the purchase of any new Apple iPhone model at Xfinity Mobile through 8/17/20. Service plan required. Existing customers can purchase an iPhone and receive $200 back in... Read more
B&H now offering $100-$200 discount on Ap...
B&H Photo has new 2020 13″ 2.0GHz MacBook Pros on sale for $100-$200 off Apple’s MSRP, starting at $1649. These are the same MacBook Pros sold by Apple in their retail and online stores, and B... Read more
Apple’s 6-Core Mac mini is on sale at Amazon...
Amazon has Apple’s new 2020 6-Core Mac mini on sale for $926.25 for a limited time. Their price is $173 off Apple’s $1099 MSRP for this model and includes a $48.75 instant discount available on their... Read more
New 2020 11″ iPad Pros on sale for $50-$75 of...
Apple reseller Expercom has new 2020 11″ Apple iPad Pros on sale for $50-$75 off MSRP, with prices starting at $749. These are the same iPad Pros sold by Apple in their retail and online stores: – 11... Read more
Switch to US Cellular and get a new Apple iPh...
US Cellular has Apple’s 2020 iPhone SE on sale for $350 off for new lines of service and a US Cellular unlimited plan. Promotion comes via monthly bill credits over a 30 month period. Their deal... Read more
Apple AirPods with Wireless Charging Case on...
Amazon has Apple’s AirPods with Wireless Charging Case on sale today for only $139.98 shipped. That’s $60 off Apple’s MSRP and the lowest price we’ve ever seen for these AirPods. Sale valid for a... Read more

Jobs Board

Director, Product Management - Lead *Apple*...
…better business results. **Job Title** Director, Product Management - Lead Apple / Token Requestor Services Overview The Mastercard Digital Enablement Services Read more
*Apple* Computing Professional - Store 286 (...
**770445BR** **Job Title:** Apple Computing Professional - Store 286 (Canton) **Job Category:** Store Associates **Store Number or Department:** 000286-Canton-Store Read more
Department Manager- Tech Shop/ *Apple* Stor...
…their parents want, and our faculty needs. As a Department Manager in our Tech Shop/ Apple Store you will spend the majority of your time on the sales floor engaging Read more
*Apple* Graders/Inspectors (Seasonal/Hourly/...
Title: Apple Graders/Inspectors (Seasonal/Hourly/No Benefits) # APPLE Location: US-VA-Winchester Read more
Tier 2 Technical Support Analyst - ( *Apple*...
…Analystiless than/strong>who will analyze and determine user software needs on all Apple devices (first support contact), Windows devices, and support printers in Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.