Esempio n. 1
0
        public virtual int sceSha256Digest(TPointer data, int Length, TPointer digest)
        {
            if (log.TraceEnabled)
            {
                log.trace(string.Format("sceSha256Digest data:{0}", Utilities.getMemoryDump(data.Address, Length)));
            }

            // Read in the source data.
            sbyte[]       b            = new sbyte[Length];
            IMemoryReader memoryReader = MemoryReader.getMemoryReader(data.Address, Length, 1);

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

            // Calculate SHA-256.
            SHA256 sha256 = new SHA256();

            sbyte[] d = sha256.doSHA256(b, Length);

            // Write back the resulting digest.
            IMemoryWriter memoryWriter = MemoryWriter.getMemoryWriter(digest.Address, 0x20, 1);

            for (int i = 0; i < 0x20; i++)
            {
                memoryWriter.writeNext((sbyte)d[i]);
            }

            return(0);
        }
Esempio n. 2
0
        public virtual int sceAdler32(int adler, TPointer data, int Length)
        {
            if (log.TraceEnabled)
            {
                log.trace(string.Format("sceAdler32 data:{0}", Utilities.getMemoryDump(data.Address, Length)));
            }

            sbyte[]       b            = new sbyte[Length];
            IMemoryReader memoryReader = MemoryReader.getMemoryReader(data.Address, Length, 1);

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

            adler32.reset();
            adler32.update(adler);
            adler32.update(b);
            int result = (int)adler32.Value;

            //if (log.DebugEnabled)
            {
                Console.WriteLine(string.Format("sceAdler32 returning 0x{0:X8}", result));
            }

            return(result);
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        public static void call()
        {
            int srcAddr = GprA0;
            int c1      = GprA1 & 0xFF;
            int result  = 0;

            IMemoryReader memoryReader = MemoryReader.getMemoryReader(srcAddr, 1);

            if (memoryReader != null)
            {
                for (int i = 0; true; i++)
                {
                    int c2 = memoryReader.readNext();
                    if (c1 == c2)
                    {
                        // Character found
                        result = srcAddr + i;
                    }
                    else if (c2 == 0)
                    {
                        // End of Src string found
                        break;
                    }
                }
            }

            GprV0 = result;
        }
Esempio n. 5
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. 6
0
        public static void call()
        {
            int src1Addr = GprA0;
            int src2Addr = GprA1;
            int n        = GprA2;

            if (n > 0)
            {
                IMemoryReader memoryReader1 = MemoryReader.getMemoryReader(src1Addr, n, 1);
                IMemoryReader memoryReader2 = MemoryReader.getMemoryReader(src2Addr, n, 1);

                if (memoryReader1 != null && memoryReader2 != null)
                {
                    for (int i = 0; i < n; i++)
                    {
                        int c1 = toLowerCase[memoryReader1.readNext()];
                        int c2 = toLowerCase[memoryReader2.readNext()];
                        if (c1 != c2)
                        {
                            GprV0 = c1 - c2;
                            return;
                        }
                        else if (c1 == 0)
                        {
                            // c1 == 0 and c2 == 0
                            break;
                        }
                    }
                }
            }

            GprV0 = 0;
        }
Esempio n. 7
0
        public static void call()
        {
            int src1Addr = GprA0;
            int src2Addr = GprA1;
            int n        = GprA2;

            if (log.TraceEnabled)
            {
                log.trace(string.Format("memcmp src1={0}, src2={1}, n=0x{2:X}", Utilities.getMemoryDump(src1Addr, n), Utilities.getMemoryDump(src2Addr, n), n));
            }
            IMemoryReader memoryReader1 = MemoryReader.getMemoryReader(src1Addr, n, 1);
            IMemoryReader memoryReader2 = MemoryReader.getMemoryReader(src2Addr, n, 1);

            for (int i = 0; i < n; i++)
            {
                int c1 = memoryReader1.readNext();
                int c2 = memoryReader2.readNext();
                if (c1 != c2)
                {
                    GprV0 = c1 - c2;
                    return;
                }
            }

            GprV0 = 0;
        }
Esempio n. 8
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();
            }
        }
Esempio n. 9
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. 10
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();
        }
Esempio n. 11
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();
        }
Esempio n. 12
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void write(java.io.OutputStream out) throws java.io.IOException
        public virtual void write(System.IO.Stream @out)
        {
            DataOutputStream data = new DataOutputStream(@out);

            data.writeInt(packetSize);
            data.writeInt(address);
            data.writeInt(Length);

            if (buffer is ByteBuffer)
            {
                WritableByteChannel channel = Channels.newChannel(@out);
                channel.write((ByteBuffer)buffer);
            }
            else
            {
                IMemoryReader reader = MemoryReader.getMemoryReader(address, Length, 1);
                for (int i = 0; i < Length; i++)
                {
                    data.writeByte(reader.readNext());
                }
            }

            VideoEngine.log_Renamed.info(string.Format("Saved memory {0:x8} - {1:x8} (len {2:x8})", address, address + Length, Length));
            //VideoEngine.Console.WriteLine("CaptureRAM write " + ((3 * 4) + Length));

            //data.flush();
            //out.flush();
        }
