wmusic: Modernize autotools files
[dockapps.git] / ascd / libworkman / plat_aix.c
blobdeb37f9968829ff6dea36e8fdd4ba5263fb83c08
1 /*
2 * $Id: plat_aix.c,v 1.7 1999/03/07 08:36:40 dirk 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 * plat_aix - AIX 4.x IDE and SCSI support 16 Dec 1998
27 * AIX 4.x Port: Erik O'Shaughnessy
28 * Original AIX IDE Code: Cloyce Spradling (xmcd libdi_d/aixioc.c )
30 * Taken from the ascd distribution.
35 #ifdef AIXV3
37 static char plat_aix_id[] = "$Id: plat_aix.c,v 1.7 1999/03/07 08:36:40 dirk Exp $";
39 #include <stdio.h>
40 #include <errno.h>
41 #include <fcntl.h>
42 #include <sys/stat.h>
43 #include <sys/types.h>
44 #include <sys/cdrom.h>
45 #include <sys/devinfo.h>
46 #include <sys/scsi.h>
47 #include <sys/scdisk.h>
49 #include "include/wm_config.h"
50 #include "include/wm_struct.h"
52 #define WM_MSG_CLASS WM_MSG_CLASS_PLATFORM
54 #define LEADOUT 0xaa
56 extern char *cd_device;
58 int min_volume = 128;
59 int max_volume = 255;
63 /* NAME: gen_init
65 * FUNCTION:
67 * RETURNS:
70 int gen_init(struct wm_drive *d){
72 return 0;
75 /* NAME: gen_get_trackcount
77 * FUNCTION:
79 * RETURNS:
82 int gen_get_trackcount(struct wm_drive *d,int *tracks){
83 struct cd_audio_cmd cmd;
85 cmd.audio_cmds = CD_TRK_INFO_AUDIO;
86 cmd.msf_flag = 0;
88 if( ioctl(d->fd,DKAUDIO,&cmd) < 0){
89 perror("DKAUDIO");
90 return -1;
93 *tracks = cmd.indexing.track_index.last_track;
95 return 0;
99 /* NAME: gen_get_cdlen
101 * FUNCTION:
103 * RETURNS:
106 int gen_get_cdlen(struct wm_drive *d,int *frames){
107 int tmp;
109 return gen_get_trackinfo(d,LEADOUT,&tmp,frames);
112 /* NAME: gen_get_trackinfo
114 * FUNCTION:
116 * RETURNS:
119 int gen_get_trackinfo(struct wm_drive *d,int track,int *data,int *startframe){
120 struct cd_audio_cmd cmd;
122 cmd.audio_cmds = CD_GET_TRK_MSF;
123 cmd.msf_flag = 1;
125 cmd.indexing.track_msf.track = track;
127 if( ioctl(d->fd,DKAUDIO,&cmd) < 0)
128 return -1;
130 *startframe = cmd.indexing.track_msf.mins * 60 * 75 +
131 cmd.indexing.track_msf.secs * 75 +
132 cmd.indexing.track_msf.frames;
134 *data = 0;
136 return 0;
139 /* NAME: gen_get_drive_status
141 * FUNCTION:
143 * RETURNS:
146 int gen_get_drive_status(struct wm_drive *d,
147 enum wm_cd_modes oldmode,
148 enum wm_cd_modes *mode,
149 int *pos,
150 int *track,
151 int *index){
152 struct cd_audio_cmd cmd;
154 *mode = WM_CDM_EJECTED;
156 if(d->fd < 0)
157 switch( wmcd_open(d) ){
158 case -1:
159 return -1;
160 case 1:
161 return 0;
164 cmd.audio_cmds = CD_INFO_AUDIO;
165 if( ioctl(d->fd,DKAUDIO,&cmd) < 0)
166 return -1;
168 switch(cmd.status){
169 case CD_PLAY_AUDIO:
170 *mode = WM_CDM_PLAYING;
171 *track = cmd.indexing.info_audio.current_track;
172 *index = cmd.indexing.info_audio.current_index;
173 *pos = cmd.indexing.info_audio.current_mins * 60 * 75 +
174 cmd.indexing.info_audio.current_secs * 75 +
175 cmd.indexing.info_audio.current_frames;
176 break;
178 case CD_PAUSE_AUDIO:
179 *mode = WM_CDM_PAUSED;
180 *track = cmd.indexing.info_audio.current_track;
181 *index = cmd.indexing.info_audio.current_index;
182 *pos = cmd.indexing.info_audio.current_mins * 60 * 75 +
183 cmd.indexing.info_audio.current_secs * 75 +
184 cmd.indexing.info_audio.current_frames;
186 break;
187 case CD_NO_AUDIO: /* no play audio in progress */
188 case CD_COMPLETED: /* play operation completed successfully */
189 case CD_STATUS_ERROR: /* invalid status or play stopped due to err */
190 case CD_NOT_VALID: /* audio status is invalid or not supported */
191 *mode = WM_CDM_STOPPED;
192 break;
193 default:
194 *mode = WM_CDM_UNKNOWN;
195 break;
198 return 0;
202 int scale_volume(int vol,int max){
203 return ((vol * (max_volume - min_volume)) / max + min_volume);
206 int unscale_volume(int vol,int max){
207 int n;
208 n = ( vol - min_volume ) * max_volume / (max - min_volume);
209 return (n <0)?0:n;
212 /* NAME: gen_get_volume
214 * FUNCTION:
216 * RETURNS:
219 int gen_get_volume(struct wm_drive *d,int *left,int *right){
220 struct cd_audio_cmd cmd;
221 int l,r;
223 fprintf(stderr,"gen_get_volume\n");
225 cmd.audio_cmds = CD_INFO_AUDIO;
226 if( ioctl(d->fd,DKAUDIO,&cmd) < 0)
227 return -1;
229 *left = unscale_volume(cmd.out_port_0_vol,100);
230 *right = unscale_volume(cmd.out_port_1_vol,100);
232 return 0;
235 /* NAME: gen_set_volume
237 * FUNCTION:
239 * RETURNS:
242 int gen_set_volume(struct wm_drive *d,int left,int right){
243 struct cd_audio_cmd cmd;
245 cmd.audio_cmds = CD_SET_VOLUME;
246 cmd.volume_type = CD_VOLUME_CHNLS;
248 cmd.out_port_0_vol = scale_volume(left,100);
249 cmd.out_port_1_vol = scale_volume(right,100);
251 if( ioctl(d->fd,DKAUDIO,&cmd) < 0){
252 perror("CD_SET_VOLUME");
253 return -1;
256 return 0;
259 /* NAME: gen_pause
261 * FUNCTION:
263 * RETURNS:
266 int gen_pause(struct wm_drive *d){
267 struct cd_audio_cmd cmd;
269 cmd.audio_cmds = CD_PAUSE_AUDIO;
271 return ioctl(d->fd,DKAUDIO,&cmd);
274 /* NAME: gen_resume
276 * FUNCTION:
278 * RETURNS:
281 int gen_resume(struct wm_drive *d){
282 struct cd_audio_cmd cmd;
284 cmd.audio_cmds = CD_RESUME_AUDIO;
285 return ioctl(d->fd,DKAUDIO,&cmd);
288 /* NAME: gen_stop
290 * FUNCTION:
292 * RETURNS:
295 int gen_stop(struct wm_drive *d){
296 struct cd_audio_cmd cmd;
298 cmd.audio_cmds = CD_STOP_AUDIO;
299 return ioctl(d->fd,DKAUDIO,&cmd);
302 /* NAME: gen_play
304 * FUNCTION:
306 * RETURNS:
309 int gen_play(struct wm_drive *d,int start,int end){
310 struct cd_audio_cmd cmd;
312 cmd.audio_cmds = CD_PLAY_AUDIO;
313 cmd.msf_flag = 1;
315 cmd.indexing.msf.first_mins = start / (60*75);
316 cmd.indexing.msf.first_secs = (start % (60*75)) / 75;
317 cmd.indexing.msf.first_frames = start % 75;
319 cmd.indexing.msf.last_mins = end / (60*75);
320 cmd.indexing.msf.last_secs = (end % (60*75)) / 75;
321 cmd.indexing.msf.last_frames = end % 75;
323 if( ioctl(d->fd,DKAUDIO,&cmd) < 0){
324 perror("DKAUDIO:CD_PLAY_AUDIO");
325 return -1;
328 return 0;
331 /* NAME: gen_eject
333 * FUNCTION:
335 * RETURNS:
338 int gen_eject(struct wm_drive *d){
340 return ioctl(d->fd,DKEJECT,NULL);
344 /*----------------------------------------*
345 * Close the CD tray
346 *----------------------------------------*/
347 int gen_closetray(struct wm_drive *d)
349 #ifdef CAN_CLOSE
350 if(!close(d->fd))
352 d->fd=-1;
353 return(wmcd_reopen(d));
354 } else {
355 return(-1);
357 #else
358 /* Always succeed if the drive can't close */
359 return(0);
360 #endif /* CAN_CLOSE */
361 } /* gen_closetray() */
364 /* NAME: wm_scsi
366 * FUNCTION:
368 * RETURNS:
373 int wm_scsi(struct wm_drive *d,
374 uchar_t *cdb, int cdblen,void *retbuf,int retbuflen,int getreply){
375 return 0;
379 /* NAME: wmcd_open
381 * FUNCTION:
383 * RETURNS:
386 int wmcd_open(struct wm_drive *d){
387 char vendor[32] = WM_STR_GENVENDOR;
388 char model[32] = WM_STR_GENMODEL;
389 char rev[32] = WM_STR_GENREV;
391 int fd;
393 if( ! d ){
394 errno = EFAULT;
395 return -1;
398 if(d->fd > -1) /* device already open? */
399 return 0;
401 if( cd_device == (char *)NULL )
402 cd_device = DEFAULT_CD_DEVICE;
404 if( (fd=openx(cd_device,O_RDONLY,NULL,SC_SINGLE)) < 0 ){
405 perror("openx");
406 return 1;
409 *d = *(find_drive_struct(vendor, model, rev));
410 wm_drive_settype(vendor, model, rev);
412 d->fd = fd;
413 d->init(d);
415 return 0;
416 } /* wmcd_open() */
419 * Re-Open the device if it is open.
422 wmcd_reopen( struct wm_drive *d )
424 int status;
426 do {
427 wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "wmcd_reopen ");
428 if (d->fd >= 0) /* Device really open? */
430 wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "closes the device and ");
431 status = close( d->fd ); /* close it! */
432 /* we know, that the file is closed, do we? */
433 d->fd = -1;
435 wm_susleep( 1000 );
436 wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "calls wmcd_open()\n");
437 status = wmcd_open( d ); /* open it as usual */
438 wm_susleep( 1000 );
439 } while ( status != 0 );
440 return status;
441 } /* wmcd_reopen() */
443 #endif /* _AIX */