コード例 #1
0
            public void Enqueue(byte *MessageIn, int MessageSize)
            {
                try
                {
                    var MessagePartition = PoolPartition.Allocate(MessageSize);
                    Messages.Enqueue(MessagePartition);
                    PspMemory.WriteBytes(MessagePartition.Low, MessageIn, MessageSize);
#if DEBUG_MSG_PIPES
                    Console.Error.WriteLine("MsgPipe.Enqueue (Ok)");
#endif
                }
                catch
                {
#if DEBUG_MSG_PIPES
                    Console.Error.WriteLine("MsgPipe.Enqueue (Failed)");
#endif
                    throw new SceKernelException(SceKernelErrors.ERROR_KERNEL_MESSAGE_PIPE_FULL);
                }

                // 0 -> 1
                NoticeAvailableForRecv();
            }
コード例 #2
0
        public void _LoadFile(string fileName)
        {
            //GC.Collect();
            SetVirtualFolder(Path.GetDirectoryName(fileName));

            var memoryStream = new PspMemoryStream(PspMemory);

            var arguments = new[]
            {
                "ms0:/PSP/GAME/virtual/EBOOT.PBP",
            };

            Stream loadStream = File.OpenRead(fileName);
            //using ()
            {
                var elfLoadStreamTry = new List <Stream>();
                //Stream ElfLoadStream = null;

                var    format = new FormatDetector().DetectSubType(loadStream);
                string title  = null;
                switch (format)
                {
                case FormatDetector.SubType.Pbp:
                {
                    var pbp = new Pbp().Load(loadStream);
                    elfLoadStreamTry.Add(pbp[Pbp.Types.PspData]);
                    Logger.TryCatch(() =>
                        {
                            var paramSfo = new Psf().Load(pbp[Pbp.Types.ParamSfo]);

                            if (paramSfo.EntryDictionary.ContainsKey("TITLE"))
                            {
                                title = (string)paramSfo.EntryDictionary["TITLE"];
                            }

                            if (paramSfo.EntryDictionary.ContainsKey("PSP_SYSTEM_VER"))
                            {
                                HleConfig.FirmwareVersion = paramSfo.EntryDictionary["PSP_SYSTEM_VER"].ToString();
                            }
                        });
                }
                break;

                case FormatDetector.SubType.Elf:
                    elfLoadStreamTry.Add(loadStream);
                    break;

                case FormatDetector.SubType.Dax:
                case FormatDetector.SubType.Cso:
                case FormatDetector.SubType.Iso:
                {
                    arguments[0] = "disc0:/PSP/GAME/SYSDIR/EBOOT.BIN";

                    var iso = SetIso(fileName);
                    Logger.TryCatch(() =>
                        {
                            var paramSfo = new Psf().Load(iso.Root.Locate("/PSP_GAME/PARAM.SFO").Open());
                            title        = (string)paramSfo.EntryDictionary["TITLE"];
                        });

                    var filesToTry = new[]
                    {
                        "/PSP_GAME/SYSDIR/BOOT.BIN",
                        "/PSP_GAME/SYSDIR/EBOOT.BIN",
                        "/PSP_GAME/SYSDIR/EBOOT.OLD",
                    };

                    foreach (var fileToTry in filesToTry)
                    {
                        try
                        {
                            elfLoadStreamTry.Add(iso.Root.Locate(fileToTry).Open());
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                        }
                        //if (ElfLoadStream.Length != 0) break;
                    }

                    /*
                     * if (ElfLoadStream.Length == 0)
                     * {
                     *  throw (new Exception(String.Format("{0} files are empty", String.Join(", ", FilesToTry))));
                     * }
                     */
                }
                break;

                default:
                    throw (new NotImplementedException("Can't load format '" + format + "'"));
                }

                Exception      loadException  = null;
                HleModuleGuest hleModuleGuest = null;

                foreach (var elfLoadStream in elfLoadStreamTry)
                {
                    try
                    {
                        loadException = null;

                        if (elfLoadStream.Length < 256)
                        {
                            throw(new InvalidProgramException("File too short"));
                        }

                        hleModuleGuest = Loader.LoadModule(
                            elfLoadStream,
                            memoryStream,
                            MemoryManager.GetPartition(MemoryPartitions.User),
                            ModuleManager,
                            title,
                            moduleName: fileName,
                            isMainModule: true
                            );

                        loadException = null;

                        break;
                    }
                    catch (InvalidProgramException e)
                    {
                        loadException = e;
                    }
                }

                if (loadException != null)
                {
                    throw loadException;
                }

                RegisterSyscalls();

                const uint startArgumentAddress = 0x08000100;
                var        endArgumentAddress   = startArgumentAddress;

                var argumentsChunk = arguments
                                     .Select(argument => Encoding.UTF8.GetBytes(argument + "\0"))
                                     .Aggregate(new byte[] { }, (accumulate, chunk) => accumulate.Concat(chunk))
                ;

                var reservedSyscallsPartition = MemoryManager.GetPartition(MemoryPartitions.Kernel0).Allocate(
                    0x100,
                    Name: "ReservedSyscallsPartition"
                    );
                var argumentsPartition = MemoryManager.GetPartition(MemoryPartitions.Kernel0).Allocate(
                    argumentsChunk.Length,
                    Name: "ArgumentsPartition"
                    );
                PspMemory.WriteBytes(argumentsPartition.Low, argumentsChunk);

                Debug.Assert(ThreadManForUser != null);

                // @TODO: Use Module Manager

                //var MainThread = ThreadManager.Create();
                //var CpuThreadState = MainThread.CpuThreadState;
                var currentCpuThreadState = new CpuThreadState(CpuProcessor);
                {
                    if (hleModuleGuest == null)
                    {
                        //throw new InvalidOperationException("hleModuleGuest == null");
                    }
                    //CpuThreadState.PC = Loader.InitInfo.PC;
                    currentCpuThreadState.Gp           = hleModuleGuest.InitInfo.Gp;
                    currentCpuThreadState.CallerModule = hleModuleGuest;

                    var threadId = (int)ThreadManForUser.sceKernelCreateThread(currentCpuThreadState, "<EntryPoint>",
                                                                               hleModuleGuest.InitInfo.Pc, 10, 0x1000, PspThreadAttributes.ClearStack, null);

                    //var Thread = HleThreadManager.GetThreadById(ThreadId);
                    ThreadManForUser._sceKernelStartThread(currentCpuThreadState, threadId, argumentsPartition.Size,
                                                           argumentsPartition.Low);
                    //Console.WriteLine("RA: 0x{0:X}", CurrentCpuThreadState.RA);
                }
                currentCpuThreadState.DumpRegisters();
                MemoryManager.GetPartition(MemoryPartitions.User).Dump();
                //ModuleManager.LoadedGuestModules.Add(HleModuleGuest);

                //MainThread.CurrentStatus = HleThread.Status.Ready;
            }
        }
