Changeset 174
- Timestamp:
- Apr 12, 2019, 12:06:05 AM (6 years ago)
- Location:
- branches/virtualcpu4
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/virtualcpu4/UCpu.pas
r173 r174 87 87 procedure InitInstructions; 88 88 public 89 Memory: array of Byte;89 Memory: Pointer; 90 90 Registers: array of TRegister; 91 91 Terminated: Boolean; … … 221 221 begin 222 222 case DataSize of 223 bw8: Registers[Read8].B := PByte( @Memory[PAddress(@Registers[Read8])^])^;224 bw16: Registers[Read8].W := PWord( @Memory[PAddress(@Registers[Read8])^])^;225 bw32: Registers[Read8].D := PDWord( @Memory[PAddress(@Registers[Read8])^])^;226 bw64: Registers[Read8].Q := PQWord( @Memory[PAddress(@Registers[Read8])^])^;223 bw8: Registers[Read8].B := PByte(Memory + PAddress(@Registers[Read8])^)^; 224 bw16: Registers[Read8].W := PWord(Memory + PAddress(@Registers[Read8])^)^; 225 bw32: Registers[Read8].D := PDWord(Memory + PAddress(@Registers[Read8])^)^; 226 bw64: Registers[Read8].Q := PQWord(Memory + PAddress(@Registers[Read8])^)^; 227 227 end; 228 228 end; … … 231 231 begin 232 232 case DataSize of 233 bw8: PByte( @Memory[PAddress(@Registers[Read8])^])^ := Registers[Read8].B;234 bw16: PWord( @Memory[PAddress(@Registers[Read8])^])^ := Registers[Read8].W;235 bw32: PDWord( @Memory[PAddress(@Registers[Read8])^])^ := Registers[Read8].D;236 bw64: PQWord( @Memory[PAddress(@Registers[Read8])^])^ := Registers[Read8].Q;233 bw8: PByte(Memory + PAddress(@Registers[Read8])^)^ := Registers[Read8].B; 234 bw16: PWord(Memory + PAddress(@Registers[Read8])^)^ := Registers[Read8].W; 235 bw32: PDWord(Memory + PAddress(@Registers[Read8])^)^ := Registers[Read8].D; 236 bw64: PQWord(Memory + PAddress(@Registers[Read8])^)^ := Registers[Read8].Q; 237 237 end; 238 238 end; … … 274 274 bw8: begin 275 275 Dec(SP, SizeOf(Byte)); 276 PByte( @Memory[SP])^ := Registers[Read8].B;276 PByte(Memory + SP)^ := Registers[Read8].B; 277 277 end; 278 278 bw16: begin 279 279 Dec(SP, SizeOf(Word)); 280 PWord( @Memory[SP])^ := Registers[Read8].W;280 PWord(Memory + SP)^ := Registers[Read8].W; 281 281 end; 282 282 bw32: begin 283 283 Dec(SP, SizeOf(DWord)); 284 PDWord( @Memory[SP])^ := Registers[Read8].D;284 PDWord(Memory + SP)^ := Registers[Read8].D; 285 285 end; 286 286 bw64: begin 287 287 Dec(SP, SizeOf(QWord)); 288 PQWord( @Memory[SP])^ := Registers[Read8].Q;288 PQWord(Memory + SP)^ := Registers[Read8].Q; 289 289 end; 290 290 end; … … 295 295 case DataSize of 296 296 bw8: begin 297 Registers[Read8].B := PByte( @Memory[SP])^;297 Registers[Read8].B := PByte(Memory + SP)^; 298 298 Inc(SP, SizeOf(Byte)); 299 299 end; 300 300 bw16: begin 301 Registers[Read8].B := PWord( @Memory[SP])^;301 Registers[Read8].B := PWord(Memory + SP)^; 302 302 Inc(SP, SizeOf(Word)); 303 303 end; 304 304 bw32: begin 305 Registers[Read8].B := PDWord( @Memory[SP])^;305 Registers[Read8].B := PDWord(Memory + SP)^; 306 306 Inc(SP, SizeOf(DWord)); 307 307 end; 308 308 bw64: begin 309 Registers[Read8].B := PQWord( @Memory[SP])^;309 Registers[Read8].B := PQWord(Memory + SP)^; 310 310 Inc(SP, SizeOf(QWord)); 311 311 end; … … 321 321 Dest.B := Read8; 322 322 Dec(SP, SizeOf(Byte)); 323 PByte( @Memory[SP])^ := Byte(IP);323 PByte(Memory + SP)^ := Byte(IP); 324 324 IP := Dest.B; 325 325 end; … … 327 327 Dest.W := Read16; 328 328 Dec(SP, SizeOf(Word)); 329 PWord( @Memory[SP])^ := Word(IP);329 PWord(Memory + SP)^ := Word(IP); 330 330 IP := Dest.W; 331 331 end; … … 333 333 Dest.D := Read32; 334 334 Dec(SP, SizeOf(DWord)); 335 PDWord( @Memory[SP])^ := DWord(IP);335 PDWord(Memory + SP)^ := DWord(IP); 336 336 IP := Dest.D; 337 337 end; … … 339 339 Dest.Q := Read64; 340 340 Dec(SP, SizeOf(QWord)); 341 PQWord( @Memory[SP])^ := QWord(IP);341 PQWord(Memory + SP)^ := QWord(IP); 342 342 IP := Dest.Q; 343 343 end; … … 349 349 case AddressSize of 350 350 bw8: begin 351 IP := PByte( @Memory[SP])^;351 IP := PByte(Memory + SP)^; 352 352 Inc(SP, SizeOf(Byte)); 353 353 end; 354 354 bw16: begin 355 IP := PWord( @Memory[SP])^;355 IP := PWord(Memory + SP)^; 356 356 Inc(SP, SizeOf(Word)); 357 357 end; 358 358 bw32: begin 359 IP := PDWord( @Memory[SP])^;359 IP := PDWord(Memory + SP)^; 360 360 Inc(SP, SizeOf(DWord)); 361 361 end; 362 362 bw64: begin 363 IP := PQWord( @Memory[SP])^;363 IP := PQWord(Memory + SP)^; 364 364 Inc(SP, SizeOf(QWord)); 365 365 end; … … 605 605 case DataSize of 606 606 bw8: begin 607 PByte( @Memory[Registers[Dest].B])^ := PByte(@Memory[Registers[Source].B])^;607 PByte(Memory + Registers[Dest].B)^ := PByte(Memory + Registers[Source].B)^; 608 608 Dec(Registers[Dest].B, SizeOf(Byte)); 609 609 Dec(Registers[Source].B, SizeOf(Byte)); 610 610 end; 611 611 bw16: begin 612 PWord( @Memory[Registers[Dest].B])^ := PWord(@Memory[Registers[Source].B])^;612 PWord(Memory + Registers[Dest].B)^ := PWord(Memory + Registers[Source].B)^; 613 613 Dec(Registers[Dest].B, SizeOf(Word)); 614 614 Dec(Registers[Source].B, SizeOf(Word)); 615 615 end; 616 616 bw32: begin 617 PDWord( @Memory[Registers[Dest].B])^ := PDWord(@Memory[Registers[Source].B])^;617 PDWord(Memory + Registers[Dest].B)^ := PDWord(Memory + Registers[Source].B)^; 618 618 Dec(Registers[Dest].B, SizeOf(DWord)); 619 619 Dec(Registers[Source].B, SizeOf(DWord)); 620 620 end; 621 621 bw64: begin 622 PQWord( @Memory[Registers[Dest].B])^ := PQWord(@Memory[Registers[Source].B])^;622 PQWord(Memory + Registers[Dest].B)^ := PQWord(Memory + Registers[Source].B)^; 623 623 Dec(Registers[Dest].B, SizeOf(QWord)); 624 624 Dec(Registers[Source].B, SizeOf(QWord)); … … 630 630 case DataSize of 631 631 bw8: begin 632 PByte( @Memory[Registers[Dest].W])^ := PByte(@Memory[Registers[Source].W])^;632 PByte(Memory + Registers[Dest].W)^ := PByte(Memory + Registers[Source].W)^; 633 633 Dec(Registers[Dest].W, SizeOf(Byte)); 634 634 Dec(Registers[Source].W, SizeOf(Byte)); 635 635 end; 636 636 bw16: begin 637 PWord( @Memory[Registers[Dest].W])^ := PWord(@Memory[Registers[Source].W])^;637 PWord(Memory + Registers[Dest].W)^ := PWord(Memory + Registers[Source].W)^; 638 638 Dec(Registers[Dest].W, SizeOf(Word)); 639 639 Dec(Registers[Source].W, SizeOf(Word)); 640 640 end; 641 641 bw32: begin 642 PDWord( @Memory[Registers[Dest].W])^ := PDWord(@Memory[Registers[Source].W])^;642 PDWord(Memory + Registers[Dest].W)^ := PDWord(Memory + Registers[Source].W)^; 643 643 Dec(Registers[Dest].W, SizeOf(DWord)); 644 644 Dec(Registers[Source].W, SizeOf(DWord)); 645 645 end; 646 646 bw64: begin 647 PQWord( @Memory[Registers[Dest].W])^ := PQWord(@Memory[Registers[Source].W])^;647 PQWord(Memory + Registers[Dest].W)^ := PQWord(Memory + Registers[Source].W)^; 648 648 Dec(Registers[Dest].W, SizeOf(QWord)); 649 649 Dec(Registers[Source].W, SizeOf(QWord)); … … 655 655 case DataSize of 656 656 bw8: begin 657 PByte( @Memory[Registers[Dest].D])^ := PByte(@Memory[Registers[Source].D])^;657 PByte(Memory + Registers[Dest].D)^ := PByte(Memory + Registers[Source].D)^; 658 658 Dec(Registers[Dest].D, SizeOf(Byte)); 659 659 Dec(Registers[Source].D, SizeOf(Byte)); 660 660 end; 661 661 bw16: begin 662 PWord( @Memory[Registers[Dest].D])^ := PWord(@Memory[Registers[Source].D])^;662 PWord(Memory + Registers[Dest].D)^ := PWord(Memory + Registers[Source].D)^; 663 663 Dec(Registers[Dest].D, SizeOf(Word)); 664 664 Dec(Registers[Source].D, SizeOf(Word)); 665 665 end; 666 666 bw32: begin 667 PDWord( @Memory[Registers[Dest].W])^ := PDWord(@Memory[Registers[Source].D])^;667 PDWord(Memory + Registers[Dest].W)^ := PDWord(Memory + Registers[Source].D)^; 668 668 Dec(Registers[Dest].D, SizeOf(DWord)); 669 669 Dec(Registers[Source].D, SizeOf(DWord)); 670 670 end; 671 671 bw64: begin 672 PQWord( @Memory[Registers[Dest].D])^ := PQWord(@Memory[Registers[Source].D])^;672 PQWord(Memory + Registers[Dest].D)^ := PQWord(Memory + Registers[Source].D)^; 673 673 Dec(Registers[Dest].D, SizeOf(QWord)); 674 674 Dec(Registers[Source].D, SizeOf(QWord)); … … 680 680 case DataSize of 681 681 bw8: begin 682 PByte( @Memory[Registers[Dest].Q])^ := PByte(@Memory[Registers[Source].Q])^;682 PByte(Memory + Registers[Dest].Q)^ := PByte(Memory + Registers[Source].Q)^; 683 683 Dec(Registers[Dest].Q, SizeOf(Byte)); 684 684 Dec(Registers[Source].Q, SizeOf(Byte)); 685 685 end; 686 686 bw16: begin 687 PWord( @Memory[Registers[Dest].Q])^ := PWord(@Memory[Registers[Source].Q])^;687 PWord(Memory + Registers[Dest].Q)^ := PWord(Memory + Registers[Source].Q)^; 688 688 Dec(Registers[Dest].Q, SizeOf(Word)); 689 689 Dec(Registers[Source].Q, SizeOf(Word)); 690 690 end; 691 691 bw32: begin 692 PDWord( @Memory[Registers[Dest].Q])^ := PDWord(@Memory[Registers[Source].Q])^;692 PDWord(Memory + Registers[Dest].Q)^ := PDWord(Memory + Registers[Source].Q)^; 693 693 Dec(Registers[Dest].Q, SizeOf(DWord)); 694 694 Dec(Registers[Source].Q, SizeOf(DWord)); 695 695 end; 696 696 bw64: begin 697 PQWord( @Memory[Registers[Dest].Q])^ := PQWord(@Memory[Registers[Source].Q])^;697 PQWord(Memory + Registers[Dest].Q)^ := PQWord(Memory + Registers[Source].Q)^; 698 698 Dec(Registers[Dest].Q, SizeOf(QWord)); 699 699 Dec(Registers[Source].Q, SizeOf(QWord)); … … 716 716 case DataSize of 717 717 bw8: begin 718 PByte( @Memory[Registers[Dest].B])^ := PByte(@Memory[Registers[Source].B])^;718 PByte(Memory + Registers[Dest].B)^ := PByte(Memory + Registers[Source].B)^; 719 719 Inc(Registers[Dest].B, SizeOf(Byte)); 720 720 Inc(Registers[Source].B, SizeOf(Byte)); 721 721 end; 722 722 bw16: begin 723 PWord( @Memory[Registers[Dest].B])^ := PWord(@Memory[Registers[Source].B])^;723 PWord(Memory + Registers[Dest].B)^ := PWord(Memory + Registers[Source].B)^; 724 724 Inc(Registers[Dest].B, SizeOf(Word)); 725 725 Inc(Registers[Source].B, SizeOf(Word)); 726 726 end; 727 727 bw32: begin 728 PDWord( @Memory[Registers[Dest].B])^ := PDWord(@Memory[Registers[Source].B])^;728 PDWord(Memory + Registers[Dest].B)^ := PDWord(Memory + Registers[Source].B)^; 729 729 Inc(Registers[Dest].B, SizeOf(DWord)); 730 730 Inc(Registers[Source].B, SizeOf(DWord)); 731 731 end; 732 732 bw64: begin 733 PQWord( @Memory[Registers[Dest].B])^ := PQWord(@Memory[Registers[Source].B])^;733 PQWord(Memory + Registers[Dest].B)^ := PQWord(Memory + Registers[Source].B)^; 734 734 Inc(Registers[Dest].B, SizeOf(QWord)); 735 735 Inc(Registers[Source].B, SizeOf(QWord)); … … 741 741 case DataSize of 742 742 bw8: begin 743 PByte( @Memory[Registers[Dest].W])^ := PByte(@Memory[Registers[Source].W])^;743 PByte(Memory + Registers[Dest].W)^ := PByte(Memory + Registers[Source].W)^; 744 744 Inc(Registers[Dest].W, SizeOf(Byte)); 745 745 Inc(Registers[Source].W, SizeOf(Byte)); 746 746 end; 747 747 bw16: begin 748 PWord( @Memory[Registers[Dest].W])^ := PWord(@Memory[Registers[Source].W])^;748 PWord(Memory + Registers[Dest].W)^ := PWord(Memory + Registers[Source].W)^; 749 749 Inc(Registers[Dest].W, SizeOf(Word)); 750 750 Inc(Registers[Source].W, SizeOf(Word)); 751 751 end; 752 752 bw32: begin 753 PDWord( @Memory[Registers[Dest].W])^ := PDWord(@Memory[Registers[Source].W])^;753 PDWord(Memory + Registers[Dest].W)^ := PDWord(Memory + Registers[Source].W)^; 754 754 Inc(Registers[Dest].W, SizeOf(DWord)); 755 755 Inc(Registers[Source].W, SizeOf(DWord)); 756 756 end; 757 757 bw64: begin 758 PQWord( @Memory[Registers[Dest].W])^ := PQWord(@Memory[Registers[Source].W])^;758 PQWord(Memory + Registers[Dest].W)^ := PQWord(Memory + Registers[Source].W)^; 759 759 Inc(Registers[Dest].W, SizeOf(QWord)); 760 760 Inc(Registers[Source].W, SizeOf(QWord)); … … 766 766 case DataSize of 767 767 bw8: begin 768 PByte( @Memory[Registers[Dest].D])^ := PByte(@Memory[Registers[Source].D])^;768 PByte(Memory + Registers[Dest].D)^ := PByte(Memory + Registers[Source].D)^; 769 769 Inc(Registers[Dest].D, SizeOf(Byte)); 770 770 Inc(Registers[Source].D, SizeOf(Byte)); 771 771 end; 772 772 bw16: begin 773 PWord( @Memory[Registers[Dest].D])^ := PWord(@Memory[Registers[Source].D])^;773 PWord(Memory + Registers[Dest].D)^ := PWord(Memory + Registers[Source].D)^; 774 774 Inc(Registers[Dest].D, SizeOf(Word)); 775 775 Inc(Registers[Source].D, SizeOf(Word)); 776 776 end; 777 777 bw32: begin 778 PDWord( @Memory[Registers[Dest].W])^ := PDWord(@Memory[Registers[Source].D])^;778 PDWord(Memory + Registers[Dest].W)^ := PDWord(Memory + Registers[Source].D)^; 779 779 Inc(Registers[Dest].D, SizeOf(DWord)); 780 780 Inc(Registers[Source].D, SizeOf(DWord)); 781 781 end; 782 782 bw64: begin 783 PQWord( @Memory[Registers[Dest].D])^ := PQWord(@Memory[Registers[Source].D])^;783 PQWord(Memory + Registers[Dest].D)^ := PQWord(Memory + Registers[Source].D)^; 784 784 Inc(Registers[Dest].D, SizeOf(QWord)); 785 785 Inc(Registers[Source].D, SizeOf(QWord)); … … 791 791 case DataSize of 792 792 bw8: begin 793 PByte( @Memory[Registers[Dest].Q])^ := PByte(@Memory[Registers[Source].Q])^;793 PByte(Memory + Registers[Dest].Q)^ := PByte(Memory + Registers[Source].Q)^; 794 794 Inc(Registers[Dest].Q, SizeOf(Byte)); 795 795 Inc(Registers[Source].Q, SizeOf(Byte)); 796 796 end; 797 797 bw16: begin 798 PWord( @Memory[Registers[Dest].Q])^ := PWord(@Memory[Registers[Source].Q])^;798 PWord(Memory + Registers[Dest].Q)^ := PWord(Memory + Registers[Source].Q)^; 799 799 Inc(Registers[Dest].Q, SizeOf(Word)); 800 800 Inc(Registers[Source].Q, SizeOf(Word)); 801 801 end; 802 802 bw32: begin 803 PDWord( @Memory[Registers[Dest].Q])^ := PDWord(@Memory[Registers[Source].Q])^;803 PDWord(Memory + Registers[Dest].Q)^ := PDWord(Memory + Registers[Source].Q)^; 804 804 Inc(Registers[Dest].Q, SizeOf(DWord)); 805 805 Inc(Registers[Source].Q, SizeOf(DWord)); 806 806 end; 807 807 bw64: begin 808 PQWord( @Memory[Registers[Dest].Q])^ := PQWord(@Memory[Registers[Source].Q])^;808 PQWord(Memory + Registers[Dest].Q)^ := PQWord(Memory + Registers[Source].Q)^; 809 809 Inc(Registers[Dest].Q, SizeOf(QWord)); 810 810 Inc(Registers[Source].Q, SizeOf(QWord)); … … 895 895 DataSizeLast := bwNone; 896 896 IP := 0; 897 SP := Length(Memory);897 SP := MemSize(Memory); 898 898 while not Terminated do 899 899 Step; … … 918 918 DataSizeLast := bwNone; 919 919 end; 920 IP := IP mod Length(Memory);920 IP := IP mod MemSize(Memory); 921 921 Inc(FTicks); 922 922 end; … … 946 946 function TCpu.Read8: Byte; 947 947 begin 948 Result := Memory[IP];948 Result := PByte(Memory + IP)^; 949 949 Inc(IP); 950 950 end; … … 952 952 function TCpu.Read16: Word; 953 953 begin 954 Result := PWord( @Memory[IP])^;954 Result := PWord(Memory + IP)^; 955 955 Inc(IP, SizeOf(Word)); 956 956 end; … … 958 958 function TCpu.Read32: DWord; 959 959 begin 960 Result := PDWord( @Memory[IP])^;960 Result := PDWord(Memory + IP)^; 961 961 Inc(IP, SizeOf(DWord)); 962 962 end; … … 964 964 function TCpu.Read64: QWord; 965 965 begin 966 Result := PQWord( @Memory[IP])^;966 Result := PQWord(Memory + IP)^; 967 967 Inc(IP, SizeOf(QWord)); 968 968 end; … … 982 982 DataSize := bw16; 983 983 AddressSize := bw16; 984 SetLength(Memory, 1000);985 984 SetLength(Registers, 32); 986 985 InitInstructions; -
branches/virtualcpu4/UFormMain.pas
r173 r174 7 7 uses 8 8 Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls, 9 ComCtrls, UCpu, U InstructionWriter, syncobjs;9 ComCtrls, UCpu, UMachine, UInstructionWriter, syncobjs; 10 10 11 11 type … … 32 32 procedure Timer1Timer(Sender: TObject); 33 33 private 34 InputBuffer: string;35 OutputBuffer: string;36 Lock: TCriticalSection;37 function CpuInput(Port: TAddress): TRegister;38 procedure CpuOutput(Port: TAddress; Value: TRegister);39 34 procedure ReloadMemoryDump; 40 35 procedure ReloadRegisterDump; 41 36 procedure LoadProgram; 42 37 public 43 Cpu: TCpu;38 Machine: TMachine; 44 39 InstructionWriter: TInstructionWriter; 45 40 end; … … 59 54 procedure TFormMain.ButtonStartClick(Sender: TObject); 60 55 begin 61 Cpu.Start;56 Machine.Cpu.Start; 62 57 end; 63 58 64 59 procedure TFormMain.ButtonStopClick(Sender: TObject); 65 60 begin 66 Cpu.Stop;61 Machine.Cpu.Stop; 67 62 end; 68 63 69 64 procedure TFormMain.FormCreate(Sender: TObject); 70 65 begin 71 Lock := TCriticalSection.Create; 72 Cpu := TCpu.Create; 73 Cpu.OnInput := CpuInput; 74 Cpu.OnOutput := CpuOutput; 75 Cpu.DataSize := bw16; 76 Cpu.AddressSize := bw16; 66 Machine := TMachine.Create; 77 67 InstructionWriter := TInstructionWriter.Create; 78 InstructionWriter.Cpu := Cpu;68 InstructionWriter.Cpu := Machine.Cpu; 79 69 end; 80 70 … … 82 72 begin 83 73 InstructionWriter.Free; 84 Cpu.Free; 85 Lock.Free; 74 Machine.Free; 86 75 end; 87 76 … … 96 85 I: Integer; 97 86 begin 98 if Item.Index < Length( Cpu.Memory) div ItemsPerLine then begin87 if Item.Index < Length(Machine.Memory) div ItemsPerLine then begin 99 88 Line := ''; 100 89 for I := 0 to ItemsPerLine - 1 do 101 Line := Line + IntToHex( Cpu.Memory[Item.Index * ItemsPerLine + I], 2) + ' ';90 Line := Line + IntToHex(Machine.Memory[Item.Index * ItemsPerLine + I], 2) + ' '; 102 91 Item.Caption := IntToHex(Item.Index * ItemsPerLine, 8); 103 92 Item.SubItems.Add(Line); … … 107 96 procedure TFormMain.ListViewRegistersData(Sender: TObject; Item: TListItem); 108 97 begin 109 if Item.Index < Length( Cpu.Registers) + 2 then begin98 if Item.Index < Length(Machine.Cpu.Registers) + 2 then begin 110 99 if Item.Index = 0 then begin 111 100 Item.Caption := 'IP'; 112 Item.SubItems.Add(IntToHex( Cpu.IP, 16));101 Item.SubItems.Add(IntToHex(Machine.Cpu.IP, 16)); 113 102 end else 114 103 if Item.Index = 1 then begin 115 104 Item.Caption := 'SP'; 116 Item.SubItems.Add(IntToHex( Cpu.SP, 16));105 Item.SubItems.Add(IntToHex(Machine.Cpu.SP, 16)); 117 106 end else begin 118 107 Item.Caption := 'R' + IntToStr(Item.Index - 2); 119 Item.SubItems.Add(IntToHex( Cpu.Registers[Item.Index - 2].D, 16));108 Item.SubItems.Add(IntToHex(Machine.Cpu.Registers[Item.Index - 2].D, 16)); 120 109 end; 121 110 end; … … 124 113 procedure TFormMain.Memo1KeyPress(Sender: TObject; var Key: char); 125 114 begin 126 Lock.Acquire;127 InputBuffer :=InputBuffer + Key;128 Lock.Release;115 Machine.LockInput.Acquire; 116 Machine.InputBuffer := Machine.InputBuffer + Key; 117 Machine.LockInput.Release; 129 118 end; 130 119 131 120 procedure TFormMain.Timer1Timer(Sender: TObject); 132 121 begin 133 Label1.Caption := 'Ticks: ' + IntToStr( Cpu.Ticks);122 Label1.Caption := 'Ticks: ' + IntToStr(Machine.Cpu.Ticks); 134 123 ReloadMemoryDump; 135 124 ReloadRegisterDump; 136 Lock.Acquire;137 Memo1.Lines.Text := Memo1.Lines.Text + OutputBuffer;138 SetLength( OutputBuffer, 0);139 Lock.Release;125 Machine.LockOutput.Acquire; 126 Memo1.Lines.Text := Memo1.Lines.Text + Machine.OutputBuffer; 127 SetLength(Machine.OutputBuffer, 0); 128 Machine.LockOutput.Release; 140 129 end; 141 130 142 131 procedure TFormMain.ReloadMemoryDump; 143 132 begin 144 ListViewMemory.Items.Count := Length( Cpu.Memory) div ItemsPerLine;133 ListViewMemory.Items.Count := Length(Machine.Memory) div ItemsPerLine; 145 134 ListViewMemory.Refresh; 146 135 end; … … 148 137 procedure TFormMain.ReloadRegisterDump; 149 138 begin 150 ListViewRegisters.Items.Count := Length( Cpu.Registers);139 ListViewRegisters.Items.Count := Length(Machine.Cpu.Registers); 151 140 ListViewRegisters.Refresh; 152 141 end; … … 190 179 end; 191 180 192 function TFormMain.CpuInput(Port: TAddress): TRegister;193 begin194 Result.Q := 0;195 case Port of196 0: begin197 Lock.Acquire;198 while (Length(InputBuffer) = 0) and not Cpu.Terminated do begin199 Lock.Release;200 Sleep(100);201 Lock.Acquire;202 end;203 if Length(InputBuffer) > 0 then begin204 Result.B := Ord(InputBuffer[1]);205 Delete(InputBuffer, 1, 1);206 end else Result.B := 0;207 Lock.Release;208 end;209 end;210 end;211 212 procedure TFormMain.CpuOutput(Port: TAddress; Value: TRegister);213 begin214 case Port of215 0: begin216 Lock.Acquire;217 OutputBuffer := OutputBuffer + Char(Value.B);218 Lock.Release;219 end;220 end;221 end;222 223 224 225 181 end. 226 182 -
branches/virtualcpu4/UInstructionWriter.pas
r173 r174 150 150 procedure TInstructionWriter.Write8(Value: Byte); 151 151 begin 152 PByte( @Cpu.Memory[IP])^ := Value;152 PByte(Cpu.Memory + IP)^ := Value; 153 153 Inc(IP, SizeOf(Byte)); 154 154 end; … … 156 156 procedure TInstructionWriter.Write16(Value: Word); 157 157 begin 158 PWord( @Cpu.Memory[IP])^ := Value;158 PWord(Cpu.Memory + IP)^ := Value; 159 159 Inc(IP, SizeOf(Word)); 160 160 end; … … 162 162 procedure TInstructionWriter.Write32(Value: DWord); 163 163 begin 164 PDWord( @Cpu.Memory[IP])^ := Value;164 PDWord(Cpu.Memory + IP)^ := Value; 165 165 Inc(IP, SizeOf(DWord)); 166 166 end; … … 168 168 procedure TInstructionWriter.Write64(Value: QWord); 169 169 begin 170 PQWord( @Cpu.Memory[IP])^ := Value;170 PQWord(Cpu.Memory + IP)^ := Value; 171 171 Inc(IP, SizeOf(QWord)); 172 172 end; -
branches/virtualcpu4/virtucpu4.lpi
r172 r174 70 70 </Item1> 71 71 </RequiredPackages> 72 <Units Count=" 4">72 <Units Count="5"> 73 73 <Unit0> 74 74 <Filename Value="virtucpu4.lpr"/> … … 90 90 <IsPartOfProject Value="True"/> 91 91 </Unit3> 92 <Unit4> 93 <Filename Value="UMachine.pas"/> 94 <IsPartOfProject Value="True"/> 95 </Unit4> 92 96 </Units> 93 97 </ProjectOptions> -
branches/virtualcpu4/virtucpu4.lpr
r172 r174 8 8 {$ENDIF} 9 9 Interfaces, // this includes the LCL widgetset 10 Forms, UFormMain, UCpu 10 Forms, UFormMain, UCpu, UMachine 11 11 { you can add units after this }; 12 12
Note:
See TracChangeset
for help on using the changeset viewer.