Example #1
0
        public virtual int sceUmdRegisterUMDCallBack(int uid)
        {
            ThreadManForUser threadMan = Modules.ThreadManForUserModule;

            if (!threadMan.hleKernelRegisterCallback(SceKernelThreadInfo.THREAD_CALLBACK_UMD, uid))
            {
                return(-1);
            }

            return(0);
        }
Example #2
0
        public virtual int scePowerRegisterCallback(int slot, int uid)
        {
            bool notifyCallback = false;
            int  result;

            // Multiple power callbacks (up to 16) can be assigned for multiple threads.
            if (slot == PSP_POWER_CB_SLOT_AUTO)
            {
                // Return ERROR_OUT_OF_MEMORY when no free slot found
                result = SceKernelErrors.ERROR_OUT_OF_MEMORY;

                for (int i = 0; i < powerCBSlots.Length; i++)
                {
                    if (powerCBSlots[i] == 0)
                    {
                        powerCBSlots[i] = uid;
                        result          = i;
                        notifyCallback  = true;
                        break;
                    }
                }
            }
            else if (slot >= 0 && slot < powerCBSlots.Length)
            {
                if (powerCBSlots[slot] == 0)
                {
                    powerCBSlots[slot] = uid;
                    result             = 0;
                    notifyCallback     = true;
                }
                else
                {
                    result = SceKernelErrors.ERROR_ALREADY;
                }
            }
            else
            {
                result = -1;
            }

            if (notifyCallback)
            {
                ThreadManForUser threadMan = Modules.ThreadManForUserModule;
                if (threadMan.hleKernelRegisterCallback(SceKernelThreadInfo.THREAD_CALLBACK_POWER, uid))
                {
                    // Start by notifying the POWER callback that we're using AC power.
                    threadMan.hleKernelNotifyCallback(SceKernelThreadInfo.THREAD_CALLBACK_POWER, uid, PSP_POWER_CB_AC_POWER);
                }
            }

            return(result);
        }
Example #3
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);
        }