Finalize version.
[marekmrva_bc.git] / AsmGridClass.pas
blob42800a0b080e1f63751acdda757d54a0b375d1bf
1 unit AsmGridClass;
3 interface
5 uses
6 ConstantsClass, CustomStringGridClass, FunctionsClass, HardwareClass,
7 ResourcesClass, SteppingClass, TypesClass,
8 Classes, Controls, Dialogs, Forms, Graphics, Grids, Menus, StdCtrls, Types;
10 type
12 TAsmGrid = class;
14 { TAsmInputBox }
16 TAsmInputBox = class(TForm)
17 private
18 pAssemble, pCancel: TButton;
19 pBox: TEdit;
20 pDontChange, pInsert: Boolean;
21 pGrid: TAsmGrid;
22 pLabel: TLabel;
23 pList: TListBox;
24 pPosition: Integer;
25 pText: String;
26 procedure pBoxOnChange(Sender: TObject); virtual;
27 procedure pBoxOnKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); virtual;
28 procedure pListOnDblClick(Sender: TObject); virtual;
29 procedure pOnButtonClick(Sender: TObject); virtual;
30 procedure pOnChange(Sender: TObject; ARow: Integer; Text: String; Insert: Boolean); virtual;
31 procedure pOnRemove(Sender: TObject; ARow: Integer); virtual;
32 procedure pOnShow(Sender: TObject); virtual;
33 public
34 constructor CreateBox(AOwner: TComponent; AsmGrid: TAsmGrid); virtual;
35 end;
37 { TAsmGrid }
39 TAsmGrid = class(TCustomStringGrid)
40 private
41 pAskReset: Boolean;
42 pColorTheme: TGridTheme;
43 pStep: TStepping;
44 pInputBox: TAsmInputBox;
45 pOldOnOperand, pOldOnStep: TChangeEvent;
46 pOnChange: TInsertEvent;
47 pOnRemove: TRemoveEvent;
48 function pGetSelectedLine: Integer; virtual;
49 function pGetWidth: Integer; virtual;
50 procedure pCustomDblClick(Sender: TObject); virtual;
51 procedure pCustomDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); virtual;
52 procedure pCustomKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); virtual;
53 procedure pCustomMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); virtual;
54 procedure pCustomPopupGetOrigin(Sender: TObject); virtual;
55 procedure pCustomPopupInsert(Sender: TObject); virtual;
56 procedure pCustomPopupRemove(Sender: TObject); virtual;
57 procedure pCustomPopupReset(Sender: TObject); virtual;
58 procedure pCustomPopupSetOrigin(Sender: TObject); virtual;
59 procedure pCustomPopupStep(Sender: TObject); virtual;
60 procedure pDrawSingleCell(Canvas: TCanvas; ACol, ARow: Integer; Rect: TRect; Colors: TColors; Highlight: Boolean); virtual;
61 procedure pOnOperand(Sender: TObject); virtual;
62 procedure pOnStep(Sender: TObject); virtual;
63 procedure pSetColorTheme(ColorTheme: TGridTheme); virtual;
64 procedure pSetSelectedLine(Line: Integer); virtual;
65 procedure pSetStep(Step: TStepping); virtual;
66 procedure pSetWidth(Width: Integer); virtual;
67 public
68 constructor CreateGrid(AOwner: TComponent; Step: TStepping); virtual;
69 function ChangeInstruction(ARow: Integer; Name: String): Boolean; overload; virtual;
70 function ChangeInstruction(Name: String): Boolean; overload; virtual;
71 function InsertInstruction(ARow: Integer; Name: String): Boolean; overload; virtual;
72 function InsertInstruction(Name: String): Boolean; overload; virtual;
73 function RemoveInstruction(ARow: Integer): Boolean; overload; virtual;
74 function RemoveInstruction: Boolean; overload; virtual;
75 function ReloadInstructions: Boolean; virtual;
76 procedure ProgramReset; virtual;
77 procedure ProgramStep; virtual;
78 property ColorTheme: TGridTheme read pColorTheme write pSetColorTheme;
79 property InputBox: TAsmInputBox read pInputBox write pInputBox;
80 property OnChangeLine: TInsertEvent read pOnChange write pOnChange;
81 property OnRemoveLine: TRemoveEvent read pOnRemove write pOnRemove;
82 property SelectedLine: Integer read pGetSelectedLine write pSetSelectedLine;
83 property Stepping: TStepping read pStep write pSetStep;
84 property Width read pGetWidth write pSetWidth;
85 end;
87 implementation
89 // ************************************************************************** //
90 // * TAsmInputBox implementation * //
91 // ************************************************************************** //
93 procedure TAsmInputBox.pBoxOnChange(Sender: TObject);
94 var
95 lstrings: TypesClass.TStrings;
96 i: Integer;
97 ltext: String;
98 begin
99 if pDontChange then Exit;
100 if not(pText = pBox.Text) or not(pPosition = pBox.SelStart) then
101 begin
102 ltext := StringBefore(pBox.Text, pBox.SelStart);
103 SetLength(lstrings, 0);
104 lstrings := pGrid.Stepping.Hardware.InstructionsByPrefix(ltext);
105 pList.Clear;
106 for i := 0 to (Length(lstrings) - 1) do
107 pList.Items.Add(lstrings[i]);
108 pList.ItemIndex := 0;
109 end;
110 pText := pBox.Text;
111 pPosition := pBox.SelStart;
112 end;
114 procedure TAsmInputBox.pOnButtonClick(Sender: TObject);
116 lrow: Integer;
117 begin
118 with pList do
119 if (Count > 0) and (ItemIndex > 0) then
120 if not(pBox.Text = Items[ItemIndex]) then
121 begin
122 pListOnDblClick(Sender);
123 Exit;
124 end;
125 lrow := pGrid.SelectedLine;
126 with pGrid.Stepping.Hardware do
127 if not ValidateInstruction(pBox.Text) then
128 begin
129 if (pList.Count > 0) then
130 begin
131 pDontChange := True;
132 pBox.Text := pList.Items[pList.ItemIndex];
133 pBox.SelStart := Length(pBox.Text);
134 pDontChange := False;
135 pBoxOnChange(Self);
137 else pLabel.Caption := LastError;
138 Exit;
139 end;
140 with pGrid do
141 begin
142 if pInsert then
143 InsertInstruction(lrow, pBox.Text)
144 else
145 ChangeInstruction(lrow, pBox.Text);
146 SelectedLine := SelectedLine + 1;
147 lrow := SelectedLine;
148 if pInsert then
149 Self.Caption := ASM_INPUT_CAPTION_INSERT + ' ' + Cells[0, lrow]
150 else
151 Self.Caption := ASM_INPUT_CAPTION_CHANGE + ' ' + Cells[0, lrow];
152 if not(VisibleRowCount + TopRow > lrow) then TopRow := TopRow + 1;
153 pOnShow(Self);
154 end;
155 end;
157 procedure TAsmInputBox.pOnChange(Sender: TObject; ARow: Integer;
158 Text: String; Insert: Boolean);
159 begin
160 if Insert then
161 begin
162 Caption := ASM_INPUT_CAPTION_INSERT + ' ' + pGrid.Cells[0, ARow];
163 pInsert := True;
165 else
166 begin
167 Caption := ASM_INPUT_CAPTION_CHANGE + ' ' + pGrid.Cells[0, ARow];
168 pInsert := False;
169 end;
170 pDontChange := True;
171 pBox.Text := Text;
172 pBox.SelStart := Length(Text);
173 pDontChange := False;
174 pBoxOnChange(Self);
175 Self.ShowModal;
176 end;
178 procedure TAsmInputBox.pBoxOnKeyDown(Sender: TObject; var Key: Word;
179 Shift: TShiftState);
181 lkey: Word;
182 begin
183 lkey := Key;
184 Key := 0;
185 case lkey of
186 KEY_HOME: pBox.SelStart := 0;
187 KEY_END: pBox.SelStart := Length(pBox.Text);
188 KEY_LEFT: pBox.SelStart := pBox.SelStart - 1;
189 KEY_UP: pList.ItemIndex := MaxOf(pList.ItemIndex - 1, 0);
190 KEY_RIGHT: pBox.SelStart := pBox.SelStart + 1;
191 KEY_DOWN: pList.ItemIndex := pList.ItemIndex + 1;
192 else Key := lkey;
193 end;
194 pBoxOnChange(Self);
195 end;
197 procedure TAsmInputBox.pListOnDblClick(Sender: TObject);
198 begin
199 if (pList.Count > 0) then
200 begin
201 pDontChange := True;
202 pBox.Text := pList.Items[pList.ItemIndex];
203 pBox.SelStart := Length(pBox.Text);
204 pDontChange := False;
205 pBoxOnChange(Self);
206 end;
207 end;
209 procedure TAsmInputBox.pOnRemove(Sender: TObject; ARow: Integer);
210 begin
211 pGrid.RemoveInstruction(ARow);
212 end;
214 procedure TAsmInputBox.pOnShow(Sender: TObject);
215 begin
216 pLabel.Caption := '';
217 pBox.SelectAll;
218 pBox.SetFocus;
219 end;
221 constructor TAsmInputBox.CreateBox(AOwner: TComponent; AsmGrid: TAsmGrid);
222 begin
223 inherited CreateNew(AOwner, 0);
224 Position := poDesktopCenter;
225 ClientWidth := 321;
226 ClientHeight := 181;
227 OnShow := pOnShow;
228 BorderStyle := bsDialog;
229 pGrid := AsmGrid;
230 with pGrid do
231 begin
232 OnChangeLine := Self.pOnChange;
233 OnRemoveLine := Self.pOnRemove;
234 end;
235 pBox := TEdit.Create(Self);
236 with pBox do
237 begin
238 Parent := Self;
239 Text := '';
240 Left := 8;
241 Top := 8;
242 Width := 309;
243 Height := 21;
244 OnChange := pBoxOnChange;
245 OnKeyDown := pBoxOnKeyDown;
246 end;
247 pList := TListBox.Create(Self);
248 with pList do
249 begin
250 Parent := Self;
251 Left := 8;
252 Top := 31;
253 Width := 309;
254 Height := 100;
255 OnDblClick := pListOnDblClick;
256 end;
257 pAssemble := TButton.Create(Self);
258 with pAssemble do
259 begin
260 Parent := Self;
261 Caption := ASM_INPUT_BUTTON_ASSEMBLE;
262 Left := 193;
263 Top := 157;
264 Width := 60;
265 Height := 20;
266 OnClick := pOnButtonClick;
267 Default := True;
268 end;
269 pCancel := TButton.Create(Self);
270 with pCancel do
271 begin
272 Parent := Self;
273 Caption := ASM_INPUT_BUTTON_CANCEL;
274 Left := 257;
275 Top := 157;
276 Width := 60;
277 Height := 20;
278 ModalResult := mrCancel;
279 Cancel := True;
280 end;
281 pLabel := TLabel.Create(Self);
282 with pLabel do
283 begin
284 Parent := Self;
285 Caption := '';
286 Left := 8;
287 Top := 135;
288 Width := 309;
289 Height := 21;
290 Font.Color := clRed;
291 end;
292 end;
294 // ************************************************************************** //
295 // * TAsmGrid implementation * //
296 // ************************************************************************** //
298 function TAsmGrid.pGetSelectedLine: Integer;
299 begin
300 Result := Selection.Top;
301 end;
303 function TAsmGrid.pGetWidth: Integer;
304 begin
305 Result := inherited Width;
306 end;
308 procedure TAsmGrid.pCustomDblClick(Sender: TObject);
310 lkey: Word;
311 begin
312 lkey := KEY_RETURN;
313 pCustomKeyDown(Self, lkey, []);
314 end;
316 procedure TAsmGrid.pCustomDrawCell(Sender: TObject; ACol, ARow: Integer;
317 Rect: TRect; State: TGridDrawState);
319 lcolors: TColors;
320 begin
321 if (Stepping.StepBlock = ARow) and (ACol = 0) then
322 begin
323 pDrawSingleCell(Canvas, ACol, ARow, Rect, ColorTheme.Step, False);
324 Exit;
325 end;
326 if (gdSelected in State) and Selected then
327 if (ACol = 0) then lcolors := ColorTheme.Address.Selected
328 else lcolors := ColorTheme.Assembly.Selected
329 else
330 if (ACol = 0) then lcolors := ColorTheme.Address.None
331 else lcolors := ColorTheme.Assembly.None;
332 if not(Objects[Acol, Arow] = nil) and
333 (TStepBlock(Objects[ACol, ARow]).IsBranch) then
334 pDrawSingleCell(Canvas, ACol, ARow, Rect, lcolors, True)
335 else
336 pDrawSingleCell(Canvas, ACol, ARow, Rect, lcolors, False);
337 end;
339 procedure TAsmGrid.pCustomKeyDown(Sender: TObject; var Key: Word;
340 Shift: TShiftState);
342 lselect, ltop: Integer;
343 ltext: String;
344 begin
345 lselect := SelectedLine;
346 ltext := Cells[1, lselect];
347 if (Key = KEY_RETURN) and (lselect = RowCount - 1) then Key := KEY_INSERT;
348 if (Key = KEY_ASTERISK_SFT) and (ssShift in Shift) then Key := KEY_ASTERISK;
349 case Key of
350 KEY_BACKSPACE:
351 begin
352 if not(@pOnRemove = nil) then pOnRemove(Self, lselect - 1);
353 SelectedLine := SelectedLine - 1;
354 end;
355 KEY_RETURN, KEY_SPACE:
356 if not(@pOnChange = nil) then pOnChange(Self, lselect, ltext, False);
357 KEY_INSERT:
358 if not(@pOnChange = nil) then pOnChange(Self, lselect, ltext, True);
359 KEY_DELETE:
360 if not(@pOnRemove = nil) then pOnRemove(Self, lselect);
361 KEY_ASTERISK:
362 if (ssCtrl in Shift) then
363 Stepping.StepBlock := lselect
364 else
365 begin
366 SelectedLine := Stepping.StepBlock;
367 ltop := Stepping.StepBlock - (VisibleRowCount div 2);
368 if (ltop < 0) then ltop := 0;
369 TopRow := ltop;
370 end;
371 KEY_F2: if (ssCtrl in Shift) then ProgramReset;
372 KEY_F8: ProgramStep;
373 end;
374 end;
376 procedure TAsmGrid.pCustomMouseDown(Sender: TObject; Button: TMouseButton;
377 Shift: TShiftState; X, Y: Integer);
379 ldummy, lrow: Integer;
380 begin
381 MouseToCell(X, Y, ldummy, lrow);
382 if not(lrow < 0) then SelectedLine := lrow;
383 end;
385 procedure TAsmGrid.pCustomPopupGetOrigin(Sender: TObject);
387 lkey: Word;
388 begin
389 lkey := KEY_ASTERISK;
390 pCustomKeyDown(Sender, lkey, []);
391 end;
393 procedure TAsmGrid.pCustomPopupInsert(Sender: TObject);
395 lkey: Word;
396 begin
397 lkey := KEY_INSERT;
398 pCustomKeyDown(Sender, lkey, []);
399 end;
401 procedure TAsmGrid.pCustomPopupRemove(Sender: TObject);
403 lkey: Word;
404 begin
405 lkey := KEY_DELETE;
406 pCustomKeyDown(Sender, lkey, []);
407 end;
409 procedure TAsmGrid.pCustomPopupReset(Sender: TObject);
411 lkey: Word;
412 begin
413 lkey := KEY_F2;
414 pCustomKeyDown(Sender, lkey, [ssCtrl]);
415 end;
417 procedure TAsmGrid.pCustomPopupSetOrigin(Sender: TObject);
419 lkey: Word;
420 begin
421 lkey := KEY_ASTERISK;
422 pCustomKeyDown(Sender, lkey, [ssCtrl]);
423 end;
425 procedure TAsmGrid.pCustomPopupStep(Sender: TObject);
427 lkey: Word;
428 begin
429 lkey := KEY_F8;
430 pCustomKeyDown(Sender, lkey, []);
431 end;
433 procedure TAsmGrid.pDrawSingleCell(Canvas: TCanvas; ACol, ARow: Integer;
434 Rect: TRect; Colors: TColors; Highlight: Boolean);
436 lsize: TSize;
437 lx, ly: Integer;
438 begin
439 with Rect do
440 begin
441 Canvas.Brush.Color := Colors.BG;
442 Canvas.FillRect(Rect);
443 lsize := Canvas.TextExtent(Cells[ACol, ARow]);
444 if (ACol = 0) then
445 begin
446 lx := (Right - Left - lsize.cx) div 2 + Left;
447 Canvas.Pen.Color := Colors.FG;
448 Canvas.MoveTo(Right - 1, Top);
449 Canvas.LineTo(Right - 1, Bottom);
451 else
452 lx := Left + Canvas.TextWidth(' ');
453 ly := (Bottom - Top - lsize.cy) div 2 + Top;
454 if Highlight then
455 begin
456 Canvas.Brush.Color := ColorTheme.Highlight.BG;
457 Canvas.Font.Color := ColorTheme.Highlight.FG;
459 else
460 Canvas.Font.Color := Colors.FG;
461 {$IFDEF UNIX}
462 // For compatibility with Lazarus :-(
463 Canvas.FillRect(lx, ly + 1, lx + lsize.cx - 1, ly + lsize.cy - 1);
464 // ...since Lazarus doesn't use Brush for text background...
465 {$ENDIF}
466 Canvas.TextOut(lx, ly, Cells[ACol, ARow]);
467 end;
468 end;
470 procedure TAsmGrid.pOnOperand(Sender: TObject);
471 begin
472 if not(Stepping.StepBlock < 0) then pAskReset := True;
473 if not(@pOldOnOperand = nil) then pOldOnOperand(Sender);
474 end;
476 procedure TAsmGrid.pOnStep(Sender: TObject);
478 ltop: Integer;
479 begin
480 if not(Stepping.StepBlock < 0) then
481 begin
482 SelectedLine := Stepping.StepBlock;
483 ltop := Stepping.StepBlock;
484 if (ltop < TopRow) or not(ltop < (TopRow + VisibleRowCount)) then
485 begin
486 ltop := ltop - (VisibleRowCount div 2);
487 if (ltop < 0) then ltop := 0;
488 TopRow := ltop;
489 end;
490 end;
491 Self.Repaint;
492 end;
494 procedure TAsmGrid.pSetColorTheme(ColorTheme: TGridTheme);
495 begin
496 pColorTheme := ColorTheme;
497 Color := ColorTheme.Assembly.None.BG;
498 end;
500 procedure TAsmGrid.pSetSelectedLine(Line: Integer);
502 lselect: TGridRect;
503 begin
504 if (Line < 0) then Line := 0;
505 if (Line > RowCount) then Line := RowCount - 1;
506 {$IFDEF UNIX}
507 SetColRow(0, Line);
508 // Lazarus is really nice, by having incompatible calls :-(
509 {$ELSE}
510 lselect.Top := Line;
511 lselect.Bottom := Line;
512 lselect.Left := 0;
513 lselect.Right := 1;
514 Selection := lselect;
515 {$ENDIF}
516 end;
518 procedure TAsmGrid.pSetStep(Step: TStepping);
519 begin
520 if not(pStep = nil) then
521 begin
522 pStep.OnStep := pOldOnStep;
523 if not(pStep.Hardware = nil) then
524 pStep.Hardware.OnOperand := pOldOnOperand;
525 end;
526 pStep := Step;
527 if not(Step = nil) then
528 begin
529 pOldOnStep := Step.OnStep;
530 Step.OnStep := pOnStep;
531 if not(Step.Hardware = nil) then
532 begin
533 pOldOnOperand := Step.Hardware.OnOperand;
534 Step.Hardware.OnOperand := pOnOperand;
535 end;
536 end;
537 end;
539 procedure TAsmGrid.pSetWidth(Width: Integer);
540 begin
541 inherited Width := Width;
542 ColWidths[1] := ClientWidth - ColWidths[0];
543 end;
545 constructor TAsmGrid.CreateGrid(AOwner: TComponent; Step: TStepping);
546 begin
547 inherited Create(AOwner);
548 ColorTheme := THEME_GRID_DEFAULT;
549 RowCount := 1;
550 ColCount := 2;
551 ScrollBars := ssVertical;
552 {$IFDEF UNIX}
553 Options := [goRangeSelect, goRowSelect, goThumbTracking];
554 // Behavior of goRangeSelect differ in Lazarus :-(
555 {$ELSE}
556 Options := [goRowSelect, goThumbTracking];
557 {$ENDIF}
558 DefaultDrawing := False;
559 OnDrawCell := pCustomDrawCell;
560 OnDblClick := pCustomDblClick;
561 OnKeyDown := pCustomKeyDown;
562 OnMouseDown := pCustomMouseDown;
563 InputBox := TAsmInputBox.CreateBox(Self, Self);
564 PopupMenu := TPopupMenu.Create(Self);
565 with PopupMenu do
566 begin
567 Items.Add(TMenuItem.Create(PopupMenu));
568 with Items[Items.Count - 1] do
569 begin
570 Caption := POP_ASM_CHANGE;
571 OnClick := pCustomDblClick;
572 Default := True;
573 end;
574 Items.Add(TMenuItem.Create(PopupMenu));
575 with Items[Items.Count - 1] do
576 begin
577 Caption := POP_ASM_INSERT;
578 OnClick := pCustomPopupInsert;
579 end;
580 Items.Add(TMenuItem.Create(PopupMenu));
581 with Items[Items.Count - 1] do
582 begin
583 Caption := POP_ASM_REMOVE;
584 OnClick := pCustomPopupRemove;
585 end;
586 Items.Add(TMenuItem.Create(PopupMenu));
587 Items[Items.Count - 1].Caption := '-';
588 Items.Add(TMenuItem.Create(PopupMenu));
589 with Items[Items.Count - 1] do
590 begin
591 Caption := POP_ASM_STEP;
592 OnClick := pCustomPopupStep;
593 end;
594 Items.Add(TMenuItem.Create(PopupMenu));
595 with Items[Items.Count - 1] do
596 begin
597 Caption := POP_ASM_RESET;
598 OnClick := pCustomPopupReset;
599 end;
600 Items.Add(TMenuItem.Create(PopupMenu));
601 Items[Items.Count - 1].Caption := '-';
602 Items.Add(TMenuItem.Create(PopupMenu));
603 with Items[Items.Count - 1] do
604 begin
605 Caption := POP_ASM_GET_ORIGIN;
606 OnClick := pCustomPopupGetOrigin;
607 end;
608 Items.Add(TMenuItem.Create(PopupMenu));
609 with Items[Items.Count - 1] do
610 begin
611 Caption := POP_ASM_SET_ORIGIN;
612 OnClick := pCustomPopupSetOrigin;
613 end;
614 end;
615 Stepping := Step;
616 ReloadInstructions;
617 end;
619 function TAsmGrid.ChangeInstruction(ARow: Integer; Name: String): Boolean;
621 linst: TInstruction;
622 begin
623 if not(Stepping.StepBlock < 0) then pAskReset := True;
624 if (ARow = RowCount - 1) then
625 begin
626 Result := Self.InsertInstruction(ARow, Name);
627 Exit;
628 end;
629 Stepping.Hardware.Address := ARow;
630 linst := Stepping.Hardware.InstructionByName(Name);
631 Result := Stepping.ChangeStepBlock(ARow, linst);
632 if Result then
633 begin
634 Objects[1, ARow] := Stepping[ARow];
635 Cells[1, ARow] := linst.Name;
636 end;
637 end;
639 function TAsmGrid.ChangeInstruction(Name: String): Boolean;
640 begin
641 Result := ChangeInstruction(SelectedLine, Name);
642 end;
644 function TAsmGrid.InsertInstruction(ARow: Integer; Name: String): Boolean;
646 i: Integer;
647 linst: TInstruction;
648 begin
649 if not(Stepping.StepBlock < 0) then pAskReset := True;
650 Stepping.Hardware.Address := ARow;
651 linst := Stepping.Hardware.InstructionByName(Name);
652 Result := Stepping.AddStepBlock(ARow, linst);
653 if Result then
654 begin
655 RowCount := RowCount + 1;
656 for i := (RowCount - 2) downto ARow do
657 begin
658 Cells[1, i + 1] := Cells[1, i];
659 Cells[0, i + 1] := ZeroPaddedInteger(i + 1, CONST_PADDING);
660 Objects[1, i + 1] := Objects[1, i];
661 end;
662 Objects[1, ARow] := Stepping[ARow];
663 Cells[1, ARow] := linst.Name;
664 Cells[0, ARow] := ZeroPaddedInteger(ARow, CONST_PADDING);
665 end;
666 end;
668 function TAsmGrid.InsertInstruction(Name: String): Boolean;
669 begin
670 Result := InsertInstruction(SelectedLine, Name);
671 end;
673 function TAsmGrid.RemoveInstruction(ARow: Integer): Boolean;
675 i: Integer;
676 begin
677 if not(Stepping.StepBlock < 0) then pAskReset := True;
678 Result := Stepping.RemoveStepBlock(ARow);
679 if Result then
680 begin
681 for i := ARow to (RowCount - 2) do
682 begin
683 Cells[1, i] := Cells[1, i + 1];
684 Objects[1, i] := Objects[1, i + 1];
685 end;
686 RowCount := RowCount - 1;
687 end;
688 end;
690 function TAsmGrid.RemoveInstruction: Boolean;
691 begin
692 Result := RemoveInstruction(SelectedLine);
693 end;
695 function TAsmGrid.ReloadInstructions: Boolean;
697 i: Integer;
698 begin
699 RowCount := Stepping.Length + 1;
700 for i := 0 to (RowCount - 1) do
701 begin
702 Cells[0, i] := ZeroPaddedInteger(i, CONST_PADDING);
703 Objects[1, i] := Stepping[i];
704 if (Objects[1, i] = nil) then Cells[1, i] := ''
705 else Cells[1, i] := TStepBlock(Objects[1, i]).CallFunction.Name;
706 end;
707 Result := True;
708 end;
710 procedure TAsmGrid.ProgramReset;
711 begin
712 Stepping.StepBlock := -1;
713 pAskReset := False;
714 end;
716 procedure TAsmGrid.ProgramStep;
718 lanswer: Integer;
719 begin
720 if pAskReset then
721 begin
722 lanswer := MessageDlg(TEXT_RESET, mtInformation, mbYesNoCancel, 0);
723 case lanswer of
724 mrYes: ProgramReset;
725 mrCancel: Exit;
726 end;
727 pAskReset := False;
728 end;
729 if (Stepping.StepBlock < 0) then
730 begin
731 LogSystemTime;
732 LogWrite(POP_ASM_CHECKING);
733 if Stepping.Valid then
734 begin
735 LogWrite(POP_ASM_DONE_RUNNING);
736 Stepping.SingleStep;
737 if (Stepping.StepBlock < 0) then LogWrite(POP_ASM_EXEC_STOPPED);
739 else LogWrite(POP_ASM_ERRORS_FOUND);
740 Exit;
741 end;
742 Stepping.SingleStep;
743 if (Stepping.StepBlock < 0) then LogWrite(POP_ASM_EXEC_STOPPED);
744 end;
746 end.