From 4f978ccba90cdeac720faac90edc0ba27efdd8c8 Mon Sep 17 00:00:00 2001 From: zeromus Date: Sun, 5 Jul 2015 17:33:29 -0500 Subject: [PATCH] repair pce-cd disc loading of subQ --- .../Consoles/PC Engine/ScsiCDBus.cs | 8 +-- BizHawk.Emulation.DiscSystem/API/Disc.API.cs | 38 ----------- .../API/DiscSectorReader.cs | 65 +++++++++++++------ 3 files changed, 49 insertions(+), 62 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/PC Engine/ScsiCDBus.cs b/BizHawk.Emulation.Cores/Consoles/PC Engine/ScsiCDBus.cs index e8b09348d9..c7cdfefdbd 100644 --- a/BizHawk.Emulation.Cores/Consoles/PC Engine/ScsiCDBus.cs +++ b/BizHawk.Emulation.Cores/Consoles/PC Engine/ScsiCDBus.cs @@ -147,7 +147,7 @@ namespace BizHawk.Emulation.Cores.PCEngine PCEngine pce; public Disc disc; - SubcodeReader subcodeReader; + DiscSectorReader DiscSectorReader; SubchannelQ subchannelQ; int audioStartLBA; int audioEndLBA; @@ -156,7 +156,7 @@ namespace BizHawk.Emulation.Cores.PCEngine { this.pce = pce; this.disc = disc; - subcodeReader = new SubcodeReader(disc); + DiscSectorReader = new DiscSectorReader(disc); } public void Think() @@ -508,8 +508,8 @@ namespace BizHawk.Emulation.Cores.PCEngine case CDAudio.CDAudioMode_Stopped: DataIn.Enqueue(3); break; } - subcodeReader.ReadLBA_SubchannelQ(sectorNum, ref subchannelQ); - DataIn.Enqueue(subchannelQ.q_status); // I do not know what status is + DiscSectorReader.ReadLBA_SubQ(sectorNum, out subchannelQ); + DataIn.Enqueue(subchannelQ.q_status); //status (control and q-mode; control is useful to know if it's a data or audio track) DataIn.Enqueue(subchannelQ.q_tno.BCDValue); // track //zero 03-jul-2015 - did I adapt this right> DataIn.Enqueue(subchannelQ.q_index.BCDValue); // index //zero 03-jul-2015 - did I adapt this right> DataIn.Enqueue(subchannelQ.min.BCDValue); // M(rel) diff --git a/BizHawk.Emulation.DiscSystem/API/Disc.API.cs b/BizHawk.Emulation.DiscSystem/API/Disc.API.cs index f341d141d2..e156f7c3ff 100644 --- a/BizHawk.Emulation.DiscSystem/API/Disc.API.cs +++ b/BizHawk.Emulation.DiscSystem/API/Disc.API.cs @@ -20,44 +20,6 @@ namespace BizHawk.Emulation.DiscSystem } } - /// - /// Simplifies access to the subcode data in a disc - /// - public class SubcodeReader - { - public SubcodeReader(Disc disc) - { - this.disc = disc; - } - - public void ReadLBA_SubchannelQ(int lba, ref SubchannelQ sq) - { - var se = disc.ReadLBA_SectorEntry(lba); - se.SubcodeSector.ReadSubcodeChannel(1, buffer, 0); - int offset = 0; - - sq.q_status = buffer[offset + 0]; - sq.q_tno.BCDValue = buffer[offset + 1]; - sq.q_index.BCDValue = buffer[offset + 2]; - sq.min.BCDValue = buffer[offset + 3]; - sq.sec.BCDValue = buffer[offset + 4]; - sq.frame.BCDValue = buffer[offset + 5]; - //nothing in byte[6] - sq.ap_min.BCDValue = buffer[offset + 7]; - sq.ap_sec.BCDValue = buffer[offset + 8]; - sq.ap_frame.BCDValue = buffer[offset + 9]; - - //CRC is stored inverted and big endian.. so... do the opposite - byte hibyte = (byte)(~buffer[offset + 10]); - byte lobyte = (byte)(~buffer[offset + 11]); - sq.q_crc = (ushort)((hibyte << 8) | lobyte); - } - - Disc disc; - byte[] buffer = new byte[96]; - } - - /// /// this is junk /// diff --git a/BizHawk.Emulation.DiscSystem/API/DiscSectorReader.cs b/BizHawk.Emulation.DiscSystem/API/DiscSectorReader.cs index 28f126702a..bf19a92c05 100644 --- a/BizHawk.Emulation.DiscSystem/API/DiscSectorReader.cs +++ b/BizHawk.Emulation.DiscSystem/API/DiscSectorReader.cs @@ -80,25 +80,6 @@ namespace BizHawk.Emulation.DiscSystem if (Policy.DeterministicClearBuffer) Array.Clear(buffer, offset, size); } - /// - /// Reads the mode field from a sector - /// If this is an audio sector, the results will be nonsense. - /// - public int ReadLBA_Mode(int lba) - { - var sector = disc.Sectors[lba + 150]; - - PrepareJob(lba); - job.DestBuffer2448 = buf2442; - job.DestOffset = 0; - job.Parts = ESectorSynthPart.Header16; - job.Disc = disc; - - sector.SectorSynth.Synth(job); - - return buf2442[15]; - } - /// /// Reads a full 2352 bytes of user data from a sector /// @@ -256,9 +237,53 @@ namespace BizHawk.Emulation.DiscSystem } } + /// + /// Reads 12 bytes of subQ data from a sector and stores it unpacked into the provided struct + /// TODO - make use of deserialize code elsewhere + /// + public void ReadLBA_SubQ(int lba, out SubchannelQ sq) + { + ReadLBA_SubQ(lba, buf12, 0); - //lets not try to use this as a sector cache. it gets too complicated. its just a temporary variable. + sq.q_status = buf12[0]; + sq.q_tno.BCDValue = buf12[1]; + sq.q_index.BCDValue = buf12[2]; + sq.min.BCDValue = buf12[3]; + sq.sec.BCDValue = buf12[4]; + sq.frame.BCDValue = buf12[5]; + sq.zero = buf12[6]; + sq.ap_min.BCDValue = buf12[7]; + sq.ap_sec.BCDValue = buf12[8]; + sq.ap_frame.BCDValue = buf12[9]; + + //CRC is stored inverted and big endian.. so... do the opposite + byte hibyte = (byte)(~buf12[10]); + byte lobyte = (byte)(~buf12[11]); + sq.q_crc = (ushort)((hibyte << 8) | lobyte); + } + + /// + /// Reads the mode field from a sector + /// If this is an audio sector, the results will be nonsense. + /// + public int ReadLBA_Mode(int lba) + { + var sector = disc.Sectors[lba + 150]; + + PrepareJob(lba); + job.DestBuffer2448 = buf2442; + job.DestOffset = 0; + job.Parts = ESectorSynthPart.Header16; + job.Disc = disc; + + sector.SectorSynth.Synth(job); + + return buf2442[15]; + } + + //lets not try to these as a sector cache. it gets too complicated. its just a temporary variable. byte[] buf2442 = new byte[2448]; + byte[] buf12 = new byte[12]; SectorSynthJob job = new SectorSynthJob(); } } \ No newline at end of file