src/cdrom/osf/SDL_syscdrom.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 26 Feb 2006 04:54:01 +0000
changeset 1438 1f4f09641645
parent 1402 d910939febfa
child 1635 92947e3a18db
permissions -rw-r--r--
Date: Sun, 26 Feb 2006 11:25:09 +0900
From: Hayashi Naoyuki
Subject: Re: [SDL] CVS stable again, please update SDL ports

Some problems are caused on Tru64 UNIX.
If applying SDL12-osf1.path, these problems are fixed.


1. configure-script say "recursive mutexes... no" and "pthread
semaphores... no".
checking for pthreads... yes
checking for recursive mutexes... no
checking for pthread semaphores... no

This is because it compiled without pthread_cflags and pthread_lib when
checking recursive mutexes and pthread semaphores.


2. Compiling src/audio/mme/SDL_mmeaudio.c fails.
cc: Severe: ./src/audio/mme/SDL_mmeaudio.c, line 25: Cannot find file
<mme_api.h> specified in #include directive. (noinclfilef)
#include <mme_api.h>
-^

This is because BUILD_CFLAGS is wrong.


3. Compiling src/cdrom/osf/SDL_syscdrom.c fails.
cc: Warning: ./src/cdrom/osf/SDL_syscdrom.c, line 176: Too few actual
parameters in the invocation of the macro "SDL_stack_alloc". (toofewactuals)
cdpath = SDL_stack_alloc(len);
------------------------------------^
cc: Error: ./src/cdrom/osf/SDL_syscdrom.c, line 176: Invalid expression.
(badexpr)
cdpath = SDL_stack_alloc(len);
-----------------^

SDL_stack_alloc is defined in include/SDL_stdinc.h.
#define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*count)


4. Linking fails if running configure with --enable-x11-shared=yes.
/usr/ccs/bin/ld:
Warning: Unresolved:
p_XData32


5. Compiling src/video/x11/SDL_x11dyn.c fails if running configure with
--enable-x11-shared=no.
cc: Error: ./src/video/x11/SDL_x11sym.h, line 149: In this statement,
"_SmtBufferOverflow" is not declared. (undeclared)
SDL_X11_SYM(1,void,_SmtBufferOverflow,(Display *dpy,register smtDisplayPtr))
^
cc: Error: ./src/video/x11/SDL_x11sym.h, line 150: In this statement,
"_SmtBufferOverflow" is not declared. (undeclared)
SDL_X11_SYM(1,void,_SmtBufferOverflow,(Display *dpy,register smtDisplayPtr))
^
cc: Error: ./src/video/x11/SDL_x11sym.h, line 150: In this statement,
"_SmtIpError" is not declared. (undeclared)
SDL_X11_SYM(1,void,_SmtIpError,(Display *dpy,register smtDisplayPtr, int))
^
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@1402
    21
#include "SDL_config.h"
slouken@654
    22
slouken@654
    23
/* Functions for system-level CD-ROM audio control */
slouken@654
    24
slouken@1019
    25
/* #define DEBUG_CDROM 1 */
slouken@654
    26
slouken@654
    27
#include <sys/types.h>
slouken@1019
    28
#include <dirent.h>
slouken@654
    29
#include <sys/stat.h>
slouken@654
    30
#include <fcntl.h>
slouken@654
    31
#include <io/cam/cdrom.h>
slouken@654
    32
#include <io/cam/rzdisk.h>
slouken@654
    33
#include <io/common/devgetinfo.h>
slouken@654
    34
slouken@654
    35
#include "SDL_cdrom.h"
slouken@1361
    36
#include "../SDL_syscdrom.h"
slouken@654
    37
slouken@654
    38
/* The maximum number of CD-ROM drives we'll detect */
slouken@654
    39
#define MAX_DRIVES 16
slouken@654
    40
slouken@654
    41
/* A list of available CD-ROM drives */
slouken@654
    42
static char *SDL_cdlist[MAX_DRIVES];
slouken@654
    43
