Пример #1
0
 public static ByteBuffer getScaledScreen(int address, int bufferWidth, int height, int pixelFormat)
 {
     lock (screenScaleLock)
     {
         return(NativeUtils.getScaledScreen(address, bufferWidth, height, pixelFormat));
     }
 }
Пример #2
0
        public override void run()
        {
            while (!exit_Renamed)
            {
                if (waitForSync(100))
                {
                    if (lineMask != 0)
                    {
                        //if (log.DebugEnabled)
                        {
                            Console.WriteLine(string.Format("Starting async rendering lineMask=0x{0:X8}", lineMask));
                        }
                        NativeUtils.rendererRender(lineMask);
                    }

                    if (response != null)
                    {
                        // Be careful to clear the response before releasing it!
                        Semaphore responseToBeReleased = response;
                        response = null;
                        responseToBeReleased.release();
                    }
                }
            }
        }
Пример #3
0
 public static void onGeStartList(PspGeList list)
 {
     if (Available && DurationStatistics.collectStatistics)
     {
         NativeUtils.notifyEvent(NativeUtils.EVENT_GE_START_LIST);
     }
 }
Пример #4
0
 public static void onGeFinishList(PspGeList list)
 {
     if (Available && DurationStatistics.collectStatistics)
     {
         NativeUtils.notifyEvent(NativeUtils.EVENT_GE_FINISH_LIST);
     }
 }
Пример #5
0
 public static void onDisplayStopWaitVblank()
 {
     if (Available && DurationStatistics.collectStatistics)
     {
         NativeUtils.stopEvent(NativeUtils.EVENT_DISPLAY_WAIT_VBLANK);
     }
 }
Пример #6
0
 public static void onDisplayVblank()
 {
     if (Available && DurationStatistics.collectStatistics)
     {
         NativeUtils.notifyEvent(NativeUtils.EVENT_DISPLAY_VBLANK);
     }
 }
Пример #7
0
 public static void onGeStopWaitList()
 {
     if (Available && DurationStatistics.collectStatistics)
     {
         NativeUtils.stopEvent(NativeUtils.EVENT_GE_WAIT_FOR_LIST);
     }
 }
Пример #8
0
 public override void run()
 {
     while (!exit_Renamed)
     {
         NativeUtils.setLogLevel();
         Utilities.sleep(100);
     }
 }
Пример #9
0
        public static float[] getMatrix(int mtxType)
        {
            int size   = getMatrixSize(mtxType);
            int offset = getMatrixOffset(mtxType);

            float[] mtx = new float[size];
            for (int i = 0; i < size; i++)
            {
                mtx[i] = NativeUtils.getCoreMtxArray(offset + i);
            }

            return(mtx);
        }
Пример #10
0
        private void executeCommandFINISH(PspGeList list)
        {
            //if (log.DebugEnabled)
            {
                Console.WriteLine(string.Format("FINISH {0}", list));
            }

            list.clearRestart();
            list.finishList();
            list.pushFinishCallback(list.id, NativeUtils.getCoreCmdArray(GeCommands.FINISH) & 0x00FFFFFF);
            list.endList();
            list.status = sceGe_user.PSP_GE_LIST_DONE;
            ExternalGE.finishList(list);
        }
Пример #11
0
        public static void startList(PspGeList list)
        {
            if (list == null)
            {
                return;
            }

            lock (drawListQueue)
            {
                if (currentList == null)
                {
                    if (State.captureGeNextFrame)
                    {
                        State.captureGeNextFrame         = false;
                        CaptureManager.captureInProgress = true;
                        NativeUtils.DumpFrames           = true;
                        NativeUtils.DumpTextures         = true;
                        logLevel  = log.Level;
                        log.Level = Level.TRACE;
                    }

                    // Save the context at the beginning of the list processing to the given address (used by sceGu).
                    if (list.hasSaveContextAddr())
                    {
                        saveContext(list.SaveContextAddr);
                    }

                    list.status = sceGe_user.PSP_GE_LIST_DRAWING;
                    NativeUtils.setLogLevel();
                    NativeUtils.CoreSadr = list.StallAddr;
                    NativeUtils.setCoreCtrlActive();
                    lock (screenScaleLock)
                    {
                        // Update the screen scale only at the start of a new list
                        NativeUtils.ScreenScale = ScreenScale;
                    }
                    currentList = list;
                    currentList.sync();
                    CoreThread.Instance.sync();
                }
                else
                {
                    drawListQueue.add(list);
                }
            }
        }
Пример #12
0
        public static int saveContext(int addr)
        {
            if (NativeUtils.CoreCtrlActive)
            {
                //if (log.DebugEnabled)
                {
                    Console.WriteLine(string.Format("Saving Core context to 0x{0:X8} - Core busy", addr));
                }
                return(-1);
            }

            //if (log.DebugEnabled)
            {
                Console.WriteLine(string.Format("Saving Core context to 0x{0:X8}", addr));
            }

            NativeUtils.saveCoreContext(addr);

            return(0);
        }
