1 /* 2 Interface to the CDROM drive. 3 4 -- Roy Keene [021119991200] rkeene@suspend.net 5 */ 6 7 #include <stdlib.h> 8 #include <err.h> 9 #include <errno.h> 10 #include <asm/errno.h> 11 #include <unistd.h> 12 #include <sys/ioctl.h> 13 #include <fcntl.h> 14 #include <sys/types.h> 15 #include <sys/stat.h> 16 #ifdef DEBUG 17 #include <stdio.h> 18 #endif 19 #include <linux/cdrom.h> 20 #include "cdrom.h" 21 22 23 int open_cdrom(char *cdromfile) { 24 int cdrom_fd; 25 cdrom_fd=open(cdromfile, O_RDONLY|O_NONBLOCK); 26 #ifdef DEBUG 27 printf("cdrom.c: open_cdrom(\"%s\")=%i\n",cdromfile,cdrom_fd); 28 if (cdrom_fd<0) { printf("cdrom.c: open_cdrom: Couldn't open %s\n",cdromfile); } 29 #endif 30 return cdrom_fd; 31 } 32 33 void cd_eject(int cdrom_fd) { 34 #ifdef DEBUG 35 printf("cdrom.c: cd_eject(cdrom_fd)\n"); 36 #endif 37 cd_stop(cdrom_fd); 38 #ifdef DEBUG 39 printf("cdrom.c: cd_eject: ioctl(cdrom,CDROMEJECT)=%i\n",ioctl(cdrom_fd, CDROMEJECT)); 40 #else 41 ioctl(cdrom_fd, CDROMEJECT); 42 #endif 43 } 44 45 void cd_playtrack(int cdrom_fd, int track) { 46 static struct cdrom_ti trackindex; 47 trackindex.cdti_trk0=track; 48 trackindex.cdti_trk1=track; 49 trackindex.cdti_ind0=0; 50 trackindex.cdti_ind1=0; 51 #ifdef DEBUG 52 printf("cdrom.c: cd_playtrack(cdrom_fd, %i)\n",track); 53 printf("cdrom.c: cd_playtrack: ioctl(cdrom_fd,CDROMSTART)=%i\n",ioctl(cdrom_fd,CDROMSTART)); 54 printf("cdrom.c: cd_playtrack: ioctl(cdrom_fd,CDROMPLAYTRKIND,&trackindex)=%i\n",ioctl(cdrom_fd,CDROMPLAYTRKIND,&trackindex)); 55 #else 56 ioctl(cdrom_fd,CDROMSTART); 57 ioctl(cdrom_fd,CDROMPLAYTRKIND,&trackindex); 58 #endif 59 } 60 61 void cd_play(int cdrom_fd, int starttrack) { 62 static struct cdrom_ti trackindex; 63 trackindex.cdti_trk0=starttrack; 64 trackindex.cdti_ind0=0; 65 trackindex.cdti_ind1=0; 66 #ifdef DEBUG 67 printf("cdrom.c: cd_play(cdrom_fd, %i)\n",starttrack); 68 trackindex.cdti_trk1=cd_num_tracks(cdrom_fd, 0); 69 printf("cdrom.c: cd_play: ioctl(cdrom_fd,CDROMSTART)=%i\n",ioctl(cdrom_fd,CDROMSTART)); 70 perror("cdrom.c: cd_play: perror"); 71 printf("cdrom.c: cd_play: ioctl(cdrom_fd,CDROMPLAYTRKIND,&trackindex)=%i\n",ioctl(cdrom_fd,CDROMPLAYTRKIND,&trackindex)); 72 perror("cdrom.c: cd_play: perror"); 73 #else 74 trackindex.cdti_trk1=cd_num_tracks(cdrom_fd, 0); 75 ioctl(cdrom_fd,CDROMSTART); 76 ioctl(cdrom_fd,CDROMPLAYTRKIND,&trackindex); 77 #endif 78 } 79 80 81 void cd_stop(int cdrom_fd) { 82 #ifdef DEBUG 83 printf("cdrom.c: cd_stop(cdrom_fd)\n"); 84 printf("cdrom.c: cd_stop: ioctl(cdrom_fd,CDROMSTOP)=%i\n",ioctl(cdrom_fd,CDROMSTOP)); 85 #else 86 ioctl(cdrom_fd,CDROMSTOP); 87 #endif 88 } 89 90 91 int cd_num_tracks(int cdrom_fd, int start) { 92 struct cdrom_tochdr toc; 93 #ifdef DEBUG 94 printf("cdrom.c: cd_num_tracks(cdrom_fd, %i)\n", start); 95 printf("cdrom.c: cd_num_tracks: ioctl(cdrom_fd, CDROMREADTOCHDR, &toc)=%i\n", ioctl(cdrom_fd, CDROMREADTOCHDR, &toc)); 96 printf("cdrom.c: cd_num_tracks: toc.cdth_trk0=%i\n",toc.cdth_trk0); 97 printf("cdrom.c: cd_num_tracks: toc.cdth_trk1=%i\n",toc.cdth_trk1); 98 #else 99 ioctl(cdrom_fd, CDROMREADTOCHDR, &toc); 100 #endif 101 if (start==1) return(toc.cdth_trk0); 102 return(toc.cdth_trk1-toc.cdth_trk0+1); 103 } 104 105 106 int cd_isplaying(int cdrom_fd) { 107 struct cdrom_subchnl status; 108 #ifdef DEBUG 109 int ioctl_retval, retval=0; 110 ioctl_retval=ioctl(cdrom_fd,CDROMSUBCHNL,&status); 111 if (status.cdsc_audiostatus==17) retval=1; 112 printf("cdrom.c: cd_isplaying(cdrom_fd)=%i\n",retval); 113 printf("cdrom.c: cd_isplaying: ioctl(cdrom_fd, CDROMSUBCHNL, &status)=%i\n",ioctl_retval); 114 printf("cdrom.c: cd_isplaying: status.cdsc_audiostatus=%i\n",status.cdsc_audiostatus); 115 printf("cdrom.c: cd_isplaying: status.cdsc_ctrl=%i\n",status.cdsc_ctrl); 116 printf("cdrom.c: cd_isplaying: status.cdsc_format=%i\n",status.cdsc_format); 117 printf("cdrom.c: cd_isplaying: status.cdsc_adr=%i\n",status.cdsc_adr); 118 printf("cdrom.c: cd_isplaying: status.cdsc_trk=%i\n",status.cdsc_trk); 119 printf("cdrom.c: cd_isplaying: status.cdsc_ind=%i\n",status.cdsc_ind); 120 printf("cdrom.c: cd_isplaying: status.cdsc_absaddr.msf.minute=%lu\n",(long) status.cdsc_absaddr.msf.minute); 121 printf("cdrom.c: cd_isplaying: status.cdsc_absaddr.msf.second=%lu\n",(long) status.cdsc_absaddr.msf.second); 122 return(retval); 123 #else 124 ioctl(cdrom_fd,CDROMSUBCHNL,&status); 125 if (status.cdsc_audiostatus==17) return(1); 126 return(0); 127 #endif 128 } 129 130 int cd_currenttrack(int cdrom_fd) { 131 struct cdrom_subchnl status; 132 #ifdef DEBUG 133 int retval=0; 134 retval=ioctl(cdrom_fd,CDROMSUBCHNL,&status); 135 printf("cdrom.c: cd_currenttrack(cdrom_fd)=%i\n",status.cdsc_trk); 136 printf("cdrom.c: cd_currenttrack: ioctl(cdrom_fd, CDROMSUBCHNL, &status)=%i\n",retval); 137 printf("cdrom.c: cd_currenttrack: status.cdsc_audiostatus=%i\n",status.cdsc_audiostatus); 138 printf("cdrom.c: cd_currenttrack: status.cdsc_ctrl=%i\n",status.cdsc_ctrl); 139 printf("cdrom.c: cd_currenttrack: status.cdsc_format=%i\n",status.cdsc_format); 140 printf("cdrom.c: cd_currenttrack: status.cdsc_adr=%i\n",status.cdsc_adr); 141 printf("cdrom.c: cd_currenttrack: status.cdsc_trk=%i\n",status.cdsc_trk); 142 printf("cdrom.c: cd_currenttrack: status.cdsc_ind=%i\n",status.cdsc_ind); 143 printf("cdrom.c: cd_currenttrack: status.cdsc_absaddr.msf.minute=%lu\n",(long) status.cdsc_absaddr.msf.minute); 144 printf("cdrom.c: cd_currenttrack: status.cdsc_absaddr.msf.second=%lu\n",(long) status.cdsc_absaddr.msf.second); 145 #else 146 ioctl(cdrom_fd,CDROMSUBCHNL,&status); 147 #endif 148 return(status.cdsc_trk); 149 } 150 151 void cd_setvolume(int cdrom_fd, unsigned char volume) { 152 struct cdrom_volctrl cdvolume; 153 cdvolume.channel0=volume; 154 cdvolume.channel1=volume; 155 cdvolume.channel2=volume; 156 cdvolume.channel3=volume; 157 #ifdef DEBUG 158 printf("cdrom.c: cd_setvolume(cdrom_fd, %i)\n",volume); 159 printf("cdrom.c: cd_setvolume: ioctl(cdrom_fd, CDROMVOLCTRL, &cdvolume)=%i\n", ioctl(cdrom_fd, CDROMVOLCTRL, &cdvolume)); 160 #else 161 ioctl(cdrom_fd, CDROMVOLCTRL, &cdvolume); 162 #endif 163 } 164 165 int cd_getvolume(int cdrom_fd) { 166 struct cdrom_volctrl cdvolume; 167 #ifdef DEBUG 168 int ioctl_retval; 169 ioctl_retval=ioctl(cdrom_fd, CDROMVOLREAD, &cdvolume); 170 printf("cdrom.c: cd_getvolume(cdrom_fd)=%i\n",cdvolume.channel0); 171 printf("cdrom.c: cd_getvolume: ioctl(cdrom_fd, CDROMVOLREAD, &cdvolume)=%i\n",ioctl_retval); 172 printf("cdrom.c: cd_getvolume: cdvolume.channel0=%i\n",cdvolume.channel0); 173 printf("cdrom.c: cd_getvolume: cdvolume.channel1=%i\n",cdvolume.channel1); 174 printf("cdrom.c: cd_getvolume: cdvolume.channel2=%i\n",cdvolume.channel2); 175 printf("cdrom.c: cd_getvolume: cdvolume.channel3=%i\n",cdvolume.channel3); 176 #else 177 ioctl(cdrom_fd, CDROMVOLREAD, &cdvolume); 178 #endif 179 return(cdvolume.channel0); 180 } cdrom.c is the source code for a library for manipulating the CD-ROM drive. |