Fix bug in SNaN & QNaN translation.
[marekmrva_bc.git] / MiscViewClass.pas
blobb15a5aed70538908654b88af84ee9f024f87215e
1 unit MiscViewClass;
3 interface
5 uses
6 ConstantsClass, CustomViewClass, FunctionsClass, HardwareClass, HexEditClass,
7 ResourcesClass, TypesClass,
8 Classes, Grids, Menus;
10 type
12 { TMiscView }
14 TMiscView = class(TCustomView)
15 private
16 pHexEdit: THexEdit;
17 function pGetWidth: Integer; virtual;
18 procedure pCustomKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); virtual;
19 procedure pOnState(Sender: TObject); virtual;
20 procedure pSetWidth(Width: Integer); virtual;
21 public
22 constructor CreateMiscView(AOwner: TComponent; Hw: THardware); virtual;
23 procedure ChangeCW; virtual;
24 procedure ChangeSW; virtual;
25 procedure CyclePrecision; virtual;
26 procedure CycleRound; virtual;
27 procedure ToggleCondition(Line: Integer); virtual;
28 property Width read pGetWidth write pSetWidth;
29 end;
31 implementation
33 // ************************************************************************** //
34 // * TMiscView implementation * //
35 // ************************************************************************** //
37 function TMiscView.pGetWidth: Integer;
38 begin
39 Result := inherited Width;
40 end;
42 procedure TMiscView.pCustomKeyDown(Sender: TObject; var Key: Word;
43 Shift: TShiftState);
44 var
45 lselect: TGridCoord;
46 begin
47 lselect := Selection.TopLeft;
48 if not(lselect.X = 1) then Exit;
49 case Key of
50 KEY_RETURN, KEY_SPACE:
51 case lselect.Y of
52 0: ChangeSW;
53 1: ChangeCW;
54 2..5: ToggleCondition(lselect.Y);
55 6: CyclePrecision;
56 7: CycleRound;
57 end;
58 end;
59 end;
61 procedure TMiscView.pOnState(Sender: TObject);
62 var
63 i: Integer;
64 begin
65 with Hardware.State.FPUState do
66 begin
67 Changes[1, 0] := not(StatusWord = Hardware.OldState.FPUState.StatusWord);
68 Changes[0, 0] := Changes[1, 0];
69 Cells[0, 0] := MSC_VIEW_FSW;
70 Cells[1, 0] := CustomDataToHex(@StatusWord, SizeOf(StatusWord));
71 Changes[1, 1] := not(ControlWord = Hardware.OldState.FPUState.ControlWord);
72 Changes[0, 1] := Changes[1, 1];
73 Cells[0, 1] := MSC_VIEW_FCW;
74 Cells[1, 1] := CustomDataToHex(@ControlWord, SizeOf(ControlWord));
75 Changes[1, 6] := not CompareStatePrecision(Hardware);
76 Changes[0, 6] := Changes[1, 6];
77 Cells[0, 6] := MSC_VIEW_PREC;
78 Cells[1, 6] := DESC_PREC[GetPrecision(Hardware.State)];
79 Changes[1, 7] := not CompareStateRound(Hardware);
80 Changes[0, 7] := Changes[1, 7];
81 Cells[0, 7] := MSC_VIEW_ROUND;
82 Cells[1, 7] := DESC_ROUN[GetRound(Hardware.State)];
83 end;
84 for i := 0 to 3 do
85 begin
86 Changes[1, i + 2] := not CompareStateCondition(Hardware, i);
87 Changes[0, i + 2] := Changes[1, i + 2];
88 Cells[0, i + 2] := DESC_COND[i];
89 if GetCondition(Hardware.State, i) then Cells[1, i + 2] := MSC_VIEW_TRUE
90 else Cells[1, i + 2] := MSC_VIEW_FALSE;
91 end;
92 end;
94 procedure TMiscView.pSetWidth(Width: Integer);
95 begin
96 inherited Width := Width;
97 ColWidths[1] := ClientWidth div 2;
98 ColWidths[0] := ClientWidth - ColWidths[1];
99 end;
101 constructor TMiscView.CreateMiscView(AOwner: TComponent; Hw: THardware);
102 begin
103 inherited CreateView(AOwner, Hw);
104 RowCount := 8;
105 ColCount := 2;
106 OnKeyDown := pCustomKeyDown;
107 OnState := pOnState;
108 pHexEdit := THexEdit.Create(Self);
109 PopupMenu := TPopupMenu.Create(Self);
110 with PopupMenu do
111 begin
112 Items.Add(TMenuItem.Create(PopupMenu));
113 with Items[Items.Count - 1] do
114 begin
115 Caption := MSC_VIEW_CHANGE;
116 OnClick := OnDblClick;
117 Default := True;
118 end;
119 end;
120 pOnState(Self);
121 end;
123 procedure TMiscView.ChangeCW;
125 lstate: THardwareState;
126 begin
127 lstate := Hardware.State;
128 pHexEdit.Caption := MSC_VIEW_CHG_CW;
129 with lstate.FPUState do
130 if pHexEdit.ShowBox(@ControlWord, SizeOf(ControlWord)) then
131 Hardware.State := lstate;
132 end;
134 procedure TMiscView.ChangeSW;
136 lstate: THardwareState;
137 begin
138 lstate := Hardware.State;
139 pHexEdit.Caption := MSC_VIEW_CHG_SW;
140 with lstate.FPUState do
141 if pHexEdit.ShowBox(@StatusWord, SizeOf(StatusWord)) then
142 Hardware.State := lstate;
143 end;
145 procedure TMiscView.CyclePrecision;
147 lstate: THardwareState;
148 begin
149 lstate := Hardware.State;
150 SetPrecision(lstate, (GetPrecision(Hardware.State) + 1) mod 4);
151 Hardware.State := lstate;
152 end;
154 procedure TMiscView.CycleRound;
156 lstate: THardwareState;
157 begin
158 lstate := Hardware.State;
159 SetRound(lstate, (GetRound(Hardware.State) + 1) mod 4);
160 Hardware.State := lstate;
161 end;
163 procedure TMiscView.ToggleCondition(Line: Integer);
165 lstate: THardwareState;
166 begin
167 if (Line < 2) or (Line > 5) then Exit;
168 Line := Line - 2;
169 lstate := Hardware.State;
170 SetCondition(lstate, Line, not GetCondition(lstate, Line));
171 Hardware.State := lstate;
172 end;
174 end.