Macintosh Q & A

Q I'm having problems with our caching drivers on the Power Macintosh 9500. Our
drivers allocate a large amount of RAM (up to 4 MB) early in the boot process. If I set
the driver's cache size to 4 MB, the computer locks up as soon as the driver is
executed. If I set the cache size to 2 MB, the driver loads and executes properly, but
the computer gets a bus error much later in the boot process (after MacsBug loads and
after the Mac OS screen is displayed, but before the Finder executes). If I set the cache
size to 1 MB, everything runs properly. What's going on here?

A Because of Open Firmware requirements, the boot stack on the new Power
Macintosh 9500 CPUs was changed to 4 MB. As a result, you can't grow the system
heap past 4 MB or a system crash will occur. If possible, try to defer allocating
memory until INIT time. The 'sysz' mechanism is supported by the enabler ('boot' 3)
when INITs are being loaded.

Q We want to maximize our throughput across the PCI bus between Macintosh memory
and a block of static RAM on our card. This static RAM is also accessible from an
on-card DSP, which constantly reads/modifies RAM. The DSP isn't directly on the PCI
bus, so it can't easily participate in cache coherency schemes. What's the best way to
get data across the PCI bus to and from this memory?

A The PowerPC processor can only burst to and from a cacheable memory space.
Your best option is to use BlockMoveDataUncached. This doesn't use burst transfers,
but rather uses floating-point loads and stores. You may want to design your own
algorithms, using the double declaration in C to get compilers to translate
BlockMoveDataUncached into floating-point loads and stores. For more information,
see Chapter 9 of Designing PCI Cards and Drivers for Power Macintosh Computers, and
Technote 1008, "Understanding PCI Bus Performance."

Q The Power Macintosh 9500 Developer Note says that the sound-in port for the 9500
has 4-conductor requirements. What is the 4-conductor pinout? Does the PlainTalk
microphone work on the 9500?

A  The 9500 has stereo in (supporting left, right, power, and ground) and requires a
mini stereo plug that you can buy today -- no wacky new pinouts. The PlainTalk
microphone works fine on the 9500.

Q Is there any information on writing native SCSI disk drivers for the PCI-based
Power Macintosh computers? In particular, what's the proper way to install a native
driver on a SCSI disk: is there a special partition type for a native driver, or should
there be a standard SCSI disk driver that loads a PowerPC code fragment?

A Apple doesn't support native SCSI drivers yet (this will be a feature of Copland,
the next generation of the Mac OS). You can write a native SCSI Interface Module
(SIM). Remember that a driver is the software that handles a particular SCSI device,
while a SIM is responsible for SCSI controllers (for example, PCI or NuBus(TM)
cards).

Normally, SCSI 4.3 drivers are loaded off the Apple_Driver43 partition, and SIMs are
typically loaded from the disk controller firmware (PCI card). If you want to load a
native SIM off of the disk, you'll have to encapsulate the code fragments and read and
link them in from your standard 680x0 driver.

Q We have SCSI routines that transfer 64K data blocks (to get the highest transfer
rates possible with the tape drive we're using). On the Power Macintosh (8100/80 or
8100/100), if the mouse is moved during a 64K transfer, the cursor is jumpy.
Lowering the cache size to 16K reduces the problem to an acceptable level but kills the
transfer rates. We're using SCSI Manager 4.3. How do we avoid the jumpy cursor
while maintaining maximum throughput?

A Your jumpy cursor is an indication that you aren't properly implementing SCSI
direct memory access (DMA). When using the 8100 (and PCI-based machines) for
DMA transfer efficiency, you should ensure the following:

Also, if you have disconnects enabled in your device or driver, it's possible that the
transfer is getting broken up and some VBL activity is occurring. The bottom line is
that you don't want a SCSI disconnect to occur during your transfer.

Q Is it possible to create and resolve aliases asynchronously?

A No, you can't resolve aliases asynchronously because the Alias Manager uses all
synchronous File Manager and Device Manager requests.

Q Is there a QuickTime codec for converting QuickDraw GX pictures to QuickDraw PICT
format? If so, can you provide this?

