-
Notifications
You must be signed in to change notification settings - Fork 380
/
Disc.cs
137 lines (116 loc) · 4.81 KB
/
Disc.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
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
{
/// <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;
}
/// <summary>
/// The DiscStructure corresponding to the TOCRaw
/// </summary>
public DiscStructure Structure;
/// <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]; } }
/// <summary>
/// The name of a disc. Loosely based on the filename. Just for informational purposes.
/// </summary>
public string Name;
/// <summary>
/// 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
/// </summary>
public DiscTOC TOC;
/// <summary>
/// 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
/// </summary>
public List<RawTOCEntry> RawTOCEntries = new List<RawTOCEntry>();
/// <summary>
/// Free-form optional memos about the disc
/// </summary>
public Dictionary<string, object> Memos = new Dictionary<string, object>();
public void Dispose()
{
foreach (var res in DisposableResources)
{
res.Dispose();
}
}
/// <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;
}
/// <summary>
/// The DiscMountPolicy used to mount the disc. Consider this read-only.
/// NOT SURE WE NEED THIS
/// </summary>
//public DiscMountPolicy DiscMountPolicy;
//----------------------------------------------------------------------------
/// <summary>
/// Disposable resources (blobs, mostly) referenced by this disc
/// </summary>
internal List<IDisposable> DisposableResources = new List<IDisposable>();
/// <summary>
/// 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)
/// </summary>
internal List<ISectorSynthJob2448> _Sectors = new List<ISectorSynthJob2448>();
/// <summary>
/// ISectorSynthProvider instance for the disc. May be daisy-chained
/// </summary>
internal ISectorSynthProvider SynthProvider;
/// <summary>
/// Parameters set during disc loading which can be referenced by the sector synthesizers
/// </summary>
internal SectorSynthParams SynthParams = new SectorSynthParams();
/// <summary>
/// Forbid public construction
/// </summary>
internal Disc()
{}
}
}