static dev_t SDL_cdmode[MAX_DRIVES];
slouken@654
    44
slouken@654
    45
/* The system-dependent CD control functions */
slouken@654
    46
static const char *SDL_SYS_CDName(int drive);
slouken@654
    47
static int         SDL_SYS_CDOpen(int drive);
slouken@654
    48
static int         SDL_SYS_CDGetTOC(SDL_CD *cdrom);
slouken@654
    49
static CDstatus    SDL_SYS_CDStatus(SDL_CD *cdrom, int *position);
slouken@654
    50
static int         SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length);
slouken@654
    51
static int         SDL_SYS_CDPause(SDL_CD *cdrom);
slouken@654
    52
static int         SDL_SYS_CDResume(SDL_CD *cdrom);
slouken@654
    53
static int         SDL_SYS_CDStop(SDL_CD *cdrom);
slouken@654
    54
static int         SDL_SYS_CDEject(SDL_CD *cdrom);
slouken@654
    55
static void        SDL_SYS_CDClose(SDL_CD *cdrom);
slouken@654
    56
slouken@654
    57
/* Check a drive to see if it is a CD-ROM */
slouken@654
    58
/* Caution!! Not tested. */ 
slouken@654
    59
static int CheckDrive(char *drive, struct stat *stbuf)
slouken@654
    60
{
slouken@873
    61
    int cdfd, is_cd = 0;
slouken@873
    62
    struct mode_sel_sns_params msp;
slouken@873
    63
    struct inquiry_info inq;
slouken@873
    64
slouken@873
    65
#ifdef DEBUG_CDROM
slouken@873
    66
    char *devtype[] = {"Disk", "Tape", "Printer", "Processor", "WORM",
slouken@873
    67
	"CD-ROM", "Scanner", "Optical", "Changer", "Comm", "Unknown"};
slouken@873
    68
#endif
slouken@873
    69
slouken@873
    70
    bzero(&msp, sizeof(msp));
slouken@873
    71
    bzero(&inq, sizeof(inq));
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@873
    78
    if ( (cdfd = open(drive, (O_RDWR|O_NDELAY), 0)) >= 0 ) {
slouken@873
    79
	msp.msp_addr   =   (caddr_t) &inq;
slouken@873
    80
	msp.msp_pgcode =                0;
slouken@873
    81
	msp.msp_pgctrl =                0;
slouken@873
    82
	msp.msp_length =      sizeof(inq);
slouken@873
    83
	msp.msp_setps  =                0;
slouken@654
    84
slouken@873
    85
	if ( ioctl(cdfd, SCSI_GET_INQUIRY_DATA, &msp) )
slouken@873
    86
	    return (0);
slouken@873
    87
slouken@873
    88
#ifdef DEBUG_CDROM
slouken@873
    89
	fprintf(stderr, "Device Type: %s\n", devtype[inq.perfdt]);
slouken@873
    90
	fprintf(stderr, "Vendor: %.8s\n", inq.vndrid);
slouken@873
    91
	fprintf(stderr, "Product: %.8s\n", inq.prodid);
slouken@873
    92
	fprintf(stderr, "Revision: %.8s\n", inq.revlvl);
slouken@873
    93
#endif
slouken@873
    94
	if ( inq.perfdt == DTYPE_RODIRECT )
slouken@873
    95
	    is_cd = 1;
slouken@654
    96
    }
slouken@654
    97
slouken@654
    98
    return(is_cd);
slouken@654
    99
}
slouken@654
   100
slouken@654
   101
/* Add a CD-ROM drive to our list of valid drives */
slouken@654
   102
