-
Notifications
You must be signed in to change notification settings - Fork 0
/
uEditorForm.pas
991 lines (927 loc) · 31.8 KB
/
uEditorForm.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
unit uEditorForm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, Menus, ExtCtrls, StdCtrls, ComCtrls, EnhCtrls, Buttons,
uAssembler, uProcessor, uTimer, uResourceStrings, uMisc, Registry,
SynEdit, SynEditPrint, SynEditHighlighter, SynHighlighterAsm, ImgList,
SynEditOptionsDialog, uSynHighlighteri8008ASM;
type
{ *********** Projectfile Structure *********** }
{ 1. Processor Data }
{ 1.1 - Fileheader }
{ 1.2 - 'Halt' }
{ 1.3 - Stack Data }
{ 1.4 - RAM Data }
{ 1.5 - Register Data }
{ 1.6 - Flag Data }
{ 1.7 - IN Port Data }
{ 1.8 - OUT Port Data }
{ 2. Editor - 'CodeModified' }
{ [3. i8008 Program, if CodeModefied is false] }
{ 4. Sourcecode }
{ *********** Projectfile Structure *********** }
TSingleStepEnabledEvent = procedure(Sender: TObject; Enabled: Boolean) of object;
TRunningEnabledEvent = procedure(Sender: TObject; Enabled: Boolean) of object;
TPCRefreshRequestEvent = procedure(Listener: IProgramCounter) of object;
TLoadEvent = procedure(Stream: TStream; var Check: Boolean) of object;
TSaveEvent = procedure(Stream: TStream; var Check: Boolean) of object;
TSupportPlugin = class;
TEditorForm = class(TForm, IProgramCounter, ILanguage, IRegistry)
pBottom: TPanel;
lbError: TListBox;
pLeft: TPanel;
sbHide: TSpeedButton;
pStatus: TPanel;
OpenDialog: TOpenDialog;
SaveDialog: TSaveDialog;
SaveProjectDialog: TSaveDialog;
OpenProjectDialog: TOpenDialog;
iProject: TImage;
iSourcecode: TImage;
LblFilename: TFilenameLabel;
synEditor: TSynEdit;
synEditorPrint: TSynEditPrint;
imglGutter: TImageList;
PrinterSetupDialog: TPrinterSetupDialog;
pMainBottom: TPanel;
procedure sbHideClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure lbErrorClick(Sender: TObject);
procedure OnKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure synEditorChange(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure OnKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure synEditorGutterClick(Sender: TObject; Button: TMouseButton;
X, Y, Line: Integer; Mark: TSynEditMark);
procedure synEditorSpecialLineColors(Sender: TObject; Line: Integer;
var Special: Boolean; var FG, BG: TColor);
private
_HideErrors: Boolean;
_SizeHeight: Integer;
_StepLine: Integer;
_ErrorLine: Integer;
_isSingleStep: Boolean;
_isRunning: Boolean;
_EnableKeys: Boolean;
_CodeModified: Boolean;
_BreakpointList: TBreakpointList;
_i8008Assembler: Ti8008Assembler;
_Program: TProgram;
_AssembleRequest: TNotifyEvent;
_AfterAssemble: TNotifyEvent;
_OnSingleStepEnabled: TSingleStepEnabledEvent;
_OnRunningEnabled: TRunningEnabledEvent;
_OnTimerEnabledRequest: TTimerEnabledRequestEvent;
_OnTick: TTickEvent;
_OnPCRefreshRequest: TPCRefreshRequestEvent;
_OnLoadProject: TLoadEvent;
_OnLoadProgram: TLoadEvent;
_OnSaveProject: TSaveEvent;
_OnSaveProgram: TSaveEvent;
_SupportPlugin: TSupportPlugin;
_i8008ASMSyn: Ti8008ASMSyn;
procedure RefreshObject(Sender: TObject);
procedure Reset(Sender: TObject);
procedure PCUpdate(Sender: TObject; Value: Word);
procedure LoadData(RegistryList: TRegistryList);
procedure SaveData(RegistryList: TRegistryList);
procedure ErrorInsert(Sender: TObject; Index: Integer);
procedure ErrorDelete(Sender: TObject; Index: Integer);
procedure setErrorList(Hide: Boolean);
function getFilename: TFilename;
procedure Stop(ClearArrow: Boolean); overload;
procedure goToLine(Line: Integer);
procedure OnAfterPaint(ACanvas: TCanvas; const AClip: TRect; FirstLine, LastLine: Integer);
public
procedure Start;
procedure Stop; overload;
procedure SingleStep;
function Assemble: Boolean;
function New: Boolean;
procedure Open(Filename: TFilename);
function OpenFile: Boolean; overload;
function OpenFile(Filename: TFilename): Boolean; overload;
function OpenProject: Boolean; overload;
function OpenProject(Filename: TFilename): Boolean; overload;
function SaveRequest: Integer;
procedure Save;
function SaveFile: Boolean;
function SaveFileAs: Boolean;
function SaveProject: Boolean;
function SaveProjectAs: Boolean;
procedure Print;
procedure ShowProgress(Value: Boolean);
procedure LoadLanguage;
procedure Show(ATop, ALeft, AWidth, AHeight: Integer); overload;
property AProgram: TProgram read _Program write _Program;
property Filename: TFilename read getFilename;
property EnableKeys: Boolean read _EnableKeys write _EnableKeys;
property OnAssembleRequest: TNotifyEvent read _AssembleRequest write _AssembleRequest;
property OnSingleStepEnabled: TSingleStepEnabledEvent read _OnSingleStepEnabled write _OnSingleStepEnabled;
property OnRunningEnabled: TRunningEnabledEvent read _OnRunningEnabled write _OnRunningEnabled;
property OnAfterAssemble: TNotifyEvent read _AfterAssemble write _AfterAssemble;
property OnTimerEnabledRequest: TTimerEnabledRequestEvent read _OnTimerEnabledRequest write _OnTimerEnabledRequest;
property OnTick: TTickEvent read _OnTick write _OnTick;
property OnPCRefreshRequest: TPCRefreshRequestEvent read _OnPCRefreshRequest write _OnPCRefreshRequest;
property OnLoadProject: TLoadEvent read _OnLoadProject write _OnLoadProject;
property OnLoadProgram: TLoadEvent read _OnLoadProgram write _OnLoadProgram;
property OnSaveProject: TSaveEvent read _OnSaveProject write _OnSaveProject;
property OnSaveProgram: TSaveEvent read _OnSaveProgram write _OnSaveProgram;
end;
TSynPaintEvent = procedure(ACanvas: TCanvas; const AClip: TRect; FirstLine, LastLine: Integer) of object;
TSupportPlugin = class(TSynEditPlugin)
private
_OnAfterPaint: TSynPaintEvent;
protected
procedure AfterPaint(ACanvas: TCanvas; const AClip: TRect; FirstLine, LastLine: Integer); override;
procedure LinesInserted(FirstLine, Count: Integer); override;
procedure LinesDeleted(FirstLine, Count: Integer); override;
public
constructor Create(AOwner: TSynEdit);
property OnAfterPaint: TSynPaintEvent read _OnAfterPaint write _OnAfterPaint;
end;
var
EditorForm: TEditorForm;
implementation
{$R *.dfm}
constructor TSupportPlugin.Create(AOwner: TSynEdit);
begin
inherited Create(AOwner);
end;
procedure TSupportPlugin.AfterPaint(ACanvas: TCanvas; const AClip: TRect; FirstLine, LastLine: integer);
begin
if Assigned(OnAfterPaint) then OnAfterPaint(ACanvas, AClip, FirstLine, LastLine);
end;
procedure TSupportPlugin.LinesInserted(FirstLine, Count: integer);
begin
end;
procedure TSupportPlugin.LinesDeleted(FirstLine, Count: integer);
begin
end;
procedure TEditorForm.FormCreate(Sender: TObject);
begin
_i8008Assembler:= Ti8008Assembler.Create;
_i8008Assembler.ErrorList.OnItemInsert:= ErrorInsert;
_i8008Assembler.ErrorList.OnItemDelete:= ErrorDelete;
_HideErrors:= false;
_SizeHeight:= lbError.Height;
iSourcecode.Left:= 3;
iSourcecode.Top:= 3;
iSourcecode.Visible:= false;
iProject.Left:= 3;
iProject.Top:= 3;
iProject.Visible:= false;
LblFilename.Caption:= '';
synEditor.Modified:= false;
_i8008ASMSyn:= Ti8008ASMSyn.Create(self);
synEditor.Highlighter:= _i8008ASMSyn;
_SupportPlugin:= TSupportPlugin.Create(synEditor);
_SupportPlugin.OnAfterPaint:= OnAfterPaint;
_BreakpointList:= TBreakpointList.Create;
_BreakpointList.ClearAllBreakpoints;
_CodeModified:= true; //false;
_isSingleStep:= false;
_isRunning:= false;
_ErrorLine:= -1;
_StepLine:= -1;
EnableKeys:= false;
LoadLanguage;
end;
procedure TEditorForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
// CanClose:= SaveRequest <> mrCancel;
end;
procedure TEditorForm.FormDestroy(Sender: TObject);
begin
_BreakpointList.Free;
synEditor.Highlighter:= nil;
_i8008ASMSyn.Free;
_SupportPlugin.Free;
_i8008Assembler.Free;
end;
procedure TEditorForm.Start;
begin
if _CodeModified or not Assigned(AProgram) then begin
if Assigned(OnAssembleRequest) then OnAssembleRequest(Self);
end else
if Assigned(AProgram) then begin
Caption:= 'Editor ( '+getString(rsRunning)+' )';
synEditor.ReadOnly:= true;
if Visible then goToLine(-1);
_isRunning:= true;
_isSingleStep:= false;
if Assigned(OnRunningEnabled) then OnRunningEnabled(Self,_isRunning);
if Assigned(OnTimerEnabledRequest) then OnTimerEnabledRequest(true);
end;
end;
procedure TEditorForm.sbHideClick(Sender: TObject);
begin
setErrorList(not _HideErrors);
end;
procedure TEditorForm.lbErrorClick(Sender: TObject);
begin
if (lbError.ItemIndex >= 0) and Visible then begin
_ErrorLine:= _i8008Assembler.ErrorList.Items[lbError.ItemIndex].Line;
goToLine(_ErrorLine);
synEditor.Invalidate;
end;
lbError.SetFocus;
end;
procedure TEditorForm.synEditorChange(Sender: TObject);
begin
if synEditor.Modified then begin
_CodeModified:= true;
LblFilename.Font.Style:= [fsBold];
end;
end;
procedure TEditorForm.OnKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if EnableKeys then
case Key of
VK_F2 : if (Shift = [ssCtrl]) then // stop
begin
Stop;
if Visible then goToLine(-1);
end;
VK_F9 : if Assigned(OnAssembleRequest) and (Shift = [ssCtrl]) then
OnAssembleRequest(Self) // assemble
else // start
Start;
ord('O'): if Shift = [ssCtrl] then // open file
OpenFile;
ord('P'): if Shift = [ssCtrl] then // open project
OpenProject;
ord('S'): if Shift = [ssCtrl] then // save file/project
Save;
end;
end;
procedure TEditorForm.OnKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (Key = VK_F7) then // single step
SingleStep;
end;
procedure TEditorForm.RefreshObject(Sender: TObject);
var
PItem: TProgramItem;
begin
if (Sender is Ti8008Stack) and (_isSingleStep or _isRunning) then
begin
if Assigned(AProgram) then
begin
PItem:= AProgram.FindItem((Sender as Ti8008Stack).ProgramCounter);
if Assigned(PItem) and _isSingleStep then begin
if Visible then goToLine(PItem.Link);
end else begin
if Visible then goToLine(-1);
end;
end;
end;
end;
procedure TEditorForm.Reset(Sender: TObject);
var
PItem: TProgramItem;
begin
if (Sender is Ti8008Stack) and (_isSingleStep or _isRunning) then
begin
if Assigned(AProgram) then
begin
PItem:= AProgram.FindItem((Sender as Ti8008Stack).ProgramCounter);
if Assigned(PItem) and _isSingleStep then begin
if Visible then goToLine(PItem.Link);
end else begin
if Visible then goToLine(-1);
end;
end;
end;
end;
procedure TEditorForm.PCUpdate(Sender: TObject; Value: Word);
var
PItem: TProgramItem;
begin
if Assigned(AProgram) then begin
PItem:= AProgram.FindItem(Value);
if _isRunning and Assigned(PItem) then begin
// stop the timer if a breakpoint is reached
if _BreakpointList.Breakpoint(PItem.Link+1) and _isRunning then begin
Stop(false);
// go to the specified sourcecodeline
_StepLine:= PItem.Link;
if Visible then goToLine(PItem.Link);
Caption:= 'Editor ( Breakpoint )';
end;
end else begin
// go to the specified sourcecodeline
if _isSingleStep and Assigned(PItem) then begin
_StepLine:= PItem.Link;
if Visible then begin
goToLine(PItem.Link);
synEditor.Invalidate;
end;
end else begin
if Visible then goToLine(-1);
end;
end;
end;
end;
procedure TEditorForm.LoadData(RegistryList: TRegistryList);
begin
if RegistryList.Registry.OpenKey(APPLICATION_MAIN_KEY, false) then begin
RegistryList.LoadFormSettings(Self, true);
if RegistryList.Registry.ValueExists('ErrorVisible') then
setErrorList(RegistryList.Registry.ReadInteger('ErrorVisible') = 1);
end;
end;
procedure TEditorForm.SaveData(RegistryList: TRegistryList);
begin
if RegistryList.Registry.OpenKey(APPLICATION_MAIN_KEY,true) then
begin
RegistryList.SaveFormSettings(Self,true);
if lbError.Visible then
RegistryList.Registry.WriteInteger('ErrorVisible',1)
else
RegistryList.Registry.WriteInteger('ErrorVisible',0);
end;
end;
procedure TEditorForm.ErrorInsert(Sender: TObject; Index: Integer);
var
Text: String;
Error: TErrorList;
begin
Error:= _i8008Assembler.ErrorList;
case Error.Items[Index].State of
isError : Text:= '['+getString(rsError)+'] : ('+IntToStr(Error.Items[Index].Line)+')';
isFatalError: Text:= '['+getString(rsFatalError)+'] : ('+IntToStr(Error.Items[Index].Line)+')';
isWarning : Text:= '['+getString(rsWarning)+'] : ('+IntToStr(Error.Items[Index].Line)+')';
isHint : Text:= '['+getString(rsHint)+'] : ('+IntToStr(Error.Items[Index].Line)+')';
isUndefined : Text:= '['+getString(rsError)+'] : ('+IntToStr(Error.Items[Index].Line)+')';
end;
Text:= Text + ' ' + Error.Items[Index].Text;
lbError.Items.Insert(Index,Text);
end;
procedure TEditorForm.ErrorDelete(Sender: TObject; Index: Integer);
begin
lbError.Items.Delete(Index);
end;
procedure TEditorForm.setErrorList(Hide: Boolean);
begin
_HideErrors:= Hide;
if Hide then pMainBottom.Height:= pMainBottom.Height - _SizeHeight
else pMainBottom.Height:= pMainBottom.Height + _SizeHeight;
if _HideErrors then sbHide.Down:= true
else sbHide.Down:= false;
end;
function TEditorForm.getFilename: TFilename;
begin
result:= LblFilename.Caption;
end;
procedure TEditorForm.Stop(ClearArrow: Boolean);
begin
if Assigned(AProgram) then
begin
Caption:= 'Editor';
synEditor.ReadOnly:= false;
if _isSingleStep then
begin
_isSingleStep:= false;
if Assigned(OnSingleStepEnabled) then
OnSingleStepEnabled(Self,_isSingleStep);
end;
if _isRunning then
begin
if Assigned(OnTimerEnabledRequest) then
OnTimerEnabledRequest(false);
_isRunning:= false;
if Assigned(OnRunningEnabled) then
OnRunningEnabled(Self,_isRunning);
end;
if ClearArrow and Visible then goToLine(-1);
end;
end;
procedure TEditorForm.Stop;
begin
Stop(true);
end;
procedure TEditorForm.SingleStep;
begin
if not _isRunning then
if _CodeModified or not Assigned(AProgram) then begin
if Assigned(OnAssembleRequest) then OnAssembleRequest(Self);
end else if Assigned(AProgram) then begin
if not _isSingleStep then begin
Caption:= 'Editor ( '+getString(rsSingleStep)+' )';
synEditor.ReadOnly:= true;
_isSingleStep:= true;
_isRunning:= false;
if Assigned(OnPCRefreshRequest) then
OnPCRefreshRequest(Self);
if Assigned(OnSingleStepEnabled) then
OnSingleStepEnabled(Self, _isSingleStep);
end else if Assigned(OnTick) then OnTick;
end;
end;
function TEditorForm.Assemble: Boolean;
var
Str: String;
Text: String;
i: Integer;
begin
Str:= '';
Text:= '';
for i:= 0 to synEditor.Lines.Count-1 do Text:= Text + synEditor.Lines.Strings[i]+#10#13;
result:= _i8008Assembler.Assemble(Text, _Program, LblFilename.Caption);
// Update Breakpoints
for i:= 0 to _BreakpointList.Count-1 do _BreakpointList.Items[i].State:= false;
for i:= 0 to _Program.Count-1 do _BreakpointList.BreakpointState[_Program.Items[i].Link+1]:= true;
if Visible then goToLine(-1);
// Show Errors
if not result and _HideErrors then setErrorList(false);
if result and Assigned(OnAfterAssemble) then OnAfterAssemble(Self);
_CodeModified:= not result;
end;
function TEditorForm.New: Boolean;
begin
if not (_isRunning or _isSingleStep) and
(SaveRequest <> mrCancel) then
begin
synEditor.Clear;
LblFilename.Caption:= '';
_BreakpointList.ClearAllBreakpoints;
synEditor.Modified:= false;
_CodeModified:= true;
AProgram:= nil;
result:= true;
iProject.Visible:= false;
iSourcecode.Visible:= false;
end
else
result:= false;
end;
function TEditorForm.OpenFile: Boolean;
begin
if not (_isRunning or _isSingleStep) then
begin
if OpenDialog.Execute then
try
if SaveRequest <> mrCancel then
begin
synEditor.Lines.LoadFromFile(OpenDialog.Filename);
LblFilename.Caption:= OpenDialog.Filename;
_BreakpointList.ClearAllBreakpoints;
if not Visible then
Show;
if Visible then goToLine(-1);
result:= true;
synEditor.Modified:= false;
_CodeModified:= true;
iProject.Visible:= false;
iSourcecode.Visible:= true;
end
else
result:= false;
except
result:= false;
end
else
result:= false;
if synEditor.Modified then
LblFilename.Font.Style:= [fsBold]
else
LblFilename.Font.Style:= [];
AProgram:= nil;
end
else
result:= false;
end;
procedure TEditorForm.Open(Filename: TFilename);
begin
if LowerCase(ExtractFileExt(Filename)) = '.pj' then
OpenProject(Filename)
else
OpenFile(Filename);
end;
function TEditorForm.OpenFile(Filename: TFilename): Boolean;
begin
if not (_isRunning or _isSingleStep) then
begin
try
if SaveRequest <> mrCancel then
begin
synEditor.Lines.LoadFromFile(Filename);
LblFilename.Caption:= Filename;
_BreakpointList.ClearAllBreakpoints;
result:= true;
synEditor.Modified:= false;
_CodeModified:= true;
iProject.Visible:= false;
iSourcecode.Visible:= true;
end
else
result:= false;
except
result:= false;
end;
if synEditor.Modified then LblFilename.Font.Style:= [fsBold]
else LblFilename.Font.Style:= [];
AProgram:= nil;
end
else
result:= false;
end;
function TEditorForm.OpenProject: Boolean;
var
FStringStream: TStringStream;
FStream: TFileStream;
CodeModified: Boolean;
begin
if not (_isRunning or _isSingleStep) then
begin
AProgram:= nil;
if OpenProjectDialog.Execute then
try
FStream:= TFileStream.Create(OpenProjectDialog.FileName,fmOpenRead,fmShareDenyWrite);
if SaveRequest <> mrCancel then begin
result:= true;
// Load i8008
if Assigned(OnLoadProject) then OnLoadProject(FStream,result);
// Load Editor State
result:= result and
(FStream.Read(CodeModified,SizeOf(CodeModified)) = SizeOf(CodeModified));
// Load i8008 Program
if result and (not CodeModified) and Assigned(OnLoadProgram) then
OnLoadProgram(FStream,result);
// Load Sourcecode
if result then begin
FStringStream:= TStringStream.Create('');
try
FStringStream.CopyFrom(FStream, FStream.Size-FStream.Position);
synEditor.Lines.LoadFromStream(FStringStream);
finally
FreeAndNil(FStringStream);
end;
LblFilename.Caption:= OpenProjectDialog.Filename;
_BreakpointList.ClearAllBreakpoints;
if not Visible then Show;
if Visible then goToLine(-1);
synEditor.Modified:= false;
_CodeModified:= CodeModified;
iProject.Visible:= true;
iSourcecode.Visible:= false;
end else MessageDlg(getString(rs_msg_OpenError),mtError,[mbOk],0);
end else result:= false;
FStream.Free;
except
result:= false;
MessageDlg(getString(rs_msg_OpenError),mtError,[mbOk],0);
end
else
result:= false;
if synEditor.Modified then
LblFilename.Font.Style:= [fsBold]
else
LblFilename.Font.Style:= [];
end
else
result:= false;
end;
function TEditorForm.OpenProject(Filename: TFilename): Boolean;
var
FStringStream: TStringStream;
FStream: TFileStream;
CodeModified: Boolean;
begin
if not (_isRunning or _isSingleStep) then
begin
AProgram:= nil;
try
FStream:= TFileStream.Create(FileName,fmOpenRead,fmShareDenyWrite);
if SaveRequest <> mrCancel then begin
result:= true;
// Load i8008
if Assigned(OnLoadProject) then
OnLoadProject(FStream,result);
// Load Editor State
result:= result and
(FStream.Read(CodeModified,SizeOf(CodeModified)) = SizeOf(CodeModified));
// Load i8008 Program
if result and (not CodeModified) and Assigned(OnLoadProgram) then
OnLoadProgram(FStream,result);
// Load Sourcecode
if result then begin
FStringStream:= TStringStream.Create('');
try
FStringStream.CopyFrom(FStream, FStream.Size-FStream.Position);
synEditor.Lines.LoadFromStream(FStringStream);
finally
FreeAndNil(FStringStream);
end;
LblFilename.Caption:= Filename;
_BreakpointList.ClearAllBreakpoints;
synEditor.Modified:= false;
_CodeModified:= CodeModified;
iProject.Visible:= true;
iSourcecode.Visible:= false;
end else MessageDlg(getString(rs_msg_OpenError),mtError,[mbOk],0);
end else result:= false;
FStream.Free;
except
result:= false;
MessageDlg(getString(rs_msg_OpenError),mtError,[mbOk],0);
end;
if synEditor.Modified then
LblFilename.Font.Style:= [fsBold]
else
LblFilename.Font.Style:= [];
end
else
result:= false;
end;
function TEditorForm.SaveRequest: Integer;
begin
result:= mrNone;
if synEditor.Modified then
result:= MessageDlg(getString(rsSaveChanges),mtConfirmation,[mbYes,mbNo,mbCancel],0);
if result = mrYes then begin
if SaveFile then result:= mrYes
else result:= mrCancel;
end else if result = mrNo then synEditor.Modified:= false;
end;
procedure TEditorForm.Save;
begin
if LowerCase(ExtractFileExt(LblFilename.Caption)) = '.pj' then SaveProject
else SaveFile;
end;
function TEditorForm.SaveFile: Boolean;
var
BackupName: TFilename;
begin
if not (_isRunning or _isSingleStep) then
begin
if synEditor.Modified then
AProgram:= nil;
if LblFilename.Caption <> '' then
try
if FileExists(LblFilename.Caption) then
begin
BackupName:= ChangeFileExt(LblFilename.Caption,'.~asm');
if FileExists(BackupName) then
DeleteFile(BackupName);
RenameFile(LblFilename.Caption,BackupName);
end;
synEditor.Lines.SaveToFile(LblFilename.Caption);
result:= true;
synEditor.Modified:= false;
except
result:= false;
end
else
result:= false;
if not result then
result:= SaveFileAs;
if synEditor.Modified then
LblFilename.Font.Style:= [fsBold]
else
LblFilename.Font.Style:= [];
end
else
result:= false;
end;
function TEditorForm.SaveFileAs: Boolean;
begin
if not (_isRunning or _isSingleStep) then
begin
if SaveDialog.Execute then
begin
if synEditor.Modified then
AProgram:= nil;
try
LblFilename.Caption:= SaveDialog.Filename;
synEditor.Lines.SaveToFile(LblFilename.Caption);
result:= true;
synEditor.Modified:= false;
except
result:= false;
end
end
else
result:= false;
if synEditor.Modified then
LblFilename.Font.Style:= [fsBold]
else
LblFilename.Font.Style:= [];
end
else
result:= false;
end;
function TEditorForm.SaveProject: Boolean;
var
BackupName: TFilename;
FStream: TFileStream;
begin
if not (_isRunning or _isSingleStep) then
begin
if synEditor.Modified then
AProgram:= nil;
if LblFilename.Caption <> '' then
try
if FileExists(LblFilename.Caption) then
begin
BackupName:= ChangeFileExt(LblFilename.Caption,'.~pj');
if FileExists(BackupName) then
DeleteFile(BackupName);
RenameFile(LblFilename.Caption,BackupName);
end;
FStream:= TFileStream.Create(LblFilename.Caption,fmCreate,fmShareExclusive);
result:= true;
// Save i8008
if Assigned(OnSaveProject) then
OnSaveProject(FStream,result);
// Save Editor State
result:= result and
(FStream.Write(_CodeModified,SizeOf(_CodeModified)) = SizeOf(_CodeModified));
// Save i8008 Program
if result and (not _CodeModified) and Assigned(OnSaveProgram) then
OnSaveProgram(FStream,result);
// Save Sourcecode
synEditor.Lines.SaveToStream(FStream);
synEditor.Modified:= false;
if not result then
MessageDlg(getString(rs_msg_SaveError),mtError,[mbOk],0);
FStream.Free;
except
result:= false;
MessageDlg(getString(rs_msg_SaveError),mtError,[mbOk],0);
end
else
result:= false;
if not result then
result:= SaveProjectAs;
if synEditor.Modified then
LblFilename.Font.Style:= [fsBold]
else
LblFilename.Font.Style:= [];
end
else
result:= false;
end;
function TEditorForm.SaveProjectAs: Boolean;
var
FStream: TFileStream;
begin
if not (_isRunning or _isSingleStep) then
begin
if SaveProjectDialog.Execute then
begin
if synEditor.Modified then
AProgram:= nil;
try
LblFilename.Caption:= SaveProjectDialog.Filename;
FStream:= TFileStream.Create(LblFilename.Caption,fmCreate,fmShareExclusive);
result:= true;
// Save i8008
if Assigned(OnSaveProject) then
OnSaveProject(FStream,result);
// Save Editor State
result:= result and
(FStream.Write(_CodeModified,SizeOf(_CodeModified)) = SizeOf(_CodeModified));
// Save i8008 Program
if result and (not _CodeModified) and Assigned(OnSaveProgram) then
OnSaveProgram(FStream,result);
// Save Sourcecode
synEditor.Lines.SaveToStream(FStream);
synEditor.Modified:= false;
if not result then
MessageDlg(getString(rs_msg_SaveError),mtError,[mbOk],0);
FStream.Free;
except
result:= false;
MessageDlg(getString(rs_msg_SaveError),mtError,[mbOk],0);
end
end
else result:= false;
if synEditor.Modified then LblFilename.Font.Style:= [fsBold]
else LblFilename.Font.Style:= [];
end
else result:= false;
end;
procedure TEditorForm.Print;
var
old: Boolean;
begin
old:= synEditor.Modified;
if PrinterSetupDialog.Execute then begin
synEditorPrint.SynEdit:= synEditor;
synEditorPrint.DocTitle:= ExtractFilename(LblFilename.Caption);
synEditorPrint.Title:= ExtractFilename(LblFilename.Caption);
synEditorPrint.Print;
end;
synEditor.Modified:= old;
end;
procedure TEditorForm.ShowProgress(Value: Boolean);
begin
_i8008Assembler.ShowProgress:= Value;
end;
procedure TEditorForm.LoadLanguage;
begin
{ Dialog }
OpenDialog.Filter:= getString(rs_filter_File);
OpenDialog.Title:= getString(rs_m_Open)+' ...';
SaveDialog.Filter:= getString(rs_filter_File);
SaveDialog.Title:= getString(rs_m_SaveAs)+' ...';
OpenProjectDialog.Filter:= getString(rs_filter_Project);
OpenProjectDialog.Title:= getString(rs_m_ProjectOpen)+' ...';
SaveProjectDialog.Filter:= getString(rs_filter_Project);
SaveProjectDialog.Title:= getString(rs_m_ProjectSaveAs)+' ...';
end;
procedure TEditorForm.Show(ATop, ALeft, AWidth, AHeight: Integer);
begin
Top:= ATop;
Left:= ALeft;
Height:= AHeight;
Width:= AWidth;
Show;
end;
procedure TEditorForm.goToLine(Line: Integer);
var
FirstLine, LastLine: Integer;
begin
if Line < 0 then begin
_StepLine:= -1;
_ErrorLine:= -1;
synEditor.Invalidate;
end else begin
Line:= Line + 1;
FirstLine:= synEditor.TopLine;
LastLine:= FirstLine + synEditor.LinesInWindow - 1;
if (Line < FirstLine) or (Line > LastLine) then synEditor.TopLine:= Line;
synEditor.Invalidate;
end;
end;
procedure TEditorForm.synEditorGutterClick(Sender: TObject;
Button: TMouseButton; X, Y, Line: Integer; Mark: TSynEditMark);
var
i: Integer;
begin
_BreakpointList.ToggleBreakpoint(Line);
// Update Breakpoints
for i:= 0 to _BreakpointList.Count-1 do _BreakpointList.Items[i].State:= false;
if Assigned(_Program) then
for i:= 0 to _Program.Count-1 do _BreakpointList.BreakpointState[_Program.Items[i].Link+1]:= true;
synEditor.InvalidateLine(Line);
end;
procedure TEditorForm.synEditorSpecialLineColors(Sender: TObject;
Line: Integer; var Special: Boolean; var FG, BG: TColor);
begin
// Error
Special:= Line = (_ErrorLine+1);
if Special then begin
FG:= clWhite;
BG:= clRed;
end;
// Programcounter
if not Special then begin
Special:= Line = (_StepLine+1);
if Special then begin
FG:= clWhite;
BG:= clAqua;
end;
// Breakpoint
if not Special then begin
Special:= _BreakpointList.Breakpoint(Line);
if Special then begin
FG:= clWhite;
BG:= clRed;
end;
end;
end;
end;
procedure TEditorForm.OnAfterPaint(ACanvas: TCanvas; const AClip: TRect;
FirstLine, LastLine: Integer);
var
X, Y, ImageIndex: Integer;
begin
if true then begin
X:= 14;
Y:= (synEditor.LineHeight - imglGutter.Height) div 2
+ synEditor.LineHeight * (FirstLine - synEditor.TopLine);
while FirstLine <= LastLine do begin
if (_StepLine+1) = FirstLine then begin
if _BreakpointList.Breakpoint(FirstLine) then ImageIndex:= 3
else ImageIndex:= 2
end else begin
if _BreakpointList.Breakpoint(FirstLine) then begin
if _BreakpointList.BreakpointState[FirstLine] then ImageIndex:= 1
else ImageIndex:= 0;
end else ImageIndex:= -1;
end;
if ImageIndex >= 0 then imglGutter.Draw(ACanvas, X, Y, ImageIndex);
Inc(FirstLine);
Inc(Y, synEditor.LineHeight);
end;
end;
end;
end.