src/cdrom/osf/SDL_syscdrom.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 22 Jul 2003 14:01:21 +0000
changeset 654 e92bcf2573cb
child 873 89666943c598
permissions -rw-r--r--
Added audio and CD-ROM support for OSF/Tru64 (thanks Hayashi!)
slouken@654
     1
/*
slouken@654
     2
    Tru64 audio module for SDL (Simple DirectMedia Layer)
slouken@654
     3
    Copyright (C) 2003
slouken@654
     4
slouken@654
     5
    This library is free software; you can redistribute it and/or
slouken@654
     6
    modify it under the terms of the GNU Library General Public
slouken@654
     7
    License as published by the Free Software Foundation; either
slouken@654
     8
    version 2 of the License, or (at your option) any later version.
slouken@654
     9
slouken@654
    10
    This library is distributed in the hope that it will be useful,
slouken@654
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@654
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@654
    13
    Library General Public License for more details.
slouken@654
    14
slouken@654
    15
    You should have received a copy of the GNU Library General Public
slouken@654
    16
    License along with this library; if not, write to the Free
slouken@654
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
slouken@654
    18
slouken@654
    19
slouken@654
    20
*/
slouken@654
    21
slouken@654
    22
slouken@654
    23
/* Functions for system-level CD-ROM audio control */
slouken@654
    24
slouken@654
    25
//#define DEBUG_CDROM 1
slouken@654
    26
slouken@654
    27
#include <sys/types.h>
slouken@654
    28
#include <sys/stat.h>
slouken@654
    29
#include <fcntl.h>
slouken@654
    30
#include <io/cam/cdrom.h>
slouken@654
    31
#include <io/cam/rzdisk.h>
slouken@654
    32
#include <io/common/devgetinfo.h>
slouken@654
    33
#include <alloca.h>
slouken@654
    34
#include <stdlib.h>
slouken@654
    35
#include <stdio.h>
slouken@654
    36
#include <string.h>
slouken@654
    37
#include <errno.h>
slouken@654
    38
slouken@654
    39
#include "SDL_error.h"
slouken@654
    40
#include "SDL_cdrom.h"
slouken@654
    41
#include "SDL_syscdrom.h"
slouken@654
    42
slouken@654
    43
/* The maximum number of CD-ROM drives we'll detect */
slouken@654
    44
#define MAX_DRIVES 16
slouken@654
    45
slouken@654
    46
/* A list of available CD-ROM drives */
slouken@654
    47
static char *SDL_cdlist[MAX_DRIVES];
slouken@654
    48
static dev_t SDL_cdmode[MAX_DRIVES];
slouken@654
    49
slouken@654
    50
/* The system-dependent CD control functions */
slouken@654
    51
static const char *SDL_SYS_CDName(int drive);
slouken@654
    52
static int         SDL_SYS_CDOpen(int drive);
slouken@654
    53
static int         SDL_SYS_CDGetTOC(SDL_CD *cdrom);
slouken@654
    54
static CDstatus    SDL_SYS_CDStatus(SDL_CD *cdrom, int *position);
slouken@654
    55
static int         SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length);
slouken@654
    56
static int         SDL_SYS_CDPause(SDL_CD *cdrom);
slouken@654
    57
static int         SDL_SYS_CDResume(SDL_CD *cdrom);
slouken@654
    58
static int         SDL_SYS_CDStop(SDL_CD *cdrom);
slouken@654
    59
static int         SDL_SYS_CDEject(SDL_CD *cdrom);
slouken@654
    60
static void        SDL_SYS_CDClose(SDL_CD *cdrom);
slouken@654
    61
slouken@654
    62
/* Some ioctl() errno values which occur when the tray is empty */
slouken@654
    63
#define ERRNO_TRAYEMPTY(errno)	\
slouken@654
    64
    ((errno == EIO) || (errno == ENOENT) || (errno == EINVAL))
slouken@654
    65
slouken@654
    66
/* Check a drive to see if it is a CD-ROM */
slouken@654
    67
/* Caution!! Not tested. */ 
slouken@654
    68
