source: branches/templates/UFormMain.pas

Last change on this file was 44, checked in by chronos, 8 months ago
  • Added: More devices.
File size: 3.0 KB
Line 
1unit UFormMain;
2
3interface
4
5uses
6 Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls;
7
8type
9
10 { TFormMain }
11
12 TFormMain = class(TForm)
13 Memo1: TMemo;
14 procedure FormShow(Sender: TObject);
15 private
16 public
17 procedure DoIOWrite(Address: QWord; Data: QWord);
18 procedure Log(Text: string);
19 end;
20
21var
22 FormMain: TFormMain;
23
24
25implementation
26
27{$R *.lfm}
28
29uses
30 Cpu, Memory, Device;
31
32{ TFormMain }
33
34procedure TFormMain.FormShow(Sender: TObject);
35var
36 Memory: TMemory;
37 Memory8: TMemory8;
38 Memory16: TMemory16;
39 Memory32: TMemory32;
40 Memory64: TMemory64;
41 IO: TDevice;
42 IO8: TDevice8;
43 IO16: TDevice16;
44 IO32: TDevice32;
45 IO64: TDevice64;
46 Cpu: TCpu;
47 Cpu8: TMemory8;
48 Cpu16: TCpu16;
49 Cpu32: TCpu32;
50 Cpu64: TCpu64;
51begin
52 Cpu := TCpu.Create;
53 try
54 Memory := TMemory.Create;
55 Memory.Memory8.Size := High(Byte);
56 Memory.SetDataBus(Cpu.Memory);
57 IO := TDevice.Create;
58 IO.Device8.OnWrite := DoIOWrite;
59 IO.SetDataBus(Cpu.IO);
60 Cpu.Cpu8.WriteOpcode(opLoadImmediate);
61 Cpu.Cpu8.Write($12);
62 Cpu.Cpu8.WriteOpcode(opOutput);
63 Cpu.Cpu8.Write(1);
64 Cpu.Cpu8.WriteOpcode(opHalt);
65 Log('Cpu run');
66 Cpu.Run;
67 finally
68 Cpu.Free;
69 end;
70
71 with TCpu8.Create do
72 try
73 Memory8 := TMemory8.Create;
74 Memory8.Size := High(Byte);
75 Memory8.SetDataBus(Memory);
76 IO8 := TDevice8.Create;
77 IO8.OnWrite := DoIOWrite;
78 IO8.SetDataBus(IO);
79 WriteOpcode(opLoadImmediate);
80 Write($12);
81 WriteOpcode(opOutput);
82 Write(1);
83 WriteOpcode(opHalt);
84 Log('Cpu8 run');
85 Run;
86 finally
87 Free;
88 end;
89
90 with TCpu16.Create do
91 try
92 Memory16 := TMemory16.Create;
93 Memory16.Size := High(Word);
94 Memory16.SetDataBus(Memory);
95 IO16 := TDevice16.Create;
96 IO16.OnWrite := DoIOWrite;
97 IO16.SetDataBus(IO);
98 WriteOpcode(opLoadImmediate);
99 Write($1234);
100 WriteOpcode(opLoadImmediate8);
101 Write8($56);
102 WriteOpcode(opOutput);
103 Write(1);
104 WriteOpcode(opHalt);
105 Log('Cpu16 run');
106 Run;
107 finally
108 Free;
109 end;
110
111 with TCpu32.Create do
112 try
113 Memory32 := TMemory32.Create;
114 Memory32.Size := High(Word);
115 Memory32.SetDataBus(Memory);
116 IO32 := TDevice32.Create;
117 IO32.OnWrite := DoIOWrite;
118 IO32.SetDataBus(IO);
119 WriteOpcode(opLoadImmediate);
120 Write(14);
121 WriteOpcode(opOutput);
122 Write(1);
123 WriteOpcode(opHalt);
124 Log('Cpu32 run');
125 Run;
126 finally
127 Free;
128 end;
129
130 with TCpu64.Create do
131 try
132 Memory64 := TMemory64.Create;
133 Memory64.Size := High(Word);
134 Memory64.SetDataBus(Memory);
135 IO64 := TDevice64.Create;
136 IO64.OnWrite := DoIOWrite;
137 IO64.SetDataBus(IO);
138 WriteOpcode(opLoadImmediate);
139 Write(14);
140 WriteOpcode(opOutput);
141 Write(1);
142 WriteOpcode(opHalt);
143 Log('Cpu64 run');
144 Run;
145 finally
146 Free;
147 end;
148end;
149
150procedure TFormMain.DoIOWrite(Address: QWord; Data: QWord);
151begin
152 Log('Address: ' + IntToHex(Address) + ', Data: ' + IntToHex(Data));
153end;
154
155procedure TFormMain.Log(Text: string);
156begin
157 Memo1.Lines.Add(Text);
158end;
159
160end.
161
Note: See TracBrowser for help on using the repository browser.