Changeset 174 for branches/virtualcpu4/UCpu.pas
- Timestamp:
- Apr 12, 2019, 12:06:05 AM (6 years ago)
- File:
-
- 1 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;
Note:
See TracChangeset
for help on using the changeset viewer.