Пример #13
0
        public static int restoreContext(int addr)
        {
            if (NativeUtils.CoreCtrlActive)
            {
                //if (log.DebugEnabled)
                {
                    Console.WriteLine(string.Format("Restoring Core context from 0x{0:X8} - Core busy", addr));
                }
                return(SceKernelErrors.ERROR_BUSY);
            }

            //if (log.DebugEnabled)
            {
                Console.WriteLine(string.Format("Restoring Core context from 0x{0:X8}", addr));
            }

            NativeUtils.restoreCoreContext(addr);

            return(0);
        }
Пример #14
0
        public static void onRestartList(PspGeList list)
        {
            if (Active)
            {
                if (list == null || list.Finished)
                {
                    return;
                }

                lock (drawListQueue)
                {
                    if (list == currentList)
                    {
                        list.status = sceGe_user.PSP_GE_LIST_DRAWING;
                        NativeUtils.setCoreCtrlActive();
                        CoreThread.Instance.sync();
                        list.sync();
                    }
                }
            }
        }
Пример #15
0
        public static void onStallAddrUpdated(PspGeList list)
        {
            if (Available && DurationStatistics.collectStatistics)
            {
                NativeUtils.stopEvent(NativeUtils.EVENT_GE_UPDATE_STALL_ADDR);
            }

            if (Active)
            {
                if (list == null)
                {
                    return;
                }

                if (list == currentList)
                {
                    NativeUtils.CoreSadr = list.StallAddr;
                    CoreThread.Instance.sync();
                }
            }
        }
Пример #16
0
        public static void init()
        {
            if (externalGESettingsListerner == null)
            {
                externalGESettingsListerner = new ExternalGESettingsListerner();
                Settings.Instance.registerSettingsListener("ExternalGE", "emu.useExternalSoftwareRenderer", externalGESettingsListerner);
            }

            if (activateWhenAvailable)
            {
                NativeUtils.init();
                if (Available)
                {
                    activate();
                }
            }
            else
            {
                deactivate();
            }
        }
Пример #17
0
        public static void exit()
        {
            if (externalGESettingsListerner != null)
            {
                Settings.Instance.removeSettingsListener("ExternalGE");
                externalGESettingsListerner = null;
            }

            if (Active)
            {
                NativeUtils.exit();
                NativeCallbacks.exit();
                CoreThread.exit();
                setLogLevelThread.exit();
                if (numberRendererThread > 0)
                {
                    for (int i = 0; i < rendererThreads.Length; i++)
                    {
                        rendererThreads[i].exit();
                    }
                }
            }
        }
Пример #18
0
        public static void finishList(PspGeList list)
        {
            Modules.sceGe_userModule.hleGeListSyncDone(list);

            lock (drawListQueue)
            {
                if (list == currentList)
                {
                    if (CaptureManager.captureInProgress)
                    {
                        log.Level = logLevel;
                        NativeUtils.DumpFrames   = false;
                        NativeUtils.DumpTextures = false;
                        NativeUtils.setLogLevel();
                        CaptureManager.captureInProgress = false;
                        Emulator.PauseEmu();
                    }

                    // Restore the context to the state at the beginning of the list processing (used by sceGu).
                    if (list.hasSaveContextAddr())
                    {
                        restoreContext(list.SaveContextAddr);
                    }

                    currentList = null;
                }
                else
                {
                    drawListQueue.remove(list);
                }
            }

            if (currentList == null)
            {
                startList(drawListQueue.poll());
            }
        }
Пример #19
0
        public static void render()
        {
            //if (log.DebugEnabled)
            {
                Console.WriteLine(string.Format("ExternalGE starting rendering"));
            }

            for (int i = 0; i < rendererThreads.Length; i++)
            {
                rendererThreads[i].sync(rendererThreadsDone);
            }

            try
            {
                //if (log.DebugEnabled)
                {
                    Console.WriteLine(string.Format("Waiting for async rendering completion"));
                }
                rendererThreadsDone.acquire(rendererThreads.Length);
            }
            catch (InterruptedException e)
            {
                Console.WriteLine("render", e);
            }

            //if (log.DebugEnabled)
            {
                Console.WriteLine(string.Format("Async rendering completion"));
            }

            NativeUtils.rendererTerminate();

            //if (log.DebugEnabled)
            {
                Console.WriteLine(string.Format("ExternalGE terminating rendering"));
            }
        }
