[comp.os.msdos.programmer] Formatting diskettes, round II

jml@stekt.oulu.fi (Lepp{j{rvi Jouni) (04/22/91)

Problem : formatting 1.2 M floppy

I have received some replies to my question about formatting
diskettes, which I posted some days ago. Thanks (again) for all those
who replied. Still, I can't make it work .. :-)  I have been suggested
that my sector header table has incorret contents (it should not). One
suggestion was to format the 15 tracks of a 1.2 M disk in two parts. I
tried this, but no luck. (Apparently int 13h, ah=5 is meant to format
an entre track). I also received dome source code, but it apparently
only reads/writes diskettes. I can do this already, but formatting is
the problem. 

So, I guess I have to try again with a piece of my code included. The
following tiny program is for Borland's turbo C. The intention is to
format the single track 1, side 0 on a 1.2 M floppy. (If I can format 
one, then I guess I can format them all.) What goes wrong with this,
is that I get just 9 formatted sectors instead of 15. The code uses
turbo's pseudo-variables and __int__(). This could cause problems
since register contents may be overwriten as setting up other
registers. According to the assembler output of the compiler, however,
this goes as intented.

#include <stdio.h>

main()
{
   unsigned i;
   unsigned char fmtbuf[15][4];
   
   /* format track 1, head 0, drive A */
   
   /* set up headers */
   
   for (i = 0; i < 15 ;i++)
   {
      fmtbuf[i][0] = 1;       /* track */
      fmtbuf[i][1] = 0;       /* head */
      fmtbuf[i][2] = i+1;     /* sector */
      fmtbuf[i][3] = 2;       /* 512 bytes / sector */
   }
   
   /* reset */
   
   _DL = 0x00;
   _AH = 0x00;
   __int__(0x13); 
   i = _AH;
   
   printf("result %x\n",i);
   
   /* set format parameters */
   
   _DL = 0x00;                /* drive A */
   _CX = 0x4f0f;              /* 80 tracks (4fh + 1), 15 sectors */
   _AX = 0x180f;              /* function 18h - set format parameters */
   __int__(0x13);
   i = _AH;
   
   printf("result %x\n",i);
     
   /* format track */

   _ES = _DS;                 /* ES:BX pointer to header table */
   _DX = 0x0000;              /* head = 0, drive = A */
   _CX = 0x0100;              /* track = 0, sector = 0 (sector value has no effect ?) */
   _BX = (unsigned) &fmtbuf;  /* ES:BX pointer to header table */
   _AX = 0x050f;              /* function 05h, format 0fh sectors */
   __int__(0x13);
   i = _AH;
   
   printf("result %x\n",i);
}

So, this is my way. What is the right way ?

If you should actually want to try the code, remember that it effectively
destroys the diskette's contents (!). The reason for track 1 is that
it is about the first track I can write without destroying the boot
record and so the BPB which my diskette scanning utility needs. I, in
turn, need this utility to see the results.

Please post answers (if any) directly to me. I'll summarize later if
there is intrest. Any clues are welcome.

-- 
- Jouni Lepp{j{rvi / jml@stekt.oulu.fi   -
- '.. but only maybe, life is a joy .. ' -

jml@stekt.oulu.fi (Lepp{j{rvi Jouni) (04/22/91)

I have to correct something in previous posting right away :

   suggestion was to format the 15 tracks of a 1.2 M disk in two
                                   ^
                                   this should be _sectors_ (of course).

One other thing : Our site's news server machine has not been working
properly for the the latest days. So, if any of you replied directly
in here the reply may have been lost. This should not have affected
mail, but if any of you who replied has not received a reply, please
repost. I've send one for each received.


--
- Jouni Lepp{j{rvi / jml@stekt.oulu.fi   -
- '.. but only maybe, life is a joy .. ' -