Ejemplo n.º 1
0
        /// <summary>
        /// Mix stereo samples in memory: add one stereo sample stream to another
        /// stereo sample stream.
        /// </summary>
        /// <param name="inAddr">    the start address of the input stereo sample stream </param>
        /// <param name="inOutAddr"> the start address of the stereo sample being updated </param>
        /// <param name="samples">   the number of stereo samples </param>
        public static void mixStereoInMemory(int inAddr, int inOutAddr, int samples)
        {
            int           Length      = samples << 2;
            IMemoryReader inReader    = MemoryReader.getMemoryReader(inAddr, Length, 4);
            IMemoryReader inOutReader = MemoryReader.getMemoryReader(inOutAddr, Length, 4);
            IMemoryWriter inOutWriter = MemoryWriter.getMemoryWriter(inOutAddr, Length, 4);

            for (int i = 0; i < samples; i++)
            {
                int inStereoValue = inReader.readNext();
                if (inStereoValue == 0)
                {
                    // InOut unchanged for this sample
                    inOutReader.skip(1);
                    inOutWriter.skip(1);
                }
                else
                {
                    int inOutStereoValue = inOutReader.readNext();
                    inOutStereoValue = mixStereo(inStereoValue, inOutStereoValue);
                    inOutWriter.writeNext(inOutStereoValue);
                }
            }
            inOutWriter.flush();
        }
Ejemplo n.º 2
0
        public static void updateCommands(int @base, int startReg, int endReg, int offsetReg, int stepReg)
        {
            Memory        mem        = Memory;
            int           start      = getRegisterValue(startReg);
            int           end        = getRegisterValue(endReg);
            int           offset     = getRegisterValue(offsetReg);
            int           step       = getRegisterValue(stepReg);
            int           skip       = (step - 4) >> 2;
            IMemoryReader baseReader = MemoryReader.getMemoryReader(getRegisterValue(@base), (end - start) << 4, 4);

            for (int i = start; i < end; i++)
            {
                baseReader.skip(1);
                int           addr       = baseReader.readNext();
                int           count      = baseReader.readNext();
                int           dest       = baseReader.readNext();
                IMemoryReader addrReader = MemoryReader.getMemoryReader(addr, count << 2, 4);
                IMemoryWriter destWriter = MemoryWriter.getMemoryWriter(dest + offset, count * step, 4);
                for (int j = 0; j < count; j++)
                {
                    int src = addrReader.readNext();
                    destWriter.writeNext(mem.read32(src));
                    destWriter.skip(skip);
                }
                destWriter.flush();
            }
        }
