⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 discinfo.c

📁 详细介绍DVD的读碟片程序:TOC表
💻 C
📖 第 1 页 / 共 4 页
字号:
                 bHiByte(wLoWord(dLBA)),
                 bLoByte(wLoWord(dLBA)));

      if (_bPlayerStatus == PLAYER_READY)
      {
        WriteDEC(RW_TRIG, READTRG + TARGETTRG + DECTRG);
      }
      else
      {
        _fgDecErr = TRUE;        // Take As A Decode Error
      }
    }

    //////////////////// check if TDB is buffered /////////////////////////
    ReadBLK(RW_DBLK, wTmp);

    if (wTmp)
    {
      StopDecoder();

      if (bReadDEC(RD_HDR3) == 1)         // Is this TDB mode 1?
      {
        dLBA = dReadDRAML4(0, 4);        // expect 'TDI' at offset 4

        if ((bHiByte(wHiWord(dLBA)) != 'T') || // 0x54
            (bLoByte(wHiWord(dLBA)) != 'D') || // 0x44
            (bHiByte(wLoWord(dLBA)) != 'I'))   // 0x49
        {
          _fgDecErr = TRUE;
        }
        else
        {
          dLBA = dReadDRAML4(0, 13);
        }
      }
      else if (bReadDEC(RD_HDR3) == 2)      // Is this TDB mode 2?
      {
        dLBA = dReadDRAML4(0, 12);          // expect 'TDI' at offset 4

        if ((bHiByte(wHiWord(dLBA)) != 'T') || // 0x54
            (bLoByte(wHiWord(dLBA)) != 'D') || // 0x44
            (bHiByte(wLoWord(dLBA)) != 'I'))   // 0x49
        {
          _fgDecErr = TRUE;
        }
        else
        {
          dLBA = dReadDRAML4(0, 21);
        }
      }
      else
      {
        _fgDecErr = TRUE;
      }

      if (!_fgDecErr)
      {
        if (bHiByte(wHiWord(dLBA)) == 0x91)   // fixed packet?
        {
          return (dBCDToBin(dLBA));
        }
        else
        {
          return (0);      // it's variable packet
        }
      }
    }
  } while (TRUE);
}