Пример #20
0
        public override void run()
        {
            setLog4jMDC();
            bool doCoreInterpret = false;

            while (!exit_Renamed)
            {
                PspGeList list = ExternalGE.CurrentList;

                if (list == null)
                {
                    if (!Emulator.pause && log.DebugEnabled)
                    {
                        Console.WriteLine(string.Format("CoreThread no current list available... waiting"));
                    }

                    waitForSync(100);
                }
                else if (doCoreInterpret || list.waitForSync(100))
                {
                    InsideRendering = true;

                    doCoreInterpret      = false;
                    NativeUtils.CoreMadr = list.Pc;
                    NativeUtils.updateMemoryUnsafeAddr();

                    //if (log.DebugEnabled)
                    {
                        Console.WriteLine(string.Format("CoreThread processing {0}", list));
                    }

                    while (NativeUtils.coreInterpret())
                    {
                        NativeUtils.updateMemoryUnsafeAddr();

                        //if (log.DebugEnabled)
                        {
                            list.Pc = NativeUtils.CoreMadr;
                            Console.WriteLine(string.Format("CoreThread looping {0}", list));
                        }

                        if (ExternalGE.numberRendererThread > 0 && NativeUtils.RendererIndexCount > 0)
                        {
                            break;
                        }
                    }

                    list.Pc = NativeUtils.CoreMadr;

                    int intrStat = NativeUtils.CoreIntrStat;
                    if ((intrStat & INTR_STAT_END) != 0)
                    {
                        if ((intrStat & INTR_STAT_SIGNAL) != 0)
                        {
                            executeCommandSIGNAL(list);
                        }
                        if ((intrStat & INTR_STAT_FINISH) != 0)
                        {
                            executeCommandFINISH(list);
                        }
                        intrStat &= ~(INTR_STAT_END | INTR_STAT_SIGNAL | INTR_STAT_FINISH);
                        NativeUtils.CoreIntrStat = intrStat;
                    }

                    if (ExternalGE.numberRendererThread > 0 && NativeUtils.RendererIndexCount > 0)
                    {
                        ExternalGE.render();
                        doCoreInterpret = true;
                    }

                    InsideRendering = false;
                }
            }

            Console.WriteLine(string.Format("CoreThread exited"));
        }
Пример #21
0
        private void executeCommandSIGNAL(PspGeList list)
        {
            int args     = NativeUtils.getCoreCmdArray(GeCommands.SIGNAL) & 0x00FFFFFF;
            int behavior = (args >> 16) & 0xFF;
            int signal   = args & 0xFFFF;

            //if (log.DebugEnabled)
            {
                Console.WriteLine(string.Format("SIGNAL (behavior={0:D}, signal=0x{1:X})",behavior,signal));
            }

            switch (behavior)
            {
            case sceGe_user.PSP_GE_SIGNAL_SYNC:
            {
                // Skip FINISH / END
                Memory mem = Memory.Instance;
                if (command(mem.read32(list.Pc)) == FINISH)
                {
                    list.readNextInstruction();
                    if (command(mem.read32(list.Pc)) == END)
                    {
                        list.readNextInstruction();
                    }
                }
                //if (log.DebugEnabled)
                {
                    Console.WriteLine(string.Format("PSP_GE_SIGNAL_SYNC ignored PC: 0x{0:X8}", list.Pc));
                }
                break;
            }

            case sceGe_user.PSP_GE_SIGNAL_CALL:
            {
                // Call list using absolute address from SIGNAL + END.
                int hi16  = signal & 0x0FFF;
                int lo16  = NativeUtils.getCoreCmdArray(GeCommands.END) & 0xFFFF;
                int addr  = (hi16 << 16) | lo16;
                int oldPc = list.Pc;
                list.callAbsolute(addr);
                int newPc = list.Pc;
                //if (log.DebugEnabled)
                {
                    Console.WriteLine(string.Format("PSP_GE_SIGNAL_CALL old PC: 0x{0:X8}, new PC: 0x{1:X8}", oldPc, newPc));
                }
                break;
            }

            case sceGe_user.PSP_GE_SIGNAL_RETURN:
            {
                // Return from PSP_GE_SIGNAL_CALL.
                int oldPc = list.Pc;
                list.ret();
                int newPc = list.Pc;
                //if (log.DebugEnabled)
                {
                    Console.WriteLine(string.Format("PSP_GE_SIGNAL_RETURN old PC: 0x{0:X8}, new PC: 0x{1:X8}", oldPc, newPc));
                }
                break;
            }

            case sceGe_user.PSP_GE_SIGNAL_TBP0_REL:
            case sceGe_user.PSP_GE_SIGNAL_TBP1_REL:
            case sceGe_user.PSP_GE_SIGNAL_TBP2_REL:
            case sceGe_user.PSP_GE_SIGNAL_TBP3_REL:
            case sceGe_user.PSP_GE_SIGNAL_TBP4_REL:
            case sceGe_user.PSP_GE_SIGNAL_TBP5_REL:
            case sceGe_user.PSP_GE_SIGNAL_TBP6_REL:
            case sceGe_user.PSP_GE_SIGNAL_TBP7_REL:
            {
                // Overwrite TBPn and TBPw with SIGNAL + END (uses relative address only).
                int hi16     = signal & 0xFFFF;
                int end      = NativeUtils.getCoreCmdArray(GeCommands.END);
                int lo16     = end & 0xFFFF;
                int width    = (end >> 16) & 0xFF;
                int addr     = list.getAddressRel((hi16 << 16) | lo16);
                int tbpValue = (behavior - sceGe_user.PSP_GE_SIGNAL_TBP0_REL + GeCommands.TBP0) << 24 | (addr & 0x00FFFFFF);
                int tbwValue = (behavior - sceGe_user.PSP_GE_SIGNAL_TBP0_REL + GeCommands.TBW0) << 24 | ((addr >> 8) & 0x00FF0000) | (width & 0xFFFF);
                NativeUtils.interpretCoreCmd(command(tbpValue), tbpValue, NativeUtils.CoreMadr);
                NativeUtils.interpretCoreCmd(command(tbwValue), tbwValue, NativeUtils.CoreMadr);
                break;
            }

            case sceGe_user.PSP_GE_SIGNAL_TBP0_REL_OFFSET:
            case sceGe_user.PSP_GE_SIGNAL_TBP1_REL_OFFSET:
            case sceGe_user.PSP_GE_SIGNAL_TBP2_REL_OFFSET:
            case sceGe_user.PSP_GE_SIGNAL_TBP3_REL_OFFSET:
            case sceGe_user.PSP_GE_SIGNAL_TBP4_REL_OFFSET:
            case sceGe_user.PSP_GE_SIGNAL_TBP5_REL_OFFSET:
            case sceGe_user.PSP_GE_SIGNAL_TBP6_REL_OFFSET:
            case sceGe_user.PSP_GE_SIGNAL_TBP7_REL_OFFSET:
            {
                // Overwrite TBPn and TBPw with SIGNAL + END (uses relative address with offset).
                int hi16 = signal & 0xFFFF;
                // Read & skip END
                int end      = NativeUtils.getCoreCmdArray(GeCommands.END);
                int lo16     = end & 0xFFFF;
                int width    = (end >> 16) & 0xFF;
                int addr     = list.getAddressRelOffset((hi16 << 16) | lo16);
                int tbpValue = (behavior - sceGe_user.PSP_GE_SIGNAL_TBP0_REL + GeCommands.TBP0) << 24 | (addr & 0x00FFFFFF);
                int tbwValue = (behavior - sceGe_user.PSP_GE_SIGNAL_TBP0_REL + GeCommands.TBW0) << 24 | ((addr >> 8) & 0x00FF0000) | (width & 0xFFFF);
                NativeUtils.interpretCoreCmd(command(tbpValue), tbpValue, NativeUtils.CoreMadr);
                NativeUtils.interpretCoreCmd(command(tbwValue), tbwValue, NativeUtils.CoreMadr);
                break;
            }

            case sceGe_user.PSP_GE_SIGNAL_HANDLER_SUSPEND:
            case sceGe_user.PSP_GE_SIGNAL_HANDLER_CONTINUE:
            case sceGe_user.PSP_GE_SIGNAL_HANDLER_PAUSE:
            {
                list.clearRestart();
                list.pushSignalCallback(list.id, behavior, signal);
                list.endList();
                list.status = sceGe_user.PSP_GE_LIST_END_REACHED;
                break;
            }

            default:
            {
                if (log.InfoEnabled)
                {
                    Console.WriteLine(string.Format("SIGNAL (behavior={0:D}, signal=0x{1:X}) unknown behavior at 0x{2:X8}", behavior, signal, list.Pc - 4));
                }
            }
            break;
            }

            if (list.Drawing)
            {
                list.sync();
                NativeUtils.setCoreCtrlActive();
            }
        }
Пример #22
0
 public static void addVideoTexture(int destinationAddress, int sourceAddress, int Length)
 {
     NativeUtils.addVideoTexture(destinationAddress, sourceAddress, Length);
 }
Пример #23
0
 public static void setMatrix(int mtxType, int offset, float value)
 {
     NativeUtils.setCoreMtxArray(getMatrixOffset(mtxType) + offset, value);
 }
Пример #24
0
 public static int getCmd(int cmd)
 {
     return(NativeUtils.getCoreCmdArray(cmd));
 }
Пример #25
0
 public static void setCmd(int cmd, int value)
 {
     NativeUtils.setCoreCmdArray(cmd, value);
 }
Пример #26
0
 public static void interpretCmd(int cmd, int value)
 {
     NativeUtils.interpretCoreCmd(cmd, value, NativeUtils.CoreMadr);
 }