Пример #1
0
void
mactcp_close(void *handle)
{
    TCPiopb         pb;

    pb.ioCRefNum = refnum;
    pb.csCode = TCPClose;
    pb.tcpStream = ((IMCOMM *) handle)->s;
    pb.csParam.close.validityFlags = 0;
    pb.csParam.close.userDataPtr = (Ptr) handle;
    PBControlSync((ParmBlkPtr) & pb);

    pb.ioCRefNum = refnum;
    pb.csCode = TCPAbort;
    pb.tcpStream = ((IMCOMM *) handle)->s;
    pb.csParam.abort.userDataPtr = (Ptr) handle;
    PBControlSync((ParmBlkPtr) & pb);

    pb.ioCRefNum = refnum;
    pb.csCode = TCPRelease;
    pb.tcpStream = ((IMCOMM *) handle)->s;
    pb.csParam.create.userDataPtr = (Ptr) handle;
    err = PBControlSync((ParmBlkPtr) & pb);
    if (err == noErr)
        free(pb.csParam.create.rcvBuff);
}
Пример #2
0
void
mactcp_close(mactcp_conn *c)
{
	TCPiopb         pb;
	OSErr	err;

	pb.ioCRefNum = c->i->refnum;
	pb.csCode = TCPClose;
	pb.tcpStream = c->s;
	pb.csParam.close.validityFlags = 0;
	pb.csParam.close.userDataPtr = (Ptr) c;
	PBControlSync((ParmBlkPtr) & pb);

	pb.ioCRefNum = c->i->refnum;
	pb.csCode = TCPAbort;
	pb.tcpStream = c->s;
	pb.csParam.abort.userDataPtr = (Ptr) c;
	PBControlSync((ParmBlkPtr) & pb);

	pb.ioCRefNum = c->i->refnum;
	pb.csCode = TCPRelease;
	pb.tcpStream = c->s;
	pb.csParam.create.userDataPtr = (Ptr) c;
	err = PBControlSync((ParmBlkPtr) & pb);
	
	if (err == noErr)
		free(pb.csParam.create.rcvBuff);
}
Пример #3
0
int mactcp_recv(void *vc, unsigned char *inbuf, size_t len)
{
	TCPiopb pb;
	OSErr err;
	mactcp_conn *c = vc;
	
	pb.ioCRefNum = c->i->refnum;
	pb.csCode = TCPRcv;
	pb.tcpStream = c->s;
	pb.csParam.receive.commandTimeoutValue = 2;
	pb.csParam.receive.rcvBuff = (char *)inbuf;
	pb.csParam.receive.rcvBuffLen = len;
	
	err = PBControlSync((ParmBlkPtr) &pb);
	
	if(err == noErr) {
		return pb.csParam.receive.rcvBuffLen;
	} else {
		if(err == connectionClosing)
			return 0;
		
		printf("mactcp_recv(): %d\n", err);
		return(POLARSSL_ERR_NET_RECV_FAILED);
	}
}
Пример #4
0
int mactcp_send(void *vc, const unsigned char *buf, size_t len)
{
	OSErr err;
	TCPiopb pb;
	wdsEntry wds[2];
	mactcp_conn *c = vc;
	
	wds[0].length = len;
	wds[0].ptr = (char *)buf;
	wds[1].length = 0;
	
	pb.ioCRefNum = c->i->refnum;
	pb.csCode = TCPSend;
	pb.tcpStream = c->s;
	pb.csParam.send.validityFlags = 0;
	pb.csParam.send.pushFlag = TRUE;
	pb.csParam.send.urgentFlag = 0;
	pb.csParam.send.wdsPtr = (Ptr)wds;
	
	err = PBControlSync((ParmBlkPtr) &pb);
	
	if(err == noErr) {
		return len;
	} else {
		printf("mactcp_send(): %d\n", err);
		return(POLARSSL_ERR_NET_SEND_FAILED);
	}
	
	return err;
}
Пример #5
0
boolean filegetdiskicon (short vnum, Handle *hdiskicon) {

	HParamBlockRec pb;
	ParamBlockRec cpb;
	OSErr ec;

	clearbytes (&pb, longsizeof (pb));
    
	pb.volumeParam.ioVRefNum = vnum;
    
	ec = PBHGetVInfoSync (&pb);
    
	if (fileerror (nil, ec))
		return (false);
    	
	cpb.cntrlParam.ioCRefNum = pb.volumeParam.ioVDRefNum;
    
	cpb.cntrlParam.ioVRefNum = pb.volumeParam.ioVDrvInfo;

	cpb.cntrlParam.csCode = 22;
    
	ec = PBControlSync (&cpb);

	if (ec != noErr) {
    
		cpb.cntrlParam.csCode = 21;
        
		ec = PBControlSync (&cpb);
		}
    	
	if (fileerror (nil, ec))
    	return (false);

	ec = PtrToHand (*(Ptr*) &cpb.cntrlParam.csParam, hdiskicon, kLargeIconSize);
	
	return (!fileerror (nil, ec));
	} /*filegetdiskicon*/
