Ignore:
Timestamp:
Sep 22, 2019, 9:31:49 PM (5 years ago)
Author:
chronos
Message:
  • Modified: All parts of virtual machine have own form in Forms subdirectory.
  • Modified: Main form moved to Forms subdirectory.
  • Modified: TCpu class moved to UCpu unit.
  • Added: Assembler and dissasembler forms.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/virtcpu varint/UInstructionWriter.pas

    r196 r197  
    66
    77uses
    8   Classes, SysUtils, UMachine;
     8  Classes, SysUtils, UCpu;
    99
    1010type
     
    1414  private
    1515  public
    16     Cpu: TCpu;
     16    Memory: Pointer;
    1717    IP: T;
     18    function GetRelativeAddr(BaseIP, TargetAddr: T): T;
    1819    procedure Write(Value: T);
     20    procedure WriteSigned(Value: T);
    1921    procedure WriteOpcode(Value: TOpcode);
     22    procedure WriteString(Text: string);
    2023    procedure NoOperation;
    2124    procedure Load(R1, R2: Integer);
     
    3033    procedure Jump(Addr: Integer);
    3134    procedure JumpCond(Addr: Integer);
    32     {$IFDEF EXT_REL_JUMP}
    3335    procedure JumpRelative(R1: Integer; Addr: Integer);
    3436    procedure JumpRelativeCond(Addr: Integer);
    35     {$ENDIF}
    3637    procedure TestEqual(R1, R2: Integer);
    3738    procedure Increment(R: Integer);
    3839    procedure Decrement(R: Integer);
    3940    constructor Create;
     41    procedure Init;
    4042  end;
    4143
     
    4446
    4547{ TInstructionWriter }
     48
     49function TInstructionWriter.GetRelativeAddr(BaseIP, TargetAddr: T): T;
     50begin
     51  Result := TargetAddr - (BaseIP + 1 + T.GetByteSize);
     52end;
     53
     54procedure TInstructionWriter.WriteString(Text: string);
     55var
     56  I: Integer;
     57begin
     58  for I := 1 to Length(Text) do
     59    Write(Ord(Text[I]));
     60end;
    4661
    4762procedure TInstructionWriter.NoOperation;
     
    129144end;
    130145
    131 {$IFDEF EXT_REL_JUMP}
    132146procedure TInstructionWriter.JumpRelative(R1: Integer; Addr: Integer);
    133147begin
     
    139153procedure TInstructionWriter.JumpRelativeCond(Addr: Integer);
    140154begin
    141   Write(T(opJumpRelCond));
     155  WriteOpcode(opJumpRelCond);
    142156  Write(Addr - IP - 1);
    143157end;
    144 {$ENDIF}
    145158
    146159procedure TInstructionWriter.Increment(R: Integer);
     
    158171constructor TInstructionWriter.Create;
    159172begin
     173  Memory := nil;
     174  Init;
     175end;
     176
     177procedure TInstructionWriter.Init;
     178begin
    160179  IP := 0;
    161   Cpu := nil;
    162180end;
    163181
     
    166184  C: Integer;
    167185begin
    168   C := Value.WriteToAddr(Pointer(NativeInt(Cpu.Memory) + IP));
     186  C := Value.WriteToAddr(Pointer(NativeUInt(Memory) + IP));
    169187  Inc(IP, C);
    170188end;
    171189
     190procedure TInstructionWriter.WriteSigned(Value: T);
     191var
     192  C: Integer;
     193begin
     194  C := Value.WriteToAddr(Pointer(NativeUInt(Memory) + IP));
     195  Inc(IP, C);
     196end;
     197
    172198procedure TInstructionWriter.WriteOpcode(Value: TOpcode);
    173199begin
Note: See TracChangeset for help on using the changeset viewer.