~ubuntu-branches/ubuntu/quantal/libkcompactdisc/quantal-updates

« back to all changes in this revision

Viewing changes to wmlib/plat_aix.c

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2012-05-26 15:25:35 UTC
  • Revision ID: package-import@ubuntu.com-20120526152535-60v997qsp1solymv
Tags: upstream-4.8.80a
Import upstream version 4.8.80a

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of WorkMan, the civilized CD player library
 
3
 * Copyright (C) 1991-1997 by Steven Grimm <koreth@midwinter.com>
 
4
 * Copyright (C) by Dirk Försterling <milliByte@DeathsDoor.com>
 
5
 *
 
6
 * This library is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU Library General Public
 
8
 * License as published by the Free Software Foundation; either
 
9
 * version 2 of the License, or (at your option) any later version.
 
10
 *
 
11
 * This library is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
 * Library General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU Library General Public
 
17
 * License along with this library; if not, write to the Free
 
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
19
 *
 
20
 *
 
21
 * plat_aix - AIX 4.x IDE and SCSI support  16 Dec 1998
 
22
 *
 
23
 * AIX 4.x Port: Erik O'Shaughnessy
 
24
 * Original AIX IDE Code: Cloyce Spradling (xmcd libdi_d/aixioc.c )
 
25
 *
 
26
 * Taken from the ascd distribution.
 
27
 *
 
28
 */
 
29
 
 
30
#if defined(AIXV3) || defined(__AIXV3)
 
31
 
 
32
#include <stdio.h>
 
33
#include <errno.h>
 
34
#include <fcntl.h>
 
35
#include <sys/stat.h>
 
36
#include <sys/types.h>
 
37
#include <sys/cdrom.h>
 
38
#include <sys/devinfo.h>
 
39
#include <sys/scsi.h>
 
40
#include <sys/scdisk.h>
 
41
 
 
42
#include "include/wm_config.h"
 
43
#include "include/wm_struct.h"
 
44
#include "include/wm_cdtext.h"
 
45
 
 
46
#define WM_MSG_CLASS WM_MSG_CLASS_PLATFORM
 
47
 
 
48
#define LEADOUT 0xaa
 
49
 
 
50
int min_volume = 128;
 
51
int max_volume = 255;
 
52
 
 
53
 
 
54
 
 
55
/* NAME: gen_init
 
56
 *
 
57
 * FUNCTION:
 
58
 *
 
59
 * RETURNS:
 
60
 */
 
61
int
 
62
gen_init(struct wm_drive *d)
 
63
{
 
64
  return 0;
 
65
} /* gen_init() */
 
66
 
 
67
 
 
68
/* NAME: gen_open
 
69
 *
 
70
 * FUNCTION:
 
71
 *
 
72
 * RETURNS:
 
73
 */
 
74
int
 
75
gen_open(struct wm_drive *d)
 
76
{
 
77
  int fd;
 
78
 
 
79
  if( ! d )
 
80
    {
 
81
      errno = EFAULT;
 
82
      return -1;
 
83
    }
 
84
 
 
85
  if(d->fd > -1)                        /* device already open? */
 
86
    {
 
87
      wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "gen_open(): [device is open (fd=%d)]\n", d->fd);
 
88
      return 0;
 
89
    }
 
90
 
 
91
  if( (fd = openx(d->cd_device,O_RDONLY,NULL,SC_SINGLE)) < 0 )
 
92
    {
 
93
      perror("openx");
 
94
      return -6;
 
95
      /* return 1 */
 
96
    }
 
97
 
 
98
  d->fd = fd;
 
99
 
 
100
  return 0;
 
101
}
 
102
 
 
103
/* NAME: gen_scsi
 
104
 *
 
105
 * FUNCTION:
 
106
 *
 
107
 * RETURNS:
 
108
 */
 
109
int
 
110
gen_scsi(struct wm_drive *d,
 
111
    uchar_t *cdb, int cdblen,
 
112
    void *retbuf, int retbuflen,
 
113
    int getreply)
 
114
{
 
115
  return -1;
 
116
} /* gen_scsi() */
 
117
 
 
118
int
 
119
gen_close( struct wm_drive *d )
 
120
{
 
121
  if(d->fd != -1) {
 
122
    wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "closing the device\n");
 
123
    close(d->fd);
 
124
    d->fd = -1;
 
125
  }
 
126
  return 0;
 
127
}
 
128
 
 
129
/* NAME: gen_get_drive_status
 
130
 *
 
131
 * FUNCTION:
 
132
 *
 
133
 * RETURNS:
 
134
 */
 
135
int
 
136
gen_get_drive_status(struct wm_drive *d,
 
137
    int oldmode,
 
138
    int *mode,
 
139
    int *pos,
 
140
    int *track,
 
141
    int *index)
 
