2
* $Id: plat_news.c,v 1.8 2001/04/10 17:34:52 dfoerste Exp $
4
* This file is part of WorkMan, the civilized CD player library
5
* (c) 1991-1997 by Steven Grimm (original author)
6
* (c) by Dirk Fļæ½rsterling (current 'author' = maintainer)
7
* The maintainer can be contacted by his e-mail address:
8
* milliByte@DeathsDoor.com
10
* This library is free software; you can redistribute it and/or
11
* modify it under the terms of the GNU Library General Public
12
* License as published by the Free Software Foundation; either
13
* version 2 of the License, or (at your option) any later version.
15
* This library is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
* Library General Public License for more details.
20
* You should have received a copy of the GNU Library General Public
21
* License along with this library; if not, write to the Free
22
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
* Sony NEWS-specific drive control routines.
28
static char plat_news_id[] = "$Id: plat_news.c,v 1.8 2001/04/10 17:34:52 dfoerste Exp $";
30
#if defined( __sony_news) || defined(sony_news)
37
#include <sys/types.h>
38
#include <sys/param.h>
42
#include "include/wm_config.h"
43
#include "include/wm_struct.h"
44
#include "include/wm_cdtext.h"
46
#define WM_MSG_CLASS WM_MSG_CLASS_PLATFORM
51
extern char *cd_device;
52
extern int intermittent_dev;
58
* Initialize the drive. A no-op for the generic driver.
61
gen_init( struct wm_drive *d )
67
* Open the CD device and figure out what kind of drive is attached.
70
wmcd_open( struct wm_drive *d )
73
static int warned = 0;
74
char vendor[32] = WM_STR_GENVENDOR;
75
char model[32] = WM_STR_GENMODEL;
76
char rev[32] = WM_STR_GENREV;
78
if (d->fd >= 0) /* Device already open? */
80
wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "wmcd_open(): [device is open (fd=%d)]\n", d->fd);
85
if (cd_device == NULL)
86
cd_device = DEFAULT_CD_DEVICE;
88
if ((d->fd = CD_Open(cd_device, 0)) < 0)
90
/* Solaris 2.2 volume manager moves links around */
91
if (errno == ENOENT && intermittent_dev)
99
char realname[MAXPATHLEN];
101
if (realpath(cd_device, realname) == NULL)
110
else if (errno != EIO) /* defined at top */
115
/* No CD in drive. */
119
/* Now fill in the relevant parts of the wm_drive structure. */
122
/* Figure out the drive type, if possible */
123
wm_scsi_get_drive_type(d, vendor, model, rev);
124
*d = *(find_drive_struct(vendor, model, rev));
125
wm_drive_settype(vendor, model, rev);
135
* Close the CD device.
148
* Re-Open the device if it is open.
151
wmcd_reopen( struct wm_drive *d )
156
wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "wmcd_reopen\n");
157
if (d->fd >= 0) /* Device really open? */
159
wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "closing the device.\n");
160
status = wmcd_close( d->fd ); /* close it! */
161
/* we know, that the file is closed, do we? */
165
wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "calling wmcd_open()\n");
166
status = wmcd_open( d ); /* open it as usual */
168
} while ( status != 0 );
170
} /* wmcd_reopen() */
173
* Pass SCSI commands to the device.
176
wm_scsi(struct wm_drive *d, unsigned char *cdb, int cdblen,
177
unsigned char *buf, int buflen, int getreply)
179
/* NEWS can't do SCSI passthrough... or can it? */
185
* Get the current status of the drive: the current play mode, the absolute
186
* position from start of disc (in frames), and the current track and index
187
* numbers if the CD is playing or paused.
190
gen_get_drive_status( struct wm_drive *d, enum wm_cd_modes oldmode,
191
enum wm_cd_modes *mode, int *pos, int *track, int *index)
195
/* If we can't get status, the CD is ejected, so default to that. */
196
*mode = WM_CDM_EJECTED;
198
/* Is the device open? */
201
switch (wmcd_open(d)) {
210
/* Disc is ejected. Close the device. */
211
if (CD_GetStatus(d->fd, &sc))
227
if (oldmode == WM_CDM_PLAYING || oldmode == WM_CDM_PAUSED)
229
*mode = WM_CDM_PAUSED;
235
*mode = WM_CDM_STOPPED;
239
if (oldmode == WM_CDM_PLAYING)
241
*mode = WM_CDM_TRACK_DONE; /* waiting for next track. */
247
*mode = WM_CDM_STOPPED;
252
} /* gen_get_drive_status() */
255
* Get the number of tracks on the CD.
258
gen_get_trackcount(struct wm_drive *d, int *tracks)
260
struct CD_Capacity cc;
262
if (CD_GetCapacity(d->fd, &cc))
265
*tracks = cc.etrack - 1;
267
} /* gen_get_trackcount() */
270
* Get the start time and mode (data or audio) of a track.
273
gen_get_trackinfo( struct wm_drive *d, int track, int *data, int *startframe )
275
struct CD_TOCinfo hdr;
276
struct CD_TOCdata ent;
281
if (CD_ReadTOC(d->fd, &hdr))
284
*data = (ent.control & 4) ? 1 : 0;
285
*startframe = ent.baddr;
288
} /* gen_get_trackinfo */
291
* Get the number of frames on the CD.
294
gen_get_cdlen( struct wm_drive *d, int *frames )
298
if ((d->get_trackcount)(d, &tmp))
301
return (gen_get_trackinfo(d, tmp + 1, &tmp, frames));
302
} /* gen_get_cdlen() */
306
* Play the CD from one position to another (both in frames.)
309
gen_play( struct wm_drive *d, int start, int end )
311
struct CD_PlayAddr msf;
313
msf.addrmode = CD_MSF;
314
msf.addr.msf.startmsf.min = start / (60*75);
315
msf.addr.msf.startmsf.sec = (start % (60*75)) / 75;
316
msf.addr.msf.startmsf.frame = start % 75;
317
msf.addr.msf.endmsf.min = end / (60*75);
318
msf.addr.msf.endmsf.sec = (end % (60*75)) / 75;
319
msf.addr.msf.endmsf.frame = end % 75;
321
if (CD_Play(d->fd, &msf))
323
printf("wm_cd_play_chunk(%d,%d)\n",start,end);
324
printf("msf = %d:%d:%d %d:%d:%d\n",
325
msf.addr.msf.startmsf.min,
326
msf.addr.msf.startmsf.sec,
327
msf.addr.msf.startmsf.frame,
328
msf.addr.msf.endmsf.min,
329
msf.addr.msf.endmsf.sec,
330
msf.addr.msf.endmsf.frame);
342
gen_pause( struct wm_drive *d )
349
* Resume playing the CD (assuming it was paused.)
352
gen_resume( struct wm_drive *d )
362
gen_stop( struct wm_drive *d )
369
* Eject the current CD, if there is one.
372
gen_eject( struct wm_drive *d )
377
if (fstat(d->fd, &stbuf) != 0)
380
/* Is this a mounted filesystem? */
381
if (ustat(stbuf.st_rdev, &ust) == 0)
384
if (CD_AutoEject(d->fd))
387
/* Close the device if it needs to vanish. */
388
if (intermittent_dev)
397
/*----------------------------------------*
400
* Please edit and send changes to
401
* milliByte@DeathsDoor.com
402
*----------------------------------------*/
404
gen_closetray(struct wm_drive *d)
407
if(!wmcd_close(d->fd))
410
return(wmcd_reopen(d));
415
/* Always succeed if the drive can't close */
417
#endif /* CAN_CLOSE */
418
} /* gen_closetray() */
422
* Set the volume level for the left and right channels. Their values
423
* range from 0 to 100.
426
gen_set_volume( struct wm_drive *d, int left, int right)
428
/* NEWS can't adjust volume! */
433
* Read the initial volume from the drive, if available. Each channel
434
* ranges from 0 to 100, with -1 indicating data not available.
437
gen_get_volume( struct wm_drive *d, omt *left, int *right)
439
/* Suns, HPs, Linux, NEWS can't read the volume; oh well */
442
} /* gen_get_volume() */
444
/*------------------------------------------------------------------------*
445
* gen_get_cdtext(drive, buffer, lenght)
446
*------------------------------------------------------------------------*/
449
gen_get_cdtext(struct wm_drive *d, unsigned char **pp_buffer, int *p_buffer_lenght)
451
return -1; /* no SCSI, no CDTEXT */
452
} /* gen_get_cdtext() */