static void AddDrive(char *drive, struct stat *stbuf)
slouken@654
   103
{
slouken@654
   104
    int i;
slouken@654
   105
slouken@654
   106
    if ( SDL_numcds < MAX_DRIVES ) {
slouken@654
   107
	/* Check to make sure it's not already in our list.
slouken@654
   108
	 * This can happen when we see a drive via symbolic link.
slouken@654
   109
	 *
slouken@873
   110
	 */
slouken@654
   111
	for ( i=0; i<SDL_numcds; ++i ) {
slouken@654
   112
	    if ( stbuf->st_rdev == SDL_cdmode[i] ) {
slouken@654
   113
#ifdef DEBUG_CDROM
slouken@654
   114
  fprintf(stderr, "Duplicate drive detected: %s == %s\n", drive, SDL_cdlist[i]);
slouken@654
   115
#endif
slouken@654
   116
	    return;
slouken@654
   117
	    }
slouken@654
   118
	}
slouken@654
   119
slouken@654
   120
	/* Add this drive to our list */
slouken@654
   121
	i = SDL_numcds;
slouken@1379
   122
	SDL_cdlist[i] = SDL_strdup(drive);
slouken@654
   123
	if ( SDL_cdlist[i] == NULL ) {
slouken@654
   124
	    SDL_OutOfMemory();
slouken@654
   125
	    return;
slouken@654
   126
	}
slouken@654
   127
	SDL_cdmode[i] = stbuf->st_rdev;
slouken@654
   128
	++SDL_numcds;
slouken@654
   129
#ifdef DEBUG_CDROM
slouken@654
   130
  fprintf(stderr, "Added CD-ROM drive: %s\n", drive);
slouken@654
   131
#endif
slouken@654
   132
    }
slouken@654
   133
}
slouken@654
   134
slouken@654
   135
