Ignore:
Timestamp:
Aug 9, 2018, 9:45:07 AM (6 years ago)
Author:
chronos
Message:
  • Added: More processor instructions.
Location:
branches/virtcpu fixed int
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/virtcpu fixed int

    • Property svn:ignore
      •  

        old new  
        33virtcpu.lps
        44virtcpu.res
         5*.dbg
  • branches/virtcpu fixed int/UFormMain.pas

    r163 r165  
    7272    AddOut(0, 1);
    7373    AddInc(2);
    74     AddJr(LabelStart);
     74    AddJump(LabelStart);
    7575    AddHalt;
    7676  end;
     
    154154function TForm1.CpuInput(Port: T): T;
    155155begin
     156  Result := 0;
    156157  case Port of
    157158    0: begin
     
    162163      if Length(KeyInputBuffer) > 0 then begin
    163164        Result := Ord(KeyInputBuffer[0]);
    164         Move(KeyInputBuffer[1], KeyInputBuffer[0], Length(KeyInputBuffer) - 1);
     165        if Length(KeyInputBuffer) > 1 then
     166          Move(KeyInputBuffer[1], KeyInputBuffer[0], Length(KeyInputBuffer) - 1);
    165167        SetLength(KeyInputBuffer, Length(KeyInputBuffer) - 1);
    166168      end else Result := 0;
  • branches/virtcpu fixed int/UInstructionWriter.pas

    r163 r165  
    2626    procedure AddIn(R1, R2: Integer);
    2727    procedure AddOut(R1, R2: Integer);
    28     procedure AddJr(Addr: Integer);
     28    procedure AddJump(Addr: Integer);
     29    {$IFDEF EXT_REL_JUMP}procedure AddJr(Addr: Integer);{$ENDIF}
    2930    procedure AddInc(R: Integer);
    3031    constructor Create;
     
    9495end;
    9596
     97procedure TInstructionWriter.AddJump(Addr: Integer);
     98begin
     99  Write(T(opJump));
     100  Write(Addr);
     101end;
     102
     103{$IFDEF EXT_REL_JUMP}
    96104procedure TInstructionWriter.AddJr(Addr: Integer);
    97105begin
     
    99107  Write(Addr - IP - 1);
    100108end;
     109{$ENDIF}
    101110
    102111procedure TInstructionWriter.AddInc(R: Integer);
  • branches/virtcpu fixed int/UMachine.pas

    r164 r165  
    55{$DEFINE EXT_ARITHMETIC}
    66{$DEFINE EXT_CONDITIONAL}
    7 //{$DEFINE EXT_LOGICAL}
     7{$DEFINE EXT_LOGICAL}
    88{$DEFINE EXT_STACK}
    99{$DEFINE EXT_SUBROUTINE}
    10 //{$DEFINE EXT_SHIFT}
     10{$DEFINE EXT_SHIFT}
    1111//{$DEFINE EXT_BLOCK}
    1212{$DEFINE EXT_GENERAL}
    1313//{$DEFINE EXT_BIT}
     14//{$DEFINE EXT_REL_JUMP}
    1415
    1516// Extension dependencies
     
    3031
    3132  TOpcode = (opNop, opLoad, opHalt, opLoadConst, opLoadMem, opStoreMem, opNeg,
    32     opJump, opJumpRel, opCall, opCallRel, opRet, opInput,
    33     opOutput, opInc, opDec, opAdd, opSub, opExchg,
    34     {$IFDEF EXT_STACK}
    35     opPush, opPop,
    36     {$ENDIF}
     33    opJump, {$IFDEF EXT_REL_JUMP}opJumpRel,{$ENDIF}
     34    opInc, opDec,
     35    {$IFDEF EXT_ARITHMETIC}opAdd, opSub,{$ENDIF}
     36    {$IFDEF EXT_IO}opInput, opOutput,{$ENDIF}
     37    {$IFDEF EXT_SUBROUTINE}opCall,
     38    {$IFDEF EXT_REL_JUMP}opCallRel,{$ENDIF}
     39    opRet,{$ENDIF}
     40    {$IFDEF EXT_GENERAL}opExchg,{$ENDIF}
     41    {$IFDEF EXT_LOGICAL}opAnd, opOr, opXor,{$ENDIF}
     42    {$IFDEF EXT_SHIFT}opShl, opShr,{$ENDIF}
     43    {$IFDEF EXT_STACK}opPush, opPop,{$ENDIF}
    3744    {$IFDEF EXT_CONDITIONAL}
    3845    opJumpRelCond, opJumpCond, opTestEqual, opTestNotEqual, opTestLess,
     
    5360    OpcodeHandlers: array[TOpcode] of TOpcodeHandler;
    5461    function ReadNext: T; inline;
     62    procedure OpcodeNop;
    5563    procedure OpcodeHalt;
    56     procedure OpcodeNop;
    5764    procedure OpcodeLoad;
    5865    procedure OpcodeLoadConst;
     66    procedure OpcodeJump;
     67    procedure OpcodeJumpRel;
     68    procedure OpcodeNeg;
     69    procedure OpcodeInc;
     70    procedure OpcodeDec;
    5971    {$IFDEF EXT_MEMORY}
    6072    procedure OpcodeLoadMem;
    6173    procedure OpcodeStoreMem;
    6274    {$ENDIF}
    63     procedure OpcodeNeg;
    6475    {$IFDEF EXT_GENERAL}
    6576    procedure OpcodeExchange;
    6677    {$ENDIF}
    67     procedure OpcodeJump;
    68     procedure OpcodeJumpRel;
    6978    {$IFDEF EXT_CONDITIONAL}
    7079    procedure OpcodeTestEqual;
     
    7584    procedure OpcodeTestLess;
    7685    procedure OpcodeJumpCond;
     86    {$IFDEF EXT_REL_JUMP}
    7787    procedure OpcodeJumpRelCond;
     88    {$ENDIF}
     89    {$ENDIF}
     90    {$IFDEF EXT_SHIFT}
     91    procedure OpcodeShl;
     92    procedure OpcodeShr;
     93    {$ENDIF}
     94    {$IFDEF EXT_LOGICAL}
     95    procedure OpcodeAnd;
     96    procedure OpcodeOr;
     97    procedure OpcodeXor;
    7898    {$ENDIF}
    7999    {$IFDEF EXT_STACK}
     
    83103    {$IFDEF EXT_SUBROUTINE}
    84104    procedure OpcodeCall;
     105    {$IFDEF EXT_REL_JUMP}
    85106    procedure OpcodeCallRel;
     107    {$ENDIF}
    86108    procedure OpcodeReturn;
    87109    {$ENDIF}
     
    90112    procedure OpcodeInput;
    91113    {$ENDIF}
    92     procedure OpcodeInc;
    93     procedure OpcodeDec;
    94114    {$IFDEF EXT_ARITHMETIC}
    95115    procedure OpcodeAdd;
     
    245265end;
    246266
     267{$IFDEF EXT_REL_JUMP}
    247268procedure TCPU.OpcodeJumpRelCond;
    248269begin
    249270  if Condition then IP := IP + ReadNext;
     271end;
     272{$ENDIF}
     273{$ENDIF}
     274
     275{$IFDEF EXT_SHIFT}
     276procedure TCPU.OpcodeShl;
     277var
     278  P1, P2: T;
     279begin
     280  P1 := ReadNext;
     281  P2 := ReadNext;
     282  Registers[P1] := Registers[P1] shl Registers[P2];
     283end;
     284
     285procedure TCPU.OpcodeShr;
     286var
     287  P1, P2: T;
     288begin
     289  P1 := ReadNext;
     290  P2 := ReadNext;
     291  Registers[P1] := Registers[P1] shr Registers[P2];
     292end;
     293{$ENDIF}
     294
     295{$IFDEF EXT_LOGICAL}
     296procedure TCPU.OpcodeAnd;
     297var
     298  P1, P2: T;
     299begin
     300  P1 := ReadNext;
     301  P2 := ReadNext;
     302  Registers[P1] := Registers[P1] and Registers[P2];
     303end;
     304
     305procedure TCPU.OpcodeOr;
     306var
     307  P1, P2: T;
     308begin
     309  P1 := ReadNext;
     310  P2 := ReadNext;
     311  Registers[P1] := Registers[P1] or Registers[P2];
     312end;
     313
     314procedure TCPU.OpcodeXor;
     315var
     316  P1, P2: T;
     317begin
     318  P1 := ReadNext;
     319  P2 := ReadNext;
     320  Registers[P1] := Registers[P1] xor Registers[P2];
    250321end;
    251322{$ENDIF}
     
    276347end;
    277348
     349{$IFDEF EXT_REL_JUMP}
    278350procedure TCPU.OpcodeCallRel;
    279351var
     
    285357  IP := IP + Addr;
    286358end;
     359{$ENDIF}
    287360
    288361procedure TCPU.OpcodeReturn;
     
    386459  OpcodeHandlers[opHalt] := OpcodeHalt;
    387460  OpcodeHandlers[opLoadConst] := OpcodeLoadConst;
     461  OpcodeHandlers[opNeg] := OpcodeNeg;
     462  OpcodeHandlers[opJump] := OpcodeJump;
     463  {$IFDEF EXT_REL_JUMP}
     464  OpcodeHandlers[opJumpRel] := OpcodeJumpRel;
     465  {$ENDIF}
    388466  {$IFDEF EXT_MEMORY}
    389467  OpcodeHandlers[opLoadMem] := OpcodeLoadMem;
    390468  OpcodeHandlers[opStoreMem] := OpcodeStoreMem;
    391469  {$ENDIF}
    392   OpcodeHandlers[opNeg] := OpcodeNeg;
    393   OpcodeHandlers[opJump] := OpcodeJump;
    394   OpcodeHandlers[opJumpRel] := OpcodeJumpRel;
    395470  {$IFDEF EXT_GENERAL}
    396471  OpcodeHandlers[opExchg] := OpcodeExchange;
     472  {$ENDIF}
     473  {$IFDEF EXT_LOGICAL}
     474  OpcodeHandlers[opAnd] := OpcodeAnd;
     475  OpcodeHandlers[opOr] := OpcodeOr;
     476  OpcodeHandlers[opXor] := OpcodeXor;
     477  {$ENDIF}
     478  {$IFDEF EXT_SHIFT}
     479  OpcodeHandlers[opShl] := OpcodeShl;
     480  OpcodeHandlers[opShr] := OpcodeShr;
    397481  {$ENDIF}
    398482  {$IFDEF EXT_STACK}
     
    402486  {$IFDEF EXT_SUBROUTINE}
    403487  OpcodeHandlers[opCall] := OpcodeCall;
     488  {$IFDEF EXT_REL_JUMP}
    404489  OpcodeHandlers[opCallRel] := OpcodeCallRel;
     490  {$ENDIF}
    405491  OpcodeHandlers[opRet] := OpcodeReturn;
    406492  {$ENDIF}
     
    417503  {$IFDEF EXT_ARITHMETIC}
    418504  OpcodeHandlers[opJumpCond] := OpcodeJumpCond;
     505  {$IFDEF EXT_REL_JUMP}
    419506  OpcodeHandlers[opJumpRelCond] := OpcodeJumpRelCond;
     507  {$ENDIF}
    420508  OpcodeHandlers[opTestEqual] := OpcodeTestEqual;
    421509  OpcodeHandlers[opTestNotEqual] := OpcodeTestNotEqual;
  • branches/virtcpu fixed int/virtcpu.lpi

    r163 r165  
    1212      <Icon Value="0"/>
    1313    </General>
    14     <BuildModes Count="1">
    15       <Item1 Name="Default" Default="True"/>
     14    <BuildModes Count="2">
     15      <Item1 Name="Debug" Default="True"/>
     16      <Item2 Name="Release">
     17        <CompilerOptions>
     18          <Version Value="11"/>
     19          <PathDelim Value="\"/>
     20          <Target>
     21            <Filename Value="virtcpu"/>
     22          </Target>
     23          <SearchPaths>
     24            <IncludeFiles Value="$(ProjOutDir)"/>
     25            <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
     26          </SearchPaths>
     27          <Parsing>
     28            <SyntaxOptions>
     29              <SyntaxMode Value="Delphi"/>
     30              <CStyleOperator Value="False"/>
     31              <AllowLabel Value="False"/>
     32              <CPPInline Value="False"/>
     33            </SyntaxOptions>
     34          </Parsing>
     35          <CodeGeneration>
     36            <SmartLinkUnit Value="True"/>
     37            <Optimizations>
     38              <OptimizationLevel Value="3"/>
     39            </Optimizations>
     40          </CodeGeneration>
     41          <Linking>
     42            <Debugging>
     43              <GenerateDebugInfo Value="False"/>
     44            </Debugging>
     45            <LinkSmart Value="True"/>
     46            <Options>
     47              <Win32>
     48                <GraphicApplication Value="True"/>
     49              </Win32>
     50            </Options>
     51          </Linking>
     52        </CompilerOptions>
     53      </Item2>
    1654    </BuildModes>
    1755    <PublishOptions>
     
    6098      <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
    6199    </SearchPaths>
     100    <Parsing>
     101      <SyntaxOptions>
     102        <SyntaxMode Value="Delphi"/>
     103        <CStyleOperator Value="False"/>
     104        <IncludeAssertionCode Value="True"/>
     105        <AllowLabel Value="False"/>
     106        <CPPInline Value="False"/>
     107      </SyntaxOptions>
     108    </Parsing>
    62109    <CodeGeneration>
    63       <Optimizations>
    64         <OptimizationLevel Value="3"/>
    65       </Optimizations>
     110      <Checks>
     111        <IOChecks Value="True"/>
     112        <RangeChecks Value="True"/>
     113        <OverflowChecks Value="True"/>
     114        <StackChecks Value="True"/>
     115      </Checks>
     116      <VerifyObjMethodCallValidity Value="True"/>
    66117    </CodeGeneration>
    67118    <Linking>
     119      <Debugging>
     120        <DebugInfoType Value="dsDwarf2Set"/>
     121        <UseHeaptrc Value="True"/>
     122        <UseExternalDbgSyms Value="True"/>
     123      </Debugging>
    68124      <Options>
    69125        <Win32>
Note: See TracChangeset for help on using the changeset viewer.