static int CheckDrive(char *drive, struct stat *stbuf)
slouken@654
    69
{
slouken@654
    70
    int is_cd, cdfd;
slouken@654
    71
    struct cd_sub_channel info;
slouken@654
    72
slouken@654
    73
    /* If it doesn't exist, return -1 */
slouken@654
    74
    if ( stat(drive, stbuf) < 0 ) {
slouken@654
    75
	return(-1);
slouken@654
    76
    }
slouken@654
    77
slouken@654
    78
    /* If it does exist, verify that it's an available CD-ROM */
slouken@654
    79
    is_cd = 0;
slouken@654
    80
    if ( S_ISCHR(stbuf->st_mode) || S_ISBLK(stbuf->st_mode) ) {
slouken@654
    81
	cdfd = open(drive, (O_RDWR|O_NDELAY), 0);
slouken@654
    82
	if ( cdfd >= 0 ) {
slouken@654
    83
	    info.sch_address_format = CDROM_MSF_FORMAT;
slouken@654
    84
	    info.sch_data_format = CDROM_CURRENT_POSITION;
slouken@654
    85
	    info.sch_alloc_length = 0;
slouken@654
    86
	    info.sch_track_number = 0;
slouken@654
    87
	    info.sch_buffer = NULL;
slouken@654
    88
	    /*
slouken@654
    89
	     *
slouken@654
    90
	     * Under Linux, EIO occurs when a disk is not present.
slouken@654
    91
	     * This isn't 100% reliable, so we use the USE_MNTENT
slouken@654
    92
	     * code above instead.
slouken@654
    93
	     *
slouken@654
    94
	     */
slouken@654
    95
	    if ( (ioctl(cdfd, CDROM_READ_SUBCHANNEL, &info) == 0) ||
slouken@654
    96
		    ERRNO_TRAYEMPTY(errno) ) {
slouken@654
    97
		is_cd = 1;
slouken@654
    98
	    }
slouken@654
    99
slouken@654
   100
	    close(cdfd);
slouken@654
   101
	}
slouken@654
   102
    }
slouken@654
   103
slouken@654
   104
    return(is_cd);
slouken@654
   105
}
slouken@654
   106
slouken@654
   107
/* Add a CD-ROM drive to our list of valid drives */
slouken@654
   108
static void AddDrive(char *drive, struct stat *stbuf)
slouken@654
   109
{
slouken@654
   110
    int i;
slouken@654
   111
slouken@654
   112
    if ( SDL_numcds < MAX_DRIVES ) {
slouken@654
   113
	/* Check to make sure it's not already in our list.
slouken@654
   114
	 * This can happen when we see a drive via symbolic link.
slouken@654
   115
	 *
slouken@654
   116
	 * /
slouken@654
   117
	for ( i=0; i<SDL_numcds; ++i ) {
slouken@654
   118
	    if ( stbuf->st_rdev == SDL_cdmode[i] ) {
slouken@654
   119
#ifdef DEBUG_CDROM
slouken@654
   120
  fprintf(stderr, "Duplicate drive detected: %s == %s\n", drive, SDL_cdlist[i]);
slouken@654
   121
#endif
slouken@654
   122
	    return;
slouken@654
   123
	    }
slouken@654
   124
	}
slouken@654
   125
slouken@654
   126
	/* Add this drive to our list */
slouken@654
   127
	i = SDL_numcds;
slouken@654
   128
	SDL_cdlist[i] = (char *)malloc(strlen(drive)+1);
slouken@654
   129
	if ( SDL_cdlist[i] == NULL ) {
slouken@654
   130
	    SDL_OutOfMemory();
slouken@654
   131
	    return;
slouken@654
   132
	}
slouken@654
   133
slouken@654
   134
	strcpy(SDL_cdlist[i], drive);
slouken@654
   135
	SDL_cdmode[i] = stbuf->st_rdev;
slouken@654
   136
	++SDL_numcds;
slouken@654
   137
#ifdef DEBUG_CDROM
slouken@654
   138
  fprintf(stderr, "Added CD-ROM drive: %s\n", drive);
slouken@654
   139
#endif
slouken@654
   140
    }
slouken@654
   141
}
slouken@654
   142
slouken@654
   143
