From 9ff8b450f440ed6a3d34430ce79ddebdd204fcdb Mon Sep 17 00:00:00 2001 From: zeromus Date: Mon, 5 Nov 2012 00:11:41 +0000 Subject: [PATCH] add the crudest possible psx disc detector. now other people can watch somewhat garbled psx game intros --- BizHawk.Emulation/Consoles/PSX/Octoshock.cs | 15 +++++++++++++ BizHawk.Emulation/DiscSystem/Disc.API.cs | 24 +++++++++++++++++++++ BizHawk.MultiClient/MainForm.cs | 3 ++- 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/BizHawk.Emulation/Consoles/PSX/Octoshock.cs b/BizHawk.Emulation/Consoles/PSX/Octoshock.cs index 917e7cc23a..e20141cc9e 100644 --- a/BizHawk.Emulation/Consoles/PSX/Octoshock.cs +++ b/BizHawk.Emulation/Consoles/PSX/Octoshock.cs @@ -22,6 +22,21 @@ namespace BizHawk.Emulation.Consoles.PSX public bool StartAsyncSound() { return true; } public void EndAsyncSound() { } + public static bool CheckIsPSX(DiscSystem.Disc disc) + { + bool ret = false; + + byte[] buf = new byte[59]; + disc.ReadLBA_2352_Flat(0x24D8, buf, 0, 59); + string sig = System.Text.ASCIIEncoding.ASCII.GetString(buf); + + //this string is considered highly unlikely to exist anywhere besides a psx disc + if (sig == " Licensed by Sony Computer Entertainment") + ret = true; + + return ret; + } + //we can only have one active core at a time, due to the lib being so static. //so we'll track the current one here and detach the previous one whenever a new one is booted up. static Octoshock CurrOctoshockCore; diff --git a/BizHawk.Emulation/DiscSystem/Disc.API.cs b/BizHawk.Emulation/DiscSystem/Disc.API.cs index f7637b923c..389b00fdc8 100644 --- a/BizHawk.Emulation/DiscSystem/Disc.API.cs +++ b/BizHawk.Emulation/DiscSystem/Disc.API.cs @@ -92,6 +92,30 @@ namespace BizHawk.DiscSystem Array.Copy(temp, 16, buffer, offset, 2048); } + /// + /// reads logical data from a flat disc address space + /// useful for plucking data from a known location on the disc + /// + public void ReadLBA_2352_Flat(long disc_offset, byte[] buffer, int offset, int length) + { + int secsize = 2352; + byte[] lba_buf = new byte[secsize]; + while(length > 0) + { + int lba = (int)(disc_offset / secsize); + int lba_within = (int)(disc_offset % secsize); + int todo = length; + int remains_in_lba = secsize - lba_within; + if (remains_in_lba < todo) + todo = remains_in_lba; + ReadLBA_2352(lba, lba_buf, 0); + Array.Copy(lba_buf, lba_within, buffer, offset, todo); + offset += todo; + length -= todo; + lba_within = 0; + } + } + /// /// Returns a SectorEntry from which you can retrieve various interesting pieces of information about the sector. diff --git a/BizHawk.MultiClient/MainForm.cs b/BizHawk.MultiClient/MainForm.cs index 011caffa84..716bdcd905 100644 --- a/BizHawk.MultiClient/MainForm.cs +++ b/BizHawk.MultiClient/MainForm.cs @@ -1435,12 +1435,13 @@ namespace BizHawk.MultiClient // In the future we need to do something smarter, possibly including simply asking the user // what system the game is for. - if (System.Windows.Forms.SystemInformation.ComputerName == "ZERO-XP") + if (BizHawk.Emulation.Consoles.PSX.Octoshock.CheckIsPSX(disc)) { game = new GameInfo(); game.System = "PSX"; game.Name = Path.GetFileNameWithoutExtension(file.Name); game.Hash = hash; + disc.Dispose(); } else {