Bringing ChocolateCaste-0.7 into the main branch.
[AROS-Contrib.git] / FryingPan / Optical / Disc_CD_RW.cpp
blobdd8daaee5a920b8a3745b97cb3fe18e7e2f32a39
1 /*
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
4 *
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.
9 *
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.
20 #include "Headers.h"
21 #include "Disc_CD_RW.h"
22 #include "Config.h"
23 #include "CfgCDInfo.h"
26 Disc_CD_RW::Disc_CD_RW(Drive *d) : Disc_CD_R(d)
28 meas = 0;
29 readfmtcaps = 0;
30 readfmtcaps = new cmd_ReadFormatCapacities(dio);
31 readfmtcaps->Go();
34 void Disc_CD_RW::Init(void)
36 Disc_CD_R::Init();
39 Disc_CD_RW::~Disc_CD_RW(void)
41 delete readfmtcaps;
44 int Disc_CD_RW::EraseDisc(int met)
46 cmd_Blank::BlankType type;
47 int err;
48 cmd_StartStopUnit ssu(dio);
50 ssu.setType(cmd_StartStopUnit::StartStop_Start);
51 ssu.Go();
53 if (NULL != atip)
55 switch (met)
57 case DRT_Blank_Complete:
58 meas = drive->GetHardwareConfig()->CDInfo()->getCBlankMeas(atip->GetLeadOutPos(), GetWriteSpeed());
59 break;
61 case DRT_Blank_Fast:
62 meas = drive->GetHardwareConfig()->CDInfo()->getQBlankMeas(atip->GetLeadOutPos(), GetWriteSpeed());
63 break;
65 default:
66 meas = 0;
70 err = SetWriteMethod(DRT_WriteMethod_TAO);
71 if (err) return err;
73 switch (met) {
74 case DRT_Blank_Complete:
75 type = cmd_Blank::Blank_All;
76 break;
77 case DRT_Blank_Fast:
78 type = cmd_Blank::Blank_Minimal;
79 break;
80 case DRT_Blank_Session:
81 type = cmd_Blank::Blank_Session;
82 break;
83 default:
84 return ODE_IllegalParameter;
87 Calibrate();
89 cmd_Blank *blk = new cmd_Blank(dio);
90 blk->setType(type, 0);
91 blk->setImmediate(true);
93 if (0 != meas)
94 meas->begin();
96 err = blk->Go();
97 WaitOpComplete();
99 if ((err == ODE_OK) && (0 != meas))
100 meas->end();
102 meas = 0;
104 // if (err == ODE_OK) Init();
105 RequestUpdate();
107 delete blk;
108 return err;
111 int Disc_CD_RW::FormatDisc(int met)
113 int err;
114 cmd_StartStopUnit ssu(dio);
116 ssu.setType(cmd_StartStopUnit::StartStop_Start);
117 ssu.Go();
119 err = SetWriteMethod(DRT_WriteMethod_Packet);
120 if (err) return err;
122 readfmtcaps->Go();
123 // if (readfmtcaps->IsFormatted())
124 // return ODE_OK;
126 cmd_Format *fmt;
128 fmt = new cmd_Format(dio);
130 if (NULL != atip)
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);
142 Calibrate();
144 if (0 != meas)
145 meas->begin();
146 err = fmt->Go();
147 WaitOpComplete();
148 if ((err == ODE_OK) && (0 != meas))
149 meas->end();
151 if (!err)
152 err = fmt->Go();
154 meas = 0;
156 RequestUpdate();
157 delete fmt;
158 return err;
161 int Disc_CD_RW::StructureDisc(void)
163 int err;
164 err = EraseDisc(DRT_Blank_Fast);
165 if (err) return err;
166 return ODE_OK;
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);
178 cl->Go();
179 WaitOpComplete();
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();
194 WaitOpComplete();
195 delete cl;
196 return error;
199 bool Disc_CD_RW::AllowMultiSessionLayout()
201 if (DiscType() == DRT_Profile_CD_MRW)
202 return false;
203 else
204 return Disc_CD_R::AllowMultiSessionLayout();
207 bool Disc_CD_RW::AllowMultiTrackLayout()
209 if (DiscType() == DRT_Profile_CD_MRW)
210 return false;
211 else
212 return Disc_CD_R::AllowMultiTrackLayout();
215 int Disc_CD_RW::SessionGapSize()
217 if (DiscType() == DRT_Profile_CD_MRW)
218 return 0;
219 else
220 return Disc_CD_R::SessionGapSize();
223 int Disc_CD_RW::TrackGapSize()
225 if (DiscType() == DRT_Profile_CD_MRW)
226 return false;
227 else
228 return Disc_CD_R::TrackGapSize();
231 int Disc_CD_RW::DiscType()
233 if (IsFormatted())
234 return DRT_Profile_CD_MRW;
235 return DRT_Profile_CD_RW;
238 int Disc_CD_RW::DiscSubType()
240 if (atip)
242 _D(Lvl_Info, "Analysing ATIP data...");
243 switch (atip->GetDiscSubType())
245 case 0:
246 _D(Lvl_Debug, "Got Low-Speed rewritable disc.");
247 return DRT_SubType_CD_RW_LowSpeed;
248 case 1:
249 _D(Lvl_Debug, "Got High-Speed rewritable disc.");
250 return DRT_SubType_CD_RW_HighSpeed;
251 case 2:
252 _D(Lvl_Debug, "Got Ultra-Speed rewritable disc.");
253 return DRT_SubType_CD_RW_UltraSpeed;
254 default:
255 _D(Lvl_Debug, "Unknown disc sub type %ld.", atip->GetDiscSubType());
256 return DRT_SubType_Unknown;
259 else
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)
269 return true;
271 cmd_GetConfiguration::Feature *x;
273 x = drive->GetDriveFeature(cmd_GetConfiguration::Feature_RigidOverwrite);
274 if (x)
275 if (x->IsCurrent()) return true;
277 x = drive->GetDriveFeature(cmd_GetConfiguration::Feature_RestrictedOverwrite);
278 if (x)
279 if (x->IsCurrent()) return true;
281 return false;
285 bool Disc_CD_RW::IsWritable(void)
287 if (DiscType() == DRT_Profile_CD_MRW)
288 return true;
289 return Disc_CD_R::IsWritable();
292 bool Disc_CD_RW::IsFormatted()
294 if (0 == readfmtcaps)
295 return false;
296 // FIXME: Zwracamy false poki nie naprawimy IsFormatted()!!!
297 // if (readfmtcaps->IsFormatted())
298 // return true;
299 return false;
302 bool Disc_CD_RW::IsFormatable()
304 if (drive->GetDriveFeature(cmd_GetConfiguration::Feature_CD_MRW))
305 return true;
306 return false;
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);
377 return ODE_OK;
380 int Disc_CD_RW::EndTrackWrite(const IOptItem*pDI)
382 return ODE_OK;
385 int16 Disc_CD_RW::GetOperationProgress()
387 if (meas != 0)
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
403 return false;