source: branches/templates/Devices/Device.pas

Last change on this file was 44, checked in by chronos, 14 months ago
  • Added: More devices.
File size: 3.1 KB
Line 
1unit Device;
2
3interface
4
5uses
6 Classes, SysUtils, AddrChannel;
7
8type
9 TWriteEvent = procedure (Address: QWord; Data: QWord) of object;
10 TReadEvent = function (Address: QWord): QWord of object;
11
12 {$MACRO ON}
13
14 {$DEFINE TGDevice := TDevice8}
15 {$DEFINE TGDeviceData := Byte}
16 {$DEFINE TGDeviceAddrChannel := TAddrChannel8}
17 {$DEFINE TGDeviceWidth := 8}
18 {$DEFINE INTERFACE}
19 {$I 'Device.inc'}
20
21 {$DEFINE TGDevice := TDevice16}
22 {$DEFINE TGDeviceData := Word}
23 {$DEFINE TGDeviceAddrChannel := TAddrChannel16}
24 {$DEFINE TGDeviceWidth := 16}
25 {$DEFINE INTERFACE}
26 {$I 'Device.inc'}
27
28 {$DEFINE TGDevice := TDevice32}
29 {$DEFINE TGDeviceData := DWord}
30 {$DEFINE TGDeviceAddrChannel := TAddrChannel32}
31 {$DEFINE TGDeviceWidth := 32}
32 {$DEFINE INTERFACE}
33 {$I 'Device.inc'}
34
35 {$DEFINE TGDevice := TDevice64}
36 {$DEFINE TGDeviceData := QWord}
37 {$DEFINE TGDeviceAddrChannel := TAddrChannel64}
38 {$DEFINE TGDeviceWidth := 64}
39 {$DEFINE INTERFACE}
40 {$I 'Device.inc'}
41
42 { TDevice }
43
44 TDevice = class
45 private
46 FDevice16: TDevice16;
47 FDevice32: TDevice32;
48 FDevice64: TDevice64;
49 FDevice8: TDevice8;
50 FWidth: TBitWidth;
51 procedure SetWidth(AValue: TBitWidth);
52 public
53 procedure SetDataBus(Channel: TAddrChannel);
54 constructor Create;
55 property Width: TBitWidth read FWidth write SetWidth;
56 property Device8: TDevice8 read FDevice8;
57 property Device16: TDevice16 read FDevice16;
58 property Device32: TDevice32 read FDevice32;
59 property Device64: TDevice64 read FDevice64;
60 end;
61
62implementation
63
64{ TDevice }
65
66procedure TDevice.SetWidth(AValue: TBitWidth);
67begin
68 if FWidth = AValue then Exit;
69 case FWidth of
70 bw8: FreeAndNil(FDevice8);
71 bw16: FreeAndNil(FDevice16);
72 bw32: FreeAndNil(FDevice32);
73 bw64: FreeAndNil(FDevice64);
74 end;
75 FWidth := AValue;
76 case FWidth of
77 bw8: FDevice8 := TDevice8.Create;
78 bw16: FDevice16 := TDevice16.Create;
79 bw32: FDevice32 := TDevice32.Create;
80 bw64: FDevice64 := TDevice64.Create;
81 end;
82end;
83
84procedure TDevice.SetDataBus(Channel: TAddrChannel);
85begin
86 if Width <> Channel.Width then raise Exception.Create('Bit width mismatch.');
87 case Width of
88 bw8: Device8.SetDataBus(Channel.AddrChannel8);
89 bw16: Device16.SetDataBus(Channel.AddrChannel16);
90 bw32: Device32.SetDataBus(Channel.AddrChannel32);
91 bw64: Device64.SetDataBus(Channel.AddrChannel64);
92 end;
93end;
94
95constructor TDevice.Create;
96begin
97 FDevice8 := TDevice8.Create;
98end;
99
100{$DEFINE TGDevice := TDevice8}
101{$DEFINE TGDeviceData := Byte}
102{$DEFINE TGDeviceAddrChannel := TAddrChannel8}
103{$DEFINE TGDeviceWidth := 8}
104{$DEFINE IMPLEMENTATION}
105{$I 'Device.inc'}
106
107{$DEFINE TGDevice := TDevice16}
108{$DEFINE TGDeviceData := Word}
109{$DEFINE TGDeviceAddrChannel := TAddrChannel16}
110{$DEFINE TGDeviceWidth := 16}
111{$DEFINE IMPLEMENTATION}
112{$I 'Device.inc'}
113
114{$DEFINE TGDevice := TDevice32}
115{$DEFINE TGDeviceData := DWord}
116{$DEFINE TGDeviceAddrChannel := TAddrChannel32}
117{$DEFINE TGDeviceWidth := 32}
118{$DEFINE IMPLEMENTATION}
119{$I 'Device.inc'}
120
121{$DEFINE TGDevice := TDevice64}
122{$DEFINE TGDeviceData := QWord}
123{$DEFINE TGDeviceAddrChannel := TAddrChannel64}
124{$DEFINE TGDeviceWidth := 64}
125{$DEFINE IMPLEMENTATION}
126{$I 'Device.inc'}
127
128end.
129
Note: See TracBrowser for help on using the repository browser.