Пример #6
0
/* Resume play */
static int SDL_SYS_CDResume(SDL_CD *cdrom)
{
	CDCntrlParam cdpb;

	SDL_memset(&cdpb, 0, sizeof(cdpb));
	cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
	cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
	cdpb.csCode = kAudioPause;
	cdpb.csParam.words[0] = 0;	/* Pause/Continue Flag (hiword) */
	cdpb.csParam.words[1] = 0;	/* Pause/Continue Flag (loword) */
	if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) {
		SDL_SetError("PBControlSync() failed");
		return(-1);
	}
	return(0);
}
Пример #7
0
/* Stop play */
static int SDL_SYS_CDStop(SDL_CD *cdrom)
{
	CDCntrlParam cdpb;

	SDL_memset(&cdpb, 0, sizeof(cdpb));
	cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
	cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
	cdpb.csCode = kAudioStop;
	cdpb.csParam.words[0] = 0;		/* Position Mode */
	cdpb.csParam.words[1] = 0;		/* Search Address (hiword) */
	cdpb.csParam.words[2] = 0;		/* Search Address (loword) */
	if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) {
		SDL_SetError("PBControlSync() failed");
		return(-1);
	}
	return(0);
}
Пример #8
0
/* Eject the CD-ROM */
static int SDL_SYS_CDEject(SDL_CD *cdrom)
{
	Boolean	disk = false;
	QHdr *driveQ = GetDrvQHdr();
	DrvQEl *driveElem;
	HParamBlockRec hpb;
	ParamBlockRec cpb;

	for ( driveElem = (DrvQEl *) driveQ->qHead; driveElem; driveElem = 
			  (driveElem) ? ((DrvQEl *) driveElem->qLink) : 
			  ((DrvQEl *) driveQ->qHead) ) {
		if ( driveQ->qTail ) {
			driveQ->qTail->qLink = 0;
		}
		if ( driveElem->dQRefNum != SDL_cdlist[cdrom->id].dRefNum ) {
			continue;
		}
	
		/* Does drive contain mounted volume? If not, skip */
		SDL_memset(&hpb, 0, sizeof(hpb));
		hpb.volumeParam.ioVRefNum = driveElem->dQDrive;
		if ( PBHGetVInfoSync(&hpb) != noErr ) {
			continue;
		}
		if ( (UnmountVol(0, driveElem->dQDrive) == noErr) && 
		     (Eject(0, driveElem->dQDrive) == noErr) ) {
			driveElem = 0; /* Clear pointer to reset our loop */
			disk = true;
		}
	}

	/* If no disk is present, just eject the tray */
	if (! disk) {
		SDL_memset(&cpb, 0, sizeof(cpb));
		cpb.cntrlParam.ioVRefNum = 0; /* No Drive */
		cpb.cntrlParam.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
		cpb.cntrlParam.csCode = kEjectTheDisc;
		if ( PBControlSync((ParmBlkPtr)&cpb) != noErr ) {
			SDL_SetError("PBControlSync() failed");
			return(-1);
		}
	}
	return(0);
}
Пример #9
0
/* Start play */
static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length)
{
	CDCntrlParam cdpb;

	/* Pause the current audio playback to avoid audible artifacts */
	if ( SDL_SYS_CDPause(cdrom) < 0 ) {
		return(-1);
	}

	/* Specify the AudioCD playback mode */
	SDL_memset(&cdpb, 0, sizeof(cdpb));
	cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
	cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
	cdpb.csCode = kSetPlayMode;
	cdpb.csParam.bytes[0] = false;			/* Repeat? */
	cdpb.csParam.bytes[1] = kPlayModeSequential;	/* Play mode */
	/* еее╩Treat as soft error, NEC Drive doesnt support this call еее */
	PBControlSync((ParmBlkPtr) &cdpb);

#if 1
	/* Specify the end of audio playback */
	SDL_memset(&cdpb, 0, sizeof(cdpb));
	cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
	cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
	cdpb.csCode = kAudioStop;
	cdpb.csParam.words[0] = kBlockPosition;		/* Position Mode */
	*(long *) (cdpb.csParam.words + 1) = start+length-1; /* Search Address */
	if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) {
		SDL_SetError("PBControlSync() failed");
		return(-1);
	}

	/* Specify the start of audio playback, and start it */
	SDL_memset(&cdpb, 0, sizeof(cdpb));
	cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
	cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
	cdpb.csCode = kAudioPlay;
	cdpb.csParam.words[0] = kBlockPosition;			/* Position Mode */
	*(long *) (cdpb.csParam.words + 1) = start+1;	/* Search Address */
	cdpb.csParam.words[3] = false;					/* Stop address? */
	cdpb.csParam.words[4] = kStereoPlayMode;		/* Audio Play Mode */
	if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) {
		SDL_SetError("PBControlSync() failed");
		return(-1);
	}
