コード例 #1
0
        private void copyMonoSamplesToMem(int[] mixedSamples, int addr, int samples, int monoVol, bool writeSamples)
        {
            // Adjust the volume according to the global volume settings
            monoVol = Audio.getVolume(monoVol);

            if (!writeSamples)
            {
                // If the samples have not been changed and the volume settings
                // would also not adjust the samples, no need to copy them back to memory.
                if (monoVol == MAX_VOLUME)
                {
                    return;
                }
            }

            int           lengthInBytes = mixedSamples.Length << 1;
            IMemoryWriter memoryWriter  = MemoryWriter.getMemoryWriter(addr, lengthInBytes, 2);

            for (int i = 0, j = 0; i < samples; i++, j++)
            {
                short sampleMono = clampSample(mixedSamples[j]);
                sampleMono = SoundChannel.adjustSample(sampleMono, monoVol);
                memoryWriter.writeNext(sampleMono & 0xFFFF);
            }
            memoryWriter.flush();
        }
コード例 #2
0
        private void copyStereoSamplesToMem(int[] mixedSamples, int addr, int samples, int leftVol, int rightVol, bool writeSamples)
        {
            // Adjust the volume according to the global volume settings
            leftVol  = Audio.getVolume(leftVol);
            rightVol = Audio.getVolume(rightVol);

            if (!writeSamples)
            {
                // If the samples have not been changed and the volume settings
                // would also not adjust the samples, no need to copy them back to memory.
                if (leftVol == MAX_VOLUME && rightVol == MAX_VOLUME)
                {
                    return;
                }
            }

            int           lengthInBytes = mixedSamples.Length << 1;
            IMemoryWriter memoryWriter  = MemoryWriter.getMemoryWriter(addr, lengthInBytes, 4);

            for (int i = 0, j = 0; i < samples; i++, j += 2)
            {
                short sampleLeft  = clampSample(mixedSamples[j]);
                short sampleRight = clampSample(mixedSamples[j + 1]);
                sampleLeft  = SoundChannel.adjustSample(sampleLeft, leftVol);
                sampleRight = SoundChannel.adjustSample(sampleRight, rightVol);
                int sampleStereo = getSampleStereo(sampleLeft, sampleRight);
                memoryWriter.writeNext(sampleStereo);
            }
            memoryWriter.flush();
        }
コード例 #3
0
        public static void stereoToMono(int dstAddrReg, int srcAddrReg, int samplesReg)
        {
            int           samples          = getRegisterValue(samplesReg);
            int           srcAddr          = getRegisterValue(srcAddrReg);
            int           dstAddr          = getRegisterValue(dstAddrReg);
            int           srcAddrAlignment = srcAddr & 0x2;
            IMemoryReader memoryReader     = MemoryReader.getMemoryReader(srcAddr - srcAddrAlignment, samples << 2, 4);
            IMemoryWriter memoryWriter     = MemoryWriter.getMemoryWriter(dstAddr, samples << 1, 2);

            if (srcAddrAlignment == 0)
            {
                // Taking left samples as mono samples
                for (int i = 0; i < samples; i++)
                {
                    int sample = memoryReader.readNext();
                    memoryWriter.writeNext(sample);
                }
            }
            else
            {
                // Taking right samples as mono samples
                for (int i = 0; i < samples; i++)
                {
                    int sample = memoryReader.readNext();
                    sample = (int)((uint)sample >> 16);
                    memoryWriter.writeNext(sample);
                }
            }
            memoryWriter.flush();
        }
コード例 #4
0
        public static void adjustVolume(int dstAddrReg, int srcAddrReg, int samplesReg, int volReg)
        {
            float vol = getFRegisterValue(volReg);

            if (vol != 1f)
            {
                int           samples      = getRegisterValue(samplesReg);
                int           srcAddr      = getRegisterValue(srcAddrReg);
                int           dstAddr      = getRegisterValue(dstAddrReg);
                IMemoryReader memoryReader = MemoryReader.getMemoryReader(srcAddr, samples << 1, 2);
                IMemoryWriter memoryWriter = MemoryWriter.getMemoryWriter(dstAddr, samples << 1, 2);

                if (vol == .5f)
                {
                    for (int i = 0; i < samples; i++)
                    {
                        int sample = memoryReader.readNext();
                        sample = (sample << 16) >> 17;
                        memoryWriter.writeNext(sample);
                    }
                }
                else
                {
                    for (int i = 0; i < samples; i++)
                    {
                        int sample = (short)memoryReader.readNext();
                        sample = (int)(sample * vol);
                        memoryWriter.writeNext(sample);
                    }
                }
                memoryWriter.flush();
            }
        }
