Changeset 42 for branches/simple
- Timestamp:
- Sep 8, 2023, 11:20:27 PM (15 months ago)
- Location:
- branches/simple
- Files:
-
- 20 added
- 8 edited
- 3 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/simple/Cpu.pas
r41 r42 4 4 5 5 uses 6 Classes, SysUtils, DataBus;6 Classes, SysUtils, Channel; 7 7 8 8 type 9 TInstruction = (inLoadImmediate8, inLoadImmediate16, inLoad8, inLoad16, 10 inStore8, inStore16, inInput8, inInput16, inOutput8, inOutput16, 11 inHalt, inJump); 9 TInstruction = (inLoadImmediate, inLoadImmediate8, inLoadImmediate16, 10 inLoad, inLoad8, inLoad16, inLoad32, inLoad64, 11 inStore, inStore8, inStore16, inStore32, inStore64, 12 inInput, inInput8, inInput16, inInput32, inInput64, 13 inOutput, inOutput8, inOutput16, inOutput32, inOutput64, 14 inNop, inHalt, inJump); 12 15 13 16 { TCpu8 } … … 16 19 private 17 20 public 18 IO: T DataBus8;19 Memory: T DataBus8;21 IO: TAddressableChannel8; 22 Memory: TAddressableChannel8; 20 23 Terminated: Boolean; 21 24 A: Byte; … … 25 28 procedure Run; 26 29 procedure Step; 30 constructor Create; 31 destructor Destroy; override; 27 32 end; 28 33 … … 32 37 private 33 38 public 34 IO: T DataBus16;35 Memory: T DataBus16;39 IO: TAddressableChannel16; 40 Memory: TAddressableChannel16; 36 41 Terminated: Boolean; 37 42 A: Word; … … 42 47 procedure Run; 43 48 procedure Step; 49 constructor Create; 50 destructor Destroy; override; 51 end; 52 53 TCpu = class 54 BitWidth: TBitWidth; 55 Cpu8: TCpu8; 56 Cpu16: TCpu16; 57 end; 58 59 TRegMulti = record 60 case Byte of 61 0: (ValueByte: Byte); 62 1: (ValueWord: Word); 63 end; 64 65 { TCpuMulti } 66 67 TCpuMulti = class 68 private 69 public 70 IO: TAddressableChannelMulti; 71 Memory: TAddressableChannelMulti; 72 Terminated: Boolean; 73 A: TRegMulti; 74 PC: TRegMulti; 75 BitWidth: TBitWidth; 76 function ReadProg8: Byte; 77 function ReadProg16: Word; 78 procedure Reset; 79 procedure Run; 80 procedure Step; 81 constructor Create; 82 destructor Destroy; override; 44 83 end; 45 84 46 85 47 86 implementation 87 88 { TCpuMulti } 89 90 function TCpuMulti.ReadProg8: Byte; 91 begin 92 case BitWidth of 93 bw8: begin 94 Result := Memory.ReadA8D8(PC.ValueByte); 95 Inc(PC.ValueByte); 96 end; 97 bw16: begin 98 Result := Memory.ReadA16D8(PC.ValueWord); 99 Inc(PC.ValueWord); 100 end; 101 end; 102 end; 103 104 function TCpuMulti.ReadProg16: Word; 105 begin 106 case BitWidth of 107 //bw8: begin 108 // Result := Memory.ReadA8D16(PC.ValueByte); 109 // Inc(PC.ValueByte); 110 //end; 111 bw16: begin 112 Result := Memory.ReadA16D16(PC.ValueWord); 113 Inc(PC.ValueWord); 114 end; 115 end; 116 end; 117 118 procedure TCpuMulti.Reset; 119 begin 120 Terminated := False; 121 PC.ValueWord := 0; 122 end; 123 124 procedure TCpuMulti.Run; 125 begin 126 while not Terminated do 127 Step; 128 end; 129 130 procedure TCpuMulti.Step; 131 var 132 Instruction: TInstruction; 133 begin 134 Instruction := TInstruction(ReadProg8); 135 case Instruction of 136 inNop: ; 137 inHalt: Terminated := True; 138 inLoadImmediate8: A.ValueByte := ReadProg8; 139 inLoadImmediate16: A.ValueWord := ReadProg16; 140 inLoadImmediate: case BitWidth of 141 bw8: A.ValueByte := ReadProg8; 142 bw16: A.ValueWord := ReadProg16; 143 end; 144 inLoad8: case BitWidth of 145 bw8: A.ValueByte := Memory.ReadA8D8(ReadProg8); 146 bw16: A.ValueByte := Memory.ReadA16D8(ReadProg16); 147 end; 148 inLoad16: case BitWidth of 149 //bw8: A.ValueWord := Memory.ReadA8D16(ReadProg8); 150 bw16: A.ValueWord := Memory.ReadA16D16(ReadProg16); 151 end; 152 inLoad: case BitWidth of 153 bw8: A.ValueByte := Memory.ReadA8D8(ReadProg8); 154 bw16: A.ValueWord := Memory.ReadA16D16(ReadProg16); 155 end; 156 inStore8: case BitWidth of 157 bw8: Memory.WriteA8D8(ReadProg8, A.ValueByte); 158 bw16: Memory.WriteA16D8(ReadProg16, A.ValueByte); 159 end; 160 inStore16: case BitWidth of 161 //bw8: Memory.WriteA8D16(ReadProg8, A.ValueWord); 162 bw16: Memory.WriteA16D16(ReadProg16, A.ValueWord); 163 end; 164 inStore: case BitWidth of 165 bw8: Memory.WriteA8D8(ReadProg8, A.ValueByte); 166 bw16: Memory.WriteA16D16(ReadProg16, A.ValueWord); 167 end; 168 inInput8: case BitWidth of 169 bw8: A.ValueByte := IO.ReadA8D8(ReadProg8); 170 bw16: A.ValueByte := IO.ReadA16D8(ReadProg16); 171 end; 172 inInput16: case BitWidth of 173 //bw8: A.ValueWord := IO.ReadA8D16(ReadProg8); 174 bw16: A.ValueWord := IO.ReadA16D16(ReadProg16); 175 end; 176 inInput: case BitWidth of 177 bw8: A.ValueByte := IO.ReadA8D8(ReadProg8); 178 bw16: A.ValueWord := IO.ReadA16D16(ReadProg16); 179 end; 180 inOutput8: case BitWidth of 181 bw8: IO.WriteA8D8(ReadProg8, A.ValueByte); 182 bw16: IO.WriteA16D8(ReadProg16, A.ValueWord); 183 end; 184 inOutput16: case BitWidth of 185 //bw8: IO.WriteA8D16(ReadProg8, A.ValueWord); 186 bw16: IO.WriteA16D16(ReadProg16, A.ValueWord); 187 end; 188 inOutput: case BitWidth of 189 bw8: IO.WriteA8D8(ReadProg8, A.ValueByte); 190 bw16: IO.WriteA16D16(ReadProg16, A.ValueWord); 191 end; 192 inJump: case BitWidth of 193 bw8: PC.ValueByte := ReadProg8; 194 bw16: PC.ValueWord := ReadProg16; 195 end; 196 end; 197 end; 198 199 constructor TCpuMulti.Create; 200 begin 201 IO := TAddressableChannelMulti.Create; 202 Memory := TAddressableChannelMulti.Create; 203 end; 204 205 destructor TCpuMulti.Destroy; 206 begin 207 FreeAndNil(IO); 208 FreeAndNil(Memory); 209 inherited; 210 end; 48 211 49 212 { TCpu16 } … … 58 221 begin 59 222 Result := Memory.Read16(PC); 60 Inc(PC, 2);223 Inc(PC, SizeOf(Word)); 61 224 end; 62 225 … … 79 242 Instruction := TInstruction(ReadProg8); 80 243 case Instruction of 244 inNop: ; 81 245 inHalt: Terminated := True; 82 inLoadImmediate8: A := ReadProg8;246 inLoadImmediate8: A := (A and $ff00) or ReadProg8; 83 247 inLoadImmediate16: A := ReadProg16; 84 inLoad8: A := Memory.Read8(ReadProg16); 248 inLoadImmediate: A := ReadProg16; 249 inLoad8: A := (A and $ff00) or Memory.Read8(ReadProg16); 85 250 inLoad16: A := Memory.Read16(ReadProg16); 251 inLoad: A := Memory.Read16(ReadProg16); 86 252 inStore8: Memory.Write8(ReadProg16, A); 87 253 inStore16: Memory.Write16(ReadProg16, A); 88 inInput8: A := IO.Read8(ReadProg16); 254 inStore: Memory.Write16(ReadProg16, A); 255 inInput8: A := (A and $ff00) or IO.Read8(ReadProg16); 89 256 inInput16: A := IO.Read16(ReadProg16); 257 inInput: A := IO.Read16(ReadProg16); 90 258 inOutput8: IO.Write8(ReadProg16, A); 91 259 inOutput16: IO.Write16(ReadProg16, A); 260 inOutput: IO.Write16(ReadProg16, A); 92 261 inJump: PC := ReadProg16; 93 262 end; 263 end; 264 265 constructor TCpu16.Create; 266 begin 267 IO := TAddressableChannel16.Create; 268 Memory := TAddressableChannel16.Create; 269 end; 270 271 destructor TCpu16.Destroy; 272 begin 273 FreeAndNil(IO); 274 FreeAndNil(Memory); 275 inherited; 94 276 end; 95 277 … … 120 302 Instruction := TInstruction(ReadProg8); 121 303 case Instruction of 122 inLoadImmediate8: A := ReadProg8; 123 inLoad8: A := Memory.Read8(ReadProg8); 124 inStore8: Memory.Write8(ReadProg8, A); 125 inInput8: A := IO.Read8(ReadProg8); 126 inOutput8: IO.Write8(ReadProg8, A); 304 inNop: ; 305 inLoadImmediate, inLoadImmediate8: A := ReadProg8; 306 inLoad, inLoad8: A := Memory.Read8(ReadProg8); 307 inStore, inStore8: Memory.Write8(ReadProg8, A); 308 inInput, inInput8: A := IO.Read8(ReadProg8); 309 inOutput, inOutput8: IO.Write8(ReadProg8, A); 127 310 inHalt: Terminated := True; 128 311 inJump: PC := ReadProg8; … … 130 313 end; 131 314 315 constructor TCpu8.Create; 316 begin 317 IO := TAddressableChannel8.Create; 318 Memory := TAddressableChannel8.Create; 319 end; 320 321 destructor TCpu8.Destroy; 322 begin 323 FreeAndNil(IO); 324 FreeAndNil(Memory); 325 inherited; 326 end; 327 132 328 end. 133 329 -
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 -
branches/simple/Forms/FormConsole.pas
r41 r42 4 4 5 5 uses 6 Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls ;6 Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, Device; 7 7 8 8 type … … 10 10 { TFormConsole } 11 11 12 TFormConsole = class(TForm )12 TFormConsole = class(TFormDevice) 13 13 Memo1: TMemo; 14 14 public -
branches/simple/Forms/FormMain.pas
r41 r42 43 43 {$R *.lfm} 44 44 45 uses 46 Screen, Channel; 47 45 48 { TFormMain } 46 49 … … 49 52 FormScreen := TFormScreen.Create(nil); 50 53 FormConsole := TFormConsole.Create(nil); 51 InitMachine 16;54 InitMachine8; 52 55 end; 53 56 … … 66 69 FreeAndNil(FormScreen); 67 70 FreeAndNil(FormConsole); 68 FreeAndNil(Machine8); 71 if Assigned(Machine8) then FreeAndNil(Machine8); 72 if Assigned(Machine16) then FreeAndNil(Machine16); 69 73 end; 70 74 … … 80 84 Console.OnWrite := FormConsole.ConsoleWrite; 81 85 Screen.OnChange := FormScreen.ScreenChange; 82 FormScreen. Machine := Machine8;86 FormScreen.Screen := TScreen.Create(bw8, Machine8.Screen, nil); 83 87 with Memory do begin 84 88 // LD A8, 'A' … … 90 94 // LD A8, 'A' 91 95 WritePos8(Byte(inLoadImmediate8)); 92 WritePos8(Ord('H')); 93 // OUT (0), A8 94 WritePos8(Byte(inOutput8)); 95 WritePos8(1); 96 WritePos8(Ord('B')); 96 97 // OUT (0), A8 97 98 WritePos8(Byte(inOutput8)); … … 110 111 Console.OnWrite := FormConsole.ConsoleWrite; 111 112 Screen.OnChange := FormScreen.ScreenChange; 112 FormScreen. Machine := Machine16;113 FormScreen.Screen := TScreen.Create(bw16, nil, Machine16.Screen); 113 114 with Memory do begin 114 115 // LD A8, 'A' … … 122 123 WritePos16(Ord('H')); 123 124 // OUT8 (0), A8 124 WritePos8(Byte(inOutput 8));125 WritePos8(Byte(inOutput16)); 125 126 WritePos16(1); 126 127 // HALT -
branches/simple/Forms/FormScreen.pas
r41 r42 4 4 5 5 uses 6 Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, Machine; 6 Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, Screen, 7 Channel, Device; 7 8 8 9 type … … 10 11 { TFormScreen } 11 12 12 TFormScreen = class(TForm )13 TFormScreen = class(TFormDevice) 13 14 Image1: TImage; 14 15 TimerDraw: TTimer; … … 17 18 DrawPending: Boolean; 18 19 public 19 Machine: TMachine;20 Screen: TScreen; 20 21 procedure ScreenChange(Sender: TObject); 21 22 end; … … 36 37 if DrawPending then begin 37 38 DrawPending := False; 38 if Machine is TMachine16then39 with TMachine16(Machine).Screendo begin39 if Screen.BitWidth = bw8 then 40 with Screen.Screen8 do begin 40 41 Image1.Picture.Bitmap.SetSize(Width * CharSize, Height * CharSize); 41 42 Image1.Picture.Bitmap.Canvas.FillRect(0, 0, Image1.Picture.Bitmap.Width, … … 46 47 Chr(Memory.Read8(Y * Width + X))); 47 48 end else 48 if Machine is TMachine8then49 with TMachine8(Machine).Screendo begin49 if Screen.BitWidth = bw16 then 50 with Screen.Screen16 do begin 50 51 Image1.Picture.Bitmap.SetSize(Width * CharSize, Height * CharSize); 51 52 Image1.Picture.Bitmap.Canvas.FillRect(0, 0, Image1.Picture.Bitmap.Width, -
branches/simple/Machine.pas
r41 r42 4 4 5 5 uses 6 Classes, SysUtils, Cpu, Memory, DeviceMa pper, Console, Screen;6 Classes, SysUtils, Cpu, Memory, DeviceManager, Console, Screen; 7 7 8 8 type … … 25 25 procedure SetPoweredOn(AValue: Boolean); override; 26 26 public 27 DeviceMa pper: TDeviceMapper8;27 DeviceManager: TDeviceManager8; 28 28 Memory: TMemory8; 29 Console: TConsole ;29 Console: TConsole8; 30 30 Cpu: TCpu8; 31 31 Screen: TScreen8; … … 41 41 procedure SetPoweredOn(AValue: Boolean); override; 42 42 public 43 DeviceMa pper: TDeviceMapper16;43 DeviceManager: TDeviceManager16; 44 44 Memory: TMemory16; 45 Console: TConsole ;45 Console: TConsole16; 46 46 Cpu: TCpu16; 47 47 Screen: TScreen16; … … 72 72 constructor TMachine16.Create; 73 73 begin 74 DeviceMapper := TDeviceMapper16.Create; 75 Console := TConsole.Create; 76 Console.RegisterMapper16(DeviceMapper); 74 Cpu := TCpu16.Create; 75 Console := TConsole16.Create; 77 76 Screen := TScreen16.Create; 78 Screen.RegisterMapper16(DeviceMapper); 77 DeviceManager := TDeviceManager16.Create; 78 DeviceManager.RegisterDevice(Console); 79 DeviceManager.RegisterDevice(Screen); 80 DeviceManager.SetDataBus(Cpu.IO); 79 81 Memory := TMemory16.Create; 80 82 Memory.Size := 65535; 81 Cpu := TCpu16.Create; 82 Cpu.IO := DeviceMapper; 83 Cpu.Memory := Memory; 83 Memory.SetDataBus(Cpu.Memory); 84 84 end; 85 85 … … 87 87 begin 88 88 FreeAndNil(Cpu); 89 FreeAndNil(DeviceMa pper);89 FreeAndNil(DeviceManager); 90 90 FreeAndNil(Console); 91 91 FreeAndNil(Memory); … … 105 105 constructor TMachine8.Create; 106 106 begin 107 DeviceMapper := TDeviceMapper8.Create; 108 Console := TConsole.Create; 109 Console.RegisterMapper8(DeviceMapper); 107 Cpu := TCpu8.Create; 108 Console := TConsole8.Create; 110 109 Screen := TScreen8.Create; 111 Screen.RegisterMapper8(DeviceMapper); 110 DeviceManager := TDeviceManager8.Create; 111 DeviceManager.RegisterDevice(Console); 112 DeviceManager.RegisterDevice(Screen); 113 DeviceManager.SetDataBus(Cpu.IO); 112 114 Memory := TMemory8.Create; 113 115 Memory.Size := 255; 114 Cpu := TCpu8.Create; 115 Cpu.IO := DeviceMapper; 116 Cpu.Memory := Memory; 116 Memory.SetDataBus(Cpu.Memory); 117 117 end; 118 118 … … 120 120 begin 121 121 FreeAndNil(Cpu); 122 FreeAndNil(DeviceMa pper);122 FreeAndNil(DeviceManager); 123 123 FreeAndNil(Console); 124 124 FreeAndNil(Memory); -
branches/simple/Memory.pas
r40 r42 4 4 5 5 uses 6 Classes, SysUtils, DataBus;6 Classes, SysUtils, Channel, Device; 7 7 8 8 type 9 10 { TMemoryMulti } 11 12 TMemoryMulti = class 13 private 14 Memory: array of Byte; 15 procedure SetSize(Value: QWord); 16 function GetSize: QWord; 17 public 18 Position: QWord; 19 property Size: QWord read GetSize write SetSize; 20 end; 21 9 22 { TMemory8 } 10 23 11 TMemory8 = class(TD ataBus8)24 TMemory8 = class(TDevice8) 12 25 private 13 26 Memory: array of Byte; … … 18 31 procedure WritePos8(Data: Byte); 19 32 function ReadPos8: Byte; 20 procedure Write8(Address: Byte; Data: Byte); override; 21 function Read8(Address: Byte): Byte; override; 33 procedure Write8(Address: Byte; Data: Byte); 34 function Read8(Address: Byte): Byte; 35 procedure SetDataBus(Channel: TAddressableChannel8); override; 22 36 property Size: Byte read GetSize write SetSize; 23 37 end; … … 25 39 { TMemory16 } 26 40 27 TMemory16 = class(TD ataBus16)41 TMemory16 = class(TDevice16) 28 42 private 29 43 Memory: array of Byte; … … 36 50 procedure WritePos8(Data: Byte); 37 51 procedure WritePos16(Data: Word); 38 function Read8(Address: Word): Byte; override; 39 function Read16(Address: Word): Word; override; 40 procedure Write8(Address: Word; Data: Byte); override; 41 procedure Write16(Address: Word; Data: Word); override; 52 function Read8(Address: Word): Byte; 53 function Read16(Address: Word): Word; 54 procedure Write8(Address: Word; Data: Byte); 55 procedure Write16(Address: Word; Data: Word); 56 procedure SetDataBus(Channel: TAddressableChannel16); override; 42 57 property Size: Word read GetSize write SetSize; 43 58 end; 44 59 60 { TMemory64 } 61 62 TMemory64 = class(TDevice64) 63 private 64 Memory: array of Byte; 65 procedure SetSize(Value: QWord); 66 function GetSize: QWord; 67 public 68 Position: QWord; 69 function ReadPos8: Byte; 70 function ReadPos16: Word; 71 function ReadPos32: DWord; 72 function ReadPos64: QWord; 73 procedure WritePos8(Data: Byte); 74 procedure WritePos16(Data: Word); 75 procedure WritePos32(Data: Word); 76 procedure WritePos64(Data: Word); 77 function Read8(Address: QWord): Byte; 78 function Read16(Address: QWord): Word; 79 function Read32(Address: QWord): DWord; 80 function Read64(Address: QWord): QWord; 81 procedure Write8(Address: QWord; Data: Byte); 82 procedure Write16(Address: QWord; Data: Word); 83 procedure Write32(Address: QWord; Data: DWord); 84 procedure Write64(Address: QWord; Data: QWord); 85 procedure SetDataBus(Channel: TAddressableChannel64); override; 86 property Size: QWord read GetSize write SetSize; 87 end; 88 89 { TMemory } 90 91 TMemory = class(TDevice) 92 BitWidth: TBitWidth; 93 Memory8: TMemory8; 94 Memory16: TMemory16; 95 end; 96 45 97 46 98 implementation 99 100 { TMemory64 } 101 102 procedure TMemory64.SetSize(Value: QWord); 103 begin 104 105 end; 106 107 function TMemory64.GetSize: QWord; 108 begin 109 110 end; 111 112 function TMemory64.ReadPos8: Byte; 113 begin 114 115 end; 116 117 function TMemory64.ReadPos16: Word; 118 begin 119 120 end; 121 122 function TMemory64.ReadPos32: DWord; 123 begin 124 125 end; 126 127 function TMemory64.ReadPos64: QWord; 128 begin 129 130 end; 131 132 procedure TMemory64.WritePos8(Data: Byte); 133 begin 134 135 end; 136 137 procedure TMemory64.WritePos16(Data: Word); 138 begin 139 140 end; 141 142 procedure TMemory64.WritePos32(Data: Word); 143 begin 144 145 end; 146 147 procedure TMemory64.WritePos64(Data: Word); 148 begin 149 150 end; 151 152 function TMemory64.Read8(Address: QWord): Byte; 153 begin 154 155 end; 156 157 function TMemory64.Read16(Address: QWord): Word; 158 begin 159 160 end; 161 162 function TMemory64.Read32(Address: QWord): DWord; 163 begin 164 165 end; 166 167 function TMemory64.Read64(Address: QWord): QWord; 168 begin 169 170 end; 171 172 procedure TMemory64.Write8(Address: QWord; Data: Byte); 173 begin 174 175 end; 176 177 procedure TMemory64.Write16(Address: QWord; Data: Word); 178 begin 179 180 end; 181 182 procedure TMemory64.Write32(Address: QWord; Data: DWord); 183 begin 184 185 end; 186 187 procedure TMemory64.Write64(Address: QWord; Data: QWord); 188 begin 189 190 end; 191 192 procedure TMemory64.SetDataBus(Channel: TAddressableChannel64); 193 begin 194 inherited SetDataBus(Channel); 195 end; 196 197 { TMemoryMulti } 198 199 procedure TMemoryMulti.SetSize(Value: QWord); 200 begin 201 SetLength(Memory, Size); 202 end; 203 204 function TMemoryMulti.GetSize: QWord; 205 begin 206 Result := Length(Memory); 207 end; 47 208 48 209 { TMemory16 } … … 103 264 end; 104 265 266 procedure TMemory16.SetDataBus(Channel: TAddressableChannel16); 267 begin 268 Channel.Read8 := Read8; 269 Channel.Read16 := Read16; 270 Channel.Write8 := Write8; 271 Channel.Write16 := Write16; 272 end; 273 105 274 { TMemory8 } 106 275 … … 137 306 end; 138 307 308 procedure TMemory8.SetDataBus(Channel: TAddressableChannel8); 309 begin 310 Channel.Write8 := Write8; 311 Channel.Read8 := Read8; 312 end; 139 313 140 314 end. -
branches/simple/simple.lpi
r41 r42 26 26 <RequiredPackages> 27 27 <Item> 28 <PackageName Value="SynEdit"/> 29 </Item> 30 <Item> 28 31 <PackageName Value="LCL"/> 29 32 </Item> … … 50 53 </Unit> 51 54 <Unit> 52 <Filename Value=" DataBus.pas"/>55 <Filename Value="Channel.pas"/> 53 56 <IsPartOfProject Value="True"/> 54 57 </Unit> … … 58 61 </Unit> 59 62 <Unit> 60 <Filename Value="DeviceMa pper.pas"/>63 <Filename Value="DeviceManager.pas"/> 61 64 <IsPartOfProject Value="True"/> 62 65 </Unit> 63 66 <Unit> 64 <Filename Value="Device .pas"/>67 <Filename Value="Devices/Device.pas"/> 65 68 <IsPartOfProject Value="True"/> 66 69 </Unit> 67 70 <Unit> 68 <Filename Value=" Console.pas"/>71 <Filename Value="Devices/Console.pas"/> 69 72 <IsPartOfProject Value="True"/> 70 73 </Unit> 71 74 <Unit> 72 <Filename Value=" Screen.pas"/>75 <Filename Value="Devices/Screen.pas"/> 73 76 <IsPartOfProject Value="True"/> 74 77 </Unit> … … 87 90 <ResourceBaseClass Value="Form"/> 88 91 </Unit> 92 <Unit> 93 <Filename Value="Assembler.pas"/> 94 <IsPartOfProject Value="True"/> 95 </Unit> 96 <Unit> 97 <Filename Value="Parser.pas"/> 98 <IsPartOfProject Value="True"/> 99 </Unit> 100 <Unit> 101 <Filename Value="Instructions.pas"/> 102 <IsPartOfProject Value="True"/> 103 </Unit> 104 <Unit> 105 <Filename Value="Message.pas"/> 106 <IsPartOfProject Value="True"/> 107 </Unit> 108 <Unit> 109 <Filename Value="Forms/FormAssembler.pas"/> 110 <IsPartOfProject Value="True"/> 111 <ComponentName Value="FormAssembler"/> 112 <HasResources Value="True"/> 113 <ResourceBaseClass Value="Form"/> 114 </Unit> 115 <Unit> 116 <Filename Value="Forms/FormDevices.pas"/> 117 <IsPartOfProject Value="True"/> 118 <ComponentName Value="FormDevices"/> 119 <HasResources Value="True"/> 120 <ResourceBaseClass Value="Form"/> 121 </Unit> 122 <Unit> 123 <Filename Value="Forms/FormDisassembler.pas"/> 124 <IsPartOfProject Value="True"/> 125 <ComponentName Value="FormDisassembler"/> 126 <ResourceBaseClass Value="Form"/> 127 </Unit> 128 <Unit> 129 <Filename Value="Forms/FormMessages.pas"/> 130 <IsPartOfProject Value="True"/> 131 <ComponentName Value="FormMessages"/> 132 <ResourceBaseClass Value="Form"/> 133 </Unit> 134 <Unit> 135 <Filename Value="Forms/FormStorage.pas"/> 136 <IsPartOfProject Value="True"/> 137 <ComponentName Value="FormStorage"/> 138 <HasResources Value="True"/> 139 <ResourceBaseClass Value="Form"/> 140 </Unit> 141 <Unit> 142 <Filename Value="Pin.pas"/> 143 <IsPartOfProject Value="True"/> 144 </Unit> 145 <Unit> 146 <Filename Value="Forms/FormDevice.pas"/> 147 <IsPartOfProject Value="True"/> 148 </Unit> 149 <Unit> 150 <Filename Value="Devices/Storage.pas"/> 151 <IsPartOfProject Value="True"/> 152 </Unit> 89 153 </Units> 90 154 </ProjectOptions> … … 96 160 <SearchPaths> 97 161 <IncludeFiles Value="$(ProjOutDir)"/> 98 <OtherUnitFiles Value="Forms "/>162 <OtherUnitFiles Value="Forms;Devices"/> 99 163 <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/> 100 164 </SearchPaths> -
branches/simple/simple.lpr
r41 r42 11 11 {$ENDIF} 12 12 Interfaces, // this includes the LCL widgetset 13 Forms, FormMain, Cpu, Machine, DataBus, Memory, DeviceMapper, Device, Console, 14 Screen, FormScreen, FormConsole; 13 Forms, FormMain, Cpu, Machine, Channel, Memory, 14 DeviceManager, Device, Console, 15 Screen, Assembler, Parser, Instructions, Message, FormScreen, FormConsole, 16 FormAssembler, FormDevices, FormDisassembler, FormMessages, FormStorage, 17 Pin, FormDevice, Storage; 15 18 16 19 {$R *.res}
Note:
See TracChangeset
for help on using the changeset viewer.