#else
	/* Specify the end of audio playback */
	FRAMES_TO_MSF(start+length, &m, &s, &f);
	SDL_memset(&cdpb, 0, sizeof(cdpb));
	cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
	cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
	cdpb.csCode = kAudioStop;
	cdpb.csParam.words[0] = kTrackPosition;			/* Position Mode */
	cdpb.csParam.words[1] = 0;						/* Search Address (hiword)*/
	cdpb.csParam.words[2] = 						/* Search Address (loword)*/
			SDL_SYS_ShortToBCD(cdrom->numtracks);	
	if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) {
		SDL_SetError("PBControlSync() failed");
		return(-1);
	}

	/* Specify the start of audio playback, and start it */
	FRAMES_TO_MSF(start, &m, &s, &f);
	SDL_memset(&cdpb, 0, sizeof(cdpb));
	cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
	cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
	cdpb.csCode = kAudioPlay;
	cdpb.csParam.words[0] = kTrackPosition;			/* Position Mode */
	cdpb.csParam.words[1] = 0;						/* Search Address (hiword)*/
	cdpb.csParam.words[2] = SDL_SYS_ShortToBCD(1);	/* Search Address (loword)*/
	cdpb.csParam.words[3] = false;					/* Stop address? */
	cdpb.csParam.words[4] = kStereoPlayMode;		/* Audio Play Mode */
	if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) {
		SDL_SetError("PBControlSync() failed");
		return(-1);
	}
