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