home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 2 / CD ACTUAL VOL 2.iso / docs / kernel.12 / readme.sbp < prev    next >
Encoding:
Text File  |  1995-09-10  |  32.6 KB  |  998 lines

  1. This README belongs to release 3.7 or newer of the SoundBlaster Pro
  2. (Matsushita, Kotobuki, Panasonic, CreativeLabs, Longshine and TEAC)
  3. CD-ROM driver for Linux.
  4.  
  5. The driver is able to drive the whole family of "traditional" IDE-style (that
  6. is NOT the new "Enhanced IDE" or "ATAPI" drive standard) Matsushita,
  7. Kotobuki, Panasonic drives, sometimes labelled as "CreativeLabs". The
  8. well-known drives are CR-521, CR-522, CR-523, CR-562, CR-563.
  9.  
  10. The Longshine LCS-7260 is a double-speed drive which uses the "old"
  11. Matsushita command set. It is supported now - with help by Serge Robyns.
  12.  
  13. There exists an "IBM External ISA CD-ROM Drive" which in fact is a CR-563
  14. with a special controller board. This drive is supported (the interface is
  15. of the "LaserMate" type), and it is possibly the best buy today (cheaper than
  16. an internal drive, and you can use it as an internal, too - f.e. plug it into
  17. a soundcard).
  18.  
  19. CreativeLabs has a new drive "CD-200". Support is under construction.
  20. Drive detection and playing audio should already work. I need qualified
  21. feedback about the bugs within the data functions or a drive (I never saw
  22. a CD200).
  23.  
  24. The quad-speed TEAC CD-55A drive is supported. The routines may still be
  25. a little bit buggy, but the data rate already reaches 500 kB/sec if you
  26. set SBP_BUFFER_FRAMES to 64. The drive is able to deliver 600 kB/sec, so
  27. this has to get a point of work.
  28.  
  29. This driver is NOT for Mitsumi or Sony or Aztech or Philips or XXX drives,
  30. and this driver is in no way usable for any new IDE ATAPI drive.
  31.  
  32. This driver will work with the soundcard interfaces (SB Pro, SB 16, Galaxy,
  33. SoundFX, ...) and/or with the "no-sound" cards (Panasonic CI-101P, LaserMate,
  34. WDH-7001C, Longshine LCS-6853, older Aztech cards, ...).
  35.  
  36. It should work too now with the "configurable" interface "Sequoia S-1000",
  37. which is found on the Spea Media FX sound card. I still need feedback about
  38. this, or such a card. Anyways, the procedure "boot DOS and wait until 
  39. CONFIG.SYS is done, then use CTL-ALT-DEL to boot Linux" should make it
  40. work.
  41.  
  42. The interface type has to get configured in /usr/include/linux/sbpcd.h, 
  43. because the behavior of some sound card interfaces is different.
  44.  
  45. With some TEAC drives I have seen interface cards which seem to lack the
  46. "drive select" lines; always drive 0 gets addressed. To avoid "mirror drives"
  47. with such interface cards, set MAX_DRIVES to 1 and jumper your drive to ID 0.
  48.  
  49. The driver respects all known drive firmware releases - my old drive is a 2.11,
  50. but it should work with CR-52x drives <2.01 ... >3.00 and with CR-56x drives
  51. <0.75 .. 5.00.
  52.  
  53. Up to 4 drives per interface card, and up to 4 interface cards are supported.
  54. All supported drive families can be mixed, but the CR-521 drives are 
  55. hard-wired to drive ID 0. The drives have to use different drive IDs, and each
  56. drive has to get a unique minor number (0...3), corresponding indirectly to 
  57. its drive ID.
  58. The drive IDs may be selected freely from 0 to 3 - they do not have to be in
  59. consecutive order.
  60.  
  61. As Don Carroll, don@ds9.us.dell.com or FIDO 1:382/14, told me, it is possible
  62. to change old drives to any ID, too. He writes in this sense:
  63.    "In order to be able to use more than one single speed drive
  64.    (they do not have the ID jumpers) you must add a DIP switch
  65.    and two resistors. The pads are already on the board next to
  66.    the power connector. You will see the silkscreen for the
  67.    switch if you remove the top cover.
  68.                     1 2 3 4
  69.              ID 0 = x F F x             O = "on"
  70.              ID 1 = x O F x             F = "off"
  71.              ID 2 = x F O x             x = "don't care"
  72.              ID 3 = x O O x
  73.    Next to the switch are the positions for R76 (7k) and R78
  74.    (12k). I had to play around with the resistor values - ID 3
  75.    did not work with other values. If the values are not good,
  76.    ID 3 behaves like ID 0."
  77.  
  78. To use more than 4 drives, you simply need a second controller card at a 
  79. different address and a second cable.
  80.  
  81. The driver supports reading of data from the CD and playing of audio tracks.
  82. The audio part should run with WorkMan, xcdplayer, with the "non-X11" products
  83. CDplayer and WorkBone - tell me if it is not compatible with other software.
  84.  
  85. With the CR-562 and CR-563 drives, the reading of audio frames is possible.
  86. This is implemented by an IOCTL function which reads READ_AUDIO frames of
  87. 2352 bytes at once (configurable with the "READ_AUDIO" define, default is 0).
  88. Reading the same frame a second time gives different data; the frame data 
  89. start at a different position, but all read bytes are valid, and we always
  90. read 98 consecutive chunks (of 24 Bytes) as a frame. Reading more than 1 frame
  91. at once possibly misses some chunks at each frame boundary. This lack has to
  92. get corrected by external, "higher level" software which reads the same frame 
  93. again and tries to find and eliminate overlapping chunks (24-byte-pieces).
  94.  
  95. The transfer rate with reading audio (1-frame-pieces) currently is very slow.
  96. This can be better reading bigger chunks, but the "missing" chunks possibly
  97. occur at the beginning of each single frame.
  98. The software interface possibly may change a bit the day the SCSI driver
  99. supports it too.
  100.  
  101. With all but the CR-52x drives, MultiSession is supported.
  102. Photo CDs work (the "old" drives like CR-521 can access only the first
  103. session of a photoCD).
  104. At ftp.gwdg.de:/pub/linux/hpcdtoppm/ you will find Hadmut Danisch's package to
  105. convert photo CD image files and Gerd Knorr's viewing utility.
  106.  
  107. The transfer rate will reach 150 kB/sec with "old" drives, 300 kB/sec with
  108. double-speed drives, and about 500 kB/sec with quad speed drives.
  109. XA (PhotoCD) disks with "old" drives give only 50 kB/sec.
  110.  
  111. This release is part of the standard kernel and consists of
  112. - this README file
  113. - the driver file linux/drivers/block/sbpcd.c
  114. - the header file linux/include/linux/sbpcd.h.
  115.  
  116.  
  117. To install:
  118. -----------
  119.  
  120. 1. Setup your hardware parameters. Though the driver does "auto-probing" at a
  121.    lot of (not all possible!) addresses, this step is recommended for
  122.    every-day use.
  123.    a. Go into /usr/src/linux/include/linux/sbpcd.h and configure it for your
  124.       hardware (near the beginning):
  125.       a1. Set it up for the appropriate type of interface board.
  126.           "Original" CreativeLabs sound cards need "SBPRO 1".
  127.           Most "compatible" sound cards (for example "Highscreen", "SoundFX"
  128.           and "Galaxy") need "SBPRO 0".
  129.           The "no-sound" board from OmniCd needs the "SBPRO 1" setup.
  130.           All other "no-sound" boards need the "SBPRO 0" setup.
  131.           The Spea Media FX sound card needs "SBPRO 2".
  132.           sbpcd.c holds some examples in its auto-probe list.
  133.           If you configure "SBPRO" wrong, the playing of audio CDs will work,
  134.           but you will not be able to mount a data CD.
  135.       a2. Tell the address of your CDROM_PORT (not of the sound port).
  136.       a3. Set DISTRIBUTION to 0.
  137.    b. Additionally for 2.a1 and 2.a2, the setup may be done during
  138.       boot time (via the "kernel command line" or "LILO option"):
  139.           sbpcd=0x230,SoundBlaster
  140.       or
  141.           sbpcd=0x320,LaserMate
  142.       or
  143.           sbpcd=0x330,SPEA
  144.       This is especially useful if you install a fresh distribution.
  145. 2. "cd /usr/src/linux" and do a "make config" and select "y" for Matsushita
  146.    CD-ROM support and for ISO9660 FileSystem support. If you do not have a
  147.    second, third, or fourth controller installed, do not say "y" to the 
  148.    secondary Matsushita CD-ROM questions.
  149.    SCSI and/or SCSI CD-ROM support is not needed.
  150.  
  151. 3. Then do a "make dep", then make the kernel image ("make zlilo" or else).
  152.  
  153. 4. Make the device file(s). The driver uses definitely and exclusive the
  154.    MAJOR 25, so do
  155.         mknod /dev/sbpcd  b 25 0       (if you have only one drive)
  156.    and/or
  157.         mknod /dev/sbpcd0 b 25 0
  158.         mknod /dev/sbpcd1 b 25 1
  159.         mknod /dev/sbpcd2 b 25 2
  160.         mknod /dev/sbpcd3 b 25 3
  161.    to make the node(s).
  162.  
  163.    The driver no longer uses the "AT bus style" device numbering; the SCSI
  164.    scheme is used now; that means, the "first found" drive gets MINOR 0
  165.    (regardless to its jumpered ID), the "next found" (at the same cable)
  166.    gets MINOR 1, ...
  167.    
  168.    For a second interface board, you have to make nodes like
  169.         mknod /dev/sbpcd4 b 26 0
  170.         mknod /dev/sbpcd5 b 26 1
  171.    and so on. Use the MAJORs 26, 27, 28.
  172.  
  173.    If you further make a link like
  174.         ln -s sbpcd /dev/cdrom
  175.    you can use the name /dev/cdrom, too.
  176.  
  177. 5. Reboot with the new kernel.
  178.  
  179. You should now be able to do
  180.               mkdir /CD
  181. and 
  182.               mount -t iso9660 -o ro /dev/sbpcd /CD
  183. or
  184.               mount -t iso9660 -o ro,block=2048 /dev/sbpcd /CD
  185. and see the contents of your CD in the /CD directory, and/or hear music with
  186. "workman -c /dev/sbpcd &".
  187.  
  188.  
  189. Using sbpcd as a "loadable module":
  190. -----------------------------------
  191.  
  192. If you do NOT select "Matsushita/Panasonic CDROM driver support" during the
  193. "make config" of your kernel, you can build the "loadable module" sbpcd.o.
  194. Read /usr/src/linux/README.modules on this.
  195.  
  196. If sbpcd gets used as a module, the support of more than one interface
  197. card (i.e. drives 4...15) is disabled.
  198.  
  199. You can specify interface address and type with the "insmod" command like:
  200.  # insmod /usr/src/linux/modules/sbpcd.o sbpcd=0x340,0
  201. or
  202.  # insmod /usr/src/linux/modules/sbpcd.o sbpcd=0x230,1
  203. where the last number represents the SBPRO setting (no strings allowed here).
  204.  
  205.  
  206. Things of interest:
  207. -------------------
  208.  
  209. The driver is configured to try the LaserMate type of interface at I/O port
  210. 0x0340 first. If this is not appropriate, sbpcd.h should get changed
  211. (you will find the right place - just at the beginning).
  212.  
  213. No DMA and no IRQ is used.
  214.  
  215. To reduce or increase the amount of kernel messages, edit sbpcd.c and play
  216. with the "DBG_xxx" switches (initialization of the variable "sbpcd_debug").
  217.  
  218. The driver uses the "variable BLOCK_SIZE" feature. To use it, you have to
  219. specify "block=2048" as a mount option. Doing this will disable the direct
  220. execution of a binary from the CD; you have to copy it to a device with the
  221. standard BLOCK_SIZE (1024) before. So, do not use this if your system is
  222. directly "running from the CDROM" (like some of YGGDRASIL's installation
  223. variants). There are CDs on the market (like the german "unifix" Linux
  224. distribution) which MUST get handled with a block_size of 1024. Generally,
  225. one can say all the CDs which hold files of the name YMTRANS.TBL are defective;
  226. do not use block=2048 with those.
  227.  
  228. At the beginning of sbpcd.c, you will find some "#define"s (f.e. EJECT and
  229. JUKEBOX). With that, you can configure the driver for some special things.
  230. You can use the appended program "cdtester" to set the auto-eject feature
  231. during runtime. Jeff Tranter's "eject" utility can do this, too (and more)
  232. for you.
  233.  
  234. There is a new ioctl CDROMMULTISESSION to obtain with a user program if
  235. the CD is an XA disk and - if it is - where the last session starts. The
  236. "cdtester" program illustrates how to call it.
  237.  
  238.  
  239. Auto-probing at boot time:
  240. --------------------------
  241.  
  242. The driver does auto-probing at many well-known interface card addresses,
  243. but not all:
  244. Some probings can cause a hang if an NE2000 ethernet card gets touched, because
  245. SBPCD's auto-probing happens before the initialization of the net drivers.
  246. Those "hazardous" addresses are excluded from auto-probing; the "kernel 
  247. command line" feature has to be used during installation if you have your 
  248. drive at those addresses. The "module" version is allowed to probe at those
  249. addresses, too.
  250.  
  251. The auto-probing looks first at the configured address resp. the address
  252. submitted by the kernel command line. With this, it is possible to use this
  253. driver within installation boot floppies, and for any non-standard address,
  254. too.
  255.  
  256. Auto-probing will make an assumption about the interface type ("SBPRO" or not),
  257. based upon the address. That assumption may be wrong (initialization will be
  258. o.k., but you will get I/O errors during mount). In that case, use the "kernel
  259. command line" feature and specify address & type at boot time to find out the
  260. right setup.
  261.  
  262. For every-day use, address and type should get configured within sbpcd.h. That
  263. will stop the auto-probing due to success with the first try.
  264.  
  265. The kernel command "sbpcd=0" suppresses each auto-probing and causes
  266. the driver not to find any drive; it is meant for people who love sbpcd
  267. so much that they do not want to miss it, even if they miss the drives. ;-)  
  268.  
  269. If you configure "#define CDROM_PORT 0" in sbpcd.h, the auto-probing is
  270. initially disabled and needs an explicit kernel command to get activated.
  271. Once activated, it does not stop before success or end-of-list. This may be
  272. useful within "universal" CDROM installation boot floppies (but using the 
  273. loadable module would be better because it allows an "extended" auto-probing
  274. without fearing NE2000 cards).
  275.  
  276. To shorten the auto-probing list to a single entry, set DISTRIBUTION 0 within
  277. sbpcd.h.
  278.  
  279.  
  280. Setting up address and interface type:
  281. --------------------------------------
  282.  
  283. If your I/O port address is not 0x340, you have to look for the #defines near
  284. the beginning of sbpcd.h and configure them: set SBPRO to 0 or 1 or 2, and
  285. change CDROM_PORT to the address of your CDROM I/O port.
  286.  
  287. Most of the "SoundBlaster compatible" cards behave like the no-sound
  288. interfaces! 
  289.  
  290. With "original" SB Pro cards, an initial setting of CD_volume through the
  291. sound cards MIXER register gets done.
  292. If you are using a "compatible" sound card of types "LaserMate" or "SPEA",
  293. you can set SOUND_BASE (in sbpcd.h) to get it done with your card, too...
  294.  
  295.  
  296. Using audio CDs:
  297. ----------------
  298.  
  299. Workman, WorkBone, xcdplayer, cdplayer and the nice little tool "cdplay" (see
  300. README.aztcd from the Aztech driver package) should work.
  301.  
  302. The program CDplayer likes to talk to "/dev/mcd" only, xcdplayer wants
  303. "/dev/rsr0", workman loves "/dev/sr0" or "/dev/cdrom" - so, do the appropriate
  304. links for using them without the need of supplying parameters.
  305.  
  306.  
  307. Copying audio tracks:
  308. ---------------------
  309.  
  310. The following program will copy track 1 (or a piece of it) from an audio CD
  311. into the file "track01":
  312.  
  313. /*=================== begin program ========================================*/
  314. /*
  315.  * read an audio track from a CD
  316.  *
  317.  * (c) 1994 Eberhard Moenkeberg <emoenke@gwdg.de>
  318.  *          may be used & enhanced freely
  319.  *
  320.  * Due to non-existent sync bytes at the beginning of each audio frame (or due
  321.  * to a firmware bug within all known drives?), it is currently a kind of
  322.  * fortune if two consecutive frames fit together.
  323.  * Usually, they overlap, or a little piece is missing. This happens in units
  324.  * of 24-byte chunks. It has to get fixed by higher-level software (reading
  325.  * until an overlap occurs, and then eliminate the overlapping chunks). 
  326.  * ftp.gwdg.de:/pub/linux/misc/cdda2wav-sbpcd.*.tar.gz holds an example of
  327.  * such an algorithm.
  328.  * This example program further is missing to obtain the SubChannel data
  329.  * which belong to each frame.
  330.  *
  331.  * This is only an example of the low-level access routine. The read data are
  332.  * pure 16-bit CDDA values; they have to get converted to make sound out of
  333.  * them.
  334.  * It is no fun to listen to it without prior overlap/underlap correction!
  335.  */
  336. #include <stdio.h>
  337. #include <sys/ioctl.h>
  338. #include <linux/cdrom.h>
  339.  
  340. static struct cdrom_tochdr hdr;
  341. static struct cdrom_tocentry entry[101];
  342. static struct cdrom_read_audio arg;
  343. static u_char buffer[CD_FRAMESIZE_RAW];
  344. static int datafile, drive;
  345. static int i, j, limit, track, err;
  346. static char filename[32];
  347.  
  348. main(int argc, char *argv[])
  349. {
  350. /*
  351.  * open /dev/cdrom
  352.  */
  353.   drive=open("/dev/cdrom", 0);
  354.   if (drive<0)
  355.     {
  356.       fprintf(stderr, "can't open drive.\n");
  357.       exit (-1);
  358.     }
  359. /*
  360.  * get TocHeader
  361.  */
  362.   fprintf(stdout, "getting TocHeader...\n");
  363.   err=ioctl(drive, CDROMREADTOCHDR, &hdr);
  364.   if (err!=0)
  365.     {
  366.       fprintf(stderr, "can't get TocHeader (error %d).\n", err);
  367.       exit (-1);
  368.     }
  369.   else
  370.     fprintf(stdout, "TocHeader: %d %d\n", hdr.cdth_trk0, hdr.cdth_trk1);
  371. /*
  372.  * get and display all TocEntries
  373.  */
  374.   fprintf(stdout, "getting TocEntries...\n");
  375.   for (i=1;i<=hdr.cdth_trk1+1;i++)
  376.     {
  377.       if (i!=hdr.cdth_trk1+1) entry[i].cdte_track = i;
  378.       else entry[i].cdte_track = CDROM_LEADOUT;
  379.       entry[i].cdte_format = CDROM_LBA;
  380.       err=ioctl(drive, CDROMREADTOCENTRY, &entry[i]);
  381.       if (err!=0)
  382.     {
  383.       fprintf(stderr, "can't get TocEntry #%d (error %d).\n", i, err);
  384.       exit (-1);
  385.     }
  386.       else
  387.     {
  388.       fprintf(stdout, "TocEntry #%d: %1X %1X %06X %02X\n",
  389.          entry[i].cdte_track,
  390.          entry[i].cdte_adr,
  391.          entry[i].cdte_ctrl,
  392.          entry[i].cdte_addr.lba,
  393.          entry[i].cdte_datamode);
  394.     }
  395.     }
  396.   fprintf(stdout, "got all TocEntries.\n");
  397. /*
  398.  * ask for track number (not implemented here)
  399.  */
  400. track=1;
  401. #if 0 /* just read a little piece (4 seconds) */
  402. entry[track+1].cdte_addr.lba=entry[track].cdte_addr.lba+300;
  403. #endif
  404. /*
  405.  * read track into file
  406.  */
  407.   sprintf(filename, "track%02d\0", track);
  408.   datafile=creat(filename, 0755);
  409.   if (datafile<0)
  410.     {
  411.       fprintf(stderr, "can't open datafile %s.\n", filename);
  412.       exit (-1);
  413.     }
  414.   arg.addr.lba=entry[track].cdte_addr.lba;
  415.   arg.addr_format=CDROM_LBA; /* CDROM_MSF would be possible here, too. */
  416.   arg.nframes=1;
  417.   arg.buf=&buffer[0];
  418.   limit=entry[track+1].cdte_addr.lba;
  419.   for (;arg.addr.lba<limit;arg.addr.lba++)
  420.     {
  421.       err=ioctl(drive, CDROMREADAUDIO, &arg);
  422.       if (err!=0)
  423.     {
  424.       fprintf(stderr, "can't read abs. frame #%d (error %d).\n", 
  425.          arg.addr.lba, err);
  426.     }
  427.       j=write(datafile, &buffer[0], CD_FRAMESIZE_RAW);
  428.       if (j!=CD_FRAMESIZE_RAW)
  429.     {
  430.       fprintf(stderr,"I/O error (datafile) at rel. frame %d\n",
  431.              arg.addr.lba-entry[track].cdte_addr.lba);
  432.     }
  433.       arg.addr.lba++;
  434.     }
  435. }
  436. /*===================== end program ========================================*/
  437.  
  438. At ftp.gwdg.de:/pub/linux/misc/cdda2wav-sbpcd.*.tar.gz is an adapted version of
  439. Heiko Eissfeldt's digital-audio to .WAV converter (the original is there, too).
  440. This is preliminary, as Heiko himself will care about it.
  441.  
  442.  
  443. Known problems:
  444. ---------------
  445.  
  446. Currently, the detection of disk change or removal is actively disabled.
  447.  
  448. Most attempts to read the UPC/EAN code result in a stream of zeroes. All my
  449. drives are mostly telling there is no UPC/EAN code on disk or there is, but it
  450. is an all-zero number. I guess now almost no CD holds such a number.
  451.  
  452. Bug reports, comments, wishes, donations (technical information is a donation,
  453. too :-) etc. to
  454.                          emoenke@gwdg.de
  455.  or to my FIDO address:  Eberhard Moenkeberg, 2:2437/210.27
  456.  
  457. SnailMail address, preferable for CD editors if they want to submit a free
  458. "cooperation" copy:
  459.                          Eberhard Moenkeberg
  460.                          Reinholdstr. 14
  461.                          D-37083 Goettingen
  462.                          Germany
  463. ---
  464.  
  465.  
  466. Appendix -- the "cdtester" utility:
  467.  
  468. /*
  469.  * cdtester.c -- test the audio functions of a CD driver
  470.  *
  471.  * (c) 1995 Eberhard Moenkeberg <emoenke@gwdg.de>
  472.  *          published under the GPL
  473.  *
  474.  *          made under heavy use of the "Tiny Audio CD Player"
  475.  *          from Werner Zimmermann <zimmerma@rz.fht-esslingen.de>
  476.  *          (see linux/drivers/block/README.aztcd)
  477.  */
  478. #undef AZT_PRIVATE_IOCTLS /* not supported by every CDROM driver */
  479. #define SBP_PRIVATE_IOCTLS /* not supported by every CDROM driver */
  480.  
  481. #include <stdio.h>
  482. #include <stdio.h>
  483. #include <malloc.h>
  484. #include <sys/ioctl.h>
  485. #include <linux/cdrom.h>
  486.  
  487. #ifdef AZT_PRIVATE_IOCTLS
  488. #include <linux/aztcd.h>
  489. #endif AZT_PRIVATE_IOCTLS
  490. #ifdef SBP_PRIVATE_IOCTLS
  491. #include <linux/sbpcd.h>
  492. #include <linux/fs.h>
  493. #endif SBP_PRIVATE_IOCTLS
  494.  
  495. struct cdrom_tochdr hdr;
  496. struct cdrom_tochdr tocHdr;
  497. struct cdrom_tocentry TocEntry[101];
  498. struct cdrom_tocentry entry;
  499. struct cdrom_multisession ms_info;
  500. struct cdrom_read_audio read_audio;
  501. struct cdrom_ti ti;
  502. struct cdrom_subchnl subchnl;
  503. struct cdrom_msf msf;
  504. struct cdrom_volctrl volctrl;
  505. #ifdef AZT_PRIVATE_IOCTLS
  506. union
  507. {
  508.     struct cdrom_msf msf;
  509.     unsigned char buf[CD_FRAMESIZE_RAW];
  510. } azt;
  511. #endif AZT_PRIVATE_IOCTLS
  512. int i, i1, i2, i3, j, k;
  513. unsigned char sequence=0;
  514. unsigned char command[80];
  515. unsigned char first=1, last=1;
  516. char *default_device="/dev/cdrom";
  517. char dev[20];
  518. char filename[20];
  519. int drive;
  520. int datafile;
  521. int rc;
  522.  
  523. void help(void)
  524. {
  525.     printf("Available Commands:\n");
  526.     printf("STOP          s      EJECT        e       QUIT         q\n");
  527.     printf("PLAY TRACK    t      PAUSE        p       RESUME       r\n");
  528.     printf("NEXT TRACK    n      REPEAT LAST  l       HELP         h\n");
  529.     printf("SUBCHANNEL_Q  c      TRACK INFO   i       PLAY AT      a\n");
  530.     printf("READ          d      READ RAW     w       READ AUDIO   A\n");
  531.     printf("MS-INFO       M      TOC          T       START        S\n");
  532.     printf("SET EJECTSW   X      DEVICE       D       DEBUG        Y\n");
  533.     printf("AUDIO_BUFSIZ  Z      RESET        R       BLKRASET     B\n");
  534.     printf("SET VOLUME    v      GET VOLUME   V\n");
  535. }
  536.  
  537. /*
  538.  *  convert MSF number (3 bytes only) to Logical_Block_Address 
  539.  */
  540. int msf2lba(u_char *msf)
  541. {
  542.     int i;
  543.     
  544.     i=(msf[0] * CD_SECS + msf[1]) * CD_FRAMES + msf[2] - CD_BLOCK_OFFSET;
  545.     if (i<0) return (0);
  546.     return (i);
  547. }
  548. /*
  549.  *  convert logical_block_address to m-s-f_number (3 bytes only)
  550.  */
  551. void lba2msf(int lba, unsigned char *msf)
  552. {
  553.     lba += CD_BLOCK_OFFSET;
  554.     msf[0] = lba / (CD_SECS*CD_FRAMES);
  555.     lba %= CD_SECS*CD_FRAMES;
  556.     msf[1] = lba / CD_FRAMES;
  557.     msf[2] = lba % CD_FRAMES;
  558. }
  559.  
  560. int init_drive(char *dev)
  561. {
  562.     unsigned char msf_ent[3];
  563.  
  564.     /*
  565.      * open the device
  566.      */
  567.     drive=open(dev,0);
  568.     if (drive<0) return (-1);
  569.     /*
  570.      * get TocHeader
  571.      */
  572.     printf("getting TocHeader...\n");
  573.     rc=ioctl(drive,CDROMREADTOCHDR,&hdr);
  574.     if (rc!=0)
  575.     {
  576.         printf("can't get TocHeader (error %d).\n",rc);
  577.         return (-2);
  578.     }
  579.     else
  580.         first=hdr.cdth_trk0;
  581.         last=hdr.cdth_trk1;
  582.         printf("TocHeader: %d %d\n",hdr.cdth_trk0,hdr.cdth_trk1);
  583.     /*
  584.      * get and display all TocEntries
  585.      */
  586.     printf("getting TocEntries...\n");
  587.     for (i=1;i<=hdr.cdth_trk1+1;i++)
  588.     {
  589.         if (i!=hdr.cdth_trk1+1) TocEntry[i].cdte_track = i;
  590.         else TocEntry[i].cdte_track = CDROM_LEADOUT;
  591.         TocEntry[i].cdte_format = CDROM_LBA;
  592.         rc=ioctl(drive,CDROMREADTOCENTRY,&TocEntry[i]);
  593.         if (rc!=0)
  594.         {
  595.             printf("can't get TocEntry #%d (error %d).\n",i,rc);
  596.         }
  597.         else
  598.         {
  599.             lba2msf(TocEntry[i].cdte_addr.lba,&msf_ent[0]);
  600.             if (TocEntry[i].cdte_track==CDROM_LEADOUT)
  601.             {
  602.                 printf("TocEntry #%02X: %1X %1X %02d:%02d:%02d (lba: 0x%06X) %02X\n",
  603.                        TocEntry[i].cdte_track,
  604.                        TocEntry[i].cdte_adr,
  605.                        TocEntry[i].cdte_ctrl,
  606.                        msf_ent[0],
  607.                        msf_ent[1],
  608.                        msf_ent[2],
  609.                        TocEntry[i].cdte_addr.lba,
  610.                        TocEntry[i].cdte_datamode);
  611.             }
  612.             else
  613.             {
  614.                 printf("TocEntry #%02d: %1X %1X %02d:%02d:%02d (lba: 0x%06X) %02X\n",
  615.                        TocEntry[i].cdte_track,
  616.                        TocEntry[i].cdte_adr,
  617.                        TocEntry[i].cdte_ctrl,
  618.                        msf_ent[0],
  619.                        msf_ent[1],
  620.                        msf_ent[2],
  621.                        TocEntry[i].cdte_addr.lba,
  622.                        TocEntry[i].cdte_datamode);
  623.             }
  624.         }
  625.     }
  626.     return (hdr.cdth_trk1); /* number of tracks */
  627. }
  628.  
  629. void display(int size,unsigned char *buffer)
  630. {
  631.     k=0;
  632.     getchar();
  633.     for (i=0;i<(size+1)/16;i++)
  634.     {
  635.         printf("%4d:",i*16);
  636.         for (j=0;j<16;j++)
  637.         {
  638.             printf(" %02X",buffer[i*16+j]);
  639.         }
  640.         printf("  ");
  641.         for (j=0;j<16;j++)
  642.         {
  643.             if (isalnum(buffer[i*16+j])) 
  644.                 printf("%c",buffer[i*16+j]);
  645.             else
  646.                 printf(".");
  647.         }
  648.         printf("\n"); 
  649.         k++;
  650.         if (k>=20)
  651.         {
  652.             printf("press ENTER to continue\n");
  653.             getchar();
  654.             k=0;
  655.         }
  656.     } 
  657.  
  658. main(int argc, char *argv[])
  659. {
  660.     printf("\nTesting tool for a CDROM driver's audio functions V0.1\n");
  661.     printf("(C) 1995 Eberhard Moenkeberg <emoenke@gwdg.de>\n");
  662.     printf("initializing...\n");
  663.     
  664.     rc=init_drive(default_device);
  665.     if (rc<0) printf("could not open %s (rc=%d).\n",default_device,rc);
  666.     help();
  667.     while (1)
  668.     {
  669.         printf("Give a one-letter command (h = help): ");
  670.         scanf("%s",command);
  671.         command[1]=0;
  672.         switch (command[0])
  673.         {
  674.         case 'D':
  675.             printf("device name (f.e. /dev/sbpcd3): ? ");
  676.             scanf("%s",&dev);
  677.             close(drive);
  678.             rc=init_drive(dev);
  679.             if (rc<0) printf("could not open %s (rc %d).\n",dev,rc);
  680.             break;
  681.         case 'e':
  682.             rc=ioctl(drive,CDROMEJECT);
  683.             if (rc<0) printf("CDROMEJECT: rc=%d.\n",rc);
  684.             break;
  685.         case 'p':
  686.             rc=ioctl(drive,CDROMPAUSE);
  687.             if (rc<0) printf("CDROMPAUSE: rc=%d.\n",rc);
  688.             break;
  689.         case 'r':
  690.             rc=ioctl(drive,CDROMRESUME);
  691.             if (rc<0) printf("CDROMRESUME: rc=%d.\n",rc);
  692.             break;
  693.         case 's':
  694.             rc=ioctl(drive,CDROMSTOP);
  695.             if (rc<0) printf("CDROMSTOP: rc=%d.\n",rc);
  696.             break;
  697.         case 'S':
  698.             rc=ioctl(drive,CDROMSTART);
  699.             if (rc<0) printf("CDROMSTART: rc=%d.\n",rc);
  700.             break;
  701.         case 't':
  702.             rc=ioctl(drive,CDROMREADTOCHDR,&tocHdr);
  703.             if (rc<0)
  704.             {
  705.                 printf("CDROMREADTOCHDR: rc=%d.\n",rc);
  706.                 break;
  707.             }
  708.             first=tocHdr.cdth_trk0;
  709.             last= tocHdr.cdth_trk1;
  710.             if ((first==0)||(first>last))
  711.             {
  712.                 printf ("--got invalid TOC data.\n");
  713.             }
  714.             else
  715.             {
  716.                 printf("--enter track number(first=%d, last=%d): ",first,last);
  717.                 scanf("%d",&i1);
  718.                 ti.cdti_trk0=i1;
  719.                 if (ti.cdti_trk0<first) ti.cdti_trk0=first;
  720.                 if (ti.cdti_trk0>last) ti.cdti_trk0=last;
  721.                 ti.cdti_ind0=0;
  722.                 ti.cdti_trk1=last;
  723.                 ti.cdti_ind1=0;
  724.                 rc=ioctl(drive,CDROMSTOP);
  725.                 rc=ioctl(drive,CDROMPLAYTRKIND,&ti);
  726.                 if (rc<0) printf("CDROMPLAYTRKIND: rc=%d.\n",rc);
  727.             }
  728.             break;
  729.         case 'n':
  730.             rc=ioctl(drive,CDROMSTOP);
  731.             if (++ti.cdti_trk0>last) ti.cdti_trk0=last;
  732.             ti.cdti_ind0=0;
  733.             ti.cdti_trk1=last;
  734.             ti.cdti_ind1=0;
  735.             rc=ioctl(drive,CDROMPLAYTRKIND,&ti);
  736.             if (rc<0) printf("CDROMPLAYTRKIND: rc=%d.\n",rc);
  737.             break;
  738.         case 'l':
  739.             rc=ioctl(drive,CDROMSTOP);
  740.             if (--ti.cdti_trk0<first) ti.cdti_trk0=first;
  741.             ti.cdti_ind0=0;
  742.             ti.cdti_trk1=last;
  743.             ti.cdti_ind1=0;
  744.             rc=ioctl(drive,CDROMPLAYTRKIND,&ti);
  745.             if (rc<0) printf("CDROMPLAYTRKIND: rc=%d.\n",rc);
  746.             break;
  747.         case 'c':
  748.             subchnl.cdsc_format=CDROM_MSF;
  749.             rc=ioctl(drive,CDROMSUBCHNL,&subchnl);
  750.             if (rc<0) printf("CDROMSUBCHNL: rc=%d.\n",rc);
  751.             else
  752.             {
  753.                 printf("AudioStatus:%s  Track:%d  Mode:%d  MSF=%02d:%02d:%02d\n",
  754.                        subchnl.cdsc_audiostatus==CDROM_AUDIO_PLAY ? "PLAYING":"NOT PLAYING",
  755.                        subchnl.cdsc_trk,subchnl.cdsc_adr, 
  756.                        subchnl.cdsc_absaddr.msf.minute,
  757.                        subchnl.cdsc_absaddr.msf.second,
  758.                        subchnl.cdsc_absaddr.msf.frame);
  759.             }
  760.             break;              
  761.         case 'i':
  762.             printf("Track No.: ");
  763.             scanf("%d",&i1);
  764.             entry.cdte_track=i1;
  765.             if (entry.cdte_track<first) entry.cdte_track=first;
  766.             if (entry.cdte_track>last)  entry.cdte_track=last;
  767.             entry.cdte_format=CDROM_MSF;
  768.             rc=ioctl(drive,CDROMREADTOCENTRY,&entry);
  769.             if (rc<0) printf("CDROMREADTOCENTRY: rc=%d.\n",rc);
  770.             else
  771.             {
  772.                 printf("Mode %d Track, starts at %02d:%02d:%02d\n",
  773.                        entry.cdte_adr,
  774.                        entry.cdte_addr.msf.minute,
  775.                        entry.cdte_addr.msf.second,
  776.                        entry.cdte_addr.msf.frame);
  777.             }
  778.             break;
  779.         case 'a':
  780.             printf("Address (min:sec:frm)  ");
  781.             scanf("%d:%d:%d",&i1,&i2,&i3);
  782.             msf.cdmsf_min0=i1;
  783.             msf.cdmsf_sec0=i2;
  784.             msf.cdmsf_frame0=i3;
  785.             if (msf.cdmsf_sec0>59) msf.cdmsf_sec0=59;
  786.             if (msf.cdmsf_frame0>74) msf.cdmsf_frame0=74;
  787.             lba2msf(TocEntry[last+1].cdte_addr.lba-1,&msf.cdmsf_min1);
  788.             rc=ioctl(drive,CDROMSTOP);
  789.             rc=ioctl(drive,CDROMPLAYMSF,&msf);
  790.             if (rc<0) printf("CDROMPLAYMSF: rc=%d.\n",rc);
  791.             break;
  792. #ifdef AZT_PRIVATE_IOCTLS /*not supported by every CDROM driver*/
  793.         case 'd':
  794.             printf("Address (min:sec:frm)  ");
  795.             scanf("%d:%d:%d",&i1,&i2,&i3);
  796.             azt.msf.cdmsf_min0=i1;
  797.             azt.msf.cdmsf_sec0=i2;
  798.             azt.msf.cdmsf_frame0=i3;
  799.             if (azt.msf.cdmsf_sec0>59) azt.msf.cdmsf_sec0=59;
  800.             if (azt.msf.cdmsf_frame0>74) azt.msf.cdmsf_frame0=74;
  801.             rc=ioctl(drive,CDROMREADMODE1,&azt.msf);
  802.             if (rc<0) printf("CDROMREADMODE1: rc=%d.\n",rc);
  803.             else display(CD_FRAMESIZE,azt.buf);
  804.             break;
  805.         case 'w':
  806.             printf("Address (min:sec:frame)  ");
  807.             scanf("%d:%d:%d",&i1,&i2,&i3);
  808.             azt.msf.cdmsf_min0=i1;
  809.             azt.msf.cdmsf_sec0=i2;
  810.             azt.msf.cdmsf_frame0=i3;
  811.             if (azt.msf.cdmsf_sec0>59) azt.msf.cdmsf_sec0=59;
  812.             if (azt.msf.cdmsf_frame0>74) azt.msf.cdmsf_frame0=74;
  813.             rc=ioctl(drive,CDROMREADMODE2,&azt.msf);
  814.             if (rc<0) printf("CDROMREADMODE2: rc=%d.\n",rc);
  815.             else display(CD_FRAMESIZE_RAW,azt.buf); /* currently only 2336 */
  816.             break;  
  817. #endif
  818.         case 'v':
  819.             printf("--Channel 0 (Left)  (0-255): ");
  820.             scanf("%d",&i1);
  821.             volctrl.channel0=i1;
  822.             printf("--Channel 1 (Right) (0-255): ");
  823.             scanf("%d",&i1);
  824.             volctrl.channel1=i1;
  825.             volctrl.channel2=0;
  826.             volctrl.channel3=0;
  827.             rc=ioctl(drive,CDROMVOLCTRL,&volctrl);
  828.             if (rc<0) printf("CDROMVOLCTRL: rc=%d.\n",rc);
  829.             break;  
  830.         case 'q':
  831.             close(drive);
  832.             exit(0);
  833.         case 'h':
  834.             help();
  835.             break;
  836.         case 'T': /* display TOC entry - without involving the driver */
  837.             scanf("%d",&i);
  838.             if ((i<hdr.cdth_trk0)||(i>hdr.cdth_trk1))
  839.                 printf("invalid track number.\n");
  840.             else
  841.                 printf("TocEntry %02d: adr=%01X ctrl=%01X msf=%02d:%02d:%02d mode=%02X\n",
  842.                        TocEntry[i].cdte_track,
  843.                        TocEntry[i].cdte_adr,
  844.                        TocEntry[i].cdte_ctrl,
  845.                        TocEntry[i].cdte_addr.msf.minute,
  846.                        TocEntry[i].cdte_addr.msf.second,
  847.                        TocEntry[i].cdte_addr.msf.frame,
  848.                        TocEntry[i].cdte_datamode);
  849.             break;
  850.         case 'A': /* read audio data into file */
  851.             printf("Address (min:sec:frm) ? ");
  852.             scanf("%d:%d:%d",&i1,&i2,&i3);
  853.             read_audio.addr.msf.minute=i1;
  854.             read_audio.addr.msf.second=i2;
  855.             read_audio.addr.msf.frame=i3;
  856.             read_audio.addr_format=CDROM_MSF;
  857.             printf("# of frames ? ");
  858.             scanf("%d",&i1);
  859.             read_audio.nframes=i1;
  860.             k=read_audio.nframes*CD_FRAMESIZE_RAW;
  861.             read_audio.buf=malloc(k);
  862.             if (read_audio.buf==NULL)
  863.             {
  864.                 printf("can't malloc %d bytes.\n",k);
  865.                 break;
  866.             }
  867.             sprintf(filename,"audio_%02d%02d%02d_%02d.%02d\0",
  868.                 read_audio.addr.msf.minute,
  869.                 read_audio.addr.msf.second,
  870.                 read_audio.addr.msf.frame,
  871.                 read_audio.nframes,
  872.                 ++sequence);
  873.             datafile=creat(filename, 0755);
  874.             if (datafile<0)
  875.             {
  876.                 printf("can't open datafile %s.\n",filename);
  877.                 break;
  878.             }
  879.             rc=ioctl(drive,CDROMREADAUDIO,&read_audio);
  880.             if (rc!=0)
  881.             {
  882.                 printf("CDROMREADAUDIO: rc=%d.\n",rc);
  883.             }
  884.             else
  885.             {
  886.                 rc=write(datafile,&read_audio.buf,k);
  887.                 if (rc!=k) printf("datafile I/O error (%d).\n",rc);
  888.             }
  889.             close(datafile);
  890.             break;
  891.         case 'X': /* set EJECT_SW (0: disable, 1: enable auto-ejecting) */
  892.             scanf("%d",&i);
  893.             rc=ioctl(drive,CDROMEJECT_SW,i);
  894.             if (rc!=0)
  895.                 printf("CDROMEJECT_SW: rc=%d.\n",rc);
  896.             else
  897.                 printf("EJECT_SW set to %d\n",i);
  898.             break;
  899.         case 'M': /* get the multisession redirection info */
  900.             ms_info.addr_format=CDROM_LBA;
  901.             rc=ioctl(drive,CDROMMULTISESSION,&ms_info);
  902.             if (rc!=0)
  903.             {
  904.                 printf("CDROMMULTISESSION(lba): rc=%d.\n",rc);
  905.             }
  906.             else
  907.             {
  908.                 if (ms_info.xa_flag) printf("MultiSession offset (lba): %d (0x%06X)\n",ms_info.addr.lba,ms_info.addr.lba);
  909.                 else
  910.                 {
  911.                     printf("this CD is not an XA disk.\n");
  912.                     break;
  913.                 }
  914.             }
  915.             ms_info.addr_format=CDROM_MSF;
  916.             rc=ioctl(drive,CDROMMULTISESSION,&ms_info);
  917.             if (rc!=0)
  918.             {
  919.                 printf("CDROMMULTISESSION(msf): rc=%d.\n",rc);
  920.             }
  921.             else
  922.             {
  923.                 if (ms_info.xa_flag)
  924.                     printf("MultiSession offset (msf): %02d:%02d:%02d (0x%02X%02X%02X)\n",
  925.                            ms_info.addr.msf.minute,
  926.                            ms_info.addr.msf.second,
  927.                            ms_info.addr.msf.frame,
  928.                            ms_info.addr.msf.minute,
  929.                            ms_info.addr.msf.second,
  930.                            ms_info.addr.msf.frame);
  931.                 else printf("this CD is not an XA disk.\n");
  932.             }
  933.             break;
  934. #ifdef SBP_PRIVATE_IOCTLS
  935.         case 'Y': /* set the driver's message level */
  936. #if 0 /* not implemented yet */
  937.             printf("enter switch name (f.e. DBG_CMD): ");
  938.             scanf("%s",&dbg_switch);
  939.             j=get_dbg_num(dbg_switch);
  940. #else
  941.             printf("enter DDIOCSDBG switch number: ");
  942.             scanf("%d",&j);
  943. #endif
  944.             printf("enter 0 for \"off\", 1 for \"on\": ");
  945.             scanf("%d",&i);
  946.             if (i==0) j|=0x80;
  947.             printf("calling \"ioctl(drive,DDIOCSDBG,%d)\"\n",j);
  948.             rc=ioctl(drive,DDIOCSDBG,j);
  949.             printf("DDIOCSDBG: rc=%d.\n",rc);
  950.             break;
  951.         case 'Z': /* set the audio buffer size */
  952.             printf("# frames wanted: ? ");
  953.             scanf("%d",&j);
  954.             rc=ioctl(drive,CDROMAUDIOBUFSIZ,j);
  955.             printf("%d frames granted.\n",rc);
  956.             break;
  957.         case 'V':
  958.             rc=ioctl(drive,CDROMVOLREAD,&volctrl);
  959.             if (rc<0) printf("CDROMVOLCTRL: rc=%d.\n",rc);
  960.             printf("Volume: channel 0 (left) %d, channel 1 (right) %d\n",volctrl.channel0,volctrl.channel1);
  961.             break;  
  962.         case 'R':
  963.             rc=ioctl(drive,CDROMRESET);
  964.             if (rc<0) printf("CDROMRESET: rc=%d.\n",rc);
  965.             break;
  966.         case 'B': /* set the driver's (?) read ahead value */
  967.             printf("enter read-ahead size: ? ");
  968.             scanf("%d",&i);
  969.             rc=ioctl(drive,BLKRASET,i);
  970.             if (rc<0) printf("BLKRASET: rc=%d.\n",rc);
  971.             break;
  972. #endif SBP_PRIVATE_IOCTLS
  973.         default:
  974.             printf("unknown command: \"%s\".\n",command);
  975.             break;
  976.         }
  977.     }
  978. }
  979. /*==========================================================================*/
  980. /*
  981.  * Overrides for Emacs so that we follow Linus's tabbing style.
  982.  * Emacs will notice this stuff at the end of the file and automatically
  983.  * adjust the settings for this buffer only.  This must remain at the end
  984.  * of the file. 
  985.  * ---------------------------------------------------------------------------
  986.  * Local variables:
  987.  * c-indent-level: 8
  988.  * c-brace-imaginary-offset: 0
  989.  * c-brace-offset: -8
  990.  * c-argdecl-indent: 8
  991.  * c-label-offset: -8
  992.  * c-continued-statement-offset: 8
  993.  * c-continued-brace-offset: 0
  994.  * End:
  995.  */
  996.  
  997.