File indexing completed on 2024-04-21 04:54:22
0001 /* 0002 * This file is part of WorkMan, the civilized CD player library 0003 * Copyright (C) 1991-1997 by Steven Grimm <koreth@midwinter.com> 0004 * Copyright (C) by Dirk Försterling <milliByte@DeathsDoor.com> 0005 * 0006 * This library is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU Library General Public 0008 * License as published by the Free Software Foundation; either 0009 * version 2 of the License, or (at your option) any later version. 0010 * 0011 * This library is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 * Library General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU Library General Public 0017 * License along with this library; if not, write to the Free 0018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 0019 * 0020 * 0021 * plat_aix - AIX 4.x IDE and SCSI support 16 Dec 1998 0022 * 0023 * AIX 4.x Port: Erik O'Shaughnessy 0024 * Original AIX IDE Code: Cloyce Spradling (xmcd libdi_d/aixioc.c ) 0025 * 0026 * Taken from the ascd distribution. 0027 * 0028 */ 0029 0030 #if defined(AIXV3) || defined(__AIXV3) 0031 0032 #include <stdio.h> 0033 #include <errno.h> 0034 #include <fcntl.h> 0035 #include <sys/stat.h> 0036 #include <sys/types.h> 0037 #include <sys/cdrom.h> 0038 #include <sys/devinfo.h> 0039 #include <sys/scsi.h> 0040 #include <sys/scdisk.h> 0041 0042 #include "include/wm_config.h" 0043 #include "include/wm_struct.h" 0044 #include "include/wm_cdtext.h" 0045 0046 #define WM_MSG_CLASS WM_MSG_CLASS_PLATFORM 0047 0048 #define LEADOUT 0xaa 0049 0050 int min_volume = 128; 0051 int max_volume = 255; 0052 0053 0054 0055 /* NAME: gen_init 0056 * 0057 * FUNCTION: 0058 * 0059 * RETURNS: 0060 */ 0061 int 0062 gen_init(struct wm_drive *d) 0063 { 0064 return 0; 0065 } /* gen_init() */ 0066 0067 0068 /* NAME: gen_open 0069 * 0070 * FUNCTION: 0071 * 0072 * RETURNS: 0073 */ 0074 int 0075 gen_open(struct wm_drive *d) 0076 { 0077 int fd; 0078 0079 if( ! d ) 0080 { 0081 errno = EFAULT; 0082 return -1; 0083 } 0084 0085 if(d->fd > -1) /* device already open? */ 0086 { 0087 wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "gen_open(): [device is open (fd=%d)]\n", d->fd); 0088 return 0; 0089 } 0090 0091 if( (fd = openx(d->cd_device,O_RDONLY,NULL,SC_SINGLE)) < 0 ) 0092 { 0093 perror("openx"); 0094 return -6; 0095 /* return 1 */ 0096 } 0097 0098 d->fd = fd; 0099 0100 return 0; 0101 } 0102 0103 /* NAME: gen_scsi 0104 * 0105 * FUNCTION: 0106 * 0107 * RETURNS: 0108 */ 0109 int 0110 gen_scsi(struct wm_drive *d, 0111 uchar_t *cdb, int cdblen, 0112 void *retbuf, int retbuflen, 0113 int getreply) 0114 { 0115 return -1; 0116 } /* gen_scsi() */ 0117 0118 int 0119 gen_close( struct wm_drive *d ) 0120 { 0121 if(d->fd != -1) { 0122 wm_lib_message(WM_MSG_LEVEL_DEBUG|WM_MSG_CLASS, "closing the device\n"); 0123 close(d->fd); 0124 d->fd = -1; 0125 } 0126 return 0; 0127 } 0128 0129 /* NAME: gen_get_drive_status 0130 * 0131 * FUNCTION: 0132 * 0133 * RETURNS: 0134 */ 0135 int 0136 gen_get_drive_status(struct wm_drive *d, 0137 int oldmode, 0138 int *mode, 0139 int *pos, 0140 int *track, 0141 int *index) 0142 { 0143 struct cd_audio_cmd cmd; 0144 0145 *mode = WM_CDM_EJECTED; 0146 0147 if(d->fd < 0) 0148 switch(d->proto.open(d)) 0149 { 0150 case -1: 0151 return -1; 0152 case 1: 0153 return 0; 0154 } 0155 0156 cmd.audio_cmds = CD_INFO_AUDIO; 0157 0158 if( ioctl(d->fd,DKAUDIO,&cmd) < 0) 0159 return -1; 0160 0161 switch(cmd.status) 0162 { 0163 case CD_PLAY_AUDIO: 0164 *mode = WM_CDM_PLAYING; 0165 *track = cmd.indexing.info_audio.current_track; 0166 *index = cmd.indexing.info_audio.current_index; 0167 *pos = cmd.indexing.info_audio.current_mins * 60 * 75 + 0168 cmd.indexing.info_audio.current_secs * 75 + 0169 cmd.indexing.info_audio.current_frames; 0170 break; 0171 0172 case CD_PAUSE_AUDIO: 0173 *mode = WM_CDM_PAUSED; 0174 *track = cmd.indexing.info_audio.current_track; 0175 *index = cmd.indexing.info_audio.current_index; 0176 *pos = cmd.indexing.info_audio.current_mins * 60 * 75 + 0177 cmd.indexing.info_audio.current_secs * 75 + 0178 cmd.indexing.info_audio.current_frames; 0179 0180 break; 0181 case CD_NO_AUDIO: /* no play audio in progress */ 0182 case CD_COMPLETED: /* play operation completed successfully */ 0183 case CD_STATUS_ERROR: /* invalid status or play stopped due to err */ 0184 case CD_NOT_VALID: /* audio status is invalid or not supported */ 0185 *mode = WM_CDM_STOPPED; 0186 break; 0187 default: 0188 *mode = WM_CDM_UNKNOWN; 0189 break; 0190 } 0191 0192 return 0; 0193 } /* gen_get_drive_status() */ 0194 0195 0196 0197 /* NAME: gen_get_trackcount 0198 * 0199 * FUNCTION: 0200 * 0201 * RETURNS: 0202 */ 0203 int 0204 gen_get_trackcount(struct wm_drive *d,int *tracks) 0205 { 0206 struct cd_audio_cmd cmd; 0207 0208 cmd.audio_cmds = CD_TRK_INFO_AUDIO; 0209 cmd.msf_flag = 0; 0210 0211 if( ioctl(d->fd,DKAUDIO,&cmd) < 0) 0212 { 0213 perror("DKAUDIO"); 0214 return -1; 0215 } 0216 0217 *tracks = cmd.indexing.track_index.last_track; 0218 0219 return 0; 0220 } /* gen_get_trackcount() */ 0221 0222 /* NAME: gen_get_trackinfo 0223 * 0224 * FUNCTION: 0225 * 0226 * RETURNS: 0227 */ 0228 int 0229 gen_get_trackinfo(struct wm_drive *d,int track,int *data,int *startframe) 0230 { 0231 struct cd_audio_cmd cmd; 0232 0233 cmd.audio_cmds = CD_GET_TRK_MSF; 0234 cmd.msf_flag = 1; 0235 0236 cmd.indexing.track_msf.track = track; 0237 0238 if( ioctl(d->fd,DKAUDIO,&cmd) < 0) 0239 return -1; 0240 0241 *startframe = cmd.indexing.track_msf.mins * 60 * 75 + 0242 cmd.indexing.track_msf.secs * 75 + 0243 cmd.indexing.track_msf.frames; 0244 0245 *data = 0; 0246 0247 return 0; 0248 } /* gen_get_trackinfo() */ 0249 0250 /* NAME: gen_get_cdlen 0251 * 0252 * FUNCTION: 0253 * 0254 * RETURNS: 0255 */ 0256 int 0257 gen_get_cdlen(struct wm_drive *d,int *frames) 0258 { 0259 int tmp; 0260 0261 return gen_get_trackinfo(d,LEADOUT,&tmp,frames); 0262 } /* gen_get_cdlen() */ 0263 0264 0265 /* NAME: gen_play 0266 * 0267 * FUNCTION: 0268 * 0269 * RETURNS: 0270 */ 0271 int 0272 gen_play(struct wm_drive *d,int start,int end) 0273 { 0274 struct cd_audio_cmd cmd; 0275 0276 cmd.audio_cmds = CD_PLAY_AUDIO; 0277 cmd.msf_flag = 1; 0278 0279 cmd.indexing.msf.first_mins = start / (60*75); 0280 cmd.indexing.msf.first_secs = (start % (60*75)) / 75; 0281 cmd.indexing.msf.first_frames = start % 75; 0282 0283 cmd.indexing.msf.last_mins = end / (60*75); 0284 cmd.indexing.msf.last_secs = (end % (60*75)) / 75; 0285 cmd.indexing.msf.last_frames = end % 75; 0286 0287 if( ioctl(d->fd,DKAUDIO,&cmd) < 0) 0288 { 0289 perror("DKAUDIO:CD_PLAY_AUDIO"); 0290 return -1; 0291 } 0292 return 0; 0293 } /* gen_play() */ 0294 0295 /* NAME: gen_pause 0296 * 0297 * FUNCTION: 0298 * 0299 * RETURNS: 0300 */ 0301 int 0302 gen_pause(struct wm_drive *d) 0303 { 0304 struct cd_audio_cmd cmd; 0305 0306 cmd.audio_cmds = CD_PAUSE_AUDIO; 0307 0308 return ioctl(d->fd,DKAUDIO,&cmd); 0309 } /* gen_pause() */ 0310 0311 0312 /* NAME: gen_resume 0313 * 0314 * FUNCTION: 0315 * 0316 * RETURNS: 0317 */ 0318 int 0319 gen_resume(struct wm_drive *d) 0320 { 0321 struct cd_audio_cmd cmd; 0322 0323 cmd.audio_cmds = CD_RESUME_AUDIO; 0324 return ioctl(d->fd,DKAUDIO,&cmd); 0325 } /* gen_resume() */ 0326 0327 /* NAME: gen_stop 0328 * 0329 * FUNCTION: 0330 * 0331 * RETURNS: 0332 */ 0333 int 0334 gen_stop(struct wm_drive *d) 0335 { 0336 struct cd_audio_cmd cmd; 0337 0338 cmd.audio_cmds = CD_STOP_AUDIO; 0339 return ioctl(d->fd,DKAUDIO,&cmd); 0340 } /* gen_stop() */ 0341 0342 /* NAME: gen_eject 0343 * 0344 * FUNCTION: 0345 * 0346 * RETURNS: 0347 */ 0348 int 0349 gen_eject(struct wm_drive *d) 0350 { 0351 return ioctl(d->fd,DKEJECT,NULL); 0352 } 0353 0354 /*----------------------------------------* 0355 * Close the CD tray 0356 *----------------------------------------*/ 0357 int 0358 gen_closetray(struct wm_drive *d) 0359 { 0360 return -1; 0361 } /* gen_closetray() */ 0362 0363 0364 int 0365 scale_volume(int vol,int max) 0366 { 0367 return ((vol * (max_volume - min_volume)) / max + min_volume); 0368 } 0369 0370 int 0371 unscale_volume(int vol,int max) 0372 { 0373 int n; 0374 n = ( vol - min_volume ) * max_volume / (max - min_volume); 0375 return (n <0)?0:n; 0376 } 0377 0378 /* NAME: gen_set_volume 0379 * 0380 * FUNCTION: 0381 * 0382 * RETURNS: 0383 */ 0384 int 0385 gen_set_volume(struct wm_drive *d,int left,int right) 0386 { 0387 struct cd_audio_cmd cmd; 0388 0389 cmd.audio_cmds = CD_SET_VOLUME; 0390 cmd.volume_type = CD_VOLUME_CHNLS; 0391 0392 cmd.out_port_0_vol = scale_volume(left,100); 0393 cmd.out_port_1_vol = scale_volume(right,100); 0394 0395 if( ioctl(d->fd,DKAUDIO,&cmd) < 0) 0396 { 0397 perror("CD_SET_VOLUME"); 0398 return -1; 0399 } 0400 0401 return 0; 0402 } /* gen_set_volume() */ 0403 0404 /* NAME: gen_get_volume 0405 * 0406 * FUNCTION: 0407 * 0408 * RETURNS: 0409 */ 0410 int 0411 gen_get_volume(struct wm_drive *d,int *left,int *right) 0412 { 0413 struct cd_audio_cmd cmd; 0414 int l,r; 0415 0416 fprintf(stderr,"gen_get_volume\n"); 0417 0418 cmd.audio_cmds = CD_INFO_AUDIO; 0419 if( ioctl(d->fd,DKAUDIO,&cmd) < 0) 0420 return -1; 0421 0422 *left = unscale_volume(cmd.out_port_0_vol,100); 0423 *right = unscale_volume(cmd.out_port_1_vol,100); 0424 0425 return 0; 0426 } /* gen_get_volume() */ 0427 0428 #endif /* _AIX */ 0429 0430 0431 0432 0433