home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / 1990 / 03 / praxis / format.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-12-29  |  5.8 KB  |  209 lines

  1. /* ------------------------------------------------------ */
  2. /*                       FORMAT.C                         */
  3. /*        PC-Controllerprogrammierung in Turbo C          */
  4. /*          (c) 1990 Ulrich Schmitz & TOOLBOX             */
  5. /* ------------------------------------------------------ */
  6. #include<dos.h>
  7. #include<stdio.h>
  8. #include<ctype.h>
  9. #include<graphics.h>
  10.  
  11. typedef unsigned char byte;   /* neuer Variablentyp BYTE  */
  12. static int katastrophe;
  13.  
  14. /* beschreibt das Format eines Sektors                    */
  15. struct FormatDes { byte Spur,
  16.             Seite,
  17.             Sektor,
  18.             Laenge; };
  19.  
  20. #ifndef MK_FP
  21. #define MK_FP(seg,ofs)((void far *)((unsigned long)(seg)<<16|ofs))
  22. #define peekb(seg, ofs) *((char far *) MK_FP(seg, ofs))
  23. #endif
  24.  
  25. /* ****************************************************** */
  26. /* RESET aller angeschlossenen Diskettenlaufwerke         */
  27. /* ****************************************************** */
  28.  
  29. byte ResetDisk()
  30. {
  31.   union REGS Register;
  32.   Register.h.ah = 0;
  33.   int86(0x13, &Register, &Register);
  34.   return(Register.h.ah);
  35. }
  36.  
  37. /* ****************************************************** */
  38. /* Fehlererkennung und Bewertung                          */
  39. /* ****************************************************** */
  40.  
  41. byte WDS(Status)
  42. byte Status;
  43. {
  44.   if (Status) {
  45.     printf("\n");  gotoxy(5,22);
  46.     printf("Fehler:                                                                ");
  47.     gotoxy(20,22);
  48.     katastrophe++;
  49.     switch (Status) {
  50.       case 0x01 :
  51.          printf("Nicht erlaubte Funktionsnummer      ");
  52.     break;
  53.       case 0x02 :
  54.          printf("Addreß-Markierung nicht gefunden    ");
  55.     break;
  56.       case 0x03 :
  57.          printf("Diskette ist schreibgeschützt       ");
  58.     break;
  59.       case 0x04 :
  60.          printf("Sektor nicht gefunden               ");
  61.     break;
  62.       case 0x06 :
  63.          printf("Diskette wurde gewechselt !         ");
  64.     break;
  65.       case 0x08 :
  66.          printf("DMA-Überlauf                        ");
  67.     break;
  68.       case 0x09 :
  69.          printf("Datenübertragung über Segmentgrenze ");
  70.     break;
  71.       case 0x10 :
  72.          printf("Lesefehler                          ");
  73.     break;
  74.       case 0x20 :
  75.          printf("Fehler des Disk-Controllers         ");
  76.     break;
  77.       case 0x40 :
  78.          printf("Spur nicht gefunden                 ");
  79.     break;
  80.       case 0x80 :
  81.          printf("Timeout-Fehler                      ");
  82.     break;
  83.       case 0xff :
  84.          printf("Unzulässige Parameter !             ");
  85.     break;
  86.       default   :
  87.        printf("Toll!, Fehler Nr.%d unbekannt! ",Status);
  88.     }
  89.     delay(5000);                /*  wartet 3-4 Sekunden   */
  90.     ResetDisk();
  91.   }
  92.   return(!Status);
  93. }
  94.  
  95. /* ****************************************************** */
  96. /* FORMAT:  formatiert eine oder mehrere Spuren           */
  97. /* Eingabe: s.u.                                          */
  98. /* Ausgabe: Fehlerstatus                                  */
  99. /* ****************************************************** */
  100.  
  101. byte Format(Laufwerk, Seite, Spur, Anzahl, Bytes)
  102. byte Laufwerk,  /* 0 oder 1                               */
  103.      Seite,     /* 0 oder 1                               */
  104.      Spur,      /* 0 bis 39                               */
  105.      Anzahl,    /* 9 (AT-Laufwerk 15), Sektoren pro Track */
  106.      Bytes;     /*      0=128  1=256  2=512  3=1024 Bytes */
  107.  
  108. {
  109. union REGS Register, Aus_Reg;
  110. struct SREGS segreg;
  111. struct FormatDes Formate[15];
  112. byte i;
  113.  
  114.   /*  Format festlegen  */
  115.  
  116.   Register.h.ah = 0x17;   /* Funktion 'Format festlegen'  */
  117.   Register.h.al = 2;      /* Drive Typ
  118.               01 -> 320/360 KByte
  119.               02 -> 360 KByte in 1.2 MByte Drive
  120.               03 -> 1.2 MByte in 1.2 MByte Drive
  121.               04 -> 720 KByte in 720 KByte Drive  */
  122.  
  123.   Register.h.dl = 0;           /* Ziel - Drive (0 oder 1) */
  124.   int86(0x13, &Register, &Aus_Reg);
  125.  
  126.   /*  Spur formatieren  */
  127.  
  128.   for(i = 1; i < Anzahl; i++) {
  129.     Formate[i].Spur   = Spur;
  130.     Formate[i].Seite  = Seite;
  131.     Formate[i].Sektor = i;
  132.     Formate[i].Laenge = Bytes;
  133.   }
  134.  
  135.   Register.h.ah = 5;            /*  Funktion formatieren  */
  136.   Register.h.al = Anzahl;
  137.   Register.h.dh = Seite;
  138.   Register.h.dl = Laufwerk;
  139.   Register.h.ch = Spur;
  140.   Register.x.bx = (unsigned int) Formate;
  141.   int86(0x13, &Register, &Aus_Reg);
  142.   return(Aus_Reg.h.ah);
  143. }
  144.  
  145.  
  146. main()
  147. {
  148. static byte Status, Laufwerk=0, Seite=0, Spur, Anzahl=9;
  149. static int i, Bytes, X_Bytes, start, ende,
  150.        erste_Spur, letzte_Spur;
  151.  
  152.   clrscr();
  153.   ResetDisk();
  154.  
  155.   printf("Bitte Seite angeben (0/1/2) :");
  156.   scanf("%d", &Seite);
  157.  
  158.   gotoxy(0,3);
  159.   printf("Von Spur (0-39):");
  160.   scanf("%d",&erste_Spur);
  161.  
  162.   gotoxy(20,2);
  163.   printf("bis Spur (0-39):");
  164.   scanf("%d",&letzte_Spur);
  165.  
  166.   printf("Bytes pro Sektor angeben ");
  167.   printf("0=128, 1=256, 2=512, 3=1024) normal=2 :");
  168.   scanf("%d",&Bytes);
  169.  
  170.   printf("Anzahl Sektoren pro Spur ");
  171.   printf("(9=normal, bei AT HD-Laufwerken 15):");
  172.   scanf("%d",&Anzahl);
  173.  
  174.   X_Bytes = 64;
  175.  
  176.   for(i = 0; i <= Bytes; i++)  X_Bytes = X_Bytes * 2;
  177.  
  178.   start = Seite;
  179.   ende  = Seite;
  180.  
  181.   if (Seite == 2) {
  182.     start = 0;
  183.     ende = 1;
  184.   }
  185.   for(Seite = start; Seite <= ende; Seite++) {
  186.     for(Spur = erste_Spur; Spur <= letzte_Spur; Spur++) {
  187.       Status = 0;
  188.       while((Status != 1) && (katastrophe <= 2)) {
  189.     Status =
  190.       WDS(Format(Laufwerk, Seite, Spur, Anzahl, Bytes));
  191.     gotoxy(2,22);
  192.     printf("  Drive:%d   Seite:%d   Spur:%02d   Sektoren/Track:%02d   Bytes/Sektor:%4d",Laufwerk,Seite,Spur,Anzahl, X_Bytes);
  193.       }
  194.     }
  195.   }
  196.   if (katastrophe <= 2) {
  197.     gotoxy(21,21);
  198.     printf("Formatieren erfolgreich abgeschlossen!");
  199.   }
  200.   else {
  201.     gotoxy(18,21);
  202.     printf("Es sind Fehler beim Formatieren aufgetreten!");
  203.   }
  204.   getch();
  205.   clrscr();
  206.   return(0);
  207. }
  208. /* ------------------------------------------------------ */
  209. /*                  Ende von FORMAT.C                     */