Skip to content

Commit

Permalink
Lots of debugger stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
RupertAvery committed May 24, 2019
1 parent 16f7aa7 commit 70b3da4
Show file tree
Hide file tree
Showing 18 changed files with 404 additions and 214 deletions.
3 changes: 3 additions & 0 deletions About.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Common/CustomComboBoxItem.cs → Common/CustomMemoryRange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

namespace Sharp6800.Common
{
public class CustomComboBoxItem : ComboBoxItem
public class CustomMemoryRange : MemoryRange
{
private TextBox _source;
private int _lastValue;

public CustomComboBoxItem(TextBox source)
public CustomMemoryRange(TextBox source)
{
_source = source;
}
Expand Down
2 changes: 1 addition & 1 deletion Common/ComboBoxItem.cs → Common/MemoryRange.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Sharp6800.Common
{
public class ComboBoxItem
public class MemoryRange
{
public virtual string Description { get; set; }
public virtual int Start { get; set; }
Expand Down
65 changes: 24 additions & 41 deletions Core6800/Cpu6800.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,22 @@ public Cpu6800()
Initialize();
}

public int Execute()
public int PostExecute()
{
if (State.WAI)
{
return 5;
}
else
{
int fetchCode = ReadMem(State.PC) & 0xff;
State.PC++;
InterpretOpCode(fetchCode);
return cycles[fetchCode];
}
}

public int PreExecute()
{
if (State.Reset == 0)
{
Expand Down Expand Up @@ -48,42 +63,14 @@ public int Execute()

CheckInterrupts();

return 0;
}

// State.ITemp

//if (Breakpoint.Contains(State.PC))
//{
// var x = 1;
// // Do something for a hardware breaskpoint
// // Log stuff

//}

//if (State.PC == 0xFDC2 && State.A == 0xF7)
//{
// var x = 1;
// // Do something for a hardware breaskpoint
// // Log stuff

//}

//if (!((PC >= 0xFE3A) && (PC <= 0xFE4F))) // Ignore OUTCH
//{
// System.Diagnostics.Debug.WriteLine(string.Format("PC:{0,4:X} A:{1,2:X} B:{2,2:X} IX:{3,4:X} SP:{4,4:X} CC:{5, 6}", PC, A, B, X, S, Convert.ToString(CC, 2)));
//}

if (State.WAI)
{
return 5;
}
else
{
int fetchCode = ReadMem(State.PC) & 0xff;
State.PC++;
InterpretOpCode(fetchCode);

return cycles[fetchCode];
}
public int Execute()
{
var preExecute = PreExecute();
if (preExecute > 0) return preExecute;
return PostExecute();
}

private void CheckInterrupts()
Expand Down Expand Up @@ -138,13 +125,9 @@ public void IRQ()
State.InterruptRequest = 0;
}

/// <summary>
/// Initiates power-on sequence
/// </summary>
public void BootStrap()
public void Reset()
{
State.Reset = 0;
Execute();
}

}
Expand Down
113 changes: 72 additions & 41 deletions Debugger/DasmDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ namespace Sharp6800.Debugger
{
public class DasmDisplay
{
private readonly Trainer.Trainer _trainer;
private readonly IntPtr targetWnd;
private readonly int width, height;
private int _selectedOffset;

public DasmDisplay(PictureBox target)
public DasmDisplay(PictureBox target, Trainer.Trainer trainer)
{
_trainer = trainer;
try
{
width = target.Width;
Expand All @@ -34,12 +35,12 @@ public DasmDisplay(PictureBox target)
public int FirstAddress { get; private set; }


public int GetOffsetFromAddress(int[] memory, int address)
public int GetOffsetFromAddress(int address)
{
for (int i = Start, offset = 0; i < memory.Length; offset++)
for (int i = Start, offset = 0; i < _trainer.Memory.Length; offset++)
{
string buf = "";
var ops = Disassembler.Disassemble(memory, i, ref buf) & 0x3;
var ops = Disassembler.Disassemble(_trainer.Memory, i, ref buf) & 0x3;
if (address == i)
{
return offset;
Expand All @@ -50,7 +51,7 @@ public int GetOffsetFromAddress(int[] memory, int address)
return 0;
}

public void Display(int[] memory, Cpu6800State state, List<int> breakpoints)
public void Display()
{
var buffer = new Bitmap(width, height);
var g = Graphics.FromImage(buffer);
Expand All @@ -62,60 +63,97 @@ public void Display(int[] memory, Cpu6800State state, List<int> breakpoints)
{
string buf = "";
string code = "";
if (i < memory.Length)
var ops = 0;

if (i < _trainer.Memory.Length)
{
var inDataRange = false;

if (MemoryMaps != null)
if (_trainer.MemoryMaps != null)
{
foreach (var memoryMap in MemoryMaps)
foreach (var memoryMap in _trainer.MemoryMaps)
{
var inDataRange = memoryMap.Ranges.FirstOrDefault(range => i >= range.Start && i <= range.End);
if (inDataRange != null)
inDataRange = i >= memoryMap.Start && i <= memoryMap.End;
if (inDataRange)
{
i = inDataRange.End + 1;
ops = memoryMap.End - memoryMap.Start + 1;

if (ops > 8)
{
ops = 8;
}

break;
}
}

}

var ops = Disassembler.Disassemble(memory, i, ref buf) & 0x3;
int k;

for (k = 0; k < ops; k++)
if (!inDataRange)
{
code = code + string.Format("{0:X2}", memory[i + k]) + " ";
ops = Disassembler.Disassemble(_trainer.Memory, i, ref buf) & 0x3;
}

for (var k = 0; k < ops; k++)
{
if (i + k < _trainer.Memory.Length)
{
code = code + string.Format("{0:X2}", _trainer.Memory[i + k]) + " ";
}
}

if (offset >= Offset)
{
if (offset == _selectedOffset)
var isAtBreakPoint = _trainer.Breakpoints.Contains(i);
var isSelected = false;
var isCurrentPC = (!_trainer.Running && i == _trainer.State.PC);

if (offset == SelectedOffset)
{
SelectedAddress = i;
using (var brush = new SolidBrush(Color.Blue))
{
g.FillRectangle(brush, 2, 20 * j, width - 2, 20);
}
isSelected = true;
}

if (breakpoints.Contains(i))

if (isAtBreakPoint || isSelected || isCurrentPC)
{
using (var brush = new SolidBrush(Color.DarkRed))
Color highlightColor = Color.White;

if (isAtBreakPoint && isSelected && isCurrentPC)
{
g.FillRectangle(brush, 2, 20 * j, width - 2, 20);
highlightColor = Color.DodgerBlue;
}
else if (isSelected && isCurrentPC)
{
highlightColor = Color.DodgerBlue;
}
else if (isAtBreakPoint && isSelected)
{
highlightColor = Color.DodgerBlue;
}
else if (isAtBreakPoint && isCurrentPC)
{
highlightColor = Color.Orange;
}
else if (isAtBreakPoint)
{
highlightColor = Color.DarkRed;
}
else if (isSelected)
{
highlightColor = Color.Blue;
}
else if (isCurrentPC)
{
highlightColor = Color.Yellow;
}
}

if (i == state.PC)
{
using (var brush = new SolidBrush(Color.Yellow))
using (var brush = new SolidBrush(highlightColor))
{
g.FillRectangle(brush, 2, 20 * j, width - 2, 20);
}
}

DrawHex(g, 10, 20 * j, string.Format("{0:X4} {1,-9} {2}", i, code, buf.ToUpper()));
DrawHex(g, 10, 20 * j, string.Format("{0:X4} {1,-9} {2}", i, code, buf.ToUpper()), isAtBreakPoint);
j++;
}

Expand All @@ -137,30 +175,23 @@ public void Display(int[] memory, Cpu6800State state, List<int> breakpoints)
p.Dispose();
}

private void DrawHex(Graphics g, int x, int y, string asm)
private void DrawHex(Graphics g, int x, int y, string asm, bool isAtBreakPoint)
{
using (var brush = new SolidBrush(Color.Black))
using (var brush = new SolidBrush(isAtBreakPoint ? Color.White : Color.Black))
{
using (var font = new Font("Courier New", 12, FontStyle.Regular))
{
g.DrawString(asm, font, brush, x, y);

}
}
}

public int SelectedAddress { get; private set; }
public int SelectedOffset { get; set; }


public int Start { get; set; }

public int Offset { get; set; }

public IEnumerable<MemoryMap> MemoryMaps { get; set; }

public void SelectOffset(int selectedOffset)
{
_selectedOffset = selectedOffset;
}
}
}
8 changes: 8 additions & 0 deletions Debugger/DataRange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ public enum RangeType
}

public class MemoryMap
{
public int Start { get; set; }
public int End { get; set; }
public RangeType Type { get; set; }
public string Description { get; set; }
}

public class MemoryMapOld
{
[XmlElement("start")]
public string Start { get; set; }
Expand Down
8 changes: 5 additions & 3 deletions Debugger/MemDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,24 @@ namespace Sharp6800.Debugger
{
public class MemDisplay
{
private readonly Trainer.Trainer _trainer;
private readonly IntPtr targetWnd;
private readonly int width, height;

public int Start { get; set; }
public int Lines { get; set; }

public MemDisplay(PictureBox target)
public MemDisplay(PictureBox target, Trainer.Trainer trainer)
{
_trainer = trainer;
width = target.Width;
height = target.Height;
targetWnd = target.Handle;
Lines = 16;
}


public void Display(int[] memory)
public void Display()
{
var buffer = new Bitmap(width, height);
using (var g = Graphics.FromImage(buffer))
Expand All @@ -32,7 +34,7 @@ public void Display(int[] memory)
var j = 0;
for (var i = Start; i <= Start + 8 * Lines; i += 8)
{
DrawHex(g, 10, 20 * j, i, memory);
DrawHex(g, 10, 20 * j, i, _trainer.Memory);
j++;
}
}
Expand Down
Loading

0 comments on commit 70b3da4

Please sign in to comment.