コード例 #5
0
        public static void callCopyWithLength(int errorCode1, int errorCode2)
        {
            int srcAddr = GprA0;
            int dstAddr = GprA1;
            int Length  = GprA2;

            int lengthSrc = getStrlen(srcAddr);

            if (lengthSrc > Length)
            {
                GprV0 = (errorCode1 << 16) | errorCode2;
                return;
            }

            IMemoryReader memoryReader = MemoryReader.getMemoryReader(srcAddr, Length, 1);
            IMemoryWriter memoryWriter = MemoryWriter.getMemoryWriter(dstAddr, Length, 1);

            for (int i = 0; i < lengthSrc; i++)
            {
                int c = toUpperCase[memoryReader.readNext()];
                memoryWriter.writeNext(c);
            }
            memoryWriter.writeNext(0);
            memoryWriter.flush();
        }
コード例 #6
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();
        }
コード例 #7
0
        public virtual void sceGuFinish()
        {
            sendCommandi(GeCommands.FINISH, 0);
            sendCommandi(GeCommands.END, 0);

            if (topAddr < listWriter.CurrentAddress)
            {
                Console.WriteLine(string.Format("sceGu memory overwrite mem={0}, listAddr=0x{1:X8}, topAddr=0x{2:X8}", sysMemInfo, listWriter.CurrentAddress, topAddr));
            }
            else
            {
                //if (log.DebugEnabled)
                {
                    Console.WriteLine(string.Format("sceGu memory usage free=0x{0:X}, mem={1}, listAddr=0x{2:X8}, topAddr=0x{3:X8}", topAddr - listWriter.CurrentAddress, sysMemInfo, listWriter.CurrentAddress, topAddr));
                }
            }

            listWriter.flush();

            int saveContextAddr = sceGuGetMemory(GeContext.SIZE_OF);

            Memory mem = Memory.Instance;

            listId = Modules.sceGe_userModule.hleGeListEnQueue(new TPointer(mem, listAddr), TPointer.NULL, -1, TPointer.NULL, saveContextAddr, false);
        }
コード例 #8
0
        public static void multMat4x4ByVec4(int matReg, int matOffset, int vecReg, int vecOffset, int resultReg, int resultOffset)
        {
            int mat    = getRegisterValue(matReg) + matOffset;
            int vec    = getRegisterValue(vecReg) + vecOffset;
            int result = getRegisterValue(resultReg) + resultOffset;

            IMemoryReader matReader    = MemoryReader.getMemoryReader(mat, 64, 4);
            IMemoryReader vecReader    = MemoryReader.getMemoryReader(vec, 16, 4);
            IMemoryWriter resultWriter = MemoryWriter.getMemoryWriter(result, 16, 4);

            float vec0 = Float.intBitsToFloat(vecReader.readNext());
            float vec1 = Float.intBitsToFloat(vecReader.readNext());
            float vec2 = Float.intBitsToFloat(vecReader.readNext());
            float vec3 = Float.intBitsToFloat(vecReader.readNext());

            for (int i = 0; i < 4; i++)
            {
                float mat0 = Float.intBitsToFloat(matReader.readNext());
                float mat1 = Float.intBitsToFloat(matReader.readNext());
                float mat2 = Float.intBitsToFloat(matReader.readNext());
                float mat3 = Float.intBitsToFloat(matReader.readNext());

                float res = vec0 * mat0 + vec1 * mat1 + vec2 * mat2 + vec3 * mat3;
                resultWriter.writeNext(Float.floatToRawIntBits(res));
            }
            resultWriter.flush();
        }
コード例 #9
0
        private static void sceGuSetMatrix(int context, int listCurrentOffset, int type, int matrix)
        {
            Memory mem         = Memory;
            int    listCurrent = mem.read32(context + listCurrentOffset);

            IMemoryWriter listWriter   = MemoryWriter.getMemoryWriter(listCurrent, 68, 4);
            IMemoryReader matrixReader = MemoryReader.getMemoryReader(matrix, 64, 4);

            switch (type)
            {
            case 0:
                listCurrent += sceGuSetMatrix4x4(listWriter, matrixReader, GeCommands.PMS, GeCommands.PROJ, 0);
                break;

            case 1:
                listCurrent += sceGuSetMatrix4x3(listWriter, matrixReader, GeCommands.VMS, GeCommands.VIEW, 0);
                break;

            case 2:
                listCurrent += sceGuSetMatrix4x3(listWriter, matrixReader, GeCommands.MMS, GeCommands.MODEL, 0);
                break;

            case 3:
                listCurrent += sceGuSetMatrix4x3(listWriter, matrixReader, GeCommands.TMS, GeCommands.TMATRIX, 0);
                break;
            }
            listWriter.flush();

            mem.write32(context + listCurrentOffset, listCurrent);
        }
