source: branches/UltimatOS/Forms/UFormCpu.pas

Last change on this file was 35, checked in by chronos, 2 years ago
  • Added: Cpu state window.
File size: 2.1 KB
Line 
1unit UFormCpu;
2
3interface
4
5uses
6 Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, StdCtrls,
7 ExtCtrls, UCpu;
8
9type
10
11 { TFormCpu }
12
13 TFormCpu = class(TForm)
14 Label1: TLabel;
15 Label2: TLabel;
16 LabelTicks: TLabel;
17 ListViewMemory: TListView;
18 ListViewRegs: TListView;
19 Timer1: TTimer;
20 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
21 procedure FormShow(Sender: TObject);
22 procedure Timer1Timer(Sender: TObject);
23 procedure ListViewMemoryData(Sender: TObject; Item: TListItem);
24 procedure ListViewRegsData(Sender: TObject; Item: TListItem);
25 private
26
27 public
28 Cpu: TCpu;
29 end;
30
31var
32 FormCpu: TFormCpu;
33
34const
35 DataPerLine = 16;
36
37
38implementation
39
40{$R *.lfm}
41
42{ TFormCpu }
43
44procedure TFormCpu.ListViewMemoryData(Sender: TObject; Item: TListItem);
45var
46 Line: string;
47 I: Integer;
48begin
49 if Item.Index * DataPerLine < Cpu.Memory.Size then begin
50 Item.Caption := IntToHex(Item.Index * DataPerLine, 8);
51 Line := '';
52 for I := 0 to DataPerLine - 1 do
53 Line := Line + IntToHex(Cpu.Memory.Data[Item.Index * DataPerLine + I], 4) + ' ';
54 Item.SubItems.Add(Line);
55 end;
56end;
57
58procedure TFormCpu.ListViewRegsData(Sender: TObject; Item: TListItem);
59begin
60 if Item.Index < Length(Cpu.R) + 2 then begin
61 if Item.Index = 0 then begin
62 Item.Caption := 'IP';
63 Item.SubItems.Add(IntToHex(Cpu.IP, 8));
64 end else
65 if Item.Index = 1 then begin
66 Item.Caption := 'SP';
67 Item.SubItems.Add(IntToHex(Cpu.SP, 8));
68 end else begin
69 Item.Caption := 'R' + IntToStr(Item.Index - 2);
70 Item.SubItems.Add(IntToHex(Cpu.R[Item.Index - 2], 8));
71 end;
72 end;
73end;
74
75procedure TFormCpu.Timer1Timer(Sender: TObject);
76begin
77 ListViewMemory.Items.Count := Cpu.Memory.Size div DataPerLine;
78 ListViewMemory.Refresh;
79 ListViewRegs.Items.Count := Length(Cpu.R) + 2;
80 ListViewRegs.Refresh;
81 LabelTicks.Caption := 'Ticks: ' + IntToStr(Cpu.Ticks);
82end;
83
84procedure TFormCpu.FormShow(Sender: TObject);
85begin
86 Timer1.Enabled := True;
87end;
88
89procedure TFormCpu.FormClose(Sender: TObject; var CloseAction: TCloseAction);
90begin
91 Timer1.Enabled := False;
92end;
93
94end.
95
Note: See TracBrowser for help on using the repository browser.