1 | unit FormCpu;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, StdCtrls,
|
---|
7 | ExtCtrls, Cpu;
|
---|
8 |
|
---|
9 | type
|
---|
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 | public
|
---|
26 | Cpu: TCpu;
|
---|
27 | end;
|
---|
28 |
|
---|
29 | const
|
---|
30 | DataPerLine = 16;
|
---|
31 |
|
---|
32 |
|
---|
33 | implementation
|
---|
34 |
|
---|
35 | {$R *.lfm}
|
---|
36 |
|
---|
37 | { TFormCpu }
|
---|
38 |
|
---|
39 | procedure TFormCpu.ListViewMemoryData(Sender: TObject; Item: TListItem);
|
---|
40 | var
|
---|
41 | Line: string;
|
---|
42 | I: Integer;
|
---|
43 | begin
|
---|
44 | if Item.Index * DataPerLine < Length(Cpu.Memory) then begin
|
---|
45 | Item.Caption := IntToHex(Item.Index * DataPerLine, 8);
|
---|
46 | Line := '';
|
---|
47 | for I := 0 to DataPerLine - 1 do
|
---|
48 | Line := Line + IntToHex(Cpu.Memory[Item.Index * DataPerLine + I], 4) + ' ';
|
---|
49 | Item.SubItems.Add(Line);
|
---|
50 | end;
|
---|
51 | end;
|
---|
52 |
|
---|
53 | procedure TFormCpu.ListViewRegsData(Sender: TObject; Item: TListItem);
|
---|
54 | begin
|
---|
55 | if Item.Index < Length(Cpu.R) + 2 then begin
|
---|
56 | if Item.Index = 0 then begin
|
---|
57 | Item.Caption := 'IP';
|
---|
58 | Item.SubItems.Add(IntToHex(Cpu.InstructionPointer, 8));
|
---|
59 | end else
|
---|
60 | if Item.Index = 1 then begin
|
---|
61 | Item.Caption := 'SP';
|
---|
62 | Item.SubItems.Add(IntToHex(Cpu.StackPointer, 8));
|
---|
63 | end else begin
|
---|
64 | Item.Caption := 'R' + IntToStr(Item.Index - 2);
|
---|
65 | Item.SubItems.Add(IntToHex(Cpu.R[Item.Index - 2], 8));
|
---|
66 | end;
|
---|
67 | end;
|
---|
68 | end;
|
---|
69 |
|
---|
70 | procedure TFormCpu.Timer1Timer(Sender: TObject);
|
---|
71 | begin
|
---|
72 | ListViewMemory.Items.Count := Length(Cpu.Memory) div DataPerLine;
|
---|
73 | ListViewMemory.Refresh;
|
---|
74 | ListViewRegs.Items.Count := Length(Cpu.R) + 2;
|
---|
75 | ListViewRegs.Refresh;
|
---|
76 | LabelTicks.Caption := 'Ticks: ' + IntToStr(Cpu.Ticks);
|
---|
77 | end;
|
---|
78 |
|
---|
79 | procedure TFormCpu.FormShow(Sender: TObject);
|
---|
80 | begin
|
---|
81 | Timer1.Enabled := True;
|
---|
82 | end;
|
---|
83 |
|
---|
84 | procedure TFormCpu.FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
---|
85 | begin
|
---|
86 | Timer1.Enabled := False;
|
---|
87 | end;
|
---|
88 |
|
---|
89 | end.
|
---|
90 |
|
---|