TweetFollow Us on Twitter

Spring 91 - MACINTOSH Q & A

MACINTOSH Q & A

MACINTOSH DEVELOPER TECHNICAL SUPPORT

Q The TrapAvailable function listed in the "Compatibility Guidelines" chapter of Inside Macintosh Volume VI contains code that checks the size of the trap table. Do I have to do this if my application doesn't support the old 64K ROMs?

A Yes, you do. With the introduction of the Macintosh Plus and 128K ROMs, the trap table was divided into the OS trap table and Toolbox trap table. The number of trap table entries was increased and the format of those entries was expanded. For additional information on this expansion see the "Using Assembly Language" chapter of Inside Macintosh Volume IV. However, the 64K to 128K ROM trap table expansion is not what the code in the TrapAvailable function is checking for. The Toolbox trap table was expanded yet again when the Macintosh II was introduced. The Macintosh Plus and SE use the smaller Toolbox trap table on pre-7.0 systems. To be sure your application is compatible with these machines on pre- 7.0 systems, check the size of the Toolbox trap table.

Q What are the guidelines for determining how much of an image CopyBits can copy to a Macintosh pixel map at one time, given a particular set of characteristics for the source map and the destination map and given how much stack space is available? For example, say that we have an 8-bit-deep pixMap to be copied to a 32-bit-deep pixMap using the ditherCopy mode and expanded by a factor of 4, and we have 45K of stack space.

A CopyBits' stack requirement depends on the width of each scan line (rowBytes). The rule of thumb is that you need at least as much stack as the rowBytes value in your image (which can be huge with 32-Bit QuickDraw), with the following additional modifiers: add an additional rowBytes for dithering; add an additional rowBytes for any stretching (source rect != dest rect); add an additional rowBytes for any color map changing; add an additional rowBytes for any color aliasing. The stack space you need is roughly five times the rowBytes of your image. In general, you're better off processing narrower scan lines. Reducing the vertical size will not affect stack requirements. Narrow, tall bands (if you can use them) will reduce the stack requirements.

Q Where can I find documentation on how to write a Macintosh printer driver equivalent to the ImageWriter® or LaserWriter driver? In particular, how are Printing Manager and QuickDraw commands translated into calls to the printer driver?

A DTS's "Learning to Drive" document and "SampleWriter" source code, available in AppleLink's Developer Support folder and on the latest Developer Essentials CD, are helpful references.

Q How can I determine what hardware device is driven by a particular Macintosh gDevice? I can call GetDeviceList and GetNextDevice to get the driver reference number of each gDevice but not the hardware ID. The system 'scrn' resource for the hardware ID of each device doesn't give me the driver reference number. The device list produced by calling GetDeviceList and GetNextDevice isn't always in the same order as the 'scrn' resource slot information.

A The following code shows how to obtain the slot number:

DCEHand = (AuxDCEHandle) GetDCtlEntry(DevInfoList[index].gdRefNum);
DevInfoList[devCount].gdSlot = (*DCEHand) -> dCtlSlot; 
                                             /* Get slot number. */

Once you have the slot number, you can call the Slot Manager to get the board name and other information you may need to identify the device, as in the following code:

/* Get the board name from the Slot Manager's board sResource. */
spB.spSlot = DevInfoList[devCount].gdSlot;
spB.spID = 0;
spB.spExtDev = 0;
spB.spCategory = 1;             /* board sResource sRsrcType value */
spB.spCType = 0;
spB.spDrvrSW = 0;
spB.spDrvrHW = 0;
if (! SNextTypesRsrc(&spB) ) {
  spB.spID = 2;       /* Found board sRsrc now, get the sRsrcName. */
  if ( ! SGetCString(&spB) ) { 
      /* Let C unravel its own strings. */
      for (count = 0;
           DevInfoList[devCount].bdName[count+1] 
                 = *((char *)(spB.spResult)+count);
           count++);
       DevInfoList[devCount].bdName[0] = count;
  }
}