コード例 #10
0
        public virtual void sceGuDrawRectangle(int x0, int y0, int x1, int y1, int color)
        {
            int           numberOfVertex   = 2;
            int           lineVertexAddr   = sceGuGetMemory(12 * numberOfVertex);
            IMemoryWriter lineVertexWriter = MemoryWriter.getMemoryWriter(lineVertexAddr, 2);

            // Color
            lineVertexWriter.writeNext(color & 0xFFFF);
            lineVertexWriter.writeNext((int)((uint)color >> 16));
            // Position
            lineVertexWriter.writeNext(x0);
            lineVertexWriter.writeNext(y0);
            lineVertexWriter.writeNext(0);
            // Align on 32-bit
            lineVertexWriter.writeNext(0);
            // Color
            lineVertexWriter.writeNext(color & 0xFFFF);
            lineVertexWriter.writeNext((int)((uint)color >> 16));
            // Position
            lineVertexWriter.writeNext(x1);
            lineVertexWriter.writeNext(y1);
            lineVertexWriter.writeNext(0);
            // Align on 32-bit
            lineVertexWriter.writeNext(0);
            lineVertexWriter.flush();

            sceGuDisable(pspsharp.graphics.RE.IRenderingEngine_Fields.GU_TEXTURE_2D);
            sceGuDrawArray(GeCommands.PRIM_SPRITES, (VTYPE_TRANSFORM_PIPELINE_RAW_COORD << 23) | (VTYPE_COLOR_FORMAT_32BIT_ABGR_8888 << 2) | (VTYPE_POSITION_FORMAT_16_BIT << 7), numberOfVertex, 0, lineVertexAddr);
        }
コード例 #11
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();
            }
        }
コード例 #12
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();
        }
コード例 #13
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: protected void read(pspsharp.state.StateInputStream stream, int address, int Length) throws java.io.IOException
        protected internal virtual void read(StateInputStream stream, int address, int Length)
        {
            IMemoryWriter memoryWriter = MemoryWriter.getMemoryWriter(this, address, Length, 4);

            for (int i = 0; i < Length; i += 4)
            {
                memoryWriter.writeNext(stream.readInt());
            }
            memoryWriter.flush();
        }
コード例 #14
0
        public virtual int sceGzipDecompress(TPointer outBufferAddr, int outBufferLength, TPointer inBufferAddr, TPointer32 crc32Addr)
        {
            if (log.TraceEnabled)
            {
                log.trace(string.Format("sceGzipDecompress: {0}", Utilities.getMemoryDump(inBufferAddr.Address, 16)));
            }

            int   result;
            CRC32 crc32 = new CRC32();

            sbyte[] buffer = new sbyte[4096];
            try
            {
                // Using a GZIPInputStream instead of an Inflater because the GZIPInputStream
                // is skipping the GZIP header and this should be done manually with an Inflater.
                GZIPInputStream @is                = new GZIPInputStream(new MemoryInputStream(inBufferAddr.Address));
                IMemoryWriter   memoryWriter       = MemoryWriter.getMemoryWriter(outBufferAddr.Address, outBufferLength, 1);
                int             decompressedLength = 0;
                while (decompressedLength < outBufferLength)
                {
                    int Length = @is.read(buffer);
                    if (Length < 0)
                    {
                        // End of GZIP stream
                        break;
                    }
                    if (decompressedLength + Length > outBufferLength)
                    {
                        Console.WriteLine(string.Format("sceGzipDecompress : decompress buffer too small inBuffer={0}, outLength={1:D}", inBufferAddr, outBufferLength));
                        @is.close();
                        return(SceKernelErrors.ERROR_INVALID_SIZE);
                    }

                    crc32.update(buffer, 0, Length);

                    for (int i = 0; i < Length; i++)
                    {
                        memoryWriter.writeNext(buffer[i] & 0xFF);
                    }
                    decompressedLength += Length;
                }
                @is.close();
                memoryWriter.flush();
                result = decompressedLength;
            }
            catch (IOException e)
            {
                Console.WriteLine("sceGzipDecompress", e);
                return(SceKernelErrors.ERROR_INVALID_FORMAT);
            }
            crc32Addr.setValue((int)crc32.Value);

            return(result);
        }
コード例 #15
0
 public void setArray(int offset, sbyte[] bytes, int bytesOffset, int n)
 {
     if (NotNull)
     {
         IMemoryWriter memoryWriter = MemoryWriter.getMemoryWriter(Memory, Address + offset, n, 1);
         for (int i = 0; i < n; i++)
         {
             memoryWriter.writeNext(bytes[bytesOffset + i] & 0xFF);
         }
         memoryWriter.flush();
     }
 }
