- Timestamp:
- Jul 12, 2022, 11:51:47 PM (2 years ago)
- Location:
- branches/UltimatOS
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/UltimatOS/Forms/UFormMain.lfm
r32 r34 1 1 object FormMain: TFormMain 2 2 Left = 227 3 Height = 7073 Height = 814 4 4 Top = 205 5 Width = 9985 Width = 1150 6 6 Caption = 'UltimatOS' 7 ClientHeight = 7078 ClientWidth = 9989 DesignTimePPI = 1 257 ClientHeight = 814 8 ClientWidth = 1150 9 DesignTimePPI = 144 10 10 OnCreate = FormCreate 11 11 OnDestroy = FormDestroy 12 12 OnKeyUp = FormKeyUp 13 13 OnShow = FormShow 14 LCLVersion = '2.2. 0.4'14 LCLVersion = '2.2.2.0' 15 15 object PaintBox1: TPaintBox 16 Left = 817 Height = 48018 Top = 819 Width = 64016 Left = 9 17 Height = 553 18 Top = 9 19 Width = 737 20 20 OnMouseMove = PaintBox1MouseMove 21 21 OnPaint = PaintBox1Paint 22 22 end 23 23 object ButtonStart: TButton 24 Left = 825 Height = 3 326 Top = 49627 Width = 9824 Left = 9 25 Height = 38 26 Top = 571 27 Width = 113 28 28 Caption = 'Start' 29 29 OnClick = ButtonStartClick … … 31 31 end 32 32 object MemoCode: TMemo 33 Left = 65634 Height = 47735 Top = 936 Width = 3 2833 Left = 756 34 Height = 550 35 Top = 10 36 Width = 378 37 37 ScrollBars = ssAutoBoth 38 38 TabOrder = 1 39 39 end 40 40 object Label1: TLabel 41 Left = 66242 Height = 2 243 Top = 5 0044 Width = 6841 Left = 763 42 Height = 26 43 Top = 576 44 Width = 79 45 45 Caption = 'Instrukcí:' 46 ParentColor = False 46 47 end 47 48 object ButtonMemory: TButton 48 Left = 55049 Height = 3 350 Top = 49651 Width = 9849 Left = 634 50 Height = 38 51 Top = 571 52 Width = 113 52 53 Caption = 'Memory' 53 54 OnClick = ButtonMemoryClick … … 55 56 end 56 57 object ButtonStop: TButton 57 Left = 1 1258 Height = 3 359 Top = 49660 Width = 9858 Left = 129 59 Height = 38 60 Top = 571 61 Width = 113 61 62 Caption = 'Stop' 62 63 OnClick = ButtonStopClick … … 64 65 end 65 66 object ButtonRestart: TButton 66 Left = 2 1667 Height = 3 368 Top = 49669 Width = 9867 Left = 249 68 Height = 38 69 Top = 571 70 Width = 113 70 71 Caption = 'Restart' 71 72 OnClick = ButtonRestartClick … … 73 74 end 74 75 object ButtonCompile: TButton 75 Left = 876 Height = 3 377 Top = 53678 Width = 9876 Left = 9 77 Height = 38 78 Top = 617 79 Width = 113 79 80 Caption = 'Compile' 80 81 OnClick = ButtonCompileClick 81 82 TabOrder = 5 82 83 end 84 object Label2: TLabel 85 Left = 763 86 Height = 26 87 Top = 632 88 Width = 55 89 Caption = 'Label2' 90 ParentColor = False 91 end 83 92 object Timer1: TTimer 84 93 Interval = 20 85 94 OnTimer = Timer1Timer 86 Left = 190 87 Top = 542 95 Left = 219 96 Top = 624 97 end 98 object Timer2: TTimer 99 OnTimer = Timer2Timer 100 Left = 768 101 Top = 664 88 102 end 89 103 end -
branches/UltimatOS/Forms/UFormMain.pas
r32 r34 18 18 ButtonRestart: TButton; 19 19 Label1: TLabel; 20 Label2: TLabel; 20 21 MemoCode: TMemo; 21 22 PaintBox1: TPaintBox; 22 23 Timer1: TTimer; 24 Timer2: TTimer; 23 25 procedure ButtonCompileClick(Sender: TObject); 24 26 procedure ButtonMemoryClick(Sender: TObject); … … 34 36 procedure PaintBox1Paint(Sender: TObject); 35 37 procedure Timer1Timer(Sender: TObject); 38 procedure Timer2Timer(Sender: TObject); 36 39 private 40 LastTicks: Integer; 37 41 procedure InitProgram; 38 42 procedure UpdateInterface; … … 143 147 end; 144 148 149 procedure TFormMain.Timer2Timer(Sender: TObject); 150 begin 151 Label2.Caption := 'Ticks/s: ' + IntToStr(Machine.Cpu.ExecutedCount - LastTicks); 152 LastTicks := Machine.Cpu.ExecutedCount; 153 end; 154 145 155 procedure TFormMain.InitProgram; 146 156 begin -
branches/UltimatOS/UCpu.pas
r32 r34 21 21 22 22 TCpu = class; 23 TInstructionHandler = procedure of object; 23 24 24 25 { TCpuThread } … … 40 41 InterruptVector: Integer; 41 42 InterruptEnabled: Boolean; 43 FInstructionHandlers: array[TInstruction] of TInstructionHandler; 42 44 function GetRunning: Boolean; 43 function ReadByte: Byte; 44 function ReadAddress: TAddress; 45 function ReadData: TData; 46 procedure Push(Value: Integer); 47 function Pop: Integer; 45 function ReadByte: Byte; inline; 46 function ReadAddress: TAddress; inline; 47 function ReadData: TData; inline; 48 procedure Push(Value: Integer); inline; 49 function Pop: Integer; inline; 48 50 procedure SetRunning(AValue: Boolean); 51 procedure InitInstructions; 52 procedure InstructionNop; 53 procedure InstructionHalt; 54 procedure InstructionSet; 55 procedure InstructionInput; 56 procedure InstructionOutput; 57 procedure InstructionInc; 58 procedure InstructionDec; 59 procedure InstructionJp; 60 procedure InstructionJpnz; 61 procedure InstructionJpz; 62 procedure InstructionAdd; 63 procedure InstructionSub; 64 procedure InstructionCall; 65 procedure InstructionRet; 66 procedure InstructionPush; 67 procedure InstructionPop; 68 procedure InstructionCopy; 69 procedure InstructionShl; 70 procedure InstructionShr; 71 procedure InstructionLoad; 72 procedure InstructionLoadi; 73 procedure InstructionStore; 74 procedure InstructionMul; 75 procedure InstructionAnd; 76 procedure InstructionAndi; 77 procedure InstructionOr; 78 procedure InstructionXor; 79 procedure InstructionInt; 80 procedure InstructionReti; 81 procedure InstructionEnableInt; 82 procedure InstructionDisableInt; 49 83 public 50 84 ExecutedCount: Integer; … … 135 169 end; 136 170 171 procedure TCpu.InitInstructions; 172 begin 173 FInstructionHandlers[inNop] := InstructionNop; 174 FInstructionHandlers[inHalt] := InstructionHalt; 175 FInstructionHandlers[inSet] := InstructionSet; 176 FInstructionHandlers[inInput] := InstructionInput; 177 FInstructionHandlers[inOutput] := InstructionOutput; 178 FInstructionHandlers[inInc] := InstructionInc; 179 FInstructionHandlers[inDec] := InstructionDec; 180 FInstructionHandlers[inJp] := InstructionJp; 181 FInstructionHandlers[inJpz] := InstructionJpz; 182 FInstructionHandlers[inJpnz] := InstructionJpnz; 183 FInstructionHandlers[inAdd] := InstructionAdd; 184 FInstructionHandlers[inSub] := InstructionSub; 185 FInstructionHandlers[inCall] := InstructionCall; 186 FInstructionHandlers[inRet] := InstructionRet; 187 FInstructionHandlers[inPush] := InstructionPush; 188 FInstructionHandlers[inPop] := InstructionPop; 189 FInstructionHandlers[inCopy] := InstructionCopy; 190 FInstructionHandlers[inShl] := InstructionShl; 191 FInstructionHandlers[inShr] := InstructionShr; 192 FInstructionHandlers[inLoad] := InstructionLoad; 193 FInstructionHandlers[inLoadi] := InstructionLoadi; 194 FInstructionHandlers[inStore] := InstructionStore; 195 FInstructionHandlers[inMul] := InstructionMul; 196 FInstructionHandlers[inAnd] := InstructionAnd; 197 FInstructionHandlers[inAndi] := InstructionAndi; 198 FInstructionHandlers[inOr] := InstructionOr; 199 FInstructionHandlers[inXor] := InstructionXor; 200 FInstructionHandlers[inInt] := InstructionInt; 201 FInstructionHandlers[inReti] := InstructionReti; 202 FInstructionHandlers[inEnableInt] := InstructionEnableInt; 203 FInstructionHandlers[inDisableInt] := InstructionDisableInt; 204 end; 205 206 procedure TCpu.InstructionNop; 207 begin 208 // No operation 209 end; 210 211 procedure TCpu.InstructionHalt; 212 begin 213 Terminated := True; 214 end; 215 216 procedure TCpu.InstructionSet; 217 var 218 RegIndex: Byte; 219 begin 220 RegIndex := ReadByte; 221 R[RegIndex] := ReadData; 222 end; 223 224 procedure TCpu.InstructionInput; 225 var 226 RegIndex: Byte; 227 Address: TAddress; 228 begin 229 RegIndex := ReadByte; 230 Address := ReadAddress; 231 if Assigned(FOnInput) then R[RegIndex] := FOnInput(Address) 232 else R[RegIndex] := 0; 233 end; 234 235 procedure TCpu.InstructionOutput; 236 var 237 RegIndex: Byte; 238 Address: TAddress; 239 begin 240 Address := ReadAddress; 241 RegIndex := ReadByte; 242 if Assigned(FOnOutput) then FOnOutput(Address, R[RegIndex]); 243 end; 244 245 procedure TCpu.InstructionInc; 246 var 247 RegIndex: Byte; 248 begin 249 RegIndex := ReadByte; 250 R[RegIndex] := R[RegIndex] + 1; 251 end; 252 253 procedure TCpu.InstructionDec; 254 var 255 RegIndex: Byte; 256 begin 257 RegIndex := ReadByte; 258 R[RegIndex] := R[RegIndex] - 1; 259 end; 260 261 procedure TCpu.InstructionJp; 262 begin 263 IP := ReadAddress; 264 end; 265 266 procedure TCpu.InstructionJpnz; 267 var 268 RegIndex: Byte; 269 Address: TAddress; 270 begin 271 RegIndex := ReadByte; 272 Address := ReadAddress; 273 if R[RegIndex] <> 0 then IP := Address; 274 end; 275 276 procedure TCpu.InstructionJpz; 277 var 278 RegIndex: Byte; 279 Address: TAddress; 280 begin 281 RegIndex := ReadByte; 282 Address := ReadAddress; 283 if R[RegIndex] = 0 then IP := Address; 284 end; 285 286 procedure TCpu.InstructionAdd; 287 var 288 RegIndex: Byte; 289 RegIndex2: Byte; 290 begin 291 RegIndex := ReadByte; 292 RegIndex2 := ReadByte; 293 R[RegIndex] := R[RegIndex] + R[RegIndex2]; 294 end; 295 296 procedure TCpu.InstructionSub; 297 var 298 RegIndex: Byte; 299 RegIndex2: Byte; 300 begin 301 RegIndex := ReadByte; 302 RegIndex2 := ReadByte; 303 R[RegIndex] := R[RegIndex] - R[RegIndex2]; 304 end; 305 306 procedure TCpu.InstructionCall; 307 var 308 Address: TAddress; 309 begin 310 Address := ReadAddress; 311 Push(IP); 312 IP := Address; 313 end; 314 315 procedure TCpu.InstructionRet; 316 begin 317 IP := Pop; 318 end; 319 320 procedure TCpu.InstructionPush; 321 begin 322 Push(R[ReadByte]); 323 end; 324 325 procedure TCpu.InstructionPop; 326 begin 327 R[ReadByte] := Pop; 328 end; 329 330 procedure TCpu.InstructionCopy; 331 var 332 RegIndex: Byte; 333 RegIndex2: Byte; 334 begin 335 RegIndex := ReadByte; 336 RegIndex2 := ReadByte; 337 R[RegIndex] := R[RegIndex2]; 338 end; 339 340 procedure TCpu.InstructionShl; 341 var 342 RegIndex: Byte; 343 Num: Byte; 344 begin 345 RegIndex := ReadByte; 346 Num := ReadByte; 347 R[RegIndex] := R[RegIndex] shl Num; 348 end; 349 350 procedure TCpu.InstructionShr; 351 var 352 RegIndex: Byte; 353 Num: Byte; 354 begin 355 RegIndex := ReadByte; 356 Num := ReadByte; 357 R[RegIndex] := R[RegIndex] shr Num; 358 end; 359 360 procedure TCpu.InstructionLoad; 361 var 362 RegIndex: Byte; 363 RegIndex2: Byte; 364 begin 365 RegIndex := ReadByte; 366 RegIndex2 := ReadByte; 367 R[RegIndex] := PData(@Memory.Data[R[RegIndex2]])^; 368 end; 369 370 procedure TCpu.InstructionLoadi; 371 var 372 RegIndex: Byte; 373 Address: TAddress; 374 begin 375 RegIndex := ReadByte; 376 Address := ReadAddress; 377 R[RegIndex] := PData(@Memory.Data[Address])^; 378 end; 379 380 procedure TCpu.InstructionStore; 381 var 382 RegIndex: Byte; 383 RegIndex2: Byte; 384 begin 385 RegIndex := ReadByte; 386 RegIndex2 := ReadByte; 387 PData(@Memory.Data[R[RegIndex2]])^ := R[RegIndex]; 388 end; 389 390 procedure TCpu.InstructionMul; 391 var 392 RegIndex: Byte; 393 RegIndex2: Byte; 394 begin 395 RegIndex := ReadByte; 396 RegIndex2 := ReadByte; 397 R[RegIndex] := R[RegIndex] * R[RegIndex2]; 398 end; 399 400 procedure TCpu.InstructionAnd; 401 var 402 RegIndex: Byte; 403 RegIndex2: Byte; 404 begin 405 RegIndex := ReadByte; 406 RegIndex2 := ReadByte; 407 R[RegIndex] := R[RegIndex] and R[RegIndex2]; 408 end; 409 410 procedure TCpu.InstructionAndi; 411 var 412 RegIndex: Byte; 413 begin 414 RegIndex := ReadByte; 415 R[RegIndex] := R[RegIndex] and ReadData; 416 end; 417 418 procedure TCpu.InstructionOr; 419 var 420 RegIndex: Byte; 421 RegIndex2: Byte; 422 begin 423 RegIndex := ReadByte; 424 RegIndex2 := ReadByte; 425 R[RegIndex] := R[RegIndex] or R[RegIndex2]; 426 end; 427 428 procedure TCpu.InstructionXor; 429 var 430 RegIndex: Byte; 431 RegIndex2: Byte; 432 begin 433 RegIndex := ReadByte; 434 RegIndex2 := ReadByte; 435 R[RegIndex] := R[RegIndex] xor R[RegIndex2]; 436 end; 437 438 procedure TCpu.InstructionInt; 439 begin 440 Interrupt(ReadByte); 441 end; 442 443 procedure TCpu.InstructionReti; 444 begin 445 IP := Pop; 446 InterruptEnabled := True; 447 end; 448 449 procedure TCpu.InstructionEnableInt; 450 begin 451 InterruptEnabled := True; 452 end; 453 454 procedure TCpu.InstructionDisableInt; 455 begin 456 InterruptEnabled := False; 457 end; 458 137 459 procedure TCpu.Run; 138 460 begin … … 161 483 var 162 484 Instruction: TInstruction; 163 Address: Integer;164 RegIndex: Byte;165 RegIndex2: Byte;166 Num: Byte;167 485 begin 168 486 Instruction := TInstruction(ReadByte); 487 if Assigned(FInstructionHandlers[Instruction]) then 488 FInstructionHandlers[Instruction] 489 else raise Exception.Create('Missing handler for instruction ' + IntToStr(Integer(Instruction))); 169 490 Inc(ExecutedCount); 170 case Instruction of171 inNop: ;172 inHalt: Terminated := True;173 inSet: begin174 RegIndex := ReadByte;175 R[RegIndex] := ReadData;176 end;177 inLoad: begin178 RegIndex := ReadByte;179 RegIndex2 := ReadByte;180 R[RegIndex] := PData(@Memory.Data[R[RegIndex2]])^;181 end;182 inLoadi: begin183 RegIndex := ReadByte;184 Address := ReadAddress;185 R[RegIndex] := PData(@Memory.Data[Address])^;186 end;187 inStore: begin188 RegIndex := ReadByte;189 RegIndex2 := ReadByte;190 PData(@Memory.Data[R[RegIndex2]])^ := R[RegIndex];191 end;192 inInput: begin193 RegIndex := ReadByte;194 Address := ReadAddress;195 if Assigned(FOnInput) then R[RegIndex] := FOnInput(Address)196 else R[RegIndex] := 0;197 end;198 inOutput: begin199 Address := ReadAddress;200 RegIndex := ReadByte;201 if Assigned(FOnOutput) then FOnOutput(Address, R[RegIndex]);202 end;203 inInc: begin204 RegIndex := ReadByte;205 R[RegIndex] := R[RegIndex] + 1;206 end;207 inDec: begin208 RegIndex := ReadByte;209 R[RegIndex] := R[RegIndex] - 1;210 end;211 inJp: begin212 IP := ReadAddress;213 end;214 inJpz: begin215 RegIndex := ReadByte;216 Address := ReadAddress;217 if R[RegIndex] = 0 then IP := Address;218 end;219 inJpnz: begin220 RegIndex := ReadByte;221 Address := ReadAddress;222 if R[RegIndex] <> 0 then IP := Address;223 end;224 inAdd: begin225 RegIndex := ReadByte;226 RegIndex2 := ReadByte;227 R[RegIndex] := R[RegIndex] + R[RegIndex2];228 end;229 inSub: begin230 RegIndex := ReadByte;231 RegIndex2 := ReadByte;232 R[RegIndex] := R[RegIndex] - R[RegIndex2];233 end;234 inPush: begin235 RegIndex := ReadByte;236 Push(R[RegIndex]);237 end;238 inPop: begin239 RegIndex := ReadByte;240 R[RegIndex] := Pop;241 end;242 inCall: begin243 Address := ReadAddress;244 Push(IP);245 IP := Address;246 end;247 inRet: begin248 IP := Pop;249 end;250 inCopy: begin251 RegIndex := ReadByte;252 RegIndex2 := ReadByte;253 R[RegIndex] := R[RegIndex2];254 end;255 inShl: begin256 RegIndex := ReadByte;257 Num := ReadByte;258 R[RegIndex] := R[RegIndex] shl Num;259 end;260 inShr: begin261 RegIndex := ReadByte;262 Num := ReadByte;263 R[RegIndex] := R[RegIndex] shr Num;264 end;265 inMul: begin266 RegIndex := ReadByte;267 RegIndex2 := ReadByte;268 R[RegIndex] := R[RegIndex] * R[RegIndex2];269 end;270 inAnd: begin271 RegIndex := ReadByte;272 RegIndex2 := ReadByte;273 R[RegIndex] := R[RegIndex] and R[RegIndex2];274 end;275 inAndi: begin276 RegIndex := ReadByte;277 R[RegIndex] := R[RegIndex] and ReadData;278 end;279 inOr: begin280 RegIndex := ReadByte;281 RegIndex2 := ReadByte;282 R[RegIndex] := R[RegIndex] or R[RegIndex2];283 end;284 inXor: begin285 RegIndex := ReadByte;286 RegIndex2 := ReadByte;287 R[RegIndex] := R[RegIndex] xor R[RegIndex2];288 end;289 inInt: begin290 Interrupt(ReadByte);291 end;292 inReti: begin293 IP := Pop;294 InterruptEnabled := True;295 end;296 inEnableInt: InterruptEnabled := True;297 inDisableInt: InterruptEnabled := False;298 end;299 491 end; 300 492 … … 319 511 constructor TCpu.Create; 320 512 begin 513 InitInstructions; 321 514 end; 322 515 -
branches/UltimatOS/UMachine.pas
r32 r34 14 14 Machine: TMachine; 15 15 procedure Reset; virtual; 16 procedure OutputHandler(Port: TAddress; Data: TData); virtual; abstract; 17 function InputHandler(Port: TAddress): TData; virtual; abstract; 16 18 end; 17 19 … … 87 89 end; 88 90 91 { TStorage } 92 93 TStorage = class(TDevice) 94 public 95 F: TFileStream; 96 FileName: string; 97 constructor Create; 98 procedure OutputHandler(Port: TAddress; Data: TData); override; 99 function InputHandler(Port: TAddress): TData; override; 100 end; 101 89 102 { TMachine } 90 103 … … 110 123 111 124 implementation 125 126 { TStorage } 127 128 constructor TStorage.Create; 129 begin 130 131 end; 132 133 procedure TStorage.OutputHandler(Port: TAddress; Data: TData); 134 begin 135 136 end; 137 138 function TStorage.InputHandler(Port: TAddress): TData; 139 begin 140 141 end; 112 142 113 143 { TMouse } -
branches/UltimatOS/UMemory.pas
r29 r34 11 11 TMemory = class 12 12 private 13 FSize: Integer; 13 14 function GetSize: Integer; 14 15 procedure SetSize(AValue: Integer); 15 16 public 16 17 Data: PByte; 17 property Size: Integer read GetSize write SetSize;18 property Size: Integer read FSize write SetSize; 18 19 constructor Create; 19 20 destructor Destroy; override; … … 32 33 procedure TMemory.SetSize(AValue: Integer); 33 34 begin 35 if FSize = AValue then Exit; 36 FSize := AValue; 34 37 Data := ReAllocMem(Data, AValue); 35 38 end;
Note:
See TracChangeset
for help on using the changeset viewer.