Пример #1
0
        // SDK location: /umd/pspumd.h:42
        // SDK declaration: int sceUmdCheckMedium();
        public int sceUmdCheckMedium()
        {
            IUmdDevice umd = _kernel.Emulator.Umd;

            if (umd == null)
            {
                return(0);
            }
            else
            {
                return((umd.State == MediaState.Present) ? 1 : 0);
            }
        }
Пример #2
0
        /// <summary>
        /// Find the game on the given UMD device.
        /// </summary>
        /// <param name="device">The UMD to search.</param>
        /// <returns>The game found on the device, or <c>null</c> if none was found.</returns>
        public static GameInformation FindGame(IUmdDevice device)
        {
            Debug.Assert(device != null);
            if (device == null)
            {
                return(null);
            }

            GameInformation info = GameLoader.GetUmdGameInformation(device);

            Debug.Assert(info != null);

            return(info);
        }
Пример #3
0
        public static List <GameInformation> FindGames(string path)
        {
            List <GameInformation> games = new List <GameInformation>();

            foreach (string umdFile in Directory.GetFiles(path, "*.iso"))
            {
                string     umdPath = Path.Combine(path, umdFile);
                IUmdDevice device  = (new Noxa.Emulation.Psp.Media.Iso.IsoFileSystem()).CreateInstance(null, new ComponentParameters()) as IUmdDevice;
                device.Load(umdPath, true);
                GameInformation info = GameLoader.FindGame(device);
                games.Add(info);
            }

            return(games);
        }
Пример #4
0
        // manual add
        public int sceUmdGetDiscInfo(int discInfo)
        {
            IUmdDevice umd = _kernel.Emulator.Umd;

            if (umd == null)
            {
                return(-1);
            }

            unsafe
            {
                uint *pinfo = ( uint * )_memorySystem.Translate(( uint )discInfo);
                *     pinfo = ( uint )umd.Capacity;
                *(pinfo + 1) = ( uint )umd.DiscType;
            }

            return(0);
        }
Пример #5
0
        private GameInformation LoadGameFromUmd(string gamePath)
        {
            //try
            {
                if (File.Exists(gamePath) == false)
                {
                    return(null);
                }

                //Type deviceType = _emulator.Umd.Factory;
                //IComponent component = ( IComponent )Activator.CreateInstance( deviceType );
                //Debug.Assert( component != null );
                //if( component == null )
                //    throw new InvalidOperationException();

                //ComponentParameters parameters = new ComponentParameters();
                //parameters[ "path" ] = gamePath;
                //IUmdDevice umdDevice = component.CreateInstance( _emulator, parameters ) as IUmdDevice;
                //Debug.Assert( umdDevice != null );
                //if( umdDevice == null )
                //    throw new InvalidOperationException();

                IUmdDevice umdDevice = _emulator.Umd;
                if (umdDevice.Load(gamePath, true) == false)
                {
                    return(null);
                }

                GameInformation game = GameLoader.FindGame(umdDevice);
                if (game != null)
                {
                    game.HostPath = gamePath;
                }

                umdDevice.Cleanup();

                return(game);
            }
            //catch
            {
                //Debug.Assert( false );
                //return null;
            }
        }
Пример #6
0
        /// <summary>
        /// Find the game on the given UMD device.
        /// </summary>
        /// <param name="device">The UMD to search.</param>
        /// <returns>The game found on the device, or <c>null</c> if none was found.</returns>
        public static GameInformation FindGame( IUmdDevice device )
        {
            Debug.Assert( device != null );
            if( device == null )
                return null;

            GameInformation info = GameLoader.GetUmdGameInformation( device );
            Debug.Assert( info != null );

            return info;
        }