Q When I draw a 32-bit Macintosh 'PICT' image from a file to an 8-bit port via an off-screen GWorld, I use dithered mode in the CopyBits call and the results are quite impressive. If there's not enough memory to allocate the GWorld, I draw the image directly to the port. But since there doesn't seem to be any way to tell QuickDraw to use dithered drawing mode, the image looks horrible. Should I use dithered mode instead of source mode? I don't want to try to parse the 'PICT' myself, but I thought that maybe a QuickDraw global could be modified in my StdBits proc to force dithered drawing for that operation only.

A You can install a bitsProc bottleneck procedure to get all the CopyBits calls when the picture is being played back. One of the parameters to the bitsProc call is the mode. You can install a procedure that passes ditherMode to the original StdBits proc.

Q Why does a call to gestaltNuBusConnectors return zero slots when there actually is a NuBusTM card or a PDS (Processor Direct Slot) card in the Macintosh IIsi slot?

A A call to gestaltNuBusConnectors returns zero slots because there's no way to determine if there's a NuBus card or a PDS card in the Macintosh IIsi slot. Gestalt can't assume that there's always a NuBus or PDS slot, so it just says there's no slot. However, Apple recommends that you always use the Slot Manager instead of Gestalt to search for cards, after first checking to see that the Slot Manager trap is implemented. The Slot Manager will safely do all the necessary work for you whether a card with a valid declaration ROM is installed or not, and you can search for the card using a variety of criteria. This technique will allow you to locate NuBus cards, but has the added benefit of being able to find PDS cards that contain declaration ROMs.

The Macintosh SE/30, IIfx, and LC have the Slot Manager and PDS slots. It's safe to assume the Slot Manager will be resident in all future machines that have either NuBus or PDS slot capability.

Q Do you have any available tools or test programs for testing how well our Macintosh application responds to core Apple events? We need a test application that will, for example, send events to open a document and print it within our application.

A One of the best tools to test Apple events like 'odoc' and 'pdoc' is the Finder®. The System 7.0 beta CD version of the Finder provides excellent 'odoc' and 'pdoc' testing capabilities. That's what most of DTS uses to test sample applications.

There are no tools designed specifically to send Apple events to an application as a test. Try using some of the DTS sample applications on the Developer Essentials disc to test your application. One of the easiest to use and adapt is the TrafficLight 3.0 sample. It already will send its own MoveWindow Apple event to any application, allowing you to see how your application is handling "foreign" events.

Also, you can adapt the CreateAndSendAppleEvent function in AppleEvents.c to send any type of event you'd like, which allows you to test events that may be specific to your application.Q Why do I get a bomb when I create a Macintosh filename starting with a period (.)?

A Macintosh filenames are not allowed to begin with a period, to avoid possible confusion with driver names, which must begin with a period. (This restriction does not apply to folder names.) Ideally, the Finder should catch this possible error and require the file to be renamed, but it doesn't. Future versions of the Finder should catch this potential problem, but until then users must remember not to begin a filename with a period. See Macintosh Technical Note #102, HFS Elucidations, for details.

Q Can the refNum returned by FSOpen ever be 1? What is the range or format of legal refNums?

A Macintosh file reference numbers (refNums) are currently positive and that means any positive number, including 1. This doesn't mean that they won't change in the future, however. To maintain system compatibility, use refNums only as they're intended to be used.

Q Calling Create from an INIT causes the INIT to be called twice if it alphabetically follows the file it creates. Is there a workaround?

