1 unit FramePicRegisters;
2 {$mode objfpc}{$H+}
3 interface
4 uses
5   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, StdCtrls, LCLProc,
6   LCLIntf, LCLType, Grids, ExtCtrls, Parser,
7   PicCore, Pic16Utils, Pic10Utils, Pic17Utils;
8 type
9 
10   { TfraPicRegisters }
11 
12   TfraPicRegisters = class(TFrame)
13     Label1: TLabel;
14     Label2: TLabel;
15     Label3: TLabel;
16     StringGrid1: TStringGrid;
17     StringGrid2: TStringGrid;
18   private
19     cxp: TCompilerBase;
20     //Acceso a los registros importantes
21     WREGptr: ^byte;
22     STATptr: ^byte;
23     procedure ShowRegister(reg: byte; gri: TStringGrid);
24   public
25     procedure SetCompiler(cxp0: TCompilerBase);
26     procedure Refrescar;
27     //procedure SetRegisters();
28     constructor Create(AOwner: TComponent) ; override;
29     destructor Destroy; override;
30   end;
31 
32 implementation
33 {$R *.lfm}
34 { TfraPicRegisters }
35 procedure TfraPicRegisters.ShowRegister(reg: byte; gri: TStringGrid);
36 {Muestra el contenido de un registro en la fila indciada de la grilla.}
37 begin
38   gri.BeginUpdate;
39   gri.Cells[0,1] := IntToStr(reg);
40   gri.Cells[1,1] := IntToHex(reg, 2);
41   if (reg and %00000001)<>0 then gri.Cells[9, 1] := '1' else gri.Cells[9, 1] := '0';
42   if (reg and %00000010)<>0 then gri.Cells[8, 1] := '1' else gri.Cells[8, 1] := '0';
43   if (reg and %00000100)<>0 then gri.Cells[7, 1] := '1' else gri.Cells[7, 1] := '0';
44   if (reg and %00001000)<>0 then gri.Cells[6, 1] := '1' else gri.Cells[6, 1] := '0';
45   if (reg and %00010000)<>0 then gri.Cells[5, 1] := '1' else gri.Cells[5, 1] := '0';
46   if (reg and %00100000)<>0 then gri.Cells[4, 1] := '1' else gri.Cells[4, 1] := '0';
47   if (reg and %01000000)<>0 then gri.Cells[3, 1] := '1' else gri.Cells[3, 1] := '0';
48   if (reg and %10000000)<>0 then gri.Cells[2, 1] := '1' else gri.Cells[2, 1] := '0';
49   gri.EndUpdate;
50 end;
51 procedure TfraPicRegisters.SetCompiler(cxp0: TCompilerBase);
52 {Fija el compilador actual.}
53 var
54   pic : TPicCore;
55 begin
56   cxp := cxp0;
57   pic := cxp0.picCore;
58   //Configura registros de acuerdo al tipo de arquitectura del compilador
59   WREGptr := nil;
60   STATptr := nil;
61   //Obtiene referencias a los registros importantes
62   case cxp.ID of
63   10: begin
64     WREGptr := @(TPIC10(pic).W);
65     StringGrid2.Cells[2,0] := 'GPWUF';
66     if copy(pic.Model,1,6) = 'PIC12F'  then begin
67       StringGrid2.Cells[3,0] := '';
68       StringGrid2.Cells[4,0] := 'PA0';
69       STATptr := @(pic.ram[Pic10Utils._STATUS].dvalue);
70     end else begin
71       //Habría que revisar si esto se cumple siempre
72       StringGrid2.Cells[3,0] := 'CWUF';
73       StringGrid2.Cells[4,0] := '';
74       STATptr := @(pic.ram[Pic10Utils._STATUS].dvalue);
75     end;
76   end;
77   16: begin
78     WREGptr := @(TPIC16(pic).W);
79     StringGrid2.Cells[2,0] := 'IRP';
80     StringGrid2.Cells[3,0] := 'RP1';
81     StringGrid2.Cells[4,0] := 'RP0';
82     STATptr := @(pic.ram[Pic16Utils._STATUS].dvalue);
83   end;
84   17: begin
85     WREGptr := @(TPIC16(pic).W);
86     StringGrid2.Cells[2,0] := '';
87     StringGrid2.Cells[3,0] := '';
88     StringGrid2.Cells[4,0] := '';
89     STATptr := @(pic.ram[Pic17Utils._STATUS].dvalue);
90   end;
91   end;
92 end;
93 procedure TfraPicRegisters.Refrescar;
94 {Refresca valores de los registros}
95 begin
96   ShowRegister(WREGptr^, StringGrid1);
97   ShowRegister(STATptr^, StringGrid2);
98 end;
99 constructor TfraPicRegisters.Create(AOwner: TComponent);
100 begin
101   inherited Create(AOwner);
102 end;
103 destructor TfraPicRegisters.Destroy;
104 begin
105   inherited Destroy;
106 end;
107 
108 end.
109 
110