A At a session during Apple's 1995 Worldwide Developers Conference, a new
technique for exporting QuickDraw GX pictures as QuickDraw PICT files was
demonstrated. The method makes use of QuickTime and a new codec that's included in
the QuickDraw GX extension version 1.1 and later. With this codec, you can embed a
flattened QuickDraw GX picture into a PICT file (or a QuickTime movie). We
recommend that you use this method if you want to allow your QuickDraw GX
application to exchange pictures with existing QuickDraw applications. You can find
sample code demonstrating the use of this codec in the Macintosh Technical Q&A
"Embedding a GX Picture into a PICT" (GX 07).

One important feature of this codec is that it does not convert QuickDraw GX pictures to
QuickDraw PICTs in the traditional sense of the word "convert." What it allows is the
embedding of QuickDraw GX objects inside a PICT file. The advantage of this is that it
allows QuickDraw GX pictures to be viewed (but not edited) in any application that can
open a PICT file. Although "embedding" is very useful, it's quite different from
"conversion."

Strictly speaking, it's not possible to convert QuickDraw GX pictures to QuickDraw
PICTs without loss of information, because QuickDraw GX has much greater
functionality than traditional QuickDraw. You can, of course, draw the QuickDraw GX
picture offscreen and capture the result in a QuickDraw PICT, but you'll lose much of
the information. There's no way to represent complex transfer modes, perspective,
advanced typography, and so on under the QuickDraw imaging model. By using the new
codec, you don't lose any of the QuickDraw GX features.

Note that this technique is quite different from that used in the older
PicturesAndPICTLibrary.c, which embeds a QuickDraw GX shape into a PICT by using
picture comments. We recommend that you use the codec instead because picture
comments have several weaknesses, including these:

Using the codec to embed the QuickDraw GX picture avoids these problems.

Q How can I find out which printer is selected in the Chooser?

A Under the old printing architecture, you can locate the driver for the currently
selected printer by accessing the 'STR ' -8192 or 'alis' -8192 resource in the System
file. The 'STR ' -8192 resource contains the name of the current driver and the 'alis'
resource contains an alias record that will take you right to the driver. Note that with
older system software the 'alis' resource doesn't appear in the System file. If the 'alis'
resource is present, resolve it; if not, look in the Extensions folder and in the System
Folder for a file with the same name as 'STR ' -8192.

With QuickDraw GX installed, the 'STR ' -8192 resource still exists for backward
compatibility with applications that don't use QuickDraw GX printing. In this case the
'STR ' -8192 resource gives the name of the default desktop printer file. For
applications that are QuickDraw GX savvy, the concept of a default printer isn't
important because the user can pick any printer from the QuickDraw GX Print dialog.

Once you've located the 'STR ' -8192 resource and you have the name of the current
printer, you can then determine the printer's zone and type using the 'PAPA' -8192
resource in the driver (if the traditional printing architecture is in use) or by
accessing the printer's 'comm' resource (if the QuickDraw GX printing architecture is
in use). Sample code demonstrating this can be found in the Macintosh Technical Q&A
"Locating the Selected Printer" (GXPD 36).

Q When I call FDecompressImage during printing, it appears that the custom StdPix
bottleneck of the LaserWriter 8.3 driver isn't called. Why not?

A FDecompressImage doesn't call through the StdPix bottleneck. The workaround is
to directly call the StdPix bottleneck in the current graphics port (or the StdPix
obtained from calling SetStdCProcs if there are no custom bottlenecks in the current
graphics port). For more information, see "Printing Images Faster With Data
Compression" in develop Issue 24.

Q When I attempt to open the built-in Ethernet driver with the OpenDriver call on a
PCI-based Macintosh, the call fails. What's the correct way to access the built-in
driver on these new Macintosh computers?

A The new PCI-based Power Macintosh computers use Open Transport for network
services. This architecture is a precursor to the changes expected for Copland. Since
Open Transport is PowerPC-native, there's no longer a dependence on the
680x0-based Device Manager and Slot Manager. To maintain compatibility for the
built-in Ethernet driver, an ENET shim was implemented so that applications that
called the Ethernet driver directly could continue to work. (Note that the ENET shim is
missing from the original Power Macintosh 9500 release, but became available with
later software updates.)

The ENET shim opens when OpenSlot is called to open the Ethernet driver in NuBus slot
0. The shim intercepts this request and loads a .ENET driver entry into the driver
table. Subsequently, applications that call OpenDriver will get the driver reference
number for the shim driver, which then handles the various Control calls it receives.
The shim works only for the built-in Ethernet device, not for an installed PCI
Ethernet card.