/***************************************************************************
     Function : bDIChkSectorType(BIT fgPhysical)
  Dsecription : CHECK THE REQUESTED SECTOR TYPE (for CD)
                Note :
                Sectors start at '_dStartAddr', and extend to a length
                of '_dXferBlkLen'.
                If 'fgPhysical' is 1, no method 2 address translation will
                be performed.
                If 'fgPhysical' is 0, method 2 addressing will be used if
                'start' is in a track of fixed-length packets.
                CHECK THE LAYER TYPE (for DVD)
                Note :
                Check data at layer0, layer1, or between layer0 and layer1
    Parameter : Physical flag
       Return : 0x40 = LBA out of range
                0x20 = Cross regions
                0x21 = Cross regions start with audio sectors
                0x22 = Cross region start with data sectors,
                       method 1 addressing
                0x05 = sectors in Leadin or Leadout region
                0x03 = data sectors, method 2 addressing, fixed packet
                0x04 = data sectors, method 1 addressing, variable packet
                0x02 = data sectors, not incremental packet writing
                0x01 = audio sectors
***************************************************************************/
BYTE bDIChkSectorType(BIT fgPhysical)
{
  WORD wDMPtr = 0;
  DWRD dLBA, dTmpLBA;
  BYTE bType;

  // Invalid LBA, Host give a wrong ATAPI Command -- add by YS
  if (bHiByte(wHiWord(_dStartAddr)) || bHiByte(wHiWord(_dXferBlkLen)))
  {
    return (0x40);      // End Has Exceeded The Last Lead Out
  }

  bType = bDIQuickChkSectorType();

  if (bType != 0)
  {
    if (bType == DATA_TRACK_FIXED_PKT)  // Packet Writing Track, To Setup Packet Info
    {
      wDMPtr = 12;          // Skip the First Disc Map Entry.

      bHiByte(wHiWord(dLBA)) = 0;
      bLoByte(wHiWord(dLBA)) = bLoByte(wHiWord(_dDiscMap));
      bHiByte(wLoWord(dLBA)) = bHiByte(wLoWord(_dDiscMap));
      bLoByte(wLoWord(dLBA)) = bLoByte(wLoWord(_dDiscMap));

      goto lbPktWriteTrk;
    }
    else
    {
      return (bType);       // Quick Check Ok
    }
  }

  wDMPtr = 12;              // Skip the First Disc Map Entry.

  do
  {
    dLBA = dReadDMMem4(wDMPtr);

    wDMPtr += 12;                       // Point to Next Record

    bType = bHiByte(wHiWord(dLBA));

    bHiByte(wHiWord(dLBA)) = 0;
  }  while (_dStartAddr >= dLBA);       // 'dLBA' is end of region

  if (bType == DATA_TRACK_FIXED_PKT)    // is a fixed packet written track?
  {
lbPktWriteTrk:

    dTmpLBA = dReadDMMem4(wDMPtr - 8);

    // store start LBA of the track
    _rCoVar6.rCDPktInfo.rTrkStrtLBA.bHi = bLoByte(wHiWord(dTmpLBA));
    _rCoVar6.rCDPktInfo.rTrkStrtLBA.bMe = bHiByte(wLoWord(dTmpLBA));
    _rCoVar6.rCDPktInfo.rTrkStrtLBA.bLo = bLoByte(wLoWord(dTmpLBA));

    dTmpLBA = dReadDMMem4(wDMPtr - 4);

    // store packet size of the track
    _rCoVar6.rCDPktInfo.rPktLen.bHi = bLoByte(wHiWord(dTmpLBA));
    _rCoVar6.rCDPktInfo.rPktLen.bMe = bHiByte(wLoWord(dTmpLBA));
    _rCoVar6.rCDPktInfo.rPktLen.bLo = bLoByte(wLoWord(dTmpLBA));

    if (fgPhysical)       // use physical
    {
      dTmpLBA = _dStartAddr + _dXferBlkLen - 1;   // address
    }
    else
    {
      // convert LBA to PBA (Physical Block Address)
      dTmpLBA = dLBAToPBA(_dStartAddr + _dXferBlkLen - 1);
    }

    if (dTmpLBA < dLBA)
    {
      // always return 2 if fgPhysical = 1
      return (fgPhysical ? DATA_TRACK_VAR_PKT : DATA_TRACK_FIXED_PKT);
    }
    // else return 3 (fixed packet data track)
    else if (dTmpLBA > _dMaxLBA)
    {
      return (0x40);      // End Has Exceeded The Last Lead Out
    }
    else
    {
      return (0x20);      // The Sectors Cross Two Different Regions.
    }
  }
  else if (bType)         // an audio or data track?
  {
#ifdef INTERNAL_TEST
    dTmpLBA = _dStartAddr + _dXferBlkLen - 1;

    if (dTmpLBA < dLBA)
    {
      return (bType);     // Sector Type. 1:Audio, 2:Data, 4:LeadIn/LeadOut
    }
    else if (dTmpLBA > _dMaxLBA)
    {
      return (0x40);      // End Has Exceeded The Last Lead Out
    }
    else
    {
      return (bType | 0x20);      // The Sectors Cross Two Different Regions.
    }
#else // for release
    return (bType);      // we do not check the LBA range
#endif
  }
  else
  {
#ifdef INTERNAL_TEST
    return (0x40);        // Start Has Exceeded The Last Lead Out
#else // for release
    return (DATA_TRACK);  // treat as a data track
#endif
  }
}

/***************************************************************************
     Function : bDIChkLayerType(void)
  Dsecription : CHECK THE REQUESTED LAYER TYPE for DVD
                set _bSeekLayer and _fgCrossLayer
    Parameter : None
       Return : 0x40 = LBA out of range
                0x02 = Data area
***************************************************************************/
BYTE bDIChkLayerType(void)
{
  DWRD dLBA;

  dLBA = _dStartAddr + _dXferBlkLen - 1;

  if (dLBA > _dMaxLBA)
  {
    if (_dStartAddr > _dMaxLBA)
    {
      return (0x40);
    }
    else
    {
      _dXferBlkLen = _dMaxLBA - _dStartAddr + 1;
      dLBA = _dMaxLBA;
    }
  }
  _bSeekLayer = SEEK_LAYER0;      // data in Layer 0
  _fgCrossLayer = FALSE;          // data is only in one layer

  if (dLBA > _dEndPSN0)
  {
    if (_dStartAddr <= _dEndPSN0)
    {
      _fgCrossLayer = TRUE;
    }
    else
    {
      if ((bReadDEC(RW_TARR) & 0x01) == SEEK_LAYER0)  //still is in Layer 0
      {
        StopDecoder();
        InvalidBuffer();
      }

      _bSeekLayer = SEEK_LAYER1;  // data in Layer 1
    }
  }

  return (0x02);
}

