Skip to content

Commit

Permalink
Parse the ORG directive when the record type is Extended linear address
Browse files Browse the repository at this point in the history
  • Loading branch information
fredimachado committed Nov 7, 2016
1 parent c5f73df commit bb97efd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
19 changes: 17 additions & 2 deletions src/PICHexDisassembler/Hex32Record.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public Hex32Record(byte byteCount, ushort address, byte recordType, ushort[] dat
{
ByteCount = byteCount;
Address = address;
RecordType = recordType;
RecordType = (RecordType)recordType;
DataBytes = dataBytes;
Checksum = checksum;

Expand All @@ -24,15 +24,30 @@ public Hex32Record(byte byteCount, ushort address, byte recordType, ushort[] dat

public byte ByteCount { get; }
public int Address { get; }
public byte RecordType { get; }
public RecordType RecordType { get; }
public ushort[] DataBytes { get; }
public byte Checksum { get; }

public Instruction[] Instructions { get; }

public override string ToString()
{
if (RecordType == RecordType.ExtendedLinearAddress)
{
return $"ORG 0x{Address:X4}";
}

return string.Join("\r\n", Instructions.Select(m => m.ToString()));
}
}

public enum RecordType
{
Data = 0,
EndOfFile,
ExtendedSegmentAddress,
StartSegmentAddress,
ExtendedLinearAddress,
StartLinearAddress
}
}
14 changes: 12 additions & 2 deletions test/PICHexDisassembler.Tests/HexParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void ParseRecordType()
var parser = new HexParser();
var parsed = parser.ParseLine(line);

Assert.Equal(0, parsed.RecordType);
Assert.Equal(RecordType.Data, parsed.RecordType);
}

[Fact]
Expand Down Expand Up @@ -85,7 +85,7 @@ public void ParseLongData()

Assert.Equal(16, parsed.ByteCount);
Assert.Equal(8, parsed.Address);
Assert.Equal(0, parsed.RecordType);
Assert.Equal(RecordType.Data, parsed.RecordType);

Assert.Equal(0x00, parsed.Instructions[0].FirstByte);
Assert.Equal(0x09, parsed.Instructions[0].SecondByte);
Expand Down Expand Up @@ -210,5 +210,15 @@ CALL 0x2C

Assert.Equal(asm, parsed.ToString());
}

[Fact]
public void ParseORGDirective()
{
var line = ":020000040000FA";
var parser = new HexParser();
var parsed = parser.ParseLine(line);

Assert.Equal("ORG 0x0000", parsed.ToString());
}
}
}

0 comments on commit bb97efd

Please sign in to comment.