For some code demonstrating how to do this, see the Macintosh Technical Q&A "Ethernet
Error on a PowerMac" (NW 14).

Q How can I check whether the Open Transport IP protocol stack is loaded?

A Open Transport provides the option to delay the complete loading of the protocol
stack. This reduces the use of system memory for the IP protocol stack until a TCP/IP
application is launched. To check whether the stack is loaded, call
OTInetGetInterfaceInfo. If it returns an IP address, the stack is loaded. If the returned
address is 0 or the call fails, the stack is not yet loaded. Note that the call to
OTInetGetInterfaceInfo doesn't force the load of the IP stack.

Q When we call DirFindRecordGet, we get the message kOCEInvalidCommand (-1501).
Is there another way to get all records from a given catalog?

A The catalog about which you're attempting to get record information doesn't
support the DirFindRecordGet function (few out there actually do). To check whether a
particular catalog supports this function, you need to first call DirGetDirectoryInfo
and check the features flags that are returned. Check the kSupportsFindRecordBit (see
Inside Macintosh: AOCE Application Interfaces, page 8-31) to see if this call is
supported. If it's not supported, you'll have to use DirEnumerateGet instead to get all
the records from a catalog.

You might want to look at the DTS Catalog Peek sample code on the Mac OS Software
Developer's Kit, which uses the DirEnumerateGet call.

Q Sometimes, after I copy an HFS volume one-to-one to a CD-ROM, aliases that look
perfectly fine on the source volume are disconnected on the CD-ROM -- the Alias
Manager claims that it can't find the volume. What should I do to detect and fix a
possible disconnected alias before writing it to CD-ROM?

A Sometimes, when aliases move from hard drives to CD-ROMs, volume information
changes, rendering the alias unresolvable. The Alias Manager requires the following
pieces of information in order to identify a volume:

The Alias Manager expects all three pieces of information to match. If they don't all
match, the Alias Manager attempts to identify the volume by matching two of the three
items, trying for a volume match in this order:

When pressing a CD-ROM, you're moving aliases from a hard drive (nonejectable
volume kind) to an ejectable volume kind. If the volume name or creation date of the
hard drive changes after alias creation, the aliases may not resolve properly. You can
avoid this problem by ensuring that the volume name of the hard disk doesn't change
while you're building a CD-ROM's content. Also, do not back up, reformat, or restore a
hard disk while you're building a CD-ROM's content, so that the creation date doesn't
change.

Sometimes, valid-looking aliases fail to resolve. Because the Finder creates alias files,
the Finder is responsible for resolving them. The Finder doesn't always check and
update aliases as carefully as you might. Additionally, the Finder always uses a
relative search path when resolving aliases.

You might want to test to see whether installing QuickTime makes a difference in the
cases where perfectly valid looking aliases fail to resolve. QuickTime includes patches
that make the Alias Manager work better.

Q What does holding the Shift key down at startup turn off under System 7?

A This information isn't documented; the following list isn't guaranteed complete or
accurate and is certain to change in the future. Under System 7.0 through System 7.5
the following files are explicitly skipped:

MacsBug will not load under System 7.0, but it will load under System 7.5 if both the
Option and Shift keys are held down. In addition, System 7.0 sets the disk cache to 64K,
while System 7.5 sets it to 96K.

Q What does turning everything off in the Extension Manager actually turn off?

A The only files the Extension Manager turns off are those that it shows. Which files
will be turned off isn't documented; the following list isn't guaranteed complete or
accurate and is certain to change in the future.

There are four creator types that the Extension Manager doesn't show: 'mntr', 'DMOV',
'extE', and '8INI'. Items of type 'extE' and '8INI' aren't shown because the Extension
Manager extension has the creator of 'extE' and the Extension Manager control panel
has the creator of '8INI'. This prevents you from using the Extension Manager to
disable itself.

Also, the Extension Manager won't show any items of type 'INIT', 'RDEV', or 'cdev' if
they have the "no INITs" Finder flag set.

