-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathuSimus.pas
More file actions
executable file
·1291 lines (1150 loc) · 36.6 KB
/
Copy pathuSimus.pas
File metadata and controls
executable file
·1291 lines (1150 loc) · 36.6 KB
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
992
993
994
995
996
997
998
999
1000
//
// Copyright 2016 Gabriel P. Silva and José Antonio S. Borges
//
// This file is part of simulator SimuS.
//
// SimuS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// SimuS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with SimuS. If not, see <http://www.gnu.org/licenses/>.
//
// Este arquivo é parte do programa MainMenu SimuS.
//
// SimuS é um software livre; você pode redistribuí-lo e/ou
// modificá-lo dentro dos termos da Licença Pública Geral GNU como
// publicada pela Fundação do Software Livre (FSF); na versão 3 da
// Licença, ou (na sua opinião) qualquer versão.
//
// Este programa é distribuído na esperança de que possa ser útil,
// mas SEM NENHUMA GARANTIA; sem uma garantia implícita de ADEQUAÇÃO
// a qualquer MERCADO ou APLICAÇÃO EM PARTICULAR. Veja a
// Licença Pública Geral GNU para maiores detalhes.
//
// Você deve ter recebido uma cópia da Licença Pública Geral GNU junto
// com este programa, se não, veja em <http://www.gnu.org/licenses/>.
//
unit uSimus;
{$IFDEF FPC}
{$MODE Delphi}
{$ENDIF}
interface
uses
{$IFnDEF FPC}
shellApi, Windows,
{$ELSE}
LCLIntf, LCLType,
{$ENDIF}
SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Menus, Buttons, uSimula, ExtCtrls, ComCtrls, SynEdit,
SynHighlighterPas, SynHighlighterAny, SynCompletion, Types, LCLTranslator,
DefaultTranslator, ResString, utrap;
type
{ TformPrincipal }
TformPrincipal = class(TForm)
chave0: TLabel;
chave1: TLabel;
BreakPointBtn: TSpeedButton;
DisplayTitulo: TLabel;
Label10: TLabel;
Label11: TLabel;
AbrirExemplo: TMenuItem;
EditorEPainelDeControle: TPanel;
l_Valor: TLabel;
MainMenu: TMainMenu;
Arquivo1: TMenuItem;
Abrir1: TMenuItem;
MolduraBanner: TBevel;
MolduraChaves: TShape;
MolduraCtrlExec: TBevel;
MolduraVisor: TBevel;
Pronto: TLabel;
Salvar1: TMenuItem;
SalvarComo1: TMenuItem;
Sair1: TMenuItem;
N1: TMenuItem;
Compilar1: TMenuItem;
Assistente1: TMenuItem;
b_executar: TButton;
b_passoAPasso: TButton;
b_parar: TButton;
l_display: TLabel;
Label5: TLabel;
Label6: TLabel;
l_teclado: TLabel;
b_entrar: TButton;
ledOff_dado: TSpeedButton;
LedOn_dado: TSpeedButton;
b_reset: TButton;
ledOn_exec: TSpeedButton;
ledOff_exec: TSpeedButton;
l_executando: TLabel;
Highlighter: TSynAnySyn;
SynAutoComplete: TSynAutoComplete;
SynCompletion: TSynCompletion;
SynEditor: TSynEdit;
Edicao: TTabSheet;
TimerDeExecucao: TTimer;
AbrirLingMquina1: TMenuItem;
SalvarLingMquina1: TMenuItem;
Sobreoprograma1: TMenuItem;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
Novo1: TMenuItem;
OpenDialog2: TOpenDialog;
SaveDialog2: TSaveDialog;
b_zera: TButton;
ch128on: TSpeedButton;
ch64on: TSpeedButton;
ch32on: TSpeedButton;
ch16on: TSpeedButton;
ch8on: TSpeedButton;
ch4on: TSpeedButton;
ch2on: TSpeedButton;
ch1on: TSpeedButton;
ch128off: TSpeedButton;
ch64off: TSpeedButton;
ch32off: TSpeedButton;
ch16off: TSpeedButton;
ch8off: TSpeedButton;
ch4off: TSpeedButton;
ch2off: TSpeedButton;
ch1off: TSpeedButton;
Shape1: TShape;
Label1: TLabel;
cb_rapido: TCheckBox;
Zerarmemria1: TMenuItem;
Editar1: TMenuItem;
Copiar1: TMenuItem;
cOlar1: TMenuItem;
Recortar1: TMenuItem;
Desfazer1: TMenuItem;
BarButton: TPanel;
OpenBtn: TSpeedButton;
SaveBtn: TSpeedButton;
CutBtn: TSpeedButton;
CopyBtn: TSpeedButton;
PasteBtn: TSpeedButton;
ExitBtn: TSpeedButton;
TutorBtn: TSpeedButton;
NewBnt: TSpeedButton;
Ajuda2: TMenuItem;
Bevel1: TBevel;
RegistradoresEMemoria: TPanel;
AlteraMemoria: TPanel;
l_endereco: TLabel;
l_novoValor: TLabel;
e_ender: TEdit;
b_recua: TButton;
b_avanca: TButton;
e_valor: TEdit;
PainelRegs: TPanel;
l_instr: TLabel;
l_instrucao: TLabel;
l_operInstrucao: TLabel;
l_registrador: TLabel;
l_PC: TLabel;
l_ACC: TLabel;
l_Z: TLabel;
l_N: TLabel;
MolduraInstrAtual: TBevel;
b_PC: TButton;
b_ACC: TButton;
b_Z: TButton;
b_N: TButton;
dumpMem: TListBox;
l_banner: TLabel;
b_C: TButton;
b_SP: TButton;
l_SP: TLabel;
l_C: TLabel;
Bevel3: TBevel;
Bevel4: TBevel;
Codigo: TPageControl;
Compilacao: TTabSheet;
lb_instrucoes: TListBox;
Execucao: TTabSheet;
m_listagem: TMemo;
Console1: TMenuItem;
cb_hexa: TCheckBox;
ProgramaoTutorada1: TMenuItem;
Conversordebases1: TMenuItem;
PainelControle: TPanel;
lb_dados: TListBox;
Splitter: TSplitter;
teclado1: TButton;
teclado2: TButton;
teclado3: TButton;
teclado6: TButton;
teclado5: TButton;
teclado4: TButton;
teclado7: TButton;
teclado8: TButton;
teclado9: TButton;
tecladoAsterico: TButton;
teclado0: TButton;
tecladoHashTag: TButton;
MolduraKeypad: TBevel;
CompileBtn: TSpeedButton;
procedure AbrirExemploClick(Sender: TObject);
procedure BreakPointBtnClick(Sender: TObject);
procedure b_pararClick(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
procedure lb_instrucoesDrawItem(Control: TWinControl; Index: Integer;
ARect: TRect; State: TOwnerDrawState);
procedure lb_instrucoesKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure lb_instrucoesSelectionChange(Sender: TObject; User: boolean);
procedure TimerDeExecucaoTimer(Sender: TObject);
procedure b_executarClick(Sender: TObject);
procedure b_resetClick(Sender: TObject);
procedure e_enderExit(Sender: TObject);
procedure b_PCClick(Sender: TObject);
procedure b_ACCClick(Sender: TObject);
procedure b_recuaClick(Sender: TObject);
procedure b_avancaClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure e_valorKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure e_valorExit(Sender: TObject);
procedure b_passoAPassoClick(Sender: TObject);
procedure b_entrarClick(Sender: TObject);
procedure Sair1Click(Sender: TObject);
procedure Sobreoprograma1Click(Sender: TObject);
procedure Assistente1Click(Sender: TObject);
procedure Abrir1Click(Sender: TObject);
procedure SalvarComo1Click(Sender: TObject);
procedure Novo1Click(Sender: TObject);
procedure NovoArquivo;
procedure Salvar1Click(Sender: TObject);
procedure SalvarLingMquina1Click(Sender: TObject);
procedure AbrirLingMquina1Click(Sender: TObject);
procedure Compilar1Click(Sender: TObject);
procedure b_zeraClick(Sender: TObject);
procedure b_ZClick(Sender: TObject);
procedure b_NClick(Sender: TObject);
procedure b_CClick(Sender: TObject);
procedure click_desliga(Sender: TObject);
procedure click_liga(Sender: TObject);
procedure cb_rapidoClick(Sender: TObject);
procedure Zerarmemria1Click(Sender: TObject);
procedure CutBtnClick(Sender: TObject);
procedure CopyBtnClick(Sender: TObject);
procedure PasteBtnClick(Sender: TObject);
procedure Desfazer1Click(Sender: TObject);
procedure Ajuda2Click(Sender: TObject);
procedure limpaEditor;
procedure atualizaListagem;
procedure preparaDebug;
procedure atualizaDebug (pc: integer);
procedure editorKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure Console1Click(Sender: TObject);
procedure cb_hexaClick(Sender: TObject);
procedure Conversordebases1Click(Sender: TObject);
procedure dumpMemClick(Sender: TObject);
procedure b_tecladoClick(Sender: TObject);
private
{ Private declarations }
function VerificaBreakpoint() : boolean;
public
{ Public declarations }
procedure atualizaInterface;
procedure mostraAlterado (alteraDump: boolean);
procedure geraDump (ender: integer);
function geraLinhaDump (ender: integer): string;
procedure atualizaDump;
procedure atualizaLeds;
procedure atualizaDados (zerando: boolean);
//procedure NovoArquivo;
end;
var
formPrincipal: TformPrincipal;
enderAlterado: integer;
nomeArq: string;
execucaoRapida: boolean;
BreakpointList : TStringList;
ExecutingLine : integer;
controlKeyPressed : boolean;
implementation
uses uHex, uvars, uAbout, uAutoPrg, uAssemb, uconsole;
{$IFnDEF FPC}
{$R *.dfm}
{$ELSE}
{$R *.lfm}
{$ENDIF}
procedure TformPrincipal.atualizaInterface;
var instr, ender, dado: integer;
ind_ti: integer;
modoEnder: integer;
begin
l_display.caption := intToHex (displayReg, 2);
l_teclado.caption := intToHex (keyReg, 2);
atualizaLeds;
l_display.caption := intToHex (displayReg, 2);
instr := (memoria[PC] shr 2) and $3f;
ind_ti := indTabInstrPorCod[instr];
if ind_ti < 0 then // instrução inválida
begin
l_instrucao.caption := '???';
l_operInstrucao.Caption := ''
end
else
begin
l_instrucao.caption := tabInstrucoes[ind_ti].mnemo;
if not modoEnderValido (ind_ti, memoria[PC] and 2) then
l_operInstrucao.Caption := '???'
else
if tabInstrucoes[ind_ti].params = 0 then
l_operInstrucao.Caption := ''
else
if tabInstrucoes[ind_ti].params = VALOR then
begin
ender := pegaMemoria (PC+1, 8);
l_operInstrucao.Caption := intToHex (ender, 2);
end
else
begin
modoEnder := memoria[PC] and 3;
case modoEnder of
0: begin {direto}
ender := pegaMemoria (PC+1, 16);
l_operInstrucao.Caption := intToHex (ender, 4);
end;
1: begin {indireto}
ender := pegaMemoria (PC+1, 16);
l_operInstrucao.Caption := '@' + intToHex (ender, 4);
end;
2: begin {imediato - 8 bits}
dado := pegaMemoria (PC+1, 8);
l_operInstrucao.Caption := '#' + intToHex (dado, 2);
end;
3: begin {imediato - 16 bits}
dado := pegaMemoria (PC+1, 16);
l_operInstrucao.Caption := '#' + intToHex (dado, 4);
end;
end;
end;
end;
l_PC.caption := intToHex (PC, 4);
l_ACC.caption := intToHex (ACC, 2);
l_SP.caption := intToHex (SP, 4);
if ALU_N then l_N.Caption := '1' else l_N.Caption := '0';
if ALU_Z then l_Z.Caption := '1' else l_Z.Caption := '0';
if ALU_C then l_C.Caption := '1' else l_C.Caption := '0';
l_banner.Caption := bannerReg;
mostraAlterado (false);
atualizaDump;
atualizaDados (false);
atualizaDebug (PC);
end;
procedure TformPrincipal.b_PCClick(Sender: TObject);
var s: string;
begin
running := false;
atualizaLeds;
s := intToHex (PC, 4);
l_PC.caption := s;
if inputQuery (SInforme, SNovoValorDoPC, s) then
PC := hexToInt (s) and $ffff;
atualizaInterface;
end;
procedure TformPrincipal.b_ACCClick(Sender: TObject);
var s: string;
begin
running := false;
atualizaLeds;
s := intToHex (ACC, 2);
l_ACC.caption := s;
if inputQuery (SInforme, SNovoValorDoAcc, s) then
ACC := hexToInt (s) and $ff;
atualizaInterface;
end;
function TformPrincipal.geraLinhaDump (ender: integer): string;
var
s: string;
i: integer;
begin
s := intToHex (ender, 4) + ': ';
if cb_hexa.checked then
begin
for i := 0 to 7 do
begin
s := s + intToHex (memoria[ender+i], 2);
if odd(i) then s := s + ' ';
end;
end
else
begin
for i := 0 to 7 do
begin
if memoria[ender+i] >= $20 then
s := s + ' ' + chr(memoria[ender+i])
else
case memoria[ender+i] of
$00: s := s + '\0';
$09: s := s + '\t';
$0a: s := s + '\n';
$0c: s := s + '\f';
$0d: s := s + '\r';
else
s := s + ' .';
end;
end;
end;
result := s;
end;
procedure TformPrincipal.geraDump (ender: integer);
begin
ender := ender and $FFF8;
dumpMem.items [ender div 8] := geraLinhaDump (ender);
end;
procedure TformPrincipal.atualizaDump;
var
i, ini, fim: integer;
begin
ini := dumpMem.TopIndex;
fim := ini + dumpMem.ClientHeight div dumpmem.ItemHeight - 1;
for i := ini to fim do
dumpMem.Items[i] := geraLinhaDump(i*8);
end;
procedure TformPrincipal.mostraAlterado (alteraDump: boolean);
begin
e_ender.text := intToHex (enderAlterado, 4);
e_valor.text := intToHex (memoria [enderAlterado], 2);
e_valor.SelectAll;
if alteraDump then
begin
geraDump (enderAlterado);
dumpMem.Selected [enderAlterado div 8] := true;
end;
end;
procedure TformPrincipal.e_enderExit(Sender: TObject);
begin
enderAlterado := hexToInt (e_ender.text) and $FFFF;
mostraAlterado (true);
end;
procedure TformPrincipal.e_valorExit(Sender: TObject);
begin
memoria [enderAlterado] := hexToInt (e_valor.text) and $FF;
mostraAlterado (true);
end;
procedure TformPrincipal.b_recuaClick(Sender: TObject);
begin
enderAlterado := (enderAlterado - 1) and $FFFF;
mostraAlterado (true);
end;
procedure TformPrincipal.b_avancaClick(Sender: TObject);
begin
enderAlterado := (enderAlterado + 1) and $FFFF;
mostraAlterado (true);
end;
procedure TformPrincipal.e_valorKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key = VK_RETURN then
begin
e_valorExit (Sender);
b_avancaClick (Sender);
end;
end;
procedure TformPrincipal.FormActivate(Sender: TObject);
begin
atualizaInterface;
atualizaDump;
end;
procedure TformPrincipal.FormCreate(Sender: TObject);
var i: integer;
begin
inicMaquina (true);
execucaoRapida := cb_rapido.Checked;
limpaEditor;
dumpMem.Items.Clear;
for i := 0 to 65535 div 8 do
dumpMem.Items.add (geraLinhaDump(i*8));
atualizaDump;
BreakpointList:= TStringList.Create;
BreakpointList.Duplicates:= dupIgnore;
BreakpointList.Sorted:= true;
Codigo.ActivePage:=Edicao;
end;
procedure TformPrincipal.b_passoAPassoClick(Sender: TObject);
begin
Codigo.ActivePage := Execucao;
running := false;
executaInstrucao;
atualizaInterface;
end;
procedure TformPrincipal.atualizaLeds;
begin
if running then
begin
ledOn_exec.Visible := true;
ledOff_exec.Visible := false;
end
else
begin
ledOn_exec.Visible := false;
ledOff_exec.Visible := true;
end;
if keyStatusReg <> 0 then
begin
ledOn_dado.Visible := true;
ledOff_dado.Visible := false;
end
else
begin
ledOn_dado.Visible := false;
ledOff_dado.Visible := true;
end;
end;
procedure TformPrincipal.b_entrarClick(Sender: TObject);
begin
keyStatusReg := 1;
atualizaLeds;
end;
procedure TformPrincipal.Sair1Click(Sender: TObject);
begin
Close;
end;
procedure TformPrincipal.Sobreoprograma1Click(Sender: TObject);
begin
aboutBox.visible := true;
end;
procedure TformPrincipal.Assistente1Click(Sender: TObject);
begin
formAutoMonta.visible := true;
end;
procedure TformPrincipal.AbrirExemploClick(Sender: TObject);
begin
b_pararClick(Sender);
if SynEditor.Modified <> false then
if MessageDlg(STudoFoiSalvo,
mtConfirmation, [mbYes, mbNo], 0) <> mrYes then exit;
OpenDialog1.InitialDir:= ExtractFilePath(Application.ExeName) + DirectorySeparator + 'Exemplos';
if openDialog1.Execute then
begin
nomeArq := openDialog1.FileName;
try
SynEditor.Lines.LoadFromFile(nomeArq);
caption := nomeArq + S_SimuladorDoProcSapiens8;
m_listagem.Clear;
lb_instrucoes.Clear;
ndebugDados := 0;
setLength (debugDados, ndebugDados);
lb_dados.Clear;
except
showMessage (SErroAoCarregarArquivo);
end;
end;
end;
procedure TformPrincipal.BreakPointBtnClick(Sender: TObject);
var
idx, isBreakpoint : integer;
begin
if Codigo.ActivePage <> Execucao then Exit;
idx := lb_instrucoes.ItemIndex;
isBreakpoint := BreakpointList.IndexOf( IntToStr(idx));
if isBreakpoint = -1 then
BreakpointList.Add(IntToStr(idx))
else
BreakpointList.Delete(isBreakPoint);
lb_instrucoes.Repaint;
end;
procedure TformPrincipal.Abrir1Click(Sender: TObject);
begin
b_pararClick(Sender);
if SynEditor.Modified <> false then
if MessageDlg(STudoFoiSalvo,
mtConfirmation, [mbYes, mbNo], 0) <> mrYes then exit;
if openDialog1.Execute then
begin
nomeArq := openDialog1.FileName;
try
SynEditor.Lines.LoadFromFile(nomeArq);
caption := nomeArq + S_SimuladorDoProcSapiens8;
m_listagem.Clear;
lb_instrucoes.Clear;
ndebugDados := 0;
setLength (debugDados, ndebugDados);
lb_dados.Clear;
except
showMessage (SErroAoCarregarArquivo);
end;
end;
end;
procedure TformPrincipal.SalvarComo1Click(Sender: TObject);
begin
if nomeArq <> '' then
SaveDialog1.FileName := nomeArq;
if SaveDialog1.execute then
begin
nomeArq := SaveDialog1.FileName;
if nomeArq <> '' then
begin
SynEditor.Lines.SaveToFile(nomeArq);
caption := nomeArq + S_SimuladorDoProcSapiens8;
end;
end;
end;
procedure TformPrincipal.limpaEditor;
begin
SynEditor.clear;
SynEditor.lines.add (';---------------------------------------------------');
SynEditor.lines.add (SPrograma);
SynEditor.lines.add (SAutor);
SynEditor.lines.add (SData);
SynEditor.lines.add (';---------------------------------------------------');
SynEditor.Lines.Add('');
SynEditor.SelStart := SynEditor.GetTextLen;
end;
procedure TformPrincipal.NovoArquivo;
begin
nomeArq := '';
caption := SSimuladorDoProcSapiens8;
limpaEditor;
m_listagem.Clear;
lb_instrucoes.Clear;
ndebugDados := 0;
setLength (debugDados, ndebugDados);
lb_dados.Clear;
end;
procedure TformPrincipal.Novo1Click(Sender: TObject);
begin
b_pararClick(Sender);
if SynEditor.Modified <> false then
if MessageDlg(STudoFoiSalvo, mtConfirmation, [mbYes, mbNo], 0) = mrYes then
begin
NovoArquivo;
end
else
begin
if nomeArq <> '' then
SaveDialog1.FileName := nomeArq;
if SaveDialog1.execute then
begin
nomeArq := SaveDialog1.FileName;
if nomeArq <> '' then
begin
SynEditor.Lines.SaveToFile(nomeArq);
caption := nomeArq + S_SimuladorDoProcSapiens8;
end;
NovoArquivo;
end
else
begin
exit;
end;
end;
end;
procedure TformPrincipal.Salvar1Click(Sender: TObject);
begin
if nomeArq <> '' then
SynEditor.Lines.SaveToFile(nomeArq)
else
salvarComo1Click (sender);
end;
procedure TformPrincipal.SalvarLingMquina1Click(Sender: TObject);
var i, ultEnderValido: integer;
arq: textFile;
begin
if saveDialog2.execute then
begin
if saveDialog2.filename = '' then exit;
assignFile (arq, saveDialog2.filename);
try
rewrite (arq);
ultEnderValido := 0;
for i := $FFFF downto 1 do
if memoria[i] <> 0 then
begin
ultEnderValido := i;
break;
end;
for i := 0 to ultEnderValido do
begin
write (arq, intToHex (memoria[i], 2));
if (i mod 8) = 7 then writeln (arq);
end;
writeln (arq);
finally
closefile (arq);
end;
end;
end;
procedure TformPrincipal.AbrirLingMquina1Click(Sender: TObject);
var
arq: textFile;
x, s: string;
ender: integer;
begin
b_pararClick(Sender);
if openDialog2.execute then
begin
assignFile (arq, openDialog2.filename);
try
reset (arq);
ender := 0;
while not eof (arq) do
begin
readln (arq, s);
trim (s);
while s <> '' do
begin
x := copy (s, 1, 2);
delete (s, 1, 2);
memoria [ender] := hexToInt (x);
ender := ender + 1;
end;
end;
finally
closefile (arq);
end;
end;
atualizaInterface;
end;
procedure TformPrincipal.preparaDebug;
var i: integer;
l, lu: string;
begin
lb_instrucoes.clear;
for i := 0 to listagem.Count-1 do
begin
l := trim (listagem[i]);
if copy (l, 1, 8) = SListagem then break; //cuidado com a traducao desse SListagem
if copy (l, 5, 99) = '' then continue;
if not (l[1] in ['0'..'9']) then continue;
if copy (l, 6, 10) = ' ' then continue;
lu := uppercase (l);
if (pos (' DB ', lu) <> 0) or
(pos (':DB ', lu) <> 0) or
(pos (' DS ', lu) <> 0) or
(pos (':DS ', lu) <> 0) or
(pos (' STR ', lu) <> 0) or
(pos (':STR ', lu) <> 0) then continue;
lb_instrucoes.Items.add(listagem[i]);
end;
end;
procedure TformPrincipal.atualizaDebug (PC: integer);
var
spc, l: string;
i: integer;
begin
//modified to support breakpoint in fastmode
if cb_rapido.Checked = true then
begin
spc := intToHex (PC, 4);
for i := 0 to lb_instrucoes.Count-1 do
begin
l := lb_instrucoes.Items[i];
if copy (l, 8, 4) = spc then
begin
ExecutingLine := i;
exit;
end;
end;
lb_instrucoes.ItemIndex := -1;
end
else
begin
spc := intToHex (PC, 4);
for i := 0 to lb_instrucoes.Count-1 do
begin
l := lb_instrucoes.Items[i];
if copy (l, 8, 4) = spc then
begin
lb_instrucoes.ItemIndex := i;
ExecutingLine :=i;
exit;
end;
end;
end;
end;
procedure TformPrincipal.atualizaDados (zerando: boolean);
var n, m: integer;
s: string;
b, b2: byte;
w: integer;
begin
if not zerando then { para compatibilidade com Lazarus em Linux}
while lb_dados.Items.Count < ndebugDados do
lb_dados.Items.add (' ');
for n := 0 to ndebugDados-1 do
with debugDados[n] do
begin
s := intToHex (ender, 4) + ' ' +
copy (nome+ ' ', 1, 10) + ' ';
case tipo of
'S': begin
s := s + '"';
for m := 0 to nposd-1 do
begin
b := memoria[ender+m and WORD_MASK];
case ord(b) of
$00: s := s + '\0';
$09: s := s + '\t';
$0a: s := s + '\n';
$0c: s := s + '\f';
$0d: s := s + '\r';
else
s := s + chr(b);
end;
end;
s := s + '"';
end;
'B': begin
for m := 0 to nposd-1 do
begin
b := memoria[ender+m and WORD_MASK];
s := s + intToHex(b,2)+'['+intToStr(b)+']'+ ' ';
end;
end;
'W': begin
for m := 0 to nposd-1 do
begin
b := memoria[(ender+m*2) and WORD_MASK];
b2 := memoria[(ender+m*2+1) and WORD_MASK];
w := b or (b2 shl 8);
s := s + intToHex(w,4)+'['+intToStr(w)+']'+ ' ';
end;
end;
end;
if zerando then
lb_dados.Items.Add (s)
else
lb_dados.Items[n] := s;
end;
end;
procedure TformPrincipal.atualizaListagem;
var i: integer;
begin
m_listagem.Clear;
for i := 0 to listagem.count-1 do
m_listagem.Lines.add (listagem[i]);
Codigo.ActivePage := Compilacao;
end;
procedure TformPrincipal.Compilar1Click(Sender: TObject);
begin
b_resetClick(Sender);
zeraMemoria;
lb_dados.Clear;
compila (nomeArq);
atualizaListagem;
preparaDebug;
atualizaInterface;
end;
procedure TformPrincipal.b_zeraClick(Sender: TObject);
begin
keyStatusReg := 0;
atualizaInterface;
end;
procedure TformPrincipal.b_ZClick(Sender: TObject);
var s: string;
begin
running := false;
atualizaLeds;
s := boolToStr (ALU_Z);
if s[1] = '-' then delete (s, 1, 1);
l_Z.caption := s;
if inputQuery (SInforme, SNovoValorDoFlagZ, s) then
ALU_Z := s = '1';
atualizaInterface;
end;
procedure TformPrincipal.b_NClick(Sender: TObject);
var s: string;
begin
running := false;
atualizaLeds;
s := boolToStr (ALU_N);
if s[1] = '-' then delete (s, 1, 1);
l_N.caption := s;
if inputQuery (SInforme, SNovoValorDoFlagN, s) then
ALU_N := s = '1';
atualizaInterface;
end;
procedure TformPrincipal.b_CClick(Sender: TObject);
var s: string;
begin
running := false;
atualizaLeds;
s := boolToStr (ALU_C);
if s[1] = '-' then delete (s, 1, 1);
l_C.caption := s;
if inputQuery (SInforme, SNovoValorDoFlagC, s) then
ALU_C := s = '1';
atualizaInterface;
end;
procedure TformPrincipal.click_desliga(Sender: TObject);
var b: integer;
begin
b := (sender as TSpeedButton).tag;
keyReg := keyReg and (not b);
l_teclado.caption := intToHex (keyReg, 2);
case b of
128: ch128off.Visible := true;
64: ch64off.Visible := true;
32: ch32off.Visible := true;
16: ch16off.Visible := true;
8: ch8off.Visible := true;
4: ch4off.Visible := true;
2: ch2off.Visible := true;
1: ch1off.Visible := true;
end;
case b of