source: branches/CpuSingleSize/Forms/FormCpu.pas

Last change on this file was 238, checked in by chronos, 16 months ago
  • Modified: Removed U prefix from unit names.
  • Fixed: Memory leaks.
File size: 2.1 KB
Line 
1unit FormCpu;
2
3interface
4
5uses
6 Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, StdCtrls,
7 ExtCtrls, Cpu;
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 public
26 Cpu: TCpu;
27 end;
28
29const
30 DataPerLine = 16;
31
32
33implementation
34
35{$R *.lfm}
36
37{ TFormCpu }
38
39procedure TFormCpu.ListViewMemoryData(Sender: TObject; Item: TListItem);
40var
41 Line: string;
42 I: Integer;
43begin
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;
51end;
52
53procedure TFormCpu.ListViewRegsData(Sender: TObject; Item: TListItem);
54begin
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;
68end;
69
70procedure TFormCpu.Timer1Timer(Sender: TObject);
71begin
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);
77end;
78
79procedure TFormCpu.FormShow(Sender: TObject);
80begin
81 Timer1.Enabled := True;
82end;
83
84procedure TFormCpu.FormClose(Sender: TObject; var CloseAction: TCloseAction);
85begin
86 Timer1.Enabled := False;
87end;
88
89end.
90
Note: See TracBrowser for help on using the repository browser.