Exemplo n.º 1
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();
        }
Exemplo n.º 2
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();
            }
        }
Exemplo n.º 3
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();
        }
Exemplo n.º 4
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();
            }
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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();
        }
Exemplo n.º 8
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;
        }
Exemplo n.º 9
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;
        }
Exemplo n.º 10
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();
        }
Exemplo n.º 11
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();
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
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;
        }
Exemplo n.º 14
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());
            }
        }
Exemplo n.º 15
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);
        }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
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);
        }
Exemplo n.º 18
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);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Synthesizing audio function with mix. </summary>
        /// <param name="addr"> Input and output address for the PCM data (must be 64-byte aligned). </param>
        /// <param name="samples"> Number of samples returned. </param>
        /// <param name="leftVol"> the volume of the left channel for modulating the input PCM data.
        ///                This volume is not affecting the currently played samples. </param>
        /// <param name="rightVol"> the volume of the right channel for modulating the input PCM data.
        ///                 This volume is not affecting the currently played samples. </param>
        public virtual void synthesizeWithMix(int addr, int samples, int leftVol, int rightVol)
        {
            int[] mixedSamples = new int[samples * 2];

            // Read the input buffer into mixedSamples.
            // Check first for simple cases...
            if (leftVol == 0 && rightVol == 0)
            {
                // Do not mix with the input buffer
                Arrays.Fill(mixedSamples, 0);
            }
            else if (leftVol == MAX_VOLUME && rightVol == MAX_VOLUME)
            {
                // Mix with the input buffer with no volume change
                int           lengthInBytes = mixedSamples.Length * 2;
                IMemoryReader memoryReader  = MemoryReader.getMemoryReader(addr, lengthInBytes, 2);
                for (int i = 0; i < mixedSamples.Length; i++)
                {
                    mixedSamples[i] = (short)memoryReader.readNext();
                }
            }
            else
            {
                // Mix with the input buffer with a volume adjustment
                int           lengthInBytes = mixedSamples.Length * 2;
                IMemoryReader memoryReader  = MemoryReader.getMemoryReader(addr, lengthInBytes, 2);
                for (int i = 0; i < samples; i++)
                {
                    short sampleLeft  = (short)memoryReader.readNext();
                    short sampleRight = (short)memoryReader.readNext();
                    sampleLeft              = SoundChannel.adjustSample(sampleLeft, leftVol);
                    sampleRight             = SoundChannel.adjustSample(sampleRight, rightVol);
                    mixedSamples[i * 2]     = sampleLeft;
                    mixedSamples[i * 2 + 1] = sampleRight;
                }
            }

            mix(mixedSamples, addr, samples, MAX_VOLUME, MAX_VOLUME, false);
        }
Exemplo n.º 20
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);
        }
Exemplo n.º 21
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);
        }
Exemplo n.º 22
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);
                }
            }
        }
Exemplo n.º 23
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);
        }
Exemplo n.º 24
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();
            }
        }
Exemplo n.º 25
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);
        }
Exemplo n.º 26
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);
        }
Exemplo n.º 27
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();
        }
Exemplo n.º 28
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);
        }
Exemplo n.º 29
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);
        }
Exemplo n.º 30
0
        public static int strcmp(int src1Addr, int src2Addr)
        {
            if (src1Addr == 0)
            {
                if (src2Addr == 0)
                {
                    return(0);
                }
                return(-1);
            }

            if (src2Addr == 0)
            {
                return(1);
            }

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

            if (memoryReader1 != null && memoryReader2 != null)
            {
                while (true)
                {
                    int c1 = memoryReader1.readNext();
                    int c2 = memoryReader2.readNext();
                    if (c1 != c2)
                    {
                        return(c1 > c2 ? 1 : -1);
                    }
                    else if (c1 == 0)
                    {
                        // c1 == 0 and c2 == 0
                        break;
                    }
                }
            }

            return(0);
        }