diff --git a/BizHawk.Emulation.Cores/Consoles/Sony/PSX/Octoshock.cs b/BizHawk.Emulation.Cores/Consoles/Sony/PSX/Octoshock.cs index 64cdfca665..c8c738ac72 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sony/PSX/Octoshock.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sony/PSX/Octoshock.cs @@ -201,10 +201,14 @@ namespace BizHawk.Emulation.Cores.Sony.PSX //todo - cache reader DiscSystem.DiscSectorReader dsr = new DiscSystem.DiscSectorReader(Disc); - dsr.ReadLBA_2448(lba, SectorBuffer, 0); - Marshal.Copy(SectorBuffer, 0, new IntPtr(dst), 2448); - - return OctoshockDll.SHOCK_OK; + int readed = dsr.ReadLBA_2448(lba, SectorBuffer, 0); + if (readed == 2448) + { + Marshal.Copy(SectorBuffer, 0, new IntPtr(dst), 2448); + return OctoshockDll.SHOCK_OK; + } + else + return OctoshockDll.SHOCK_ERROR; } } diff --git a/BizHawk.Emulation.DiscSystem/DiscSectorReader.cs b/BizHawk.Emulation.DiscSystem/DiscSectorReader.cs index 5917fae582..71dd18298e 100644 --- a/BizHawk.Emulation.DiscSystem/DiscSectorReader.cs +++ b/BizHawk.Emulation.DiscSystem/DiscSectorReader.cs @@ -87,6 +87,8 @@ namespace BizHawk.Emulation.DiscSystem { var sector = disc.SynthProvider.Get(lba); + if (sector == null) return 0; + PrepareBuffer(buffer, offset, 2352); PrepareJob(lba); job.DestBuffer2448 = buf2442; @@ -110,6 +112,8 @@ namespace BizHawk.Emulation.DiscSystem public int ReadLBA_2448(int lba, byte[] buffer, int offset) { var sector = disc.SynthProvider.Get(lba); + + if (sector == null) return 0; PrepareBuffer(buffer, offset, 2352); PrepareJob(lba); @@ -122,7 +126,7 @@ namespace BizHawk.Emulation.DiscSystem sector.Synth(job); //we went straight to the caller's buffer, so no need to copy - return 2442; + return 2448; } int ReadLBA_2048_Mode1(int lba, byte[] buffer, int offset) @@ -130,6 +134,8 @@ namespace BizHawk.Emulation.DiscSystem //we can read the 2048 bytes directly var sector = disc.SynthProvider.Get(lba); + if (sector == null) return 0; + PrepareBuffer(buffer, offset, 2048); PrepareJob(lba); job.DestBuffer2448 = buf2442; @@ -147,6 +153,8 @@ namespace BizHawk.Emulation.DiscSystem //we can read the 2048 bytes directly but we have to get them from the mode 2 data var sector = disc.SynthProvider.Get(lba); + if (sector == null) return 0; + PrepareBuffer(buffer, offset, 2048); PrepareJob(lba); job.DestBuffer2448 = buf2442; @@ -167,6 +175,8 @@ namespace BizHawk.Emulation.DiscSystem { var sector = disc.SynthProvider.Get(lba); + if (sector == null) return 0; + PrepareBuffer(buffer, offset, 12); PrepareJob(lba); job.DestBuffer2448 = buf2442; @@ -198,6 +208,8 @@ namespace BizHawk.Emulation.DiscSystem //in no case do we need the ECC so build special flags here var sector = disc.SynthProvider.Get(lba); + if (sector == null) return 0; + PrepareBuffer(buffer, offset, 2048); PrepareJob(lba); job.DestBuffer2448 = buf2442; @@ -273,6 +285,8 @@ namespace BizHawk.Emulation.DiscSystem { var sector = disc.SynthProvider.Get(lba); + if (sector == null) return 0; + PrepareJob(lba); job.DestBuffer2448 = buf2442; job.DestOffset = 0; diff --git a/BizHawk.Emulation.DiscSystem/Internal/SectorSynth.cs b/BizHawk.Emulation.DiscSystem/Internal/SectorSynth.cs index a16dee9813..07caf7d171 100644 --- a/BizHawk.Emulation.DiscSystem/Internal/SectorSynth.cs +++ b/BizHawk.Emulation.DiscSystem/Internal/SectorSynth.cs @@ -133,6 +133,8 @@ namespace BizHawk.Emulation.DiscSystem public ISectorSynthJob2448 Get(int lba) { int index = lba - FirstLBA; + if (index < 0) return null; + if (index >= Sectors.Count) return null; return Sectors[index]; } } diff --git a/output/dll/octoshock.dll b/output/dll/octoshock.dll index 1786a3712b..e8a0a325dc 100644 Binary files a/output/dll/octoshock.dll and b/output/dll/octoshock.dll differ diff --git a/psx/octoshock/psx/psx.cpp b/psx/octoshock/psx/psx.cpp index bbe63bba12..7a30774eb9 100644 --- a/psx/octoshock/psx/psx.cpp +++ b/psx/octoshock/psx/psx.cpp @@ -2415,11 +2415,12 @@ Breakout: bool ShockDiscRef::ReadLBA_PW(uint8* pwbuf96, int32 lba, bool hint_fullread) { //TODO - whats that hint mean - //TODO - should return false if out of range totally //reference: static const int32 LBA_Read_Minimum = -150; //reference: static const int32 LBA_Read_Maximum = 449849; // 100 * 75 * 60 - 150 - 1 u8 tmp[2448]; - ReadLBA2448(lba,tmp); + s32 ret = ReadLBA2448(lba,tmp); + if(ret != SHOCK_OK) + return false; memcpy(pwbuf96,tmp+2352,96); return true; }