コード例 #16
0
        public virtual int sceZlibDecompress(TPointer outBufferAddr, int outBufferLength, TPointer inBufferAddr, TPointer32 crc32Addr)
        {
            sbyte[]       inBuffer    = new sbyte[4096];
            sbyte[]       outBuffer   = new sbyte[4096];
            int           inBufferPtr = 0;
            IMemoryReader reader      = MemoryReader.getMemoryReader(inBufferAddr.Address, 1);
            IMemoryWriter writer      = MemoryWriter.getMemoryWriter(outBufferAddr.Address, outBufferLength, 1);
            CRC32         crc32       = new CRC32();
            Inflater      inflater    = new Inflater();

            while (!inflater.finished())
            {
                if (inflater.needsInput())
                {
                    for (inBufferPtr = 0; inBufferPtr < inBuffer.Length; ++inBufferPtr)
                    {
                        inBuffer[inBufferPtr] = (sbyte)reader.readNext();
                    }
                    inflater.Input = inBuffer;
                }

                try
                {
                    int count = inflater.inflate(outBuffer);

                    if (inflater.TotalOut > outBufferLength)
                    {
                        Console.WriteLine(string.Format("sceZlibDecompress : zlib decompress buffer too small inBuffer={0}, outLength={1:D}", inBufferAddr, outBufferLength));
                        return(SceKernelErrors.ERROR_INVALID_SIZE);
                    }
                    crc32.update(outBuffer, 0, count);
                    for (int i = 0; i < count; ++i)
                    {
                        writer.writeNext(outBuffer[i] & 0xFF);
                    }
                }
                catch (DataFormatException)
                {
                    Console.WriteLine(string.Format("sceZlibDecompress : malformed zlib stream inBuffer={0}", inBufferAddr));
                    return(SceKernelErrors.ERROR_INVALID_FORMAT);
                }
            }
            writer.flush();

            crc32Addr.setValue((int)crc32.Value);

            return(inflater.TotalOut);
        }
コード例 #17
0
        public static void sceGuCopyImage(int contextAddr1, int contextAddr2, int listCurrentOffset)
        {
            Memory mem         = Memory;
            int    psm         = GprA0;
            int    sx          = GprA1;
            int    sy          = GprA2;
            int    width       = GprA3;
            int    height      = GprT0;
            int    srcw        = GprT1;
            int    src         = GprT2;
            int    dx          = GprT3;
            int    dy          = StackParam0;
            int    destw       = StackParam1;
            int    dest        = StackParam2;
            int    context     = mem.read32(getRelocatedAddress(contextAddr1, contextAddr2));
            int    listCurrent = mem.read32(context + listCurrentOffset);
            int    cmd;

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

            cmd = (GeCommands.TRXSBP << 24) | (src & 0x00FFFFFF);
            listWriter.writeNext(cmd);

            cmd = (GeCommands.TRXSBW << 24) | ((src >> 8) & 0x000F0000) | srcw;
            listWriter.writeNext(cmd);

            cmd = (GeCommands.TRXPOS << 24) | (sy << 10) | sx;
            listWriter.writeNext(cmd);

            cmd = (GeCommands.TRXDBP << 24) | (dest & 0x00FFFFFF);
            listWriter.writeNext(cmd);

            cmd = (GeCommands.TRXDBW << 24) | ((dest >> 8) & 0x000F0000) | destw;
            listWriter.writeNext(cmd);

            cmd = (GeCommands.TRXDPOS << 24) | (dy << 10) | dx;
            listWriter.writeNext(cmd);

            cmd = (GeCommands.TRXSIZE << 24) | ((height - 1) << 10) | (width - 1);
            listWriter.writeNext(cmd);

            cmd = (GeCommands.TRXKICK << 24) | (pspsharp.graphics.RE.IRenderingEngine_Fields.sizeOfTextureType[psm] == 4 ? GeCommands.TRXKICK_32BIT_TEXEL_SIZE : GeCommands.TRXKICK_16BIT_TEXEL_SIZE);
            listWriter.writeNext(cmd);

            listWriter.flush();
            mem.write32(context + listCurrentOffset, listCurrent + 32);
        }
コード例 #18
0
        private static void sceGuBoneMatrix(int context, int listCurrentOffset, int index, int matrix)
        {
            Memory mem         = Memory;
            int    listCurrent = mem.read32(context + listCurrentOffset);

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

            if (writeDUMMY)
            {
                listWriter.writeNext(GeCommands.DUMMY << 24);
                listCurrent += 4;
            }
            IMemoryReader matrixReader = MemoryReader.getMemoryReader(matrix, 64, 4);

            listCurrent += sceGuSetMatrix4x3(listWriter, matrixReader, GeCommands.BOFS, GeCommands.BONE, index * 12);
            listWriter.flush();

            mem.write32(context + listCurrentOffset, listCurrent);
        }