int  SDL_SYS_CDInit(void)
slouken@654
   136
{
slouken@1019
   137
    /* checklist:
slouken@1019
   138
     *
slouken@1019
   139
     * Tru64 5.X (/dev/rdisk/cdrom?c)
slouken@1019
   140
     * dir: /dev/rdisk, name: cdrom
slouken@1019
   141
     *
slouken@1019
   142
     * Digital UNIX 4.0X (/dev/rrz?c)
slouken@1019
   143
     * dir: /dev, name: rrz
slouken@654
   144
     *
slouken@654
   145
     */
slouken@1019
   146
    struct {
slouken@1019
   147
	char *dir;
slouken@1019
   148
	char *name;
slouken@1019
   149
    } checklist[] = {
slouken@1019
   150
	{"/dev/rdisk", "cdrom"},
slouken@1019
   151
	{"/dev", "rrz"},
slouken@1019
   152
	{NULL, NULL}};
slouken@654
   153
    char drive[32];
slouken@654
   154
    char *SDLcdrom;
slouken@654
   155
    int i, j, exists;
slouken@654
   156
    struct stat stbuf;
slouken@654
   157
slouken@654
   158
    /* Fill in our driver capabilities */
slouken@654
   159
    SDL_CDcaps.Name   = SDL_SYS_CDName;
slouken@654
   160
    SDL_CDcaps.Open   = SDL_SYS_CDOpen;
slouken@654
   161
    SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
slouken@654
   162
    SDL_CDcaps.Status = SDL_SYS_CDStatus;
slouken@654
   163
    SDL_CDcaps.Play   = SDL_SYS_CDPlay;
slouken@654
   164
    SDL_CDcaps.Pause  = SDL_SYS_CDPause;
slouken@654
   165
    SDL_CDcaps.Resume = SDL_SYS_CDResume;
slouken@654
   166
    SDL_CDcaps.Stop   = SDL_SYS_CDStop;
slouken@654
   167
    SDL_CDcaps.Eject  = SDL_SYS_CDEject;
slouken@654
   168
    SDL_CDcaps.Close  = SDL_SYS_CDClose;
slouken@654
   169
slouken@654
   170
slouken@654
   171
    /* Look in the environment for our CD-ROM drive list */
slouken@1336
   172
    SDLcdrom = SDL_getenv("SDL_CDROM");	/* ':' separated list of devices */
slouken@654
   173
    if ( SDLcdrom != NULL ) {
slouken@654
   174
	char *cdpath, *delim;
slouken@1379
   175
	size_t len = SDL_strlen(SDLcdrom)+1;
slouken@1438
   176
	cdpath = SDL_stack_alloc(char, len);
slouken@654
   177
	if ( cdpath != NULL ) {
slouken@1379
   178
	    SDL_strlcpy(cdpath, SDLcdrom, len);
slouken@654
   179
	    SDLcdrom = cdpath;
slouken@654
   180
	    do {
slouken@1336
   181
		delim = SDL_strchr(SDLcdrom, ':');
slouken@654
   182
		if ( delim ) {
slouken@654
   183
		    *delim++ = '\0';
slouken@654
   184
		}
slouken@654
   185
		if ( CheckDrive(SDLcdrom, &stbuf) > 0 ) {
slouken@654
   186
		    AddDrive(SDLcdrom, &stbuf);
slouken@654
   187
		}
slouken@654
   188
		if ( delim ) {
slouken@654
   189
		    SDLcdrom = delim;
slouken@654
   190
		} else {
slouken@654
   191
		    SDLcdrom = NULL;
slouken@654
   192
		}
slouken@654
   193
	    } while ( SDLcdrom );
slouken@1379
   194
	    SDL_stack_free(cdpath);
slouken@654
   195
	}
slouken@654
   196
slouken@654
   197
	/* If we found our drives, there's nothing left to do */
slouken@654
   198
	if ( SDL_numcds > 0 ) {
slouken@654
   199
	    return(0);
slouken@654
   200
	}
slouken@654
   201
    }
slouken@654
   202
    /* Scan the system for CD-ROM drives */
slouken@1019
   203
    for ( i = 0; checklist[i].dir; ++i) {
slouken@1019
   204
	DIR *devdir;
slouken@1019
   205
	struct dirent *devent;
slouken@1019
   206
	int name_len;
slouken@1019
   207
slouken@1019
   208
	devdir = opendir(checklist[i].dir);
slouken@1019
   209
	if (devdir) {
slouken@1336
   210
	    name_len = SDL_strlen(checklist[i].name);
slouken@1019
   211
	    while (devent = readdir(devdir))
slouken@1336
   212
		if (SDL_memcmp(checklist[i].name, devent->d_name, name_len) == 0)
slouken@1019
   213
		    if (devent->d_name[devent->d_namlen-1] == 'c') {
slouken@1338
   214
			SDL_snprintf(drive, SDL_arraysize(drive), "%s/%s", checklist[i].dir, devent->d_name);
slouken@1019
   215
#ifdef DEBUG_CDROM
slouken@1019
   216
			fprintf(stderr, "Try to add drive: %s\n", drive);
slouken@1019
   217
#endif
slouken@1019
   218
			if ( CheckDrive(drive, &stbuf) > 0 )
slouken@1019
   219
			    AddDrive(drive, &stbuf);
slouken@1019
   220
		    }
slouken@1019
   221
	    closedir(devdir);
slouken@654
   222
	} else {
slouken@1019
   223
#ifdef DEBUG_CDROM
slouken@1019
   224
	    fprintf(stderr, "cannot open dir: %s\n", checklist[i].dir);
slouken@1019
   225
#endif
slouken@654
   226
	}
slouken@654
   227
    }
slouken@654
   228
    return (0);
slouken@654
   229
}
slouken@654
   230
slouken@654
   231
static const char *SDL_SYS_CDName(int drive)
slouken@654
   232
{
slouken@654
   233
    return(SDL_cdlist[drive]);
slouken@654
   234
}
slouken@654
   235
slouken@654
   236
static int SDL_SYS_CDOpen(int drive)
slouken@654
   237
{
slouken@654
   238
    /* O_RDWR: To use ioctl(fd, SCSI_STOP_UNIT) */
slouken@654
   239
    return(open(SDL_cdlist[drive], (O_RDWR|O_NDELAY), 0));
slouken@654
   240
}
slouken@654
   241
slouken@654
   242
