Changeset 172


Ignore:
Timestamp:
Apr 10, 2019, 11:49:27 PM (5 years ago)
Author:
chronos
Message:
  • Added: Build modes.
  • Fixed: Background thread code should not access main thread visual controls.
Location:
branches/virtualcpu4
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/virtualcpu4

    • Property svn:ignore
      •  

        old new  
        11lib
        22virtucpu4.exe
         3virtucpu4
        34*.lps
        45*.res
  • branches/virtualcpu4/UFormMain.lfm

    r171 r172  
    11object FormMain: TFormMain
    22  Left = 223
    3   Height = 790
     3  Height = 948
    44  Top = 54
    5   Width = 1432
     5  Width = 1718
    66  Caption = 'VirtCpu4'
    7   ClientHeight = 790
    8   ClientWidth = 1432
    9   DesignTimePPI = 120
     7  ClientHeight = 948
     8  ClientWidth = 1718
     9  DesignTimePPI = 144
    1010  OnCreate = FormCreate
    1111  OnDestroy = FormDestroy
     
    1313  LCLVersion = '2.0.0.4'
    1414  object ButtonStart: TButton
    15     Left = 984
    16     Height = 31
    17     Top = 8
    18     Width = 94
     15    Left = 1181
     16    Height = 37
     17    Top = 10
     18    Width = 113
    1919    Caption = 'Start'
    2020    OnClick = ButtonStartClick
     21    ParentFont = False
    2122    TabOrder = 0
    2223  end
    2324  object ButtonStop: TButton
    24     Left = 984
    25     Height = 31
    26     Top = 48
    27     Width = 94
     25    Left = 1181
     26    Height = 37
     27    Top = 58
     28    Width = 113
    2829    Caption = 'Stop'
    2930    OnClick = ButtonStopClick
     31    ParentFont = False
    3032    TabOrder = 1
    3133  end
    3234  object Label1: TLabel
    33     Left = 984
    34     Height = 20
    35     Top = 96
    36     Width = 35
     35    Left = 1181
     36    Height = 26
     37    Top = 115
     38    Width = 48
    3739    Caption = 'Ticks:'
    3840    ParentColor = False
     41    ParentFont = False
    3942  end
    4043  object ListViewRegisters: TListView
    41     Left = 8
    42     Height = 769
    43     Top = 8
    44     Width = 312
     44    Left = 10
     45    Height = 922
     46    Top = 10
     47    Width = 374
    4548    Anchors = [akTop, akLeft, akBottom]
    4649    Columns = <   
    4750      item
    4851        Caption = 'Register'
    49         Width = 100
     52        Width = 120
    5053      end   
    5154      item
    52         Width = 180
     55        Width = 239
    5356      end>
    54     Font.Height = -17
     57    Font.Height = -20
    5558    Font.Name = 'Liberation Mono'
    5659    OwnerData = True
     
    6164  end
    6265  object ListViewMemory: TListView
    63     Left = 328
    64     Height = 769
    65     Top = 8
    66     Width = 648
     66    Left = 394
     67    Height = 922
     68    Top = 10
     69    Width = 778
    6770    Anchors = [akTop, akLeft, akBottom]
    6871    Columns = <   
    6972      item
    7073        Caption = 'Address'
    71         Width = 100
     74        Width = 120
    7275      end   
    7376      item
    74         Width = 500
     77        Width = 643
    7578      end>
    76     Font.Height = -17
     79    Font.Height = -20
    7780    Font.Name = 'Liberation Mono'
    7881    OwnerData = True
     
    8386  end
    8487  object Memo1: TMemo
    85     Left = 984
    86     Height = 619
    87     Top = 160
    88     Width = 432
     88    Left = 1181
     89    Height = 743
     90    Top = 192
     91    Width = 518
    8992    OnKeyPress = Memo1KeyPress
     93    ParentFont = False
    9094    ReadOnly = True
    9195    TabOrder = 4
    9296  end
    9397  object Label2: TLabel
    94     Left = 984
    95     Height = 20
    96     Top = 136
    97     Width = 56
     98    Left = 1181
     99    Height = 26
     100    Top = 163
     101    Width = 73
    98102    Caption = 'Console:'
    99103    ParentColor = False
     104    ParentFont = False
    100105  end
    101106  object Timer1: TTimer
    102107    Interval = 200
    103108    OnTimer = Timer1Timer
    104     left = 96
    105     top = 144
     109    left = 115
     110    top = 173
    106111  end
    107112end
  • branches/virtualcpu4/UFormMain.pas

    r171 r172  
    77uses
    88  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
    9   ComCtrls, UCpu, UInstructionWriter;
     9  ComCtrls, UCpu, UInstructionWriter, syncobjs;
    1010
    1111type
     
    3232    procedure Timer1Timer(Sender: TObject);
    3333  private
    34     KeyInputBuffer: array of Char;
     34    InputBuffer: string;
     35    OutputBuffer: string;
     36    Lock: TCriticalSection;
    3537    function CpuInput(Port: TAddress): TRegister;
    3638    procedure CpuOutput(Port: TAddress; Value: TRegister);
     
    6769procedure TFormMain.FormCreate(Sender: TObject);
    6870begin
     71  Lock := TCriticalSection.Create;
    6972  Cpu := TCpu.Create;
    7073  Cpu.OnInput := CpuInput;
     
    8083  InstructionWriter.Free;
    8184  Cpu.Free;
     85  Lock.Free;
    8286end;
    8387
     
    120124procedure TFormMain.Memo1KeyPress(Sender: TObject; var Key: char);
    121125begin
    122   SetLength(KeyInputBuffer, Length(KeyInputBuffer) + 1);
    123   KeyInputBuffer[High(KeyInputBuffer)] := Key;
     126  Lock.Acquire;
     127  InputBuffer := InputBuffer + Key;
     128  Lock.Release;
    124129end;
    125130
     
    129134  ReloadMemoryDump;
    130135  ReloadRegisterDump;
     136  Lock.Acquire;
     137  Memo1.Lines.Text := Memo1.Lines.Text + OutputBuffer;
     138  SetLength(OutputBuffer, 0);
     139  Lock.Release;
    131140end;
    132141
     
    186195  case Port of
    187196    0: begin
    188       while (Length(KeyInputBuffer) = 0) and not Cpu.Terminated do begin
     197      Lock.Acquire;
     198      while (Length(InputBuffer) = 0) and not Cpu.Terminated do begin
     199        Lock.Release;
    189200        Sleep(100);
     201        Lock.Acquire;
    190202      end;
    191       if Length(KeyInputBuffer) > 0 then begin
    192         Result.B := Ord(KeyInputBuffer[0]);
    193         if Length(KeyInputBuffer) > 1 then
    194           Move(KeyInputBuffer[1], KeyInputBuffer[0], Length(KeyInputBuffer) - 1);
    195         SetLength(KeyInputBuffer, Length(KeyInputBuffer) - 1);
     203      if Length(InputBuffer) > 0 then begin
     204        Result.B := Ord(InputBuffer[1]);
     205        Delete(InputBuffer, 1, 1);
    196206      end else Result.B := 0;
     207      Lock.Release;
    197208    end;
    198209  end;
     
    202213begin
    203214  case Port of
    204     0: Memo1.Lines.Text := Memo1.Lines.Text + Char(Value.B);
     215    0: begin
     216      Lock.Acquire;
     217      OutputBuffer := OutputBuffer + Char(Value.B);
     218      Lock.Release;
     219    end;
    205220  end;
    206221end;
  • branches/virtualcpu4/virtucpu4.lpi

    r170 r172  
    1616      <Icon Value="0"/>
    1717    </General>
    18     <BuildModes Count="1">
    19       <Item1 Name="Default" Default="True"/>
     18    <BuildModes Count="2">
     19      <Item1 Name="Debug" Default="True"/>
     20      <Item2 Name="Release">
     21        <CompilerOptions>
     22          <Version Value="11"/>
     23          <PathDelim Value="\"/>
     24          <Target>
     25            <Filename Value="virtucpu4"/>
     26          </Target>
     27          <SearchPaths>
     28            <IncludeFiles Value="$(ProjOutDir)"/>
     29            <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)-$(BuildMode)"/>
     30          </SearchPaths>
     31          <Parsing>
     32            <SyntaxOptions>
     33              <SyntaxMode Value="Delphi"/>
     34              <CStyleOperator Value="False"/>
     35              <AllowLabel Value="False"/>
     36              <CPPInline Value="False"/>
     37            </SyntaxOptions>
     38          </Parsing>
     39          <CodeGeneration>
     40            <SmartLinkUnit Value="True"/>
     41            <Optimizations>
     42              <OptimizationLevel Value="3"/>
     43            </Optimizations>
     44          </CodeGeneration>
     45          <Linking>
     46            <Debugging>
     47              <GenerateDebugInfo Value="False"/>
     48            </Debugging>
     49            <LinkSmart Value="True"/>
     50            <Options>
     51              <Win32>
     52                <GraphicApplication Value="True"/>
     53              </Win32>
     54            </Options>
     55          </Linking>
     56        </CompilerOptions>
     57      </Item2>
    2058    </BuildModes>
    2159    <PublishOptions>
     
    62100    <SearchPaths>
    63101      <IncludeFiles Value="$(ProjOutDir)"/>
    64       <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
     102      <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)-$(BuildMode)"/>
    65103    </SearchPaths>
     104    <Parsing>
     105      <SyntaxOptions>
     106        <SyntaxMode Value="Delphi"/>
     107        <CStyleOperator Value="False"/>
     108        <IncludeAssertionCode Value="True"/>
     109        <AllowLabel Value="False"/>
     110        <CPPInline Value="False"/>
     111      </SyntaxOptions>
     112    </Parsing>
     113    <CodeGeneration>
     114      <Checks>
     115        <IOChecks Value="True"/>
     116        <RangeChecks Value="True"/>
     117        <OverflowChecks Value="True"/>
     118        <StackChecks Value="True"/>
     119      </Checks>
     120      <VerifyObjMethodCallValidity Value="True"/>
     121    </CodeGeneration>
    66122    <Linking>
     123      <Debugging>
     124        <UseHeaptrc Value="True"/>
     125      </Debugging>
    67126      <Options>
    68127        <Win32>
  • branches/virtualcpu4/virtucpu4.lpr

    r170 r172  
    44
    55uses
    6   {$IFDEF UNIX}{$IFDEF UseCThreads}
     6  {$IFDEF UNIX}
    77  cthreads,
    8   {$ENDIF}{$ENDIF}
     8  {$ENDIF}
    99  Interfaces, // this includes the LCL widgetset
    1010  Forms, UFormMain, UCpu
Note: See TracChangeset for help on using the changeset viewer.