int  SDL_SYS_CDInit(void)
slouken@654
   144
{
slouken@654
   145
    /* checklist: /dev/cdrom,/dev/cd?c /dev/acd?c
slouken@654
   146
     * /dev/matcd?c /dev/mcd?c /dev/scd?c
slouken@654
   147
     *
slouken@654
   148
     */
slouken@654
   149
    static char *checklist[] = {
slouken@654
   150
	"?0 rdisk/cdrom?",NULL};
slouken@654
   151
    char drive[32];
slouken@654
   152
    char *SDLcdrom;
slouken@654
   153
    int i, j, exists;
slouken@654
   154
    struct stat stbuf;
slouken@654
   155
slouken@654
   156
    /* Fill in our driver capabilities */
slouken@654
   157
    SDL_CDcaps.Name   = SDL_SYS_CDName;
slouken@654
   158
    SDL_CDcaps.Open   = SDL_SYS_CDOpen;
slouken@654
   159
    SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
slouken@654
   160
    SDL_CDcaps.Status = SDL_SYS_CDStatus;
slouken@654
   161
    SDL_CDcaps.Play   = SDL_SYS_CDPlay;
slouken@654
   162
    SDL_CDcaps.Pause  = SDL_SYS_CDPause;
slouken@654
   163
    SDL_CDcaps.Resume = SDL_SYS_CDResume;
slouken@654
   164
    SDL_CDcaps.Stop   = SDL_SYS_CDStop;
slouken@654
   165
    SDL_CDcaps.Eject  = SDL_SYS_CDEject;
slouken@654
   166
    SDL_CDcaps.Close  = SDL_SYS_CDClose;
slouken@654
   167
slouken@654
   168
slouken@654
   169
    /* Look in the environment for our CD-ROM drive list */
slouken@654
   170
    SDLcdrom = getenv("SDL_CDROM");	/* ':' separated list of devices */
slouken@654
   171
    if ( SDLcdrom != NULL ) {
slouken@654
   172
	char *cdpath, *delim;
slouken@654
   173
	cdpath = malloc(strlen(SDLcdrom)+1);
slouken@654
   174
	if ( cdpath != NULL ) {
slouken@654
   175
	    strcpy(cdpath, SDLcdrom);
slouken@654
   176
	    SDLcdrom = cdpath;
slouken@654
   177
	    do {
slouken@654
   178
		delim = strchr(SDLcdrom, ':');
slouken@654
   179
		if ( delim ) {
slouken@654
   180
		    *delim++ = '\0';
slouken@654
   181
		}
slouken@654
   182
		if ( CheckDrive(SDLcdrom, &stbuf) > 0 ) {
slouken@654
   183
		    AddDrive(SDLcdrom, &stbuf);
slouken@654
   184
		}
slouken@654
   185
		if ( delim ) {
slouken@654
   186
		    SDLcdrom = delim;
slouken@654
   187
		} else {
slouken@654
   188
		    SDLcdrom = NULL;
slouken@654
   189
		}
slouken@654
   190
	    } while ( SDLcdrom );
slouken@654
   191
	    free(cdpath);
slouken@654
   192
	}
slouken@654
   193
slouken@654
   194
	/* If we found our drives, there's nothing left to do */
slouken@654
   195
	if ( SDL_numcds > 0 ) {
slouken@654
   196
	    return(0);
slouken@654
   197
	}
slouken@654
   198
    }
slouken@654
   199
    /* Scan the system for CD-ROM drives */
slouken@654
   200
    for ( i=0; checklist[i]; ++i ) {
slouken@654
   201
	if ( checklist[i][0] == '?' ) {
slouken@654
   202
	    char *insert;
slouken@654
   203
	    exists = 1;
slouken@654
   204
	    for ( j=checklist[i][1]; exists; ++j ) {
slouken@654
   205
		sprintf(drive, "/dev/%sc", &checklist[i][3]);
slouken@654
   206
		insert = strchr(drive, '?');
slouken@654
   207
		if ( insert != NULL ) {
slouken@654
   208
		    *insert = j;
slouken@654
   209
		}
slouken@654
   210
		switch (CheckDrive(drive, &stbuf)) {
slouken@654
   211
		    /* Drive exists and is a CD-ROM */
slouken@654
   212
		    case 1:
slouken@654
   213
			AddDrive(drive, &stbuf);
slouken@654
   214
			break;
slouken@654
   215
			/* Drive exists, but isn't a CD-ROM */
slouken@654
   216
		    case 0:
slouken@654
   217
			break;
slouken@654
   218
			/* Drive doesn't exist */
slouken@654
   219
		    case -1:
slouken@654
   220
			exists = 0;
slouken@654
   221
			break;
slouken@654
   222
		}
slouken@654
   223
	    }
slouken@654
   224
	} else {
slouken@654
   225
	    sprintf(drive, "/dev/%s", checklist[i]);
slouken@654
   226
	    if ( CheckDrive(drive, &stbuf) > 0 ) {
slouken@654
   227
		AddDrive(drive, &stbuf);
slouken@654
   228
	    }
slouken@654
   229
	}
slouken@654
   230
    }
slouken@654
   231
/*
slouken@654
   232
    SDLcdrom=malloc(sizeof(char) * 32);
slouken@654
   233
    strcpy(SDLcdrom,"/dev/rdisk/cdrom0c");
slouken@654
   234
    SDL_cdlist[0] = SDLcdrom;
slouken@654
   235
    stat(SDLcdrom, &stbuf);
slouken@654
   236
    SDL_cdmode[0] = stbuf.st_rdev;
slouken@654
   237
    SDL_numcds = 1;
slouken@654
   238
 */
slouken@654
   239
    return (0);
slouken@654
   240
}
slouken@654
   241
