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
|
program trdsimul; (* 20 janvier 1988, 11 h 00 *)
(* traduit d'assembleur en simulateur
Fichiers d'entre
.REC en hexadcimal
extraire autant de fichiers.ABS que d'ORG nouvelles.
crer le fichier BATCH chargeant ces fichiers successifs.
.LST listing.
n'extraire que la table des symboles.
Fichiers en sortie
nomfichier.BAT (nom pass en paramtre sur ligne de commande)
F1.ABS, F2.ABS, etc.ABS
INITIALISER
ramasser argument sur ligne de commande.
ouvrir Lecture Arg.LST
ouvrir Lecture Arg.REC
Ouvrir Ecriture F1.ABS
Ouvrir Ecriture Arg.BAT
*)
Const
LongSpecPath = 24;
LongSpecFic = 28; (* 24 + 4 *)
type
Param = string[LongSpecPath];
SpecFic = string[LongSpecFic];
chaine = string[255];
octet = string[3];
mot = string[5];
FSpec = string[6];
SymAss = string[8]; (* 8 Caractres significatifs *)
NomDos = string[12];
Const
Fabs : array[1 .. 9] of FSpec =
('F1.ABS','F2.ABS','F3.ABS','F4.ABS','F5.ABS','F6.ABS','F7.ABS','F8.ABS','F9.ABS');
var
Nomrepert : string [20] ;
Nomfich, DebPath : Param;
RecFile, LstFile, BatFile : Text;
FFile : file of byte ;
FFic : SpecFic;
Interrog, ACopier_, NouvLign :chaine;
Long_ : octet;
Adre_ : mot;
Symb, Adres : SymAss;
Nom : NomDos;
Longr, PrecLongr, RapErr, PrecAdresse, NouvAdresse, Decal, IndexF : Integer;
Longl, Lon, FinPath, Bl, Ch, IndexSortie, NbEntry, Compte, I : Integer;
Longr1 : byte ;
Debut (*, PremLign *) : boolean;
BEGIN (* initialisations *)
Writeln ('Conversion du format Motorola S1-S9 en format binaire + Symboles') ;
Debut := true;
(* PremLign := true; *)
(* Nomfich := Paramstr(1); *)
getdir(0,Nomrepert) ;
If ParamCount > 0 Then Interrog := Paramstr(1) Else begin
write ('Nom du fichier
traiter ? ') ;
readln (Interrog) ;
end ;
FinPath := Pos(':',Interrog);
NomFich := Copy(Interrog, succ(FinPath), 8);
If FinPath > 1 Then DebPath := Copy(Interrog, 1, FinPath)
Else DebPath := '';
Nom := NomFich + '.REC';
Assign(RecFile, Nom);
Reset(RecFile);
Nom := NomFich + '.LST';
Assign(LstFile, Nom);
Reset(LstFile);
Assign(BatFile,'STARTUP.F');
ReWrite(BatFile);
Write ('Genere : STARTUP.F') ;
IndexSortie := 1;
FFic := DebPath + FAbs[IndexSortie];
Write(', ',FFic);
Assign(FFile, FFic);
ReWrite(FFile);
(* Oprations sur .REC
Tant que pas dernire ligne: lire
extraire ligne suivante
premier caractre: S1, S9, S0.
Si S1, c'est du code
prendre en considration.
octet suivant = longueur de ligne = 2 + nb d'octets
charger. Garder.
deux octets suivants = adresse de chargement.
Faire la diffrence avec adresse prcdente.
Est-ce gal au prcdent nombre d'octets
charger?
Si oui, fermer le fichier de sortie, en ouvrir un autre pour
cette nouvelle adresse.
et rpertorier cette adresse et ce fichier.
Sinon ajouter cette ligne au fichier de sortie en usage.
Dernire ligne ?
Non: passer la ligne suivante.
Oui: fermer les fichiers de sortie,
d'entre,
crire le fichier .BAT
*)
While Not Eof(RecFile) do
begin
ReadLn(RecFile,Interrog);
If Interrog[2] = '1' Then
begin (* c'est du code *)
Long_ := '$' + Copy(Interrog, 3,2);
Val(Long_, Longr, RapErr);
Longr := Longr - 3 ;
Adre_ := '$' + Copy(Interrog,5,4);
Val(Adre_, NouvAdresse, RapErr);
If debut Then
Begin
WriteLn(BatFile,'c F1.ABS 0x' + Copy(Interrog,5,4));
Debut := false;
End
Else (* ce n'est pas le dbut *)
Begin
Decal := NouvAdresse - PrecAdresse;
(* si Decal = Longueur prcdente, alors poursuivre mme fichier de sortie *)
If Decal <> PrecLongr Then
begin
(* fermer ancien, ouvrir suivant *)
Flush(FFile);
Close(FFile);
IndexSortie := Succ(IndexSortie);
FFic := DebPath + Fabs[IndexSortie];
Write(', ',FFic);
Assign(FFile, FFic);
Rewrite(FFile);
(* mettre
jour fichier BAT *)
WriteLn(BatFile,'c ',FABS[Indexsortie],' 0x' + Copy(Interrog,5,4));
end; (* de discordance d'adresse *)
end; (* of else: pas au dbut *)
PrecLongr := Longr ;
Longr := Longr + Longr;
ACopier_ := Copy(Interrog, 9, Longr);
I := 0 ;
repeat
I := I+2 ;
Longr1 := Ord(Acopier_[I]) - 48;
If Longr1 > 9 Then Longr1 := Longr1 - 7;
Longl := Ord(Acopier_[I-1]) - 48;
If Longl > 9 Then Longl := Longl - 7;
Longr1 := 16 * Longl + Longr1;
Write(FFile, Longr1 );
until I>=Length(ACopier_) ;
PrecAdresse := NouvAdresse;
(* debut := false;*)
end; (* of S1 *)
end; (* Eof(RecFile) *)
Flush(FFile);
Close(FFile);
Close(RecFile);
(* oprations sur .LST: ngliger tant que pas SYMBOL TABLE
rpter aprs ces mots et jeter dans fichier
*)
Repeat
ReadLn(LstFile,Interrog);
Until Pos('SYMBOL',Interrog) <> 0;
Compte := 0;
(* extraire symboles de la table *)
While Not Eof(LstFile) do
Begin
Repeat
ReadLn(LstFile,Interrog);
Lon := Ord(Interrog[0]);
Until Lon > 2; (* on limine les lignes vides *)
Bl := Pos(' ', Interrog);
Symb := Copy(Interrog,1,Bl-1);
Ch := Bl;
Repeat
Ch := Succ(Ch);
Until Ord(Interrog[Ch]) > 32;
Interrog := copy(Interrog, Ch, Lon-Ch+1);
Lon := Ord(Interrog[0]);
Bl := Pos(' ', Interrog);
Adres := Copy(Interrog,1, Bl-1);
if Symb<>'' then NouvLign := Symb + '=0x' + Adres ;
Compte := Succ(Compte);
If Compte < 999 (* NbEntry *) Then
Begin
Ch := Bl;
Repeat
Ch := Succ(Ch);
Until Ord(Interrog[Ch]) > 32;
Interrog := copy(Interrog, Ch, Lon-Ch+1);
Lon := Ord(Interrog[0]);
Bl := Pos(' ', Interrog);
Symb := Copy(Interrog,1, Bl-1);
Ch := Bl;
Repeat
Ch := Succ(Ch);
Until Ord(Interrog[Ch]) > 32;
Interrog := copy(Interrog, Ch, Lon-Ch+1);
Bl := Pos(' ', Interrog);
If Bl > 0 Then Adres := Copy(Interrog,1, Bl)
Else Adres := Interrog;
if Symb<>'' then NouvLign := Nouvlign +';'+ Symb + '=0x' + Adres;
Compte := Succ(Compte);
End; (* de ligne
deux entres *)
WriteLn(BatFile, NouvLign);
End; (* of While *)
(* Eof(LstFile) *)
WriteLn(BatFile,'<fonc.f');
Close(BatFile);
Close(LstFile);
Writeln ;
End. |
Partager