Emulation.DiscSystem - cleanup - use extension method, using declarations
This commit is contained in:
parent
3f9b93be59
commit
4cf29c5169
|
@ -19,10 +19,8 @@ namespace BizHawk.Emulation.DiscSystem
|
||||||
|
|
||||||
public void WriteFile(string fname)
|
public void WriteFile(string fname)
|
||||||
{
|
{
|
||||||
using (FileStream fs = new FileStream(fname, FileMode.Create, FileAccess.Write, FileShare.Read))
|
using FileStream fs = new FileStream(fname, FileMode.Create, FileAccess.Write, FileShare.Read);
|
||||||
{
|
WriteStream(fs);
|
||||||
WriteStream(fs);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stream BaseStream;
|
public Stream BaseStream;
|
||||||
|
|
|
@ -421,21 +421,17 @@ namespace BizHawk.Emulation.DiscSystem
|
||||||
string imgPath = Path.ChangeExtension(path, ".img");
|
string imgPath = Path.ChangeExtension(path, ".img");
|
||||||
string subPath = Path.ChangeExtension(path, ".sub");
|
string subPath = Path.ChangeExtension(path, ".sub");
|
||||||
var buf2448 = new byte[2448];
|
var buf2448 = new byte[2448];
|
||||||
DiscSectorReader dsr = new DiscSectorReader(disc);
|
DiscSectorReader dsr = new DiscSectorReader(disc);
|
||||||
|
|
||||||
using (var imgFile = File.OpenWrite(imgPath))
|
using var imgFile = File.OpenWrite(imgPath);
|
||||||
using (var subFile = File.OpenWrite(subPath))
|
using var subFile = File.OpenWrite(subPath);
|
||||||
{
|
int nLBA = disc.Session1.LeadoutLBA;
|
||||||
|
for (int lba = 0; lba < nLBA; lba++)
|
||||||
int nLBA = disc.Session1.LeadoutLBA;
|
{
|
||||||
for (int lba = 0; lba < nLBA; lba++)
|
dsr.ReadLBA_2448(lba, buf2448, 0);
|
||||||
{
|
imgFile.Write(buf2448, 0, 2352);
|
||||||
dsr.ReadLBA_2448(lba, buf2448, 0);
|
subFile.Write(buf2448, 2352, 96);
|
||||||
imgFile.Write(buf2448, 0, 2352);
|
}
|
||||||
subFile.Write(buf2448, 2352, 96);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class SS_CCD : ISectorSynthJob2448
|
class SS_CCD : ISectorSynthJob2448
|
||||||
|
|
|
@ -251,17 +251,15 @@ namespace BizHawk.Emulation.DiscSystem.CUE
|
||||||
//TODO - fix exception-throwing inside
|
//TODO - fix exception-throwing inside
|
||||||
//TODO - verify stream-disposing semantics
|
//TODO - verify stream-disposing semantics
|
||||||
var fs = File.OpenRead(choice);
|
var fs = File.OpenRead(choice);
|
||||||
using (var blob = new Disc.Blob_WaveFile())
|
using var blob = new Disc.Blob_WaveFile();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
try
|
blob.Load(fs);
|
||||||
{
|
cfi.Type = CompiledCueFileType.WAVE;
|
||||||
blob.Load(fs);
|
}
|
||||||
cfi.Type = CompiledCueFileType.WAVE;
|
catch
|
||||||
}
|
{
|
||||||
catch
|
cfi.Type = CompiledCueFileType.DecodeAudio;
|
||||||
{
|
|
||||||
cfi.Type = CompiledCueFileType.DecodeAudio;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (blobPathExt == ".APE") cfi.Type = CompiledCueFileType.DecodeAudio;
|
else if (blobPathExt == ".APE") cfi.Type = CompiledCueFileType.DecodeAudio;
|
||||||
|
|
|
@ -357,10 +357,10 @@ namespace BizHawk.Emulation.DiscSystem
|
||||||
{
|
{
|
||||||
var data = ReadSectorCached(lba);
|
var data = ReadSectorCached(lba);
|
||||||
if (data == null) return false;
|
if (data == null) return false;
|
||||||
byte[] cmp = System.Text.Encoding.ASCII.GetBytes(s);
|
byte[] cmp = Encoding.ASCII.GetBytes(s);
|
||||||
byte[] cmp2 = new byte[cmp.Length];
|
byte[] cmp2 = new byte[cmp.Length];
|
||||||
Buffer.BlockCopy(data, n, cmp2, 0, cmp.Length);
|
Buffer.BlockCopy(data, n, cmp2, 0, cmp.Length);
|
||||||
return System.Linq.Enumerable.SequenceEqual(cmp, cmp2);
|
return cmp.SequenceEqual(cmp2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool SectorContains(string s, int lba = 0)
|
private bool SectorContains(string s, int lba = 0)
|
||||||
|
|
|
@ -23,58 +23,56 @@ namespace BizHawk.Emulation.DiscSystem.SBI
|
||||||
/// <exception cref="SBIParseException">file at <see cref="IN_Path"/> does not contain valid header or contains misformatted record</exception>
|
/// <exception cref="SBIParseException">file at <see cref="IN_Path"/> does not contain valid header or contains misformatted record</exception>
|
||||||
public void Run()
|
public void Run()
|
||||||
{
|
{
|
||||||
using (var fs = File.OpenRead(IN_Path))
|
using var fs = File.OpenRead(IN_Path);
|
||||||
|
BinaryReader br = new BinaryReader(fs);
|
||||||
|
string sig = br.ReadStringFixedAscii(4);
|
||||||
|
if (sig != "SBI\0")
|
||||||
|
throw new SBIParseException("Missing magic number");
|
||||||
|
|
||||||
|
SubQPatchData ret = new SubQPatchData();
|
||||||
|
List<short> bytes = new List<short>();
|
||||||
|
|
||||||
|
//read records until done
|
||||||
|
for (; ; )
|
||||||
{
|
{
|
||||||
BinaryReader br = new BinaryReader(fs);
|
//graceful end
|
||||||
string sig = br.ReadStringFixedAscii(4);
|
if (fs.Position == fs.Length)
|
||||||
if (sig != "SBI\0")
|
break;
|
||||||
throw new SBIParseException("Missing magic number");
|
|
||||||
|
|
||||||
SubQPatchData ret = new SubQPatchData();
|
if (fs.Position + 4 > fs.Length) throw new SBIParseException("Broken record");
|
||||||
List<short> bytes = new List<short>();
|
var m = BCD2.BCDToInt(br.ReadByte());
|
||||||
|
var s = BCD2.BCDToInt(br.ReadByte());
|
||||||
//read records until done
|
var f = BCD2.BCDToInt(br.ReadByte());
|
||||||
for (; ; )
|
var ts = new Timestamp(m, s, f);
|
||||||
|
ret.ABAs.Add(ts.Sector);
|
||||||
|
int type = br.ReadByte();
|
||||||
|
switch (type)
|
||||||
{
|
{
|
||||||
//graceful end
|
case 1: //Q0..Q9
|
||||||
if (fs.Position == fs.Length)
|
if (fs.Position + 10 > fs.Length) throw new SBIParseException("Broken record");
|
||||||
|
for (int i = 0; i <= 9; i++) bytes.Add(br.ReadByte());
|
||||||
|
for (int i = 10; i <= 11; i++) bytes.Add(-1);
|
||||||
break;
|
break;
|
||||||
|
case 2: //Q3..Q5
|
||||||
if (fs.Position + 4 > fs.Length) throw new SBIParseException("Broken record");
|
if (fs.Position + 3 > fs.Length) throw new SBIParseException("Broken record");
|
||||||
var m = BCD2.BCDToInt(br.ReadByte());
|
for (int i = 0; i <= 2; i++) bytes.Add(-1);
|
||||||
var s = BCD2.BCDToInt(br.ReadByte());
|
for (int i = 3; i <= 5; i++) bytes.Add(br.ReadByte());
|
||||||
var f = BCD2.BCDToInt(br.ReadByte());
|
for (int i = 6; i <= 11; i++) bytes.Add(-1);
|
||||||
var ts = new Timestamp(m, s, f);
|
break;
|
||||||
ret.ABAs.Add(ts.Sector);
|
case 3: //Q7..Q9
|
||||||
int type = br.ReadByte();
|
if (fs.Position + 3 > fs.Length) throw new SBIParseException("Broken record");
|
||||||
switch (type)
|
for (int i = 0; i <= 6; i++) bytes.Add(-1);
|
||||||
{
|
for (int i = 7; i <= 9; i++) bytes.Add(br.ReadByte());
|
||||||
case 1: //Q0..Q9
|
for (int i = 10; i <= 11; i++) bytes.Add(-1);
|
||||||
if (fs.Position + 10 > fs.Length) throw new SBIParseException("Broken record");
|
break;
|
||||||
for (int i = 0; i <= 9; i++) bytes.Add(br.ReadByte());
|
default:
|
||||||
for (int i = 10; i <= 11; i++) bytes.Add(-1);
|
throw new SBIParseException("Broken record");
|
||||||
break;
|
|
||||||
case 2: //Q3..Q5
|
|
||||||
if (fs.Position + 3 > fs.Length) throw new SBIParseException("Broken record");
|
|
||||||
for (int i = 0; i <= 2; i++) bytes.Add(-1);
|
|
||||||
for (int i = 3; i <= 5; i++) bytes.Add(br.ReadByte());
|
|
||||||
for (int i = 6; i <= 11; i++) bytes.Add(-1);
|
|
||||||
break;
|
|
||||||
case 3: //Q7..Q9
|
|
||||||
if (fs.Position + 3 > fs.Length) throw new SBIParseException("Broken record");
|
|
||||||
for (int i = 0; i <= 6; i++) bytes.Add(-1);
|
|
||||||
for (int i = 7; i <= 9; i++) bytes.Add(br.ReadByte());
|
|
||||||
for (int i = 10; i <= 11; i++) bytes.Add(-1);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new SBIParseException("Broken record");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret.subq = bytes.ToArray();
|
|
||||||
|
|
||||||
OUT_Data = ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret.subq = bytes.ToArray();
|
||||||
|
|
||||||
|
OUT_Data = ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue