Subject: CD-ROM stuff
To: MacBSD General <macbsd-general@sun-lamp.cs.berkeley.edu>
From: Allen Briggs <briggs@cray-ymp.acm.stuorg.vt.edu>
List: macbsd-general
Date: 01/27/1994 19:23:52
Here's a little program I cooked up.  (I got a CD-ROM drive :-) :-)
This should work on any SCSI-2 CD-ROM, as far as I know, but it works
on my Toshiba 3401.  It occurs to me that I ran the supplied player
application, so you might need to run that to initialize the drive.
Dunno...  I'm running out the line out jacks.

You don't get support for this and I'm not answering any questions
about it--it's a quick hack and if you can use it, cool.  If not, you
can fix it or toss it.  If you know about a more full-featured program,
I'd like to hear about it (unless it's xcdplayer ;-)...

BTW, you might get some mileage from doing:
	rm -f /dev/rcd0a
	mknod /dev/rcd0a c 17 0

Cheers,
-allen

-----<<<<<  Cut here  >>>>>-----

/* Trivial CD player program.  Use, abuse, burn this code, whatever. */

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/cdio.h>
#include <sys/fcntl.h>

int	cdfd;
char	cdfname[20] = "/dev/rcd0a";

#define OPTSTR	"f:t:T:spre"

static void
usage(char *prog)
{
	fprintf(stderr, "Usage: %s [-f device] [-t start_track] [-T end_track] "
			"[-s]\n", prog);
	fprintf(stderr, "Where:\n");
	fprintf(stderr, "\t-s  means stop\n");
}

main(int argc, char *argv[])
{
	struct ioc_toc_header	hdr;
	struct ioc_vol		vol;
	struct ioc_play_track	play;
	int			c, track=1, etrack=99, stop=0;

	while ((c = getopt(argc, argv, OPTSTR)) != -1) {
		switch (c) {
			case 'f':
				strcpy(cdfname, optarg);
				break;
			case 'T':
				etrack = strtol(optarg, NULL, 0);
				if (etrack <= 0) {
					usage(argv[0]);
					exit(-1);
				}
				break;
			case 't':
				track = strtol(optarg, NULL, 0);
				if (track == 0) {
					usage(argv[0]);
					exit(-1);
				}
				break;
			case 's': stop = 1; break;
		}
	}

	cdfd = open(cdfname, O_RDONLY);
	if (cdfd < 0) {
		perror(cdfname);
		exit(-2);
	}

	if (stop) {
		if (ioctl(cdfd, CDIOCSTOP, NULL) < 0) {
			perror("CDIOCSTOP");
			exit(-1);
		}
		exit(0);
	}

	if (ioctl(cdfd, CDIOREADTOCHEADER, &hdr) < 0) {
		perror("CDIOREADTOCHEADER");
		exit(-3);
	}

	if (track > etrack) {
		fprintf(stderr, "Starting track is greater than ending track.\n");
		usage(argv[0]);
	}
	if (track > hdr.ending_track) {
		fprintf(stderr, "Last track is %d, you specified track %d.\n",
				hdr.ending_track, track);
		usage(argv[0]);
		
	}
	if (track < hdr.starting_track) {
		fprintf(stderr, "First track is %d, you specified track %d.\n",
				hdr.starting_track, track);
		usage(argv[0]);
	}

	if (ioctl(cdfd, CDIOCSETSTERIO, NULL) < 0) {
		perror("CDIOCSETSTERIO");
		exit(-4);
	}

	play.start_track = track;
	play.start_index = 1;
	play.end_track = etrack;
	play.end_index = 1;
	if (ioctl(cdfd, CDIOCPLAYTRACKS, &play) < 0) {
		perror("CDIOPLAYTRACKS");
		exit(-4);
	}
}

-----<<<<<  Cut here  >>>>>-----


------------------------------------------------------------------------------