Changeset 87


Ignore:
Timestamp:
Jul 16, 2015, 9:20:40 AM (9 years ago)
Author:
chronos
Message:

Another experimental virtual CPU implementation.

Location:
branches
Files:
8 added
2 edited

Legend:

Unmodified
Added
Removed
  • branches/Machine/UMachine.pas

    r86 r87  
    99
    1010type
     11  //TAddrInt = Int8;
     12  TAddrInt = Int16;
     13  //TAddrInt = Int32;
     14  //TAddrInt = Int64;
     15  TDataInt = Int16;
     16  //TDataInt = Int16;
     17  //TDataInt = Int32;
     18  //TDataInt = Int64;
     19
    1120  TOpcode = (opNop, opHalt, opCopy, opAdd, opSub, opMul, opDiv, opSet,
    1221    opParamClearAll, opParamSelect, opParamSet, opParamIndirect, opParamNext,
    13     opSkip, opSign);
     22    opSkip, opSign, opParamSize);
    1423
    1524  TAreaType = (atAddress, atMemory, atIOPort, atRegister, atSysRegister);
    1625
     26  TSysAddr = (saInstructionPointer, saAddrWidth, saDataWidth, saRegisterCount);
     27
    1728  TParameter = record
    18     Number: Integer;
     29    Number: TAddrInt;
    1930    Area: Integer;
     31    Size: Integer;
    2032    Defined: Boolean;
    2133  end;
     
    4254    procedure OpcodeParamIndirect;
    4355    procedure OpcodeParamClearAll;
     56    procedure OpcodeParamSize;
    4457    procedure OpcodeSkip;
    4558    procedure OpcodeSign;
    4659    function ReadNext: Integer;
    4760  public
    48     Memory: array of Integer;
    49     Registers: array of Integer;
    50     IP: Integer;
     61    Memory: array of Byte;
     62    Registers: array of TAddrInt;
     63    IP: TAddrInt;
    5164    Params: array of TParameter;
    5265    Terminated: Boolean;
    53     function ReadPort(Address: Integer): Integer;
    54     procedure WritePort(Address: Integer; Value: Integer);
    55     function ReadArea(AreaIndex: Integer; Address: Integer): Integer;
    56     procedure WriteArea(AreaIndex: Integer; Address: Integer; Value: Integer);
     66    function ReadPort(Address: Integer): TDataInt;
     67    procedure WritePort(Address: TAddrInt; Value: TDataInt);
     68    function ReadArea(AreaIndex: Integer; Address: TAddrInt): TDataInt;
     69    procedure WriteArea(AreaIndex: Integer; Address: TAddrInt; Value: TDataInt);
     70    function ReadSys(Address: TAddrInt): TDataInt;
    5771    procedure Run;
    5872    constructor Create;
     
    7488procedure TMachine.OpcodeCopy;
    7589begin
    76   WriteArea(Params[0].Area, Params[0].Number, ReadArea(Params[1].Area, Params[1].Number));
     90//  for I := 0 to Params[0].Size - 1 do begin
     91    WriteArea(Params[0].Area, Params[0].Number, ReadArea(Params[1].Area, Params[1].Number));
    7792end;
    7893
     
    144159    Params[I].Area := Integer(atAddress);
    145160    Params[I].Defined := False;
     161    Params[I].Size := 1;
    146162  end;
    147163  CurrentParam := 0;
     164end;
     165
     166procedure TMachine.OpcodeParamSize;
     167begin
     168  Params[CurrentParam].Size := ReadNext;
    148169end;
    149170
     
    169190end;
    170191
    171 function TMachine.ReadPort(Address: Integer): Integer;
     192function TMachine.ReadPort(Address: Integer): TDataInt;
    172193begin
    173194  Result := 0;
    174195end;
    175196
    176 procedure TMachine.WritePort(Address: Integer; Value: Integer);
    177 begin
    178 
    179 end;
    180 
    181 function TMachine.ReadArea(AreaIndex: Integer; Address: Integer): Integer;
     197procedure TMachine.WritePort(Address: TAddrInt; Value: TDataInt);
     198begin
     199
     200end;
     201
     202function TMachine.ReadArea(AreaIndex: Integer; Address: TAddrInt): TDataInt;
    182203begin
    183204  if AreaIndex = Integer(atAddress) then Result := Address
     
    185206  else if AreaIndex = Integer(atIOPort) then Result := ReadPort(Address)
    186207  else if AreaIndex = Integer(atRegister) then Result := Registers[Address]
    187   else if AreaIndex = Integer(atSysRegister) then begin
    188     if Address = 0 then Result := IP
    189     else Result := 0;
    190   end else raise Exception.Create('Unsupported area number ' + IntToStr(AreaIndex));
    191 end;
    192 
    193 procedure TMachine.WriteArea(AreaIndex: Integer; Address: Integer;
    194   Value: Integer);
     208  else if AreaIndex = Integer(atSysRegister) then Result := ReadSys(Address)
     209  else raise Exception.Create('Unsupported area number ' + IntToStr(AreaIndex));
     210end;
     211
     212procedure TMachine.WriteArea(AreaIndex: Integer; Address: TAddrInt;
     213  Value: TDataInt);
    195214begin
    196215  if AreaIndex = Integer(atAddress) then
     
    201220    if Address = 0 then IP := Value
    202221  end else raise Exception.Create('Unsupported area number ' + IntToStr(AreaIndex));
     222end;
     223
     224function TMachine.ReadSys(Address: TAddrInt): TDataInt;
     225begin
     226  if Address = Integer(saInstructionPointer) then Result := IP
     227  else if Address = Integer(saAddrWidth) then Result := SizeOf(TAddrInt)
     228  else if Address = Integer(saDataWidth) then Result := SizeOf(TDataInt)
     229  else if Address = Integer(saRegisterCount) then Result := Length(Registers)
     230  else Result := 0;
    203231end;
    204232
     
    244272  OpcodeTable[opSign] := OpcodeSign;
    245273  OpcodeTable[opParamNext] := OpcodeParamNext;
     274  OpcodeTable[opParamSize] := OpcodeParamSize;
    246275end;
    247276
  • branches/Machine/project1.lpi

    r86 r87  
    4444        <HasResources Value="True"/>
    4545        <ResourceBaseClass Value="Form"/>
    46         <UnitName Value="UFormMain"/>
    4746      </Unit1>
    4847      <Unit2>
    4948        <Filename Value="UMachine.pas"/>
    5049        <IsPartOfProject Value="True"/>
    51         <UnitName Value="UMachine"/>
    5250      </Unit2>
    5351      <Unit3>
    5452        <Filename Value="UCompiler.pas"/>
    5553        <IsPartOfProject Value="True"/>
    56         <UnitName Value="UCompiler"/>
    5754      </Unit3>
    5855    </Units>
Note: See TracChangeset for help on using the changeset viewer.