⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logicev.pas

📁 汇编编程艺术
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit Logicev;

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, ExtCtrls, VBXCtrl, Switch, StdCtrls, Buttons, TabNotBk,
  Grids, About;

type
  TLogicEval = class(TForm)
    Screens: TTabbedNotebook;

    A: TBiSwitch;	{ Input Switches on EXECUTE form.	}
    B: TBiSwitch;
    C: TBiSwitch;
    D: TBiSwitch;

    W: TShape;		{ Four LEDs on EXECUTE form.		}
    X: TShape;
    Y: TShape;
    Z: TShape;
    WLbl: TLabel;	{Labels on the LEDs.			}
    XLbl: TLabel;
    YLbl: TLabel;
    ZLbl: TLabel;
    E: TShape;
    F: TShape;
    G: TShape;
    I: TShape;
    J: TShape;
    H: TShape;
    K: TShape;
    SevenSeg: TPanel;
    ExecVariables: TStringGrid;

    EqnList: TListBox;		{ List of equations on execute page.	}

    AInit: TGroupBox;		{ "Buttons" on the INIT page.		}
    BInit: TGroupBox;
    CInit: TGroupBox;
    DInit: TGroupBox;
    EInit: TGroupBox;
    FInit: TGroupBox;
    GInit: TGroupBox;
    Hinit: TGroupBox;
    IInit: TGroupBox;
    Jinit: TGroupBox;
    KInit: TGroupBox;
    LInit: TGroupBox;
    MInit: TGroupBox;
    NInit: TGroupBox;
    OInit: TGroupBox;
    PInit: TGroupBox;
    QInit: TGroupBox;
    RInit: TGroupBox;
    SInit: TGroupBox;
    TInit: TGroupBox;
    UInit: TGroupBox;
    VInit: TGroupBox;
    WInit: TGroupBox;
    XInit: TGroupBox;
    YInit: TGroupBox;
    ZInit: TGroupBox;

    AValue: TLabel;		{ Values displayed on the "INIT" page.	}
    BValue: TLabel;
    CValue: TLabel;
    DValue: TLabel;
    EValue: TLabel;
    FValue: TLabel;
    GValue: TLabel;
    HValue: TLabel;
    IValue: TLabel;
    JValue: TLabel;
    KValue: TLabel;
    LValue: TLabel;
    MValue: TLabel;
    NValue: TLabel;
    OValue: TLabel;
    PValue: TLabel;
    QValue: TLabel;
    RValue: TLabel;
    SValue: TLabel;
    TValue: TLabel;
    UValue: TLabel;
    VValue: TLabel;
    WValue: TLabel;
    XValue: TLabel;
    YValue: TLabel;
    ZValue: TLabel;


    Exit: TButton;	{ Various buttons appearing on the forms.	}
    ExitBtn1: TButton;
    ExitBtn: TButton;
    AboutBtn1: TButton;
    AboutBtn2: TButton;
    AboutBtn3: TButton;
    AddEqnBtn: TButton;
    DeleteBtn: TButton;
    EditBtn: TButton;
    PrintBtn: TButton;
    PrintBtn2: TButton;
    PrintBtn3: TButton;
    PulseBtn: TBitBtn;

    PrintDialog: TPrintDialog;
    InstabilityAnnunc: TPanel;

    tt30: TPanel;	{ Squares in the truth table on the create page	}
    tt31: TPanel;
    tt32: TPanel;
    tt33: TPanel;
    tt00: TPanel;
    tt01: TPanel;
    tt02: TPanel;
    tt03: TPanel;
    tt10: TPanel;
    tt20: TPanel;
    tt11: TPanel;
    tt12: TPanel;
    tt13: TPanel;
    tt21: TPanel;
    tt22: TPanel;
    tt23: TPanel;

    ctt00: TPanel;
    ctt10: TPanel;
    ctt20: TPanel;
    ctt30: TPanel;
    ctt01: TPanel;
    ctt02: TPanel;
    ctt03: TPanel;
    ctt11: TPanel;
    ctt12: TPanel;
    ctt13: TPanel;
    ctt21: TPanel;
    ctt22: TPanel;
    ctt23: TPanel;
    ctt31: TPanel;
    ctt32: TPanel;
    ctt33: TPanel;


    ba00: TLabel;	{Labels on the truth table.			}
    ba01: TLabel;
    ba10: TLabel;
    ba11: TLabel;
    dc00: TLabel;
    DC01: TLabel;
    DC10: TLabel;
    DC11: TLabel;
    dc211: TLabel;
    dc210: TLabel;
    dc201: TLabel;
    dc200: TLabel;

    RBrace1: TLabel;
    ClkLbl1: TLabel;
    RBrace2: TLabel;
    ClkLbl2: TLabel;

    InitInstrsLbl: TLabel;
    Instrs2: TLabel;
    ExecEqns: TMemo;

    procedure COn(Sender: TObject);
    procedure COff(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure AOff(Sender: TObject);
    procedure AOn(Sender: TObject);
    procedure BOff(Sender: TObject);
    procedure BOn(Sender: TObject);
    procedure DOff(Sender: TObject);
    procedure DOn(Sender: TObject);
    procedure ExitBtnClick(Sender: TObject);
    procedure AboutBtn2Click(Sender: TObject);
    procedure InitClick(Sender: TObject);
    procedure AddEqnBtnClick(Sender: TObject);
    procedure ValueClick(Sender: TObject);
    procedure EqnListClick(Sender: TObject);
    procedure EditBtnClick(Sender: TObject);
    procedure EqnListDblClick(Sender: TObject);
    procedure DeleteBtnClick(Sender: TObject);
    procedure PrintBtnClick(Sender: TObject);
    procedure ScreensChange(Sender: TObject; NewTab: Integer;
      var AllowChange: Boolean);
    procedure PulseBtnClick(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;



  { TruthType-	Data type that holds the binary information of a truth	}
  {		table.  NumVars is the number of variables that provide	}
  {		indexes into this truth table.  theVars[0..3] are the	}
  {		single character variable names used in this function.	}
  {		theVars[4] is where the function stores its result.	}
  {		tt[clk,d,c,b,a] is the actual truth table.		}

  TruthType = record
  		NumVars:integer;
                theVars:array [0..4] of char;
                tt:array [0..1,0..1,0..1,0..1,0..1] of integer;

  	      end;
var
  LogicEval: TLogicEval;

  { tt is an array of pointers to the panels that make up the squares	}
  { of the truth table on the create page.  It provides a convenient	}
  { way to access those panels using array notation.			}

  tt: array [0..1, 0..1, 0..1, 0..1, 0..1] of TPanel;

  { TruthTbls holds the truth tables for each of the functions the	}
  { user defines on the Create page.					}

  TruthTbls: array ['A'..'Z'] of TruthType;

  { EqnSet holds the set of variables that have been defined and for	}
  { which truth tables exist.						}

  EqnSet: set of char;









implementation

{$R *.DFM}

uses EqnEntry;


type
   variables= array ['@'..'['] of integer;

var

   { Values holds the current values of all the variables in the system	}
   { Values2 is an array of pointers that point at the labels that	}
   { display each of the values on the initialization page.		}

   Values:	variables;
   Values2:	array ['@'..'['] of TLabel;





{ FormCreate does all the initialization when the program starts.	}

procedure TLogicEval.FormCreate(Sender: TObject);
var i:integer;
    ch:char;

begin


     { Label all the variables on the EXECUTE page.  Also, set their	}
     { values all to zero.						}

     for i := 1 to 26 do
     begin

         ExecVariables.Cells[i,0] := chr(ord('@') + i);
         ExecVariables.Cells[i,1] := '0';

     end;
     ExecVariables.Cells[0,0] := '#';
     ExecVariables.Cells[0,1] := '0';

     { Initialize all the variable values to zero.			}

     for ch := '@' to '[' do Values[ch] := 0;

     { At this point there are no equations defined.  Note that here.	}

     EqnSet := [];

     { Initialize the array of Value pointers so they point at the	}
     { value labels on the initialization page.				}

     Values2['A'] := AValue;
     Values2['B'] := BValue;
     Values2['C'] := CValue;
     Values2['D'] := DValue;
     Values2['E'] := EValue;
     Values2['F'] := FValue;
     Values2['G'] := GValue;
     Values2['H'] := HValue;
     Values2['I'] := IValue;
     Values2['J'] := JValue;
     Values2['K'] := KValue;
     Values2['L'] := LValue;
     Values2['M'] := MValue;
     Values2['N'] := NValue;
     Values2['O'] := OValue;
     Values2['P'] := PValue;
     Values2['Q'] := QValue;
     Values2['R'] := RValue;
     Values2['S'] := SValue;
     Values2['T'] := TValue;
     Values2['U'] := UValue;
     Values2['V'] := VValue;
     Values2['W'] := WValue;
     Values2['X'] := XValue;
     Values2['Y'] := YValue;
     Values2['Z'] := ZValue;


     { Initialize the tt array so that each element points at the	}
     { appropriate square on the truth table on the CREATE page.	}

     tt[0, 0,0,0,0]:= tt00;
     tt[0, 0,0,0,1]:= tt01;
     tt[0, 0,0,1,0]:= tt02;
     tt[0, 0,0,1,1]:= tt03;

     tt[0, 0,1,0,0]:= tt10;
     tt[0, 0,1,0,1]:= tt11;
     tt[0, 0,1,1,0]:= tt12;
     tt[0, 0,1,1,1]:= tt13;

     tt[0, 1,0,0,0]:= tt20;
     tt[0, 1,0,0,1]:= tt21;
     tt[0, 1,0,1,0]:= tt22;
     tt[0, 1,0,1,1]:= tt23;

     tt[0, 1,1,0,0]:= tt30;
     tt[0, 1,1,0,1]:= tt31;
     tt[0, 1,1,1,0]:= tt32;
     tt[0, 1,1,1,1]:= tt33;


     tt[1, 0,0,0,0]:= ctt00;
     tt[1, 0,0,0,1]:= ctt01;
     tt[1, 0,0,1,0]:= ctt02;
     tt[1, 0,0,1,1]:= ctt03;

     tt[1, 0,1,0,0]:= ctt10;
     tt[1, 0,1,0,1]:= ctt11;
     tt[1, 0,1,1,0]:= ctt12;
     tt[1, 0,1,1,1]:= ctt13;

     tt[1, 1,0,0,0]:= ctt20;
     tt[1, 1,0,0,1]:= ctt21;
     tt[1, 1,0,1,0]:= ctt22;
     tt[1, 1,0,1,1]:= ctt23;

     tt[1, 1,1,0,0]:= ctt30;
     tt[1, 1,1,0,1]:= ctt31;
     tt[1, 1,1,1,0]:= ctt32;
     tt[1, 1,1,1,1]:= ctt33;

     { Initialize the default equation for the equation editor.		}

     LastEqn := 'F=0';

     { Make the CREATE page show up on the form when we start.		}

     Screens.ActivePage := 'Create';

end;



{ The following procedure stores "Value" into the variable specified by	}
{ "vName".  It also updates the variable display and any necessary LEDs	}
{ on the EXECUTE page.							}

procedure SetVar(vName:char; Value:integer);
begin

  with LogicEval do begin

     { Convert "#" to "@" so we can use a compact array ("@" appears	}
     { just before "A" in the ASCII character set, "#" is some distance	}
     { away from the alphabetic characters).				}

     if (vName = '#') then vName := '@';

     { Update the value in the Values matrix and the label on the init-	}
     { ialization page.							}

     Values [vName] := Value;
     Values2[vName].Caption := chr(Value+ord('0'));

     { Update the value on the EXECUTE page.				}

     ExecVariables.Cells[ord(vName)-ord('@'),1] :=
           chr(ord('0') + Value);

     { If this variable is E..K, then update the corresponding segment	}
     { on the seven-segment display.					}

     if (vName = 'E') then
        if (Value = 1) then E.Brush.Color := clRed
        else E.Brush.Color := clSilver;

     if (vName = 'F') then
        if (Value = 1) then F.Brush.Color := clRed
        else F.Brush.Color := clSilver;

     if (vName = 'G') then
        if (Value = 1) then G.Brush.Color := clRed
        else G.Brush.Color := clSilver;

     if (vName = 'H') then
        if (Value = 1) then H.Brush.Color := clRed
        else H.Brush.Color := clSilver;

     if (vName = 'I') then
        if (Value = 1) then I.Brush.Color := clRed
        else I.Brush.Color := clSilver;

     if (vName = 'J') then
        if (Value = 1) then J.Brush.Color := clRed
        else J.Brush.Color := clSilver;

     if (vName = 'K') then
        if (Value = 1) then K.Brush.Color := clRed
        else K.Brush.Color := clSilver;


     { If this variable is W..Z, then update the corresponding LED.	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -