work on cue ECM synthesizing

This commit is contained in:
zeromus 2015-07-01 04:44:03 -05:00
parent aa50d28346
commit 4e8f649512
6 changed files with 63 additions and 17 deletions

View File

@ -7,6 +7,21 @@ namespace BizHawk.Emulation.DiscSystem
{
public partial class Disc : IDisposable
{
/// <summary>
/// A blob that always reads 0
/// </summary>
internal sealed class Blob_Zeros : IBlob
{
public int Read(long byte_pos, byte[] buffer, int offset, int count)
{
Array.Clear(buffer, offset, count);
return count;
}
public void Dispose()
{
}
}
internal sealed class Blob_ZeroPadAdapter : IBlob
{

View File

@ -209,7 +209,7 @@ namespace BizHawk.Emulation.DiscSystem
{
//TODO - do a better job synthesizing Q
var se_pregap = new SectorEntry(null);
var ss_pregap = new SS_Pregap();
var ss_pregap = new SS_Gap();
//pregaps set pause flag
//TODO - do a better job synthesizing P
@ -343,7 +343,7 @@ namespace BizHawk.Emulation.DiscSystem
{
//TODO - do a better job synthesizing Q
var se_pregap = new SectorEntry(null);
var ss_pregap = new SS_Pregap();
var ss_pregap = new SS_Gap();
//postgaps set pause flag. is this good enough?
ss_pregap.Pause = true;

View File

@ -19,7 +19,7 @@ namespace BizHawk.Emulation.DiscSystem
{
if ((job.Parts & ESectorSynthPart.SubchannelP) != 0)
{
SynthUtils.P(job.DestBuffer2448, job.DestOffset + 2352, Pause);
SynthUtils.SubP(job.DestBuffer2448, job.DestOffset + 2352, Pause);
}
if ((job.Parts & ESectorSynthPart.SubchannelQ) != 0)
@ -33,14 +33,14 @@ namespace BizHawk.Emulation.DiscSystem
static class SynthUtils
{
public static void P(byte[] buffer, int offset, bool pause)
public static void SubP(byte[] buffer, int offset, bool pause)
{
byte val = (byte)(pause?0xFF:0x00);
for (int i = 0; i < 12; i++)
buffer[offset + i] = val;
}
public static void Header(byte[] buffer, int offset, int LBA, byte mode)
public static void SectorHeader(byte[] buffer, int offset, int LBA, byte mode)
{
buffer[offset + 0] = 0x00;
for (int i = 1; i < 11; i++) buffer[offset + i] = 0xFF;
@ -51,17 +51,21 @@ namespace BizHawk.Emulation.DiscSystem
buffer[offset + 14] = ts.FRAC;
buffer[offset + 15] = mode;
}
}
/// <summary>
/// Represents a pregap sector
/// TODO - represent any zero sector
/// </summary>
class SS_Pregap : SS_Base
{
public override void Synth(SectorSynthJob job)
/// <summary>
/// Make sure everything else in the sector userdata is done before calling this
/// </summary>
public static void ECM_Mode1(byte[] buffer, int offset, int LBA)
{
//EDC
uint edc = ECM.EDC_Calc(buffer, offset, 2064);
ECM.PokeUint(buffer, 2064, edc);
//reserved, zero
for (int i = 0; i < 8; i++) buffer[offset + 2068 + i] = 0;
//ECC
ECM.ECC_Populate(buffer, offset, buffer, offset, false);
}
}
@ -77,12 +81,27 @@ namespace BizHawk.Emulation.DiscSystem
Blob.Read(BlobOffset, job.DestBuffer2448, job.DestOffset + 16, 2048);
if ((job.Parts & ESectorSynthPart.Header16) != 0)
SynthUtils.Header(job.DestBuffer2448, job.DestOffset + 0, job.LBA, 1);
SynthUtils.SectorHeader(job.DestBuffer2448, job.DestOffset + 0, job.LBA, 1);
if ((job.Parts & ESectorSynthPart.ECMAny) != 0)
SynthUtils.ECM_Mode1(job.DestBuffer2448, job.DestOffset + 0, job.LBA);
SynthSubcode(job);
}
}
/// <summary>
/// Represents a pregap or postgap sector.
/// The Pause flag isn't set in here because it might need special logic varying between sectors
/// Implemented as another sector type with a blob reading all zeros
/// </summary>
class SS_Gap : SS_Mode1_2048
{
public SS_Gap()
{
Blob = new Disc.Blob_Zeros();
}
}
/// <summary>
/// Represents a Mode1 or Mode2 2352-byte sector

View File

@ -226,7 +226,8 @@ namespace BizHawk.Emulation.DiscSystem
(sector[sector_offset + 12 + 0] << 0)
| (sector[sector_offset + 12 + 1] << 8)
| (sector[sector_offset + 12 + 2] << 16)
| (sector[sector_offset + 12 + 3] << 24));
);
//| (sector[sector_offset + 12 + 3] << 24));
}
/// <summary>
@ -237,7 +238,7 @@ namespace BizHawk.Emulation.DiscSystem
sector[sector_offset + 12 + 0] = (byte)((address >> 0) & 0xFF);
sector[sector_offset + 12 + 1] = (byte)((address >> 8) & 0xFF);
sector[sector_offset + 12 + 2] = (byte)((address >> 16) & 0xFF);
sector[sector_offset + 12 + 3] = (byte)((address >> 24) & 0xFF);
//sector[sector_offset + 12 + 3] = (byte)((address >> 24) & 0xFF);
}

View File

@ -9,6 +9,7 @@ namespace BizHawk.Emulation.DiscSystem
/// <summary>
/// General disc policies to be logically applied at mounting time. The choices are irreversible once a disc is loaded.
/// Maybe these are only for CUEs, but maybe not. Not sure yet.
/// Could put caching policies here too (cached ecm calculations, etc.)
/// </summary>
public class DiscMountPolicy
{

View File

@ -47,10 +47,20 @@ namespace BizHawk.Emulation.DiscSystem
/// </summary>
EDC12 = 8,
/// <summary>
/// The entire possible 276+12=288 bytes of ECM data is required (ECC276|EDC12)
/// </summary>
ECM288Complete = (ECC276 | EDC12),
/// <summary>
/// An alias for ECM288Complete
/// </summary>
ECMAny = ECM288Complete,
/// <summary>
/// A mode2 userdata section is required: the main 2048 user bytes AND the ECC and EDC areas
/// </summary>
User2336 = (User2048|ECC276|EDC12),
User2336 = (User2048 | ECM288Complete),
/// <summary>
/// The complete sector userdata (2352 bytes) is required