diff --git a/src/BizHawk.Emulation.Cores/Consoles/Sega/PicoDrive/LibPicoDrive.cs b/src/BizHawk.Emulation.Cores/Consoles/Sega/PicoDrive/LibPicoDrive.cs index 0df8bae96d..ea07e055d9 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Sega/PicoDrive/LibPicoDrive.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Sega/PicoDrive/LibPicoDrive.cs @@ -29,7 +29,25 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.PicoDrive /// If TRUE, preallocate 32X data structures. When set to false, /// 32X games will still run, but will not have memory domains [BizImport(CC)] - public abstract bool Init(bool cd, bool _32xPreinit, Region regionAutoOrder, Region regionOverride); + public abstract bool Init(bool cd, bool _32xPreinit, Region regionAutoOrder, Region regionOverride); + + public const int CD_MAX_TRACKS = 100; + + [StructLayout(LayoutKind.Sequential)] + public struct Track + { + public int start; + public int end; + } + + [StructLayout(LayoutKind.Sequential)] + public class TOC + { + public int end; + public int last; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = CD_MAX_TRACKS)] + public readonly Track[] tracks = new Track[CD_MAX_TRACKS]; + } [BizImport(CC)] public abstract void SetCDReadCallback(CDReadCallback callback); diff --git a/src/BizHawk.Emulation.Cores/Consoles/Sega/PicoDrive/PicoDrive.cs b/src/BizHawk.Emulation.Cores/Consoles/Sega/PicoDrive/PicoDrive.cs index f6f79c05ad..fad2125799 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Sega/PicoDrive/PicoDrive.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Sega/PicoDrive/PicoDrive.cs @@ -71,7 +71,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.PicoDrive _exe.AddReadonlyFile(comm.CoreFileProvider.GetFirmwareOrThrow(new("GEN", "CD_BIOS_EU")), "cd.eu"); _exe.AddReadonlyFile(comm.CoreFileProvider.GetFirmwareOrThrow(new("GEN", "CD_BIOS_US")), "cd.us"); _exe.AddReadonlyFile(comm.CoreFileProvider.GetFirmwareOrThrow(new("GEN", "CD_BIOS_JP")), "cd.jp"); - _exe.AddReadonlyFile(gpgx.GPGX.GetCDData(cd), "toc"); + _exe.AddReadonlyFile(GetTOC(cd), "toc"); _cd = cd; _cdReader = new DiscSectorReader(_cd); _core.SetCDReadCallback(_cdcallback); @@ -154,6 +154,46 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.PicoDrive return new LibPicoDrive.FrameInfo { Buttons = b }; } + private static byte[] GetTOC(Disc cd) + { + var toc = new LibPicoDrive.TOC(); + + var ses = cd.Session1; + var ntrack = ses.InformationTrackCount; + + for (var i = 0; i < LibPicoDrive.CD_MAX_TRACKS; i++) + { + if (i < ntrack) + { + toc.tracks[i].start = ses.Tracks[i + 1].LBA; + toc.tracks[i].end = ses.Tracks[i + 2].LBA; + if (i == ntrack - 1) + { + toc.end = toc.tracks[i].end; + toc.last = ntrack; + } + } + else + { + toc.tracks[i].start = 0; + toc.tracks[i].end = 0; + } + } + + var size = Marshal.SizeOf(toc); + var ret = new byte[size]; + + unsafe + { + fixed (byte* p = ret) + { + Marshal.StructureToPtr(ret, (IntPtr)p, false); + } + } + + return ret; + } + private void CDRead(int lba, IntPtr dest, bool audio) { if (audio) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.cs b/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.cs index f6a5dfd511..3eff376ec3 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.cs @@ -304,17 +304,21 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx var ret = new LibGPGX.CDData(); var ses = cd.Session1; - int ntrack = ses.InformationTrackCount; + var ntrack = ses.InformationTrackCount; // bet you a dollar this is all wrong - //zero 07-jul-2015 - throws a dollar in the pile, since he probably messed it up worse - for (int i = 0; i < LibGPGX.CD_MAX_TRACKS; i++) + // zero 07-jul-2015 - throws a dollar in the pile, since he probably messed it up worse + for (var i = 0; i < LibGPGX.CD_MAX_TRACKS; i++) { + ret.tracks[i].fd = IntPtr.Zero; + ret.tracks[i].loopEnabled = 0; + ret.tracks[i].loopOffset = 0; + if (i < ntrack) { - ret.tracks[i].mode = ses.Tracks[i].Mode; ret.tracks[i].start = ses.Tracks[i + 1].LBA; ret.tracks[i].end = ses.Tracks[i + 2].LBA; + ret.tracks[i].mode = ses.Tracks[i].Mode; if (i == ntrack - 1) { ret.end = ret.tracks[i].end; @@ -323,25 +327,27 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx } else { - ret.tracks[i].mode = 0; ret.tracks[i].start = 0; ret.tracks[i].end = 0; + ret.tracks[i].mode = 0; } } + ret.sub = IntPtr.Zero; return ret; } public static unsafe byte[] GetCDData(Disc cd) { var ret = GetCDDataStruct(cd); - int size = Marshal.SizeOf(ret); - byte[] retdata = new byte[size]; + var size = Marshal.SizeOf(ret); + var retdata = new byte[size]; - fixed (byte* p = &retdata[0]) + fixed (byte* p = retdata) { Marshal.StructureToPtr(ret, (IntPtr)p, false); } + return retdata; } diff --git a/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/LibGPGX.cs b/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/LibGPGX.cs index aa355da0eb..cd8f12744f 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/LibGPGX.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/LibGPGX.cs @@ -282,9 +282,12 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx [StructLayout(LayoutKind.Sequential)] public struct CDTrack { + public IntPtr fd; public int start; public int end; public int mode; + public int loopEnabled; + public int loopOffset; } [StructLayout(LayoutKind.Sequential)] @@ -294,6 +297,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx public int last; [MarshalAs(UnmanagedType.ByValArray, SizeConst = CD_MAX_TRACKS)] public readonly CDTrack[] tracks = new CDTrack[CD_MAX_TRACKS]; + public IntPtr sub; } [BizImport(CallingConvention.Cdecl)]