Skip to content

Commit

Permalink
fix some errors with 2442 vs 2448, repair CCD dumping, repair discohawk
Browse files Browse the repository at this point in the history
  • Loading branch information
zeromus committed Jul 11, 2015
1 parent bdb64ce commit 901d5c1
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 57 deletions.
4 changes: 2 additions & 2 deletions BizHawk.Client.DiscoHawk/DiscoHawk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,8 @@ static bool CompareFile(string infile, DiscInterface loadDiscInterface, DiscInte
if (cancelToken.Token.IsCancellationRequested)
return false;

src_dsr.ReadLBA_2442(lba, src_databuf, 0);
dst_dsr.ReadLBA_2442(lba, dst_databuf, 0);
src_dsr.ReadLBA_2448(lba, src_databuf, 0);
dst_dsr.ReadLBA_2448(lba, dst_databuf, 0);

//check the header
for (int b = 0; b < 16; b++)
Expand Down
3 changes: 1 addition & 2 deletions BizHawk.Client.DiscoHawk/MainDiscoForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ private void lblMagicDragArea_DragDrop(object sender, DragEventArgs e)
string baseName = Path.GetFileNameWithoutExtension(file);
baseName += "_hawked";
string outfile = Path.Combine(Path.GetDirectoryName(file), baseName) + ".ccd";
//TODO CCD
//CCD_Format.Dump(disc, outfile);
CCD_Format.Dump(disc, outfile);
}
this.Cursor = Cursors.Default;
}
Expand Down
2 changes: 1 addition & 1 deletion BizHawk.Emulation.Cores/Consoles/Sony/PSX/Octoshock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ int ShockDisc_ReadLBA2448(IntPtr opaque, int lba, void* dst)

//todo - cache reader
DiscSystem.DiscSectorReader dsr = new DiscSystem.DiscSectorReader(Disc);
dsr.ReadLBA_2442(lba, SectorBuffer, 0);
dsr.ReadLBA_2448(lba, SectorBuffer, 0);
Marshal.Copy(SectorBuffer, 0, new IntPtr(dst), 2448);

//if (subcodeLog)
Expand Down
89 changes: 47 additions & 42 deletions BizHawk.Emulation.DiscSystem/DiscFormats/CCD_format.cs
Original file line number Diff line number Diff line change
Expand Up @@ -368,25 +368,38 @@ public static void Dump(Disc disc, string path)
{
using (var sw = new StreamWriter(path))
{
//NOTE: IsoBuster requires the A0,A1,A2 RawTocEntries to be first or else it can't do anything with the tracks
//if we ever get them in a different order, we'll have to re-order them here

sw.WriteLine("[CloneCD]");
sw.WriteLine("Version=3");
sw.WriteLine();
sw.WriteLine("[Disc]");
sw.WriteLine("TocEntries={0}", disc.RawTOCEntries.Count);
sw.WriteLine("Sessions=1");
sw.WriteLine("DataTracksScrambled=0");
sw.WriteLine("CDTextLength=0"); //not supported anyway
sw.WriteLine();
sw.WriteLine("[Session 1]");
sw.WriteLine("PreGapMode=2");
sw.WriteLine("PreGapSubC=1");
sw.WriteLine();
for (int i = 0; i < disc.RawTOCEntries.Count; i++)
{
var entry = disc.RawTOCEntries[i];

//ehhh something's wrong with how I track these
int point = entry.QData.q_index.DecimalValue;
if (point == 100) point = 0xA0;
if (point == 101) point = 0xA1;
if (point == 102) point = 0xA2;

sw.WriteLine("[Entry {0}]", i);
sw.WriteLine("Session=1");
sw.WriteLine("Point=0x{0:x2}", entry.QData.q_index);
sw.WriteLine("Point=0x{0:x2}", point);
sw.WriteLine("ADR=0x{0:x2}", entry.QData.ADR);
sw.WriteLine("Control=0x{0:x2}", (int)entry.QData.CONTROL);
sw.WriteLine("TrackNo={0}", entry.QData.q_tno);
sw.WriteLine("TrackNo={0}", entry.QData.q_tno.DecimalValue);
sw.WriteLine("AMin={0}", entry.QData.min.DecimalValue);
sw.WriteLine("ASec={0}", entry.QData.sec.DecimalValue);
sw.WriteLine("AFrame={0}", entry.QData.frame.DecimalValue);
Expand All @@ -396,53 +409,45 @@ public static void Dump(Disc disc, string path)
sw.WriteLine("PSec={0}", entry.QData.ap_sec.DecimalValue);
sw.WriteLine("PFrame={0}", entry.QData.ap_frame.DecimalValue);
sw.WriteLine("PLBA={0}", entry.QData.AP_Timestamp.Sector - 150); //remember to adapt the absolute MSF to an LBA (this field is redundant...)
sw.WriteLine();
}

//TODO - this is nonsense, right? the whole CCD track and index list isn't really needed.
//at least not for us when we'll always be writing a .sub file
//for (int i = 0; i < disc.Structure.Sessions[0].Tracks.Count; i++)
//{
// var st = disc.Structure.Sessions[0].Tracks[i];
// sw.WriteLine("[TRACK {0}]", st.Number);
// sw.WriteLine("MODE={0}", st.ModeHeuristic); //MAYBE A BAD PLAN!
// //dont write an index=0 identical to an index=1. It might work, or it might not.
// int idx = 0;
// if (st.Indexes[0].LBA == st.Indexes[1].LBA)
// idx = 1;
// for (; idx < st.Indexes.Count; idx++)
// {
// sw.WriteLine("INDEX {0}={1}", st.Indexes[idx].Number, st.Indexes[idx].LBA);
// }
//}

//this is nonsense, really. the whole CCD track list shouldn't be needed.
//but in order to make a high quality CCD which can be inspected by various other tools, we need it
//now, regarding the indexes.. theyre truly useless. having indexes written out with the tracks is bad news.
//index information is only truly stored in subQ
for (int tnum = 1; tnum <= disc.Session1.LastInformationTrack.Number; tnum++)
{
var track = disc.Session1.Tracks[tnum];
sw.WriteLine("[TRACK {0}]", track.Number);
sw.WriteLine("MODE={0}", track.Mode);
//indexes are BS, dont write them. but we certainly need an index 1
sw.WriteLine("INDEX 1={0}", track.LBA);
sw.WriteLine();
}
}

//TODO - actually re-add
//dump the img and sub
//TODO - acquire disk size first
//string imgPath = Path.ChangeExtension(path, ".img");
//string subPath = Path.ChangeExtension(path, ".sub");
//var buffer = new byte[2352];
//using (var s = File.OpenWrite(imgPath))
//{
// DiscSectorReader dsr = new DiscSectorReader(disc);

// //TODO - dont write leadout sectors, if they exist!
// for (int aba = 150; aba < disc.Sectors.Count; aba++)
// {
// dsr.ReadLBA_2352(aba - 150, buffer, 0);
// s.Write(buffer, 0, 2352);
// }
//}
//using (var s = File.OpenWrite(subPath))
//{
// //TODO - dont write leadout sectors, if they exist!
// for (int aba = 150; aba < disc.Sectors.Count; aba++)
// {
// disc.ReadLBA_SectorEntry(aba - 150).SubcodeSector.ReadSubcodeDeinterleaved(buffer, 0);
// s.Write(buffer, 0, 96);
// }
//}
string imgPath = Path.ChangeExtension(path, ".img");
string subPath = Path.ChangeExtension(path, ".sub");
var buf2448 = new byte[2448];
DiscSectorReader dsr = new DiscSectorReader(disc);

using (var imgFile = File.OpenWrite(imgPath))
using (var subFile = File.OpenWrite(subPath))
{

int nLBA = disc.Session1.LeadoutLBA;
for (int lba = 0; lba < nLBA; lba++)
{
dsr.ReadLBA_2448(lba, buf2448, 0);
imgFile.Write(buf2448, 0, 2352);
subFile.Write(buf2448, 2352, 96);
}
}

}

