- Timestamp:
- Jul 10, 2022, 12:37:58 AM (2 years ago)
- Location:
- branches/UltimatOS
- Files:
-
- 10 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/UltimatOS
- Property svn:ignore
-
old new 2 2 UltimatOS.lps 3 3 UltimatOS.res 4 UltimatOS.dbg 4 5 lib
-
- Property svn:ignore
-
branches/UltimatOS/Forms/UFormMain.lfm
r30 r32 10 10 OnCreate = FormCreate 11 11 OnDestroy = FormDestroy 12 OnKeyUp = FormKeyUp 12 13 OnShow = FormShow 13 14 LCLVersion = '2.2.0.4' … … 17 18 Top = 8 18 19 Width = 640 20 OnMouseMove = PaintBox1MouseMove 19 21 OnPaint = PaintBox1Paint 20 22 end 21 object Button Run: TButton23 object ButtonStart: TButton 22 24 Left = 8 23 25 Height = 33 24 26 Top = 496 25 27 Width = 98 26 Caption = ' Run'27 OnClick = Button RunClick28 Caption = 'Start' 29 OnClick = ButtonStartClick 28 30 TabOrder = 0 29 31 end … … 44 46 end 45 47 object ButtonMemory: TButton 46 Left = 12848 Left = 550 47 49 Height = 33 48 50 Top = 496 … … 51 53 OnClick = ButtonMemoryClick 52 54 TabOrder = 2 55 end 56 object ButtonStop: TButton 57 Left = 112 58 Height = 33 59 Top = 496 60 Width = 98 61 Caption = 'Stop' 62 OnClick = ButtonStopClick 63 TabOrder = 3 64 end 65 object ButtonRestart: TButton 66 Left = 216 67 Height = 33 68 Top = 496 69 Width = 98 70 Caption = 'Restart' 71 OnClick = ButtonRestartClick 72 TabOrder = 4 73 end 74 object ButtonCompile: TButton 75 Left = 8 76 Height = 33 77 Top = 536 78 Width = 98 79 Caption = 'Compile' 80 OnClick = ButtonCompileClick 81 TabOrder = 5 53 82 end 54 83 object Timer1: TTimer -
branches/UltimatOS/Forms/UFormMain.pas
r30 r32 13 13 TFormMain = class(TForm) 14 14 ButtonMemory: TButton; 15 ButtonRun: TButton; 15 ButtonCompile: TButton; 16 ButtonStart: TButton; 17 ButtonStop: TButton; 18 ButtonRestart: TButton; 16 19 Label1: TLabel; 17 20 MemoCode: TMemo; 18 21 PaintBox1: TPaintBox; 19 22 Timer1: TTimer; 23 procedure ButtonCompileClick(Sender: TObject); 20 24 procedure ButtonMemoryClick(Sender: TObject); 21 procedure ButtonRunClick(Sender: TObject); 25 procedure ButtonRestartClick(Sender: TObject); 26 procedure ButtonStartClick(Sender: TObject); 27 procedure ButtonStopClick(Sender: TObject); 22 28 procedure FormCreate(Sender: TObject); 23 29 procedure FormDestroy(Sender: TObject); 30 procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); 24 31 procedure FormShow(Sender: TObject); 32 procedure PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X, 33 Y: Integer); 25 34 procedure PaintBox1Paint(Sender: TObject); 26 35 procedure Timer1Timer(Sender: TObject); 27 36 private 28 37 procedure InitProgram; 38 procedure UpdateInterface; 29 39 public 30 40 Machine: TMachine; … … 40 50 41 51 uses 42 U InstructionWriter, UFormMemory;52 UAssembler, UFormMemory; 43 53 44 54 { TFormMain } … … 50 60 end; 51 61 52 procedure TFormMain.Button RunClick(Sender: TObject);62 procedure TFormMain.ButtonStartClick(Sender: TObject); 53 63 begin 54 64 Machine.Reset; 55 with TInstructionWriter.Create do56 try57 Memory := Machine.Cpu.Memory;58 Parse(MemoCode.Lines);59 finally 60 Free;61 end; 62 Machine. Cpu.Run;63 Label1.Caption := 'Executed instructions: ' + IntToStr(Machine.Cpu.ExecutedCount);65 ButtonCompile.Click; 66 Machine.Running := True; 67 UpdateInterface; 68 end; 69 70 procedure TFormMain.ButtonStopClick(Sender: TObject); 71 begin 72 Machine.Running := False; 73 UpdateInterface; 64 74 end; 65 75 … … 70 80 end; 71 81 82 procedure TFormMain.ButtonCompileClick(Sender: TObject); 83 begin 84 with TAssembler.Create do 85 try 86 Memory := Machine.Cpu.Memory; 87 Parse(MemoCode.Lines); 88 finally 89 Free; 90 end; 91 end; 92 93 procedure TFormMain.ButtonRestartClick(Sender: TObject); 94 begin 95 ButtonStop.Click; 96 ButtonStart.Click; 97 end; 98 72 99 procedure TFormMain.FormDestroy(Sender: TObject); 73 100 begin … … 75 102 end; 76 103 104 procedure TFormMain.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState 105 ); 106 begin 107 Machine.Keyboard.Press(Key); 108 end; 109 77 110 procedure TFormMain.FormShow(Sender: TObject); 78 111 begin 112 UpdateInterface; 113 end; 114 115 procedure TFormMain.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X, 116 Y: Integer); 117 begin 118 Machine.Mouse.Move(X, Y); 79 119 end; 80 120 … … 99 139 PaintBox1.Repaint; 100 140 end; 141 Label1.Caption := 'Executed instructions: ' + IntToStr(Machine.Cpu.ExecutedCount) + LineEnding + 142 'Interrupts: ' + IntToStr(Machine.Cpu.InterruptCount); 101 143 end; 102 144 … … 106 148 end; 107 149 150 procedure TFormMain.UpdateInterface; 151 begin 152 ButtonStart.Enabled := not Machine.Running; 153 ButtonStop.Enabled := Machine.Running; 154 ButtonRestart.Enabled := not Machine.Running; 155 end; 156 108 157 end. 109 158 -
branches/UltimatOS/Graphics.asm
r31 r32 14 14 PUSH R0 15 15 PUSH R1 16 Start:16 RectangleStart: 17 17 COPY R0, R8 18 18 COPY R1, R9 19 19 CALL SetPixelAddr 20 20 COPY R5, R3 21 Line:21 RectangleLine: 22 22 OUT (ScreenWriteData), R7 23 23 DEC R5 24 JPNZ R5, Line24 JPNZ R5, RectangleLine 25 25 DEC R6 26 26 INC R9 27 JPNZ R6, Start27 JPNZ R6, RectangleStart 28 28 POP R1 29 29 POP R0 -
branches/UltimatOS/IO.asm
r29 r32 10 10 .const ScreenSetAddr 0 11 11 .const ScreenWriteData 1 12 .const CounterSetInterval 2 13 .const CounterSetState 3 12 14 15 ; Interrupt vectors 16 .const InterruptVectorCounter 2 17 .const InterruptVectorMouse 3 18 .const InterruptVectorKeyboard 4 19 -
branches/UltimatOS/Program.asm
r30 r32 1 1 .include IO.asm 2 2 3 CALL Start 4 .org 8 5 .dd InterruptHandlerCounter 6 .dd InterruptHandlerMouse 7 .dd InterruptHandlerKeyboard 8 9 .org $100 10 Start: 3 11 ;SET R0, $ff7700 ; Color 4 12 ;SET R1, 100 ; X … … 22 30 ;CALL WriteChar 23 31 24 HALT 32 StartLoop: 33 JP StartLoop 34 ;HALT 35 36 InterruptHandlerCounter: 37 RETI 38 39 MousePosX: 40 .dd 0 41 MousePosY: 42 .dd 0 43 44 InterruptHandlerMouse: 45 PUSH R0 46 PUSH R1 47 IN R0, (MouseGetPosX) 48 SET R1, MousePosX 49 ST (R1), R0 50 IN R0, (MouseGetPosY) 51 SET R1, MousePosY 52 ST (R1), R0 53 POP R1 54 POP R0 55 RETI 56 57 InterruptHandlerKeyboard: 58 RETI 25 59 26 60 HelloWorld: .db "Hello world", 0 -
branches/UltimatOS/UAssembler.pas
r31 r32 1 unit U InstructionWriter;1 unit UAssembler; 2 2 3 3 interface … … 25 25 end; 26 26 27 { TLabel } 28 27 29 TLabel = class 28 30 Name: string; 29 31 Address: TAddress; 30 32 ForwardRefs: array of TAddress; 33 procedure AddForwardRef(Address: TAddress); 31 34 end; 32 35 … … 50 53 end; 51 54 52 { T InstructionWriter }53 54 T InstructionWriter = class55 { TAssembler } 56 57 TAssembler = class 55 58 private 56 59 InstructionDefs: TInstructionDefs; … … 59 62 LineNumber: Integer; 60 63 function ParseText(var Text: string; Separator: Char): string; 64 function ParseConst(Text: string; out Value: Integer): Boolean; 65 function ParseLabel(Text: string; out Value: Integer): Boolean; 66 function ParseNumber(Text: string; out Value: Integer): Boolean; 61 67 procedure WriteParam(Param: TInstructionParam; var Text: string); 62 68 procedure Error(Text: string); … … 65 71 IP: Integer; 66 72 procedure Parse(Lines: TStrings); 67 procedure Write(Text: string);73 procedure ParseLine(Text: string); 68 74 procedure WriteInstruction(Instruction: TInstruction); 69 75 procedure WriteAddress(Address: TAddress); … … 80 86 implementation 81 87 88 { TLabel } 89 90 procedure TLabel.AddForwardRef(Address: TAddress); 91 begin 92 SetLength(ForwardRefs, Length(ForwardRefs) + 1); 93 ForwardRefs[Length(ForwardRefs) - 1] := Address; 94 end; 95 82 96 { TConstants } 83 97 … … 144 158 145 159 146 { T InstructionWriter }147 148 function T InstructionWriter.ParseText(var Text: string; Separator: Char160 { TAssembler } 161 162 function TAssembler.ParseText(var Text: string; Separator: Char 149 163 ): string; 150 164 var … … 161 175 end; 162 176 163 procedure TInstructionWriter.WriteParam(Param: TInstructionParam; var Text: string); 177 function TAssembler.ParseConst(Text: string; out Value: Integer): Boolean; 178 var 179 FoundConstant: TConstant; 180 begin 181 FoundConstant := Constants.SearchByName(UpperCase(Text)); 182 if Assigned(FoundConstant) then begin 183 Result := True; 184 Value := FoundConstant.Value; 185 end; 186 Result := False; 187 end; 188 189 function TAssembler.ParseLabel(Text: string; out Value: Integer): Boolean; 190 var 191 FoundLabel: TLabel; 192 begin 193 Result := True; 194 FoundLabel := Labels.SearchByName(UpperCase(Text)); 195 if Assigned(FoundLabel) then begin 196 // Existing label 197 if FoundLabel.Address = -1 then begin 198 FoundLabel.AddForwardRef(IP); 199 Value := 0; 200 end else 201 Value := FoundLabel.Address; 202 end else begin 203 // Forward label reference 204 with Labels.AddNew(UpperCase(Text), -1) do begin 205 AddForwardRef(IP); 206 end; 207 Value := 0; 208 end; 209 end; 210 211 function TAssembler.ParseNumber(Text: string; out Value: Integer): Boolean; 212 begin 213 if TryStrToInt(Text, Value) then begin 214 Result := True; 215 end else 216 Result := False; 217 end; 218 219 procedure TAssembler.WriteParam(Param: TInstructionParam; var Text: string); 164 220 var 165 221 Address: string; … … 179 235 Exit; 180 236 end; 181 FoundLabel := Labels.SearchByName(UpperCase(Address)); 182 if Assigned(FoundLabel) then begin 183 // Existing label 184 WriteAddress(FoundLabel.Address); 185 end else begin 186 // Forward label reference 187 with Labels.AddNew(UpperCase(Address), -1) do begin 188 SetLength(ForwardRefs, Length(ForwardRefs) + 1); 189 ForwardRefs[Length(ForwardRefs) - 1] := IP; 190 end; 191 WriteAddress(0); 192 end; 237 ParseLabel(Address, Value); 238 WriteAddress(Value); 193 239 end; 194 240 end; … … 205 251 Exit; 206 252 end; 207 FoundLabel := Labels.SearchByName(UpperCase(Address)); 208 if Assigned(FoundLabel) then begin 209 // Existing label 210 WriteAddress(FoundLabel.Address); 211 end else begin 212 // Forward label reference 213 with Labels.AddNew(UpperCase(Address), -1) do begin 214 SetLength(ForwardRefs, Length(ForwardRefs) + 1); 215 ForwardRefs[Length(ForwardRefs) - 1] := IP; 216 end; 217 WriteAddress(0); 218 end; 253 ParseLabel(Address, Value); 254 WriteAddress(Value); 219 255 end; 220 256 end else Error('Expected indirect address ' + Address); … … 245 281 Exit; 246 282 end; 247 FoundLabel := Labels.SearchByName(UpperCase(Address)); 248 if Assigned(FoundLabel) then begin 249 // Existing label 250 WriteData(FoundLabel.Address); 251 end else begin 252 // Forward label reference 253 with Labels.AddNew(UpperCase(Address), -1) do begin 254 SetLength(ForwardRefs, Length(ForwardRefs) + 1); 255 ForwardRefs[Length(ForwardRefs) - 1] := IP; 256 end; 257 WriteData(0); 258 end; 283 ParseLabel(Address, Value); 284 WriteData(Value); 259 285 end; 260 286 end; … … 273 299 end; 274 300 275 procedure T InstructionWriter.Error(Text: string);301 procedure TAssembler.Error(Text: string); 276 302 begin 277 303 raise Exception.Create(IntToStr(LineNumber) + ': ' + Text); 278 304 end; 279 305 280 procedure T InstructionWriter.Parse(Lines: TStrings);306 procedure TAssembler.Parse(Lines: TStrings); 281 307 var 282 308 I: Integer; … … 284 310 for I := 0 to Lines.Count - 1 do begin 285 311 LineNumber := I + 1; 286 Write(Lines[I]);312 ParseLine(Lines[I]); 287 313 end; 288 314 for I := 0 to Labels.Count - 1 do begin … … 292 318 end; 293 319 294 procedure T InstructionWriter.Write(Text: string);320 procedure TAssembler.ParseLine(Text: string); 295 321 var 296 322 FoundLabel: TLabel; … … 304 330 Lines: TStringList; 305 331 Param: string; 332 Num: Integer; 306 333 begin 307 334 // Remove comments … … 375 402 if InstructionName = 'dd' then begin 376 403 while Text <> '' do begin 377 Param := ParseText(Text, ',');404 Param := Trim(ParseText(Text, ',')); 378 405 if Param.StartsWith('"') and Param.EndsWith('"') then begin 379 406 Param := Copy(Param, 2, Length(Param) - 2); 380 407 for I := 1 to Length(Param) do 381 408 WriteCardinal(Ord(Param[I])); 382 end else WriteCardinal(StrToInt(Param)); 383 end; 409 end else begin 410 if ParseNumber(Param, Num) then 411 WriteCardinal(Num) 412 else if ParseConst(Param, Num) then 413 WriteCardinal(Num) 414 else if ParseLabel(Param, Num) then 415 WriteCardinal(Num); 416 end; 417 end; 418 end else 419 if InstructionName = 'org' then begin 420 IP := StrToInt(Text); 384 421 end else Error('Unsupported directive name ' + InstructionName); 385 422 end else begin … … 396 433 end; 397 434 398 procedure T InstructionWriter.WriteInstruction(Instruction: TInstruction);435 procedure TAssembler.WriteInstruction(Instruction: TInstruction); 399 436 begin 400 437 Memory.Data[IP] := Byte(Instruction); … … 402 439 end; 403 440 404 procedure T InstructionWriter.WriteAddress(Address: TAddress);441 procedure TAssembler.WriteAddress(Address: TAddress); 405 442 begin 406 443 PAddress(@Memory.Data[IP])^ := Address; … … 408 445 end; 409 446 410 procedure T InstructionWriter.WriteData(Data: TData);447 procedure TAssembler.WriteData(Data: TData); 411 448 begin 412 449 PData(@Memory.Data[IP])^ := Data; … … 414 451 end; 415 452 416 procedure T InstructionWriter.WriteIndex(Index: Byte);453 procedure TAssembler.WriteIndex(Index: Byte); 417 454 begin 418 455 Memory.Data[IP] := Index; … … 420 457 end; 421 458 422 procedure T InstructionWriter.WriteReg(Index: Byte);459 procedure TAssembler.WriteReg(Index: Byte); 423 460 begin 424 461 Memory.Data[IP] := Index; … … 426 463 end; 427 464 428 procedure T InstructionWriter.WriteByte(Value: Byte);465 procedure TAssembler.WriteByte(Value: Byte); 429 466 begin 430 467 Memory.Data[IP] := Value; … … 432 469 end; 433 470 434 procedure T InstructionWriter.WriteWord(Value: Word);471 procedure TAssembler.WriteWord(Value: Word); 435 472 begin 436 473 PWord(@Memory.Data[IP])^ := Value; … … 438 475 end; 439 476 440 procedure T InstructionWriter.WriteCardinal(Value: Cardinal);477 procedure TAssembler.WriteCardinal(Value: Cardinal); 441 478 begin 442 479 PCardinal(@Memory.Data[IP])^ := Value; … … 444 481 end; 445 482 446 constructor T InstructionWriter.Create;483 constructor TAssembler.Create; 447 484 begin 448 485 Labels := TLabels.Create; … … 477 514 AddNew(inOr, 'OR', ipRegIndex, ipRegIndex); 478 515 AddNew(inXor, 'XOR', ipRegIndex, ipRegIndex); 479 end; 480 end; 481 482 destructor TInstructionWriter.Destroy; 516 AddNew(inInt, 'INT', ipIndex); 517 AddNew(inReti, 'RETI'); 518 AddNew(inEnableInt, 'EI'); 519 AddNew(inDisableInt, 'DI'); 520 end; 521 end; 522 523 destructor TAssembler.Destroy; 483 524 begin 484 525 FreeAndNil(InstructionDefs); -
branches/UltimatOS/UCpu.pas
r31 r32 9 9 TInstruction = (inNop, inHalt, inSet, inInput, inOutput, inInc, inDec, inJp, 10 10 inJpz, inJpnz, inAdd, inSub, inCall, inRet, inPush, inPop, inCopy, 11 inShl, inShr, inLoad, inLoadi, inStore, inMul, inAnd, inAndi, inOr, inXor); 11 inShl, inShr, inLoad, inLoadi, inStore, inMul, inAnd, inAndi, inOr, inXor, 12 inInt, inReti, inEnableInt, inDisableInt); 12 13 TAddress = Integer; 13 14 PAddress = ^TAddress; … … 19 20 TOnOutput = procedure (Address: Integer; Value: TData) of object; 20 21 22 TCpu = class; 23 24 { TCpuThread } 25 26 TCpuThread = class(TThread) 27 Cpu: TCpu; 28 procedure Execute; override; 29 destructor Destroy; override; 30 end; 31 21 32 { TCpu } 22 33 23 34 TCpu = class 24 35 private 36 FCpuThread: TCpuThread; 25 37 FOnInput: TOnInput; 26 38 FOnOutput: TOnOutput; 39 InterruptPending: Boolean; 40 InterruptVector: Integer; 41 InterruptEnabled: Boolean; 42 function GetRunning: Boolean; 27 43 function ReadByte: Byte; 28 44 function ReadAddress: TAddress; … … 30 46 procedure Push(Value: Integer); 31 47 function Pop: Integer; 48 procedure SetRunning(AValue: Boolean); 32 49 public 33 50 ExecutedCount: Integer; 51 InterruptCount: Integer; 34 52 Terminated: Boolean; 35 53 Memory: TMemory; … … 38 56 SP: TAddress; 39 57 procedure Run; 58 procedure Start; 59 procedure Stop; 40 60 procedure Step; 41 61 procedure Reset; 62 procedure Interrupt(Vector: Integer); 63 constructor Create; 64 destructor Destroy; override; 42 65 property OnInput: TOnInput read FOnInput write FOnInput; 43 66 property OnOutput: TOnOutput read FOnOutput write FOnOutput; 67 property Running: Boolean read GetRunning write SetRunning; 44 68 end; 45 69 46 70 47 71 implementation 72 73 { TCpuThread } 74 75 procedure TCpuThread.Execute; 76 begin 77 Cpu.Run; 78 end; 79 80 destructor TCpuThread.Destroy; 81 begin 82 Cpu.FCpuThread := nil; 83 inherited; 84 end; 48 85 49 86 { TCpu } … … 55 92 end; 56 93 94 function TCpu.GetRunning: Boolean; 95 begin 96 Result := Assigned(FCpuThread); 97 end; 98 57 99 function TCpu.ReadAddress: TAddress; 58 100 begin … … 79 121 end; 80 122 123 procedure TCpu.SetRunning(AValue: Boolean); 124 begin 125 if AValue and not Assigned(FCpuThread) then begin 126 FCpuThread := TCpuThread.Create(True); 127 FCpuThread.FreeOnTerminate := True; 128 FCpuThread.Cpu := Self; 129 FCpuThread.Start; 130 end else 131 if not AValue and Assigned(FCpuThread) then begin 132 Terminated := True; 133 FreeAndNil(FCpuThread); 134 end; 135 end; 136 81 137 procedure TCpu.Run; 82 138 begin 83 while not Terminated do 139 while not Terminated do begin 140 if InterruptEnabled and InterruptPending then begin 141 InterruptEnabled := False; 142 InterruptPending := False; 143 Push(IP); 144 IP := PAddress(@Memory.Data[InterruptVector * SizeOf(TAddress)])^; 145 end; 84 146 Step; 147 end; 148 end; 149 150 procedure TCpu.Start; 151 begin 152 Running := True; 153 end; 154 155 procedure TCpu.Stop; 156 begin 157 Running := False; 85 158 end; 86 159 … … 214 287 R[RegIndex] := R[RegIndex] xor R[RegIndex2]; 215 288 end; 289 inInt: begin 290 Interrupt(ReadByte); 291 end; 292 inReti: begin 293 IP := Pop; 294 InterruptEnabled := True; 295 end; 296 inEnableInt: InterruptEnabled := True; 297 inDisableInt: InterruptEnabled := False; 216 298 end; 217 299 end; … … 223 305 SP := 0; 224 306 ExecutedCount := 0; 307 InterruptEnabled := True; 308 InterruptPending := False; 309 InterruptCount := 0; 310 end; 311 312 procedure TCpu.Interrupt(Vector: Integer); 313 begin 314 InterruptPending := True; 315 InterruptVector := Vector; 316 Inc(InterruptCount); 317 end; 318 319 constructor TCpu.Create; 320 begin 321 end; 322 323 destructor TCpu.Destroy; 324 begin 325 Running := False; 326 inherited; 225 327 end; 226 328 -
branches/UltimatOS/UMachine.pas
r31 r32 4 4 5 5 uses 6 Classes, SysUtils, UCpu, UMemory ;6 Classes, SysUtils, UCpu, UMemory, ExtCtrls; 7 7 8 8 type 9 TMachine = class; 9 10 10 11 { TDevice } 11 12 12 13 TDevice = class 14 Machine: TMachine; 13 15 procedure Reset; virtual; 14 16 end; 17 18 { TMouse } 15 19 16 20 TMouse = class(TDevice) 17 21 Position: TPoint; 22 InterruptVector: Integer; 23 procedure Move(X, Y: Integer); 18 24 end; 19 25 … … 54 60 TKeyboard = class(TDevice) 55 61 Buffer: TFifo; 62 InterruptVector: Integer; 56 63 function ReadKey: Integer; 57 64 function KeyReady: Integer; … … 59 66 destructor Destroy; override; 60 67 procedure Reset; override; 68 procedure Press(KeyCode: Integer); 69 end; 70 71 { TCounter } 72 73 TCounter = class(TDevice) 74 private 75 Timer: TTimer; 76 function GetEnabled: Boolean; 77 function GetInterval: Integer; 78 procedure SetEnabled(AValue: Boolean); 79 procedure SetInterval(AValue: Integer); 80 procedure DoTimer(Sender: TObject); 81 public 82 InterruptVector: Integer; 83 constructor Create; 84 destructor Destroy; override; 85 property Enabled: Boolean read GetEnabled write SetEnabled; 86 property Interval: Integer read GetInterval write SetInterval; 61 87 end; 62 88 … … 67 93 function CpuInput(Address: TAddress): TData; 68 94 procedure CpuOutput(Address: TAddress; Value: TData); 95 function GetRunning: Boolean; 96 procedure SetRunning(AValue: Boolean); 69 97 public 70 98 Cpu: TCpu; … … 73 101 Mouse: TMouse; 74 102 Screen: TScreen; 103 Counter: TCounter; 75 104 procedure Reset; 76 105 constructor Create; 77 106 destructor Destroy; override; 107 property Running: Boolean read GetRunning write SetRunning; 78 108 end; 79 109 80 110 81 111 implementation 112 113 { TMouse } 114 115 procedure TMouse.Move(X, Y: Integer); 116 begin 117 Position := Point(X, Y); 118 Machine.Cpu.Interrupt(InterruptVector); 119 end; 120 121 { TCounter } 122 123 function TCounter.GetEnabled: Boolean; 124 begin 125 Result := Timer.Enabled; 126 end; 127 128 function TCounter.GetInterval: Integer; 129 begin 130 Result := Timer.Interval; 131 end; 132 133 procedure TCounter.SetEnabled(AValue: Boolean); 134 begin 135 Timer.Enabled := AValue; 136 end; 137 138 procedure TCounter.SetInterval(AValue: Integer); 139 begin 140 Timer.Interval := AValue; 141 end; 142 143 procedure TCounter.DoTimer(Sender: TObject); 144 begin 145 Machine.Cpu.Interrupt(InterruptVector); 146 end; 147 148 constructor TCounter.Create; 149 begin 150 Timer := TTimer.Create(nil); 151 Timer.OnTimer := DoTimer; 152 Enabled := False; 153 end; 154 155 destructor TCounter.Destroy; 156 begin 157 FreeAndNil(Timer); 158 inherited; 159 end; 82 160 83 161 { TDevice } … … 183 261 begin 184 262 Buffer.Clear; 263 end; 264 265 procedure TKeyboard.Press(KeyCode: Integer); 266 begin 267 Buffer.Put(KeyCode); 268 Machine.Cpu.Interrupt(InterruptVector); 185 269 end; 186 270 … … 201 285 begin 202 286 if Address = 0 then Screen.SetPointer(Value) 203 else if Address = 1 then Screen.WriteData(Value); 287 else if Address = 1 then Screen.WriteData(Value) 288 else if Address = 2 then Counter.Interval := Value 289 else if Address = 3 then Counter.Enabled := Value = 1; 290 end; 291 292 function TMachine.GetRunning: Boolean; 293 begin 294 Result := Cpu.Running; 295 end; 296 297 procedure TMachine.SetRunning(AValue: Boolean); 298 begin 299 Cpu.Running := AValue; 204 300 end; 205 301 … … 213 309 constructor TMachine.Create; 214 310 begin 311 Counter := TCounter.Create; 312 Counter.Machine := Self; 313 Counter.InterruptVector := 2; 215 314 Memory := TMemory.Create; 216 315 Memory.Size := 200000; 217 316 Keyboard := TKeyboard.Create; 317 Keyboard.Machine := Self; 318 Keyboard.InterruptVector := 4; 218 319 Mouse := TMouse.Create; 320 Mouse.Machine := Self; 321 Mouse.InterruptVector := 3; 219 322 Screen := TScreen.Create; 220 323 Screen.Size := Point(640, 480); … … 232 335 FreeAndNil(Screen); 233 336 FreeAndNil(Memory); 337 FreeAndNil(Counter); 234 338 inherited; 235 339 end; -
branches/UltimatOS/UltimatOS.lpi
r30 r32 52 52 </Options> 53 53 </Linking> 54 <Other> 55 <CompilerMessages> 56 <IgnoredMessages idx6058="True" idx3124="True" idx3123="True"/> 57 </CompilerMessages> 58 </Other> 54 59 </CompilerOptions> 55 60 </Item> … … 92 97 </Unit> 93 98 <Unit> 94 <Filename Value="U InstructionWriter.pas"/>99 <Filename Value="UAssembler.pas"/> 95 100 <IsPartOfProject Value="True"/> 96 101 </Unit> … … 99 104 <IsPartOfProject Value="True"/> 100 105 <ComponentName Value="FormMemory"/> 106 <HasResources Value="True"/> 101 107 <ResourceBaseClass Value="Form"/> 102 108 </Unit> … … 132 138 </CodeGeneration> 133 139 <Linking> 140 <Debugging> 141 <UseExternalDbgSyms Value="True"/> 142 </Debugging> 134 143 <Options> 135 144 <Win32> … … 138 147 </Options> 139 148 </Linking> 149 <Other> 150 <CompilerMessages> 151 <IgnoredMessages idx6058="True" idx3124="True" idx3123="True"/> 152 </CompilerMessages> 153 </Other> 140 154 </CompilerOptions> 141 155 <Debugging> -
branches/UltimatOS/UltimatOS.lpr
r30 r32 11 11 {$ENDIF} 12 12 Interfaces, // this includes the LCL widgetset 13 Forms, UFormMain, UMachine, UCpu, UMemory, U InstructionWriter, UFormMemory13 Forms, UFormMain, UMachine, UCpu, UMemory, UAssembler, UFormMemory 14 14 { you can add units after this }; 15 15
Note:
See TracChangeset
for help on using the changeset viewer.