1 | unit Memory;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, AddrChannel;
|
---|
7 |
|
---|
8 | type
|
---|
9 | {$MACRO ON}
|
---|
10 |
|
---|
11 | {$DEFINE TGMemory := TMemory8}
|
---|
12 | {$DEFINE TGMemoryData := Byte}
|
---|
13 | {$DEFINE TGMemoryAddrChannel := TAddrChannel8}
|
---|
14 | {$DEFINE TGMemoryWidth := 8}
|
---|
15 | {$DEFINE INTERFACE}
|
---|
16 | {$I 'Memory.inc'}
|
---|
17 |
|
---|
18 | {$DEFINE TGMemory := TMemory16}
|
---|
19 | {$DEFINE TGMemoryData := Word}
|
---|
20 | {$DEFINE TGMemoryAddrChannel := TAddrChannel16}
|
---|
21 | {$DEFINE TGMemoryWidth := 16}
|
---|
22 | {$DEFINE INTERFACE}
|
---|
23 | {$I 'Memory.inc'}
|
---|
24 |
|
---|
25 | {$DEFINE TGMemory := TMemory32}
|
---|
26 | {$DEFINE TGMemoryData := DWord}
|
---|
27 | {$DEFINE TGMemoryAddrChannel := TAddrChannel32}
|
---|
28 | {$DEFINE TGMemoryWidth := 32}
|
---|
29 | {$DEFINE INTERFACE}
|
---|
30 | {$I 'Memory.inc'}
|
---|
31 |
|
---|
32 | {$DEFINE TGMemory := TMemory64}
|
---|
33 | {$DEFINE TGMemoryData := QWord}
|
---|
34 | {$DEFINE TGMemoryAddrChannel := TAddrChannel64}
|
---|
35 | {$DEFINE TGMemoryWidth := 64}
|
---|
36 | {$DEFINE INTERFACE}
|
---|
37 | {$I 'Memory.inc'}
|
---|
38 |
|
---|
39 | { TMemory }
|
---|
40 |
|
---|
41 | TMemory = class
|
---|
42 | private
|
---|
43 | FMemory16: TMemory16;
|
---|
44 | FMemory32: TMemory32;
|
---|
45 | FMemory64: TMemory64;
|
---|
46 | FMemory8: TMemory8;
|
---|
47 | FWidth: TBitWidth;
|
---|
48 | procedure SetWidth(AValue: TBitWidth);
|
---|
49 | public
|
---|
50 | procedure SetDataBus(Channel: TAddrChannel);
|
---|
51 | constructor Create;
|
---|
52 | property Width: TBitWidth read FWidth write SetWidth;
|
---|
53 | property Memory8: TMemory8 read FMemory8;
|
---|
54 | property Memory16: TMemory16 read FMemory16;
|
---|
55 | property Memory32: TMemory32 read FMemory32;
|
---|
56 | property Memory64: TMemory64 read FMemory64;
|
---|
57 | end;
|
---|
58 |
|
---|
59 | implementation
|
---|
60 |
|
---|
61 | { TMemory }
|
---|
62 |
|
---|
63 | procedure TMemory.SetWidth(AValue: TBitWidth);
|
---|
64 | begin
|
---|
65 | if FWidth = AValue then Exit;
|
---|
66 | case FWidth of
|
---|
67 | bw8: FreeAndNil(FMemory8);
|
---|
68 | bw16: FreeAndNil(FMemory16);
|
---|
69 | bw32: FreeAndNil(FMemory32);
|
---|
70 | bw64: FreeAndNil(FMemory64);
|
---|
71 | end;
|
---|
72 | FWidth := AValue;
|
---|
73 | case FWidth of
|
---|
74 | bw8: FMemory8 := TMemory8.Create;
|
---|
75 | bw16: FMemory16 := TMemory16.Create;
|
---|
76 | bw32: FMemory32 := TMemory32.Create;
|
---|
77 | bw64: FMemory64 := TMemory64.Create;
|
---|
78 | end;
|
---|
79 | end;
|
---|
80 |
|
---|
81 | procedure TMemory.SetDataBus(Channel: TAddrChannel);
|
---|
82 | begin
|
---|
83 | if Width <> Channel.Width then raise Exception.Create('Bit width mismatch.');
|
---|
84 | case Width of
|
---|
85 | bw8: Memory8.SetDataBus(Channel.AddrChannel8);
|
---|
86 | bw16: Memory16.SetDataBus(Channel.AddrChannel16);
|
---|
87 | bw32: Memory32.SetDataBus(Channel.AddrChannel32);
|
---|
88 | bw64: Memory64.SetDataBus(Channel.AddrChannel64);
|
---|
89 | end;
|
---|
90 | end;
|
---|
91 |
|
---|
92 | constructor TMemory.Create;
|
---|
93 | begin
|
---|
94 | FMemory8 := TMemory8.Create;
|
---|
95 | end;
|
---|
96 |
|
---|
97 | {$DEFINE TGMemory := TMemory8}
|
---|
98 | {$DEFINE TGMemoryData := Byte}
|
---|
99 | {$DEFINE TGMemoryAddrChannel := TAddrChannel8}
|
---|
100 | {$DEFINE TGMemoryWidth := 8}
|
---|
101 | {$DEFINE IMPLEMENTATION}
|
---|
102 | {$I 'Memory.inc'}
|
---|
103 |
|
---|
104 | {$DEFINE TGMemory := TMemory16}
|
---|
105 | {$DEFINE TGMemoryData := Word}
|
---|
106 | {$DEFINE TGMemoryAddrChannel := TAddrChannel16}
|
---|
107 | {$DEFINE TGMemoryWidth := 16}
|
---|
108 | {$DEFINE IMPLEMENTATION}
|
---|
109 | {$I 'Memory.inc'}
|
---|
110 |
|
---|
111 | {$DEFINE TGMemory := TMemory32}
|
---|
112 | {$DEFINE TGMemoryData := DWord}
|
---|
113 | {$DEFINE TGMemoryAddrChannel := TAddrChannel32}
|
---|
114 | {$DEFINE TGMemoryWidth := 32}
|
---|
115 | {$DEFINE IMPLEMENTATION}
|
---|
116 | {$I 'Memory.inc'}
|
---|
117 |
|
---|
118 | {$DEFINE TGMemory := TMemory64}
|
---|
119 | {$DEFINE TGMemoryData := QWord}
|
---|
120 | {$DEFINE TGMemoryAddrChannel := TAddrChannel64}
|
---|
121 | {$DEFINE TGMemoryWidth := 64}
|
---|
122 | {$DEFINE IMPLEMENTATION}
|
---|
123 | {$I 'Memory.inc'}
|
---|
124 |
|
---|
125 | end.
|
---|
126 |
|
---|