static int SDL_SYS_CDGetTOC(SDL_CD *cdrom)
slouken@654
   243
{
slouken@654
   244
    struct cd_toc                  toc;
slouken@654
   245
    struct cd_toc_header           hdr;
slouken@654
   246
    struct cd_toc_entry          *cdte;
slouken@654
   247
    int i;
slouken@654
   248
    int okay = 0;
slouken@654
   249
    if ( ioctl(cdrom->id, CDROM_TOC_HEADER, &hdr) ) {
slouken@654
   250
	fprintf(stderr,"ioctl error CDROM_TOC_HEADER\n");
slouken@654
   251
	return -1;
slouken@654
   252
    }
slouken@654
   253
    cdrom->numtracks = hdr.th_ending_track - hdr.th_starting_track + 1;
slouken@654
   254
    if ( cdrom->numtracks > SDL_MAX_TRACKS ) {
slouken@654
   255
	cdrom->numtracks = SDL_MAX_TRACKS;
slouken@654
   256
    }
slouken@654
   257
#ifdef DEBUG_CDROM
slouken@654
   258
  fprintf(stderr,"hdr.th_data_len1 = %d\n", hdr.th_data_len1);
slouken@654
   259
  fprintf(stderr,"hdr.th_data_len0 = %d\n", hdr.th_data_len0);
slouken@654
   260
  fprintf(stderr,"hdr.th_starting_track = %d\n", hdr.th_starting_track);
slouken@654
   261
  fprintf(stderr,"hdr.th_ending_track = %d\n", hdr.th_ending_track);
slouken@654
   262
  fprintf(stderr,"cdrom->numtracks = %d\n", cdrom->numtracks);
slouken@654
   263
#endif
slouken@654
   264
    toc.toc_address_format = CDROM_LBA_FORMAT;
slouken@654
   265
    toc.toc_starting_track = 0;
slouken@654
   266
    toc.toc_alloc_length = (hdr.th_data_len1 << 8) +
slouken@654
   267
			    hdr.th_data_len0 + sizeof(hdr);
slouken@654
   268
    if ( (toc.toc_buffer = alloca(toc.toc_alloc_length)) == NULL) {
slouken@654
   269
	fprintf(stderr,"cannot allocate toc.toc_buffer\n");
slouken@654
   270
	return -1;
slouken@654
   271
    }
slouken@654
   272
slouken@654
   273
    bzero (toc.toc_buffer, toc.toc_alloc_length);
slouken@654
   274
    if (ioctl(cdrom->id, CDROM_TOC_ENTRYS, &toc)) {
slouken@654
   275
	fprintf(stderr,"ioctl error CDROM_TOC_ENTRYS\n");
slouken@654
   276
	return -1;
slouken@654
   277
    }
slouken@654
   278
slouken@873
   279
    cdte =(struct cd_toc_entry *) ((char *) toc.toc_buffer + sizeof(hdr));
slouken@873
   280
    for (i=0; i <= cdrom->numtracks; ++i) {
slouken@873
   281
	if (i == cdrom->numtracks ) {
slouken@873
   282
	    cdrom->track[i].id = 0xAA;;
slouken@873
   283
	} else {
slouken@873
   284
	    cdrom->track[i].id = hdr.th_starting_track + i;
slouken@873
   285
	}
slouken@654
   286
slouken@873
   287
	cdrom->track[i].type =
slouken@873
   288
	    cdte[i].te_control & CDROM_DATA_TRACK;
slouken@873
   289
	cdrom->track[i].offset =
slouken@873
   290
	    cdte[i].te_absaddr.lba.addr3 << 24 |
slouken@873
   291
	    cdte[i].te_absaddr.lba.addr2 << 16 |
slouken@873
   292
	    cdte[i].te_absaddr.lba.addr1 << 8  |
slouken@873
   293
	    cdte[i].te_absaddr.lba.addr0;
slouken@873
   294
	cdrom->track[i].length = 0;
slouken@873
   295
	if ( i > 0 ) {
slouken@873
   296
	    cdrom->track[i - 1].length =
slouken@873
   297
		cdrom->track[i].offset -
slouken@873
   298
		cdrom->track[i - 1].offset;
slouken@654
   299
	}
slouken@873
   300
    }
slouken@654
   301
#ifdef DEBUG_CDROM
slouken@654
   302
  for (i = 0; i <= cdrom->numtracks; i++) {
slouken@654
   303
    fprintf(stderr,"toc_entry[%d].te_track_number = %d\n",
slouken@654
   304
	    i,cdte[i].te_track_number);
slouken@654
   305
    fprintf(stderr,"cdrom->track[%d].id = %d\n", i,cdrom->track[i].id);
slouken@654
   306
    fprintf(stderr,"cdrom->track[%d].type = %x\n", i,cdrom->track[i].type);
slouken@654
   307
    fprintf(stderr,"cdrom->track[%d].offset = %d\n", i,cdrom->track[i].offset);
slouken@654
   308
    fprintf(stderr,"cdrom->track[%d].length = %d\n", i,cdrom->track[i].length);
slouken@654
   309
  }
slouken@654
   310
#endif
slouken@654
   311
    if ( i == (cdrom->numtracks+1) ) {
slouken@654
   312
	okay = 1;
slouken@654
   313
    }
slouken@654
   314
slouken@654
   315
    return(okay ? 0 : -1);
slouken@654
   316
}
slouken@654
   317
