using System; using System.Linq; using System.Text; using System.IO; using System.Collections.Generic; //ARCHITECTURE NOTE: //No provisions are made for caching synthesized data for later accelerated use. //This is because, in the worst case that might result in synthesizing an entire disc in memory. //Instead, users should be advised to `hawk` the disc first for most rapid access so that synthesis won't be necessary and speed will be maximized. //This will result in a completely flattened CCD where everything comes right off the hard drive //Our choice here might be an unwise decision for disc ID and miscellaneous purposes but it's best for gaming and stream-converting (hawking and hashing) //TODO: in principle, we could mount audio to decode only on an as-needed basis //this might result in hiccups during emulation, though, so it should be an option. //This would imply either decode-length processing (scan file without decoding) or decoding and discarding the data. //We should probably have some richer policy specifications for this kind of thing, but it's not a high priority. Main workflow is still discohawking. //Alternate policies would probably be associated with copious warnings (examples: ? ? ?) namespace BizHawk.Emulation.DiscSystem { public partial class Disc : IDisposable { /// /// Automagically loads a disc, without any fine-tuned control at all /// public static Disc LoadAutomagic(string path) { var job = new DiscMountJob { IN_FromPath = path }; //job.IN_DiscInterface = DiscInterface.MednaDisc; //TEST job.Run(); return job.OUT_Disc; } /// /// The DiscStructure corresponding to the TOCRaw /// public DiscStructure Structure; /// /// DiscStructure.Session 1 of the disc, since that's all thats needed most of the time. /// public DiscStructure.Session Session1 { get { return Structure.Sessions[1]; } } /// /// The name of a disc. Loosely based on the filename. Just for informational purposes. /// public string Name; /// /// The DiscTOCRaw corresponding to the RawTOCEntries. /// TODO - there's one of these for every session, so... having one here doesnt make sense /// so... /// TODO - remove me /// public DiscTOC TOC; /// /// The raw TOC entries found in the lead-in track. /// These aren't very useful, but theyre one of the most lowest-level data structures from which other TOC-related stuff is derived /// public List RawTOCEntries = new List(); /// /// Free-form optional memos about the disc /// public Dictionary Memos = new Dictionary(); public void Dispose() { foreach (var res in DisposableResources) { res.Dispose(); } } /// /// Easily extracts a mode1 sector range (suitable for extracting ISO FS data files) /// public byte[] Easy_Extract_Mode1(int lba_start, int lba_count, int byteLength = -1) { int totsize = lba_count * 2048; byte[] ret = new byte[totsize]; var dsr = new DiscSectorReader(this); dsr.Policy.DeterministicClearBuffer = false; for (int i = 0; i < lba_count; i++) { dsr.ReadLBA_2048(lba_start + i, ret, i*2048); } if (byteLength != -1 && byteLength != totsize) { byte[] newret = new byte[byteLength]; Array.Copy(ret, newret, byteLength); return newret; } return ret; } // /// // /// The DiscMountPolicy used to mount the disc. Consider this read-only. // /// NOT SURE WE NEED THIS // /// // public DiscMountPolicy DiscMountPolicy; //---------------------------------------------------------------------------- /// /// Disposable resources (blobs, mostly) referenced by this disc /// internal List DisposableResources = new List(); /// /// The sectors on the disc. Don't use this directly! Use the SectorSynthProvider instead. /// TODO - eliminate this entirely and do entirely with the delegate (much faster disc loading... but massively annoying architecture inside-out logic) /// internal List _Sectors = new List(); /// /// ISectorSynthProvider instance for the disc. May be daisy-chained /// internal ISectorSynthProvider SynthProvider; /// /// Parameters set during disc loading which can be referenced by the sector synthesizers /// internal SectorSynthParams SynthParams = new SectorSynthParams(); /// /// Forbid public construction /// internal Disc() {} } }