Пример #1
0
        /// <summary>
        /// Writes the values of the memory control block to emulated memory.
        /// </summary>
        /// <param name="memory">Emulated memory where block will be written.</param>
        public void Write(PhysicalMemory memory)
        {
            memory.SetByte(this.Segment, 0, this.IsLast ? (byte)0x5A : (byte)0x4D);
            memory.SetUInt16(this.Segment, 1, this.PspSegment);
            memory.SetUInt16(this.Segment, 3, this.Length);

            // These are just to clear the name area to make sure it is padded with nulls.
            memory.SetUInt32(this.Segment, 8, 0);
            memory.SetUInt32(this.Segment, 12, 0);

            memory.SetString(this.Segment, 8, this.ImageName, false);
        }
Пример #2
0
        public static byte ConvToConv(PhysicalMemory memory, uint sourceAddress, uint destAddress, int length)
        {
            if (length < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(length));
            }
            if (length == 0)
            {
                return(0);
            }

            if (sourceAddress + length > PhysicalMemory.ConvMemorySize || destAddress + length > PhysicalMemory.ConvMemorySize)
            {
                return(0xA2);
            }

            bool overlap = (sourceAddress + length - 1 >= destAddress || destAddress + length - 1 >= sourceAddress);
            bool reverse = overlap && sourceAddress > destAddress;

            if (!reverse)
            {
                for (uint offset = 0; offset < length; offset++)
                {
                    memory.SetByte(destAddress + offset, memory.GetByte(sourceAddress + offset));
                }
            }
            else
            {
                for (int offset = length - 1; offset >= 0; offset--)
                {
                    memory.SetByte(destAddress + (uint)offset, memory.GetByte(sourceAddress + (uint)offset));
                }
            }

            return(overlap ? (byte)0x92 : (byte)0);
        }
Пример #3
0
        public static byte EmsToConv(EmsHandle sourceHandle, int sourcePage, int sourcePageOffset, PhysicalMemory memory, uint destAddress, int length)
        {
            if (length < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(length));
            }
            if (length == 0)
            {
                return(0);
            }

            if (destAddress + length > PhysicalMemory.ConvMemorySize)
            {
                return(0xA2);
            }
            if (sourcePageOffset >= ExpandedMemoryManager.PageSize)
            {
                return(0x95);
            }

            int  offset      = sourcePageOffset;
            uint sourceCount = destAddress;
            int  pageIndex   = sourcePage;

            while (length > 0)
            {
                int    size   = Math.Min(length, ExpandedMemoryManager.PageSize - offset);
                byte[] source = sourceHandle.GetLogicalPage(pageIndex);
                if (source == null)
                {
                    return(0x8A);
                }

                for (int i = 0; i < size; i++)
                {
                    memory.SetByte(sourceCount++, source[offset + i]);
                }

                length -= size;
                pageIndex++;
                offset = 0;
            }

            return(0);
        }