#ifdef SUPPORT_DTS_CD
/***************************************************************************
     Function : BOOL fgChkDTSCD(void)
  Dsecription : check if this Disc is DTS CD or not
    Parameter : None
       Return : TRUE - DTS CD
                FALSE - not DTS CD
***************************************************************************/
BOOL fgChkDTSCD(void)
{
  BYTE bIdx;
  WORD wTocIdx;
  DWRD dSeekPos;
  BOOL fgSeek;

  StopDecoder();              // Stop Decoding if Cache Miss

  for(bIdx=_bFirstTNo, wTocIdx=7; bIdx<=_bLastTNo; bIdx++, wTocIdx+=6)
  {
    if ((bReadTOCMem(wTocIdx) & 0x40) == 0)
    {
      bLoByte(wHiWord(dSeekPos)) = bReadTOCMem(wTocIdx + 2);
      bHiByte(wLoWord(dSeekPos)) = bReadTOCMem(wTocIdx + 3);
      bLoByte(wLoWord(dSeekPos)) = bReadTOCMem(wTocIdx + 4);
      break;
    }
    else
    {
      wLoWord(dSeekPos) += 6;
    }
  }

  fgSeek = TRUE;
  _bRDRetryCnt = 0;
  SRVSetSpeed(LEADIN_CD_SPEED);

  WriteDEC(RW_MCIER, bReadDEC(RW_MCIER) | DTSEN);
  MCDRdSeek2(bLoByte(wHiWord(dSeekPos)),
             bHiByte(wLoWord(dSeekPos)),
             bLoByte(wLoWord(dSeekPos)));
  WriteDEC(RW_MCIER, bReadDEC(RW_MCIER) & (~DTSEN));

  do
  {
    //////////////////////// Status Checking Stage //////////////////////////
    if ((_fgAbort) ||      // Abort Command !!
        ((!fgSeek) && (_wPauseTimer > DTS_CD_DETECT_TIMEOUT)) ||
        (_bRDRetryCnt >= 5))      // retry 5 times at most
    {
      // disable DTS detection
      WriteDEC(RW_MCIER, bReadDEC(RW_MCIER) & (~DTSEN));
      return (FALSE);   // not DTS CD
    }

    ////////////////////////// Error Handling Stage /////////////////////////
    if (_testbit_(fgSeek))
    {
      MCDRdSeek2(bLoByte(wHiWord(dSeekPos)),
                 bHiByte(wLoWord(dSeekPos)),
                 bLoByte(wLoWord(dSeekPos)));

      if (_bPlayerStatus == PLAYER_READY)
      { // enable DTS CD detection
        WriteDEC(RW_MCIER, bReadDEC(RW_MCIER) | DTSEN);
        _wPauseTimer = 0;   // reset time counter
      }
      else
      {
        fgSeek = TRUE;
        ++_bRDRetryCnt;
      }
    }

    if (bReadDEC(RD_MCSTA) & (DTS14+DTS16))
    {
      // disable DTS detection
      WriteDEC(RW_MCIER, bReadDEC(RW_MCIER) & (~DTSEN));
      return (TRUE);
    }
  } while (TRUE);
}
#endif

/************************************************************************
     Function : BYTE bDIQuickChkSectorType(void)
  Dsecription : Quickly check the type of sectors starting from
                _dStartAddr and extending _dXferBlkLen sectors.
                The function utilizes
                _dDiscMap(bTrkType,bTrkEndH,bTrkEndM,bTrkEndL)
                as storage of the very first disc map record.

    Parameter : None
       Return : 0x40 = LBA out of range
                0x20 = Cross regions
                0x21 = Cross regions start with audio sectors
                0x22 = Cross region start with data sectors,
                       method 1 addressing
                0x04 = sectors in Leadin or Leadout region
                0x03 = data sectors, method 2 addressing
                0x02 = data sectors, method 1 addressing
                0x01 = audio sectors
                0x00 = not decided yet
************************************************************************/
BYTE bDIQuickChkSectorType(void)
{
  DWRD dTmpMap, dTmpLBA;

  dTmpMap = _dDiscMap;
  bHiByte(wHiWord(dTmpMap)) = 0;

  if (dTmpMap > _dStartAddr)               // first map lba > _dStartAddr
  {
#ifdef INTERNAL_TEST
    dTmpLBA = _dStartAddr + _dXferBlkLen - 1;
    // first map lba > _dStartAddr + dXferBlkLen -1
    if (dTmpMap > dTmpLBA)
    {
      return (bHiByte(wHiWord(_dDiscMap)));       // first disc track type
    }
    else
    {
      if (dTmpLBA > _dMaxLBA)    // _dStartAddr + _dXFerBlkLen -1 > _dMaxLBA
      {
        return (0x40);
      }
      else
      {
        return (0x20 | bHiByte(wHiWord(_dDiscMap)));   // Cross two region
      }
    }
#else // for release
    return (bHiByte(wHiWord(_dDiscMap)));       // we do not check the LBA range
#endif
  }
  else
  {
    return (0x00);        // return 0 if _dStartAddr >= first map lba
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -