[comp.sys.mac.programmer] Has AppleSoundChip? Gestalt? How?

2fmlcalls@kuhub.cc.ukans.edu (04/09/91)

How does one determine if te AppleSoundChip is present?  I got my hands on the
new Interface files for THINK Pascal (GestaltEqu most notably) and tried to
blindly call Gestalt('hdwr',theResponse).

LINK_ERROR - Gestalt not implemented {or some such}

So, how does one use Gestalt with THINK Pascal 3.0?  Or how can one determine
if the ASC is present without a call to Gestalt?  (And, related, like calling
WNEvent, do you need to check for a TrapAvail before even considering a call to
Gestalt?)

BTW, I have System 6.07 on an si.  (I would think Gestalt would be in 6.07!?)
Also, I'm not an APDA developer, so references to APDA-eyes-only docs are in
vain.

john calhoun

smoke@well.sf.ca.us (Nicholas Jackiw) (04/11/91)

In article <1991Apr9.011011.29542@kuhub.cc.ukans.edu> 2fmlcalls@kuhub.cc.ukans.edu writes:
>
>LINK_ERROR - Gestalt not implemented {or some such}
>
>So, how does one use Gestalt with THINK Pascal 3.0?  Or how can one determine
>if the ASC is present without a call to Gestalt?  (And, related, like calling
>WNEvent, do you need to check for a TrapAvail before even considering a call to
>Gestalt?)

I haven't been able to find the necessary glue for Gestalt on any of
the 7 beta cds, either.  I must not be looking in the right place.

At any rate, try this:
 function Gestalt (selector: OSType; var response: LONGINT): OSErr;
 inline
  $202f, $0004, $A1AD, $225f, $2288, $584f, $3E80;

This glue pops the parameters off the stack and puts them into the
appropriate registers before making the call.  It works under 7; I
have no idea how _Gestalt's implemented under 6.x, but I imagine
this'll work too.

As to your related question, yes you must make sure Gestalt's implemented
beforehand.  The latest Officially Recommended Way to do this:

 const
  Unimplemented = $A89F;

 function GetTrapType (theTrap: integer): TrapType;
  const
   TrapMask = $0800;

 begin
  if Band(theTrap, TrapMask) > 0 then
   GetTrapType := ToolTrap
  else
   GetTrapType := OSTrap
 end;

 function NumToolboxTraps: integer;
 begin
  if NGetTrapAddress($A86E, ToolTrap) = NGetTrapAddress($AA6E, ToolTrap) then {InitGraf=Unimplemented?}
   NumToolboxTraps := $200
  else
   NumToolboxTraps := $400
 end;


 function TrapAvailable (theTrap: integer): boolean;

  var
   tType: TrapType;

 begin
  tType := GetTrapType(theTrap);
  if tType = ToolTrap then
   begin
    theTrap := Band(theTrap, $07FF);
    if theTrap >= NumToolBoxTraps then
     theTrap := Unimplemented
   end;
  TrapAvailable := NGetTrapAddress(theTrap, tType) <> NGetTrapAddress(Unimplemented, ToolTrap)
 end;

begin
 {Your code begins here}
hasGestalt := TrapAvailable($A1AD);				{Determine whether Gestalt is implemented}
    
...
end;

I love this stuff.  With the new edition manager, or any other OS package
that requires initialization, you now have to write code that checks to
see (TrapAvailable) whether you can check to see (Gestalt) whether you
can check to see (InitEditionMgr) whether you can use editions.  Fortunately,
the code to check to see whether your user has forgotten to turn the Mac's
power on is much simpler.

>
>john calhoun


-- 
                              --- * ---
Nicholas Jackiw                Smoke@well.sf.ca.us | Jackiw@cs.swarthmore.edu
Key Curriculum Press, Inc.     Applelink: D3970    | (415) 548-2304
                              --- * ---

wdh@well.sf.ca.us (Bill Hofmann) (04/12/91)

In article <24147@well.sf.ca.us> smoke@well.sf.ca.us (Nicholas Jackiw) writes:
>I haven't been able to find the necessary glue for Gestalt on any of
>the 7 beta cds, either.  I must not be looking in the right place.

On the 7.0b4 CD, look in SuperBeta:Development Tools:Symantec: or :MPW:.
There are updaters for THINK C and Pascal, along with libraries.  Be forewarned
that since THINK C uses the MPW headers (almost), some behavior of you programs
*WILL* change.  In particular, Boolean is now unsigned char, whereas before
it was a signed int.

-Bill Hofmann

c89andma@odalix.ida.liu.se (Andreas Magnusson) (04/13/91)

smoke@well.sf.ca.us (Nicholas Jackiw) writes:

