home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cdrom.zip / DDK / BASE / SRC / DEV / DASD / CDROM / OS2CDROM / cdtosh.c < prev    next >
C/C++ Source or Header  |  1996-06-18  |  11KB  |  405 lines

  1. /**************************************************************************
  2.  *
  3.  * SOURCE FILE NAME = CDTOSH.C
  4.  *
  5.  * DESCRIPTIVE NAME = Vendor unique command processing Toshiba SCSI-2
  6.  *                    CD-ROM Drives
  7.  *
  8.  * Copyright : COPYRIGHT IBM CORPORATION, 1991, 1992
  9.  *             LICENSED MATERIAL - PROGRAM PROPERTY OF IBM
  10.  *             REFER TO COPYRIGHT INSTRUCTION FORM#G120-2083
  11.  *             RESTRICTED MATERIALS OF IBM
  12.  *             IBM CONFIDENTIAL
  13.  *
  14.  * VERSION = V2.0
  15.  *
  16.  * DATE
  17.  *
  18.  * DESCRIPTION
  19.  *
  20.  *
  21.  * FUNCTIONS
  22.  *
  23.  * ENTRY POINTS:
  24.  *
  25.  * DEPENDENCIES:
  26.  *
  27.  * NOTES
  28.  *
  29.  *
  30.  * STRUCTURES
  31.  *
  32.  * EXTERNAL REFERENCES
  33.  *
  34.  * EXTERNAL FUNCTIONS
  35.  *
  36.  * CHANGE ACTIVITY =
  37.  *  DATE      FLAG        APAR   CHANGE DESCRIPTION
  38.  *  --------  ----------  -----  --------------------------------------
  39.  *  mm/dd/yy  @Vr.mpppxx  xxxxx  xxxxxxx
  40.  ****************************************************************************/
  41.  
  42. #include "cdh.h"
  43. #include "tocdb.h"
  44.  
  45. USHORT Tosh_Read_2352_NoCDDA (NPUNITCB, ULONG, USHORT, ULONG);
  46.  
  47.  
  48. /****************************************************************************
  49.  *
  50.  * FUNCTION NAME = Tosh_Read_2048
  51.  *
  52.  * DESCRIPTION   = Read 2048 byte sectors for Toshiba 3301 & 3401
  53.  *
  54.  *      USHORT Tosh_Read_2048      (NPUNITCB pUnitCB, ULONG LBA,
  55.  *                                   USHORT transfer_count, ULONG ppDataBuff)
  56.  *
  57.  * INPUT         = pUnitCB          - Pointer to UnitCB
  58.  *                 LBA              - LBA
  59.  *                 transfer_count   - count of sectors to transfer
  60.  *                 ppDataBuff       - phys addr of data buffer
  61.  *
  62.  * OUTPUT        = USHORT           - Packet Status word
  63.  *
  64.  * RETURN-NORMAL =
  65.  * RETURN-ERROR  =
  66.  *
  67.  ****************************************************************************/
  68.  
  69. USHORT Tosh_Read_2048 (pUnitCB, LBA, transfer_count, ppDataBuff)
  70.  
  71. NPUNITCB pUnitCB;
  72. ULONG    LBA;
  73. USHORT   transfer_count;
  74. ULONG    ppDataBuff;
  75.  
  76. {
  77.    USHORT disk_density, rc;
  78.  
  79.    /*
  80.    ** Make sure the density is set properly for Toshiba 3301 drives
  81.    */
  82.    disk_density = pUnitCB->DeviceInfo.disk_density;
  83.  
  84.    if (LBA == 0L && transfer_count == 1)
  85.    {
  86.       if ( (rc = Tosh_GetDensityCode (pUnitCB, (USHORT FAR *) &disk_density))
  87.                                                                     & STERR)
  88.          return (rc);
  89.  
  90.       pUnitCB->DeviceInfo.disk_density = disk_density;
  91.    }
  92.  
  93.    if (disk_density == CD_DENSITY_CDDA)
  94.       return (STDON + STERR + ERROR_I24_SECTOR_NOT_FOUND);
  95.  
  96.    /*
  97.    ** Issue mode select if density code or block length is not right
  98.    */
  99.    if ( ((pUnitCB->DeviceInfo.current_density == CD_DENSITY_CDDA) ||
  100.          (pUnitCB->DeviceInfo.current_density != disk_density)    ||
  101.          (pUnitCB->DeviceInfo.current_block_size != 2048))        &&
  102.          (pUnitCB->DeviceInfo.current_density != CD_DENSITY_CDXA_83) )
  103.    {
  104.  
  105.       /* Set density code to 0x83 if stock Toshiba 3401 since it */
  106.       /* has a firmware bug with density code 0x81               */
  107.  
  108.       if ( (pUnitCB->DeviceInfo.vendor_id_code == TOSHIBA) &&
  109.            (pUnitCB->DeviceInfo.product_id_code == TOSHIBA_3401) )
  110.       {
  111.          disk_density = CD_DENSITY_CDXA_83;
  112.       }
  113.  
  114.       rc = ChainModeSelectRead (pUnitCB, LBA, transfer_count,
  115.                                          ppDataBuff, 2048, disk_density);
  116.    }
  117.    else
  118.    {
  119.       rc = ReadSector (pUnitCB, LBA, transfer_count, ppDataBuff, 2048);
  120.    }
  121.    return (rc);
  122. }
  123.  
  124.  
  125. /****************************************************************************
  126.  *
  127.  * FUNCTION NAME = Tosh_Read_2352
  128.  *
  129.  * DESCRIPTION   = Read 2352 byte sectors for Toshiba 3301 & 3401
  130.  *
  131.  *     USHORT Tosh_Read_2352  (NPUNITCB pUnitCB, ULONG LBA,
  132.  *                                 USHORT transfer_count, ULONG ppDataBuff)
  133.  *
  134.  * INPUT         = pUnitCB          - Pointer to UnitCB
  135.  *                 ul_LBA           - LBA
  136.  *                 transfer_count   - count of sectors to transfer
  137.  *                 ppDataBuff       - phys addr of data buffer
  138.  *
  139.  * OUTPUT        = USHORT           - Packet Status word
  140.  *
  141.  * RETURN-NORMAL =
  142.  * RETURN-ERROR  =
  143.  *
  144.  ****************************************************************************/
  145.  
  146. USHORT Tosh_Read_2352 (pUnitCB, LBA, transfer_count, ppDataBuff)
  147.  
  148. NPUNITCB pUnitCB;
  149. ULONG    LBA;
  150. USHORT   transfer_count;
  151. ULONG    ppDataBuff;
  152.  
  153. {
  154.    USHORT rc, density;
  155.  
  156.    /*
  157.    ** If this is a Toshiba drive that doesnt support reading CD-DA
  158.    ** audio sectors, then just try reading 2352 XA.
  159.    */
  160.    if ( (pUnitCB->DeviceInfo.vendor_id_code == TOSHIBA) &&
  161.         ( !(pUnitCB->DeviceInfo.Audio.capabilities & DCAPS_CDDA) ) )
  162.    {
  163.        rc = Tosh_Read_2352_NoCDDA (pUnitCB, LBA, transfer_count, ppDataBuff);
  164.        return(rc);
  165.    }
  166.  
  167.    /*
  168.    ** If current block size is not 2352, issue Mode Select prior to
  169.    ** the read.
  170.    */
  171.    if (pUnitCB->DeviceInfo.current_block_size != 2352)
  172.    {
  173.       rc = ChainModeSelectRead (pUnitCB, LBA, transfer_count,
  174.                                          ppDataBuff, 2352, CD_DENSITY_CDDA);
  175.    }
  176.    else
  177.    {
  178.       rc = ReadSector (pUnitCB, LBA, transfer_count, ppDataBuff, 2352);
  179.    }
  180.  
  181.    /*
  182.    ** If a read error occurred, try changing the density code and
  183.    ** reissuing the the read command.
  184.    */
  185.    if ( (rc == STDON + STERR + ERROR_I24_BAD_COMMAND) ||
  186.         (rc == STDON + STERR + ERROR_I24_SEEK) )
  187.    {
  188.       if (pUnitCB->DeviceInfo.current_density != CD_DENSITY_CDDA)
  189.          density = CD_DENSITY_CDDA;
  190.       else if (pUnitCB->DeviceInfo.disk_density != CD_DENSITY_CDDA)
  191.          density = pUnitCB->DeviceInfo.disk_density;
  192.       else
  193.          goto Tosh_Exit;
  194.  
  195.       rc = ChainModeSelectRead (pUnitCB, LBA, transfer_count,
  196.                                          ppDataBuff, 2352, density);
  197.    }
  198.  
  199. Tosh_Exit:
  200.    return(rc);
  201. }
  202.  
  203.  
  204. /****************************************************************************
  205.  *
  206.  * FUNCTION NAME = Tosh_Read_2352_NoCDDA
  207.  *
  208.  * DESCRIPTION   = Read 2352 byte sectors for Toshiba 3301
  209.  *
  210.  *   USHORT Tosh_Read_2352_NoCDDA  (NPUNITCB pUnitCB, ULONG LBA,
  211.  *                                    USHORT transfer_count, ULONG ppDataBuff)
  212.  *
  213.  * INPUT         = pUnitCB          - Pointer to UnitCB
  214.  *                 ul_LBA           - LBA
  215.  *                 transfer_count   - count of sectors to transfer
  216.  *                 ppDataBuff       - phys addr of data buffer
  217.  *
  218.  * OUTPUT        = USHORT           - Packet Status word
  219.  *
  220.  * RETURN-NORMAL =
  221.  * RETURN-ERROR  =
  222.  *
  223.  ****************************************************************************/
  224.  
  225. USHORT Tosh_Read_2352_NoCDDA (pUnitCB, LBA, transfer_count, ppDataBuff)
  226.  
  227. NPUNITCB pUnitCB;
  228. ULONG    LBA;
  229. USHORT   transfer_count;
  230. ULONG    ppDataBuff;
  231.  
  232. {
  233.    USHORT rc, disk_density;
  234.  
  235.    /*
  236.    ** If current block size is not 2352, issue Mode Select prior to
  237.    ** the read.
  238.    */
  239.    disk_density = pUnitCB->DeviceInfo.disk_density;
  240.  
  241.    if ( (pUnitCB->DeviceInfo.current_density != disk_density) ||
  242.         (pUnitCB->DeviceInfo.current_block_size != 2352) )
  243.    {
  244.       rc = ChainModeSelectRead (pUnitCB, LBA, transfer_count,
  245.                                          ppDataBuff, 2352, disk_density);
  246.    }
  247.    else
  248.    {
  249.       rc = ReadSector (pUnitCB, LBA, transfer_count, ppDataBuff, 2352);
  250.    }
  251.  
  252.  
  253.    return(rc);
  254. }
  255.  
  256.  
  257. /****************************************************************************
  258.  *
  259.  * FUNCTION NAME = Tosh_GetDensityCode
  260.  *
  261.  * DESCRIPTION   = Get density code for sector zero.
  262.  *
  263.  *    This routine returns the density code for sector zero.  This routine
  264.  *    should only be called if the drive is a Toshiba 3301.
  265.  *
  266.  *    USHORT Tosh_GetDensityCode  (NPUNITCB pUnitCB, USHORT FAR * density_code)
  267.  *
  268.  * INPUT         = pUnitCB          - Pointer to UnitCB
  269.  *                 density_code     - Density Code
  270.  *                                    00 = CD-ROM
  271.  *                                    81 = CD-ROM XA
  272.  *                                    82 = CD-DA
  273.  *
  274.  * OUTPUT        = USHORT           - Packet status word
  275.  *
  276.  * RETURN-NORMAL =
  277.  * RETURN-ERROR  =
  278.  *
  279.  ****************************************************************************/
  280.  
  281. USHORT Tosh_GetDensityCode (pUnitCB, density_code)
  282.  
  283. NPUNITCB pUnitCB;
  284. USHORT   FAR *density_code;
  285.  
  286. {
  287.    USHORT rc;
  288.    NPIORB_CDB pIORB;
  289.    struct ReadHeader_Data NEAR *pCDBData;
  290.  
  291.  
  292.    BuildCDB_ReadHeader(pUnitCB, 0, (NPIORB_CDB FAR *) &pIORB);
  293.  
  294.    pCDBData = (struct ReadHeader_Data NEAR *) pIORB->CDB_data;
  295.  
  296.    rc = SubmitIORB_Wait(pUnitCB, pIORB);
  297.  
  298.    if (rc == STDON)
  299.    {
  300.       switch(pCDBData->cdrom_data_mode)
  301.       {
  302.          case 0x02:
  303.             *density_code = CD_DENSITY_CDXA;
  304.             break;
  305.  
  306.          case 0x00:
  307.          case 0x01:
  308.          default:
  309.             *density_code = CD_DENSITY_DEFAULT;
  310.             break;
  311.       }
  312.    }
  313.    else
  314.    {
  315.       if (rc == STDON + STERR + ERROR_I24_BAD_COMMAND)
  316.       {
  317.          *density_code = CD_DENSITY_CDDA;
  318.          rc = STDON;
  319.       }
  320.    }
  321.    FreeIORB (pUnitCB, pIORB);
  322.    return (rc);
  323. }
  324.  
  325.  
  326. /****************************************************************************
  327.  *
  328.  * FUNCTION NAME = Tosh_GetLastSessionAddr
  329.  *
  330.  * DESCRIPTION   = Get address of last session on multisession disk
  331.  *
  332.  *   This routine returns the address of the last session of a multisession
  333.  *   photo CD disk.  This routine should only be called is the drive is
  334.  *   a Toshiba 3401 or the drive is a non-SCSI CD-ROM which supports
  335.  *   multi-session.
  336.  *
  337.  *   USHORT Tosh_GetLastSessionAddr (NPUNITCB pUnitCB, ULONG FAR * session_addr)
  338.  *
  339.  * INPUT         =  pUnitCB          - Pointer to UnitCB
  340.  *                  session_addr     - Pointer to returned session addr
  341.  *
  342.  * OUTPUT        =  USHORT           - Packet status word
  343.  *
  344.  *                                     if the STERR bit is on, then the disk
  345.  *                                       is not a multisession disk and the
  346.  *                                       session_addr field is not valid
  347.  *
  348.  *                                     if the STERR bit is NOT set, then the
  349.  *                                       disk is a multi-session disk and the
  350.  *                                       session addr field is valid
  351.  *
  352.  * RETURN-NORMAL =
  353.  * RETURN-ERROR  =
  354.  *
  355.  ****************************************************************************/
  356.  
  357. USHORT Tosh_GetLastSessionAddr (pUnitCB, session_addr)
  358.  
  359. NPUNITCB pUnitCB;
  360. ULONG    FAR *session_addr;
  361.  
  362. {
  363.    USHORT rc;
  364.    NPIORB_CDB pIORB;
  365.    union TOSH_ReadDiskInfo_Data NEAR *pCDBData;
  366.    union  AddressType last_session;
  367.  
  368.  
  369.    Tosh_BuildCDB_ReadDiskInfo (pUnitCB, TOSH_LASTSESSION_INFO,
  370.                                         (NPIORB_CDB FAR *) &pIORB);
  371.  
  372.    pCDBData = (union TOSH_ReadDiskInfo_Data NEAR *) pIORB->CDB_data;
  373.  
  374.    rc = SubmitIORB_Wait(pUnitCB, pIORB);
  375.  
  376.    if (rc == STDON)
  377.    {
  378.       /*
  379.       ** If zero returned in data fields, then not multisession
  380.       */
  381.       if ( (pCDBData->last_session.amin == 0) &&
  382.            (pCDBData->last_session.asec == 0) &&
  383.            (pCDBData->last_session.aframe == 0) )
  384.       {
  385.          rc = STDON + STERR;
  386.       }
  387.       else
  388.       {
  389.          last_session.ul_redbook.min = BCDtoBinary(pCDBData->last_session.amin);
  390.          last_session.ul_redbook.sec = BCDtoBinary(pCDBData->last_session.asec);
  391.          last_session.ul_redbook.frame =
  392.                                  BCDtoBinary(pCDBData->last_session.aframe);
  393.          last_session.ul_redbook.zero = 0;
  394.  
  395.          last_session.dword = RedBookToHSG (last_session.dword);
  396.  
  397.          *session_addr = last_session.dword;
  398.       }
  399.  
  400.    }
  401.    FreeIORB (pUnitCB, pIORB);
  402.    return (rc);
  403. }
  404.  
  405.