mirror of
https://github.com/MoleskiCoder/EightBitNet.git
synced 2025-11-25 21:17:35 +00:00
Make the intel hex file format parser easier to use.
This commit is contained in:
@@ -122,7 +122,7 @@ namespace EightBit
|
||||
|
||||
protected void LoadHexFile(string path)
|
||||
{
|
||||
using var file = new IntelHexFile(path);
|
||||
var file = new IntelHexFile(path);
|
||||
foreach (var (address, content) in file.Parse())
|
||||
{
|
||||
var mapped = this.Mapping(address);
|
||||
|
||||
@@ -8,24 +8,18 @@ namespace EightBit
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
public class IntelHexFile(string path) : IDisposable
|
||||
public class IntelHexFile(string path)
|
||||
{
|
||||
private readonly StreamReader reader = File.OpenText(path);
|
||||
private readonly string _path = path;
|
||||
private bool eof;
|
||||
private bool disposed = false;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
this.Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
public IEnumerable<Tuple<ushort, byte[]>> Parse()
|
||||
{
|
||||
this.eof = false;
|
||||
while (!this.reader.EndOfStream && !this.eof)
|
||||
using var reader = File.OpenText(this._path);
|
||||
while (!reader.EndOfStream && !this.eof)
|
||||
{
|
||||
var line = this.reader.ReadLine() ?? throw new InvalidOperationException("Early EOF detected");
|
||||
var line = reader.ReadLine() ?? throw new InvalidOperationException("Early EOF detected");
|
||||
var parsed = this.Parse(line);
|
||||
if (parsed != null)
|
||||
{
|
||||
@@ -39,19 +33,6 @@ namespace EightBit
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!this.disposed)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
this.reader.Dispose();
|
||||
}
|
||||
|
||||
this.disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] ParseDataRecord(string line, byte count)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNullOrEmpty(line);
|
||||
|
||||
Reference in New Issue
Block a user