Пример #7
0
        public bool Create()
        {
            Debug.Assert( _isCreated == false );
            if( _isCreated == true )
                return true;

            _shutDown = false;
            _state = InstanceState.Idle;

            // Try to create all the components
            Debug.Assert( _params.BiosComponent != null );
            Debug.Assert( _params.CpuComponent != null );
            if( _params.AudioComponent != null )
            {
                _audio = _params.AudioComponent.CreateInstance( this, _params[ _params.AudioComponent ] ) as IAudioDriver;
                _instances.Add( ( IComponentInstance )_audio );
            }
            _cpu = _params.CpuComponent.CreateInstance( this, _params[ _params.CpuComponent ] ) as ICpu;
            _instances.Add( ( IComponentInstance )_cpu );
            _bios = _params.BiosComponent.CreateInstance( this, _params[ _params.BiosComponent ] ) as IBios;
            _instances.Add( ( IComponentInstance )_bios );
            foreach( IComponent component in _params.IOComponents )
            {
                IIODriver driver = component.CreateInstance( this, _params[ component ] ) as IIODriver;
                _io.Add( driver );
                _instances.Add( ( IComponentInstance )driver );
            }
            if( _params.InputComponent != null )
            {
                _input = _params.InputComponent.CreateInstance( this, _params[ _params.InputComponent ] ) as IInputDevice;
                _instances.Add( _input );
                _input.WindowHandle = _host.Player.Handle;
            }
            if( _params.UmdComponent != null )
            {
                _umd = _params.UmdComponent.CreateInstance( this, _params[ _params.UmdComponent ] ) as IUmdDevice;
                _instances.Add( _umd );
            }
            if( _params.MemoryStickComponent != null )
            {
                _memoryStick = _params.MemoryStickComponent.CreateInstance( this, _params[ _params.MemoryStickComponent ] ) as IMemoryStickDevice;
                _instances.Add( _memoryStick );
            }
            if( _params.VideoComponent != null )
            {
                _video = _params.VideoComponent.CreateInstance( this, _params[ _params.VideoComponent ] ) as IVideoDriver;
                _video.ControlHandle = _host.Player.ControlHandle;
                _instances.Add( ( IComponentInstance )_video );
            }

            #if XMB
            _xmb = new CrossMediaBar.Manager( this, _host.Player.Handle, _host.Player.ControlHandle );
            #else
            #endif

            // Create thread
            _thread = new Thread( new ThreadStart( this.RuntimeThread ) );
            _thread.Name = "Host runtime thread";
            _thread.IsBackground = true;
            _thread.Start();

            _isCreated = true;

            return true;
        }