コード例 #19
0
        public static void mixMonoToStereo(int leftChannelAddrReg, int rightChannelAddrReg, int stereoChannelAddrReg, int lengthReg, int lengthStep)
        {
            int leftChannelAddr   = getRegisterValue(leftChannelAddrReg);
            int rightChannelAddr  = getRegisterValue(rightChannelAddrReg);
            int stereoChannelAddr = getRegisterValue(stereoChannelAddrReg);
            int Length            = getRegisterValue(lengthReg) * lengthStep;

            IMemoryReader leftChannelReader   = MemoryReader.getMemoryReader(leftChannelAddr, Length, 2);
            IMemoryReader rightChannelReader  = MemoryReader.getMemoryReader(rightChannelAddr, Length, 2);
            IMemoryWriter stereoChannelWriter = MemoryWriter.getMemoryWriter(stereoChannelAddr, Length << 1, 2);

            for (int i = 0; i < Length; i += 2)
            {
                int left  = leftChannelReader.readNext();
                int right = rightChannelReader.readNext();
                stereoChannelWriter.writeNext(left);
                stereoChannelWriter.writeNext(right);
            }
            stereoChannelWriter.flush();
        }
コード例 #20
0
        public virtual int hleUtilsBufferCopyWithRange(TPointer outAddr, int outSize, TPointer inAddr, int inSize, int cmd)
        {
            int originalInSize = inSize;

            // The input size needs for some KIRK commands to be 16-bytes aligned
            inSize = Utilities.alignUp(inSize, 15);

            // Read the whole input buffer, including a possible header
            // (up to 144 bytes, depending on the KIRK command)
            sbyte[]       inBytes        = new sbyte[inSize + 144]; // Up to 144 bytes header
            IMemoryReader memoryReaderIn = MemoryReader.getMemoryReader(inAddr, inSize, 1);

            for (int i = 0; i < inSize; i++)
            {
                inBytes[i] = (sbyte)memoryReaderIn.readNext();
            }

            // Some KIRK commands (e.g. PSP_KIRK_CMD_SHA1_HASH) only update a part of the output buffer.
            // Read the whole output buffer so that it can be updated completely after the KIRK call.
            sbyte[]       outBytes        = new sbyte[Utilities.alignUp(outSize, 15)];
            IMemoryReader memoryReaderOut = MemoryReader.getMemoryReader(outAddr, outBytes.Length, 1);

            for (int i = 0; i < outBytes.Length; i++)
            {
                outBytes[i] = (sbyte)memoryReaderOut.readNext();
            }

            int result = hleUtilsBufferCopyWithRange(outBytes, 0, outSize, inBytes, 0, originalInSize, cmd);

            // Write back the whole output buffer to the memory.
            IMemoryWriter memoryWriter = MemoryWriter.getMemoryWriter(outAddr, outSize, 1);

            for (int i = 0; i < outSize; i++)
            {
                memoryWriter.writeNext(outBytes[i] & 0xFF);
            }
            memoryWriter.flush();

            return(result);
        }
コード例 #21
0
        public static void writeOutput(float[][] samples, int outputAddr, int numberOfSamples, int decodedChannels, int outputChannels)
        {
            IMemoryWriter writer = MemoryWriter.getMemoryWriter(outputAddr, numberOfSamples * 2 * outputChannels, 2);

            switch (outputChannels)
            {
            case 1:
                for (int i = 0; i < numberOfSamples; i++)
                {
                    int sample = convertSampleFloatToInt16(samples[0][i]);
                    writer.writeNext(sample);
                }
                break;

            case 2:
                if (decodedChannels == 1)
                {
                    // Convert decoded mono into output stereo
                    for (int i = 0; i < numberOfSamples; i++)
                    {
                        int sample = convertSampleFloatToInt16(samples[0][i]);
                        writer.writeNext(sample);
                        writer.writeNext(sample);
                    }
                }
                else
                {
                    for (int i = 0; i < numberOfSamples; i++)
                    {
                        int lsample = convertSampleFloatToInt16(samples[0][i]);
                        int rsample = convertSampleFloatToInt16(samples[1][i]);
                        writer.writeNext(lsample);
                        writer.writeNext(rsample);
                    }
                }
                break;
            }
            writer.flush();
        }
コード例 #22
0
        protected internal static void writeMd5Digest(int address, sbyte[] digest)
        {
            // The PSP returns 16 bytes
            const int     digestLength = 16;
            int           size         = digest == null ? 0 : System.Math.Min(digest.Length, digestLength);
            IMemoryWriter memoryWriter = MemoryWriter.getMemoryWriter(address, digestLength, 1);

            for (int i = 0; i < size; i++)
            {
                memoryWriter.writeNext(digest[i] & 0xFF);
            }
            for (int i = size; i < digestLength; i++)
            {
                memoryWriter.writeNext(0);
            }
            memoryWriter.flush();

            if (log.TraceEnabled)
            {
                log.trace(string.Format("return MD5 digest: {0}", Utilities.getMemoryDump(address, digestLength)));
            }
        }
コード例 #23
0
        public static void call(int posPixelXreg, int maxPixelXreg, int windowsDataAddressReg, int addr1BaseReg, int addr1BaseXreg, int addr2BaseReg, int addr2BaseYreg, int addr3BaseReg)
        {
            Memory        mem                = Memory;
            int           posPixelX          = getRegisterValue(posPixelXreg);
            int           maxPixelX          = getRegisterValue(maxPixelXreg);
            int           startAddress1      = getRegisterValue(addr1BaseReg) + ((getRegisterValue(addr1BaseXreg) + posPixelX) << 1);
            int           windowsDataAddress = getRegisterValue(windowsDataAddressReg);
            int           startAddress2      = getRegisterValue(addr2BaseReg) + (((getRegisterValue(addr2BaseYreg) - mem.read16(74 + windowsDataAddress)) * mem.read16(84 + windowsDataAddress) + (posPixelX - mem.read16(72 + windowsDataAddress))) << 1);
            int           startAddress3      = getRegisterValue(addr3BaseReg) + (posPixelX << 1);
            IMemoryReader memoryReader1      = MemoryReader.getMemoryReader(startAddress1, 2);
            IMemoryReader memoryReader2      = MemoryReader.getMemoryReader(startAddress2, 2);
            IMemoryWriter memoryWriter       = MemoryWriter.getMemoryWriter(startAddress3, 2);

            for (int x = posPixelX; x <= maxPixelX; x++)
            {
                int color1 = memoryReader1.readNext();
                int color2 = memoryReader2.readNext();
                int r      = ((color1 >> 3) & 0x03) + (color2 & 0x1F);
                int g      = ((color1 >> 8) & 0x03) + ((color2 >> 5) & 0x1F);
                int b      = ((color1 >> 13) & 0x03) + ((color2 >> 10) & 0x1F);
                if (r > 0x1F)
                {
                    r = 0x1F;
                }
                if (g > 0x1F)
                {
                    g = 0x1F;
                }
                if (b > 0x1F)
                {
                    b = 0x1F;
                }
                int color = (b << 10) + (g << 5) + r + 0x8000;
                memoryWriter.writeNext(color);
            }
            memoryWriter.flush();
        }
コード例 #24
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);
        }
コード例 #25
0
        /// <summary>
        /// Set memory range to a fixed value </summary>
        /// <param name="dstAddrReg">	register number containing the start address </param>
        /// <param name="cReg">			register number containing the value </param>
        /// <param name="nStartReg">		register number giving the start value of the counter </param>
        /// <param name="nEndReg">		register number giving the end value of the counter </param>
        /// <param name="cLength">		2: take only the lower 16bit of the value
        ///                      4: take the 32bit of the value </param>
        public static void call(int dstAddrReg, int cReg, int nStartReg, int cLength, int nEndReg)
        {
            int dstAddr = getRegisterValue(dstAddrReg);
            int c       = getRegisterValue(cReg);
            int nStart  = getRegisterValue(nStartReg);
            int nEnd    = getRegisterValue(nEndReg);
            int n       = nEnd - nStart;

            if (n == 0)
            {
                return;
            }

            if (cLength == 2)
            {
                // Both bytes identical?
                if ((c & 0xFF) == ((c >> 8) & 0xFF))
                {
                    // This is equivalent to a normal memset
                    Memory.memsetWithVideoCheck(dstAddr, (sbyte)c, n * 2);
                }
                else
                {
                    // We have currently no built-in memset for 16bit values
                    // do it manually...
                    Memory mem     = Memory;
                    int    value32 = (c & 0xFFFF) | (c << 16);
                    short  value16 = unchecked ((short)(c & 0xFFFF));
                    if (n > 0 && (dstAddr & 3) != 0)
                    {
                        mem.write16(dstAddr, value16);
                        dstAddr += 2;
                        n--;
                    }
                    IMemoryWriter memoryWriter = MemoryWriter.getMemoryWriter(dstAddr, n * 2, 4);
                    for (int i = 0; i < n; i += 2, dstAddr += 4)
                    {
                        memoryWriter.writeNext(value32);
                    }
                    memoryWriter.flush();
                    if ((n & 1) != 0)
                    {
                        mem.write16(dstAddr, value16);
                    }
                }
            }
            else if (cLength == 4)
            {
                // All bytes identical?
                if ((c & 0xFF) == ((c >> 8) & 0xFF) && (c & 0xFFFF) == ((c >> 16) & 0xFFFF))
                {
                    // This is equivalent to a normal memset
                    Memory.memsetWithVideoCheck(dstAddr, (sbyte)c, n * 4);
                }
                else
                {
                    IMemoryWriter memoryWriter = MemoryWriter.getMemoryWriter(dstAddr, n * 4, 4);
                    for (int i = 0; i < n; i++)
                    {
                        memoryWriter.writeNext(c);
                    }
                    memoryWriter.flush();
                }
            }
            else
            {
                Compiler.Console.WriteLine("Memset.call: unsupported cLength=0x" + cLength.ToString("x"));
            }

            setRegisterValue(dstAddrReg, getRegisterValue(dstAddrReg) + n * cLength);
            setRegisterValue(nStartReg, nEnd);
        }