142
{
 
143
  struct cd_audio_cmd cmd;
 
144
 
 
145
  *mode = WM_CDM_EJECTED;
 
146
 
 
147
  if(d->fd < 0)
 
148
    switch(d->proto.open(d))
 
149
      {
 
150
      case -1:
 
151
        return -1;
 
152
      case 1:
 
153
        return 0;
 
154
      }
 
155
 
 
156
  cmd.audio_cmds = CD_INFO_AUDIO;
 
157
 
 
158
  if( ioctl(d->fd,DKAUDIO,&cmd) < 0)
 
159
    return -1;
 
160
 
 
161
  switch(cmd.status)
 
162
    {
 
163
    case CD_PLAY_AUDIO:
 
164
      *mode = WM_CDM_PLAYING;
 
165
      *track = cmd.indexing.info_audio.current_track;
 
166
      *index = cmd.indexing.info_audio.current_index;
 
167
      *pos = cmd.indexing.info_audio.current_mins * 60 * 75 +
 
168
        cmd.indexing.info_audio.current_secs * 75 +
 
169
        cmd.indexing.info_audio.current_frames;
 
170
      break;
 
171
 
 
172
    case CD_PAUSE_AUDIO:
 
173
      *mode = WM_CDM_PAUSED;
 
174
      *track = cmd.indexing.info_audio.current_track;
 
175
      *index = cmd.indexing.info_audio.current_index;
 
176
      *pos = cmd.indexing.info_audio.current_mins * 60 * 75 +
 
177
        cmd.indexing.info_audio.current_secs * 75 +
 
178
        cmd.indexing.info_audio.current_frames;
 
179
 
 
180
      break;
 
181
    case CD_NO_AUDIO:           /* no play audio in progress */
 
182
    case CD_COMPLETED:          /* play operation completed successfully */
 
183
    case CD_STATUS_ERROR:       /* invalid status or play stopped due to err */
 
184
    case CD_NOT_VALID:          /* audio status is invalid or not supported */
 
185
      *mode = WM_CDM_STOPPED;
 
186
      break;
 
187
    default:
 
188
      *mode = WM_CDM_UNKNOWN;
 
189
      break;
 
190
    }
 
191
 
 
192
  return 0;
 
193
} /* gen_get_drive_status() */
 
194
 
 
195
 
 
196
 
 
197
/* NAME: gen_get_trackcount
 
198
 *
 
199
 * FUNCTION:
 
200
 *
 
201
 * RETURNS:
 
202
 */
 
203
int
 
204
gen_get_trackcount(struct wm_drive *d,int *tracks)
 
205
{
 
206
  struct cd_audio_cmd cmd;
 
207
 
 
208
  cmd.audio_cmds = CD_TRK_INFO_AUDIO;
 
209
  cmd.msf_flag = 0;
 
210
 
 
211
  if( ioctl(d->fd,DKAUDIO,&cmd) < 0)
 
212
    {
 
213
      perror("DKAUDIO");
 
214
      return -1;
 
215
    }
 
216
 
 
217
  *tracks = cmd.indexing.track_index.last_track;
 
218
 
 
219
  return 0;
 
220
} /* gen_get_trackcount() */
 
221
 
 
222
/* NAME: gen_get_trackinfo
 
223
 *
 
224
 * FUNCTION:
 
225
 *
 
226
 * RETURNS:
 
227
 */
 
228
int
 
229
gen_get_trackinfo(struct wm_drive *d,int track,int *data,int *startframe)
 
230
{
 
231
  struct cd_audio_cmd cmd;
 
232
 
 
233
  cmd.audio_cmds = CD_GET_TRK_MSF;
 
234
  cmd.msf_flag = 1;
 
235
 
 
236
  cmd.indexing.track_msf.track = track;
 
237
 
 
238
  if( ioctl(d->fd,DKAUDIO,&cmd) < 0)
 
239
    return -1;
 
240
 
 
241
  *startframe = cmd.indexing.track_msf.mins * 60 * 75 +
 
242
    cmd.indexing.track_msf.secs * 75 +
 
243
    cmd.indexing.track_msf.frames;
 
244
 
 
245
  *data = 0;
 
246
 
 
247
  return 0;
 
248
} /* gen_get_trackinfo() */
 
249
 
 
250
/* NAME: gen_get_cdlen
 
251
 *
 
252
 * FUNCTION:
 
253
 *
 
254
 * RETURNS:
 
255
 */
 
256
int
 
257
gen_get_cdlen(struct wm_drive *d,int *frames)
 
258
{
 
259
  int tmp;
 
260
 
 
261
  return gen_get_trackinfo(d,LEADOUT,&tmp,frames);
 
262
} /* gen_get_cdlen() */
 
263
 
 
264
 
 
265
/* NAME: gen_play
 
266
 *
 
267
 * FUNCTION:
 
268
 *
 
269
 * RETURNS:
 
270
 */
 
271
int
 
272
gen_play(struct wm_drive *d,int start,int end)
 
273
{
 
274
  struct cd_audio_cmd cmd;
 
275
 
 
276
  cmd.audio_cmds = CD_PLAY_AUDIO;
 
277
  cmd.msf_flag = 1;
 
278
 
 
279
  cmd.indexing.msf.first_mins = start / (60*75);
 
280
  cmd.indexing.msf.first_secs = (start % (60*75)) / 75;
 
281
  cmd.indexing.msf.first_frames = start % 75;
 
282
 
 
283
  cmd.indexing.msf.last_mins = end / (60*75);
 
284
  cmd.indexing.msf.last_secs = (end % (60*75)) / 75;
 
285
  cmd.indexing.msf.last_frames = end % 75;
 
286
 
 
287
  if( ioctl(d->fd,DKAUDIO,&cmd) < 0)
 
288
    {
 
289
      perror("DKAUDIO:CD_PLAY_AUDIO");
 
290
      return -1;
 
291
    }
 
292
  return 0;
 
293
} /* gen_play() */
 