A This particular limitation of the startup process occurs when you create files in the same folder as the INIT that alphabetically precede your INIT file. HFS orders files alphabetically, and the startup process does its thing by incrementing the ioFDirIndex field of a PBGetFileInfo call. Your INIT file (for example, file #5) is getting opened, your INIT is called, and it creates a file. The file it creates, for example, is file #3--that is, it's alphabetically before your INIT file. Now your INIT file is file #6, and when you return, it increments the ioFDirIndex value from 5 to-- you guessed it--6, opens that file, and runs your INIT again.

The workaround is to avoid creating files in the same folder as the INIT that alphabetically precede your INIT file. Also, the file you create should be placed in the Preferences folder within the System Folder, for both System 6 and System 7. Check for a Preferences folder within the System Folder using FindFolder, and create one if it doesn't exist.

Q During a Macintosh application's life, does the value of A5 change? Why does SetCurrentA5 have to set A5 to CurrentA5? Aren't A5 and CurrentA5 the same while an application is executing non-interrupt- time code?

A A5 is not necessarily always equal to CurrentA5. Because the Macintosh operating system and Toolbox don't need to access your application's jump table or global variables (which A5 points to), they often use A5 for other purposes, except for the parts of the Toolbox that need to perform graphics operations and use the QuickDraw globals defined by your application.

Because the operating system or Toolbox can change A5, you must make sure it's set correctly if the operating system or Toolbox ever calls your code in the form of a callback. For example, if you make an asynchronous File Manager call, your I/O completion routine must call SetCurrentA5 for your I/O completion routine. Other places where you may want to call SetCurrentA5 are in trap patches, your GrowZoneProc, custom MDEFs, WDEFs, or CDEFs, or control action procedures.

Please note that even SetCurrentA5 is not sufficient when writing code that's executed at interrupt time, such as VBL and Time Manager tasks. When an interrupt occurs that your application wants to handle, there is no guarantee that the low-memory global CurrentA5 belongs to your application. The interrupt could occur while some other application is running under MultiFinder®. In this case, you should use other approaches to setting A5. Please see Technical Note #180, MultiFinder Miscellanea, for further information.

Q My Macintosh application receives information from the serial port, keeping as much information in memory as possible. However, if I do run out of memory, my GrowZone routine is allowed to delete older information. Does the operating system allow the GrowZone routine to be called recursively? That is, if in handling a GrowZone call, my code does something that requires memory, such as bringing in a font that isn't there, can I call the GrowZone routine again or would doing so cause an error? Am I allowed to update things on the screen, such as windows and text in windows, while in my GrowZone routine?

A Neither the GrowZone routine nor the Macintosh system is reentrant. There is very little that you can safely do in a GrowZone routine. The system expects that the typical extent of a GrowZone routine is to check a table or some other predesignated criteria and then to release or not to release any memory blocks it can. Any sort of user interface is well beyond the reasonable scope of this level of routine.

Keep a list of handles to blocks of text that you're willing to purge, so that your GrowZone routine can look through them when called and then release one or more blocks. Any more than that is really stretching GrowZone too far. By the way, SetGrowZone should not be assumed to return a result. Inside Macintosh is incorrect in saying that D0 contains a result code on exit.

Q Do I need to call StripAddress when using SwapMMUMode to switch to 32-bit mode? I would like to assume that all my pointers are valid 32-bit quantities when in 32-bit mode.

A Yes, though it would be nice to be able to assume that all your master pointers are valid 32-bit quantities when in 32-bit mode, the assumption would only be true of master pointers that were created in a zone created while you were in 32-bit mode, and even this would only be true on systems that have a 32-bit Memory Manager (the Macintosh IIci, IIfx, LC, and IIsi).

You need to call StripAddress on any master pointers that were created in a 24-bit world that you expect to use while in 32-bit mode. You also need to call StripAddress on distinct master pointers that were created in 24-bit mode if you want to compare them, regardless of whether you're currently in 32-bit mode.

Q When building a standalone code resource (such as an 'XCMD', 'INIT', 'CDEV', or 'CDEF') with the MPW Linker, the main entry point is specified with the "-m" option. So why does one also need to make sure that the main routine is the first one in its object file, and that that object file is the first one linked? Why isn't "-m" enough for the Linker to figure this out?

A The MPW® Linker generally places modules in the output file in the order that they appear in the sequence of files to be linked. When building an application, the Linker builds the jump table after building all the code resources; thus, it doesn't need to have "seen" the main procedure first in order to place the main procedure's entry first in the jump table. For standalone code resources (which have no jump table), the main procedure must be first in the code resource. The simplest way to make sure this happens is, as you say, to make sure that the main procedure is the first one the Linker sees.

Q Why does MPW Pascal convert SINGLE numbers to extended, create a temporary area for them, and then pass a pointer to those extended numbers on the stack?

A The conversion of single-precision values to extended is being done to maintain accuracy. It's entirely possible to generate values of extended precision while doing the intermediate math with single-precision values, and the MPW compilers do this conversion to preserve accuracy. If your application doesn't need the accuracy, you can declare the parameters to be of type LONGINT, and typecast them as necessary within your procedure or function. There's no way to tell the MPW compilers not to do the conversion if the parameters are declared as SINGLE.

Q What is the difference between RelString and EqualString? What should Macintosh developers use when sorting? Do you suggest having an option for the international sort?

A RelString and EqualString are mainly intended for the File Manager. The File Manager uses them for quick-and-dirty string comparison so that it knows how to return files ordered alphabetically when you use indexed File Manager routines, and so that it can detect file name collisions. Beyond that, RelString and EqualString aren't localizable or extensible.

The International Utilities string comparison routines are localizable and extensible. They use information in the active 'itl2' resource to determine how the characters are sorted. Most localized systems come with their own 'itl2' resource, so string comparisons are done correctly for the region for which the system is localized. Because RelString and EqualString stay the same for all these regions, you'll probably find some cases in which strings are compared incorrectly by these routines.

One important place where RelString and EqualString don't work very well is with the new characters in the extended Macintosh character set. When the LaserWriter was introduced, the LaserWriter fonts used the extended Macintosh character set, which added many new characters, including several new uppercase characters with diacriticals. In system software version 6.0.4, the International Utilities were updated to take advantage of these new characters. For example, the uppercase "E" with a grave accent first appeared in the extended Macintosh character set. With 6.0.4, the lowercase and uppercase "E" with a grave accent were considered to be equal in primary ordering, and unequal in secondary ordering, which is correct. Even today, RelString and EqualString think in the old Macintosh character set, erroneously believing that lowercase and uppercase "E" with a grave accent have nothing to do with each other.

Q The Macintosh IIsi and LC computers don't come with programmer's switches. How do I get reset and NMI on these machines?

A Both machines have an ADB (Apple Desktop Bus) I/O processor which incorporates the reset and NMI functions through the keyboard. The functions are accessed as follows:

  • Use MacsBug 6.2 or later to enable the NMI on the Macintosh IIsi or LC. Both machines start up with NMI disabled because nontechnical users might get into trouble with it, so the ADB controller must be programmed to enable it. Once MacsBug is installed, you can activate NMI by holding down the Command key while pressing the Power button.
  • Hold down the Command and Control keys while pressing the Power button, with or without MacsBug installed, to reset these Macintosh systems.

Under some circumstances you may have to hold the reset and NMI key combinations down for a little while (but no more than a second) to make sure the ADB processor sees them.

You'll find the latest MacsBug on the Developer Essentials disc and in AppleLink's Developer Support folder. The MacsBug reference manual is very helpful. A package containing both MacsBug 6.2 and the manual is available from APDA for $35.00 (#M7034/B).

Q What's wrong with having VBL (Vertical Blanking) tasks make calls to the Macintosh Memory Manager, either directly or indirectly?

A The problem is that the Memory Manager could be moving memory around when an interrupt occurs. If the VBL task also moves memory, the heap could be destroyed. VBL tasks are intended to provide a method of time-syncing to the video beam of the display. (On slotted Macintosh models you'd use SlotVInstall.) They're also used to get periodic time for short tasks, although the Time Manager is better for this. VBL tasks should minimize execution time. The best use of a VBL task is to do a short condition check and set a flag for the main process to indicate that it's now a good time to do something.

Q Can I still write to James Brown at his work release address?

A The Godfather of Soul was released from prison on parole last March. His new address is
Universal Attractions
218 West 57 Street
New York, NY 10019

Kudos to our readers who care enough to ask us terrific and well thought-out questions. The answers are supplied by our teams of technical gurus; our thanks to all. Special thanks to Pete "Luke" Alexander, Mark Baumwell, Rich Collyer, Marcie "MG" Griffin, C. K. Haun, Dennis Hescox, Kevin Mellander, Guillermo Ortiz, Keith Rollin, Kent Sandvik, Gordon Sheridan, Paul Snively, Bryan Stearns, Forrest Tanaka, Vince Tapia, and Scott "Zz" Zimmerman for the material in this Q & A column.*

Have more questions? Need more answers? Take a look at the developer technical library on AppleLink (updated weekly) or the Q & A stack on the Developer Essentials disc.*

 
AAPL
$102.50
Apple Inc.
+0.25
MSFT
$45.43
Microsoft Corpora
+0.55
GOOG
$571.60
Google Inc.
+2.40

MacTech Search:
Community Search:

Software Updates via MacUpdate

VueScan 9.4.41 - 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
Cloud 3.0.0 - File sharing from your men...
Cloud is simple file sharing for the Mac. Drag a file from your Mac to the CloudApp icon in the menubar and we take care of the rest. A link to the file will automatically be copied to your clipboard... Read more
LibreOffice 4.3.1.2 - Free Open Source o...
LibreOffice is an office suite (word processor, spreadsheet, presentations, drawing tool) compatible with other major office suites. The Document Foundation is coordinating development and... Read more
SlingPlayer Plugin 3.3.20.505 - Browser...
SlingPlayer is the screen interface software that works hand-in-hand with the hardware inside the Slingbox to make your TV viewing experience just like that at home. It features an array of... Read more
Get Lyrical 3.8 - Auto-magically adds ly...
Get Lyrical auto-magically add lyrics to songs in iTunes. You can choose either a selection of tracks, or the current track. Or turn on "Active Tagging" to get lyrics for songs as you play them.... Read more
Viber 4.2.2 - Send messages and make cal...
Viber lets you send free messages and make free calls to other Viber users, on any device and network, in any country! Viber syncs your contacts, messages and call history with your mobile device,... Read more
Cocktail 7.6 - General maintenance and o...
Cocktail is a general purpose utility for OS X that lets you clean, repair and optimize your Mac. It is a powerful digital toolset that helps hundreds of thousands of Mac users around the world get... Read more
LaunchBar 6.1 - Powerful file/URL/email...
LaunchBar is an award-winning productivity utility that offers an amazingly intuitive and efficient way to search and access any kind of information stored on your computer or on the Web. It provides... Read more
Maya 2015 - Professional 3D modeling and...
Maya is an award-winning software and powerful, integrated 3D modeling, animation, visual effects, and rendering solution. Because Maya is based on an open architecture, all your work can be scripted... Read more
BBEdit 10.5.12 - Powerful text and HTML...
BBEdit is the leading professional HTML and text editor for the Mac. Specifically crafted in response to the needs of Web authors and software developers, this award-winning product provides a... Read more

Latest Forum Discussions

See All

Qube Kingdom – Tips, Tricks, Strategies,...
Qube Kingdom is a tower defense game from DeNA. You rally your troops – magicians, archers, knights, barbarians, and others – and fight against an evil menace looking to dominate your kingdom of tiny squares. Planning a war isn’t easy, so here are a... | Read more »
Qube Kingdom Review
Qube Kingdom Review By Nadia Oxford on August 29th, 2014 Our Rating: :: KIND OF A SQUARE KINGDOMUniversal App - Designed for iPhone and iPad Qube Kingdom has cute visuals, but it’s a pretty basic tower defense game at heart.   | Read more »
Fire in the Hole Review
Fire in the Hole Review By Rob Thomas on August 29th, 2014 Our Rating: :: WALK THE PLANKUniversal App - Designed for iPhone and iPad Seafoam’s Fire in the Hole looks like a bright, 8-bit throwback, but there’s not enough booty to... | Read more »
Alien Creeps TD is Now Available Worldwi...
Alien Creeps TD is Now Available Worldwide Posted by Ellis Spice on August 29th, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Dodo Master Review
Dodo Master Review By Jordan Minor on August 29th, 2014 Our Rating: :: NEST EGGiPad Only App - Designed for the iPad Dodo Master is tough but fair, and that’s what makes it a joy to play.   | Read more »
Motorsport Manager Review
Motorsport Manager Review By Lee Hamlet on August 29th, 2014 Our Rating: :: MARVELOUS MANAGEMENTUniversal App - Designed for iPhone and iPad Despite its depth and sense of tactical freedom, Motorsport Manager is one of the most... | Read more »
Motorsport Manager – Beginner Tips, Tric...
The world of Motorsport management can be an unforgiving and merciless one, so to help with some of the stress that comes with running a successful race team, here are a few hints and tips to leave your opponents in the dust. | Read more »
CalPal Update Brings the App to 2.0, Add...
CalPal Update Brings the App to 2.0, Adds Lots of New Stuff Posted by Ellis Spice on August 29th, 2014 [ permalink ] | Read more »
Baseball Battle Review
Baseball Battle Review By Jennifer Allen on August 29th, 2014 Our Rating: :: SIMPLE HITTINGUniversal App - Designed for iPhone and iPad Simple and cute, Baseball Battle is a fairly fun baseball game for those looking for something... | Read more »
Checkmark 2.1 Update Released, and it’s...
Checkmark 2.1 Update Released, and it’s on Sale for a Limited Time Posted by Jessica Fisher on August 29th, 2014 [ permalink ] | Read more »

Price Scanner via MacPrices.net

Labor Day Weekend MacBook Pro sale; 15-inch m...
B&H Photo has the new 2014 15″ Retina MacBook Pros on sale for up to $125 off MSRP. Shipping is free, and B&H charges NY sales tax only. They’ll also include free copies of Parallels Desktop... Read more
Labor Day Weekend iPad mini sale; $50 to $100...
Best Buy has the iPad mini with Retina Display (WiFi models) on sale for $50 off MSRP on their online store for Labor Day Weekend. Choose free shipping or free local store pick up. Price is for... Read more
13-inch 1.4GHz MacBook Air on sale for $899,...
Adorama has the new 2014 13″ 1.4GHz/128GB MacBook Air on sale for $899.99 including free shipping plus NY & NJ tax only. Their price is $100 off MSRP. Read more
It’s Official: Apple Issues Invitations To Se...
Apple has issued one of its characteristically cryptic press invitations for a special event to be held at the Flint Center for the Performing Arts in hometown Cupertino on Sept. 9, 2014 at 10:00 am... Read more
Tablet Shipments To See First On-year Decline...
TrendForce analyst Caroline Chen notes that when the iPad launched in 2010, it was an instant hit and spurred a tablet PC revolution, with tablets so popular that that notebook PC sales stagnated and... Read more
SOBERLINK Releases Apple iOS Compatible Handh...
Cypress, California based SOBERLINK, Inc., creator of the first handheld Breathalyzer designed to improve recovery outcomes, continues to show prominence in the mobile alcohol monitoring space with... Read more
New 21″ 1.4GHz iMac on sale again for $999, s...
Best Buy has the new 21″ 1.4GHz iMac on sale for $999.99 on their online store. Their price is $100 off MSRP. Choose free shipping or free local store pick up. Price is for online orders only, in-... Read more
Smartphone Outlook Remains Strong for 2014, U...
According to a new mobile phone forecast from the International Data Corporation (IDC) Worldwide Quarterly Mobile Phone Tracker, more than 1.25 billion smartphones will be shipped worldwide in 2014,... Read more
Save up to $60 with Apple refurbished iPod to...
The Apple Store has Apple Certified Refurbished 5th generation iPod touches available starting at $149. Apple’s one-year warranty is included with each model, and shipping is free. Many, but not all... Read more
12-Inch MacBook Air Coming in 4Q14 or 2015 –...
Digitimes’ Aaron Lee and Joseph Tsai report that according to Taiwan-based upstream supply chain insiders, Apple plans to launch a thinner MacBook model either at year end 2014 or in 2015, and that... Read more

Jobs Board

*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
Senior Event Manager, *Apple* Retail Market...
…This senior level position is responsible for leading and imagining the Apple Retail Team's global event strategy. Delivering an overarching brand story; in-store, Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.