slouken@654
   242
static const char *SDL_SYS_CDName(int drive)
slouken@654
   243
{
slouken@654
   244
    return(SDL_cdlist[drive]);
slouken@654
   245
}
slouken@654
   246
slouken@654
   247
static int SDL_SYS_CDOpen(int drive)
slouken@654
   248
{
slouken@654
   249
    /* O_RDWR: To use ioctl(fd, SCSI_STOP_UNIT) */
slouken@654
   250
    return(open(SDL_cdlist[drive], (O_RDWR|O_NDELAY), 0));
slouken@654
   251
}
slouken@654
   252
slouken@654
   253
static int SDL_SYS_CDGetTOC(SDL_CD *cdrom)
slouken@654
   254
{
slouken@654
   255
    struct cd_toc                  toc;
slouken@654
   256
    struct cd_toc_header           hdr;
slouken@654
   257
    struct cd_toc_entry          *cdte;
slouken@654
   258
    int i;
slouken@654
   259
    int okay = 0;
slouken@654
   260
    if ( ioctl(cdrom->id, CDROM_TOC_HEADER, &hdr) ) {
slouken@654
   261
	fprintf(stderr,"ioctl error CDROM_TOC_HEADER\n");
slouken@654
   262
	return -1;
slouken@654
   263
    }
slouken@654
   264
    cdrom->numtracks = hdr.th_ending_track - hdr.th_starting_track + 1;
slouken@654
   265
    if ( cdrom->numtracks > SDL_MAX_TRACKS ) {
slouken@654
   266
	cdrom->numtracks = SDL_MAX_TRACKS;
slouken@654
   267
    }
slouken@654
   268
#ifdef DEBUG_CDROM
slouken@654
   269
  fprintf(stderr,"hdr.th_data_len1 = %d\n", hdr.th_data_len1);
slouken@654
   270
  fprintf(stderr,"hdr.th_data_len0 = %d\n", hdr.th_data_len0);
slouken@654
   271
  fprintf(stderr,"hdr.th_starting_track = %d\n", hdr.th_starting_track);
slouken@654
   272
  fprintf(stderr,"hdr.th_ending_track = %d\n", hdr.th_ending_track);
slouken@654
   273
  fprintf(stderr,"cdrom->numtracks = %d\n", cdrom->numtracks);
slouken@654
   274
#endif
slouken@654
   275
    toc.toc_address_format = CDROM_LBA_FORMAT;
slouken@654
   276
    toc.toc_starting_track = 0;
slouken@654
   277
    toc.toc_alloc_length = (hdr.th_data_len1 << 8) +
slouken@654
   278
			    hdr.th_data_len0 + sizeof(hdr);
slouken@654
   279
    if ( (toc.toc_buffer = alloca(toc.toc_alloc_length)) == NULL) {
slouken@654
   280
	fprintf(stderr,"cannot allocate toc.toc_buffer\n");
slouken@654
   281
	return -1;
slouken@654
   282
    }
slouken@654
   283
slouken@654
   284
    bzero (toc.toc_buffer, toc.toc_alloc_length);
slouken@654
   285
    if (ioctl(cdrom->id, CDROM_TOC_ENTRYS, &toc)) {
slouken@654
   286
	fprintf(stderr,"ioctl error CDROM_TOC_ENTRYS\n");
slouken@654
   287
	return -1;
slouken@654
   288
    }
slouken@654
   289
slouken@654
   290
    (char *)cdte = toc.toc_buffer + sizeof(hdr);
slouken@654
   291
	for (i=0; i <= cdrom->numtracks; ++i) {
slouken@654
   292
	    if (i == cdrom->numtracks ) {
slouken@654
   293
		cdrom->track[i].id = 0xAA;;
slouken@654
   294
	    } else {
slouken@654
   295
		cdrom->track[i].id = hdr.th_starting_track + i;
slouken@654
   296
	    }
slouken@654
   297
slouken@654
   298
	    cdrom->track[i].type =
slouken@654
   299
		cdte[i].te_control & CDROM_DATA_TRACK;
slouken@654
   300
	    cdrom->track[i].offset =
slouken@654
   301
		cdte[i].te_absaddr.lba.addr3 << 24 |
slouken@654
   302
		cdte[i].te_absaddr.lba.addr2 << 16 |
slouken@654
   303
		cdte[i].te_absaddr.lba.addr1 << 8  |
slouken@654
   304
		cdte[i].te_absaddr.lba.addr0;
slouken@654
   305
	    cdrom->track[i].length = 0;
slouken@654
   306
	    if ( i > 0 ) {
slouken@654
   307
		cdrom->track[i - 1].length =
slouken@654
   308
		    cdrom->track[i].offset -
slouken@654
   309
		    cdrom->track[i - 1].offset;
slouken@654
   310
	    }
slouken@654
   311
	}
slouken@654
   312
#ifdef DEBUG_CDROM
slouken@654
   313
  for (i = 0; i <= cdrom->numtracks; i++) {
slouken@654
   314
    fprintf(stderr,"toc_entry[%d].te_track_number = %d\n",
slouken@654
   315
	    i,cdte[i].te_track_number);
slouken@654
   316
    fprintf(stderr,"cdrom->track[%d].id = %d\n", i,cdrom->track[i].id);
slouken@654
   317
    fprintf(stderr,"cdrom->track[%d].type = %x\n", i,cdrom->track[i].type);
slouken@654
   318
    fprintf(stderr,"cdrom->track[%d].offset = %d\n", i,cdrom->track[i].offset);
slouken@654
   319
    fprintf(stderr,"cdrom->track[%d].length = %d\n", i,cdrom->track[i].length);
slouken@654
   320
  }
slouken@654
   321
#endif
slouken@654
   322
    if ( i == (cdrom->numtracks+1) ) {
slouken@654
   323
	okay = 1;
slouken@654
   324
    }
slouken@654
   325
slouken@654
   326
    return(okay ? 0 : -1);
slouken@654
   327
}
slouken@654
   328
