From e703d3a99fa3965f9e2c0c72560b1a50f9ca20e3 Mon Sep 17 00:00:00 2001 From: beirich Date: Tue, 16 Aug 2011 03:11:27 +0000 Subject: [PATCH] [pce] fix R-Type CD audio start bug(s) --- .../Consoles/PC Engine/ScsiCDBus.cs | 9 +++-- BizHawk.Emulation/DiscSystem/Disc.API.cs | 3 +- BizHawk.Emulation/Sound/CDAudio.cs | 33 ++++--------------- BizHawk.Emulation/Util.cs | 4 +-- 4 files changed, 14 insertions(+), 35 deletions(-) diff --git a/BizHawk.Emulation/Consoles/PC Engine/ScsiCDBus.cs b/BizHawk.Emulation/Consoles/PC Engine/ScsiCDBus.cs index 2a8c41b384..ae6359c911 100644 --- a/BizHawk.Emulation/Consoles/PC Engine/ScsiCDBus.cs +++ b/BizHawk.Emulation/Consoles/PC Engine/ScsiCDBus.cs @@ -378,7 +378,6 @@ namespace BizHawk.Emulation.Consoles.TurboGrafx int sector = (CommandBuffer[1] & 0x1f) << 16; sector |= CommandBuffer[2] << 8; sector |= CommandBuffer[3]; - sector += 150; // BLEH if (CommandBuffer[4] == 0) throw new Exception("requesting 0 sectors read............................."); @@ -414,7 +413,7 @@ throw new Exception("requesting 0 sectors read............................."); case 0x80: // Set start offset in track units byte trackNo = CommandBuffer[2].BCDtoBin(); - audioStartLBA = disc.TOC.Sessions[0].Tracks[trackNo - 1].Indexes[1].LBA; + audioStartLBA = disc.TOC.Sessions[0].Tracks[trackNo - 1].Indexes[1].aba - 150; Console.WriteLine("Set Start track: {0} lba={1}", trackNo, audioStartLBA); break; } @@ -454,7 +453,7 @@ throw new Exception("requesting 0 sectors read............................."); case 0x80: // Set end offset in track units byte trackNo = CommandBuffer[2].BCDtoBin(); - audioEndLBA = disc.TOC.Sessions[0].Tracks[trackNo - 1].Indexes[1].LBA; + audioEndLBA = disc.TOC.Sessions[0].Tracks[trackNo - 1].Indexes[1].aba - 150; Console.WriteLine("Set End track: {0} lba={1}", trackNo, audioEndLBA); break; } @@ -496,7 +495,7 @@ throw new Exception("requesting 0 sectors read............................."); private void CommandReadSubcodeQ() { - var sectorEntry = disc.ReadLBA_SectorEntry(pce.CDAudio.CurrentSector); + var sectorEntry = disc.ReadLBA_SectorEntry(pce.CDAudio.CurrentSector); DataIn.Clear(); @@ -560,7 +559,7 @@ throw new Exception("requesting 0 sectors read............................."); throw new Exception("Request more tracks than exist.... need to do error handling"); // I error handled your mom last night - int lbaPos = disc.TOC.Sessions[0].Tracks[track].Indexes[1].LBA; + int lbaPos = disc.TOC.Sessions[0].Tracks[track].Indexes[1].aba - 150; byte m, s, f; Disc.ConvertLBAtoMSF(lbaPos, out m, out s, out f); diff --git a/BizHawk.Emulation/DiscSystem/Disc.API.cs b/BizHawk.Emulation/DiscSystem/Disc.API.cs index d79edbacf7..61558fc763 100644 --- a/BizHawk.Emulation/DiscSystem/Disc.API.cs +++ b/BizHawk.Emulation/DiscSystem/Disc.API.cs @@ -148,6 +148,7 @@ namespace BizHawk.DiscSystem //TODO - somewhat redundant with Timestamp, which is due for refactoring into something not cue-related public static void ConvertLBAtoMSF(int lba, out byte m, out byte s, out byte f) { + lba += 150; m = (byte) (lba / 75 / 60); s = (byte) ((lba - (m * 75 * 60)) / 75); f = (byte) (lba - (m * 75 * 60) - (s * 75)); @@ -156,7 +157,7 @@ namespace BizHawk.DiscSystem // converts MSF to LBA offset public static int ConvertMSFtoLBA(byte m, byte s, byte f) { - return f + (s*75) + (m*75*60); + return f + (s*75) + (m*75*60) - 150; } // gets an identifying hash. hashes the first 512 sectors of diff --git a/BizHawk.Emulation/Sound/CDAudio.cs b/BizHawk.Emulation/Sound/CDAudio.cs index 9e40fd72bc..84b0560f99 100644 --- a/BizHawk.Emulation/Sound/CDAudio.cs +++ b/BizHawk.Emulation/Sound/CDAudio.cs @@ -51,9 +51,8 @@ namespace BizHawk.Emulation.Sound if (track < 1 || track > Disc.TOC.Sessions[0].Tracks.Count) return; - //note for vecna: you may find that the new "Point" and "SeekPoint" concept in the TOC is more useful than this kind of logic. just something to think about - StartLBA = Disc.TOC.Sessions[0].Tracks[track - 1].Indexes[1].LBA; - EndLBA = StartLBA + Disc.TOC.Sessions[0].Tracks[track - 1].length_aba; + StartLBA = Disc.TOC.Sessions[0].Tracks[track - 1].Indexes[1].aba - 150; + EndLBA = StartLBA + Disc.TOC.Sessions[0].Tracks[track - 1].length_aba; PlayingTrack = track; CurrentSector = StartLBA; SectorOffset = 0; @@ -62,31 +61,11 @@ namespace BizHawk.Emulation.Sound public void PlayStartingAtLba(int lba) { - int track; - var tracks = Disc.TOC.Sessions[0].Tracks; - bool foundTrack = false; + var point = Disc.TOC.SeekPoint(lba); + PlayingTrack = point.TrackNum; + StartLBA = lba; + EndLBA = point.Track.Indexes[1].aba + point.Track.length_aba - 150; - //note for vecna: you may find that the new "Point" and "SeekPoint" concept in the TOC is more useful than this kind of logic. just something to think about - for (track = 0; track < tracks.Count; track++) - { - int trackStart = tracks[track].Indexes[0].LBA; - int trackEnd = trackStart + tracks[track].length_aba; - if (lba >= trackStart && lba < trackEnd) - { - foundTrack = true; - StartLBA = lba; - EndLBA = trackEnd; - break; - } - } - - if (foundTrack == false) - { - Stop(); - return; - } - - PlayingTrack = track + 1; CurrentSector = StartLBA; SectorOffset = 0; Mode = CDAudioMode.Playing; diff --git a/BizHawk.Emulation/Util.cs b/BizHawk.Emulation/Util.cs index 5b872464bb..443c0b1681 100644 --- a/BizHawk.Emulation/Util.cs +++ b/BizHawk.Emulation/Util.cs @@ -616,12 +616,12 @@ namespace BizHawk public static byte BinToBCD(this byte v) { - return (byte) (((v/10)*16) | (v%10)); + return (byte) (((v / 10) * 16) + (v % 10)); } public static byte BCDtoBin(this byte v) { - return (byte)(((v / 16) * 10) | (v % 16)); + return (byte) (((v / 16) * 10) + (v % 16)); } public static string FormatFileSize(long filesize)