class SS_CCD : ISectorSynthJob2448
Expand Down
4 changes: 2 additions & 2 deletions BizHawk.Emulation.DiscSystem/DiscSectorReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ public int ReadLBA_2352(int lba, byte[] buffer, int offset)
}

/// <summary>
/// Reads the absolutely complete 2442 byte sector including all the user data and subcode
/// Reads the absolutely complete 2448 byte sector including all the user data and subcode
/// </summary>
public int ReadLBA_2442(int lba, byte[] buffer, int offset)
public int ReadLBA_2448(int lba, byte[] buffer, int offset)
{
var sector = disc.Sectors[lba + 150];

Expand Down
7 changes: 6 additions & 1 deletion BizHawk.Emulation.DiscSystem/DiscStructure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class Session
/// This excludes track 0 and the lead-out track.
/// Use this instead of Tracks.Count
/// </summary>
public int InformationTrackCount;
public int InformationTrackCount { get { return Tracks.Count - 2; } }

/// <summary>
/// All the tracks in the session.. but... Tracks[0] is the lead-in track placeholder. Tracks[1] should be "Track 1". So beware of this.
Expand All @@ -53,6 +53,11 @@ public class Session
/// </summary>
public Track FirstInformationTrack { get { return Tracks[1]; } }

/// <summary>
/// A reference to the first information track (Track 1)
/// </summary>
public Track LastInformationTrack { get { return Tracks[InformationTrackCount]; } }

/// <summary>
/// A reference to the lead-out track.
/// Effectively, the end of the user area of the disc.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class Synthesize_A0A1A2_Job
/// </summary>
public void Run(List<RawTOCEntry> entries)
{
//NOTE: entries are inserted at the beginning due to observations of CCD indicating they might need to be that way
//Since I'm being asked to synthesize them here, I guess I can put them in whatever order I want, can't I?

SubchannelQ sq = new SubchannelQ();

//ADR (q-Mode) is necessarily 0x01 for a RawTOCEntry
Expand All @@ -60,22 +63,21 @@ public void Run(List<RawTOCEntry> entries)
}
sq.ap_frame.DecimalValue = 0;

entries.Add(new RawTOCEntry { QData = sq });
entries.Insert(0, new RawTOCEntry { QData = sq });

//last recorded track number:
sq.q_index.BCDValue = 0xA1;
sq.ap_min.DecimalValue = IN_LastRecordedTrackNumber;
sq.ap_sec.DecimalValue = 0;
sq.ap_frame.DecimalValue = 0;

entries.Add(new RawTOCEntry { QData = sq });
entries.Insert(1, new RawTOCEntry { QData = sq });

//leadout:
sq.q_index.BCDValue = 0xA2;
sq.AP_Timestamp = IN_LeadoutTimestamp;


entries.Add(new RawTOCEntry { QData = sq });
entries.Insert(2, new RawTOCEntry { QData = sq });
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ public void Run()
{
session.Tracks[i].NextTrack = session.Tracks[i + 1];
}

//other misc fields
session.InformationTrackCount = session.Tracks.Count - 2;
}
}
}

0 comments on commit 901d5c1

Please sign in to comment.