>In article <1991Apr9.011011.29542@kuhub.cc.ukans.edu> 2fmlcalls@kuhub.cc.ukans.edu writes:
>>
>>LINK_ERROR - Gestalt not implemented {or some such}
>>
[ Stuff deleted \

>This glue pops the parameters off the stack and puts them into the
>appropriate registers before making the call.  It works under 7; I
>have no idea how _Gestalt's implemented under 6.x, but I imagine
>this'll work too.

It's implemented in System 6.0.4 and up.

>I love this stuff.  With the new edition manager, or any other OS package
>that requires initialization, you now have to write code that checks to
>see (TrapAvailable) whether you can check to see (Gestalt) whether you
>can check to see (InitEditionMgr) whether you can use editions.  Fortunately,
>the code to check to see whether your user has forgotten to turn the Mac's
>power on is much simpler.

Yes, it's lovely, no doubt about it!

>>
>>john calhoun


>-- 
>                              --- * ---
>Nicholas Jackiw                Smoke@well.sf.ca.us | Jackiw@cs.swarthmore.edu
>Key Curriculum Press, Inc.     Applelink: D3970    | (415) 548-2304
>                              --- * ---

/Andreas
--
 _____________________________________  ____________________________________
| Andreas Magnusson                   ||SnailMail:     Andreas Magnusson    |
| Linkoping Institute of Technology   ||               Rydsv. 260 A:32      |
|      	       	       	              ||               S-58251 Linkoping    |
| c89andma@odalix.ida.liu.se          ||               SWEDEN               |
| zune@nanny.lysator.liu.se           ||                                    |
`-------------------------------------'`------- New SnailMail Address ------'

keith@Apple.COM (Keith Rollin) (04/14/91)

>smoke@well.sf.ca.us (Nicholas Jackiw) writes:
>
>>I love this stuff.  With the new edition manager, or any other OS package
>>that requires initialization, you now have to write code that checks to
>>see (TrapAvailable) whether you can check to see (Gestalt) whether you
>>can check to see (InitEditionMgr) whether you can use editions.  

This is not quite true. Gestalt is implemented as glue in both the
latest MPW and THINK environments. This means that you do NOT have to
call some sort of TrapAvailable routine in order to call Gestalt. As
long as you have the latest development systems, you can just call it.

The Gestalt glue, in turn, makes its own check to see if there is a
version of Gestalt installed in the ROMs or by the System. If so, the
glue forwards to those routines. Otherwise, it does as best as it can
by itself, providing pretty much the same information as the
SysEnvirons call.

If you have a better idea on how Apple can provide new functionality
and maintain flexibility without requiring programs to make these
checks, let us know. (BTW: there is an answer to this challenge... use
MacApp 3.0 when it comes out later on this year. It does all this
checking for you! This announcement paid for by the Happy MacApp
Programmers of the World Committee.)

-- 
------------------------------------------------------------------------------
Keith Rollin  ---  Apple Computer, Inc. 
INTERNET: keith@apple.com
    UUCP: {decwrl, hoptoad, nsc, sun, amdahl}!apple!keith
"But where the senses fail us, reason must step in."  - Galileo

phils@chaos.cs.brandeis.edu (Phil Shapiro) (04/17/91)

In article <1991Apr9.011011.29542@kuhub.cc.ukans.edu>
2fmlcalls@kuhub.cc.ukans.edu writes:

   How does one determine if the AppleSoundChip is present?  I got my
   hands on the new Interface files for THINK Pascal (GestaltEqu most
   notably) and tried to blindly call Gestalt('hdwr',theResponse).

From IM VI:
gestaltSoundAttr - Returns information about the sound capabilities of
the machine. (It's 'snd '.)
 
                           CONST  gestaltStereoCapability     = 0;
                                  gestaltStereoMixing         = 1;
                                  gestaltSoundIOMgrPresent    = 3;
                                  gestaltBuiltInSoundInput    = 4;
                                  gestaltHasSoundInputDevice  = 5;
 
If the bit gestaltStereoCapability is TRUE, the available hardware can
play stereo sounds. The bit gestaltStereoMixing indicates that the
sound hardware of the machine mixes both left and right channels of
stereo sound into a single audio signal for the internal speaker. The
gestaltSoundIOMgrPresent bit indicates that the new sound input
routines are available, and the gestaltBuiltInSoundInput bit indicates
that a built-in sound input device is available. The
gestaltHasSoundInputDevice bit indicates that some sound input device
is available.

   LINK_ERROR - Gestalt not implemented {or some such}

If you're going to use the "new" Interfaces, then you must use the
"new" libraries.  If you use the new Interface.lib file, which is on
the System 7 CD-ROM, then you shouldn't get this link error.  If you
don't have the System 7 disk, I can email (or post) a library that
contains the glue for Gestalt.

   So, how does one use Gestalt with THINK Pascal 3.0?  Or how can one
   determine if the ASC is present without a call to Gestalt?  (And,
   related, like calling WNEvent, do you need to check for a TrapAvail
   before even considering a call to Gestalt?)

Yes, you must check to see if Gestalt is avail before using the
Gestalt Manager.  Gestalt's trap is 0xA1AD.

   BTW, I have System 6.07 on an si.  (I would think Gestalt would be
   in 6.07!?)

Gestalt is in all systems after 6.0.4.

	-phil
--
   Phil Shapiro                           Technical Support Analyst
   Language Products Group                     Symantec Corporation
		Internet: phils@chaos.cs.brandeis.edu