Пример #8
0
        public int realIoOpen(int fileName, int flags, int mode, bool async)
        {
            string path = _kernel.ReadString(( uint )fileName);

            if (string.IsNullOrEmpty(path) == true)
            {
                return(-1);
            }
            IMediaItem item = _kernel.FindPath(path);

            if (item is IMediaFolder)
            {
                // Block access?
                Debug.Assert(item.Device is IUmdDevice);
                IUmdDevice umd    = ( IUmdDevice )item.Device;
                Stream     stream = umd.OpenImageStream();
                if (stream == null)
                {
                    Log.WriteLine(Verbosity.Normal, Feature.Bios, "sceIoOpen: could not open image stream '{0}'", path);

                    if (async == true)
                    {
                        KFile fakehandle = new KFile(_kernel, false);
                        fakehandle.Result       = 0x80010002;
                        fakehandle.PendingClose = true;
                        _kernel.AddHandle(fakehandle);
                        return(( int )fakehandle.UID);
                    }

                    return(-1);
                }

                KDevice dev = _kernel.FindDevice(umd);
                Debug.Assert(dev != null);

                KFile handle = new KFile(_kernel, dev, item, stream);
                handle.IsBlockAccess = true;
                _kernel.AddHandle(handle);

                handle.Result = handle.UID;

                Log.WriteLine(Verbosity.Verbose, Feature.Bios, "sceIoOpen: opened block access on {0} with ID {1:X}", path, handle.UID);

                return(( int )handle.UID);
            }
            else
            {
                IMediaFile file = ( IMediaFile )item;
                if (file == null)
                {
                    // Create if needed
                    if ((flags & 0x0200) != 0)
                    {
                        string       newName;
                        IMediaFolder parent;
                        if (path.IndexOf('/') >= 0)
                        {
                            string parentPath = path.Substring(0, path.LastIndexOf('/'));
                            newName = path.Substring(path.LastIndexOf('/') + 1);
                            parent  = ( IMediaFolder )_kernel.FindPath(parentPath);
                        }
                        else
                        {
                            newName = path;
                            parent  = _kernel.CurrentPath;
                        }
                        if (parent == null)
                        {
                            Log.WriteLine(Verbosity.Normal, Feature.Bios, "sceIoOpen: could not find parent to create file '{0}' in on open", path);

                            if (async == true)
                            {
                                KFile fakehandle = new KFile(_kernel, false);
                                fakehandle.Result       = 0x80010002;
                                fakehandle.PendingClose = true;
                                _kernel.AddHandle(fakehandle);
                                return(( int )fakehandle.UID);
                            }

                            return(-1);
                        }
                        file = parent.CreateFile(newName);
                    }
                    else
                    {
                        Log.WriteLine(Verbosity.Normal, Feature.Bios, "sceIoOpen: could not find path '{0}'", path);

                        if (async == true)
                        {
                            KFile fakehandle = new KFile(_kernel, false);
                            fakehandle.Result       = 0x80010002;
                            fakehandle.PendingClose = true;
                            _kernel.AddHandle(fakehandle);
                            return(( int )fakehandle.UID);
                        }

                        return(unchecked (( int )0x8002012f));
                    }
                }

                /*
                 *	#define PSP_O_RDONLY	0x0001
                 #define PSP_O_WRONLY	0x0002
                 #define PSP_O_RDWR		(PSP_O_RDONLY | PSP_O_WRONLY)
                 #define PSP_O_NBLOCK	0x0004
                 #define PSP_O_DIROPEN	0x0008	// Internal use for dopen
                 #define PSP_O_APPEND	0x0100
                 #define PSP_O_CREAT		0x0200
                 #define PSP_O_TRUNC		0x0400
                 #define	PSP_O_EXCL		0x0800
                 #define PSP_O_NOWAIT	0x8000*/
                MediaFileMode fileMode = MediaFileMode.Normal;
                if ((flags & 0x0100) == 0x0100)
                {
                    fileMode = MediaFileMode.Append;
                }
                if ((flags & 0x0400) == 0x0400)
                {
                    fileMode = MediaFileMode.Truncate;
                }
                MediaFileAccess fileAccess = MediaFileAccess.ReadWrite;
                if ((flags & 0x0001) == 0x0001)
                {
                    fileAccess = MediaFileAccess.Read;
                }
                if ((flags & 0x0002) == 0x0002)
                {
                    fileAccess = MediaFileAccess.Write;
                }
                if ((flags & 0x0003) == 0x0003)
                {
                    fileAccess = MediaFileAccess.ReadWrite;
                }

                if ((flags & 0x0800) != 0)
                {
                    // Exclusive O_EXCL
                    //int x = 1;
                }
                if ((flags & 0x8000) != 0)
                {
                    // Non-blocking O_NOWAIT
                    //int x = 1;
                }
                if ((flags & 0x0004) != 0)
                {
                    // ? O_NBLOCK
                    //int x = 1;
                }

                Stream stream = file.Open(fileMode, fileAccess);
                if (stream == null)
                {
                    Log.WriteLine(Verbosity.Normal, Feature.Bios, "sceIoOpen: could not open stream on file '{0}' for mode {1} access {2}", path, fileMode, fileAccess);
                    return(-1);
                }

                IMediaDevice device = file.Device;
                KDevice      dev    = _kernel.FindDevice(file.Device);
                Debug.Assert(dev != null);

                KFile handle = new KFile(_kernel, dev, file, stream);
                _kernel.AddHandle(handle);

                handle.Result = handle.UID;

                Log.WriteLine(Verbosity.Verbose, Feature.Bios, "sceIoOpen: opened file {0} with ID {1:X}", path, handle.UID);

                return(( int )handle.UID);
            }
        }