コード例 #3
0
        public void AvcDecode(SceMpegAu *MpegAccessUnit, int FrameWidth, GuPixelFormats GuPixelFormat,
                              PspPointer OutputBuffer)
        {
            if (MpegAccessUnit != null)
            {
                *MpegAccessUnit = GetAvcAu(StreamId.Avc);
            }

            while (MpegPsDemuxer.HasMorePackets)
            {
                if (!DecodePsPacket())
                {
                    return;
                }
            }

            if (VideoStream.Length <= 0)
            {
                return;
            }

            // Buffer 1MB
            //if (VideoStream.Length <= 1 * 1024 * 1024) return;

            try
            {
                //if (H264FrameDecoder.HasMorePackets)
                {
                    //Console.WriteLine("VideoStream.Length: {0}", VideoStream.Length);
                    var Frame = H264FrameDecoder.DecodeFrame();

                    ConsoleUtils.SaveRestoreConsoleColor(ConsoleColor.DarkGreen,
                                                         () => { Console.WriteLine("DecodedFrame: {0}", FrameIndex); });

                    var Bitmap = FrameUtils.imageFromFrameWithoutEdges(Frame, FrameWidth, 272);

                    var TempBuffer =
                        new byte[PixelFormatDecoder.GetPixelsSize(GuPixelFormat, Bitmap.Width * Bitmap.Height)];
                    fixed(byte *TempBufferPtr = TempBuffer)
                    {
                        var TempBufferPtr2 = TempBufferPtr;

                        Bitmap.LockBitsUnlock(PixelFormat.Format32bppArgb, (BitmapData) =>
                        {
                            var InputBuffer = (OutputPixel *)BitmapData.Scan0.ToPointer();
                            int Count       = Bitmap.Width * Bitmap.Height;

                            for (int n = 0; n < Count; n++)
                            {
                                var Color        = InputBuffer[n];
                                InputBuffer[n].R = Color.B;
                                InputBuffer[n].G = Color.G;
                                InputBuffer[n].B = Color.R;
                                InputBuffer[n].A = 0xFF;
                            }

                            PixelFormatDecoder.Encode(GuPixelFormat, InputBuffer, TempBufferPtr2,
                                                      Bitmap.Width * Bitmap.Height);
                            PixelFormatDecoder.Encode(PspDisplay.CurrentInfo.PixelFormat, InputBuffer,
                                                      (byte *)Memory.PspAddressToPointerSafe(PspDisplay.CurrentInfo.FrameAddress), 512,
                                                      Bitmap.Width, Bitmap.Height);
                            PspDisplay.CurrentInfo.PlayingVideo = true;
                        });
                        PspDisplay.CurrentInfo.PlayingVideo = true;
                        Memory.WriteBytes(OutputBuffer.Address, TempBufferPtr, TempBuffer.Length);
                        GpuImpl.InvalidateCache(OutputBuffer.Address, TempBuffer.Length);
                    }

                    if (SaveBitmapFrame)
                    {
                        Bitmap.Save(@"c:\temp\frame" + (FrameIndex) + ".png");
                    }
                    FrameIndex++;
                }
                //PixelFormat

                return;
            }
            catch (EndOfStreamException)
            {
                ConsoleUtils.SaveRestoreConsoleColor(ConsoleColor.Red,
                                                     () => { Console.WriteLine("H264FrameDecoder.DecodeFrame: EndOfStreamException"); });
            }
        }