slouken@654
   318
/* Get CD-ROM status */
slouken@654
   319
static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position)
slouken@654
   320
{
slouken@654
   321
    CDstatus                     status;
slouken@654
   322
    struct cd_sub_channel            sc;
slouken@654
   323
    struct cd_subc_channel_data     scd;
slouken@654
   324
slouken@654
   325
    sc.sch_address_format = CDROM_LBA_FORMAT;
slouken@654
   326
    sc.sch_data_format    = CDROM_CURRENT_POSITION;
slouken@654
   327
    sc.sch_track_number   = 0;
slouken@654
   328
    sc.sch_alloc_length   = sizeof(scd);
slouken@654
   329
    sc.sch_buffer         = (caddr_t)&scd;
slouken@654
   330
    if ( ioctl(cdrom->id, CDROM_READ_SUBCHANNEL, &sc) ) {
slouken@654
   331
	status = CD_ERROR;
slouken@654
   332
	fprintf(stderr,"ioctl error CDROM_READ_SUBCHANNEL \n");
slouken@654
   333
    } else {
slouken@654
   334
	switch (scd.scd_header.sh_audio_status) {
slouken@654
   335
	    case AS_AUDIO_INVALID:
slouken@654
   336
		status = CD_STOPPED;
slouken@654
   337
		break;
slouken@654
   338
	    case AS_PLAY_IN_PROGRESS:
slouken@654
   339
		status = CD_PLAYING;
slouken@654
   340
		break;
slouken@654
   341
	    case AS_PLAY_PAUSED:
slouken@654
   342
		status = CD_PAUSED;
slouken@654
   343
		break;
slouken@654
   344
	    case AS_PLAY_COMPLETED:
slouken@654
   345
		status = CD_STOPPED;
slouken@654
   346
		break;
slouken@654
   347
	    case AS_PLAY_ERROR:
slouken@654
   348
		status = CD_ERROR;
slouken@654
   349
		break;
slouken@654
   350
	    case AS_NO_STATUS:
slouken@654
   351
		status = CD_STOPPED;
slouken@654
   352
		break;
slouken@654
   353
	    default:
slouken@654
   354
		status = CD_ERROR;
slouken@654
   355
		break;
slouken@654
   356
	}
slouken@654
   357
#ifdef DEBUG_CDROM
slouken@654
   358
  fprintf(stderr,"scd.scd_header.sh_audio_status = %x\n",
slouken@654
   359
	scd.scd_header.sh_audio_status);
slouken@654
   360
#endif
slouken@654
   361
    }
slouken@654
   362
    if (position) {
slouken@654
   363
	if (status == CD_PLAYING || (status == CD_PAUSED) ) {
slouken@654
   364
	    *position =
slouken@654
   365
		scd.scd_position_data.scp_absaddr.lba.addr3 << 24 |
slouken@654
   366
		scd.scd_position_data.scp_absaddr.lba.addr2 << 16 |
slouken@654
   367
		scd.scd_position_data.scp_absaddr.lba.addr1 << 8  |
slouken@654
   368
		scd.scd_position_data.scp_absaddr.lba.addr0;
slouken@654
   369
	} else {
slouken@654
   370
	    *position = 0;
slouken@654
   371
	}
slouken@654
   372
    }
slouken@654
   373
slouken@654
   374
    return status;
slouken@654
   375
}
slouken@654
   376