Пример #9
0
        public bool Create()
        {
            Debug.Assert(_isCreated == false);
            if (_isCreated == true)
            {
                return(true);
            }

            _shutDown = false;
            _state    = InstanceState.Idle;

            // Try to create all the components
            Debug.Assert(_params.BiosComponent != null);
            Debug.Assert(_params.CpuComponent != null);
            if (_params.AudioComponent != null)
            {
                _audio = _params.AudioComponent.CreateInstance(this, _params[_params.AudioComponent]) as IAudioDriver;
                _instances.Add(( IComponentInstance )_audio);
            }
            _cpu = _params.CpuComponent.CreateInstance(this, _params[_params.CpuComponent]) as ICpu;
            _instances.Add(( IComponentInstance )_cpu);
            _bios = _params.BiosComponent.CreateInstance(this, _params[_params.BiosComponent]) as IBios;
            _instances.Add(( IComponentInstance )_bios);
            foreach (IComponent component in _params.IOComponents)
            {
                IIODriver driver = component.CreateInstance(this, _params[component]) as IIODriver;
                _io.Add(driver);
                _instances.Add(( IComponentInstance )driver);
            }
            if (_params.InputComponent != null)
            {
                _input = _params.InputComponent.CreateInstance(this, _params[_params.InputComponent]) as IInputDevice;
                _instances.Add(_input);
                //_input.WindowHandle = _host.Player.Handle;
            }
            if (_params.UmdComponent != null)
            {
                _umd = _params.UmdComponent.CreateInstance(this, _params[_params.UmdComponent]) as IUmdDevice;
                _instances.Add(_umd);
            }
            if (_params.MemoryStickComponent != null)
            {
                _memoryStick = _params.MemoryStickComponent.CreateInstance(this, _params[_params.MemoryStickComponent]) as IMemoryStickDevice;
                _instances.Add(_memoryStick);
            }
            if (_params.VideoComponent != null)
            {
                _video = _params.VideoComponent.CreateInstance(this, _params[_params.VideoComponent]) as IVideoDriver;
                //_video.ControlHandle = _host.Player.ControlHandle;
                _instances.Add(( IComponentInstance )_video);
            }

            // Create thread
            _thread              = new Thread(new ThreadStart(this.RuntimeThread));
            _thread.Name         = "Host runtime thread";
            _thread.IsBackground = true;
            _thread.Start();

            _isCreated = true;

            return(true);
        }
Пример #10
0
        public IMediaItem FindPath(string path)
        {
            // Hack for ToE and maybe others
            path = path.Replace("host0:UMD", "umd0:");

            int colonPos = path.IndexOf(':');

            if (colonPos >= 0)
            {
                // Absolute path
                string  deviceName = path.Substring(0, colonPos);
                KDevice kdevice;
                if (this.DeviceLookup.TryGetValue(deviceName, out kdevice) == false)
                {
                    Log.WriteLine(Verbosity.Critical, Feature.Bios, "FindPath({0}): unable to find device {1}", path, deviceName);
                    return(null);
                }
                IMediaDevice device = kdevice.Device;
                if (device.State == MediaState.Present)
                {
                    path = path.Substring(colonPos + 1);
                    if (path.StartsWith("/sce_lbn") == true)
                    {
                        Debug.Assert(device is IUmdDevice);
                        IUmdDevice umd = ( IUmdDevice )device;

                        // Lookup LBN/etc
                        //0x0_size0xbb141
                        path = path.Substring(8);
                        int    sep   = path.LastIndexOf('_');
                        string slbn  = path.Substring(0, sep);
                        string ssize = path.Substring(sep + 5);
                        long   lbn;
                        long   size;
                        if (slbn.StartsWith("0x"))
                        {
                            lbn = long.Parse(slbn.Substring(2), NumberStyles.HexNumber);
                        }
                        else
                        {
                            lbn = long.Parse(slbn);
                        }
                        if (ssize.StartsWith("0x"))
                        {
                            size = long.Parse(ssize.Substring(2), NumberStyles.HexNumber);
                        }
                        else
                        {
                            size = long.Parse(ssize);
                        }
                        return(umd.Lookup(lbn, size));
                    }
                    else
                    {
                        return(device.Root.Find(path));
                    }
                }
                else
                {
                    Log.WriteLine(Verbosity.Normal, Feature.Bios, "FindPath: device {0} is ejected, cannot access {1}", device.Description, path);
                    return(null);
                }
            }
            else
            {
                // Relative path
                Debug.Assert(this.CurrentPath != null);
                return(this.CurrentPath.Find(path));
            }
        }