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.
Location:
branches/virtcpu varint/Forms
Files:
13 added
2 moved

Legend:

Unmodified
Added
Removed
  • branches/virtcpu varint/Forms/UFormMain.lfm

    r196 r197  
    1010  OnCreate = FormCreate
    1111  OnDestroy = FormDestroy
    12   OnKeyPress = FormKeyPress
    1312  OnShow = FormShow
    1413  LCLVersion = '2.0.2.0'
    15   object ListViewMemory: TListView
    16     Left = 618
    17     Height = 824
    18     Top = 48
    19     Width = 880
    20     Columns = <   
    21       item
    22         Caption = 'Address'
    23         Width = 120
    24       end   
    25       item
    26         Width = 745
    27       end>
    28     Font.Name = 'Liberation Mono'
    29     OwnerData = True
    30     ParentFont = False
    31     TabOrder = 0
    32     ViewStyle = vsReport
    33     OnData = ListViewMemoryData
    34   end
    35   object ListViewRegisters: TListView
    36     Left = 374
    37     Height = 824
    38     Top = 49
    39     Width = 230
    40     Columns = <   
    41       item
    42         Caption = 'Register'
    43         Width = 96
    44       end   
    45       item
    46         Width = 120
    47       end>
    48     Font.Name = 'Liberation Mono'
    49     OwnerData = True
    50     ParentFont = False
    51     TabOrder = 1
    52     ViewStyle = vsReport
    53     OnData = ListViewRegistersData
    54   end
    55   object Memo1: TMemo
    56     Left = 19
    57     Height = 637
    58     Top = 29
    59     Width = 341
    60     OnKeyPress = Memo1KeyPress
    61     ParentFont = False
    62     ReadOnly = True
    63     TabOrder = 2
    64   end
    65   object Button1: TButton
     14  object ButtonStart: TButton
    6615    Left = 247
    6716    Height = 37
     
    6918    Width = 113
    7019    Caption = 'Start'
    71     OnClick = Button1Click
     20    OnClick = ButtonStartClick
    7221    ParentFont = False
    73     TabOrder = 3
     22    TabOrder = 0
    7423  end
    75   object Button2: TButton
     24  object ButtonStop: TButton
    7625    Left = 106
    7726    Height = 37
     
    7928    Width = 113
    8029    Caption = 'Stop'
    81     OnClick = Button2Click
     30    OnClick = ButtonStopClick
    8231    ParentFont = False
     32    TabOrder = 1
     33  end
     34  object ButtonConsole: TButton
     35    Left = 44
     36    Height = 38
     37    Top = 37
     38    Width = 113
     39    Caption = 'Console'
     40    OnClick = ButtonConsoleClick
     41    TabOrder = 2
     42  end
     43  object ButtonMemory: TButton
     44    Left = 46
     45    Height = 38
     46    Top = 86
     47    Width = 113
     48    Caption = 'Memory'
     49    OnClick = ButtonMemoryClick
     50    TabOrder = 3
     51  end
     52  object ButtonScreen: TButton
     53    Left = 47
     54    Height = 38
     55    Top = 139
     56    Width = 113
     57    Caption = 'Screen'
     58    OnClick = ButtonScreenClick
    8359    TabOrder = 4
    8460  end
    85   object LabelTicks: TLabel
    86     Left = 19
    87     Height = 26
    88     Top = 734
    89     Width = 48
    90     Caption = 'Ticks:'
    91     ParentColor = False
    92     ParentFont = False
     61  object ButtonCpuState: TButton
     62    Left = 44
     63    Height = 38
     64    Top = 192
     65    Width = 113
     66    Caption = 'CPU state'
     67    OnClick = ButtonCpuStateClick
     68    TabOrder = 5
     69  end
     70  object ButtonAssembler: TButton
     71    Left = 358
     72    Height = 38
     73    Top = 48
     74    Width = 169
     75    Caption = 'Assembler'
     76    OnClick = ButtonAssemblerClick
     77    TabOrder = 6
     78  end
     79  object ButtonDisassembler: TButton
     80    Left = 358
     81    Height = 38
     82    Top = 104
     83    Width = 170
     84    Caption = 'Disassembler'
     85    OnClick = ButtonDisassemblerClick
     86    TabOrder = 7
    9387  end
    9488  object Timer1: TTimer
    9589    Interval = 500
    96     OnTimer = Timer1Timer
    9790    left = 271
    9891    top = 810
  • branches/virtcpu varint/Forms/UFormMain.pas

    r196 r197  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
    9   StdCtrls, ExtCtrls, UMachine, UInstructionWriter;
     9  StdCtrls, ExtCtrls, UMachine, UInstructionWriter, UCpu;
    1010
    1111type
     
    1414
    1515  TFormMain = class(TForm)
    16     Button1: TButton;
    17     Button2: TButton;
    18     LabelTicks: TLabel;
    19     ListViewMemory: TListView;
    20     ListViewRegisters: TListView;
    21     Memo1: TMemo;
     16    ButtonStart: TButton;
     17    ButtonStop: TButton;
     18    ButtonAssembler: TButton;
     19    ButtonDisassembler: TButton;
     20    ButtonCpuState: TButton;
     21    ButtonScreen: TButton;
     22    ButtonMemory: TButton;
     23    ButtonConsole: TButton;
    2224    Timer1: TTimer;
    23     procedure Button1Click(Sender: TObject);
    24     procedure Button2Click(Sender: TObject);
     25    procedure ButtonStartClick(Sender: TObject);
     26    procedure ButtonStopClick(Sender: TObject);
     27    procedure ButtonAssemblerClick(Sender: TObject);
     28    procedure ButtonConsoleClick(Sender: TObject);
     29    procedure ButtonCpuStateClick(Sender: TObject);
     30    procedure ButtonDisassemblerClick(Sender: TObject);
     31    procedure ButtonMemoryClick(Sender: TObject);
     32    procedure ButtonScreenClick(Sender: TObject);
    2533    procedure FormCreate(Sender: TObject);
    2634    procedure FormDestroy(Sender: TObject);
    27     procedure FormKeyPress(Sender: TObject; var Key: char);
    2835    procedure FormShow(Sender: TObject);
    29     procedure ListViewMemoryData(Sender: TObject; Item: TListItem);
    30     procedure ListViewRegistersData(Sender: TObject; Item: TListItem);
    31     procedure Memo1KeyPress(Sender: TObject; var Key: char);
    32     procedure Timer1Timer(Sender: TObject);
    3336  private
    34     KeyInputBuffer: array of Char;
    35     procedure ReloadMemoryDump;
    36     procedure ReloadRegisterDump;
    37     function CpuInput(Port: T): T;
    38     procedure CpuOutput(Port, Value: T);
    3937  public
    4038    Machine: TMachine;
     
    4543  FormMain: TFormMain;
    4644
    47 const
    48   ItemsPerLine = 16;
    49 
    5045
    5146implementation
    5247
    5348{$R *.lfm}
     49
     50uses
     51  UFormConsole, UFormMemory, UFormScreen, UFormCpuState, UFormAssembler,
     52  UFormDisassembler;
    5453
    5554{ TFormMain }
     
    110109end;
    111110
    112 procedure TFormMain.FormKeyPress(Sender: TObject; var Key: char);
    113 begin
    114 end;
    115 
    116111procedure TFormMain.FormCreate(Sender: TObject);
    117112begin
    118113  Machine := TMachine.Create(nil);
    119   Machine.Cpu.OnInput := CpuInput;
    120   Machine.Cpu.OnOutput := CpuOutput;
    121114  InstructionWriter := TInstructionWriter.Create;
    122   InstructionWriter.Cpu := Machine.Cpu;
    123115end;
    124116
    125 procedure TFormMain.Button1Click(Sender: TObject);
     117procedure TFormMain.ButtonStartClick(Sender: TObject);
    126118begin
    127119  Machine.Cpu.Start;
    128120end;
    129121
    130 procedure TFormMain.Button2Click(Sender: TObject);
     122procedure TFormMain.ButtonStopClick(Sender: TObject);
    131123begin
    132124  Machine.Cpu.Stop;
    133125end;
    134126
    135 procedure TFormMain.ListViewMemoryData(Sender: TObject; Item: TListItem);
    136 var
    137   Line: string;
    138   I: Integer;
     127procedure TFormMain.ButtonAssemblerClick(Sender: TObject);
    139128begin
    140   if Item.Index < Machine.MemorySize div ItemsPerLine then begin
    141     Line := '';
    142     for I := 0 to ItemsPerLine - 1 do
    143       Line := Line + IntToHex(PByte(NativeUInt(Machine.Memory) + Item.Index * ItemsPerLine + I)^, 2) + ' ';
    144     Item.Caption := IntToHex(Item.Index * ItemsPerLine, 8);
    145     Item.SubItems.Add(Line);
    146   end;
     129  if not Assigned(FormAssembler) then
     130    FormAssembler := TFormAssembler.Create(Self);
     131  FormAssembler.Assembler.InstructionWriter.Memory := Machine.Memory;
     132  FormAssembler.Show;
    147133end;
    148134
    149 procedure TFormMain.ListViewRegistersData(Sender: TObject; Item: TListItem);
     135procedure TFormMain.ButtonConsoleClick(Sender: TObject);
    150136begin
    151   if Item.Index < Length(Machine.Cpu.Registers) + 1 then begin
    152     if Item.Index = 0 then begin
    153       Item.Caption := 'IP';
    154       Item.SubItems.Add(IntToHex(Int64(Machine.Cpu.IP), 8));
    155     end else
    156     if Item.Index = 1 then begin
    157       Item.Caption := 'SP';
    158       Item.SubItems.Add(IntToHex(Int64(Machine.Cpu.SP), 8));
    159     end else begin
    160       Item.Caption := 'R' + IntToStr(Item.Index - 2);
    161       Item.SubItems.Add(IntToHex(Int64(Machine.Cpu.Registers[Item.Index - 2]), 8));
    162     end;
    163   end;
     137  if not Assigned(FormConsole) then
     138    FormConsole := TFormConsole.Create(nil);
     139  FormConsole.Machine := Machine;
     140  FormConsole.Show;
    164141end;
    165142
    166 procedure TFormMain.Memo1KeyPress(Sender: TObject; var Key: char);
     143procedure TFormMain.ButtonCpuStateClick(Sender: TObject);
    167144begin
    168   SetLength(KeyInputBuffer, Length(KeyInputBuffer) + 1);
    169   KeyInputBuffer[High(KeyInputBuffer)] := Key;
     145  if not Assigned(FormCpuState) then
     146     FormCpuState := TFormCpuState.Create(Self);
     147   FormCpuState.Machine := Machine;
     148   FormCpuState.Show;
     149   FormCpuState.Reload;
    170150end;
    171151
    172 procedure TFormMain.Timer1Timer(Sender: TObject);
     152procedure TFormMain.ButtonDisassemblerClick(Sender: TObject);
    173153begin
    174   ReloadMemoryDump;
    175   ReloadRegisterDump;
    176   LabelTicks.Caption := 'Ticks: ' + IntToStr(Machine.Cpu.Ticks);
     154  if not Assigned(FormDisassembler) then
     155    FormDisassembler := TFormDisassembler.Create(Self);
     156  FormDisassembler.Disassembler.Cpu := Machine.Cpu;
     157  FormDisassembler.Show;
     158  FormDisassembler.Reload;
    177159end;
    178160
    179 procedure TFormMain.ReloadMemoryDump;
     161procedure TFormMain.ButtonMemoryClick(Sender: TObject);
    180162begin
    181   ListViewMemory.Items.Count := Machine.MemorySize div ItemsPerLine;
    182   ListViewMemory.Refresh;
     163  if not Assigned(FormMemory) then
     164    FormMemory := TFormMemory.Create(Self);
     165  FormMemory.Machine := Machine;
     166  FormMemory.Show;
     167  FormMemory.Reload;
    183168end;
    184169
    185 procedure TFormMain.ReloadRegisterDump;
     170procedure TFormMain.ButtonScreenClick(Sender: TObject);
    186171begin
    187   ListViewRegisters.Items.Count := Length(Machine.Cpu.Registers);
    188   ListViewRegisters.Refresh;
    189 end;
    190 
    191 function TFormMain.CpuInput(Port: T): T;
    192 begin
    193   Result := 0;
    194   case Integer(Port) of
    195     0: begin
    196       while (Length(KeyInputBuffer) = 0) and not Machine.Cpu.Terminated do begin
    197         Sleep(100);
    198         Application.ProcessMessages;
    199       end;
    200       if Length(KeyInputBuffer) > 0 then begin
    201         Result := Ord(KeyInputBuffer[0]);
    202         if Length(KeyInputBuffer) > 1 then
    203           Move(KeyInputBuffer[1], KeyInputBuffer[0], Length(KeyInputBuffer) - 1);
    204         SetLength(KeyInputBuffer, Length(KeyInputBuffer) - 1);
    205       end else Result := 0;
    206     end;
    207   end;
    208 end;
    209 
    210 procedure TFormMain.CpuOutput(Port, Value: T);
    211 begin
    212   case Integer(Port) of
    213     0: Memo1.Lines.Text := Memo1.Lines.Text + Char(Value);
    214   end;
     172  if not Assigned(FormScreen) then
     173    FormScreen := TFormScreen.Create(Self);
     174  FormScreen.Machine := Machine;
     175  FormScreen.Show;
     176  FormScreen.Reload;
    215177end;
    216178
Note: See TracChangeset for help on using the changeset viewer.