mirror of
https://github.com/MoleskiCoder/EightBitNet.git
synced 2025-08-15 11:27:27 +00:00
Further refactoring of the hex loader class to be a little easier to read.
Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -34,7 +34,7 @@ namespace EightBit
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Tuple<ushort, List<byte>>> Parse()
|
||||
public IEnumerable<Tuple<ushort, byte[]>> Parse()
|
||||
{
|
||||
var eof = false;
|
||||
while (!this.reader.EndOfStream && !eof)
|
||||
@@ -49,7 +49,7 @@ namespace EightBit
|
||||
}
|
||||
}
|
||||
|
||||
private Tuple<ushort, List<byte>> Parse(string line)
|
||||
private Tuple<ushort, byte[]> Parse(string line)
|
||||
{
|
||||
var colon = line.Substring(0, 1);
|
||||
if (colon != ":")
|
||||
@@ -69,8 +69,19 @@ namespace EightBit
|
||||
switch (recordType)
|
||||
{
|
||||
case 0x00:
|
||||
return ParseDataRecord(line, address, count);
|
||||
|
||||
case 0x01:
|
||||
return null;
|
||||
|
||||
default:
|
||||
throw new InvalidOperationException("Unhandled hex file record.");
|
||||
}
|
||||
}
|
||||
|
||||
private static Tuple<ushort, byte[]> ParseDataRecord(string line, ushort address, byte count)
|
||||
{
|
||||
var data = new List<byte>(count);
|
||||
var data = new byte[count];
|
||||
var requiredLength = 9 + 2 + (count * 2);
|
||||
if (line.Length != requiredLength)
|
||||
{
|
||||
@@ -81,19 +92,10 @@ namespace EightBit
|
||||
{
|
||||
var position = 9 + (i * 2);
|
||||
var datumString = line.Substring(position, 2);
|
||||
var datum = Convert.ToByte(datumString, 16);
|
||||
data.Add(datum);
|
||||
data[i] = Convert.ToByte(datumString, 16);
|
||||
}
|
||||
|
||||
return new Tuple<ushort, List<byte>>(address, data);
|
||||
}
|
||||
|
||||
case 0x01:
|
||||
return null;
|
||||
|
||||
default:
|
||||
throw new InvalidOperationException("Unhandled hex file record.");
|
||||
}
|
||||
return new Tuple<ushort, byte[]>(address, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user