unit FormCallStack;

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, ExtCtrls,
  Debugger, Disassembler;

type

  { TFormCallStack }

  TFormCallStack = class(TForm)
    ListView1: TListView;
    Timer1: TTimer;
    procedure FormShow(Sender: TObject);
    procedure ListView1Data(Sender: TObject; Item: TListItem);
    procedure Timer1Timer(Sender: TObject);
  private
    FReloadPending: Boolean;
  public
    Debugger: TDebugger;
    Disassembler: TDisassembler;
    procedure ReloadList;
    procedure Reload;
  end;

var
  FormCallStack: TFormCallStack;


implementation

{$R *.lfm}

{ TFormCallStack }

procedure TFormCallStack.FormShow(Sender: TObject);
begin
  ReloadList;
end;

procedure TFormCallStack.ListView1Data(Sender: TObject; Item: TListItem);
begin
  if Item.Index < Debugger.CallStack.Count then
  with Debugger.CallStack[Debugger.CallStack.Count - 1 - Item.Index] do begin
    Item.Caption := IntToStr(Item.Index + 1);
    Item.Data := Debugger.CallStack[Item.Index];
    Item.SubItems.Add(IntToHex(Address, 4));
    Item.SubItems.Add(IntToHex(Value, 4));
    Item.SubItems.Add(Comment);
  end;
end;

procedure TFormCallStack.Timer1Timer(Sender: TObject);
begin
  if FReloadPending then begin
    FReloadPending := False;
    ReloadList;
  end;
end;

procedure TFormCallStack.ReloadList;
begin
  ListView1.Items.Count := Debugger.CallStack.Count;
  ListView1.Refresh;
end;

procedure TFormCallStack.Reload;
begin
  FReloadPending := True;
end;

end.

