ftp.nice.ch/pub/next/tools/scsi/SCSI2_ToolBox.941207.NI.bs.gnutar.gz#/SCSI2_ToolBox/SCSI2_Kit/Source/CDSCSI.m

This is CDSCSI.m in view mode; [Download] [Up]

//
//	CDSCSI_Class - subclass of SCSI2_Class for CD disk drive devices
//
//	Copyright (C) 1994 by Christopher Wolf.
//
//	This library is free software; you can redistribute it and/or
//	modify it under the terms of the GNU Library General Public
//	License as published by the Free Software Foundation; either
//	version 2 of the License, or (at your option) any later version.
//
//	This library is distributed in the hope that it will be useful,
//	but WITHOUT ANY WARRANTY; without even the implied warranty of
//	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//	Library General Public License for more details.
//
//	You should have received a copy of the GNU Library General Public
//	License along with this library; if not, write to the Free
//	Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
//	Bug-reports, comments and questions should be directed to:
//		Christopher Wolf <chris@alchemy.geo.cornell.edu>
//
//	Portions of this code and documentation are derived from an 
//	earlier work (SCSI Inquirer) Copyright (C) 1990, 1991, 1992 by 
//	Jiro Nakamura and used with permission.
//

//
// 	For best results view this file with a tab size of 4 and
//	a display width of 132 columns or wider.
//

//	file version information
#define RCSCDM "$Id: CDSCSI.m,v 0.20 94/11/12 01:23:31 chris Exp Locker: chris $"

//	generic Unix headers
#import <stdio.h>
#import <libc.h>

// 	NeXTSTEP headers
#import <appkit/appkit.h>

//	SCSI2 class specific headers 
#import "CDSCSI.h"
#import "errio.h"

// string constants
const char RCScdm[] = RCSCDM;
const char RCScdh[] = RCSCDH;

@implementation CDSCSI


//	----------------------------------------------------------------------
//
//	NAME
//		isDevice
//
//	RETURNS
//		(BOOL)			YES if sub-class can handle device, NO otherwise. 
//
//	EXPLANATION
//		It is the sub-classes responsibility to implement this method. 
//		The method should return YES if the subclass of SCSI can handle
//		the device at the current target, NO otherwise.  
//
//	SEE ALSO
//		findDevice (SCSI), findDevice: (SCSI)
//	
//	----------------------------------------------------------------------
	
- (BOOL) isDevice
	{

	struct inquiry_reply ibuffer;
	BOOL result;
	PrintFunction oldPf = dprintf;
	
	dprintf = printfToNull;
	result = ((![self inquiry: &ibuffer]) && (ibuffer.ir_devicetype == DEVTYPE_CDROM));
	dprintf = oldPf;
		
	return result;
	
	}

- (int) eject
	{

	struct cdb6_start_stop *cdbp = &sr.sr_cdb.cdb6_start_stop;
	BOOL wasOpen = isOpen;
	int result = -1;
	
	if (wasOpen || ![self openSCSI])
		{
			
		[SCSI clearCommandBlock: (cdb *)cdbp];
		
		cdbp->ss_opcode = C6OP_STARTSTOP;
		cdbp->ss_lun    = lun;
		cdbp->ss_loej	= 1;
		
		sr.sr_dma_dir	= SR_DMA_RD;
		sr.sr_addr		= NULL;
		sr.sr_dma_max   = 0;
		sr.sr_ioto		= timeout;	

		result = [self performRequest];	

		}
		
	if (!wasOpen && [self closeSCSI])
		{
		result = -1;
		}

	return(result);		

	}
	
- (int) readTOC: (struct toc *) toc MSF: (BOOL)msf;
	{

	struct cdb10_read_toc *cdbp = &sr.sr_cdb.cdb10_read_toc;
	BOOL wasOpen = isOpen;
	int result = -1;

	if (wasOpen || ![self openSCSI])
		{
			
		[SCSI clearCommandBlock: (cdb *) cdbp];
		
		cdbp->rtoc_opcode 		= C10OP_READTOC;
		cdbp->rtoc_lun			= lun;
		cdbp->rtoc_msf			= 0;
		cdbp->rtoc_starttrack 	= 0;
		writeBigEndianShort(sizeof(*toc),&(cdbp->rtoc_length_BE16));

		sr.sr_dma_dir	= SR_DMA_RD;
		sr.sr_addr		= (char *)toc;
		sr.sr_dma_max   = sizeof(*toc);
		sr.sr_ioto		= timeout;	

		result = [self performRequest];	

		}
		
	if (!wasOpen && [self closeSCSI])
		{
		result = -1;
		}

	return result;		

	}

- (int) playFromMSF:(u_char)firstMinute:(u_char)firstSecond:(u_char)firstFrame
	ToMSF:(u_char)lastMinute:(u_char)lastSecond:(u_char)lastFrame
	{
	
	struct cdb10_play_audio_msf *cdbp = &sr.sr_cdb.cdb10_play_audio_msf;
	BOOL wasOpen = isOpen;
	int result = -1;
	
	if (wasOpen || ![self openSCSI])
		{
			
		[SCSI clearCommandBlock: (cdb *) cdbp];
		
		cdbp->pam_opcode 	= C10OP_PLAYAUDIOMSF;
		cdbp->pam_start_m 	= firstMinute;
		cdbp->pam_start_s	= firstSecond;
		cdbp->pam_start_f	= firstFrame;
		cdbp->pam_end_m		= lastMinute;
		cdbp->pam_end_s		= lastSecond;
		cdbp->pam_end_f		= lastFrame;
				
		sr.sr_dma_dir	= SR_DMA_RD;
		sr.sr_addr		= NULL;
		sr.sr_dma_max   = 0;
		sr.sr_ioto		= timeout;	

		result = [self performRequest];	

		}
		
	if (!wasOpen && [self closeSCSI])
		{
		result = -1;
		}

	return(result);		

	}

@end

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.