Changeset 223 for branches/CpuSingleSize/UMachine.pas
- Timestamp:
- Jul 12, 2022, 10:43:40 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/CpuSingleSize/UMachine.pas
r220 r223 1 1 unit UMachine; 2 3 {$mode delphi}4 2 5 3 interface … … 9 7 10 8 type 11 TDeviceClass = (dcNone, dcKeyboard, dcMouse, dcStorage, dcScreen, dcConsole); 9 TDeviceClass = (dcNone, dcKeyboard, dcMouse, dcStorage, dcScreen, dcConsole, 10 dcTimer); 12 11 TDeviceClassSet = set of TDeviceClass; 13 12 … … 35 34 InterruptVector: Integer; 36 35 Form: TFormDevice; 36 procedure PulseInterrupt; 37 37 procedure OutputHandler(Port, Data: TInteger); virtual; 38 38 function InputHandler(Port: TInteger): TInteger; virtual; … … 64 64 TConsoleOutputPort = (opConsoleWriteChar); 65 65 66 { T Console }67 68 T Console = class(TDevice)66 { TDeviceConsole } 67 68 TDeviceConsole = class(TDevice) 69 69 Lock: TCriticalSection; 70 70 InputBuffer: TQueue<TInteger>; … … 79 79 TScreenOutputPort = (opScreenSetAddr, opScreenWrite); 80 80 81 { T Screen }82 83 T Screen = class(TDevice)81 { TDeviceScreen } 82 83 TDeviceScreen = class(TDevice) 84 84 private 85 85 FSize: TPoint; … … 97 97 TKeyboardInputPort = (ipKeyboardRead); 98 98 99 { T Keyboard }100 101 T Keyboard = class(TDevice)99 { TDeviceKeyboard } 100 101 TDeviceKeyboard = class(TDevice) 102 102 constructor Create; 103 103 function ReadKey: TInteger; … … 108 108 TStorageOutputPort = (opStorageSetAddr, opStorageWrite); 109 109 110 { T Storage }111 112 T Storage = class(TDevice)110 { TDeviceStorage } 111 112 TDeviceStorage = class(TDevice) 113 113 public 114 114 F: TFileStream; … … 119 119 end; 120 120 121 { TMouse } 122 123 TMouse = class(TDevice) 124 constructor Create; 121 { TDeviceMouse } 122 123 TDeviceMouse = class(TDevice) 124 constructor Create; 125 end; 126 127 TTimerOutputPort = (opTimerSetInterval, opTimerSetEnabled); 128 { TDeviceTimer } 129 130 TDeviceTimer = class(TDevice) 131 Interval: Integer; 132 Enabled: Boolean; 133 constructor Create; 134 procedure OutputHandler(Port, Data: TInteger); override; 125 135 end; 126 136 … … 144 154 145 155 const 146 DeviceClassText: array[TDeviceClass] of string = ('None', 'Keyboard', 'Mouse', 'Storage', 'Screen', 'Console' );156 DeviceClassText: array[TDeviceClass] of string = ('None', 'Keyboard', 'Mouse', 'Storage', 'Screen', 'Console', 'Timer'); 147 157 148 158 149 159 implementation 160 161 { TDeviceTimer } 162 163 constructor TDeviceTimer.Create; 164 begin 165 DeviceClass := dcTimer; 166 end; 167 168 procedure TDeviceTimer.OutputHandler(Port, Data: TInteger); 169 begin 170 case TTimerOutputPort(Port) of 171 opTimerSetInterval: Interval := Data; 172 opTimerSetEnabled: Enabled := Data > 0; 173 end; 174 end; 150 175 151 176 { TDeviceManager } … … 225 250 { TDevice } 226 251 252 procedure TDevice.PulseInterrupt; 253 begin 254 Cpu.Interrupt(InterruptVector); 255 end; 256 227 257 procedure TDevice.OutputHandler(Port, Data: TInteger); 228 258 begin … … 234 264 end; 235 265 236 { T Mouse }237 238 constructor T Mouse.Create;266 { TDeviceMouse } 267 268 constructor TDeviceMouse.Create; 239 269 begin 240 270 DeviceClass := dcMouse; 241 271 end; 242 272 243 { T Storage }244 245 constructor T Storage.Create;273 { TDeviceStorage } 274 275 constructor TDeviceStorage.Create; 246 276 begin 247 277 DeviceClass := dcStorage; 248 278 end; 249 279 250 procedure T Storage.OutputHandler(Port, Data: TInteger);280 procedure TDeviceStorage.OutputHandler(Port, Data: TInteger); 251 281 begin 252 282 case TStorageOutputPort(Port) of … … 258 288 end; 259 289 260 function T Storage.InputHandler(Port: TInteger): TInteger;290 function TDeviceStorage.InputHandler(Port: TInteger): TInteger; 261 291 begin 262 292 case TStorageInputPort(Port) of … … 268 298 end; 269 299 270 { T Console }271 272 constructor T Console.Create;300 { TDeviceConsole } 301 302 constructor TDeviceConsole.Create; 273 303 begin 274 304 DeviceClass := dcConsole; … … 278 308 end; 279 309 280 destructor T Console.Destroy;310 destructor TDeviceConsole.Destroy; 281 311 begin 282 312 InputBuffer.Free; … … 286 316 end; 287 317 288 procedure T Console.OutputHandler(Port, Data: TInteger);318 procedure TDeviceConsole.OutputHandler(Port, Data: TInteger); 289 319 begin 290 320 case TConsoleOutputPort(Port) of … … 300 330 end; 301 331 302 function T Console.InputHandler(Port: TInteger): TInteger;332 function TDeviceConsole.InputHandler(Port: TInteger): TInteger; 303 333 begin 304 334 case TConsoleInputPort(Port) of … … 324 354 end; 325 355 326 { T Screen }327 328 procedure T Screen.SetSize(AValue: TPoint);356 { TDeviceScreen } 357 358 procedure TDeviceScreen.SetSize(AValue: TPoint); 329 359 begin 330 360 if FSize = AValue then Exit; … … 333 363 end; 334 364 335 constructor T Screen.Create;365 constructor TDeviceScreen.Create; 336 366 begin 337 367 DeviceClass := dcScreen; … … 339 369 end; 340 370 341 procedure T Screen.OutputHandler(Port, Data: TInteger);371 procedure TDeviceScreen.OutputHandler(Port, Data: TInteger); 342 372 begin 343 373 case TScreenOutputPort(Port) of … … 351 381 end; 352 382 353 function T Screen.InputHandler(Port: TInteger): TInteger;383 function TDeviceScreen.InputHandler(Port: TInteger): TInteger; 354 384 begin 355 385 case TScreenInputPort(Port) of … … 359 389 end; 360 390 361 { T Keyboard }362 363 function T Keyboard.ReadKey: TInteger;391 { TDeviceKeyboard } 392 393 function TDeviceKeyboard.ReadKey: TInteger; 364 394 begin 365 395 Result := 0; 366 396 end; 367 397 368 function T Keyboard.InputHandler(Port: TInteger): TInteger;398 function TDeviceKeyboard.InputHandler(Port: TInteger): TInteger; 369 399 begin 370 400 case TKeyboardInputPort(Port) of … … 373 403 end; 374 404 375 constructor T Keyboard.Create;405 constructor TDeviceKeyboard.Create; 376 406 begin 377 407 DeviceClass := dcKeyboard; … … 404 434 procedure TMachine.InitDevices; 405 435 var 406 Screen: T Screen;407 Keyboard: T Keyboard;408 Console: T Console;409 Storage: T Storage;410 Mouse: T Mouse;436 Screen: TDeviceScreen; 437 Keyboard: TDeviceKeyboard; 438 Console: TDeviceConsole; 439 Storage: TDeviceStorage; 440 Mouse: TDeviceMouse; 411 441 DeviceManager: TDeviceManager; 442 Timer: TDeviceTimer; 412 443 begin 413 444 DeviceManager := TDeviceManager.Create; … … 415 446 RegisterDevice(DeviceManager); 416 447 417 Console := T Console.Create;448 Console := TDeviceConsole.Create; 418 449 RegisterDevice(Console); 419 450 Console.InterruptVector := 1; 420 451 421 Keyboard := TKeyboard.Create; 452 Keyboard := TDeviceKeyboard.Create; 453 Keyboard.InterruptVector := 4; 422 454 RegisterDevice(Keyboard); 423 455 424 Screen := T Screen.Create;456 Screen := TDeviceScreen.Create; 425 457 RegisterDevice(Screen); 426 458 427 Storage := T Storage.Create;459 Storage := TDeviceStorage.Create; 428 460 RegisterDevice(Storage); 429 461 430 Storage := T Storage.Create;462 Storage := TDeviceStorage.Create; 431 463 RegisterDevice(Storage); 432 464 433 Mouse := TMouse.Create; 465 Mouse := TDeviceMouse.Create; 466 Mouse.InterruptVector := 3; 434 467 RegisterDevice(Mouse); 468 469 Timer := TDeviceTimer.Create; 470 Timer.InterruptVector := 2; 471 RegisterDevice(Timer); 435 472 end; 436 473 437 474 procedure TMachine.PowerOn; 438 475 begin 439 Cpu. Data:= Memory.Data;476 Cpu.Memory := Memory.Data; 440 477 Cpu.Start; 441 478 end;
Note:
See TracChangeset
for help on using the changeset viewer.