2011-05-08 09:07:46 +00:00
using System ;
2011-08-07 03:21:03 +00:00
using System.Linq ;
2011-05-08 09:07:46 +00:00
using System.Text ;
using System.IO ;
using System.Collections.Generic ;
2015-06-23 18:57:11 +00:00
//ARCHITECTURE NOTE:
2015-06-27 09:57:22 +00:00
//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)
2015-07-01 07:56:55 +00:00
//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: ? ? ?)
2015-06-27 09:57:22 +00:00
2013-11-03 23:45:44 +00:00
namespace BizHawk.Emulation.DiscSystem
2011-05-08 09:07:46 +00:00
{
2011-09-04 06:15:41 +00:00
public partial class Disc : IDisposable
2011-05-08 09:07:46 +00:00
{
2015-07-08 07:54:05 +00:00
/// <summary>
/// Automagically loads a disc, without any fine-tuned control at all
/// </summary>
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 ;
}
2013-06-25 08:31:48 +00:00
/// <summary>
2015-07-03 09:11:07 +00:00
/// The DiscStructure corresponding to the TOCRaw
2013-06-25 08:31:48 +00:00
/// </summary>
2014-12-04 05:40:10 +00:00
public DiscStructure Structure ;
2013-06-25 08:31:48 +00:00
2015-07-08 03:29:11 +00:00
/// <summary>
/// DiscStructure.Session 1 of the disc, since that's all thats needed most of the time.
/// </summary>
public DiscStructure . Session Session1 { get { return Structure . Sessions [ 1 ] ; } }
2015-07-13 01:08:30 +00:00
/// <summary>
/// The name of a disc. Loosely based on the filename. Just for informational purposes.
/// </summary>
public string Name ;
2013-06-25 08:31:48 +00:00
/// <summary>
2015-07-08 04:12:06 +00:00
/// The DiscTOCRaw corresponding to the RawTOCEntries.
/// TODO - there's one of these for every session, so... having one here doesnt make sense
2015-07-08 07:54:05 +00:00
/// so...
/// TODO - remove me
2013-06-25 08:31:48 +00:00
/// </summary>
2015-07-08 04:12:06 +00:00
public DiscTOC TOC ;
2011-05-08 09:07:46 +00:00
2015-07-08 03:29:11 +00:00
/// <summary>
2015-07-08 04:12:06 +00:00
/// 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
2015-07-08 03:29:11 +00:00
/// </summary>
2015-07-08 04:12:06 +00:00
public List < RawTOCEntry > RawTOCEntries = new List < RawTOCEntry > ( ) ;
2015-06-23 18:57:11 +00:00
2015-07-08 03:29:11 +00:00
/// <summary>
2015-07-08 04:12:06 +00:00
/// Free-form optional memos about the disc
2015-07-08 03:29:11 +00:00
/// </summary>
2015-07-08 04:12:06 +00:00
public Dictionary < string , object > Memos = new Dictionary < string , object > ( ) ;
2011-05-08 09:07:46 +00:00
2011-09-04 06:15:41 +00:00
public void Dispose ( )
{
2015-06-23 18:57:11 +00:00
foreach ( var res in DisposableResources )
2011-09-04 06:15:41 +00:00
{
2015-06-23 18:57:11 +00:00
res . Dispose ( ) ;
2011-09-04 06:15:41 +00:00
}
}
2017-09-08 03:39:06 +00:00
/// <summary>
/// Easily extracts a mode1 sector range (suitable for extracting ISO FS data files)
/// </summary>
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 ;
}
2015-06-23 18:57:11 +00:00
/// <summary>
2015-07-08 04:12:06 +00:00
/// The DiscMountPolicy used to mount the disc. Consider this read-only.
/// NOT SURE WE NEED THIS
2015-06-23 18:57:11 +00:00
/// </summary>
2015-07-08 04:12:06 +00:00
//public DiscMountPolicy DiscMountPolicy;
2011-06-20 09:09:21 +00:00
2017-09-08 03:39:06 +00:00
2015-07-08 04:12:06 +00:00
//----------------------------------------------------------------------------
2015-01-05 23:01:23 +00:00
2015-07-08 04:12:06 +00:00
/// <summary>
/// Disposable resources (blobs, mostly) referenced by this disc
/// </summary>
internal List < IDisposable > DisposableResources = new List < IDisposable > ( ) ;
2015-01-05 23:01:23 +00:00
2015-07-08 04:12:06 +00:00
/// <summary>
2015-07-15 02:04:05 +00:00
/// 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)
2015-07-08 04:12:06 +00:00
/// </summary>
2015-07-15 02:04:05 +00:00
internal List < ISectorSynthJob2448 > _Sectors = new List < ISectorSynthJob2448 > ( ) ;
/// <summary>
/// ISectorSynthProvider instance for the disc. May be daisy-chained
/// </summary>
internal ISectorSynthProvider SynthProvider ;
2015-01-05 23:01:23 +00:00
2015-07-08 04:12:06 +00:00
/// <summary>
/// Parameters set during disc loading which can be referenced by the sector synthesizers
/// </summary>
internal SectorSynthParams SynthParams = new SectorSynthParams ( ) ;
2011-05-08 09:07:46 +00:00
2015-07-02 06:06:03 +00:00
/// <summary>
2015-07-08 07:54:05 +00:00
/// Forbid public construction
2015-07-02 06:06:03 +00:00
/// </summary>
2015-07-08 07:54:05 +00:00
internal Disc ( )
{ }
2015-07-06 11:06:37 +00:00
2011-06-20 09:09:21 +00:00
}
2011-05-08 09:07:46 +00:00
}