From de5eaf3c4bfa323116a23a148ef878d7b856c948 Mon Sep 17 00:00:00 2001 From: zeromus Date: Wed, 10 Dec 2014 19:39:19 +0000 Subject: [PATCH] discsystem bugfixes: create TOCRaw for CUE files, fix Q subchannel generation Control field, make Read_2048 support multiple modes (but im not sure how great an idea it is now); add copious warnings about unsafe junk that needs rewriting --- BizHawk.Emulation.DiscSystem/Disc.cs | 32 ++++++++++++++++--- .../SectorInterfaces.cs | 13 +++++++- .../TOC/DiscStructure.cs | 4 +++ 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/BizHawk.Emulation.DiscSystem/Disc.cs b/BizHawk.Emulation.DiscSystem/Disc.cs index b135493420..690e7907aa 100644 --- a/BizHawk.Emulation.DiscSystem/Disc.cs +++ b/BizHawk.Emulation.DiscSystem/Disc.cs @@ -205,7 +205,8 @@ FILE ""xarp.barp.marp.farp"" BINARY var ret = new Disc(); ret.FromCuePathInternal(cuePath, prefs); ret.Structure.Synthesize_TOCPointsFromSessions(); - ret.Synthesize_SubcodeFromCurrentTOC(); + ret.Synthesize_SubcodeFromStructure(); + ret.Synthesize_TOCRawFromStructure(); return ret; } @@ -223,15 +224,38 @@ FILE ""xarp.barp.marp.farp"" BINARY var ret = new Disc(); ret.FromIsoPathInternal(isoPath); ret.Structure.Synthesize_TOCPointsFromSessions(); - ret.Synthesize_SubcodeFromCurrentTOC(); + ret.Synthesize_SubcodeFromStructure(); return ret; } + /// + /// Synthesizes a crudely estimated TOCRaw from the disc structure. + /// + public void Synthesize_TOCRawFromStructure() + { + TOCRaw = new DiscTOCRaw(); + TOCRaw.FirstRecordedTrackNumber = 1; + TOCRaw.LastRecordedTrackNumber = Structure.Sessions[0].Tracks.Count; + int lastEnd = 0; + for (int i = 0; i < Structure.Sessions[0].Tracks.Count; i++) + { + var track = Structure.Sessions[0].Tracks[i]; + TOCRaw.TOCItems[i + 1].Control = track.Control; + TOCRaw.TOCItems[i + 1].Exists = true; + //TOCRaw.TOCItems[i + 1].LBATimestamp = new Timestamp(track.Start_ABA - 150); //AUGH. see comment in Start_ABA + //TOCRaw.TOCItems[i + 1].LBATimestamp = new Timestamp(track.Indexes[1].LBA); //ZOUNDS! + TOCRaw.TOCItems[i + 1].LBATimestamp = new Timestamp(track.Indexes[1].LBA + 150); //WHATEVER, I DONT KNOW. MAKES IT MATCH THE CCD, BUT THERES MORE PROBLEMS + lastEnd = track.LengthInSectors + track.Indexes[1].LBA; + } + + TOCRaw.LeadoutTimestamp = new Timestamp(lastEnd); + } + /// /// Creates the subcode (really, just subchannel Q) for this disc from its current TOC. /// Depends on the TOCPoints existing in the structure /// - void Synthesize_SubcodeFromCurrentTOC() + void Synthesize_SubcodeFromStructure() { int aba = 0; int dpIndex = 0; @@ -249,7 +273,7 @@ FILE ""xarp.barp.marp.farp"" BINARY var se = Sectors[aba]; - EControlQ control = EControlQ.None; + EControlQ control = dp.Track.Control; //we always use ADR=1 (mode-1 q block) //this could be more sophisticated but it is almost useless for emulation (only useful for catalog/ISRC numbers) diff --git a/BizHawk.Emulation.DiscSystem/SectorInterfaces.cs b/BizHawk.Emulation.DiscSystem/SectorInterfaces.cs index 6c7d0da9b3..2f16075679 100644 --- a/BizHawk.Emulation.DiscSystem/SectorInterfaces.cs +++ b/BizHawk.Emulation.DiscSystem/SectorInterfaces.cs @@ -31,7 +31,18 @@ namespace BizHawk.Emulation.DiscSystem } public int Read_2048(byte[] buffer, int offset) { - return Blob.Read(Offset, buffer, offset, 2048); + //this depends on CD-XA mode and such. so we need to read the mode bytes + //HEY!!!!!! SHOULD THIS BE DONE BASED ON THE CLAIMED TRACK TYPE, OR ON WHATS IN THE SECTOR? + //this is kind of a function of the CD reader.. it's not clear how this function should work. + //YIKES!!!!!!!!!!!!!! + //well, we need to scrutinize it for CCD files anyway, so... + //this sucks. + Blob.Read(Offset + 16, buffer, 0, 1); + byte mode = buffer[0]; + if(mode == 1) + return Blob.Read(Offset + 16, buffer, offset, 2048); + else + return Blob.Read(Offset + 24, buffer, offset, 2048); } } diff --git a/BizHawk.Emulation.DiscSystem/TOC/DiscStructure.cs b/BizHawk.Emulation.DiscSystem/TOC/DiscStructure.cs index 429d94851a..4b0a044711 100644 --- a/BizHawk.Emulation.DiscSystem/TOC/DiscStructure.cs +++ b/BizHawk.Emulation.DiscSystem/TOC/DiscStructure.cs @@ -187,6 +187,10 @@ namespace BizHawk.Emulation.DiscSystem /// /// The beginning ABA of the track (index 1). This isn't well-supported, yet + /// WHAT? IS THIS NOT AN ABA SOMETIMES? + /// IS IT THE INDEX 0 OF THE TRACK? THATS FUCKED UP. COMPARE TO TOCRAW ENTRIES. IT SHOULD BE MATCHING THAT + /// HEY??? SHOULD THIS EVEN BE HERE? YOURE SUPPOSED TO USE THE INDEXES INSTEAD. + /// WELL, IF WE KEEP THIS THE MEANING SHOULD BE SAME AS INDEX[1].LBA (or ABA) SO BE SURE TO WRITE THAT COMMENT HERE /// public int Start_ABA;