slouken@654
   377
/* Start play */
slouken@654
   378
static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length)
slouken@654
   379
{
slouken@873
   380
/*
slouken@873
   381
 * Play MSF
slouken@654
   382
 */
slouken@654
   383
    struct cd_play_audio_msf msf;
slouken@654
   384
    int end;
slouken@654
   385
slouken@654
   386
    bzero(&msf, sizeof(msf));
slouken@654
   387
    end = start +length;
slouken@874
   388
    FRAMES_TO_MSF(start + 150, /* LBA = 4500*M + 75*S + F - 150 */
slouken@654
   389
		  &msf.msf_starting_M_unit,
slouken@654
   390
		  &msf.msf_starting_S_unit,
slouken@654
   391
		  &msf.msf_starting_F_unit);
slouken@874
   392
    FRAMES_TO_MSF(end + 150, /* LBA = 4500*M + 75*S + F - 150 */
slouken@654
   393
		  &msf.msf_ending_M_unit,
slouken@654
   394
		  &msf.msf_ending_S_unit,
slouken@654
   395
		  &msf.msf_ending_F_unit);
slouken@654
   396
slouken@654
   397
    return(ioctl(cdrom->id, CDROM_PLAY_AUDIO_MSF, &msf));
slouken@654
   398
}
slouken@654
   399
slouken@654
   400
/* Pause play */
slouken@654
   401
static int SDL_SYS_CDPause(SDL_CD *cdrom)
slouken@654
   402
{
slouken@654
   403
    return(ioctl(cdrom->id, CDROM_PAUSE_PLAY));
slouken@654
   404
}
slouken@654
   405
slouken@654
   406
/* Resume play */
slouken@654
   407
static int SDL_SYS_CDResume(SDL_CD *cdrom)
slouken@654
   408
{
slouken@654
   409
    return(ioctl(cdrom->id, CDROM_RESUME_PLAY));
slouken@654
   410
}
slouken@654
   411
slouken@654
   412
/* Stop play */
slouken@654
   413
static int SDL_SYS_CDStop(SDL_CD *cdrom)
slouken@654
   414
{
slouken@654
   415
    return(ioctl(cdrom->id, SCSI_STOP_UNIT));
slouken@654
   416
}
slouken@654
   417
slouken@654
   418
/* Eject the CD-ROM */
slouken@654
   419
static int SDL_SYS_CDEject(SDL_CD *cdrom)
slouken@654
   420
{
slouken@654
   421
    return(ioctl(cdrom->id, CDROM_EJECT_CADDY));
slouken@654
   422
}
slouken@654
   423
slouken@654
   424
/* Close the CD-ROM handle */
slouken@654
   425
static void SDL_SYS_CDClose(SDL_CD *cdrom)
slouken@654
   426
{
slouken@654
   427
    close(cdrom->id);
slouken@654
   428
}
slouken@654
   429
slouken@654
   430
void SDL_SYS_CDQuit(void)
slouken@654
   431
{
slouken@654
   432
    int i;
slouken@654
   433
slouken@654
   434
    if ( SDL_numcds > 0 ) {
slouken@654
   435
	for ( i=0; i<SDL_numcds; ++i ) {
slouken@1336
   436
	    SDL_free(SDL_cdlist[i]);
slouken@654
   437
	}
slouken@654
   438
	SDL_numcds = 0;
slouken@654
   439
    }
slouken@654
   440
}
slouken@654
   441
slouken@874
   442