Changeset 181


Ignore:
Timestamp:
Apr 13, 2019, 12:03:31 AM (6 years ago)
Author:
chronos
Message:
  • Added: Disassemble instruction.
Location:
branches/virtualcpu4
Files:
3 added
8 edited

Legend:

Unmodified
Added
Removed
  • branches/virtualcpu4/Forms/UFormDisassembler.lfm

    r180 r181  
    2525      item
    2626        Caption = 'Opcode'
    27         Width = 100
     27        Width = 150
    2828      end   
    2929      item
    3030        Caption = 'Assembly'
    31         Width = 490
     31        Width = 440
    3232      end>
    3333    OwnerData = True
  • branches/virtualcpu4/Forms/UFormDisassembler.pas

    r180 r181  
    77uses
    88  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls,
    9   UInstructionWriter;
     9  UDisassembler;
    1010
    1111type
  • branches/virtualcpu4/Forms/UFormMain.lfm

    r180 r181  
    11object FormMain: TFormMain
    2   Left = 288
    3   Height = 948
    4   Top = 196
    5   Width = 1718
     2  Left = 780
     3  Height = 269
     4  Top = 527
     5  Width = 659
    66  Caption = 'VirtCpu4'
    7   ClientHeight = 948
    8   ClientWidth = 1718
     7  ClientHeight = 269
     8  ClientWidth = 659
    99  DesignTimePPI = 144
    1010  OnCreate = FormCreate
     
    1313  LCLVersion = '2.0.0.4'
    1414  object ButtonStart: TButton
    15     Left = 1181
     15    Left = 229
    1616    Height = 37
    17     Top = 10
     17    Top = 17
    1818    Width = 113
    1919    Caption = 'Start'
     
    2323  end
    2424  object ButtonStop: TButton
    25     Left = 1181
     25    Left = 229
    2626    Height = 37
    27     Top = 58
     27    Top = 65
    2828    Width = 113
    2929    Caption = 'Stop'
     
    3333  end
    3434  object ButtonDisassembler: TButton
    35     Left = 1323
     35    Left = 371
    3636    Height = 38
    37     Top = 10
     37    Top = 17
    3838    Width = 185
    3939    Caption = 'Disassembler'
     
    4242  end
    4343  object ButtonMemory: TButton
    44     Left = 1323
     44    Left = 371
    4545    Height = 38
    46     Top = 57
     46    Top = 64
    4747    Width = 185
    4848    Caption = 'Memory'
     
    5151  end
    5252  object ButtonCpuState: TButton
    53     Left = 1323
     53    Left = 371
    5454    Height = 38
    55     Top = 104
     55    Top = 111
    5656    Width = 185
    5757    Caption = 'CPU state'
     
    6060  end
    6161  object ButtonScreen: TButton
    62     Left = 976
     62    Left = 24
    6363    Height = 38
    64     Top = 9
     64    Top = 16
    6565    Width = 185
    6666    Caption = 'Screen'
     
    6969  end
    7070  object ButtonConsole: TButton
    71     Left = 976
     71    Left = 24
    7272    Height = 38
    73     Top = 57
     73    Top = 64
    7474    Width = 185
    7575    Caption = 'Console'
  • branches/virtualcpu4/Forms/UFormMain.pas

    r180 r181  
    6060  if not Assigned(FormDisassembler) then
    6161    FormDisassembler := TFormDisassembler.Create(Self);
    62   FormDisassembler.Disassembler.Memory.Owner:= False;
    63   FormDisassembler.Disassembler.Memory.Data := Machine.Memory;
     62  FormDisassembler.Disassembler.Cpu := Machine.Cpu;
    6463  FormDisassembler.Disassembler.Process;
    6564  FormDisassembler.Show;
     
    164163    Decrement(R2);
    165164    Test(R2);
    166     AddrPrefix8; JumpNotZero(LabelPrintLoop);
     165    AddrPrefix8; JumpRelNotZero(LabelPrintLoop);
    167166    Pop(R1);
    168167    Pop(R2);
  • branches/virtualcpu4/UCpu.pas

    r180 r181  
    134134  end;
    135135
     136  TOpcodeParam = (prNone, prReg, prData, prAddr, prAddrRel);
     137  TOpcodeDef = record
     138    Name: string;
     139    Param1: TOpcodeParam;
     140    Param2: TOpcodeParam;
     141    Param3: TOpcodeParam;
     142  end;
     143
    136144const
    137145  BitWidthBytes: array[TBitWidth] of Byte = (0, 1, 2, 4, 8);
    138146  BitWidthText: array[TBitWidth] of string = ('None', '8-bit', '16-bit', '32-bit', '64-bit');
     147  OpcodeDef: array[TOpcode] of TOpcodeDef = (
     148    (Name: 'NOP'; Param1: prNone; Param2: prNone; Param3: prNone),
     149    (Name: 'HALT'; Param1: prNone; Param2: prNone; Param3: prNone),
     150    (Name: 'LD'; Param1: prReg; Param2: prReg; Param3: prNone),
     151    (Name: 'LDI'; Param1: prReg; Param2: prData; Param3: prNone),
     152    (Name: 'JP'; Param1: prAddr; Param2: prNone; Param3: prNone),
     153    (Name: 'JPZ'; Param1: prAddr; Param2: prNone; Param3: prNone),
     154    (Name: 'JPNZ'; Param1: prAddr; Param2: prNone; Param3: prNone),
     155    (Name: 'JR'; Param1: prAddrRel; Param2: prNone; Param3: prNone),
     156    (Name: 'JRZ'; Param1: prAddrRel; Param2: prNone; Param3: prNone),
     157    (Name: 'JRNZ'; Param1: prAddrRel; Param2: prNone; Param3: prNone),
     158    (Name: 'NEG'; Param1: prReg; Param2: prNone; Param3: prNone),
     159    (Name: 'CLR'; Param1: prReg; Param2: prNone; Param3: prNone),
     160    (Name: 'LDM'; Param1: prReg; Param2: prReg; Param3: prNone),
     161    (Name: 'STM'; Param1: prReg; Param2: prReg; Param3: prNone),
     162    (Name: 'EX'; Param1: prReg; Param2: prReg; Param3: prNone),
     163    (Name: 'PUSH'; Param1: prReg; Param2: prNone; Param3: prNone),
     164    (Name: 'POP'; Param1: prReg; Param2: prNone; Param3: prNone),
     165    (Name: 'CALL'; Param1: prAddr; Param2: prNone; Param3: prNone),
     166    (Name: 'RET'; Param1: prNone; Param2: prNone; Param3: prNone),
     167    (Name: 'ADD'; Param1: prReg; Param2: prReg; Param3: prNone),
     168    (Name: 'ADDI'; Param1: prReg; Param2: prData; Param3: prNone),
     169    (Name: 'SUB'; Param1: prReg; Param2: prReg; Param3: prNone),
     170    (Name: 'SUBI'; Param1: prReg; Param2: prData; Param3: prNone),
     171    (Name: 'INC'; Param1: prReg; Param2: prNone; Param3: prNone),
     172    (Name: 'DEC'; Param1: prReg; Param2: prNone; Param3: prNone),
     173    (Name: 'IN'; Param1: prReg; Param2: prAddr; Param3: prNone),
     174    (Name: 'OUT'; Param1: prAddr; Param2: prReg; Param3: prNone),
     175    (Name: 'SHL'; Param1: prReg; Param2: prReg; Param3: prNone),
     176    (Name: 'SHR'; Param1: prReg; Param2: prReg; Param3: prNone),
     177    (Name: 'DP8'; Param1: prNone; Param2: prNone; Param3: prNone),
     178    (Name: 'DP16'; Param1: prNone; Param2: prNone; Param3: prNone),
     179    (Name: 'DP32'; Param1: prNone; Param2: prNone; Param3: prNone),
     180    (Name: 'DP64'; Param1: prNone; Param2: prNone; Param3: prNone),
     181    (Name: 'DS'; Param1: prNone; Param2: prNone; Param3: prNone),
     182    (Name: 'AS'; Param1: prNone; Param2: prNone; Param3: prNone),
     183    (Name: 'TEST'; Param1: prReg; Param2: prNone; Param3: prNone),
     184    (Name: 'AND'; Param1: prReg; Param2: prReg; Param3: prNone),
     185    (Name: 'OR'; Param1: prReg; Param2: prReg; Param3: prNone),
     186    (Name: 'XOR'; Param1: prReg; Param2: prReg; Param3: prNone),
     187    (Name: 'LDDR'; Param1: prReg; Param2: prReg; Param3: prReg),
     188    (Name: 'LDDR'; Param1: prReg; Param2: prReg; Param3: prReg),
     189    (Name: 'MUL'; Param1: prReg; Param2: prReg; Param3: prNone),
     190    (Name: 'DIV'; Param1: prReg; Param2: prReg; Param3: prNone),
     191    (Name: 'MOD'; Param1: prReg; Param2: prReg; Param3: prNone),
     192    (Name: 'AP8'; Param1: prNone; Param2: prNone; Param3: prNone),
     193    (Name: 'AP16'; Param1: prNone; Param2: prNone; Param3: prNone),
     194    (Name: 'AP32'; Param1: prNone; Param2: prNone; Param3: prNone),
     195    (Name: 'AP64'; Param1: prNone; Param2: prNone; Param3: prNone)
     196  );
    139197
    140198implementation
  • branches/virtualcpu4/UInstructionWriter.pas

    r180 r181  
    66
    77uses
    8   Classes, SysUtils, UCpu, UMemory, fgl;
     8  Classes, SysUtils, UCpu;
    99
    1010type
     
    3131    procedure Write64(Value: QWord);
    3232    procedure WriteAddress(Value: TAddress);
    33     procedure WriteAddressSigned(Value: TAddressSigned);
     33    procedure WriteAddressSigned(Value: TAddressSigned); inline;
    3434    procedure WriteData(Value: QWord);
    3535    procedure WriteString(Text: string);
     
    6464  end;
    6565
    66   { TAssembler }
    67 
    68   TAssembler = class
    69     Source: TStringList;
    70     Dest: array of Byte;
    71     procedure Compile;
    72   end;
    73 
    74   TDisassemblerLine = class
    75     Address: Integer;
    76     Opcode: string;
    77     Instruction: string;
    78   end;
    79 
    80   { TDisassembler }
    81 
    82   TDisassembler = class
    83     Memory: TMemoryPos;
    84     Output: TFPGObjectList<TDisassemblerLine>;
    85     procedure Process;
    86     constructor Create;
    87     destructor Destroy; override;
    88   end;
    89 
    90 const
    91   OpcodeName: array[TOpcode] of string = ('NOP', 'HALT', 'LD', 'LDI', 'JP', 'JPZ',
    92     'JPNZ', 'JR', 'JRZ', 'JRNZ', 'NEG', 'CLR', 'LDM', 'STM', 'EX', 'PUSH', 'POP',
    93     'CALL', 'RET', 'ADD', 'ADDI', 'SUB', 'SUBI', 'INC', 'DEC', 'IN', 'OUT',
    94     'SHL', 'SHR', 'DP8', 'DP16', 'DP32', 'DP64', 'DS', 'AS', 'TEST', 'AND', 'OR',
    95     'XOR', 'LDDR', 'LDIR', 'MUL', 'DIV', 'MOD', 'AP8', 'AP16', 'AP32', 'AP64');
    9666
    9767implementation
    98 
    99 { TDisassembler }
    100 
    101 procedure TDisassembler.Process;
    102 var
    103   Opcode: Byte;
    104   Line: TDisassemblerLine;
    105 begin
    106   Output.Clear;
    107   Memory.Position := Memory.Data;
    108 
    109   while Memory.Position < Memory.Data + Memory.Size do begin
    110     Opcode := Memory.ReadByte;
    111     if Opcode < Integer(High(TOpcode)) then begin
    112       Line := TDisassemblerLine.Create;
    113       Line.Address := Memory.Position - Memory.Data;
    114       Line.Opcode := IntToHex(Opcode, 2);
    115       Line.Instruction := OpcodeName[TOpcode(Opcode)];
    116       Output.Add(Line);
    117     end;
    118   end;
    119 end;
    120 
    121 constructor TDisassembler.Create;
    122 begin
    123   Output := TFPGObjectList<TDisassemblerLine>.Create;
    124   Memory := TMemoryPos.Create;
    125 end;
    126 
    127 destructor TDisassembler.Destroy;
    128 begin
    129   Memory.Free;
    130   Output.Free;
    131   inherited Destroy;
    132 end;
    133 
    134 { TAssembler }
    135 
    136 procedure TAssembler.Compile;
    137 begin
    138 
    139 end;
    14068
    14169{ TInstructionWriter }
  • branches/virtualcpu4/virtucpu4.lpi

    r180 r181  
    7171      </Item1>
    7272    </RequiredPackages>
    73     <Units Count="11">
     73    <Units Count="14">
    7474      <Unit0>
    7575        <Filename Value="virtucpu4.lpr"/>
     
    129129        <ResourceBaseClass Value="Form"/>
    130130      </Unit10>
     131      <Unit11>
     132        <Filename Value="UDisassembler.pas"/>
     133        <IsPartOfProject Value="True"/>
     134      </Unit11>
     135      <Unit12>
     136        <Filename Value="UAssembler.pas"/>
     137        <IsPartOfProject Value="True"/>
     138      </Unit12>
     139      <Unit13>
     140        <Filename Value="UInstructionReader.pas"/>
     141        <IsPartOfProject Value="True"/>
     142      </Unit13>
    131143    </Units>
    132144  </ProjectOptions>
  • branches/virtualcpu4/virtucpu4.lpr

    r180 r181  
    99  Interfaces, // this includes the LCL widgetset
    1010  SysUtils, Forms, UFormMain, UCpu, UMachine, UMemory, UFormDisassembler,
    11   UFormMemory, UFormCpuState, UFormScreen, UFormConsole
     11  UFormMemory, UFormCpuState, UFormScreen, UFormConsole, UDisassembler,
     12  UAssembler, UInstructionReader
    1213  { you can add units after this };
    1314
Note: See TracChangeset for help on using the changeset viewer.