Esempio n. 13
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();
        }
Esempio n. 14
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. 15
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: protected void write(pspsharp.state.StateOutputStream stream, int address, int Length) throws java.io.IOException
        protected internal virtual void write(StateOutputStream stream, int address, int Length)
        {
            IMemoryReader memoryReader = MemoryReader.getMemoryReader(this, address, Length, 4);

            for (int i = 0; i < Length; i += 4)
            {
                stream.writeInt(memoryReader.readNext());
            }
        }
Esempio n. 16
0
        public override int ioDevctl(string deviceName, int command, TPointer inputPointer, int inputLength, TPointer outputPointer, int outputLength)
        {
            switch (command)
            {
            case EMULATOR_DEVCTL_GET_HAS_DISPLAY:
                if (!outputPointer.AddressGood || outputLength < 4)
                {
                    return(base.ioDevctl(deviceName, command, inputPointer, inputLength, outputPointer, outputLength));
                }
                outputPointer.setValue32(Screen.hasScreen());
                break;

            case EMULATOR_DEVCTL_SEND_OUTPUT:
                sbyte[]       input        = new sbyte[inputLength];
                IMemoryReader memoryReader = MemoryReader.getMemoryReader(inputPointer.Address, inputLength, 1);
                for (int i = 0; i < inputLength; i++)
                {
                    input[i] = (sbyte)memoryReader.readNext();
                }
                string outputString = StringHelper.NewString(input);
                //if (log.DebugEnabled)
                {
                    Console.WriteLine(outputString);
                }
                AutoTestsOutput.appendString(outputString);
                break;

            case EMULATOR_DEVCTL_IS_EMULATOR:
                break;

            case EMULATOR_DEVCTL_EMIT_SCREENSHOT:
                BufferInfo   fb           = Modules.sceDisplayModule.BufferInfoFb;
                Buffer       buffer       = Memory.Instance.getBuffer(fb.topAddr, fb.bufferWidth * fb.height * getPixelFormatBytes(fb.pixelFormat));
                CaptureImage captureImage = new CaptureImage(fb.topAddr, 0, buffer, fb.width, fb.height, fb.bufferWidth, fb.pixelFormat, false, 0, false, true, null);
                captureImage.FileName   = ScreenshotFileName;
                captureImage.FileFormat = ScreenshotFormat;
                try
                {
                    captureImage.write();
                    //if (log.DebugEnabled)
                    {
                        Console.WriteLine(string.Format("Screenshot 0x{0:X8}-0x{1:X8} saved under '{2}'", fb.topAddr, fb.bottomAddr, captureImage.FileName));
                    }
                }
                catch (IOException e)
                {
                    Console.WriteLine("Emit Screenshot", e);
                }
                break;

            default:
                // Unknown command
                return(base.ioDevctl(deviceName, command, inputPointer, inputLength, outputPointer, outputLength));
            }

            return(0);
        }
Esempio n. 17
0
        /// <summary>
        /// Generate a hashCode on a memory range using a rather simple but fast method.
        /// The hashCode will be independent of the address, i.e. the same hashCode will
        /// be generated for the same data at different memory addresses.
        /// </summary>
        /// <param name="hashCode">		current hashCode value </param>
        /// <param name="memoryReader">	the memory reader for the values to be hashed </param>
        /// <param name="lengthInBytes">	Length of the memory range </param>
        /// <returns> updated hashCode value </returns>
        public static int getHashCodeFloatingMemory(int hashCode, IMemoryReader memoryReader, int lengthInBytes)
        {
            for (int i = 0; i < lengthInBytes; i += 4)
            {
                int value = memoryReader.readNext();
                hashCode ^= value + i;
                hashCode += i;
            }

            return(hashCode);
        }
Esempio n. 18
0
        private static int sceGuSetMatrix4x4(IMemoryWriter listWriter, IMemoryReader matrixReader, int startCmd, int matrixCmd, int index)
        {
            listWriter.writeNext((startCmd << 24) + index);
            int cmd = matrixCmd << 24;

            for (int i = 0; i < 16; i++)
            {
                listWriter.writeNext(cmd | ((int)((uint)matrixReader.readNext() >> 8)));
            }
            return(68);
        }
Esempio n. 19
0
        protected internal static sbyte[] getMemoryBytes(int address, int size)
        {
            sbyte[]       bytes        = new sbyte[size];
            IMemoryReader memoryReader = MemoryReader.getMemoryReader(address, size, 1);

            for (int i = 0; i < size; i++)
            {
                bytes[i] = (sbyte)memoryReader.readNext();
            }

            return(bytes);
        }
Esempio n. 20
0
        protected internal static int doAudioOutput(SoundChannel channel, int pvoid_buf)
        {
            int ret = -1;

            if (channel.Reserved)
            {
                //if (log.DebugEnabled)
                {
                    Console.WriteLine(string.Format("doAudioOutput({0}, 0x{1:X8})", channel.ToString(), pvoid_buf));
                }
                int     bytesPerSample = channel.FormatStereo ? 4 : 2;
                int     nbytes         = bytesPerSample * channel.SampleLength;
                sbyte[] data           = new sbyte[nbytes];

                IMemoryReader memoryReader = MemoryReader.getMemoryReader(pvoid_buf, nbytes, 2);
                if (channel.FormatMono)
                {
                    int volume = Audio.getVolume(channel.LeftVolume);
                    for (int i = 0; i < nbytes; i += 2)
                    {
                        short sample = (short)memoryReader.readNext();

                        sample = SoundChannel.adjustSample(sample, volume);

                        SoundChannel.storeSample(sample, data, i);
                    }
                }
                else
                {
                    int leftVolume  = Audio.getVolume(channel.LeftVolume);
                    int rightVolume = Audio.getVolume(channel.RightVolume);
                    for (int i = 0; i < nbytes; i += 4)
                    {
                        short lsample = (short)memoryReader.readNext();
                        short rsample = (short)memoryReader.readNext();

                        lsample = SoundChannel.adjustSample(lsample, leftVolume);
                        rsample = SoundChannel.adjustSample(rsample, rightVolume);

                        SoundChannel.storeSample(lsample, data, i);
                        SoundChannel.storeSample(rsample, data, i + 2);
                    }
                }
                Modules.sceAudioModule.audioData = data;
                channel.play(data);
                ret = channel.SampleLength;
            }
            else
            {
                Console.WriteLine("doAudioOutput: channel " + channel.Index + " not reserved");
            }
            return(ret);
        }
Esempio n. 21
0
        /// <summary>
        /// Generate a hashCode on a memory range using a rather simple but fast method.
        /// </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>
        /// <returns> updated hashCode value </returns>
        public static int getHashCode(int hashCode, int addr, int lengthInBytes)
        {
            IMemoryReader memoryReader = MemoryReader.getMemoryReader(addr, lengthInBytes, 4);

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

            return(hashCode);
        }
Esempio n. 22
0
        public sbyte[] getArray8(int offset, sbyte[] bytes, int bytesOffset, int n)
        {
            if (NotNull)
            {
                IMemoryReader memoryReader = MemoryReader.getMemoryReader(Memory, Address + offset, n, 1);
                for (int i = 0; i < n; i++)
                {
                    bytes[bytesOffset + i] = (sbyte)memoryReader.readNext();
                }
            }

            return(bytes);
        }
Esempio n. 23
0
        private static int getListSize(int listAddr)
        {
            IMemoryReader memoryReader = MemoryReader.getMemoryReader(listAddr, 4);

            for (int i = 1; true; i++)
            {
                int instruction = memoryReader.readNext();
                int cmd         = VideoEngine.command(instruction);
                if (cmd == GeCommands.RET)
                {
                    return(i);
                }
            }
        }
Esempio n. 24
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. 25
0
        public RandomTextureAccessReader(IMemoryReader imageReader, int width, int height)
        {
            this.width  = width;
            this.height = height;
            // Read the whole texture into the "pixels" array
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'sealed override':
//ORIGINAL LINE: sealed override int Length = width * height;
            int Length = width * height;

            pixels = new int[Length];
            for (int i = 0; i < Length; i++)
            {
                pixels[i] = imageReader.readNext();
            }
        }
Esempio n. 26
0
        /// <summary>
        /// Generate a hashCode on a memory range using a more complex but slower method.
        /// </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>
        /// <returns> updated hashCode value </returns>
        public static int getHashCodeComplex(int hashCode, int addr, int lengthInBytes)
        {
            IMemoryReader memoryReader = MemoryReader.getMemoryReader(addr, lengthInBytes, 4);
            int           n            = lengthInBytes / 4;

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

            return(hashCode);
        }
Esempio n. 27
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);
        }
Esempio n. 28
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);
        }
Esempio n. 29
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();
        }
Esempio n. 30
0
        public static void call(int src1AddrReg, int src2AddrReg, int n, int resultReg, int equalValue, int notEqualValue)
        {
            int src1Addr = getRegisterValue(src1AddrReg);
            int src2Addr = getRegisterValue(src2AddrReg);

            IMemoryReader memoryReader1 = MemoryReader.getMemoryReader(src1Addr, n, 4);
            IMemoryReader memoryReader2 = MemoryReader.getMemoryReader(src2Addr, n, 4);

            for (int i = 0; i < n; i += 4)
            {
                int value1 = memoryReader1.readNext();
                int value2 = memoryReader2.readNext();
                if (value1 != value2)
                {
                    setRegisterValue(resultReg, notEqualValue);
                    return;
                }
            }

            setRegisterValue(resultReg, equalValue);
        }