#endif

	return(0);
}
Пример #10
0
/* Get CD-ROM status */
static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position)
{
	CDCntrlParam cdpb;
	CDstatus status = CD_ERROR;
	Boolean spinning = false;

	if (position) *position = 0;

	/* Get the number of tracks on the CD by examining the TOC */
	if ( ! get_drivenum(cdrom->id) ) {
		return(CD_TRAYEMPTY);
	}
	SDL_memset(&cdpb, 0, sizeof(cdpb));
	cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
	cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
	cdpb.csCode = kReadTOC;
	cdpb.csParam.words[0] = kGetTrackRange;
	if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) {
		SDL_SetError("PBControlSync() failed");
		return(CD_ERROR);
	}

	cdrom->numtracks = 
			SDL_SYS_BCDToShort(cdpb.csParam.bytes[1]) - 
			SDL_SYS_BCDToShort(cdpb.csParam.bytes[0]) + 1;
	if ( cdrom->numtracks > SDL_MAX_TRACKS )
		cdrom->numtracks = SDL_MAX_TRACKS;
	cdrom->cur_track = 0; /* Apparently these are set elsewhere */
	cdrom->cur_frame = 0; /* Apparently these are set elsewhere */


	if (1 || SDL_cdlist[cdrom->id].hasAudio) {
		/* Get the current playback status */
		SDL_memset(&cdpb, 0, sizeof(cdpb));
		cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
		cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
		cdpb.csCode = kAudioStatus;
		if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) {
			SDL_SetError("PBControlSync() failed");
			return(-1);
		}
	
		switch(cdpb.csParam.cd.status) {
			case kStatusPlaying:
				status = CD_PLAYING;
				spinning = true;
				break;
			case kStatusPaused:
				status = CD_PAUSED;
				spinning = true;
				break;
			case kStatusMuted:
				status = CD_PLAYING; /* What should I do here? */
				spinning = true;
				break;
			case kStatusDone:
				status = CD_STOPPED;
				spinning = true;
				break;
			case kStatusStopped:
				status = CD_STOPPED;
				spinning = false;
				break;
			case kStatusError:
			default:
				status = CD_ERROR;
				spinning = false;
				break;
			}

		if (spinning && position) *position = MSF_TO_FRAMES(
				SDL_SYS_BCDToShort(cdpb.csParam.cd.minute),
				SDL_SYS_BCDToShort(cdpb.csParam.cd.second),
				SDL_SYS_BCDToShort(cdpb.csParam.cd.frame));
		}
	else
		status = CD_ERROR; /* What should I do here? */

	return(status);
}
Пример #11
0
static int SDL_SYS_CDGetTOC(SDL_CD *cdrom)
{
	CDCntrlParam		cdpb;
	CDTrackData			tracks[SDL_MAX_TRACKS];
	long				i, leadout;

	/* Get the number of tracks on the CD by examining the TOC */
	SDL_memset(&cdpb, 0, sizeof(cdpb));
	cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
	cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
	cdpb.csCode = kReadTOC;
	cdpb.csParam.words[0] = kGetTrackRange;
	if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) {
		SDL_SetError("PBControlSync() failed");
		return(-1);
	}

	cdrom->numtracks = 
			SDL_SYS_BCDToShort(cdpb.csParam.bytes[1]) - 
			SDL_SYS_BCDToShort(cdpb.csParam.bytes[0]) + 1;
	if ( cdrom->numtracks > SDL_MAX_TRACKS )
		cdrom->numtracks = SDL_MAX_TRACKS;
	cdrom->status = CD_STOPPED;
	cdrom->cur_track = 0; /* Apparently these are set elsewhere */
	cdrom->cur_frame = 0; /* Apparently these are set elsewhere */


	/* Get the lead out area of the CD by examining the TOC */
	SDL_memset(&cdpb, 0, sizeof(cdpb));
	cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
	cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
	cdpb.csCode = kReadTOC;
	cdpb.csParam.words[0] = kGetLeadOutArea;
	if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) {
		SDL_SetError("PBControlSync() failed");
		return(-1);
	}

	leadout = MSF_TO_FRAMES(
			SDL_SYS_BCDToShort(cdpb.csParam.bytes[0]),
			SDL_SYS_BCDToShort(cdpb.csParam.bytes[1]),
			SDL_SYS_BCDToShort(cdpb.csParam.bytes[2]));

	/* Get an array of track locations by examining the TOC */
	SDL_memset(tracks, 0, sizeof(tracks));
	SDL_memset(&cdpb, 0, sizeof(cdpb));
	cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
	cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
	cdpb.csCode = kReadTOC;
	cdpb.csParam.words[0] = kGetTrackEntries;	/* Type of Query */
	* ((long *) (cdpb.csParam.words+1)) = (long) tracks;				
	cdpb.csParam.words[3] = cdrom->numtracks * sizeof(tracks[0]);		
	* ((char *) (cdpb.csParam.words+4)) = 1;	/* First track */
	if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) {
		SDL_SetError("PBControlSync() failed");
		return(-1);
	}

	/* Read all the track TOC entries */
	SDL_cdlist[cdrom->id].hasAudio = false;
	for ( i=0; i<cdrom->numtracks; ++i ) 
		{
		cdrom->track[i].id = i+1;
		if (tracks[i].entry.control & kDataTrackMask)
			cdrom->track[i].type = SDL_DATA_TRACK;
		else
			{
			cdrom->track[i].type = SDL_AUDIO_TRACK;
			SDL_cdlist[SDL_numcds].hasAudio = true;
			}
		
		cdrom->track[i].offset = MSF_TO_FRAMES(
				SDL_SYS_BCDToShort(tracks[i].entry.min),
				SDL_SYS_BCDToShort(tracks[i].entry.min),
				SDL_SYS_BCDToShort(tracks[i].entry.frame));
		cdrom->track[i].length = MSF_TO_FRAMES(
				SDL_SYS_BCDToShort(tracks[i+1].entry.min),
				SDL_SYS_BCDToShort(tracks[i+1].entry.min),
				SDL_SYS_BCDToShort(tracks[i+1].entry.frame)) -
				cdrom->track[i].offset;
		}
	
	/* Apparently SDL wants a fake last entry */
	cdrom->track[i].offset = leadout;
	cdrom->track[i].length = 0;

	return(0);
}
Пример #12
0
OSErr mactcp_connect(mactcp_inst *i, mactcp_conn *c, char *hostname, short port)
{
	volatile int resolverDone = FALSE;
	struct hostInfo hi;
	size_t buflen;
	UDPiopb upb;
	TCPiopb pb;
	OSErr err;
	
	if(!i->initialized) {
		printf("mactcp_connect(): not initialized\n");
		return -1;
	}
	
	c->i = i;
	err = StrToAddr(hostname, &hi, i->mactcp_lookupdone_upp, (char *)&resolverDone);
	if(err == cacheFault) {
		while(!resolverDone)
			continue;
	}

	if(err != noErr && err != cacheFault)
		return err;
		
	/* get the max MTU size for this path */
	/* we use this to calculate the buffer size */
	upb.ioCRefNum = i->refnum;
	upb.csCode = UDPMaxMTUSize;
	upb.csParam.mtu.remoteHost = hi.addr[0];
	err = PBControlSync((ParmBlkPtr) &upb);
	
	if(err != noErr) {
		printf("mactcp_connect(): error getting MTU, err=%d\n", err);
		return err;
	}
	
        /*
         * this is broken on my PM7500 w/ 7.6.1 
         * the MTU returned is always absurdly high
         */
#if 0
	buflen = upb.csParam.mtu.mtuSize * 4 + 1024;
	if(buflen < 4096)
		buflen = 4096;
#else
        buflen = 4096;
#endif
		
	pb.ioCRefNum = i->refnum;
	pb.csCode = TCPCreate;
	pb.csParam.create.rcvBuff = malloc(buflen);
	pb.csParam.create.rcvBuffLen = buflen;
	pb.csParam.create.notifyProc = i->mactcp_asr_upp;
	pb.csParam.create.userDataPtr = (Ptr)c;
	
	err = PBControlSync((ParmBlkPtr) &pb);
	if(err != noErr) {
		printf("mactcp_connect(): error creating TCP stream, err=%d", err);
		return err;
	}
	
	c->s = pb.tcpStream;
	
	pb.ioCRefNum = i->refnum;
	pb.csCode = TCPActiveOpen;
	pb.tcpStream = c->s;
	pb.csParam.open.validityFlags = 0;
	pb.csParam.open.remoteHost = hi.addr[0];
	pb.csParam.open.remotePort = port;
	pb.csParam.open.localPort = 0;
	pb.csParam.open.timeToLive = 0;
	pb.csParam.open.security = 0;
	pb.csParam.open.optionCnt = 0;
	pb.csParam.open.userDataPtr = (Ptr)c;
	err = PBControlSync((ParmBlkPtr) &pb);
	if(err != noErr) {
		printf("Error connecting TCP stream: %d\n", err);
		return err;
	}
	
	c->readable = 1;
	
	return noErr;
}
Пример #13
0
static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length)
{
	CDCntrlParam cdpb;

	
	if ( SDL_SYS_CDPause(cdrom) < 0 ) {
		return(-1);
	}

	
	SDL_memset(&cdpb, 0, sizeof(cdpb));
	cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
	cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
	cdpb.csCode = kSetPlayMode;
	cdpb.csParam.bytes[0] = false;			
	cdpb.csParam.bytes[1] = kPlayModeSequential;	
	
	PBControlSync((ParmBlkPtr) &cdpb);

#if 1
	
	SDL_memset(&cdpb, 0, sizeof(cdpb));
	cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
	cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
	cdpb.csCode = kAudioStop;
	cdpb.csParam.words[0] = kBlockPosition;		
	*(long *) (cdpb.csParam.words + 1) = start+length-1; 
	if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) {
		SDL_SetError("PBControlSync() failed");
		return(-1);
	}

	
	SDL_memset(&cdpb, 0, sizeof(cdpb));
	cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
	cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
	cdpb.csCode = kAudioPlay;
	cdpb.csParam.words[0] = kBlockPosition;			
	*(long *) (cdpb.csParam.words + 1) = start+1;	
	cdpb.csParam.words[3] = false;					
	cdpb.csParam.words[4] = kStereoPlayMode;		
	if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) {
		SDL_SetError("PBControlSync() failed");
		return(-1);
	}
