home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-07-14 | 3.7 KB | 141 lines | [TEXT/CWIE] |
- //• ------------------------------------------------------------------------------------------ •
- //•
- //• Copyright © 1996 Apple Computer, Inc., All Rights Reserved
- //•
- //•
- //• You may incorporate this sample code into your applications without
- //• restriction, though the sample code has been provided "AS IS" and the
- //• responsibility for its operation is 100% yours. However, what you are
- //• not permitted to do is to redistribute the source as "DSC Sample Code"
- //• after having made changes. If you're going to re-distribute the source,
- //• we require that you make it clear in the source that the code was
- //• descended from Apple Sample Code, but that you've made changes.
- //•
- //• Authors:
- //• Chris De Salvo
- //•
- //• ------------------------------------------------------------------------------------------ •
-
- //• ------------------------------ Includes
-
- #include <Devices.h>
-
- #include <string.h>
-
- #include "ErrorHandler.h"
- #include "RedbookHandler.h"
-
- //• ------------------------------ Private Definitions
- //• ------------------------------ Private Types
- //• ------------------------------ Private Variables
-
- static SInt16 gDriverRef = -1;
-
- //• ------------------------------ Private Functions
-
- static Boolean RedbookIsCDInserted(void);
-
- //• ------------------------------ Public Variables
-
- Boolean gCDAudio = true;
-
- //• -------------------- RedbookHandlerInit
-
- void
- RedbookHandlerInit(void)
- {
- OSErr theErr;
-
- //• Attempt to open the CD-ROM driver so we can call it later
- theErr = OpenDriver("\p.AppleCD", &gDriverRef);
-
- if (theErr)
- gDriverRef = -1;
- }
-
- //• -------------------- RedbookIsCDInserted
-
- static Boolean
- RedbookIsCDInserted(void)
- {
- ParamBlockRec params;
- OSErr theErr;
-
- if (gDriverRef == -1)
- return (false);
-
- memset(¶ms, 0, sizeof (ParamBlockRec));
-
- //• On return from a drive status call the csParam fields have the same info
- //• as the regular disk driver DrvSts structure. The fourth byte in that
- //• structure is true or false depending on whether or not a disk is in the drive.
-
- params.cntrlParam.ioCompletion = nil;
- params.cntrlParam.ioVRefNum = 1;
- params.cntrlParam.ioCRefNum = gDriverRef;
- params.cntrlParam.csCode = 8; //• Drive Status
-
- theErr = PBStatusSync((ParmBlkPtr) ¶ms);
- if (theErr)
- return (false);
-
- return (params.cntrlParam.csParam[1] & 0xFF);
- }
-
- //• -------------------- RedbookGetNumTracks
-
- short
- RedbookGetNumTracks(void)
- {
- ParamBlockRec params;
- OSErr theErr;
- UInt8 lastTrack;
-
- if (gDriverRef == -1)
- return (0);
-
- memset(¶ms, 0, sizeof (ParamBlockRec));
-
- params.cntrlParam.ioVRefNum = 1;
- params.cntrlParam.ioCRefNum = gDriverRef;
- params.cntrlParam.csCode = 100; //• Read TOC
- params.cntrlParam.csParam[0] = 1; //• Type 1 TOC lookup marker
-
- theErr = PBControlSync(¶ms);
- if (theErr)
- return (0);
-
- lastTrack = params.cntrlParam.csParam[0] & 0xFF;
-
- //• Return the number of tracks in decimal instead of BCD form.
- return ((((lastTrack >> 4) & 0x0F) * 10) + (lastTrack & 0x0F));
- }
-
- //• -------------------- RedbookPlayTrackNum
-
- void
- RedbookPlayTrackNum(UInt16 trackNum)
- {
- ParamBlockRec params;
-
- if (gDriverRef == -1)
- return;
-
- if (false == gCDAudio)
- return;
-
- memset(¶ms, 0, sizeof (ParamBlockRec));
-
- params.cntrlParam.ioCRefNum = gDriverRef;
- params.cntrlParam.csCode = 104; //• Audio Play
- params.cntrlParam.csParam[0] = 0x0002; //• Use a BCD Track Number
-
- //• Params 1 and 2 are the 32-bit value (in BCD) of the track to play.
- //• Seems odd to me that they used 2 bytes for this since the highest legal
- //• track number you can have is 99 and only needs 1 byte.
- params.cntrlParam.csParam[2] = ((trackNum / 10) << 4) + (trackNum % 10);
- params.cntrlParam.csParam[4] = 0x0009; //• Play in normal stereo mode
-
- PBControlSync(¶ms);
- }
-