6 ConstantsClass
, FunctionsClass
, HardwareClass
, ResourcesClass
, TypesClass
;
21 function pErrorSet
: Boolean; virtual;
22 procedure pSetError(Input
: String = GLOB_NO_ERROR
); virtual;
24 constructor Create(Owner
: TStepping
; Call
: TInstruction
); virtual;
25 function ExecuteCall
: Integer; virtual;
26 function Valid
: Boolean; virtual;
27 property CallFunction
: TInstruction read pCall write pCall
;
28 property LastError
: String read pError
;
29 property Position
: Integer read pPosition write pPosition default
-1;
30 property IsBranch
: Boolean read pBranch
;
31 destructor Destroy
; override;
39 pSteps
: array of TStepBlock
;
41 pLength
, pStepBlock
: Integer;
42 pOnStep
: TChangeEvent
;
44 function pBlockFromCall(Position
: Integer; Call
: TInstruction
): TStepBlock
; virtual;
45 function pErrorSet
: Boolean; virtual;
46 function pGetBlock(Position
: Integer): TStepBlock
; virtual;
47 function pValidPosition(var Position
: Integer): Boolean; virtual;
48 procedure pSetError(Input
: String = GLOB_NO_ERROR
; Where
: String = ''); virtual;
49 procedure pSetStepBlock(Input
: Integer); virtual;
51 constructor Create
; virtual;
52 function AddStepBlock(Position
: Integer; Call
: TInstruction
): Boolean; virtual;
53 function ChangeStepBlock(Position
: Integer; Call
: TInstruction
): Boolean; virtual;
54 function RemoveStepBlock(Position
: Integer): Boolean; virtual;
55 function Valid
: Boolean; virtual;
56 procedure SingleStep
; virtual;
57 // ? function Animate(Input: Pointer); ?
58 destructor Destroy
; override;
59 property Block
[Position
: Integer]: TStepBlock read pGetBlock
; default
;
60 property Hardware
: THardware read pHardware write pHardware
;
61 property LastError
: String read pError
;
62 property Length
: Integer read pLength default
0;
63 property OnStep
: TChangeEvent read pOnStep write pOnStep
;
64 property StepBlock
: Integer read pStepBlock write pSetStepBlock
;
70 // ************************************************************************** //
71 // * TStepBlock implementation * //
72 // ************************************************************************** //
74 function TStepBlock
.pErrorSet
: Boolean;
76 Result
:= not(pError
= GLOB_NO_ERROR
);
79 procedure TStepBlock
.pSetError(Input
: String = GLOB_NO_ERROR
);
84 constructor TStepBlock
.Create(Owner
: TStepping
; Call
: TInstruction
);
88 pBranch
:= (not(Call
= nil) and (Call
.Branch
= BRANCH_BRANCH
));
92 function TStepBlock
.ExecuteCall
: Integer;
95 if not Valid
then Exit
;
96 if pCall
.Execute
and IsBranch
then
97 Result
:= StringToAddress(pCall
.BranchAddress
, Position
)
99 Result
:= Position
+ 1;
102 function TStepBlock
.Valid
: Boolean;
108 if (pCall
= nil) then pSetError(STEP_NO_CALL_FUNCTION
)
109 else if IsBranch
then
111 lbranch
:= StringToAddress(pCall
.BranchAddress
, Position
);
112 if (lbranch
< 0) or (lbranch
> pOwner
.Length
) then
113 pSetError(STEP_BRANCH_OUT_OF_RANGE
);
115 if not pErrorSet
then Result
:= True;
118 destructor TStepBlock
.Destroy
;
124 // ************************************************************************** //
125 // * TStepping implementation * //
126 // ************************************************************************** //
128 function TStepping
.pBlockFromCall(Position
: Integer; Call
: TInstruction
): TStepBlock
;
133 pSetError(STEP_NO_CALL_FUNCTION
);
136 Result
:= TStepBlock
.Create(Self
, Call
);
137 Result
.Position
:= Position
;
141 function TStepping
.pErrorSet
: Boolean;
143 Result
:= not(pError
= GLOB_NO_ERROR
);
146 function TStepping
.pGetBlock(Position
: Integer): TStepBlock
;
149 if pValidPosition(Position
) then Result
:= pSteps
[Position
]
153 function TStepping
.pValidPosition(var Position
: Integer): Boolean;
156 if (Position
< STEP_FIRST
) then
158 pSetError(STEP_POSITION_OUT_OF_RANGE
);
161 if (Position
= STEP_LAST
) then Position
:= pLength
- 1;
162 if not(Position
< pLength
) then pSetError(STEP_POSITION_OUT_OF_RANGE
)
166 procedure TStepping
.pSetError(Input
: String = GLOB_NO_ERROR
;
170 if not(Where
= '') then pError
:= Where
+ ': ' + pError
;
173 procedure TStepping
.pSetStepBlock(Input
: Integer);
176 if not pValidPosition(Input
) then Input
:= -1;
178 if not(@pOnStep
= nil) then pOnStep(Self
);
181 constructor TStepping
.Create
;
184 SetLength(pSteps
, 0);
189 function TStepping
.AddStepBlock(Position
: Integer; Call
: TInstruction
197 pLength
:= pLength
+ 1;
198 if not pValidPosition(Position
) then
200 pLength
:= pLength
- 1;
203 lblock
:= pBlockFromCall(Position
, Call
);
206 pLength
:= pLength
- 1;
209 SetLength(pSteps
, pLength
);
210 for i
:= (pLength
- 2) downto Position
do
212 pSteps
[i
+ 1] := pSteps
[i
];
213 pSteps
[i
+ 1].Position
:= i
+ 1;
215 pSteps
[Position
] := lblock
;
216 if not(Hardware
= nil) then Hardware
.MaxAddress
:= pLength
;
221 function TStepping
.ChangeStepBlock(Position
: Integer; Call
: TInstruction
228 if not pValidPosition(Position
) then Exit
;
229 lblock
:= pBlockFromCall(Position
, Call
);
230 if pErrorSet
then Exit
;
231 pSteps
[Position
].Free
;
232 pSteps
[Position
] := lblock
;
237 function TStepping
.RemoveStepBlock(Position
: Integer): Boolean;
243 if not pValidPosition(Position
) then Exit
;
244 pSteps
[Position
].Free
;
245 for i
:= Position
to (pLength
- 2) do
247 pSteps
[i
] := pSteps
[i
+ 1];
248 pSteps
[i
].Position
:= i
;
250 pLength
:= pLength
- 1;
251 SetLength(pSteps
, pLength
);
252 if not(Hardware
= nil) then Hardware
.MaxAddress
:= pLength
;
257 function TStepping
.Valid
: Boolean;
264 for i
:= 0 to (pLength
- 1) do
266 Result
:= Result
and pSteps
[i
].Valid
;
267 if pSteps
[i
].pErrorSet
then
268 pSetError(pSteps
[i
].LastError
, ZeroPaddedInteger(i
, CONST_PADDING
));
269 if not Result
or pErrorSet
then Break
;
274 procedure TStepping
.SingleStep
;
279 if not pValid
then Valid
;
280 if not pValid
then Exit
;
282 if not pValidPosition(lpos
) then StepBlock
:= 0
283 else StepBlock
:= pSteps
[lpos
].ExecuteCall
;
286 destructor TStepping
.Destroy
;
288 while (Length
> 0) do RemoveStepBlock(STEP_LAST
);