Changeset 174 for branches


Ignore:
Timestamp:
Apr 12, 2019, 12:06:05 AM (6 years ago)
Author:
chronos
Message:
  • Added: Unit UMachine which will cover virtual hardware for virtual CPU.
Location:
branches/virtualcpu4
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • branches/virtualcpu4/UCpu.pas

    r173 r174  
    8787    procedure InitInstructions;
    8888  public
    89     Memory: array of Byte;
     89    Memory: Pointer;
    9090    Registers: array of TRegister;
    9191    Terminated: Boolean;
     
    221221begin
    222222  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])^)^;
    227227  end;
    228228end;
     
    231231begin
    232232  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;
    237237  end;
    238238end;
     
    274274    bw8: begin
    275275      Dec(SP, SizeOf(Byte));
    276       PByte(@Memory[SP])^ := Registers[Read8].B;
     276      PByte(Memory + SP)^ := Registers[Read8].B;
    277277    end;
    278278    bw16: begin
    279279      Dec(SP, SizeOf(Word));
    280       PWord(@Memory[SP])^ := Registers[Read8].W;
     280      PWord(Memory + SP)^ := Registers[Read8].W;
    281281    end;
    282282    bw32: begin
    283283      Dec(SP, SizeOf(DWord));
    284       PDWord(@Memory[SP])^ := Registers[Read8].D;
     284      PDWord(Memory + SP)^ := Registers[Read8].D;
    285285    end;
    286286    bw64: begin
    287287      Dec(SP, SizeOf(QWord));
    288       PQWord(@Memory[SP])^ := Registers[Read8].Q;
     288      PQWord(Memory + SP)^ := Registers[Read8].Q;
    289289    end;
    290290  end;
     
    295295  case DataSize of
    296296    bw8: begin
    297       Registers[Read8].B := PByte(@Memory[SP])^;
     297      Registers[Read8].B := PByte(Memory + SP)^;
    298298      Inc(SP, SizeOf(Byte));
    299299    end;
    300300    bw16: begin
    301       Registers[Read8].B := PWord(@Memory[SP])^;
     301      Registers[Read8].B := PWord(Memory + SP)^;
    302302      Inc(SP, SizeOf(Word));
    303303    end;
    304304    bw32: begin
    305       Registers[Read8].B := PDWord(@Memory[SP])^;
     305      Registers[Read8].B := PDWord(Memory + SP)^;
    306306      Inc(SP, SizeOf(DWord));
    307307    end;
    308308    bw64: begin
    309       Registers[Read8].B := PQWord(@Memory[SP])^;
     309      Registers[Read8].B := PQWord(Memory + SP)^;
    310310      Inc(SP, SizeOf(QWord));
    311311    end;
     
    321321      Dest.B := Read8;
    322322      Dec(SP, SizeOf(Byte));
    323       PByte(@Memory[SP])^ := Byte(IP);
     323      PByte(Memory + SP)^ := Byte(IP);
    324324      IP := Dest.B;
    325325    end;
     
    327327      Dest.W := Read16;
    328328      Dec(SP, SizeOf(Word));
    329       PWord(@Memory[SP])^ := Word(IP);
     329      PWord(Memory + SP)^ := Word(IP);
    330330      IP := Dest.W;
    331331    end;
     
    333333      Dest.D := Read32;
    334334      Dec(SP, SizeOf(DWord));
    335       PDWord(@Memory[SP])^ := DWord(IP);
     335      PDWord(Memory + SP)^ := DWord(IP);
    336336      IP := Dest.D;
    337337    end;
     
    339339      Dest.Q := Read64;
    340340      Dec(SP, SizeOf(QWord));
    341       PQWord(@Memory[SP])^ := QWord(IP);
     341      PQWord(Memory + SP)^ := QWord(IP);
    342342      IP := Dest.Q;
    343343    end;
     
    349349  case AddressSize of
    350350    bw8: begin
    351       IP := PByte(@Memory[SP])^;
     351      IP := PByte(Memory + SP)^;
    352352      Inc(SP, SizeOf(Byte));
    353353    end;
    354354    bw16: begin
    355       IP := PWord(@Memory[SP])^;
     355      IP := PWord(Memory + SP)^;
    356356      Inc(SP, SizeOf(Word));
    357357    end;
    358358    bw32: begin
    359       IP := PDWord(@Memory[SP])^;
     359      IP := PDWord(Memory + SP)^;
    360360      Inc(SP, SizeOf(DWord));
    361361    end;
    362362    bw64: begin
    363       IP := PQWord(@Memory[SP])^;
     363      IP := PQWord(Memory + SP)^;
    364364      Inc(SP, SizeOf(QWord));
    365365    end;
     
    605605      case DataSize of
    606606        bw8: begin
    607           PByte(@Memory[Registers[Dest].B])^ := PByte(@Memory[Registers[Source].B])^;
     607          PByte(Memory + Registers[Dest].B)^ := PByte(Memory + Registers[Source].B)^;
    608608          Dec(Registers[Dest].B, SizeOf(Byte));
    609609          Dec(Registers[Source].B, SizeOf(Byte));
    610610        end;
    611611        bw16: begin
    612           PWord(@Memory[Registers[Dest].B])^ := PWord(@Memory[Registers[Source].B])^;
     612          PWord(Memory + Registers[Dest].B)^ := PWord(Memory + Registers[Source].B)^;
    613613          Dec(Registers[Dest].B, SizeOf(Word));
    614614          Dec(Registers[Source].B, SizeOf(Word));
    615615        end;
    616616        bw32: begin
    617           PDWord(@Memory[Registers[Dest].B])^ := PDWord(@Memory[Registers[Source].B])^;
     617          PDWord(Memory + Registers[Dest].B)^ := PDWord(Memory + Registers[Source].B)^;
    618618          Dec(Registers[Dest].B, SizeOf(DWord));
    619619          Dec(Registers[Source].B, SizeOf(DWord));
    620620        end;
    621621        bw64: begin
    622           PQWord(@Memory[Registers[Dest].B])^ := PQWord(@Memory[Registers[Source].B])^;
     622          PQWord(Memory + Registers[Dest].B)^ := PQWord(Memory + Registers[Source].B)^;
    623623          Dec(Registers[Dest].B, SizeOf(QWord));
    624624          Dec(Registers[Source].B, SizeOf(QWord));
     
    630630      case DataSize of
    631631        bw8: begin
    632           PByte(@Memory[Registers[Dest].W])^ := PByte(@Memory[Registers[Source].W])^;
     632          PByte(Memory + Registers[Dest].W)^ := PByte(Memory + Registers[Source].W)^;
    633633          Dec(Registers[Dest].W, SizeOf(Byte));
    634634          Dec(Registers[Source].W, SizeOf(Byte));
    635635        end;
    636636        bw16: begin
    637           PWord(@Memory[Registers[Dest].W])^ := PWord(@Memory[Registers[Source].W])^;
     637          PWord(Memory + Registers[Dest].W)^ := PWord(Memory + Registers[Source].W)^;
    638638          Dec(Registers[Dest].W, SizeOf(Word));
    639639          Dec(Registers[Source].W, SizeOf(Word));
    640640        end;
    641641        bw32: begin
    642           PDWord(@Memory[Registers[Dest].W])^ := PDWord(@Memory[Registers[Source].W])^;
     642          PDWord(Memory + Registers[Dest].W)^ := PDWord(Memory + Registers[Source].W)^;
    643643          Dec(Registers[Dest].W, SizeOf(DWord));
    644644          Dec(Registers[Source].W, SizeOf(DWord));
    645645        end;
    646646        bw64: begin
    647           PQWord(@Memory[Registers[Dest].W])^ := PQWord(@Memory[Registers[Source].W])^;
     647          PQWord(Memory + Registers[Dest].W)^ := PQWord(Memory + Registers[Source].W)^;
    648648          Dec(Registers[Dest].W, SizeOf(QWord));
    649649          Dec(Registers[Source].W, SizeOf(QWord));
     
    655655      case DataSize of
    656656        bw8: begin
    657           PByte(@Memory[Registers[Dest].D])^ := PByte(@Memory[Registers[Source].D])^;
     657          PByte(Memory + Registers[Dest].D)^ := PByte(Memory + Registers[Source].D)^;
    658658          Dec(Registers[Dest].D, SizeOf(Byte));
    659659          Dec(Registers[Source].D, SizeOf(Byte));
    660660        end;
    661661        bw16: begin
    662           PWord(@Memory[Registers[Dest].D])^ := PWord(@Memory[Registers[Source].D])^;
     662          PWord(Memory + Registers[Dest].D)^ := PWord(Memory + Registers[Source].D)^;
    663663          Dec(Registers[Dest].D, SizeOf(Word));
    664664          Dec(Registers[Source].D, SizeOf(Word));
    665665        end;
    666666        bw32: begin
    667           PDWord(@Memory[Registers[Dest].W])^ := PDWord(@Memory[Registers[Source].D])^;
     667          PDWord(Memory + Registers[Dest].W)^ := PDWord(Memory + Registers[Source].D)^;
    668668          Dec(Registers[Dest].D, SizeOf(DWord));
    669669          Dec(Registers[Source].D, SizeOf(DWord));
    670670        end;
    671671        bw64: begin
    672           PQWord(@Memory[Registers[Dest].D])^ := PQWord(@Memory[Registers[Source].D])^;
     672          PQWord(Memory + Registers[Dest].D)^ := PQWord(Memory + Registers[Source].D)^;
    673673          Dec(Registers[Dest].D, SizeOf(QWord));
    674674          Dec(Registers[Source].D, SizeOf(QWord));
     
    680680      case DataSize of
    681681        bw8: begin
    682           PByte(@Memory[Registers[Dest].Q])^ := PByte(@Memory[Registers[Source].Q])^;
     682          PByte(Memory + Registers[Dest].Q)^ := PByte(Memory + Registers[Source].Q)^;
    683683          Dec(Registers[Dest].Q, SizeOf(Byte));
    684684          Dec(Registers[Source].Q, SizeOf(Byte));
    685685        end;
    686686        bw16: begin
    687           PWord(@Memory[Registers[Dest].Q])^ := PWord(@Memory[Registers[Source].Q])^;
     687          PWord(Memory + Registers[Dest].Q)^ := PWord(Memory + Registers[Source].Q)^;
    688688          Dec(Registers[Dest].Q, SizeOf(Word));
    689689          Dec(Registers[Source].Q, SizeOf(Word));
    690690        end;
    691691        bw32: begin
    692           PDWord(@Memory[Registers[Dest].Q])^ := PDWord(@Memory[Registers[Source].Q])^;
     692          PDWord(Memory + Registers[Dest].Q)^ := PDWord(Memory + Registers[Source].Q)^;
    693693          Dec(Registers[Dest].Q, SizeOf(DWord));
    694694          Dec(Registers[Source].Q, SizeOf(DWord));
    695695        end;
    696696        bw64: begin
    697           PQWord(@Memory[Registers[Dest].Q])^ := PQWord(@Memory[Registers[Source].Q])^;
     697          PQWord(Memory + Registers[Dest].Q)^ := PQWord(Memory + Registers[Source].Q)^;
    698698          Dec(Registers[Dest].Q, SizeOf(QWord));
    699699          Dec(Registers[Source].Q, SizeOf(QWord));
     
    716716      case DataSize of
    717717        bw8: begin
    718           PByte(@Memory[Registers[Dest].B])^ := PByte(@Memory[Registers[Source].B])^;
     718          PByte(Memory + Registers[Dest].B)^ := PByte(Memory + Registers[Source].B)^;
    719719          Inc(Registers[Dest].B, SizeOf(Byte));
    720720          Inc(Registers[Source].B, SizeOf(Byte));
    721721        end;
    722722        bw16: begin
    723           PWord(@Memory[Registers[Dest].B])^ := PWord(@Memory[Registers[Source].B])^;
     723          PWord(Memory + Registers[Dest].B)^ := PWord(Memory + Registers[Source].B)^;
    724724          Inc(Registers[Dest].B, SizeOf(Word));
    725725          Inc(Registers[Source].B, SizeOf(Word));
    726726        end;
    727727        bw32: begin
    728           PDWord(@Memory[Registers[Dest].B])^ := PDWord(@Memory[Registers[Source].B])^;
     728          PDWord(Memory + Registers[Dest].B)^ := PDWord(Memory + Registers[Source].B)^;
    729729          Inc(Registers[Dest].B, SizeOf(DWord));
    730730          Inc(Registers[Source].B, SizeOf(DWord));
    731731        end;
    732732        bw64: begin
    733           PQWord(@Memory[Registers[Dest].B])^ := PQWord(@Memory[Registers[Source].B])^;
     733          PQWord(Memory + Registers[Dest].B)^ := PQWord(Memory + Registers[Source].B)^;
    734734          Inc(Registers[Dest].B, SizeOf(QWord));
    735735          Inc(Registers[Source].B, SizeOf(QWord));
     
    741741      case DataSize of
    742742        bw8: begin
    743           PByte(@Memory[Registers[Dest].W])^ := PByte(@Memory[Registers[Source].W])^;
     743          PByte(Memory + Registers[Dest].W)^ := PByte(Memory + Registers[Source].W)^;
    744744          Inc(Registers[Dest].W, SizeOf(Byte));
    745745          Inc(Registers[Source].W, SizeOf(Byte));
    746746        end;
    747747        bw16: begin
    748           PWord(@Memory[Registers[Dest].W])^ := PWord(@Memory[Registers[Source].W])^;
     748          PWord(Memory + Registers[Dest].W)^ := PWord(Memory + Registers[Source].W)^;
    749749          Inc(Registers[Dest].W, SizeOf(Word));
    750750          Inc(Registers[Source].W, SizeOf(Word));
    751751        end;
    752752        bw32: begin
    753           PDWord(@Memory[Registers[Dest].W])^ := PDWord(@Memory[Registers[Source].W])^;
     753          PDWord(Memory + Registers[Dest].W)^ := PDWord(Memory + Registers[Source].W)^;
    754754          Inc(Registers[Dest].W, SizeOf(DWord));
    755755          Inc(Registers[Source].W, SizeOf(DWord));
    756756        end;
    757757        bw64: begin
    758           PQWord(@Memory[Registers[Dest].W])^ := PQWord(@Memory[Registers[Source].W])^;
     758          PQWord(Memory + Registers[Dest].W)^ := PQWord(Memory + Registers[Source].W)^;
    759759          Inc(Registers[Dest].W, SizeOf(QWord));
    760760          Inc(Registers[Source].W, SizeOf(QWord));
     
    766766      case DataSize of
    767767        bw8: begin
    768           PByte(@Memory[Registers[Dest].D])^ := PByte(@Memory[Registers[Source].D])^;
     768          PByte(Memory + Registers[Dest].D)^ := PByte(Memory + Registers[Source].D)^;
    769769          Inc(Registers[Dest].D, SizeOf(Byte));
    770770          Inc(Registers[Source].D, SizeOf(Byte));
    771771        end;
    772772        bw16: begin
    773           PWord(@Memory[Registers[Dest].D])^ := PWord(@Memory[Registers[Source].D])^;
     773          PWord(Memory + Registers[Dest].D)^ := PWord(Memory + Registers[Source].D)^;
    774774          Inc(Registers[Dest].D, SizeOf(Word));
    775775          Inc(Registers[Source].D, SizeOf(Word));
    776776        end;
    777777        bw32: begin
    778           PDWord(@Memory[Registers[Dest].W])^ := PDWord(@Memory[Registers[Source].D])^;
     778          PDWord(Memory + Registers[Dest].W)^ := PDWord(Memory + Registers[Source].D)^;
    779779          Inc(Registers[Dest].D, SizeOf(DWord));
    780780          Inc(Registers[Source].D, SizeOf(DWord));
    781781        end;
    782782        bw64: begin
    783           PQWord(@Memory[Registers[Dest].D])^ := PQWord(@Memory[Registers[Source].D])^;
     783          PQWord(Memory + Registers[Dest].D)^ := PQWord(Memory + Registers[Source].D)^;
    784784          Inc(Registers[Dest].D, SizeOf(QWord));
    785785          Inc(Registers[Source].D, SizeOf(QWord));
     
    791791      case DataSize of
    792792        bw8: begin
    793           PByte(@Memory[Registers[Dest].Q])^ := PByte(@Memory[Registers[Source].Q])^;
     793          PByte(Memory + Registers[Dest].Q)^ := PByte(Memory + Registers[Source].Q)^;
    794794          Inc(Registers[Dest].Q, SizeOf(Byte));
    795795          Inc(Registers[Source].Q, SizeOf(Byte));
    796796        end;
    797797        bw16: begin
    798           PWord(@Memory[Registers[Dest].Q])^ := PWord(@Memory[Registers[Source].Q])^;
     798          PWord(Memory + Registers[Dest].Q)^ := PWord(Memory + Registers[Source].Q)^;
    799799          Inc(Registers[Dest].Q, SizeOf(Word));
    800800          Inc(Registers[Source].Q, SizeOf(Word));
    801801        end;
    802802        bw32: begin
    803           PDWord(@Memory[Registers[Dest].Q])^ := PDWord(@Memory[Registers[Source].Q])^;
     803          PDWord(Memory + Registers[Dest].Q)^ := PDWord(Memory + Registers[Source].Q)^;
    804804          Inc(Registers[Dest].Q, SizeOf(DWord));
    805805          Inc(Registers[Source].Q, SizeOf(DWord));
    806806        end;
    807807        bw64: begin
    808           PQWord(@Memory[Registers[Dest].Q])^ := PQWord(@Memory[Registers[Source].Q])^;
     808          PQWord(Memory + Registers[Dest].Q)^ := PQWord(Memory + Registers[Source].Q)^;
    809809          Inc(Registers[Dest].Q, SizeOf(QWord));
    810810          Inc(Registers[Source].Q, SizeOf(QWord));
     
    895895  DataSizeLast := bwNone;
    896896  IP := 0;
    897   SP := Length(Memory);
     897  SP := MemSize(Memory);
    898898  while not Terminated do
    899899    Step;
     
    918918    DataSizeLast := bwNone;
    919919  end;
    920   IP := IP mod Length(Memory);
     920  IP := IP mod MemSize(Memory);
    921921  Inc(FTicks);
    922922end;
     
    946946function TCpu.Read8: Byte;
    947947begin
    948   Result := Memory[IP];
     948  Result := PByte(Memory + IP)^;
    949949  Inc(IP);
    950950end;
     
    952952function TCpu.Read16: Word;
    953953begin
    954   Result := PWord(@Memory[IP])^;
     954  Result := PWord(Memory + IP)^;
    955955  Inc(IP, SizeOf(Word));
    956956end;
     
    958958function TCpu.Read32: DWord;
    959959begin
    960   Result := PDWord(@Memory[IP])^;
     960  Result := PDWord(Memory + IP)^;
    961961  Inc(IP, SizeOf(DWord));
    962962end;
     
    964964function TCpu.Read64: QWord;
    965965begin
    966   Result := PQWord(@Memory[IP])^;
     966  Result := PQWord(Memory + IP)^;
    967967  Inc(IP, SizeOf(QWord));
    968968end;
     
    982982  DataSize := bw16;
    983983  AddressSize := bw16;
    984   SetLength(Memory, 1000);
    985984  SetLength(Registers, 32);
    986985  InitInstructions;
  • branches/virtualcpu4/UFormMain.pas

    r173 r174  
    77uses
    88  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
    9   ComCtrls, UCpu, UInstructionWriter, syncobjs;
     9  ComCtrls, UCpu, UMachine, UInstructionWriter, syncobjs;
    1010
    1111type
     
    3232    procedure Timer1Timer(Sender: TObject);
    3333  private
    34     InputBuffer: string;
    35     OutputBuffer: string;
    36     Lock: TCriticalSection;
    37     function CpuInput(Port: TAddress): TRegister;
    38     procedure CpuOutput(Port: TAddress; Value: TRegister);
    3934    procedure ReloadMemoryDump;
    4035    procedure ReloadRegisterDump;
    4136    procedure LoadProgram;
    4237  public
    43     Cpu: TCpu;
     38    Machine: TMachine;
    4439    InstructionWriter: TInstructionWriter;
    4540  end;
     
    5954procedure TFormMain.ButtonStartClick(Sender: TObject);
    6055begin
    61   Cpu.Start;
     56  Machine.Cpu.Start;
    6257end;
    6358
    6459procedure TFormMain.ButtonStopClick(Sender: TObject);
    6560begin
    66   Cpu.Stop;
     61  Machine.Cpu.Stop;
    6762end;
    6863
    6964procedure TFormMain.FormCreate(Sender: TObject);
    7065begin
    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;
    7767  InstructionWriter := TInstructionWriter.Create;
    78   InstructionWriter.Cpu := Cpu;
     68  InstructionWriter.Cpu := Machine.Cpu;
    7969end;
    8070
     
    8272begin
    8373  InstructionWriter.Free;
    84   Cpu.Free;
    85   Lock.Free;
     74  Machine.Free;
    8675end;
    8776
     
    9685  I: Integer;
    9786begin
    98   if Item.Index < Length(Cpu.Memory) div ItemsPerLine then begin
     87  if Item.Index < Length(Machine.Memory) div ItemsPerLine then begin
    9988    Line := '';
    10089    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) + ' ';
    10291    Item.Caption := IntToHex(Item.Index * ItemsPerLine, 8);
    10392    Item.SubItems.Add(Line);
     
    10796procedure TFormMain.ListViewRegistersData(Sender: TObject; Item: TListItem);
    10897begin
    109   if Item.Index < Length(Cpu.Registers) + 2 then begin
     98  if Item.Index < Length(Machine.Cpu.Registers) + 2 then begin
    11099    if Item.Index = 0 then begin
    111100      Item.Caption := 'IP';
    112       Item.SubItems.Add(IntToHex(Cpu.IP, 16));
     101      Item.SubItems.Add(IntToHex(Machine.Cpu.IP, 16));
    113102    end else
    114103    if Item.Index = 1 then begin
    115104      Item.Caption := 'SP';
    116       Item.SubItems.Add(IntToHex(Cpu.SP, 16));
     105      Item.SubItems.Add(IntToHex(Machine.Cpu.SP, 16));
    117106    end else begin
    118107      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));
    120109    end;
    121110  end;
     
    124113procedure TFormMain.Memo1KeyPress(Sender: TObject; var Key: char);
    125114begin
    126   Lock.Acquire;
    127   InputBuffer := InputBuffer + Key;
    128   Lock.Release;
     115  Machine.LockInput.Acquire;
     116  Machine.InputBuffer := Machine.InputBuffer + Key;
     117  Machine.LockInput.Release;
    129118end;
    130119
    131120procedure TFormMain.Timer1Timer(Sender: TObject);
    132121begin
    133   Label1.Caption := 'Ticks: ' + IntToStr(Cpu.Ticks);
     122  Label1.Caption := 'Ticks: ' + IntToStr(Machine.Cpu.Ticks);
    134123  ReloadMemoryDump;
    135124  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;
    140129end;
    141130
    142131procedure TFormMain.ReloadMemoryDump;
    143132begin
    144   ListViewMemory.Items.Count := Length(Cpu.Memory) div ItemsPerLine;
     133  ListViewMemory.Items.Count := Length(Machine.Memory) div ItemsPerLine;
    145134  ListViewMemory.Refresh;
    146135end;
     
    148137procedure TFormMain.ReloadRegisterDump;
    149138begin
    150   ListViewRegisters.Items.Count := Length(Cpu.Registers);
     139  ListViewRegisters.Items.Count := Length(Machine.Cpu.Registers);
    151140  ListViewRegisters.Refresh;
    152141end;
     
    190179end;
    191180
    192 function TFormMain.CpuInput(Port: TAddress): TRegister;
    193 begin
    194   Result.Q := 0;
    195   case Port of
    196     0: begin
    197       Lock.Acquire;
    198       while (Length(InputBuffer) = 0) and not Cpu.Terminated do begin
    199         Lock.Release;
    200         Sleep(100);
    201         Lock.Acquire;
    202       end;
    203       if Length(InputBuffer) > 0 then begin
    204         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 begin
    214   case Port of
    215     0: begin
    216       Lock.Acquire;
    217       OutputBuffer := OutputBuffer + Char(Value.B);
    218       Lock.Release;
    219     end;
    220   end;
    221 end;
    222 
    223 
    224 
    225181end.
    226182
  • branches/virtualcpu4/UInstructionWriter.pas

    r173 r174  
    150150procedure TInstructionWriter.Write8(Value: Byte);
    151151begin
    152   PByte(@Cpu.Memory[IP])^ := Value;
     152  PByte(Cpu.Memory + IP)^ := Value;
    153153  Inc(IP, SizeOf(Byte));
    154154end;
     
    156156procedure TInstructionWriter.Write16(Value: Word);
    157157begin
    158   PWord(@Cpu.Memory[IP])^ := Value;
     158  PWord(Cpu.Memory + IP)^ := Value;
    159159  Inc(IP, SizeOf(Word));
    160160end;
     
    162162procedure TInstructionWriter.Write32(Value: DWord);
    163163begin
    164   PDWord(@Cpu.Memory[IP])^ := Value;
     164  PDWord(Cpu.Memory + IP)^ := Value;
    165165  Inc(IP, SizeOf(DWord));
    166166end;
     
    168168procedure TInstructionWriter.Write64(Value: QWord);
    169169begin
    170   PQWord(@Cpu.Memory[IP])^ := Value;
     170  PQWord(Cpu.Memory + IP)^ := Value;
    171171  Inc(IP, SizeOf(QWord));
    172172end;
  • branches/virtualcpu4/virtucpu4.lpi

    r172 r174  
    7070      </Item1>
    7171    </RequiredPackages>
    72     <Units Count="4">
     72    <Units Count="5">
    7373      <Unit0>
    7474        <Filename Value="virtucpu4.lpr"/>
     
    9090        <IsPartOfProject Value="True"/>
    9191      </Unit3>
     92      <Unit4>
     93        <Filename Value="UMachine.pas"/>
     94        <IsPartOfProject Value="True"/>
     95      </Unit4>
    9296    </Units>
    9397  </ProjectOptions>
  • branches/virtualcpu4/virtucpu4.lpr

    r172 r174  
    88  {$ENDIF}
    99  Interfaces, // this includes the LCL widgetset
    10   Forms, UFormMain, UCpu
     10  Forms, UFormMain, UCpu, UMachine
    1111  { you can add units after this };
    1212
Note: See TracChangeset for help on using the changeset viewer.