Ejemplo n.º 3
0
        public static void call(int baseAddressReg, int offset1, int offset2, int offset3, int destAddressReg)
        {
            Memory mem         = Memory;
            int    baseAddress = getRegisterValue(baseAddressReg);
            int    paramAddr   = mem.read32(baseAddress + offset1);
            int    count       = mem.read16(paramAddr + offset2);

            if (count <= 0)
            {
                return;
            }
            int destAddr    = getRegisterValue(destAddressReg);
            int srcBaseAddr = mem.read32(baseAddress + offset3);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'sealed override':
//ORIGINAL LINE: sealed override float[] src1 = new float[16];
            float[] src1 = new float[16];
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'sealed override':
//ORIGINAL LINE: sealed override float[] src2 = new float[16];
            float[] src2 = new float[16];
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'sealed override':
//ORIGINAL LINE: sealed override float[] dst = new float[16];
            float[] dst = new float[16];

            int           Length     = count * 304;
            IMemoryReader src1Reader = MemoryReader.getMemoryReader(srcBaseAddr + 64, Length, 4);
            IMemoryReader src2Reader = MemoryReader.getMemoryReader(srcBaseAddr + 128, Length, 4);
            IMemoryReader src3Reader = MemoryReader.getMemoryReader(srcBaseAddr + 296, Length, 4);
            IMemoryWriter boneWriter = MemoryWriter.getMemoryWriter(srcBaseAddr + 192, Length, 4);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'sealed override':
//ORIGINAL LINE: sealed override int cmdBONE = pspsharp.graphics.GeCommands.BONE << 24;
            int cmdBONE = GeCommands.BONE << 24;

            for (int i = 0; i < count; i++)
            {
                if ((src3Reader.readNext() & 1) != 0)
                {
                    for (int j = 0; j < 12; j++)
                    {
                        boneWriter.writeNext(cmdBONE);
                    }

                    src1Reader.skip(76);
                    src2Reader.skip(76);
                }
                else
                {
                    for (int j = 0; j < 16; j++)
                    {
                        src1[j] = Float.intBitsToFloat(src1Reader.readNext());
                        src2[j] = Float.intBitsToFloat(src2Reader.readNext());
                    }

                    // VMMUL
                    for (int n1 = 0, j = 0, k = 0; n1 < 4; n1++, k += 4)
                    {
                        // We only need a 4x3 dst matrix because the BONE matrix is only 4x3
                        for (int n2 = 0; n2 < 3; n2++, j++)
                        {
                            float dot = src1[n2] * src2[k];
                            dot   += src1[n2 + 4] * src2[k + 1];
                            dot   += src1[n2 + 8] * src2[k + 2];
                            dst[j] = dot + src1[n2 + 12] * src2[k + 3];
                        }
                        j++;
                    }

                    for (int n1 = 0, j = 0; n1 < 4; n1++)
                    {
                        // The BONE matrix is only 4x3
                        for (int n2 = 0; n2 < 3; n2++, j++)
                        {
                            int intBits = Float.floatToRawIntBits(dst[j]);
                            boneWriter.writeNext(cmdBONE | ((int)((uint)intBits >> 8)));
                        }
                        j++;                         // Skip one column
                    }

                    src1Reader.skip(60);
                    src2Reader.skip(60);
                }
                src3Reader.skip(75);
                boneWriter.skip(64);
            }
            boneWriter.flush();

            // This is probably not used by the application as it is overwritten
            // at each loop and only the last loop result is left...
            for (int n1 = 0, k = 0; n1 < 4; n1++, k += 4)
            {
                const int n2  = 3;
                float     dot = src1[n2] * src2[k];
                dot += src1[n2 + 4] * src2[k + 1];
                dot += src1[n2 + 8] * src2[k + 2];
                dst[(n1 << 2) + n2] = dot + src1[n2 + 12] * src2[k + 3];
            }
            IMemoryWriter dstWriter = MemoryWriter.getMemoryWriter(destAddr, 64, 4);

            for (int n1 = 0; n1 < 4; n1++)
            {
                for (int n2 = 0; n2 < 4; n2++)
                {
                    int intBits = Float.floatToRawIntBits(dst[(n2 << 2) + n1]);
                    dstWriter.writeNext(intBits);
                }
            }
            dstWriter.flush();
        }
Ejemplo n.º 4
0
        public static void call(int matrix1Reg, int matrix2Reg, int destReg, int countReg)
        {
            int matrix1Addr = getRegisterValue(matrix1Reg);
            int matrix2Addr = getRegisterValue(matrix2Reg);
            int dest        = getRegisterValue(destReg);
            int count       = getRegisterValue(countReg);

            if (count <= 0)
            {
                return;
            }

            IMemoryReader matrix1Reader = MemoryReader.getMemoryReader(matrix1Addr, 48 * count, 4);
            IMemoryReader matrix2Reader = MemoryReader.getMemoryReader(matrix2Addr, 48 * count, 4);
            IMemoryWriter destWriter    = MemoryWriter.getMemoryWriter(dest, 64 * count, 4);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'sealed override':
//ORIGINAL LINE: sealed override float[] matrix2 = new float[12];
            float[] matrix2 = new float[12];
            int     cmdBONE = GeCommands.BONE << 24;
            int     cmdRET = GeCommands.RET << 24;
            float   dot, m1a, m1b, m1c;

            for (int i = 0; i < count; i++)
            {
                for (int j = 0; j < 12; j++)
                {
                    matrix2[j] = Float.intBitsToFloat(matrix2Reader.readNext());
                }

                for (int n1 = 0; n1 < 3; n1++)
                {
                    m1a = Float.intBitsToFloat(matrix1Reader.readNext());
                    m1b = Float.intBitsToFloat(matrix1Reader.readNext());
                    m1c = Float.intBitsToFloat(matrix1Reader.readNext());
                    for (int n2 = 0; n2 < 3; n2++)
                    {
                        dot  = m1a * matrix2[n2];
                        dot += m1b * matrix2[n2 + 3];
                        dot += m1c * matrix2[n2 + 6];
                        destWriter.writeNext(((int)((uint)Float.floatToRawIntBits(dot) >> 8)) | cmdBONE);
                    }
                }

                m1a = Float.intBitsToFloat(matrix1Reader.readNext());
                m1b = Float.intBitsToFloat(matrix1Reader.readNext());
                m1c = Float.intBitsToFloat(matrix1Reader.readNext());
                for (int n2 = 0; n2 < 3; n2++)
                {
                    dot  = m1a * matrix2[n2];
                    dot += m1b * matrix2[n2 + 3];
                    dot += m1c * matrix2[n2 + 6];
                    dot += matrix2[n2 + 9];
                    destWriter.writeNext(((int)((uint)Float.floatToRawIntBits(dot) >> 8)) | cmdBONE);
                }

                destWriter.writeNext(cmdRET);
                destWriter.skip(3);
            }
            destWriter.flush();
        }