The Extension Manager shows only items of type 'INIT', 'RDEV', 'cdev', 'PRES', 'PRER',
'adev', 'fext', 'scri', 'cbnd', 'fbdn', 'tbnd', 'ddev', 'appe', 'gc24', 'adrp', 'dbgr', 'dfil',
'APPL', 'FFIL', 'pext', and 'vbnd'.

Q Do I always need to call PrJobDialog to print a document? Why?

A Yes, you do. The reason for this is that many drivers (notably LaserWriter 8)
don't initialize the job-specific settings until PrJobInit is called. Without this call,
they fall back on the default, which is usually stored in the driver in the PREC 0
resource.

The normal definition of the PREC (which maps to a TPrint structure) doesn't have as
much space as LaserWriter 8 needs. Because of this, LaserWriter 8 stores some
settings in this PREC 0 resource and others in the LaserWriter 8 Prefs file. This
separation of LaserWriter settings can wreak havoc on a job run without the
PrJobDialog call.

If you absolutely must avoid displaying the job dialog box, there are two ways to work
around it. Note that these are not supported methods, and by using either of them you'll
make your application hostile to QuickDraw GX and to Copland.

Q I'm writing a printer driver, and I've noticed that when I print a window from the
Finder with my driver the icons don't show up. What gives?

