6 ConstantsClass
, FunctionsClass
, HardwareClass
, PrefixTreeClass
,
7 ResourcesClass
, SteppingClass
, TypesClass
,
17 function pErrorSet
: Boolean; virtual;
18 procedure pSetError(Input
: String = GLOB_NO_ERROR
; FileName
: String = ''; Line
: PInteger
= nil); virtual;
20 function LoadFromFile(const FileName
: string; Step
: TStepping
): Boolean; virtual;
21 function SaveToFile(const FileName
: string; Step
: TStepping
): Boolean; virtual;
22 property LastError
: String read pError write pError
;
27 // ************************************************************************** //
28 // * TAsmFileIO implementation * //
29 // ************************************************************************** //
31 function TAsmFileIO
.pErrorSet
: Boolean;
33 Result
:= not(pError
= GLOB_NO_ERROR
);
36 procedure TAsmFileIO
.pSetError(Input
: String = GLOB_NO_ERROR
;
37 FileName
: String = ''; Line
: PInteger
= nil);
40 if not(FileName
= '') then
41 if not(Line
= nil) then
42 pError
:= FileName
+ '(' + IntToStr(Line
^) + '): ' + pError
44 pError
:= FileName
+ ': ' + pError
;
45 if not(pError
= GLOB_NO_ERROR
) then LogWrite(pError
, True);
48 function TAsmFileIO
.LoadFromFile(const FileName
: string; Step
: TStepping
63 LogWrite(FIO_LOADING
+ FileName
);
65 AssignFile(lfile
, FileName
);
66 FileMode
:= fmOpenRead
;
70 while not Eof(lfile
) do
74 if ContainsCharacter(lline
, FIO_COMMENT
) then
76 LogWrite(FIO_COMMENT
+ ParseAfterFirst(lline
, FIO_COMMENT
));
77 lline
:= ParseBeforeFirst(lline
, FIO_COMMENT
);
79 lline
:= OmmitEverywhere(TrimCharacter(lline
, ' '), ' ', ' ');
80 lline
:= UpperCase(lline
);
81 if (lline
= '') then Continue
;
85 if not IsPrefixOf(FIO_SYSTEM
, lline
) then
87 pSetError(FIO_SYSTEM_NOT_FOUND
, FileName
);
88 LogWrite(FIO_ERROR_LOADING
+ FileName
);
91 lsystem
:= ToTLine(lline
, i
);
95 if (lline
= FIO_DATA
) then lstate
:= lstate
+ 1
96 else lstate
:= lstate
+ 2;
98 if (lline
= FIO_CODE
) then lstate
:= lstate
+ 1
99 else ldata
:= MergeTLinesLine(ldata
, ToTLine(lline
, i
));
101 linst
:= MergeTLinesLine(linst
, ToTLine(lline
, i
));
107 lhardware
:= THardware
.Create
;
111 for i
:= 0 to (Length(ldata
) - 1) do
112 if not ValidateOperand(ldata
[i
].Line
) then
113 pSetError(LastError
, FileName
, @ldata
[i
].Number
);
116 LogWrite(FIO_ERROR_LOADING
);
119 for i
:= 0 to (Length(ldata
) - 1) do
120 OperandAdd(ldata
[i
].Line
);
121 for i
:= 0 to (Length(linst
) - 1) do
122 if not ValidateInstruction(linst
[i
].Line
) then
123 pSetError(LastError
, FileName
, @linst
[i
].Number
);
126 LogWrite(FIO_ERROR_LOADING
);
133 with Step
.Hardware
do
136 for i
:= 0 to (Length(ldata
) - 1) do
137 OperandAdd(ldata
[i
].Line
);
138 Step
.InitializeBlocks
;
139 for i
:= 0 to (Length(linst
) - 1) do
140 Step
.AddStepBlock(STEP_LAST
, InstructionByName(linst
[i
].Line
));
143 LogWrite(FIO_LOADED
);
146 function TAsmFileIO
.SaveToFile(const FileName
: string; Step
: TStepping
151 loper
: POperandRecord
;
152 ltrees
: TPrefixTrees
;
157 LogWrite(FIO_SAVING
+ FileName
);
159 AssignFile(lfile
, FileName
);
161 Writeln(lfile
, FIO_SYSTEM
+ ' ' + APP_VERSION
);
163 Writeln(lfile
, FIO_DATA
);
164 ltrees
:= Step
.Hardware
.Operands
.GetAllDescendants
;
165 for i
:= 0 to (Length(ltrees
) - 1) do
167 loper
:= POperandRecord(ltrees
[i
].Data
);
168 if (loper
^.Default
= '') then Continue
;
169 for j
:= 0 to (Length(sOperandTypes
) - 1) do
170 with sOperandTypes
[j
] do
171 if (OperandType
= loper
^.OperandType
) then
173 Writeln(lfile
, ' ' + loper
^.Name
+ OPER_SEP
+ Description
);
178 Writeln(lfile
, FIO_CODE
);
179 for i
:= 0 to (Step
.Length
- 1) do
180 Writeln(lfile
, ' ' + Step
[i
].CallFunction
.Name
);