Ejemplo n.º 5
0
        // See ffmpeg - binkidtc.c - ff_bink_idct_add_c
        public static void binkIdctAdd(int contextAddr1, int contextAddr2)
        {
            int contextAddr = getRelocatedAddress(contextAddr1, contextAddr2);
            int dstAddr     = GprA0;
            int dstStep     = GprA1;
            int blockAddr   = GprA2;
            int blockOffset = GprA3;
            int srcAddr     = GprT0;
            int srcStep     = GprT1;

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'sealed override':
//ORIGINAL LINE: sealed override short[] block = new short[64];
            short[]       block        = new short[64];
            IMemoryReader sourceReader = MemoryReader.getMemoryReader(blockAddr, 128, 2);

            for (int i = 0; i < 64; i++)
            {
                block[i] = (short)sourceReader.readNext();
            }

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'sealed override':
//ORIGINAL LINE: sealed override int[] context = new int[64];
            int[] context = new int[64];
            contextAddr += blockOffset << 8;
            IMemoryReader contextReader = MemoryReader.getMemoryReader(contextAddr, 256, 4);

            for (int i = 0; i < 64; i++)
            {
                context[i] = contextReader.readNext();
            }

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'sealed override':
//ORIGINAL LINE: sealed override int[] temp = new int[64];
            int[] temp = new int[64];
            for (int i = 0; i < 8; i++)
            {
                // See ffmpeg - binkidtc.c - bink_idct_col
                if (block[i + 8] == 0 && block[i + 16] == 0 && block[i + 24] == 0 && block[i + 32] == 0 && block[i + 40] == 0 && block[i + 48] == 0 && block[i + 56] == 0)
                {
                    int src0 = (block[i] * context[i]) >> 11;
                    temp[i]      = src0;
                    temp[i + 8]  = src0;
                    temp[i + 16] = src0;
                    temp[i + 24] = src0;
                    temp[i + 32] = src0;
                    temp[i + 40] = src0;
                    temp[i + 48] = src0;
                    temp[i + 56] = src0;
                }
                else
                {
                    int src0 = (block[i] * context[i]) >> 11;
                    int src1 = (block[i + 8] * context[i + 8]) >> 11;
                    int src2 = (block[i + 16] * context[i + 16]) >> 11;
                    int src6 = (block[i + 48] * context[i + 48]) >> 11;
                    int src3 = (block[i + 24] * context[i + 24]) >> 11;
                    int src4 = (block[i + 32] * context[i + 32]) >> 11;
                    int src5 = (block[i + 40] * context[i + 40]) >> 11;
                    int src7 = (block[i + 56] * context[i + 56]) >> 11;
                    int a0   = src0 + src4;
                    int a1   = src0 - src4;
                    int a2   = src2 + src6;
                    int a3   = (2896 * (src2 - src6)) >> 11;
                    int a4   = src5 + src3;
                    int a5   = src5 - src3;
                    int a6   = src1 + src7;
                    int a7   = src1 - src7;
                    int b0   = a6 + a4;
                    int b1   = ((a5 + a7) * 3784) >> 11;
                    int b2   = ((a5 * -5352) >> 11) - b0 + b1;
                    int b3   = (((a6 - a4) * 2896) >> 11) - b2;
                    int b4   = ((a7 * 2217) >> 11) + b3 - b1;
                    temp[i]      = a0 + a2 + b0;
                    temp[i + 8]  = a1 + a3 - a2 + b2;
                    temp[i + 16] = a1 - a3 + a2 + b3;
                    temp[i + 24] = a0 - a2 - b4;
                    temp[i + 32] = a0 - a2 + b4;
                    temp[i + 40] = a1 - a3 + a2 - b3;
                    temp[i + 48] = a1 + a3 - a2 - b2;
                    temp[i + 56] = a0 + a2 - b0;
                }
            }

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'sealed override':
//ORIGINAL LINE: sealed override int[] src = new int[8];
            int[] src = new int[8];
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'sealed override':
//ORIGINAL LINE: sealed override int[] dst = new int[8];
            int[]         dst       = new int[8];
            IMemoryReader srcReader = MemoryReader.getMemoryReader(srcAddr, 8 * srcStep, 1);
            IMemoryWriter dstWriter = MemoryWriter.getMemoryWriter(dstAddr, 8 * dstStep, 1);

            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    src[j] = srcReader.readNext();
                }
                srcReader.skip(srcStep - 8);

                int n    = i * 8;
                int src0 = temp[n];
                int src1 = temp[n + 1];
                int src2 = temp[n + 2];
                int src3 = temp[n + 3];
                int src4 = temp[n + 4];
                int src5 = temp[n + 5];
                int src6 = temp[n + 6];
                int src7 = temp[n + 7];
                int a0   = src0 + src4;
                int a1   = src0 - src4;
                int a2   = src2 + src6;
                int a3   = (2896 * (src2 - src6)) >> 11;
                int a4   = src5 + src3;
                int a5   = src5 - src3;
                int a6   = src1 + src7;
                int a7   = src1 - src7;
                int b0   = a6 + a4;
                int b1   = ((a5 + a7) * 3784) >> 11;
                int b2   = ((a5 * -5352) >> 11) - b0 + b1;
                int b3   = (((a6 - a4) * 2896) >> 11) - b2;
                int b4   = ((a7 * 2217) >> 11) + b3 - b1;
                dst[0] = src[0] + (((a0 + a2 + b0) + 0x7F) >> 8);
                dst[1] = src[1] + (((a1 + a3 - a2 + b2) + 0x7F) >> 8);
                dst[2] = src[2] + (((a1 - a3 + a2 + b3) + 0x7F) >> 8);
                dst[3] = src[3] + (((a0 - a2 - b4) + 0x7F) >> 8);
                dst[4] = src[4] + (((a0 - a2 + b4) + 0x7F) >> 8);
                dst[5] = src[5] + (((a1 - a3 + a2 - b3) + 0x7F) >> 8);
                dst[6] = src[6] + (((a1 + a3 - a2 - b2) + 0x7F) >> 8);
                dst[7] = src[7] + (((a0 + a2 - b0) + 0x7F) >> 8);

                for (int j = 0; j < 8; j++)
                {
                    dstWriter.writeNext(dst[j]);
                }
                dstWriter.flush();
                dstWriter.skip(dstStep - 8);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Mix stereo samples in memory: add one stereo sample stream (multiplied by
        /// a given volume value) to another stereo sample stream.
        /// </summary>
        /// <param name="inAddr">        the start address of the input stereo sample stream </param>
        /// <param name="inOutAddr">     the start address of the stereo sample being updated </param>
        /// <param name="samples">       the number of stereo samples </param>
        /// <param name="inLeftVolume">  the volume value for the input left channel stream,
        ///                      in the range [0..1] </param>
        /// <param name="inRightVolume"> the volume value for the input right channel stream,
        ///                      in the range [0..1] </param>
        public static void mixStereoInMemory(int inAddr, int inOutAddr, int samples, float inLeftVolume, float inRightVolume)
        {
            if (System.Math.Abs(inLeftVolume) < 0.0001f)
            {
                inLeftVolume = 0.0f;
            }
            if (System.Math.Abs(inRightVolume) < 0.0001f)
            {
                inRightVolume = 0.0f;
            }

            if (inLeftVolume == 0.0f && inRightVolume == 0.0f)
            {
                // Nothing to do
                return;
            }

            if (inLeftVolume == 1.0f && inRightVolume == 1.0f)
            {
                // Simple case, without inVolume
                mixStereoInMemory(inAddr, inOutAddr, samples);
                return;
            }

            if (inLeftVolume < 0.0f || inLeftVolume > 1.0f)
            {
                if (Modules.log.isEnabledFor(Level.WARN))
                {
                    Modules.Console.WriteLine(string.Format("Utils.mixStereoInMemory left volume outside range {0:F}", inLeftVolume));
                }
            }
            if (inRightVolume < 0.0f || inRightVolume > 1.0f)
            {
                if (Modules.log.isEnabledFor(Level.WARN))
                {
                    Modules.Console.WriteLine(string.Format("Utils.mixStereoInMemory right volume outside range {0:F}", inRightVolume));
                }
            }

            int           Length      = samples << 2;
            IMemoryReader inReader    = MemoryReader.getMemoryReader(inAddr, Length, 4);
            IMemoryReader inOutReader = MemoryReader.getMemoryReader(inOutAddr, Length, 4);
            IMemoryWriter inOutWriter = MemoryWriter.getMemoryWriter(inOutAddr, Length, 4);

            for (int i = 0; i < samples; i++)
            {
                int inStereoValue = inReader.readNext();
                if (inStereoValue == 0)
                {
                    // InOut unchanged for this sample
                    inOutReader.skip(1);
                    inOutWriter.skip(1);
                }
                else
                {
                    inStereoValue = getStereo(inStereoValue, inLeftVolume, inRightVolume);
                    int inOutStereoValue = inOutReader.readNext();
                    inOutStereoValue = mixStereo(inStereoValue, inOutStereoValue);
                    inOutWriter.writeNext(inOutStereoValue);
                }
            }
            inOutWriter.flush();
        }
Ejemplo n.º 7
0
        private static void sceGuDrawSprite(int context, int listCurrentOffset, int x, int y, int z, int u, int v, int flip, int rotation, int wOffset, int hOffset, int dxOffset, int dyOffset)
        {
            Memory mem         = Memory;
            int    listCurrent = mem.read32(context + listCurrentOffset);
            int    w           = mem.read32(context + wOffset);
            int    h           = mem.read32(context + hOffset);
            int    dx          = mem.read32(context + dxOffset);
            int    dy          = mem.read32(context + dyOffset);
            int    cmd;

            IMemoryWriter listWriter = MemoryWriter.getMemoryWriter(listCurrent, 44, 4);

            int           vertexAddress = listCurrent + 8;
            IMemoryWriter vertexWriter  = MemoryWriter.getMemoryWriter(vertexAddress, 20, 2);
            int           v0u           = u;
            int           v0v           = v;
            int           v0x           = x;
            int           v0y           = y;
            int           v1u           = u + w;
            int           v1v           = v + h;
            int           v1x           = x + dx;
            int           v1y           = y + dy;

            if ((flip & 1) != 0)
            {
                int tmp = v0u;
                v0u = v1u;
                v1u = tmp;
            }
            if ((flip & 2) != 0)
            {
                int tmp = v0v;
                v0v = v1v;
                v1v = tmp;
            }
            switch (rotation)
            {
            case 1:
            {
                int tmp = v0y;
                v0y = v1y;
                v1y = tmp;
                break;
            }

            case 2:
            {
                int tmp = v0x;
                v0x = v1x;
                v1x = tmp;
                tmp = v0y;
                v0y = v1y;
                v1y = tmp;
                break;
            }

            case 3:
            {
                int tmp = v0x;
                v0x = v1x;
                v1x = tmp;
                break;
            }
            }

            vertexWriter.writeNext(v0u);
            vertexWriter.writeNext(v0v);
            vertexWriter.writeNext(v0x);
            vertexWriter.writeNext(v0y);
            vertexWriter.writeNext(z);
            vertexWriter.writeNext(v1u);
            vertexWriter.writeNext(v1v);
            vertexWriter.writeNext(v1x);
            vertexWriter.writeNext(v1y);
            vertexWriter.writeNext(z);
            vertexWriter.flush();

            int jumpAddr = vertexAddress + 20;

            cmd = (GeCommands.BASE << 24) | ((jumpAddr >> 8) & 0x00FF0000);
            listWriter.writeNext(cmd);

            cmd = (GeCommands.JUMP << 24) | (jumpAddr & 0x00FFFFFF);
            listWriter.writeNext(cmd);

            // Skip the 2 vertex entries
            listWriter.skip(5);

            cmd = (GeCommands.VTYPE << 24) | ((GeCommands.VTYPE_TRANSFORM_PIPELINE_RAW_COORD << 23) | (GeCommands.VTYPE_POSITION_FORMAT_16_BIT << 7) | GeCommands.VTYPE_TEXTURE_FORMAT_16_BIT);
            listWriter.writeNext(cmd);

            cmd = (GeCommands.BASE << 24) | ((vertexAddress >> 8) & 0x00FF0000);
            listWriter.writeNext(cmd);

            cmd = (GeCommands.VADDR << 24) | (vertexAddress & 0x00FFFFFF);
            listWriter.writeNext(cmd);

            cmd = (GeCommands.PRIM << 24) | (GeCommands.PRIM_SPRITES << 16) | 2;
            listWriter.writeNext(cmd);

            listWriter.flush();

            mem.write32(context + listCurrentOffset, jumpAddr + 16);
        }