示例#1
0
        public override void copyToMemory(int address, ByteBuffer source, int Length)
        {
            // copy in 1 byte steps until address is "int"-aligned
            while (!isIntAligned(address) && Length > 0 && source.hasRemaining())
            {
                sbyte b = source.get();
                write8(address, b);
                address++;
                Length--;
            }

            // copy 1 int at each loop
            int           countInt     = System.Math.Min(Length, source.remaining()) >> 2;
            IMemoryWriter memoryWriter = MemoryWriter.getMemoryWriter(address, countInt << 2, 4);

            for (int i = 0; i < countInt; i++)
            {
                int data1 = source.get() & 0xFF;
                int data2 = source.get() & 0xFF;
                int data3 = source.get() & 0xFF;
                int data4 = source.get() & 0xFF;
                int data  = (data4 << 24) | (data3 << 16) | (data2 << 8) | data1;
                memoryWriter.writeNext(data);
            }
            memoryWriter.flush();
            int copyLength = countInt << 2;

            Length  -= copyLength;
            address += copyLength;

            // copy rest Length in 1 byte steps (rest Length <= 3)
            while (Length > 0 && source.hasRemaining())
            {
                sbyte b = source.get();
                write8(address, b);
                address++;
                Length--;
            }
        }
示例#2
0
        protected internal override void memcpy(int destination, int source, int Length, bool checkOverlap)
        {
            if (Length <= 0)
            {
                return;
            }

            destination = normalizeAddress(destination);
            source      = normalizeAddress(source);

            Modules.sceDisplayModule.write(destination);

            if (isIntAligned(source) && isIntAligned(destination) && isIntAligned(Length))
            {
                // Source, destination and Length are "int"-aligned
                memcpyAligned4(destination, source, Length, checkOverlap);
            }
            else if ((source & 0x03) == (destination & 0x03) && (!checkOverlap || !areOverlapping(destination, source, Length)))
            {
                // Source and destination have the same alignment and are not overlapping
                while (!isIntAligned(source) && Length > 0)
                {
                    write8(destination, (sbyte)read8(source));
                    source++;
                    destination++;
                    Length--;
                }

                int length4 = Length & ~0x03;
                if (length4 > 0)
                {
                    memcpyAligned4(destination, source, length4, checkOverlap);
                    source      += length4;
                    destination += length4;
                    Length      -= length4;
                }

                while (Length > 0)
                {
                    write8(destination, (sbyte)read8(source));
                    destination++;
                    source++;
                    Length--;
                }
            }
            else
            {
                //
                // Buffers are not "int"-aligned, copy in 1 byte steps.
                // Overlapping address ranges must be correctly handled:
                //   If source >= destination:
                //                 [---source---]
                //       [---destination---]
                //      => Copy from the head
                //   If source < destination:
                //       [---source---]
                //                 [---destination---]
                //      => Copy from the tail
                //
                if (!checkOverlap || source >= destination || !areOverlapping(destination, source, Length))
                {
                    if (areOverlapping(destination, source, 4))
                    {
                        // Cannot use MemoryReader if source and destination are overlapping in less than 4 bytes
                        for (int i = 0; i < Length; i++)
                        {
                            write8(destination + i, (sbyte)read8(source + i));
                        }
                    }
                    else
                    {
                        IMemoryReader sourceReader      = MemoryReader.getMemoryReader(source, Length, 1);
                        IMemoryWriter destinationWriter = MemoryWriter.getMemoryWriter(destination, Length, 1);
                        for (int i = 0; i < Length; i++)
                        {
                            destinationWriter.writeNext(sourceReader.readNext());
                        }
                        destinationWriter.flush();
                    }
                }
                else
                {
                    for (int i = Length - 1; i >= 0; i--)
                    {
                        write8(destination + i, (sbyte)read8(source + i));
                    }
                }
            }
        }
示例#3
0
 public MemoryReaderWriterGeneric(int address, int step)
 {
     memoryReader = MemoryReader.getMemoryReader(address, step);
     memoryWriter = MemoryWriter.getMemoryWriter(address, step);
     currentValue = memoryReader.readNext();
 }