A What you've uncovered is an "optimization" in the Icon Utilities. When drawing an
icon, the Icon Utilities use CopyMask rather than go through the standard bottlenecks.
This is true unless you're saving to a PICT or you set a certain low-memory global
(which isn't well documented) indicating that CopyBits should be used.

The following two macros tell the Icon Utilities to use CopyBits instead of CopyMask:

#define setPrinting() {*((short *)0x948) = 0;}

 

#define clearPrinting() {*((short *)0x948) = -1;}

 

Call setPrinting in your PrOpenPage function and clearPrinting in your PrClosePage
function, and all should be well.

Q Which LaserWriter drivers are ColorSync aware?

A Currently, LaserWriter driver 8.3 is the only ColorSync-aware LaserWriter
driver; versions earlier than 8.3 are not.

Q What does the 7.5.2 Printing Update 1.1 update? Why do I need it?

A This extension fixes a printing problem that may occur on Power Macintosh 7200,
7500, 8500, and 9500 computers using System 7.5.2. Without this fix, your
computer may freeze if you attempt to print on a network-based printer that's busy.

The update contains a new version of the LaserWriter driver (8.3.2) and also a fix to
serial DMA. The changes fix the ATP and PAP networking protocol layers.

An updated version of the PAP.WrkStation.o library will be distributed on a future
version of the Mac OS Software Developer's Kit; developers who have licensed the
library will be notified when the new library is available.

Q Do QuickDraw 3D mesh contours run in the same or the opposite direction as the
face? For example, if the face runs clockwise, will the contour run counterclockwise?

A The exterior face needs to be defined in a counterclockwise direction, but the
contours defining holes can run in either direction. The mesh code is able to identify
holes in a face.

Q I'm using QuickDraw 3D 1.0 on a Power Macintosh 7100. If I try to launch my
application when QuickDraw 3D is disabled with the Extension Manager, I get a
message that the application couldn't be opened because QuickDraw 3D could not be
found. Since the application has to run even if the user doesn't have QuickDraw 3D,
what should I do ?

A You're "hard linking" to the QuickDraw 3D shared library. You need to "weak link"
to the library instead. With Metrowerks CodeWarrior this is trivial: simply select the
project window, click the small triangle to the right of the library in the window, and
choose the Import Weak option from the pop-up menu. In your code, use the Gestalt
selector for QuickDraw 3D to determine whether the library exists. If it does, you
should additionally check at least one symbol in the library against
kUnresolvedCFragSymbolAddress to be sure the library was linked successfully, as
described in Inside Macintosh: PowerPC System Software on page 1-25. It's possible
for Gestalt to indicate that the library is available even though the weak link failed --
for example, if there isn't enough memory available.

Q I've been trying to use QuickTime to step through a movie of PICTs activated by
keyboard input (that is, press a key and the next frame is displayed). My problem is
that I can't consistently step one frame at a time. What's the easiest way to move to the
next frame?

A The easiest way is to use a movie controller to accomplish this. You can send
mcActionStep to the controller to bump the movie to a new frame. A little more work,
but perhaps more suitable for you if you don't want to use a controller, is to use
GetMovieNextInterestingTime to find the next frame.

Q Is there any way to ask QuickTime, at the operating system level, whether any
movies are currently playing?

A No, there's no supported way to do this.

Q We're writing a screen saver that plays QuickTime movies. Our WaitNextEvent loop
is very basic. We've noticed that other background applications don't get any time,
even if we use WaitNextEvent and make sure that MoviesTask doesn't spend too much
time playing the movie. However, if we add code to track update events with
BeginUpdate and EndUpdate the problem goes away. Why?

A QuickTime and other parts of the operating system are sending update events to
your application. If these events aren't handled, they're resent, resulting in no time
yield to other applications. By calling BeginUpdate and EndUpdate or otherwise taking
care of the update event inside your event loop, you allow yielding to other
applications. See Macintosh Technical Note "Pending Update Perils" (TB 37) for more
information.

Q Is the data rate stored somewhere in a QuickTime movie? If not, how can I compute
it?

A The data rate isn't stored in the movie, because a QuickTime movie isn't required
to have a constant data rate: it can change over the duration of the movie. Typically, in
the case of video, one sample equals one frame; in the case of sound and other media,
this one-to-one relationship doesn't necessarily hold. Additionally, none of the video
samples in a continuous stream are exactly the same size, even if in practical terms
this is often assumed.

There are several possible methods of measuring the rate of samples, but the quickest
and easiest is to do what Movie Player does: for each track, get the media size and
divide by the media duration. This provides a rough estimate of the data rate that
should be suitable for most purposes and works for all types of movies, video and
otherwise.

Q It's critical in my CD project to be able to load small QuickTime loop movies entirely
into RAM. This is still not supported in QuickTime for Windows 2.0.3. Will this
functionality be available soon, or should I focus on developing a workaround?

A Support for loading a movie into and playing it from RAM will not be in QuickTime
for Windows 2.1. It is, however, still on Apple's to-do list. For now, you can improve
performance by copying your small movie to a temporary file on the hard drive. From
there you can force it into the disk cache or DOS buffers by opening and reading all of
it yourself.

Q How can I place blue-screen video over a QuickTime VR panorama?

A For starters, you need to know the exact view over which you want to place the
video. Note that if you're only warping in one dimension, it may be a bit tricky.

To get a very close match, take the following steps:

This should mostly take machine time, not your time. Steps 1 and 3 can be scripted in
MPW. Step 2 can be scripted in AppleScript using PhotoFlash or in DeBabelizer, and
step 4 in HyperCard or Director. Step 5 uses ConvertToMovie. Once you develop these
scripting tools the first time, each sequence should be pretty quick to fire up.

Q My cat exhibits a behavior I hope you can explain. Every now and again, he'll sniff
something with particular attention and intensity -- the bend of my wrist, say, or a
spot on the rug. So far so good. But then when he lifts his head, he holds his mouth
open, his lower jaw hanging stupidly. It looks ridiculous! And he seems totally
unaware of it, invariably sitting there for several seconds, mouth gaping, looking
around blithely as if there's nothing out of the ordinary, before finally licking his
chops and closing his mouth. What's going on? Is there any way I can curb this
behavior? It's embarrassing.

A First off, don't worry. Your cat is perfectly normal. All cats do this, and there's
nothing wrong with it (except of course that it looks silly). Your cat is simply making
use of a little-known sensory organ called the vomeronasal organ, or Jacobson's organ.
It's a second scent organ, located far forward on the roof of the mouth, and is
supplemental to -- but distinct from -- the nose. It's even wired into slightly
different areas of the brain, areas dealing with feeding and complex sexual behaviors.
Many other animal species have a Jacobson's organ, from rattlesnakes to bighorn
sheep, but humans don't.

The behavior you've noted is called the flehmen reaction (flehmen is a German word
with no satisfactory English translation). By holding his mouth open and not
breathing, your cat is concentrating the molecules to be sensed over his Jacobson's
organ, allowing it to do its job. The behavior is exhibited by all cats, domestic and
wild, large and small.

______________________________

These answers are supplied by the technical gurus in Apple's Developer Support
Center. For more answers, see the Macintosh Technical Q&As on this issue's CD or on
the World Wide Web at http://dev.info.apple.com/techqa/Main.html. (Older Q&As can
be found in the Macintosh Q&A Technical Notes on the CD.)*