prepwork for sector synthesis provider

This commit is contained in:
zeromus 2015-07-14 21:04:05 -05:00
parent 587f0293b9
commit 64aa41c0e3
8 changed files with 69 additions and 23 deletions

View File

@ -88,10 +88,15 @@ namespace BizHawk.Emulation.DiscSystem
internal List<IDisposable> DisposableResources = new List<IDisposable>();
/// <summary>
/// The sectors on the disc
/// TODO - replace with delegate (much faster disc loading, support of reading of arbitrary lead-out and lead-in sectors)
/// 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>();
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

View File

@ -565,7 +565,7 @@ namespace BizHawk.Emulation.DiscSystem
Policy = IN_DiscMountPolicy,
TrackType = pregapTrackType
};
disc.Sectors.Add(ss_gap);
disc._Sectors.Add(ss_gap);
int qRelMSF = i - 150;
@ -590,7 +590,7 @@ namespace BizHawk.Emulation.DiscSystem
//(the TOC is unreliable, and the Track records are redundant)
for (int i = 0; i < loadResults.NumImgSectors; i++)
{
disc.Sectors.Add(synth);
disc._Sectors.Add(synth);
}
return disc;

View File

@ -162,7 +162,7 @@ namespace BizHawk.Emulation.DiscSystem.CUE
toc_sq.min = BCD2.FromDecimal(0);
toc_sq.sec = BCD2.FromDecimal(0);
toc_sq.frame = BCD2.FromDecimal(0);
toc_sq.AP_Timestamp = new Timestamp(OUT_Disc.Sectors.Count);
toc_sq.AP_Timestamp = new Timestamp(OUT_Disc._Sectors.Count);
OUT_Disc.RawTOCEntries.Add(new RawTOCEntry { QData = toc_sq });
}
@ -322,14 +322,14 @@ namespace BizHawk.Emulation.DiscSystem.CUE
ss.sq.SetStatus(ADR, (EControlQ)(int)qTrack.CompiledCueTrack.Flags);
ss.sq.q_tno = BCD2.FromDecimal(cct.Number);
ss.sq.q_index = BCD2.FromDecimal(curr_index);
ss.sq.AP_Timestamp = new Timestamp(OUT_Disc.Sectors.Count);
ss.sq.AP_Timestamp = new Timestamp(OUT_Disc._Sectors.Count);
ss.sq.Timestamp = new Timestamp(qRelMSF);
//setup subP
if (curr_index == 0)
ss.Pause = true;
OUT_Disc.Sectors.Add(ss);
OUT_Disc._Sectors.Add(ss);
relMSF++;
if (cct.IsFinalInFile)
@ -363,14 +363,14 @@ namespace BizHawk.Emulation.DiscSystem.CUE
ss.sq.SetStatus(ADR, (EControlQ)(int)cct.Flags);
ss.sq.q_tno = BCD2.FromDecimal(cct.Number);
ss.sq.q_index = BCD2.FromDecimal(curr_index);
ss.sq.AP_Timestamp = new Timestamp(OUT_Disc.Sectors.Count);
ss.sq.AP_Timestamp = new Timestamp(OUT_Disc._Sectors.Count);
ss.sq.Timestamp = new Timestamp(relMSF);
//-subP-
//always paused--is this good enough?
ss.Pause = true;
OUT_Disc.Sectors.Add(ss);
OUT_Disc._Sectors.Add(ss);
relMSF++;
}
@ -383,7 +383,7 @@ namespace BizHawk.Emulation.DiscSystem.CUE
IN_FirstRecordedTrackNumber = IN_CompileJob.OUT_CompiledDiscInfo.FirstRecordedTrackNumber,
IN_LastRecordedTrackNumber = IN_CompileJob.OUT_CompiledDiscInfo.LastRecordedTrackNumber,
IN_Session1Format = IN_CompileJob.OUT_CompiledDiscInfo.SessionFormat,
IN_LeadoutTimestamp = new Timestamp(OUT_Disc.Sectors.Count) //do we need a +150?
IN_LeadoutTimestamp = new Timestamp(OUT_Disc._Sectors.Count) //do we need a +150?
};
TOCMiscInfo.Run(OUT_Disc.RawTOCEntries);

View File

@ -43,15 +43,16 @@ namespace BizHawk.Emulation.DiscSystem
var synth = new SS_MednaDisc();
//make sector interfaces:
//1. mandatory track 1 pregap
for (int i = 0; i < 150; i++)
{
disc.Sectors.Add(synth);
disc._Sectors.Add(synth);
}
//2. actual sectors
for (int i = 0; i < nSectors; i++)
{
disc.Sectors.Add(synth);
disc._Sectors.Add(synth);
}
//ADR (q-Mode) is necessarily 0x01 for a RawTOCEntry

View File

