diff --git a/EightBit/Bus.cs b/EightBit/Bus.cs index ca877fe..6701b3b 100644 --- a/EightBit/Bus.cs +++ b/EightBit/Bus.cs @@ -5,8 +5,6 @@ namespace EightBit { using System; - using System.Collections.Generic; - using System.IO; public abstract class Bus : IMapper { @@ -140,7 +138,7 @@ namespace EightBit var content = chunk.Item2; var mapped = this.Mapping(address); var offset = address - mapped.Begin; - mapped.Memory.Load(content.ToArray(), offset); + mapped.Memory.Load(content, offset); } } } diff --git a/EightBit/IntelHexFile.cs b/EightBit/IntelHexFile.cs index 104a516..a475b58 100644 --- a/EightBit/IntelHexFile.cs +++ b/EightBit/IntelHexFile.cs @@ -34,7 +34,7 @@ namespace EightBit } } - public IEnumerable>> Parse() + public IEnumerable> Parse() { var eof = false; while (!this.reader.EndOfStream && !eof) @@ -49,7 +49,7 @@ namespace EightBit } } - private Tuple> Parse(string line) + private Tuple Parse(string line) { var colon = line.Substring(0, 1); if (colon != ":") @@ -69,24 +69,7 @@ namespace EightBit switch (recordType) { case 0x00: - { - var data = new List(count); - var requiredLength = 9 + 2 + (count * 2); - if (line.Length != requiredLength) - { - throw new InvalidOperationException("Invalid hex file: line is not the required length"); - } - - for (var i = 0; i < count; ++i) - { - var position = 9 + (i * 2); - var datumString = line.Substring(position, 2); - var datum = Convert.ToByte(datumString, 16); - data.Add(datum); - } - - return new Tuple>(address, data); - } + return ParseDataRecord(line, address, count); case 0x01: return null; @@ -95,5 +78,24 @@ namespace EightBit throw new InvalidOperationException("Unhandled hex file record."); } } + + private static Tuple ParseDataRecord(string line, ushort address, byte count) + { + var data = new byte[count]; + var requiredLength = 9 + 2 + (count * 2); + if (line.Length != requiredLength) + { + throw new InvalidOperationException("Invalid hex file: line is not the required length"); + } + + for (var i = 0; i < count; ++i) + { + var position = 9 + (i * 2); + var datumString = line.Substring(position, 2); + data[i] = Convert.ToByte(datumString, 16); + } + + return new Tuple(address, data); + } } }