コード例 #26
0
        public override int ioIoctl(int command, TPointer inputPointer, int inputLength, TPointer outputPointer, int outputLength)
        {
            int result;

            switch (command)
            {
            // UMD file seek set.
            case 0x01010005:
            {
                if (inputPointer.AddressGood && inputLength >= 4)
                {
                    int offset = inputPointer.getValue32();
                    //if (log.DebugEnabled)
                    {
                        Console.WriteLine(string.Format("ioIoctl umd file seek set {0:D}", offset));
                    }
                    Position = offset;
                    result   = 0;
                }
                else
                {
                    result = ERROR_INVALID_ARGUMENT;
                }
                break;
            }

            // Get UMD Primary Volume Descriptor
            case 0x01020001:
            {
                if (outputPointer.AddressGood && outputLength == UmdIsoFile.sectorLength)
                {
                    try
                    {
                        sbyte[]       primaryVolumeSector = iso.readSector(UmdIsoReader.startSector);
                        IMemoryWriter memoryWriter        = MemoryWriter.getMemoryWriter(outputPointer.Address, outputLength, 1);
                        for (int i = 0; i < outputLength; i++)
                        {
                            memoryWriter.writeNext(primaryVolumeSector[i] & 0xFF);
                        }
                        memoryWriter.flush();
                        result = 0;
                    }
                    catch (IOException e)
                    {
                        Console.WriteLine("ioIoctl", e);
                        result = ERROR_KERNEL_FILE_READ_ERROR;
                    }
                }
                else
                {
                    result = ERROR_ERRNO_INVALID_ARGUMENT;
                }
                break;
            }

            // Get UMD Path Table
            case 0x01020002:
            {
                if (outputPointer.AddressGood && outputLength <= UmdIsoFile.sectorLength)
                {
                    try
                    {
                        sbyte[]    primaryVolumeSector = iso.readSector(UmdIsoReader.startSector);
                        ByteBuffer primaryVolume       = ByteBuffer.wrap(primaryVolumeSector);
                        primaryVolume.position(140);
                        int           pathTableLocation = Utilities.readWord(primaryVolume);
                        sbyte[]       pathTableSector   = iso.readSector(pathTableLocation);
                        IMemoryWriter memoryWriter      = MemoryWriter.getMemoryWriter(outputPointer.Address, outputLength, 1);
                        for (int i = 0; i < outputLength; i++)
                        {
                            memoryWriter.writeNext(pathTableSector[i] & 0xFF);
                        }
                        memoryWriter.flush();
                        result = 0;
                    }
                    catch (IOException e)
                    {
                        Console.WriteLine("ioIoctl", e);
                        result = ERROR_KERNEL_FILE_READ_ERROR;
                    }
                }
                else
                {
                    result = ERROR_ERRNO_INVALID_ARGUMENT;
                }
                break;
            }

            // Get Sector size
            case 0x01020003:
            {
                if (outputPointer.AddressGood && outputLength == 4)
                {
                    outputPointer.setValue32(UmdIsoFile.sectorLength);
                    result = 0;
                }
                else
                {
                    result = ERROR_ERRNO_INVALID_ARGUMENT;
                }
                break;
            }

            // Get UMD file pointer.
            case 0x01020004:
            {
                if (outputPointer.AddressGood && outputLength >= 4)
                {
                    try
                    {
                        int fPointer = (int)file.FilePointer;
                        outputPointer.setValue32(fPointer);
                        //if (log.DebugEnabled)
                        {
                            Console.WriteLine(string.Format("ioIoctl umd file get file pointer {0:D}", fPointer));
                        }
                        result = 0;
                    }
                    catch (IOException e)
                    {
                        Console.WriteLine("ioIoctl", e);
                        result = ERROR_KERNEL_FILE_READ_ERROR;
                    }
                }
                else
                {
                    result = ERROR_INVALID_ARGUMENT;
                }
                break;
            }

            // Get UMD file start sector.
            case 0x01020006:
            {
                if (outputPointer.AddressGood && outputLength >= 4)
                {
                    int startSector = 0;
                    startSector = file.StartSector;
                    //if (log.DebugEnabled)
                    {
                        Console.WriteLine(string.Format("ioIoctl umd file get start sector {0:D}", startSector));
                    }
                    outputPointer.setValue32(startSector);
                    result = 0;
                }
                else
                {
                    result = ERROR_INVALID_ARGUMENT;
                }
                break;
            }

            // Get UMD file Length in bytes.
            case 0x01020007:
            {
                if (outputPointer.AddressGood && outputLength >= 8)
                {
                    long Length = this.Length();
                    outputPointer.Value64 = Length;
                    //if (log.DebugEnabled)
                    {
                        Console.WriteLine(string.Format("ioIoctl get file size {0:D}", Length));
                    }
                    result = 0;
                }
                else
                {
                    result = ERROR_INVALID_ARGUMENT;
                }
                break;
            }

            // Read UMD file.
            case 0x01030008:
            {
                if (inputPointer.AddressGood && inputLength >= 4)
                {
                    int Length = inputPointer.getValue32();
                    if (Length > 0)
                    {
                        if (outputPointer.AddressGood && outputLength >= Length)
                        {
                            try
                            {
                                Utilities.readFully(file, outputPointer.Address, Length);
                                Position = Position + Length;
                                result   = Length;
                            }
                            catch (IOException e)
                            {
                                Console.WriteLine("ioIoctl", e);
                                result = ERROR_KERNEL_FILE_READ_ERROR;
                            }
                        }
                        else
                        {
                            result = ERROR_INVALID_ARGUMENT;
                        }
                    }
                    else
                    {
                        result = ERROR_INVALID_ARGUMENT;
                    }
                }
                else
                {
                    result = ERROR_INVALID_ARGUMENT;
                }
                break;
            }

            // UMD disc read sectors operation.
            case 0x01F30003:
            {
                if (inputPointer.AddressGood && inputLength >= 4)
                {
                    int numberOfSectors = inputPointer.getValue32();
                    if (numberOfSectors > 0)
                    {
                        if (outputPointer.AddressGood && outputLength >= numberOfSectors)
                        {
                            try
                            {
                                int Length = numberOfSectors * UmdIsoFile.sectorLength;
                                Utilities.readFully(file, outputPointer.Address, Length);
                                Position = Position + Length;
                                result   = Length / UmdIsoFile.sectorLength;
                            }
                            catch (IOException e)
                            {
                                Console.WriteLine("ioIoctl", e);
                                result = ERROR_KERNEL_FILE_READ_ERROR;
                            }
                        }
                        else
                        {
                            result = ERROR_ERRNO_INVALID_ARGUMENT;
                        }
                    }
                    else
                    {
                        result = ERROR_ERRNO_INVALID_ARGUMENT;
                    }
                }
                else
                {
                    result = ERROR_ERRNO_INVALID_ARGUMENT;
                }
                break;
            }

            // UMD file seek whence.
            case 0x01F100A6:
            {
                if (inputPointer.AddressGood && inputLength >= 16)
                {
                    long offset = inputPointer.getValue64(0);
                    int  whence = inputPointer.getValue32(12);
                    if (SectorBlockMode)
                    {
                        offset *= UmdIsoFile.sectorLength;
                    }
                    //if (log.DebugEnabled)
                    {
                        Console.WriteLine(string.Format("ioIoctl UMD file seek offset {0:D}, whence {1:D}", offset, whence));
                    }
                    switch (whence)
                    {
                    case PSP_SEEK_SET:
                        Position = offset;
                        result   = 0;
                        break;

                    case PSP_SEEK_CUR:
                        Position = Position + offset;
                        result   = 0;
                        break;

                    case PSP_SEEK_END:
                        Position = Length() + offset;
                        result   = 0;
                        break;

                    default:
                        Console.WriteLine(string.Format("ioIoctl - unhandled whence {0:D}", whence));
                        result = ERROR_INVALID_ARGUMENT;
                        break;
                    }
                }
                else
                {
                    result = ERROR_INVALID_ARGUMENT;
                }
                break;
            }

            default:
                result = base.ioIoctl(command, inputPointer, inputLength, outputPointer, outputLength);
                break;
            }

            return(result);
        }
コード例 #27
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();
        }
コード例 #28
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();
        }
コード例 #29
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();
        }
コード例 #30
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);
            }
        }