Changeset 42 for branches/simple/Devices
- Timestamp:
- Sep 8, 2023, 11:20:27 PM (15 months ago)
- Location:
- branches/simple/Devices
- Files:
-
- 2 added
- 3 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/simple/Devices/Console.pas
r41 r42 4 4 5 5 uses 6 Classes, SysUtils, Device, DeviceMa pper;6 Classes, SysUtils, Device, DeviceManager, Channel; 7 7 8 8 type 9 { TConsole }10 9 11 TConsole = class(TDevice16) 10 { TConsole8 } 11 12 TConsole8 = class(TDevice8) 12 13 private 13 14 FOnRead: TReadEvent8; … … 16 17 function Read8: Byte; 17 18 public 18 procedure RegisterMapper8(Mapper: TDeviceMapper8); override; 19 procedure RegisterMapper16(Mapper: TDeviceMapper16); override; 19 function GetHandlerCount: Integer; override; 20 function GetHandler(Address: Integer): TChannel8; override; 21 property OnWrite: TWriteEvent8 read FOnWrite write FOnWrite; 22 property OnRead: TReadEvent8 read FOnRead write FOnRead; 23 end; 24 25 { TConsole16 } 26 27 TConsole16 = class(TDevice16) 28 private 29 FOnRead: TReadEvent8; 30 FOnWrite: TWriteEvent8; 31 procedure Write8(Data: Byte); 32 function Read8: Byte; 33 public 34 function GetHandlerCount: Integer; override; 35 function GetHandler(Address: Integer): TChannel16; override; 20 36 property OnWrite: TWriteEvent8 read FOnWrite write FOnWrite; 21 37 property OnRead: TReadEvent8 read FOnRead write FOnRead; … … 25 41 implementation 26 42 27 { TConsole }43 { TConsole8 } 28 44 29 procedure TConsole.RegisterMapper8(Mapper: TDeviceMapper8); 30 begin 31 Mapper.RegisterReadHandler(Read8); 32 Mapper.RegisterWriteHandler(Write8); 33 end; 34 35 procedure TConsole.RegisterMapper16(Mapper: TDeviceMapper16); 36 begin 37 Mapper.RegisterReadHandler(Read8, nil); 38 Mapper.RegisterWriteHandler(Write8, nil); 39 end; 40 41 procedure TConsole.Write8(Data: Byte); 45 procedure TConsole8.Write8(Data: Byte); 42 46 begin 43 47 if Assigned(FOnWrite) then FOnWrite(Data); 44 48 end; 45 49 46 function TConsole .Read8: Byte;50 function TConsole8.Read8: Byte; 47 51 begin 48 52 if Assigned(FOnRead) then Result := FOnRead … … 50 54 end; 51 55 56 function TConsole8.GetHandlerCount: Integer; 57 begin 58 Result := 1; 59 end; 60 61 function TConsole8.GetHandler(Address: Integer): TChannel8; 62 begin 63 if Address = 0 then begin 64 Result := TChannel8.Create; 65 Result.Read8 := Read8; 66 Result.Write8 := Write8; 67 end; 68 end; 69 70 { TConsole16 } 71 72 procedure TConsole16.Write8(Data: Byte); 73 begin 74 if Assigned(FOnWrite) then FOnWrite(Data); 75 end; 76 77 function TConsole16.Read8: Byte; 78 begin 79 if Assigned(FOnRead) then Result := FOnRead 80 else Result := 0; 81 end; 82 83 function TConsole16.GetHandlerCount: Integer; 84 begin 85 Result := 1; 86 end; 87 88 function TConsole16.GetHandler(Address: Integer): TChannel16; 89 begin 90 if Address = 0 then begin 91 Result := TChannel16.Create; 92 Result.Read8 := Read8; 93 Result.Write8 := Write8; 94 end; 95 end; 52 96 53 97 end. -
branches/simple/Devices/Device.pas
r41 r42 4 4 5 5 uses 6 Classes, SysUtils, DeviceMapper;6 Classes, SysUtils, Channel, Generics.Collections, Forms; 7 7 8 8 type 9 TDeviceClass = (dcNone, dcKeyboard, dcMouse, dcStorage, dcScreen, dcConsole, 10 dcTimer); 11 TDeviceClassSet = set of TDeviceClass; 12 9 13 { TDevice8 } 10 14 11 15 TDevice8 = class 12 procedure RegisterMapper8(Mapper: TDeviceMapper8); virtual; abstract; 16 BaseAddress: Byte; 17 procedure SetDataBus(Channel: TAddressableChannel8); virtual; 18 function GetHandlerCount: Integer; virtual; 19 function GetHandler(Address: Integer): TChannel8; virtual; 13 20 end; 14 21 … … 16 23 17 24 TDevice16 = class 18 procedure RegisterMapper8(Mapper: TDeviceMapper8); virtual; abstract; 19 procedure RegisterMapper16(Mapper: TDeviceMapper16); virtual; abstract; 25 BaseAddress: Word; 26 procedure SetDataBus(Channel: TAddressableChannel16); virtual; 27 function GetHandlerCount: Integer; virtual; 28 function GetHandler(Address: Integer): TChannel16; virtual; 20 29 end; 30 31 { TDevice32 } 32 33 TDevice32 = class 34 BaseAddress: DWord; 35 procedure SetDataBus(Channel: TAddressableChannel32); virtual; 36 function GetHandlerCount: Integer; virtual; 37 function GetHandler(Address: Integer): TChannel32; virtual; 38 end; 39 40 { TDevice64 } 41 42 TDevice64 = class 43 BaseAddress: QWord; 44 procedure SetDataBus(Channel: TAddressableChannel64); virtual; 45 function GetHandlerCount: Integer; virtual; 46 function GetHandler(Address: Integer): TChannel64; virtual; 47 end; 48 49 TDevice = class; 50 51 { TFormDevice } 52 53 TFormDevice = class(TForm) 54 protected 55 function GetDevice: TDevice; virtual; 56 procedure SetDevice(AValue: TDevice); virtual; 57 public 58 property Device: TDevice read GetDevice write SetDevice; 59 end; 60 61 TFormDeviceClass = class of TFormDevice; 62 63 { TDevice } 64 65 TDevice = class 66 Name: string; 67 DeviceClass: TDeviceClass; 68 Form: TFormDevice; 69 end; 70 71 { TDevices } 72 73 TDevices = class(TObjectList<TDevice>) 74 function GetDevicesCountByClass(DeviceClass: TDeviceClass): Integer; 75 function GetDevicesByClass(DeviceClass: TDeviceClass): TDevices; 76 function GetClasses: TDeviceClassSet; 77 end; 78 79 const 80 DeviceClassText: array[TDeviceClass] of string = ('None', 'Keyboard', 'Mouse', 'Storage', 'Screen', 'Console', 'Timer'); 21 81 22 82 23 83 implementation 24 84 85 { TFormDevice } 86 87 function TFormDevice.GetDevice: TDevice; 88 begin 89 Result := nil; 90 end; 91 92 procedure TFormDevice.SetDevice(AValue: TDevice); 93 begin 94 end; 95 96 { TDevices } 97 98 function TDevices.GetDevicesCountByClass(DeviceClass: TDeviceClass): Integer; 99 var 100 I: Integer; 101 begin 102 Result := 0; 103 for I := 0 to Count - 1 do 104 if Items[I].DeviceClass = DeviceClass then Inc(Result); 105 end; 106 107 function TDevices.GetDevicesByClass(DeviceClass: TDeviceClass): TDevices; 108 var 109 I: Integer; 110 begin 111 Result := TDevices.Create(False); 112 for I := 0 to Count - 1 do 113 if Items[I].DeviceClass = DeviceClass then Result.Add(Items[I]) 114 end; 115 116 function TDevices.GetClasses: TDeviceClassSet; 117 var 118 I: Integer; 119 begin 120 Result := []; 121 for I := 0 to Count - 1 do 122 if not (Items[I].DeviceClass in Result) then 123 Result := Result + [Items[I].DeviceClass]; 124 end; 125 126 { TDevice32 } 127 128 procedure TDevice32.SetDataBus(Channel: TAddressableChannel32); 129 begin 130 end; 131 132 function TDevice32.GetHandlerCount: Integer; 133 begin 134 Result := 0; 135 end; 136 137 function TDevice32.GetHandler(Address: Integer): TChannel32; 138 begin 139 end; 140 141 { TDevice64 } 142 143 procedure TDevice64.SetDataBus(Channel: TAddressableChannel64); 144 begin 145 end; 146 147 function TDevice64.GetHandlerCount: Integer; 148 begin 149 Result := 0; 150 end; 151 152 function TDevice64.GetHandler(Address: Integer): TChannel64; 153 begin 154 end; 155 156 { TDevice8 } 157 158 procedure TDevice8.SetDataBus(Channel: TAddressableChannel8); 159 begin 160 end; 161 162 function TDevice8.GetHandlerCount: Integer; 163 begin 164 Result := 0; 165 end; 166 167 function TDevice8.GetHandler(Address: Integer): TChannel8; 168 begin 169 end; 170 171 { TDevice16 } 172 173 procedure TDevice16.SetDataBus(Channel: TAddressableChannel16); 174 begin 175 end; 176 177 function TDevice16.GetHandlerCount: Integer; 178 begin 179 Result := 0; 180 end; 181 182 function TDevice16.GetHandler(Address: Integer): TChannel16; 183 begin 184 end; 185 25 186 end. 26 187 -
branches/simple/Devices/Screen.pas
r41 r42 4 4 5 5 uses 6 Classes, SysUtils, Device, DeviceMa pper, Memory;6 Classes, SysUtils, Device, DeviceManager, Memory, Channel; 7 7 8 8 type … … 31 31 constructor Create; 32 32 destructor Destroy; override; 33 procedure RegisterMapper8(Mapper: TDeviceMapper8); override; 33 function GetHandlerCount: Integer; override; 34 function GetHandler(Address: Integer): TChannel8; override; 34 35 property OnChange: TNotifyEvent read FOnChange write FOnChange; 35 36 end; … … 59 60 constructor Create; 60 61 destructor Destroy; override; 61 procedure RegisterMapper8(Mapper: TDeviceMapper8); override;62 procedure RegisterMapper16(Mapper: TDeviceMapper16); override;62 function GetHandlerCount: Integer; override; 63 function GetHandler(Address: Integer): TChannel16; override; 63 64 property OnChange: TNotifyEvent read FOnChange write FOnChange; 64 65 end; 65 66 67 TScreen = class(TDevice) 68 BitWidth: TBitWidth; 69 Screen8: TScreen8; 70 Screen16: TScreen16; 71 constructor Create(BitWidth: TBitWidth; Screen8: TScreen8; Screen16: TScreen16); 72 end; 73 66 74 67 75 implementation 76 77 { TScreen } 78 79 constructor TScreen.Create(BitWidth: TBitWidth; Screen8: TScreen8; 80 Screen16: TScreen16); 81 begin 82 Self.BitWidth := BitWidth; 83 Self.Screen8 := Screen8; 84 Self.Screen16 := Screen16; 85 end; 68 86 69 87 { TScreen16 } … … 149 167 end; 150 168 151 procedure TScreen16.RegisterMapper8(Mapper: TDeviceMapper8); 152 begin 153 end; 154 155 procedure TScreen16.RegisterMapper16(Mapper: TDeviceMapper16); 156 begin 157 Mapper.RegisterReadHandler(ReadData8, ReadData16); 158 Mapper.RegisterWriteHandler(WriteData8, WriteData16); 159 Mapper.RegisterReadHandler(nil, ReadAddr16); 160 Mapper.RegisterWriteHandler(nil, WriteAddr16); 161 Mapper.RegisterReadHandler(nil, ReadWidth16); 162 Mapper.RegisterWriteHandler(nil, WriteWidth16); 163 Mapper.RegisterReadHandler(nil, ReadHeight16); 164 Mapper.RegisterWriteHandler(nil, WriteHeight16); 169 function TScreen16.GetHandlerCount: Integer; 170 begin 171 Result := 4; 172 end; 173 174 function TScreen16.GetHandler(Address: Integer): TChannel16; 175 begin 176 if Address = 0 then begin 177 Result := TChannel16.Create; 178 Result.Read16 := ReadData16; 179 Result.Write16 := WriteData16; 180 end else 181 if Address = 1 then begin 182 Result := TChannel16.Create; 183 Result.Read16 := ReadAddr16; 184 Result.Write16 := WriteAddr16; 185 end else 186 if Address = 2 then begin 187 Result := TChannel16.Create; 188 Result.Read16 := ReadWidth16; 189 Result.Write16 := WriteWidth16; 190 end else 191 if Address = 3 then begin 192 Result := TChannel16.Create; 193 Result.Read16 := ReadHeight16; 194 Result.Write16 := WriteHeight16; 195 end; 165 196 end; 166 197 … … 236 267 end; 237 268 238 procedure TScreen8.RegisterMapper8(Mapper: TDeviceMapper8); 239 begin 240 Mapper.RegisterReadHandler(ReadData8); 241 Mapper.RegisterWriteHandler(WriteData8); 242 Mapper.RegisterReadHandler(ReadAddr8); 243 Mapper.RegisterWriteHandler(WriteAddr8); 244 Mapper.RegisterReadHandler(ReadWidth8); 245 Mapper.RegisterWriteHandler(WriteWidth8); 246 Mapper.RegisterReadHandler(ReadHeight8); 247 Mapper.RegisterWriteHandler(WriteHeight8); 269 function TScreen8.GetHandlerCount: Integer; 270 begin 271 Result := 4; 272 end; 273 274 function TScreen8.GetHandler(Address: Integer): TChannel8; 275 begin 276 if Address = 0 then begin 277 Result := TChannel8.Create; 278 Result.Read8 := ReadData8; 279 Result.Write8 := WriteData8; 280 end else 281 if Address = 1 then begin 282 Result := TChannel8.Create; 283 Result.Read8 := ReadAddr8; 284 Result.Write8 := WriteAddr8; 285 end else 286 if Address = 2 then begin 287 Result := TChannel8.Create; 288 Result.Read8 := ReadWidth8; 289 Result.Write8 := WriteWidth8; 290 end else 291 if Address = 3 then begin 292 Result := TChannel8.Create; 293 Result.Read8 := ReadHeight8; 294 Result.Write8 := WriteHeight8; 295 end; 248 296 end; 249 297
Note:
See TracChangeset
for help on using the changeset viewer.