/[projet1]/public/oric/demos/assembly_2002/makedisk/FloppyBuilder.c
Defence Force logotype

Contents of /public/oric/demos/assembly_2002/makedisk/FloppyBuilder.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 473 - (show annotations)
Fri Apr 29 22:00:16 2011 UTC (9 years, 1 month ago) by dbug
File MIME type: text/plain
File size: 9483 byte(s)
Added the Assembly 2002 demo, it's very messy, need some cleanup, but well
1 #include <stdio.h>
2 #define DEBUG 0
3
4 #define header_dsk 256+156
5
6
7 // Nombre de secteur pour une piste
8 #define taille_piste 17
9
10 #define taille_secteur 256
11 // Header secteur
12 #define nb_oct_before_sector 59 // Cas de 17 secteurs/pistes !
13 //#define nb_oct_after_sector 31
14 #define nb_oct_after_sector 43
15
16 int formule_disk(int track,int sector)
17 {
18 int offset;
19 // printf("Secteur %d\n",sector);
20 offset=header_dsk; // on ajoute le header
21 offset+=track*6400; // On avance à la bonne piste
22
23 offset+=(taille_secteur+nb_oct_after_sector+nb_oct_before_sector)*(sector-1);
24 return offset;
25 }
26
27 void install_boot_sector(FILE *floppy,char *fichier)
28 {
29 FILE *builder2;
30 int i=0;
31 char car;
32 if (fichier[strlen(fichier)-1]=='\n') fichier[strlen(fichier)-1]='\0';
33 builder2=fopen(fichier,"rb");
34 if (builder2!=NULL)
35 {
36 if (DEBUG>1)
37 printf("\033[35m{!} FloppyBuilder IN BOOT SECTOR : Write %s\n",fichier);
38
39 fseek(floppy,0x0319,SEEK_SET); // On avance de temp
40 while (fread (&car,1, 1, builder2)==1)
41 {
42 if (i==256)
43 {
44 printf("\033[34m{!} Error File for boot sector is larger than 256 Bytes !\n");
45 break;
46 }
47 // car='J';
48 fputc(car,floppy);
49 i++;
50 }
51
52 }
53 else
54 printf("\033[34m{!} Error can't found file %s",fichier);
55 printf("\033[31m");
56 // return 0x0319;
57 }
58
59 int detecte_chaine_renvoi_suite(char *a_detecter,char *ligne,char sortie[])
60 {
61 /*Cherche si la chaine *a_detecter est dans ligne si oui
62 elle renvoie ce qui suit sinon renvoie chaine vide*/
63 int i=0,j=0;
64 char test_chaine[200];
65
66 while (ligne[i]==' ' && ligne[i]=='\t') i++;
67
68 for(j=0;j<strlen(a_detecter);j++)
69 {
70 test_chaine[j]=ligne[i];
71 i++;
72 }
73 test_chaine[j]='\0';
74 if (strcmp(test_chaine,a_detecter)==0)
75 {
76 j=0;
77 while (ligne[i]!='\0'&&ligne[i]!='\n')
78 {
79 sortie[j]=ligne[i];
80 i++;
81 j++;
82 }
83 sortie[j]='\0';
84 return 1;
85 }
86 return -1;
87 }
88
89
90
91
92
93
94
95 main (int argv, char *argc[])
96
97 {
98
99 int num_prg=0;
100
101 FILE *filetobuild;
102 FILE *builder;
103 FILE *floppy;
104 FILE *loader;
105 int ptr_floppy=0;
106 char ligne[900];
107 int num_track=0;
108 int track=12;
109 int ptr_track=0;
110 int sector=17;
111 int ptr_sector=1;
112 char car;
113 int size=0;
114 int temp;
115 int i;
116 int ptr_nb_oct=0;
117 int jump_to_next_track;
118 int foireux=0;
119 int nb_sectors_by_files=0;
120 int start=0;
121 char sortie[1500];
122 char code_drive[1500]="datas_lecteur\n.byt ";
123 char code_sector[1500]="datas_secteur\n.byt ";
124 char code_track[1500]="datas_piste\n.byt ";
125 char code_nombre_secteur[1500]="nombre_secteur\n.byt ";
126 char code_adress_low[1500]="adresse_chargement_low\n.byt ";
127 char code_adress_high[1500]="adresse_chargement_high\n.byt ";
128 char buf_convert[100];
129 char strbuf[5];
130 int all_code=0;
131 int change_track=0;
132
133 printf("FloppyBuilder 2001 May By Jede V0.1\n");
134 printf("FloppyBuilder 2002 May By Jede V0.2 (Current)\n");
135 //printf("\33[31mBe careful ! Track 42 sector 15-17 is reserved for Booting the program !\n");
136 printf("\033[37m");
137 /*Read the conf file*/
138 filetobuild=fopen("filetobuild.txt","r");
139
140 system("cp -f default.dsk 1vip4.dsk");
141
142 if (filetobuild==NULL)
143 printf("----------------------------------------------------------->FloppyBuilder :Can't open filetobuild.txt\n");
144 else
145 {
146 start=0;
147 floppy=fopen("1vip4.dsk","rb+");
148 printf("FloppyBuilder : 1vip4.dsk is created\n");
149 //jump_to_next_track=6400-(taille_secteur+nb_oct_after_sector+nb_oct_before_sector)*taille_piste-1;
150 //ptr_track*6400+header_dsk+(taille_secteur+nb_oct_after_sector+nb_oct_before_sector)*(ptr_sector-1);
151 temp=formule_disk(ptr_track,ptr_sector);
152
153 fseek(floppy,temp,SEEK_SET); // On avance de temp
154 //printf("{!} FloppyBuilder : First position at %x\n",temp);
155 // On lit la piste et le secteur
156 fscanf(filetobuild,"%d %d",&ptr_track,&ptr_sector);
157 if (DEBUG>1)
158 printf("FloppyBuilder : Write at Track %d sector %d \n",ptr_track,ptr_sector);
159 // On saute grosse bidouille
160 fgets(ligne,900,filetobuild);
161 while (fgets(ligne,900,filetobuild)!=NULL)
162 {
163 if (detecte_chaine_renvoi_suite("#bootsector",ligne,sortie)==1)
164 {
165 //fscanf(filetobuild,"%d %d",&ptr_track,&ptr_sector);
166 printf("Installing in boot sector !\n");
167 fgets(ligne,900,filetobuild); // On lit le fichier à installer dans le boot sector
168 install_boot_sector(floppy,ligne);
169 }
170 else
171 if (detecte_chaine_renvoi_suite("#new position on disk",ligne,sortie)==1)
172 {
173 fscanf(filetobuild,"%d %d",&ptr_track,&ptr_sector);
174 fgets(ligne,900,filetobuild);
175 if (DEBUG>1)
176 {
177 printf("FloppyBuilder : Change position !!!\n");
178 printf("FloppyBuilder : Write at Track %d sector %d \n",ptr_track,ptr_sector);
179 }
180 fgets(ligne,900,filetobuild);
181 }
182 else
183 if (detecte_chaine_renvoi_suite("#load it at ",ligne,sortie)==1)
184 {
185 //printf("%s\n",ligne);
186 if (start==1)
187 {
188 strcat(code_adress_low,",");
189 strcat(code_adress_high,",");
190 }
191 strbuf[0]='$';
192 strbuf[1]=sortie[0];
193 strbuf[2]=sortie[1];
194 strbuf[3]='\0';
195 strcat(code_adress_high,strbuf);
196 strbuf[0]='$';
197 strbuf[1]=sortie[2];
198 strbuf[2]=sortie[3];
199 strbuf[3]='\0';
200 strcat(code_adress_low,strbuf);
201 }
202 else
203 {
204 if (ligne[strlen(ligne)-1]=='\n') ligne[strlen(ligne)-1]='\0';
205 if (DEBUG>1)
206 {
207 printf("\033[37m");
208 printf("\033[32m{!} FloppyBuilder : Request to add %s\n",ligne);
209 printf("\033[37m");
210 printf("FloppyBuilder : Write %s at Track %d sector %d \n",ligne,ptr_track,ptr_sector);
211 }
212 if (ptr_sector==taille_piste+1)
213 {
214 ptr_sector=1;
215 ptr_track++;
216 }
217
218
219
220 ptr_nb_oct=0;
221
222 if (start==1)
223 {
224 strcat(code_drive,",");
225 strcat(code_sector,",");
226 strcat(code_track,",");
227 strcat(code_nombre_secteur,",");
228
229 }
230 if (ptr_track>41) // face 2
231 {
232 sprintf(buf_convert,"%d",ptr_track-42+128);
233 }
234 else
235 sprintf(buf_convert,"%d",ptr_track);
236 temp=formule_disk(ptr_track,ptr_sector);
237 // temp=ptr_track*6400+header_dsk+(taille_secteur+nb_oct_after_sector+nb_oct_before_sector)*(ptr_sector-1);
238 if (DEBUG>1)
239 printf("{!} FloppyBuilder : Write file at %x\n",temp);
240 fseek(floppy,temp,SEEK_SET); // On avance de temp
241
242 strcat(code_track,buf_convert);
243
244 sprintf(buf_convert,"%d",ptr_sector);
245 strcat(code_sector,buf_convert);
246
247 strcat(code_drive,"0");
248 //
249
250 /*LECTURE */
251
252 /*********************************ICI on construit la floppy avec le pgrm c ici que le bug se trouve*/
253 builder=fopen(ligne,"rb");
254 if (builder==NULL)
255 printf("----------------------------------------------------------->FloppyBuilder : Error can't open %s\n",ligne);
256 else
257 {
258 if (DEBUG>1)
259 printf("\033[32m{!} FloppyBuilder : Write %s\n",ligne);
260 nb_sectors_by_files=0;
261 while (fread (&car,1, 1, builder)==1)
262 {
263 //On écrit un secteur ? On saute le descripteur
264
265
266 if (ptr_nb_oct==256) // We reached a sector
267 {
268
269 fseek(floppy,nb_oct_after_sector+nb_oct_before_sector,SEEK_CUR); // On avance de temp
270 ptr_nb_oct=0;
271 ptr_sector++;
272 nb_sectors_by_files++;
273 }
274
275 if (ptr_sector==taille_piste+1) // We reached the end of the track!
276 {
277
278 // printf("nb_oct %d\n",ptr_nb_oct);
279 //fputc(car,floppy);
280 //fread (&car,1, 1, builder);
281 ptr_nb_oct=0;
282 ptr_sector=1;
283 ptr_track++;
284 temp=formule_disk(ptr_track,ptr_sector);
285 if (DEBUG>1)
286 {
287 printf("{!} FloppyBuilder : Go to the next track Sector 1 at %x\n",temp);
288 }
289 fseek(floppy,temp,SEEK_SET); // On avance de temp
290 //ptr_nb_oct=1;// On écrit 2 fois l'octet, si on ne le fait pas le disk n'est pas valide
291 }
292
293
294
295
296 fputc(car,floppy);
297 ptr_nb_oct++;
298 ptr_floppy++;
299 size++;
300 }
301 }
302 if (DEBUG>1)
303 printf("{!} FloppyBuilder : %d bytes written from %s, Sectors written : %d \n",size,ligne,nb_sectors_by_files);
304 all_code+=size;
305 //ptr_sector++;
306 nb_sectors_by_files++;
307 sprintf(buf_convert,"%d",nb_sectors_by_files);
308 strcat(code_nombre_secteur,buf_convert);
309 ptr_sector++;
310 size=0;
311 fclose(builder);
312 num_prg++;
313
314
315 start=1;
316 }// Fin test load it at
317 /*********************************Fin de construiction du prgm ds la floppy*/
318 } // fin bcl de lecture ds filetobuild
319 loader=fopen("loader.cod","w");
320 printf("{!} FloppyBuilder : nb prg %d\n",num_prg);
321
322 fputs(code_drive,loader);
323 fputs("\n",loader);
324
325
326 fputs("nb_prgm\n",loader);
327 fputs(code_sector,loader);
328 fputs("\n",loader);
329 fputs(code_track,loader);
330 fputs("\n",loader);
331 fputs(code_nombre_secteur,loader);
332 fputs("\n",loader);
333 fputs(code_adress_low,loader);
334 fputs("\n",loader);
335 fputs(code_adress_high,loader);
336 fputs("\n",loader);
337
338
339 fclose(loader);
340 fclose(filetobuild);
341 //printf("FloppyBuilder : filetobuild.txt is closed\n");
342 fclose(floppy);
343 //while (ptr_floppy<SIMPLE_FACE) {fputc(car,floppy);}
344 printf("FloppyBuilder : floppy.dsk built successfully\n");
345 printf("{!} FloppyBuilder : %d bytes written\n",all_code);
346
347 }
348
349 printf("\033[39m");
350 }

  ViewVC Help
Powered by ViewVC 1.1.26