slouken@654
   329
/* Get CD-ROM status */
slouken@654
   330
static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position)
slouken@654
   331
{
slouken@654
   332
    CDstatus                     status;
slouken@654
   333
    struct cd_sub_channel            sc;
slouken@654
   334
    struct cd_subc_channel_data     scd;
slouken@654
   335
slouken@654
   336
    sc.sch_address_format = CDROM_LBA_FORMAT;
slouken@654
   337
    sc.sch_data_format    = CDROM_CURRENT_POSITION;
slouken@654
   338
    sc.sch_track_number   = 0;
slouken@654
   339
    sc.sch_alloc_length   = sizeof(scd);
slouken@654
   340
    sc.sch_buffer         = (caddr_t)&scd;
slouken@654
   341
    if ( ioctl(cdrom->id, CDROM_READ_SUBCHANNEL, &sc) ) {
slouken@654
   342
	status = CD_ERROR;
slouken@654
   343
	fprintf(stderr,"ioctl error CDROM_READ_SUBCHANNEL \n");
slouken@654
   344
    } else {
slouken@654
   345
	switch (scd.scd_header.sh_audio_status) {
slouken@654
   346
	    case AS_AUDIO_INVALID:
slouken@654
   347
		status = CD_STOPPED;
slouken@654
   348
		break;
slouken@654
   349
	    case AS_PLAY_IN_PROGRESS:
slouken@654
   350
		status = CD_PLAYING;
slouken@654
   351
		break;
slouken@654
   352
	    case AS_PLAY_PAUSED:
slouken@654
   353
		status = CD_PAUSED;
slouken@654
   354
		break;
slouken@654
   355
	    case AS_PLAY_COMPLETED:
slouken@654
   356
		status = CD_STOPPED;
slouken@654
   357
		break;
slouken@654
   358
	    case AS_PLAY_ERROR:
slouken@654
   359
		status = CD_ERROR;
slouken@654
   360
		break;
slouken@654
   361
	    case AS_NO_STATUS:
slouken@654
   362
		status = CD_STOPPED;
slouken@654
   363
		break;
slouken@654
   364
	    default:
slouken@654
   365
		status = CD_ERROR;
slouken@654
   366
		break;
slouken@654
   367
	}
slouken@654
   368
#ifdef DEBUG_CDROM
slouken@654
   369
  fprintf(stderr,"scd.scd_header.sh_audio_status = %x\n",
slouken@654
   370
	scd.scd_header.sh_audio_status);
slouken@654
   371
#endif
slouken@654
   372
    }
slouken@654
   373
    if (position) {
slouken@654
   374
	if (status == CD_PLAYING || (status == CD_PAUSED) ) {
slouken@654
   375
	    *position =
slouken@654
   376
		scd.scd_position_data.scp_absaddr.lba.addr3 << 24 |
slouken@654
   377
		scd.scd_position_data.scp_absaddr.lba.addr2 << 16 |
slouken@654
   378
		scd.scd_position_data.scp_absaddr.lba.addr1 << 8  |
slouken@654
   379
		scd.scd_position_data.scp_absaddr.lba.addr0;
slouken@654
   380
	} else {
slouken@654
   381
	    *position = 0;
slouken@654
   382
	}
slouken@654
   383
    }
slouken@654
   384
slouken@654
   385
    return status;
slouken@654
   386
}
slouken@654
   387
slouken@654
   388
/* Start play */
slouken@654
   389
static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length)
slouken@654
   390
{
slouken@654
   391
/* Play MSF
slouken@654
   392
 *
slouken@654
   393
 */
slouken@654
   394
    struct cd_play_audio_msf msf;
slouken@654
   395
    int end;
slouken@654
   396
slouken@654
   397
    bzero(&msf, sizeof(msf));
slouken@654
   398
    end = start +length;
slouken@654
   399
    FRAMES_TO_MSF(start,
slouken@654
   400
		  &msf.msf_starting_M_unit,
slouken@654
   401
		  &msf.msf_starting_S_unit,
slouken@654
   402
		  &msf.msf_starting_F_unit);
slouken@654
   403
    FRAMES_TO_MSF(end,
slouken@654
   404
		  &msf.msf_ending_M_unit,
slouken@654
   405
		  &msf.msf_ending_S_unit,
slouken@654
   406
		  &msf.msf_ending_F_unit);
slouken@654
   407
slouken@654
   408
    return(ioctl(cdrom->id, CDROM_PLAY_AUDIO_MSF, &msf));
slouken@654
   409
}
slouken@654
   410
slouken@654
   411
/* Pause play */
slouken@654
   412
static int SDL_SYS_CDPause(SDL_CD *cdrom)
slouken@654
   413
{
slouken@654
   414
    return(ioctl(cdrom->id, CDROM_PAUSE_PLAY));
slouken@654
   415
}
slouken@654
   416
slouken@654
   417
/* Resume play */
slouken@654
   418
static int SDL_SYS_CDResume(SDL_CD *cdrom)
slouken@654
   419
{
slouken@654
   420
    return(ioctl(cdrom->id, CDROM_RESUME_PLAY));
slouken@654
   421
}
slouken@654
   422
slouken@654
   423
/* Stop play */
slouken@654
   424
static int SDL_SYS_CDStop(SDL_CD *cdrom)
slouken@654
   425
{
slouken@654
   426
    return(ioctl(cdrom->id, SCSI_STOP_UNIT));
slouken@654
   427
}
slouken@654
   428
slouken@654
   429
/* Eject the CD-ROM */
slouken@654
   430
static int SDL_SYS_CDEject(SDL_CD *cdrom)
slouken@654
   431
{
slouken@654
   432
    return(ioctl(cdrom->id, CDROM_EJECT_CADDY));
slouken@654
   433
}
slouken@654
   434
slouken@654
   435
/* Close the CD-ROM handle */
slouken@654
   436
static void SDL_SYS_CDClose(SDL_CD *cdrom)
slouken@654
   437
{
slouken@654
   438
    close(cdrom->id);
slouken@654
   439
}
slouken@654
   440
slouken@654
   441
void SDL_SYS_CDQuit(void)
slouken@654
   442
{
slouken@654
   443
    int i;
slouken@654
   444
slouken@654
   445
    if ( SDL_numcds > 0 ) {
slouken@654
   446
	for ( i=0; i<SDL_numcds; ++i ) {
slouken@654
   447
	    free(SDL_cdlist[i]);
slouken@654
   448
	}
slouken@654
   449
	SDL_numcds = 0;
slouken@654
   450
    }
slouken@654
   451
}
slouken@654
   452
slouken@654
   453