Esempio n. 1
0
            // TODO: Switch to builder pattern.
            public void Register(ushort address, IMemorySource source)
            {
                Asserts.True(source.Size > 0,
                             $"Source at {ByteFormatter.ToHex16(address)} is empty!");
                Asserts.True(address + source.Size <= this.Size,
                             $"Source at {ByteFormatter.ToHex16(address)} hangs off right end of mapper!");
                Asserts.True(address + source.Size <= this.Size,
                             $"Source at {ByteFormatter.ToHex16(address)} hangs off right end of mapper!");

                var newStartAddress = address;
                var newEndAddress   = newStartAddress + (source.Size - 1);

                foreach (var existingKvp in this.sourcesBuilder_)
                {
                    var existingStartAddress = existingKvp.Key;
                    var existingEndAddress   =
                        existingStartAddress + (existingKvp.Value.Size - 1);
                    if (newStartAddress <= existingEndAddress &&
                        newEndAddress >= existingStartAddress)
                    {
                        Assert.Fail(
                            $"New source at {ByteFormatter.ToHex16(address)} intersects with old source!");
                    }
                }

                this.sourcesBuilder_.Add(address,
                                         new MemoryMapperSource(address, source));
            }
Esempio n. 2
0
 public IMemoryMapperBuilder Register(
     ushort address,
     IMemorySource source)
 {
     this.impl_.Register(address, source);
     return(this);
 }
Esempio n. 3
0
        /// <summary>
        /// Updates the values displayed to match the memory source.
        /// </summary>
        /// <param name="source">Memory where values are read from.</param>
        /// <param name="address">Initial address in memory to read from.</param>
        private void UpdateValues(IMemorySource source, QualifiedAddress address)
        {
            var buffer = new byte[this.rows.Count * 16];

            source.ReadBytes(buffer, 0, address, buffer.Length);
            var textBuffer = new StringBuilder(16);

            for (int i = 0; i < rows.Count; i++)
            {
                textBuffer.Length    = 0;
                rows[i].Address.Text = (address + (i * 16)).ToString();
                for (int c = 0; c < 16; c++)
                {
                    byte b = buffer[(i * 16) + c];
                    rows[i].HexValues[c].Text = b.ToString("X2");

                    if (b == '\n' || b == '\r' || b == '\t')
                    {
                        textBuffer.Append(' ');
                    }
                    else if (b < '!')
                    {
                        textBuffer.Append('.');
                    }
                    else
                    {
                        textBuffer.Append((char)b);
                    }
                }

                rows[i].ByteValues.Text = textBuffer.ToString();
            }
        }
Esempio n. 4
0
 public MemoryMapperSource(ushort address, IMemorySource impl)
 {
     this.Address = address;
     this.impl_   = impl;
 }