@ -65,6 +65,14 @@ namespace BizHawk.Emulation.DiscSystem
{
OUT_Disc.Name = Path.GetFileName(IN_FromPath);
//setup the lowest level synth provider
var sssp = new SimpleSectorSynthProvider()
{
Sectors = OUT_Disc._Sectors,
FirstLBA = -150
};
OUT_Disc.SynthProvider = sssp;
//generate toc and structure:
//1. TOCRaw from RawTOCEntries
var tocSynth = new Synthesize_DiscTOC_From_RawTOCEntries_Job() { Entries = OUT_Disc.RawTOCEntries };

View File

@ -85,7 +85,7 @@ namespace BizHawk.Emulation.DiscSystem
/// </summary>
public int ReadLBA_2352(int lba, byte[] buffer, int offset)
{
var sector = disc.Sectors[lba + 150];
var sector = disc.SynthProvider.Get(lba);
PrepareBuffer(buffer, offset, 2352);
PrepareJob(lba);
@ -109,7 +109,7 @@ namespace BizHawk.Emulation.DiscSystem
/// </summary>
public int ReadLBA_2448(int lba, byte[] buffer, int offset)
{
var sector = disc.Sectors[lba + 150];
var sector = disc.SynthProvider.Get(lba);
PrepareBuffer(buffer, offset, 2352);
PrepareJob(lba);
@ -128,7 +128,7 @@ namespace BizHawk.Emulation.DiscSystem
int ReadLBA_2048_Mode1(int lba, byte[] buffer, int offset)
{
//we can read the 2048 bytes directly
var sector = disc.Sectors[lba + 150];
var sector = disc.SynthProvider.Get(lba);
PrepareBuffer(buffer, offset, 2352);
PrepareJob(lba);
@ -145,7 +145,7 @@ namespace BizHawk.Emulation.DiscSystem
int ReadLBA_2048_Mode2_Form1(int lba, byte[] buffer, int offset)
{
//we can read the 2048 bytes directly but we have to get them from the mode 2 data
var sector = disc.Sectors[lba + 150];
var sector = disc.SynthProvider.Get(lba);
PrepareBuffer(buffer, offset, 2352);
PrepareJob(lba);
@ -165,7 +165,7 @@ namespace BizHawk.Emulation.DiscSystem
/// </summary>
public int ReadLBA_SubQ(int lba, byte[] buffer, int offset)
{
var sector = disc.Sectors[lba + 150];
var sector = disc.SynthProvider.Get(lba);
PrepareBuffer(buffer, offset, 12);
PrepareJob(lba);
@ -196,7 +196,7 @@ namespace BizHawk.Emulation.DiscSystem
{
//we need to determine the type of the sector.
//in no case do we need the ECC so build special flags here
var sector = disc.Sectors[lba + 150];
var sector = disc.SynthProvider.Get(lba);
PrepareBuffer(buffer, offset, 2048);
PrepareJob(lba);
@ -271,7 +271,7 @@ namespace BizHawk.Emulation.DiscSystem
/// </summary>
public int ReadLBA_Mode(int lba)
{
var sector = disc.Sectors[lba + 150];
var sector = disc.SynthProvider.Get(lba);
PrepareJob(lba);
job.DestBuffer2448 = buf2442;

View File

@ -29,14 +29,14 @@ namespace BizHawk.Emulation.DiscSystem
int lba = sbi.ABAs[i] - 150;
//create a synthesizer which can return the patched data
var ss_patchq = new SS_PatchQ() { Original = disc.Sectors[lba + 150] };
var ss_patchq = new SS_PatchQ() { Original = disc._Sectors[lba + 150] };
byte[] subQbuf = ss_patchq.Buffer_SubQ;
//read the old subcode
dsr.ReadLBA_SubQ(lba, subQbuf, 0);
//insert patch
disc.Sectors[lba + 150] = ss_patchq;
disc._Sectors[lba + 150] = ss_patchq;
//apply SBI patch
for (int j = 0; j < 12; j++)

View File

@ -98,8 +98,14 @@ namespace BizHawk.Emulation.DiscSystem
Complete2448 = SubcodeComplete | User2352,
}
/// <summary>
/// Basic unit of sector synthesis
/// </summary>
interface ISectorSynthJob2448
{
/// <summary>
/// Synthesizes a sctor with the given job parameters
/// </summary>
void Synth(SectorSynthJob job);
}
@ -116,6 +122,32 @@ namespace BizHawk.Emulation.DiscSystem
public Disc Disc;
}
/// <summary>
/// an ISectorSynthProvider that just returns a value from an array of pre-made sectors
/// </summary>
class SimpleSectorSynthProvider : ISectorSynthProvider
{
public List<ISectorSynthJob2448> Sectors = new List<ISectorSynthJob2448>();
public int FirstLBA;
public ISectorSynthJob2448 Get(int lba)
{
int index = lba - FirstLBA;
return Sectors[index];
}
}
/// <summary>
/// When creating a disc, this is set with a callback that can deliver an ISectorSynthJob2448 for the given LBA
/// </summary>
interface ISectorSynthProvider
{
/// <summary>
/// Retrieves an ISectorSynthJob2448 for the given LBA
/// </summary>
ISectorSynthJob2448 Get(int lba);
}
/// <summary>
/// Generic parameters for sector synthesis.
/// To cut down on resource utilization, these can be stored in a disc and are tightly coupled to
@ -123,7 +155,7 @@ namespace BizHawk.Emulation.DiscSystem
/// </summary>
struct SectorSynthParams
{
public long[] BlobOffsets;
//public long[] BlobOffsets;
public MednaDisc MednaDisc;
}