#else
	
	FRAMES_TO_MSF(start+length, &m, &s, &f);
	SDL_memset(&cdpb, 0, sizeof(cdpb));
	cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
	cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
	cdpb.csCode = kAudioStop;
	cdpb.csParam.words[0] = kTrackPosition;			
	cdpb.csParam.words[1] = 0;						
	cdpb.csParam.words[2] = 						
			SDL_SYS_ShortToBCD(cdrom->numtracks);	
	if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) {
		SDL_SetError("PBControlSync() failed");
		return(-1);
	}

	
	FRAMES_TO_MSF(start, &m, &s, &f);
	SDL_memset(&cdpb, 0, sizeof(cdpb));
	cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
	cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
	cdpb.csCode = kAudioPlay;
	cdpb.csParam.words[0] = kTrackPosition;			
	cdpb.csParam.words[1] = 0;						
	cdpb.csParam.words[2] = SDL_SYS_ShortToBCD(1);	
	cdpb.csParam.words[3] = false;					
	cdpb.csParam.words[4] = kStereoPlayMode;		
	if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) {
		SDL_SetError("PBControlSync() failed");
		return(-1);
	}
#endif

	return(0);
}
Пример #14
0
static int SDL_SYS_CDGetTOC(SDL_CD *cdrom)
{
	CDCntrlParam		cdpb;
	CDTrackData			tracks[SDL_MAX_TRACKS];
	long				i, leadout;

	
	SDL_memset(&cdpb, 0, sizeof(cdpb));
	cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
	cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
	cdpb.csCode = kReadTOC;
	cdpb.csParam.words[0] = kGetTrackRange;
	if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) {
		SDL_SetError("PBControlSync() failed");
		return(-1);
	}

	cdrom->numtracks = 
			SDL_SYS_BCDToShort(cdpb.csParam.bytes[1]) - 
			SDL_SYS_BCDToShort(cdpb.csParam.bytes[0]) + 1;
	if ( cdrom->numtracks > SDL_MAX_TRACKS )
		cdrom->numtracks = SDL_MAX_TRACKS;
	cdrom->status = CD_STOPPED;
	cdrom->cur_track = 0; 
	cdrom->cur_frame = 0; 


	
	SDL_memset(&cdpb, 0, sizeof(cdpb));
	cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
	cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
	cdpb.csCode = kReadTOC;
	cdpb.csParam.words[0] = kGetLeadOutArea;
	if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) {
		SDL_SetError("PBControlSync() failed");
		return(-1);
	}

	leadout = MSF_TO_FRAMES(
			SDL_SYS_BCDToShort(cdpb.csParam.bytes[0]),
			SDL_SYS_BCDToShort(cdpb.csParam.bytes[1]),
			SDL_SYS_BCDToShort(cdpb.csParam.bytes[2]));

	
	SDL_memset(tracks, 0, sizeof(tracks));
	SDL_memset(&cdpb, 0, sizeof(cdpb));
	cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
	cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
	cdpb.csCode = kReadTOC;
	cdpb.csParam.words[0] = kGetTrackEntries;	
	* ((long *) (cdpb.csParam.words+1)) = (long) tracks;				
	cdpb.csParam.words[3] = cdrom->numtracks * sizeof(tracks[0]);		
	* ((char *) (cdpb.csParam.words+4)) = 1;	
	if ( PBControlSync((ParmBlkPtr)&cdpb) != noErr ) {
		SDL_SetError("PBControlSync() failed");
		return(-1);
	}

	
	SDL_cdlist[cdrom->id].hasAudio = false;
	for ( i=0; i<cdrom->numtracks; ++i ) 
		{
		cdrom->track[i].id = i+1;
		if (tracks[i].entry.control & kDataTrackMask)
			cdrom->track[i].type = SDL_DATA_TRACK;
		else
			{
			cdrom->track[i].type = SDL_AUDIO_TRACK;
			SDL_cdlist[SDL_numcds].hasAudio = true;
			}
		
		cdrom->track[i].offset = MSF_TO_FRAMES(
				SDL_SYS_BCDToShort(tracks[i].entry.min),
				SDL_SYS_BCDToShort(tracks[i].entry.min),
				SDL_SYS_BCDToShort(tracks[i].entry.frame));
		cdrom->track[i].length = MSF_TO_FRAMES(
				SDL_SYS_BCDToShort(tracks[i+1].entry.min),
				SDL_SYS_BCDToShort(tracks[i+1].entry.min),
				SDL_SYS_BCDToShort(tracks[i+1].entry.frame)) -
				cdrom->track[i].offset;
		}
	
	
	cdrom->track[i].offset = leadout;
	cdrom->track[i].length = 0;

	return(0);
}