/[projet1]/public/pc/tools/osdk/main/makedisk/FloppyBuilder.cpp
Defence Force logotype

Contents of /public/pc/tools/osdk/main/makedisk/FloppyBuilder.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 975 - (show annotations)
Sun Nov 24 15:00:25 2013 UTC (6 years, 1 month ago) by dbug
File size: 11894 byte(s)
Added the last known version of the FloppyBuilder source code.
It may or may not have been the one that was used to build the semi working version of MakeDisk.exe that I used for my two last demos, at least now it's on the depot so we can try to see if it works.
1
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <string.h>
5
6
7 #define DEBUG 0
8
9 #define header_dsk 256+156
10
11
12 // Nombre de secteur pour une piste
13 #define taille_piste 17
14
15 #define taille_secteur 256
16 // Header secteur
17 #define nb_oct_before_sector 59 // Cas de 17 secteurs/pistes !
18 //#define nb_oct_after_sector 31
19 #define nb_oct_after_sector 43
20
21 int formule_disk(int track,int sector)
22 {
23 int offset;
24 // printf("Secteur %d\n",sector);
25 offset=header_dsk; // on ajoute le header
26 offset+=track*6400; // On avance à la bonne piste
27
28 offset+=(taille_secteur+nb_oct_after_sector+nb_oct_before_sector)*(sector-1);
29 return offset;
30 }
31
32
33
34 void install_boot_sector(FILE *handle_dsk,char *fichier)
35 {
36 FILE *builder2;
37 int i=0;
38 char car;
39 if (fichier[strlen(fichier)-1]=='\n') fichier[strlen(fichier)-1]='\0';
40 builder2=fopen(fichier,"rb");
41 if (builder2!=NULL)
42 {
43 if (DEBUG>1)
44 {
45 printf("FloppyBuilder IN BOOT SECTOR : Write %s\n",fichier);
46 }
47
48 fseek(handle_dsk,0x0319,SEEK_SET); // On avance de temp
49 while (fread (&car,1, 1, builder2)==1)
50 {
51 if (i==256)
52 {
53 printf("Error File for boot sector is larger than 256 Bytes !\n");
54 break;
55 }
56 // car='J';
57 fputc(car,handle_dsk);
58 i++;
59 }
60
61 }
62 else
63 {
64 printf("Error can't found file %s",fichier);
65 }
66 }
67
68
69
70 int detecte_chaine_renvoi_suite(char *a_detecter,char *ligne,char sortie[])
71 {
72 /*Cherche si la chaine *a_detecter est dans ligne si oui
73 elle renvoie ce qui suit sinon renvoie chaine vide*/
74 int i=0,j=0;
75 char test_chaine[200];
76
77 while (ligne[i]==' ' && ligne[i]=='\t') i++;
78
79 for(j=0;j<strlen(a_detecter);j++)
80 {
81 test_chaine[j]=ligne[i];
82 i++;
83 }
84 test_chaine[j]='\0';
85 if (strcmp(test_chaine,a_detecter)==0)
86 {
87 j=0;
88 while (ligne[i]!='\0'&&ligne[i]!='\n')
89 {
90 sortie[j]=ligne[i];
91 i++;
92 j++;
93 }
94 sortie[j]='\0';
95 return 1;
96 }
97 return -1;
98 }
99
100
101
102
103 void CopyDisk(const char *source_name,const char *dest_name)
104 {
105 char buffer[_MAX_PATH];
106
107 sprintf(buffer,"copy /b %s %s",source_name,dest_name);
108 system(buffer);
109 }
110
111
112
113
114 void DisplayError()
115 {
116 printf("\n");
117 printf("\nÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿");
118 printf("\n³ MakeDisk ³");
119 printf("\n³ V0.001 ³");
120 printf("\n³ (c) 2002 Debrune Jerome ³");
121 printf("\nÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ");
122 printf("\n");
123 printf("\nUsage:");
124 printf("\nMakeDisk <descriptionfile> <sourcedisk> <destinationdisk> ");
125 exit(1);
126 }
127
128
129 #define NB_ARG 3
130
131
132
133 bool get_switch(const char *&ptr_arg,const char *ptr_switch)
134 {
135 int lenght=strlen(ptr_switch);
136
137 if (memicmp(ptr_arg,ptr_switch,lenght))
138 {
139 // Not a match
140 return false;
141 }
142 // Validate the parameter
143 ptr_arg+=lenght;
144 return true;
145 }
146
147
148 int get_value(const char *&ptr_arg,long default_value)
149 {
150 char* ptr_end;
151 long value=strtoul(ptr_arg,&ptr_end,10);
152 if (ptr_arg==ptr_end)
153 {
154 value=default_value;
155 }
156 ptr_arg=ptr_end;
157 return value;
158 }
159
160
161
162 void main(int argc, char *argv[])
163 {
164 long nb_arg;
165
166 bool flag_pack=true;
167 long param=1;
168
169 if (argc>1)
170 {
171 for (;;)
172 {
173 nb_arg=argc;
174 const char *ptr_arg=argv[param];
175
176 /*
177 if (get_switch(ptr_arg,"-u")) // UNPACK
178 {
179 flag_pack=false;
180 argc--;
181 param++;
182 }
183 else
184 if (get_switch(ptr_arg,"-p")) // PACK
185 {
186 flag_pack=true;
187 argc--;
188 param++;
189 }
190 */
191 if (nb_arg==argc) break;
192 }
193 }
194
195
196 if (argc!=(NB_ARG+1))
197 {
198 DisplayError();
199 }
200
201
202 //
203 // Copy last parameters
204 //
205 char description_name[_MAX_PATH];
206 char source_name[_MAX_PATH];
207 char dest_name[_MAX_PATH];
208
209 strcpy(description_name,argv[param]);
210 param++;
211 strcpy(source_name,argv[param]);
212 param++;
213 strcpy(dest_name,argv[param]);
214
215
216 int num_prg=0;
217
218 FILE *handle_description;
219 FILE *handle_builder;
220 FILE *handle_dsk;
221 FILE *loader;
222 int ptr_floppy=0;
223 char ligne[900];
224 int num_track=0;
225 int track=12;
226 int ptr_track=0;
227 int sector=17;
228 int ptr_sector=1;
229 char car;
230 int size=0;
231 int temp;
232 int ptr_nb_oct=0;
233 int foireux=0;
234 int nb_sectors_by_files=0;
235 int start=0;
236 char sortie[1500];
237 char code_drive[1500]="datas_lecteur\n.byt ";
238 char code_sector[1500]="datas_secteur\n.byt ";
239 char code_track[1500]="datas_piste\n.byt ";
240 char code_nombre_secteur[1500]="nombre_secteur\n.byt ";
241 char code_adress_low[1500]="adresse_chargement_low\n.byt ";
242 char code_adress_high[1500]="adresse_chargement_high\n.byt ";
243 char buf_convert[100];
244 char strbuf[5];
245 int all_code=0;
246 int change_track=0;
247
248 //
249 // Open the description file
250 //
251 handle_description=fopen(description_name,"r");
252 if (!handle_description)
253 {
254 printf("FloppyBuilder :Can't open '%s'\n",description_name);
255 exit(1);
256 }
257
258 //
259 // Copy the floppy disk
260 //
261 CopyDisk(source_name,dest_name);
262
263
264 handle_dsk=fopen(dest_name,"rb+");
265 if (!handle_dsk)
266 {
267 printf("FloppyBuilder :Can't open '%s'\n",dest_name);
268 exit(1);
269 }
270
271
272 printf("FloppyBuilder : %s is created\n",dest_name);
273 //jump_to_next_track=6400-(taille_secteur+nb_oct_after_sector+nb_oct_before_sector)*taille_piste-1;
274 //ptr_track*6400+header_dsk+(taille_secteur+nb_oct_after_sector+nb_oct_before_sector)*(ptr_sector-1);
275 temp=formule_disk(ptr_track,ptr_sector);
276
277 fseek(handle_dsk,temp,SEEK_SET); // On avance de temp
278 //printf("{!} FloppyBuilder : First position at %x\n",temp);
279 // On lit la piste et le secteur
280 fscanf(handle_description,"%d %d",&ptr_track,&ptr_sector);
281 if (DEBUG>1)
282 {
283 printf("FloppyBuilder : Write at Track %d sector %d \n",ptr_track,ptr_sector);
284 }
285
286 // On saute grosse bidouille
287 fgets(ligne,900,handle_description);
288 while (fgets(ligne,900,handle_description)!=NULL)
289 {
290 if (detecte_chaine_renvoi_suite("#bootsector",ligne,sortie)==1)
291 {
292 //fscanf(handle_description,"%d %d",&ptr_track,&ptr_sector);
293 printf("Installing in boot sector !\n");
294 fgets(ligne,900,handle_description); // On lit le fichier à installer dans le boot sector
295 install_boot_sector(handle_dsk,ligne);
296 }
297 else
298 if (detecte_chaine_renvoi_suite("#new position on disk",ligne,sortie)==1)
299 {
300 fscanf(handle_description,"%d %d",&ptr_track,&ptr_sector);
301 fgets(ligne,900,handle_description);
302 if (DEBUG>1)
303 {
304 printf("FloppyBuilder : Change position !!!\n");
305 printf("FloppyBuilder : Write at Track %d sector %d \n",ptr_track,ptr_sector);
306 }
307 fgets(ligne,900,handle_description);
308 }
309 else
310 if (detecte_chaine_renvoi_suite("#load it at ",ligne,sortie)==1)
311 {
312 //printf("%s\n",ligne);
313 if (start==1)
314 {
315 strcat(code_adress_low,",");
316 strcat(code_adress_high,",");
317 }
318 strbuf[0]='$';
319 strbuf[1]=sortie[0];
320 strbuf[2]=sortie[1];
321 strbuf[3]='\0';
322 strcat(code_adress_high,strbuf);
323 strbuf[0]='$';
324 strbuf[1]=sortie[2];
325 strbuf[2]=sortie[3];
326 strbuf[3]='\0';
327 strcat(code_adress_low,strbuf);
328 }
329 else
330 {
331 if (ligne[strlen(ligne)-1]=='\n') ligne[strlen(ligne)-1]='\0';
332 if (DEBUG>1)
333 {
334 printf("\033[37m");
335 printf("\033[32m{!} FloppyBuilder : Request to add %s\n",ligne);
336 printf("\033[37m");
337 printf("FloppyBuilder : Write %s at Track %d sector %d \n",ligne,ptr_track,ptr_sector);
338 }
339 if (ptr_sector==taille_piste+1)
340 {
341 ptr_sector=1;
342 ptr_track++;
343 }
344
345 ptr_nb_oct=0;
346
347 if (start==1)
348 {
349 strcat(code_drive,",");
350 strcat(code_sector,",");
351 strcat(code_track,",");
352 strcat(code_nombre_secteur,",");
353
354 }
355 if (ptr_track>41) // face 2
356 {
357 sprintf(buf_convert,"%d",ptr_track-42+128);
358 }
359 else
360 {
361 sprintf(buf_convert,"%d",ptr_track);
362 }
363 temp=formule_disk(ptr_track,ptr_sector);
364 // temp=ptr_track*6400+header_dsk+(taille_secteur+nb_oct_after_sector+nb_oct_before_sector)*(ptr_sector-1);
365 if (DEBUG>1)
366 {
367 printf("{!} FloppyBuilder : Write file at %x\n",temp);
368 }
369 fseek(handle_dsk,temp,SEEK_SET); // On avance de temp
370
371 strcat(code_track,buf_convert);
372
373 sprintf(buf_convert,"%d",ptr_sector);
374 strcat(code_sector,buf_convert);
375
376 strcat(code_drive,"0");
377 //
378
379 /*LECTURE */
380
381 // ICI on construit la handle_dsk avec le pgrm c ici que le bug se trouve
382 handle_builder=fopen(ligne,"rb");
383 if (!handle_builder)
384 {
385 printf("FloppyBuilder: Error can't open %s\n",ligne);
386 exit(1);
387 }
388
389 if (DEBUG>1)
390 printf("\033[32m{!} FloppyBuilder : Write %s\n",ligne);
391 nb_sectors_by_files=0;
392 while (fread (&car,1, 1, handle_builder)==1)
393 {
394 //On écrit un secteur ? On saute le descripteur
395
396 if (ptr_nb_oct==256) // We reached a sector
397 {
398
399 fseek(handle_dsk,nb_oct_after_sector+nb_oct_before_sector,SEEK_CUR); // On avance de temp
400 ptr_nb_oct=0;
401 ptr_sector++;
402 nb_sectors_by_files++;
403 }
404
405 if (ptr_sector==taille_piste+1) // We reached the end of the track!
406 {
407 ptr_nb_oct=0;
408 ptr_sector=1;
409 ptr_track++;
410 temp=formule_disk(ptr_track,ptr_sector);
411 if (DEBUG>1)
412 {
413 printf("{!} FloppyBuilder : Go to the next track Sector 1 at %x\n",temp);
414 }
415 fseek(handle_dsk,temp,SEEK_SET); // On avance de temp
416 }
417
418 fputc(car,handle_dsk);
419 ptr_nb_oct++;
420 ptr_floppy++;
421 size++;
422 }
423
424 if (DEBUG>1)
425 printf("{!} FloppyBuilder : %d bytes written from %s, Sectors written : %d \n",size,ligne,nb_sectors_by_files);
426
427 all_code+=size;
428 //ptr_sector++;
429 nb_sectors_by_files++;
430 sprintf(buf_convert,"%d",nb_sectors_by_files);
431 strcat(code_nombre_secteur,buf_convert);
432 ptr_sector++;
433 size=0;
434 fclose(handle_builder);
435 num_prg++;
436
437
438 start=1;
439 }// Fin test load it at
440 /*********************************Fin de construiction du prgm ds la handle_dsk*/
441 } // fin bcl de lecture ds handle_description
442
443 loader=fopen("loader.cod","w");
444 printf("{!} FloppyBuilder : nb prg %d\n",num_prg);
445
446 fputs(code_drive,loader);
447 fputs("\n",loader);
448
449 fputs("nb_prgm\n",loader);
450 fputs(code_sector,loader);
451 fputs("\n",loader);
452 fputs(code_track,loader);
453 fputs("\n",loader);
454 fputs(code_nombre_secteur,loader);
455 fputs("\n",loader);
456 fputs(code_adress_low,loader);
457 fputs("\n",loader);
458 fputs(code_adress_high,loader);
459 fputs("\n",loader);
460
461
462 fclose(loader);
463 fclose(handle_description);
464 //printf("FloppyBuilder : handle_description.txt is closed\n");
465 fclose(handle_dsk);
466 //while (ptr_floppy<SIMPLE_FACE) {fputc(car,handle_dsk);}
467 printf("FloppyBuilder : handle_dsk.dsk built successfully\n");
468 printf("{!} FloppyBuilder : %d bytes written\n",all_code);
469 }

  ViewVC Help
Powered by ViewVC 1.1.26