2 * FryingPan - Amiga CD/DVD Recording Software (User Interface and supporting Libraries only)
3 * Copyright (C) 2001-2011 Tomasz Wiszkowski Tomasz.Wiszkowski at gmail.com
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public License
7 * as published by the Free Software Foundation; either version 2.1
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "Disc_CD_RW.h"
23 #include "CfgCDInfo.h"
26 Disc_CD_RW::Disc_CD_RW(Drive
*d
) : Disc_CD_R(d
)
30 readfmtcaps
= new cmd_ReadFormatCapacities(dio
);
34 void Disc_CD_RW::Init(void)
39 Disc_CD_RW::~Disc_CD_RW(void)
44 int Disc_CD_RW::EraseDisc(int met
)
46 cmd_Blank::BlankType type
;
48 cmd_StartStopUnit
ssu(dio
);
50 ssu
.setType(cmd_StartStopUnit::StartStop_Start
);
57 case DRT_Blank_Complete
:
58 meas
= drive
->GetHardwareConfig()->CDInfo()->getCBlankMeas(atip
->GetLeadOutPos(), GetWriteSpeed());
62 meas
= drive
->GetHardwareConfig()->CDInfo()->getQBlankMeas(atip
->GetLeadOutPos(), GetWriteSpeed());
70 err
= SetWriteMethod(DRT_WriteMethod_TAO
);
74 case DRT_Blank_Complete
:
75 type
= cmd_Blank::Blank_All
;
78 type
= cmd_Blank::Blank_Minimal
;
80 case DRT_Blank_Session
:
81 type
= cmd_Blank::Blank_Session
;
84 return ODE_IllegalParameter
;
89 cmd_Blank
*blk
= new cmd_Blank(dio
);
90 blk
->setType(type
, 0);
91 blk
->setImmediate(true);
99 if ((err
== ODE_OK
) && (0 != meas
))
104 // if (err == ODE_OK) Init();
111 int Disc_CD_RW::FormatDisc(int met
)
114 cmd_StartStopUnit
ssu(dio
);
116 ssu
.setType(cmd_StartStopUnit::StartStop_Start
);
119 err
= SetWriteMethod(DRT_WriteMethod_Packet
);
123 // if (readfmtcaps->IsFormatted())
128 fmt
= new cmd_Format(dio
);
132 meas
= drive
->GetHardwareConfig()->CDInfo()->getCFormatMeas(atip
->GetLeadOutPos(), GetWriteSpeed());
136 // fmt->setType(cmd_Format::Format_MRW_FullFormat, 0xffffffff, 0);
137 // fmt->setImmediate(0);
139 fmt
->setType(cmd_Format::Format_CD_DVD_FullFormat
, readfmtcaps
->GetMaxCapacity(), 0);
140 fmt
->setImmediate(true);
148 if ((err
== ODE_OK
) && (0 != meas
))
161 int Disc_CD_RW::StructureDisc(void)
164 err
= EraseDisc(DRT_Blank_Fast
);
169 int Disc_CD_RW::CloseDisc(int lType
, int lTrack
)
171 if (DiscType() != DRT_Profile_CD_MRW
)
172 return Disc_CD_R::CloseDisc(lType
, lTrack
);
174 cmd_Close
*cl
= new cmd_Close(dio
);
176 cl
->setType(cmd_Close::Close_FlushBuffers
, 0);
177 cl
->setImmediate(true);
181 if (lType
== DRT_Close_Track
) {
182 cl
->setType(cmd_Close::Close_FlushBuffers
, 0);
183 } else if (lType
== DRT_Close_Session
) {
184 cl
->setType(cmd_Close::Close_CDMRW_StopFormat
, 0);
185 } else if (lType
== DRT_Close_Finalize
) {
186 cl
->setType(cmd_Close::Close_CDMRW_Finalize
, 0);
190 * do not let immediate go up here. immediate flush causes problems.
192 //cl->setImmediate(true);
193 int error
= cl
->Go();
199 bool Disc_CD_RW::AllowMultiSessionLayout()
201 if (DiscType() == DRT_Profile_CD_MRW
)
204 return Disc_CD_R::AllowMultiSessionLayout();
207 bool Disc_CD_RW::AllowMultiTrackLayout()
209 if (DiscType() == DRT_Profile_CD_MRW
)
212 return Disc_CD_R::AllowMultiTrackLayout();
215 int Disc_CD_RW::SessionGapSize()
217 if (DiscType() == DRT_Profile_CD_MRW
)
220 return Disc_CD_R::SessionGapSize();
223 int Disc_CD_RW::TrackGapSize()
225 if (DiscType() == DRT_Profile_CD_MRW
)
228 return Disc_CD_R::TrackGapSize();
231 int Disc_CD_RW::DiscType()
234 return DRT_Profile_CD_MRW
;
235 return DRT_Profile_CD_RW
;
238 int Disc_CD_RW::DiscSubType()
242 _D(Lvl_Info
, "Analysing ATIP data...");
243 switch (atip
->GetDiscSubType())
246 _D(Lvl_Debug
, "Got Low-Speed rewritable disc.");
247 return DRT_SubType_CD_RW_LowSpeed
;
249 _D(Lvl_Debug
, "Got High-Speed rewritable disc.");
250 return DRT_SubType_CD_RW_HighSpeed
;
252 _D(Lvl_Debug
, "Got Ultra-Speed rewritable disc.");
253 return DRT_SubType_CD_RW_UltraSpeed
;
255 _D(Lvl_Debug
, "Unknown disc sub type %ld.", atip
->GetDiscSubType());
256 return DRT_SubType_Unknown
;
261 _D(Lvl_Debug
, "No atip data, unknown disc sub type.");
262 return DRT_SubType_Unknown
;
266 bool Disc_CD_RW::IsOverwritable(void)
268 if (DiscType() == DRT_Profile_CD_MRW
)
271 cmd_GetConfiguration::Feature
*x
;
273 x
= drive
->GetDriveFeature(cmd_GetConfiguration::Feature_RigidOverwrite
);
275 if (x
->IsCurrent()) return true;
277 x
= drive
->GetDriveFeature(cmd_GetConfiguration::Feature_RestrictedOverwrite
);
279 if (x
->IsCurrent()) return true;
285 bool Disc_CD_RW::IsWritable(void)
287 if (DiscType() == DRT_Profile_CD_MRW
)
289 return Disc_CD_R::IsWritable();
292 bool Disc_CD_RW::IsFormatted()
294 if (0 == readfmtcaps
)
296 // FIXME: Zwracamy false poki nie naprawimy IsFormatted()!!!
297 // if (readfmtcaps->IsFormatted())
302 bool Disc_CD_RW::IsFormatable()
304 if (drive
->GetDriveFeature(cmd_GetConfiguration::Feature_CD_MRW
))
309 int Disc_CD_RW::CheckItemData(const IOptItem
*pDI
)
311 if (DiscType() != DRT_Profile_CD_MRW
)
313 return Disc_CD_R::CheckItemData(pDI
);
316 if (pDI
->getPreGapSize() != 0)
318 _D(Lvl_Error
, "Pad size other than 0 not allowed");
319 return ODE_BadLayout
;
321 if (pDI
->isIncremental())
323 _D(Lvl_Error
, "Incremental tracks not allowed");
324 return ODE_BadLayout
;
326 if (pDI
->hasCDText())
328 _D(Lvl_Error
, "CD-Text allowed only on CD media");
329 return ODE_BadLayout
;
331 if (pDI
->isPreemphasized())
333 _D(Lvl_Error
, "Preemphasy allowed only on CD media");
334 return ODE_BadLayout
;
337 if (pDI
->getItemType() == Item_Disc
)
339 if (pDI
->getFlags() && DIF_Disc_MasterizeCD
)
341 _D(Lvl_Error
, "Disc can not be masterized");
342 return ODE_BadLayout
;
345 else if (pDI
->getItemType() == Item_Session
)
348 else if (pDI
->getItemType() == Item_Track
)
350 if (pDI
->getDataType() != Data_Mode1
)
352 _D(Lvl_Error
, "Only Data/Mode1 tracks allowed on MRW media");
353 return ODE_BadLayout
;
355 if (pDI
->getSectorSize() != 2048)
357 _D(Lvl_Error
, "Invalid sector size");
358 return ODE_BadLayout
;
361 else if (pDI
->getItemType() == Item_Index
)
363 _D(Lvl_Error
, "Indices not allowed");
364 return ODE_BadLayout
;
367 return Disc::CheckItemData(pDI
);
370 int Disc_CD_RW::BeginTrackWrite(const IOptItem
*pDI
)
372 if (DiscType() != DRT_Profile_CD_MRW
)
374 return Disc_CD_R::BeginTrackWrite(pDI
);
376 const_cast<IOptItem
*>(pDI
)->setPreGapSize(0);
380 int Disc_CD_RW::EndTrackWrite(const IOptItem
*pDI
)
385 int16
Disc_CD_RW::GetOperationProgress()
389 return meas
->getProgress();
391 return Disc::GetOperationProgress();
394 uint32
Disc_CD_RW::GetDiscSize()
396 // if (0 != readfmtcaps)
397 // return readfmtcaps->GetMaxCapacity();
398 return Disc_CD_R::GetDiscSize();
401 bool Disc_CD_RW::wantCDText() const