Skip to content

Commit

Permalink
Fix for address overflow error
Browse files Browse the repository at this point in the history
  • Loading branch information
Brad Robinson committed Nov 4, 2013
1 parent 3e0b8a0 commit 36fc40c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
Binary file modified yazd.zip
Binary file not shown.
6 changes: 5 additions & 1 deletion yazd/Disassembler.cs
Expand Up @@ -58,7 +58,11 @@ public static string FormatAddr(ushort addr, bool link=true, bool prefix=true)

public static Instruction Disassemble(byte[] buffer, ushort offsetInBuffer, ushort addr)
{
Func<byte> readByte = () => { addr++; return buffer[offsetInBuffer++]; };
Func<byte> readByte = () =>
{
addr++;
return (byte)(offsetInBuffer<buffer.Length ? buffer[offsetInBuffer++] : 0);
};

var i = new Instruction();
i.addr = addr;
Expand Down
8 changes: 4 additions & 4 deletions yazd/Program.cs
Expand Up @@ -294,7 +294,7 @@ public int Run(string[] args)
while (!instructions.ContainsKey(addr) && addr >= _start && addr < _start + _len)
{
// Disassemble this instruction
var i = Disassembler.Disassemble(code, (ushort)(addr - _baseAddr - _header), (ushort)addr);
var i = Disassembler.Disassemble(code, (ushort)(addr - _baseAddr + _header), (ushort)addr);

// Possible address reference?
if (_markWordRefs && i.word_val.HasValue && (i.opCode.flags & (OpCodeFlags.Jumps | OpCodeFlags.RefAddr)) == 0)
Expand Down Expand Up @@ -326,7 +326,7 @@ public int Run(string[] args)
for (int addr = _start; addr < _start + _len; )
{
// Disassemble this instruction
var i = Disassembler.Disassemble(code, (ushort)(addr - _baseAddr - _header), (ushort)addr);
var i = Disassembler.Disassemble(code, (ushort)(addr - _baseAddr + _header), (ushort)addr);

// Add it
instructions.Add(addr, i);
Expand All @@ -344,7 +344,7 @@ public int Run(string[] args)
{
for (int j = from; j < to; j++)
{
var data = code[j - _baseAddr - _header];
var data = code[j - _baseAddr + _header];

// Get the byte
var instruction = new Instruction();
Expand Down Expand Up @@ -513,7 +513,7 @@ public int Run(string[] args)
w.Write("{0:X4}:", i.addr);
for (int j = 0; j < i.bytes; j++)
{
var data = code[i.addr + j - _baseAddr - _header];
var data = code[i.addr + j - _baseAddr + _header];
w.Write(" {0:X2}", data);
}

Expand Down

0 comments on commit 36fc40c

Please sign in to comment.