294
 
 
295
/* NAME: gen_pause
 
296
 *
 
297
 * FUNCTION:
 
298
 *
 
299
 * RETURNS:
 
300
 */
 
301
int
 
302
gen_pause(struct wm_drive *d)
 
303
{
 
304
  struct cd_audio_cmd cmd;
 
305
 
 
306
  cmd.audio_cmds = CD_PAUSE_AUDIO;
 
307
 
 
308
  return ioctl(d->fd,DKAUDIO,&cmd);
 
309
} /* gen_pause() */
 
310
 
 
311
 
 
312
/* NAME: gen_resume
 
313
 *
 
314
 * FUNCTION:
 
315
 *
 
316
 * RETURNS:
 
317
 */
 
318
int
 
319
gen_resume(struct wm_drive *d)
 
320
{
 
321
  struct cd_audio_cmd cmd;
 
322
 
 
323
  cmd.audio_cmds = CD_RESUME_AUDIO;
 
324
  return ioctl(d->fd,DKAUDIO,&cmd);
 
325
} /* gen_resume() */
 
326
 
 
327
/* NAME: gen_stop
 
328
 *
 
329
 * FUNCTION:
 
330
 *
 
331
 * RETURNS:
 
332
 */
 
333
int
 
334
gen_stop(struct wm_drive *d)
 
335
{
 
336
  struct cd_audio_cmd cmd;
 
337
 
 
338
  cmd.audio_cmds = CD_STOP_AUDIO;
 
339
  return ioctl(d->fd,DKAUDIO,&cmd);
 
340
} /* gen_stop() */
 
341
 
 
342
/* NAME: gen_eject
 
343
 *
 
344
 * FUNCTION:
 
345
 *
 
346
 * RETURNS:
 
347
 */
 
348
int
 
349
gen_eject(struct wm_drive *d)
 
350
{
 
351
  return ioctl(d->fd,DKEJECT,NULL);
 
352
}
 
353
 
 
354
/*----------------------------------------*
 
355
 * Close the CD tray
 
356
 *----------------------------------------*/
 
357
int
 
358
gen_closetray(struct wm_drive *d)
 
359
{
 
360
  return -1;
 
361
} /* gen_closetray() */
 
362
 
 
363
 
 
364
int
 
365
scale_volume(int vol,int max)
 
366
{
 
367
  return ((vol * (max_volume - min_volume)) / max + min_volume);
 
368
}
 
369
 
 
370
int
 
371
unscale_volume(int vol,int max)
 
372
{
 
373
  int n;
 
374
  n = ( vol - min_volume ) * max_volume / (max - min_volume);
 
375
  return (n <0)?0:n;
 
376
}
 
377
 
 
378
/* NAME: gen_set_volume
 
379
 *
 
380
 * FUNCTION:
 
381
 *
 
382
 * RETURNS:
 
383
 */
 
384
int
 
385
gen_set_volume(struct wm_drive *d,int left,int right)
 
386
{
 
387
  struct cd_audio_cmd cmd;
 
388
 
 
389
  cmd.audio_cmds = CD_SET_VOLUME;
 
390
  cmd.volume_type = CD_VOLUME_CHNLS;
 
391
 
 
392
  cmd.out_port_0_vol = scale_volume(left,100);
 
393
  cmd.out_port_1_vol = scale_volume(right,100);
 
394
 
 
395
  if( ioctl(d->fd,DKAUDIO,&cmd) < 0)
 
396
    {
 
397
      perror("CD_SET_VOLUME");
 
398
      return -1;
 
399
    }
 
400
 
 
401
  return 0;
 
402
} /* gen_set_volume() */
 
403
 
 
404
/* NAME: gen_get_volume
 
405
 *
 
406
 * FUNCTION:
 
407
 *
 
408
 * RETURNS:
 
409
 */
 
410
int
 
411
gen_get_volume(struct wm_drive *d,int *left,int *right)
 
412
{
 
413
  struct cd_audio_cmd cmd;
 
414
  int l,r;
 
415
 
 
416
  fprintf(stderr,"gen_get_volume\n");
 
417
 
 
418
  cmd.audio_cmds = CD_INFO_AUDIO;
 
419
  if( ioctl(d->fd,DKAUDIO,&cmd) < 0)
 
420
    return -1;
 
421
 
 
422
  *left = unscale_volume(cmd.out_port_0_vol,100);
 
423
  *right = unscale_volume(cmd.out_port_1_vol,100);
 
424
 
 
425
  return 0;
 
426
} /* gen_get_volume() */
 
427
 
 
428
#endif /* _AIX */
 
429
 
 
430
 
 
431
 
 
432
 
 
433