Esempio n. 1
0
        public static void call()
        {
            int a0 = GprA0;
            int a1 = GprA1;

            IMemoryReader memoryReader = MemoryReader.getMemoryReader(a1, 64, 4);
            int           i00          = memoryReader.readNext();
            int           i01          = memoryReader.readNext();
            int           i02          = memoryReader.readNext();

            memoryReader.skip(1);
            int i10 = memoryReader.readNext();
            int i11 = memoryReader.readNext();
            int i12 = memoryReader.readNext();

            memoryReader.skip(1);
            int i20 = memoryReader.readNext();
            int i21 = memoryReader.readNext();
            int i22 = memoryReader.readNext();

            memoryReader.skip(1);
            int i30 = memoryReader.readNext();
            int i31 = memoryReader.readNext();
            int i32 = memoryReader.readNext();

            float a00 = Float.intBitsToFloat(i00);
            float a01 = Float.intBitsToFloat(i01);
            float a02 = Float.intBitsToFloat(i02);
            float a10 = Float.intBitsToFloat(i10);
            float a11 = Float.intBitsToFloat(i11);
            float a12 = Float.intBitsToFloat(i12);
            float a20 = Float.intBitsToFloat(i20);
            float a21 = Float.intBitsToFloat(i21);
            float a22 = Float.intBitsToFloat(i22);
            float a30 = Float.intBitsToFloat(i30);
            float a31 = Float.intBitsToFloat(i31);
            float a32 = Float.intBitsToFloat(i32);

            IMemoryWriter memoryWriter = MemoryWriter.getMemoryWriter(a0, 64, 4);

            memoryWriter.writeNext(i00);
            memoryWriter.writeNext(i10);
            memoryWriter.writeNext(i20);
            memoryWriter.writeNext(0);
            memoryWriter.writeNext(i01);
            memoryWriter.writeNext(i11);
            memoryWriter.writeNext(i21);
            memoryWriter.writeNext(0);
            memoryWriter.writeNext(i02);
            memoryWriter.writeNext(i12);
            memoryWriter.writeNext(i22);
            memoryWriter.writeNext(0);
            memoryWriter.writeNext(Float.floatToRawIntBits(-(a00 * a30 + a01 * a31 + a02 * a32)));
            memoryWriter.writeNext(Float.floatToRawIntBits(-(a10 * a30 + a11 * a31 + a12 * a32)));
            memoryWriter.writeNext(Float.floatToRawIntBits(-(a20 * a30 + a21 * a31 + a22 * a32)));
            memoryWriter.writeNext(0x3F800000);
            memoryWriter.flush();
        }
Esempio n. 2
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();
        }
Esempio n. 3
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();
            }
        }
Esempio n. 4
0
        private static int sceGuSetMatrix4x3(IMemoryWriter listWriter, IMemoryReader matrixReader, int startCmd, int matrixCmd, int index)
        {
            listWriter.writeNext((startCmd << 24) + index);
            int cmd = matrixCmd << 24;

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    listWriter.writeNext(cmd | ((int)((uint)matrixReader.readNext() >> 8)));
                }
                matrixReader.skip(1);
            }
            return(52);
        }
Esempio n. 5
0
        /// <summary>
        /// Generate a hashCode on a memory range using a rather simple but fast method
        /// and a stride.
        /// </summary>
        /// <param name="hashCode">		current hashCode value </param>
        /// <param name="addr">			start of the memory range to be hashed </param>
        /// <param name="lengthInBytes">	Length of the memory range </param>
        /// <param name="strideInBytes"> stride (hash only 4 bytes every stride bytes) </param>
        /// <returns> updated hashCode value </returns>
        public static int getHashCode(int hashCode, int addr, int lengthInBytes, int strideInBytes)
        {
            if (strideInBytes <= 4)
            {
                // There is no stride...
                return(getHashCode(hashCode, addr, lengthInBytes));
            }

            int skip = (strideInBytes / 4) - 1;

            IMemoryReader memoryReader = MemoryReader.getMemoryReader(addr, lengthInBytes, 4);
            int           step         = (skip + 1) * 4;

            lengthInBytes -= lengthInBytes % strideInBytes;
            for (int i = 0, j = 0; i < lengthInBytes; i += step, j++)
            {
                int value = memoryReader.readNext();
                memoryReader.skip(skip);
                hashCode ^= value + salt[j & 0xFF];
                hashCode += i + addr;
            }

            return(hashCode);
        }
Esempio n. 6
0
        /// <summary>
        /// Generate a hashCode on a memory range using a more complex but slower method.
        /// This method also uses a stride to scan only parts of the memory range.
        /// </summary>
        /// <param name="hashCode">		current hashCode value </param>
        /// <param name="addr">			start of the memory range to be hashed </param>
        /// <param name="lengthInBytes">	Length of the memory range </param>
        /// <param name="strideInBytes"> stride (hash only 4 bytes every stride bytes) </param>
        /// <returns> updated hashCode value </returns>
        public static int getHashCodeComplex(int hashCode, int addr, int lengthInBytes, int strideInBytes)
        {
            if (strideInBytes <= 4)
            {
                // There is no stride...
                return(getHashCodeComplex(hashCode, addr, lengthInBytes));
            }

            int skip = (strideInBytes / 4) - 1;

            IMemoryReader memoryReader = MemoryReader.getMemoryReader(addr, lengthInBytes, 4);
            int           n            = lengthInBytes / strideInBytes;

            for (int i = 0; i < n; i++)
            {
                int value = memoryReader.readNext();
                memoryReader.skip(skip);
                value     = Integer.rotateLeft(value, i & 31);
                hashCode ^= value + i + addr;
                hashCode += i + addr;
            }

            return(hashCode);
        }
Esempio n. 7
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();
        }
Esempio n. 8
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);
            }
        }
Esempio n. 9
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();
        }