Exemple #1
0
        protected internal virtual int hleCtrlReadBuffer(int addr, int count, bool positive)
        {
            if (count < 0 || count > SAMPLE_BUFFER_SIZE)
            {
                return(SceKernelErrors.ERROR_INVALID_SIZE);
            }

            // Some data available in sample buffer?
            if (NumberOfAvailableSamples > 0)
            {
                // Yes, read immediately
                return(hleCtrlReadBufferImmediately(addr, count, positive, false));
            }

            // No, wait for next sampling
            ThreadManForUser         threadMan                = Modules.ThreadManForUserModule;
            SceKernelThreadInfo      currentThread            = threadMan.CurrentThread;
            ThreadWaitingForSampling threadWaitingForSampling = new ThreadWaitingForSampling(currentThread, addr, count, positive);

            threadsWaitingForSampling.Add(threadWaitingForSampling);
            threadMan.hleBlockCurrentThread(SceKernelThreadInfo.JPCSP_WAIT_CTRL);

            //if (log.DebugEnabled)
            {
                Console.WriteLine("hleCtrlReadBuffer waiting for sample");
            }

            return(0);
        }
Exemple #2
0
        public virtual void hleCtrlExecuteSampling()
        {
            //if (log.DebugEnabled)
            {
                Console.WriteLine("hleCtrlExecuteSampling");
            }

            Controller controller = State.controller;

            controller.hleControllerPoll();

            setButtons(controller.Lx, controller.Ly, controller.Rx, controller.Ry, controller.Buttons, controller.hasRightAnalogController());

            latchSamplingCount++;

            Sample currentSampling = samples[currentSamplingIndex];

            currentSampling.setValues(TimeStamp, Lx, Ly, Rx, Ry, Buttons);

            currentSamplingIndex = incrementSampleIndex(currentSamplingIndex);
            if (currentSamplingIndex == currentReadingIndex)
            {
                currentReadingIndex = incrementSampleIndex(currentReadingIndex);
            }

            while (threadsWaitingForSampling.Count > 0)
            {
                ThreadWaitingForSampling wait = threadsWaitingForSampling.RemoveAt(0);
                if (wait.thread.isWaitingForType(SceKernelThreadInfo.JPCSP_WAIT_CTRL))
                {
                    //if (log.DebugEnabled)
                    {
                        Console.WriteLine("hleExecuteSampling waiting up thread " + wait.thread);
                    }
                    wait.thread.cpuContext._v0 = hleCtrlReadBufferImmediately(wait.readAddr, wait.readCount, wait.readPositive, false);
                    Modules.ThreadManForUserModule.hleUnblockThread(wait.thread.uid);
                    break;
                }

                //if (log.DebugEnabled)
                {
                    Console.WriteLine("hleExecuteSampling thread " + wait.thread + " was no longer blocked");
                }
            }
        }