コード例 #1
0
        public virtual int scePowerUnregisterCallback(int slot)
        {
            if (slot < 0 || slot >= powerCBSlots.Length)
            {
                return(-1);
            }

            if (powerCBSlots[slot] != 0)
            {
                ThreadManForUser threadMan = Modules.ThreadManForUserModule;
                threadMan.hleKernelUnRegisterCallback(SceKernelThreadInfo.THREAD_CALLBACK_POWER, powerCBSlots[slot]);
                powerCBSlots[slot] = 0;
            }

            return(0);
        }
コード例 #2
0
        public override int ioDevctl(string deviceName, int command, TPointer inputPointer, int inputLength, TPointer outputPointer, int outputLength)
        {
            int result;

            switch (command)
            {
            // Register memorystick insert/eject callback (fatms0).
            case 0x02415821:
            {
                Console.WriteLine("sceIoDevctl register memorystick insert/eject callback (fatms0)");
                ThreadManForUser threadMan = Modules.ThreadManForUserModule;
                if (!deviceName.Equals("fatms0:"))
                {
                    result = ERROR_MEMSTICK_DEVCTL_BAD_PARAMS;
                }
                else if (inputPointer.AddressGood && inputLength == 4)
                {
                    int       cbid         = inputPointer.getValue32();
                    const int callbackType = SceKernelThreadInfo.THREAD_CALLBACK_MEMORYSTICK_FAT;
                    if (threadMan.hleKernelRegisterCallback(callbackType, cbid))
                    {
                        // Trigger the registered callback immediately.
                        // Only trigger this one callback, not all the MS callbacks.
                        threadMan.hleKernelNotifyCallback(callbackType, cbid, MemoryStick.StateFatMs);
                        result = 0;                                 // Success.
                    }
                    else
                    {
                        result = SceKernelErrors.ERROR_ERRNO_INVALID_ARGUMENT;
                    }
                }
                else
                {
                    result = SceKernelErrors.ERROR_ERRNO_INVALID_ARGUMENT;
                }
                break;
            }

            // Unregister memorystick insert/eject callback (fatms0).
            case 0x02415822:
            {
                Console.WriteLine("sceIoDevctl unregister memorystick insert/eject callback (fatms0)");
                ThreadManForUser threadMan = Modules.ThreadManForUserModule;
                if (!deviceName.Equals("fatms0:"))
                {
                    result = ERROR_MEMSTICK_DEVCTL_BAD_PARAMS;
                }
                else if (inputPointer.AddressGood && inputLength == 4)
                {
                    int cbid = inputPointer.getValue32();
                    threadMan.hleKernelUnRegisterCallback(SceKernelThreadInfo.THREAD_CALLBACK_MEMORYSTICK_FAT, cbid);
                    result = 0;                             // Success.
                }
                else
                {
                    result = SceKernelErrors.ERROR_ERRNO_INVALID_ARGUMENT;
                }
                break;
            }

            // Set if the device is assigned/inserted or not (fatms0).
            case 0x02415823:
            {
                Console.WriteLine("sceIoDevctl set assigned device (fatms0)");
                if (!deviceName.Equals("fatms0:"))
                {
                    result = ERROR_MEMSTICK_DEVCTL_BAD_PARAMS;
                }
                else if (inputPointer.AddressGood && inputLength >= 4)
                {
                    // 0 - Device is not assigned (callback not registered).
                    // 1 - Device is assigned (callback registered).
                    MemoryStick.StateFatMs = inputPointer.getValue32();
                    result = 0;
                }
                else
                {
                    result = IO_ERROR;
                }
                break;
            }

            // Check if the device is write protected (fatms0).
            case 0x02425824:
            {
                Console.WriteLine("sceIoDevctl check write protection (fatms0)");
                if (!deviceName.Equals("fatms0:") && !deviceName.Equals("ms0:"))
                {                         // For this command the alias "ms0:" is also supported.
                    result = ERROR_MEMSTICK_DEVCTL_BAD_PARAMS;
                }
                else if (outputPointer.AddressGood)
                {
                    // 0 - Device is not protected.
                    // 1 - Device is protected.
                    outputPointer.setValue32(0);
                    result = 0;
                }
                else
                {
                    result = IO_ERROR;
                }
                break;
            }

            // Get MS capacity (fatms0).
            case 0x02425818:
            {
                Console.WriteLine("sceIoDevctl get MS capacity (fatms0)");
                int sectorSize   = 0x200;
                int sectorCount  = MemoryStick.SectorSize / sectorSize;
                int maxClusters  = (int)((MemoryStick.FreeSize * 95L / 100) / (sectorSize * sectorCount));
                int freeClusters = maxClusters;
                int maxSectors   = maxClusters;
                if (inputPointer.AddressGood && inputLength >= 4)
                {
                    int addr = inputPointer.getValue32();
                    if (Memory.isAddressGood(addr))
                    {
                        Console.WriteLine("sceIoDevctl refer ms free space");
                        Memory mem = Memory.Instance;
                        mem.write32(addr, maxClusters);
                        mem.write32(addr + 4, freeClusters);
                        mem.write32(addr + 8, maxSectors);
                        mem.write32(addr + 12, sectorSize);
                        mem.write32(addr + 16, sectorCount);
                        result = 0;
                    }
                    else
                    {
                        Console.WriteLine("sceIoDevctl 0x02425818 bad save address " + string.Format("0x{0:X8}", addr));
                        result = IO_ERROR;
                    }
                }
                else
                {
                    Console.WriteLine("sceIoDevctl 0x02425818 bad param address " + string.Format("0x{0:X8}", inputPointer) + " or size " + inputLength);
                    result = IO_ERROR;
                }
                break;
            }

            // Check if the device is assigned/inserted (fatms0).
            case 0x02425823:
            {
                Console.WriteLine("sceIoDevctl check assigned device (fatms0)");
                if (!deviceName.Equals("fatms0:"))
                {
                    result = ERROR_MEMSTICK_DEVCTL_BAD_PARAMS;
                }
                else if (outputPointer.AddressGood && outputLength >= 4)
                {
                    // 0 - Device is not assigned (callback not registered).
                    // 1 - Device is assigned (callback registered).
                    outputPointer.setValue32(MemoryStick.StateFatMs);
                    result = 0;
                }
                else
                {
                    result = IO_ERROR;
                }
                break;
            }

            case 0x00005802:
            {
                if (!"flash1:".Equals(deviceName) || inputLength != 0 || outputLength != 0)
                {
                    result = IO_ERROR;
                }
                else
                {
                    result = 0;
                }
                break;
            }

            default:
            {
                result = base.ioDevctl(deviceName, command, inputPointer, inputLength, outputPointer, outputLength);
            }
            break;
            }

            return(result);
        }